mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
fix(core): fix response code for requesting wechat APIs (#422)
This commit is contained in:
parent
ec8ecf262a
commit
2e08ec9db0
2 changed files with 10 additions and 11 deletions
|
@ -43,7 +43,7 @@ describe('getAccessToken', () => {
|
||||||
nock(accessTokenEndpointUrl.origin)
|
nock(accessTokenEndpointUrl.origin)
|
||||||
.get(accessTokenEndpointUrl.pathname)
|
.get(accessTokenEndpointUrl.pathname)
|
||||||
.query(parameters)
|
.query(parameters)
|
||||||
.reply(200, {
|
.reply(0, {
|
||||||
access_token: 'access_token',
|
access_token: 'access_token',
|
||||||
openid: 'openid',
|
openid: 'openid',
|
||||||
});
|
});
|
||||||
|
@ -56,7 +56,7 @@ describe('getAccessToken', () => {
|
||||||
nock(accessTokenEndpointUrl.origin)
|
nock(accessTokenEndpointUrl.origin)
|
||||||
.get(accessTokenEndpointUrl.pathname)
|
.get(accessTokenEndpointUrl.pathname)
|
||||||
.query(parameters)
|
.query(parameters)
|
||||||
.reply(200, {});
|
.reply(0, {});
|
||||||
await expect(getAccessToken('code')).rejects.toMatchError(
|
await expect(getAccessToken('code')).rejects.toMatchError(
|
||||||
new ConnectorError(ConnectorErrorCodes.SocialAuthCodeInvalid)
|
new ConnectorError(ConnectorErrorCodes.SocialAuthCodeInvalid)
|
||||||
);
|
);
|
||||||
|
@ -84,10 +84,7 @@ describe('getUserInfo', () => {
|
||||||
const parameters = new URLSearchParams({ access_token: 'accessToken', openid: 'openid' });
|
const parameters = new URLSearchParams({ access_token: 'accessToken', openid: 'openid' });
|
||||||
|
|
||||||
it('should get valid SocialUserInfo', async () => {
|
it('should get valid SocialUserInfo', async () => {
|
||||||
nock(userInfoEndpointUrl.origin)
|
nock(userInfoEndpointUrl.origin).get(userInfoEndpointUrl.pathname).query(parameters).reply(0, {
|
||||||
.get(userInfoEndpointUrl.pathname)
|
|
||||||
.query(parameters)
|
|
||||||
.reply(200, {
|
|
||||||
unionid: 'this_is_an_arbitrary_wechat_union_id',
|
unionid: 'this_is_an_arbitrary_wechat_union_id',
|
||||||
headimgurl: 'https://github.com/images/error/octocat_happy.gif',
|
headimgurl: 'https://github.com/images/error/octocat_happy.gif',
|
||||||
nickname: 'wechat bot',
|
nickname: 'wechat bot',
|
||||||
|
@ -119,7 +116,7 @@ describe('getUserInfo', () => {
|
||||||
nock(userInfoEndpointUrl.origin)
|
nock(userInfoEndpointUrl.origin)
|
||||||
.get(userInfoEndpointUrl.pathname)
|
.get(userInfoEndpointUrl.pathname)
|
||||||
.query(parameters)
|
.query(parameters)
|
||||||
.reply(200, { errcode: 40_003, errmsg: 'invalid openid' });
|
.reply(0, { errcode: 40_003, errmsg: 'invalid openid' });
|
||||||
await expect(
|
await expect(
|
||||||
getUserInfo({ accessToken: 'accessToken', openid: 'openid' })
|
getUserInfo({ accessToken: 'accessToken', openid: 'openid' })
|
||||||
).rejects.toMatchError(new Error('invalid openid'));
|
).rejects.toMatchError(new Error('invalid openid'));
|
||||||
|
|
|
@ -120,6 +120,8 @@ export const getUserInfo: GetUserInfo = async (accessTokenObject) => {
|
||||||
// be the return value from getAccessToken per testing.
|
// be the return value from getAccessToken per testing.
|
||||||
// In another word, 'openid' is required but the response of getUserInfo is consistent as long as
|
// In another word, 'openid' is required but the response of getUserInfo is consistent as long as
|
||||||
// access_token is valid.
|
// access_token is valid.
|
||||||
|
// We are expecting to get 41009 'missing openid' response according to the developers doc, but the
|
||||||
|
// fact is that we still got 40001 'invalid credentials' response.
|
||||||
if (errcode === 40_001) {
|
if (errcode === 40_001) {
|
||||||
throw new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid);
|
throw new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue