0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-03 21:48:55 -05:00

fix(connector-alipay-native): fix data guard (#992)

This commit is contained in:
Darcy Ye 2022-05-30 17:36:42 +08:00 committed by GitHub
parent 28198590fa
commit 2dc50d6531
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -170,7 +170,7 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
const { id, name, avatar } = await alipayNativeMethods.getUserInfo({ authCode: 'code' });
const { id, name, avatar } = await alipayNativeMethods.getUserInfo({ auth_code: 'code' });
expect(id).toEqual('2088000000000000');
expect(name).toEqual('PlayboyEric');
expect(avatar).toEqual('https://www.alipay.com/xxx.jpg');
@ -192,7 +192,7 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
await expect(alipayNativeMethods.getUserInfo({ authCode: 'wrong_code' })).rejects.toMatchError(
await expect(alipayNativeMethods.getUserInfo({ auth_code: 'wrong_code' })).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid, 'Invalid auth token')
);
});
@ -213,7 +213,7 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
await expect(alipayNativeMethods.getUserInfo({ authCode: 'wrong_code' })).rejects.toMatchError(
await expect(alipayNativeMethods.getUserInfo({ auth_code: 'wrong_code' })).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.General)
);
});
@ -236,7 +236,7 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
await expect(alipayNativeMethods.getUserInfo({ authCode: 'wrong_code' })).rejects.toMatchError(
await expect(alipayNativeMethods.getUserInfo({ auth_code: 'wrong_code' })).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.InvalidResponse)
);
});
@ -247,6 +247,6 @@ describe('getUserInfo', () => {
.mockResolvedValueOnce(mockedAlipayNativeConfigWithValidPrivateKey);
nock(alipayEndpointUrl.origin).post(alipayEndpointUrl.pathname).query(true).reply(500);
await expect(alipayNativeMethods.getUserInfo({ authCode: 'wrong_code' })).rejects.toThrow();
await expect(alipayNativeMethods.getUserInfo({ auth_code: 'wrong_code' })).rejects.toThrow();
});
});

View file

@ -40,7 +40,7 @@ import { signingParameters } from './utils';
export type { AlipayNativeConfig } from './types';
const dataGuard = z.object({ authCode: z.string() });
const dataGuard = z.object({ auth_code: z.string() });
export default class AlipayNativeConnector implements SocialConnector {
public metadata: ConnectorMetadata = defaultMetadata;
@ -99,9 +99,9 @@ export default class AlipayNativeConnector implements SocialConnector {
};
public getUserInfo: GetUserInfo = async (data) => {
const { authCode } = dataGuard.parse(data);
const { auth_code } = dataGuard.parse(data);
const config = await this.getConfig(this.metadata.id);
const { accessToken } = await this.getAccessToken(authCode);
const { accessToken } = await this.getAccessToken(auth_code);
assert(
accessToken && config,
new ConnectorError(ConnectorErrorCodes.InsufficientRequestParameters)