Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #145 from logto-io/renovate/logto-standard-toolkit…
Browse files Browse the repository at this point in the history
…-monorepo-packages

fix(deps): update dependency @logto/connector-kit to v1.0.0-rc.3
  • Loading branch information
gao-sun authored Mar 19, 2023
2 parents b2446de + 4ec0889 commit 17932ff
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 287 deletions.
34 changes: 34 additions & 0 deletions .changeset/nice-walls-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"@logto/connector-mock-standard-email": patch
"@logto/connector-sendgrid-email": patch
"@logto/connector-logto-email": patch
"@logto/connector-tencent-sms": patch
"@logto/connector-aliyun-sms": patch
"@logto/connector-mock-email": patch
"@logto/connector-twilio-sms": patch
"@logto/connector-aliyun-dm": patch
"@logto/connector-logto-sms": patch
"@logto/connector-mock-sms": patch
"@logto/connector-aws-ses": patch
"@logto/connector-azuread": patch
"@logto/connector-smtp": patch
"@logto/connector-alipay-native": patch
"@logto/connector-alipay-web": patch
"@logto/connector-apple": patch
"@logto/connector-discord": patch
"@logto/connector-facebook": patch
"@logto/connector-feishu-web": patch
"@logto/connector-github": patch
"@logto/connector-google": patch
"@logto/connector-kakao": patch
"@logto/connector-logto-social-demo": patch
"@logto/connector-mock-social": patch
"@logto/connector-naver": patch
"@logto/connector-oauth": patch
"@logto/connector-oidc": patch
"@logto/connector-saml": patch
"@logto/connector-wechat-native": patch
"@logto/connector-wechat-web": patch
---

bump connector-kit version
38 changes: 9 additions & 29 deletions packages/connector-alipay-native/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe('getAccessToken', () => {
sign: '<signature>',
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({}, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.General, '{}'));
await expect(connector.getUserInfo({}, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.General, '{}')
);
});

it('should throw when accessToken is empty', async () => {
Expand Down Expand Up @@ -155,10 +155,7 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
const connector = await createConnector({ getConfig });
const { id, name, avatar } = await connector.getUserInfo({ auth_code: 'code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
});
const { id, name, avatar } = await connector.getUserInfo({ auth_code: 'code' }, jest.fn());
expect(id).toEqual('2088000000000000');
expect(name).toEqual('PlayboyEric');
expect(avatar).toEqual('https://www.alipay.com/xxx.jpg');
Expand All @@ -179,10 +176,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid, 'Invalid auth token')
);
Expand All @@ -203,10 +197,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAuthCodeInvalid, 'Invalid auth code')
);
Expand All @@ -227,10 +218,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.General, {
errorDescription: 'Invalid parameter',
Expand All @@ -257,21 +245,13 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.InvalidResponse));
});

it('should throw with other request errors', async () => {
nock(alipayEndpointUrl.origin).post(alipayEndpointUrl.pathname).query(true).reply(500);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
).rejects.toThrow();
await expect(connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())).rejects.toThrow();
});
});
36 changes: 11 additions & 25 deletions packages/connector-alipay-web/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,17 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
const connector = await createConnector({ getConfig });
const { id, name, avatar } = await connector.getUserInfo({ auth_code: 'code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
});
const { id, name, avatar } = await connector.getUserInfo({ auth_code: 'code' }, jest.fn());
expect(id).toEqual('2088000000000000');
expect(name).toEqual('PlayboyEric');
expect(avatar).toEqual('https://www.alipay.com/xxx.jpg');
});

it('throw General error if auth_code not provided in input', async () => {
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({}, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.InvalidResponse, '{}'));
await expect(connector.getUserInfo({}, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.InvalidResponse, '{}')
);
});

it('should throw SocialAccessTokenInvalid with code 20001', async () => {
Expand All @@ -172,10 +169,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid, 'Invalid auth token')
);
Expand All @@ -196,10 +190,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAuthCodeInvalid, 'Invalid auth code')
);
Expand All @@ -220,10 +211,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ auth_code: 'wrong_code' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.General, {
errorDescription: 'Invalid parameter',
Expand All @@ -249,16 +237,14 @@ describe('getUserInfo', () => {
sign: '<signature>',
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'code' }, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.InvalidResponse));
await expect(connector.getUserInfo({ auth_code: 'code' }, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.InvalidResponse)
);
});

it('should throw with other request errors', async () => {
nock(alipayEndpointUrl.origin).post(alipayEndpointUrl.pathname).query(true).reply(500);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ auth_code: 'code' }, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toThrow();
await expect(connector.getUserInfo({ auth_code: 'code' }, jest.fn())).rejects.toThrow();
});
});
23 changes: 10 additions & 13 deletions packages/connector-apple/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,15 @@ describe('getUserInfo', () => {
const mockJwtVerify = jwtVerify;
mockJwtVerify.mockImplementationOnce(() => ({ payload: { sub: userId } }));
const connector = await createConnector({ getConfig });
const userInfo = await connector.getUserInfo({ id_token: 'idToken' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
});
const userInfo = await connector.getUserInfo({ id_token: 'idToken' }, jest.fn());
expect(userInfo).toEqual({ id: userId });
});

it('should throw if id token is missing', async () => {
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({}, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.General, '{}'));
await expect(connector.getUserInfo({}, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.General, '{}')
);
});

it('should throw if verify id token failed', async () => {
Expand All @@ -78,9 +75,9 @@ describe('getUserInfo', () => {
throw new Error('jwtVerify failed');
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ id_token: 'id_token' }, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.SocialIdTokenInvalid));
await expect(connector.getUserInfo({ id_token: 'id_token' }, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialIdTokenInvalid)
);
});

it('should throw if the id token payload does not contains sub', async () => {
Expand All @@ -89,8 +86,8 @@ describe('getUserInfo', () => {
payload: { iat: 123_456 },
}));
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ id_token: 'id_token' }, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.SocialIdTokenInvalid));
await expect(connector.getUserInfo({ id_token: 'id_token' }, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialIdTokenInvalid)
);
});
});
13 changes: 3 additions & 10 deletions packages/connector-discord/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ describe('Discord connector', () => {
code: 'code',
redirectUri: 'dummyRedirectUri',
},
jest.fn(),
{ set: jest.fn(), get: jest.fn() }
jest.fn()
);
expect(socialUserInfo).toMatchObject({
id: '1234567890',
Expand All @@ -113,21 +112,15 @@ describe('Discord connector', () => {
nock(userInfoEndpoint).get('').reply(401);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ code: 'code', redirectUri: 'dummyRedirectUri' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ code: 'code', redirectUri: 'dummyRedirectUri' }, jest.fn())
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid));
});

it('throws unrecognized error', async () => {
nock(userInfoEndpoint).get('').reply(500);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ code: 'code', redirectUri: 'dummyRedirectUri' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ code: 'code', redirectUri: 'dummyRedirectUri' }, jest.fn())
).rejects.toThrow();
});
});
Expand Down
19 changes: 5 additions & 14 deletions packages/connector-facebook/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ describe('Facebook connector', () => {
code,
redirectUri: dummyRedirectUri,
},
jest.fn(),
{ set: jest.fn(), get: jest.fn() }
jest.fn()
);
expect(socialUserInfo).toMatchObject({
id: '1234567890',
Expand All @@ -144,10 +143,7 @@ describe('Facebook connector', () => {
nock(userInfoEndpoint).get('').query({ fields }).reply(400);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ code, redirectUri: dummyRedirectUri }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ code, redirectUri: dummyRedirectUri }, jest.fn())
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid));
});

Expand All @@ -171,8 +167,7 @@ describe('Facebook connector', () => {
error_description: 'Permissions error.',
error_reason: 'user_denied',
},
jest.fn(),
{ set: jest.fn(), get: jest.fn() }
jest.fn()
)
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.AuthorizationFailed, 'Permissions error.')
Expand All @@ -199,8 +194,7 @@ describe('Facebook connector', () => {
error_description: 'General error encountered.',
error_reason: 'user_denied',
},
jest.fn(),
{ set: jest.fn(), get: jest.fn() }
jest.fn()
)
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.General, {
Expand All @@ -216,10 +210,7 @@ describe('Facebook connector', () => {
nock(userInfoEndpoint).get('').reply(500);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ code, redirectUri: dummyRedirectUri }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ code, redirectUri: dummyRedirectUri }, jest.fn())
).rejects.toThrow();
});
});
Expand Down
25 changes: 7 additions & 18 deletions packages/connector-feishu-web/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ describe('getUserInfo', () => {
code: 'code',
redirectUri: 'http://localhost:3000',
},
jest.fn(),
{ set: jest.fn(), get: jest.fn() }
jest.fn()
);
expect(id).toEqual('ou_caecc734c2e3328a62489fe0648c4b98779515d3');
expect(name).toEqual('李雷');
Expand All @@ -145,9 +144,9 @@ describe('getUserInfo', () => {

it('throw General error if code not provided in input', async () => {
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({}, jest.fn(), { set: jest.fn(), get: jest.fn() })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.InvalidResponse, '{}'));
await expect(connector.getUserInfo({}, jest.fn())).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.InvalidResponse, '{}')
);
});

it('should throw SocialAccessTokenInvalid with code invalid_token', async () => {
Expand All @@ -157,11 +156,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo(
{ code: 'error_code', redirectUri: 'http://localhost:3000' },
jest.fn(),
{ set: jest.fn(), get: jest.fn() }
)
connector.getUserInfo({ code: 'error_code', redirectUri: 'http://localhost:3000' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid, 'invalid access token')
);
Expand All @@ -173,10 +168,7 @@ describe('getUserInfo', () => {
});
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ code: 'code', redirectUri: 'http://localhost:3000' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ code: 'code', redirectUri: 'http://localhost:3000' }, jest.fn())
).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.InvalidResponse, 'invalid user response')
);
Expand All @@ -186,10 +178,7 @@ describe('getUserInfo', () => {
nock(userInfoUrl.origin).get(userInfoUrl.pathname).query(true).reply(500);
const connector = await createConnector({ getConfig });
await expect(
connector.getUserInfo({ code: 'code', redirectUri: 'http://localhost:3000' }, jest.fn(), {
set: jest.fn(),
get: jest.fn(),
})
connector.getUserInfo({ code: 'code', redirectUri: 'http://localhost:3000' }, jest.fn())
).rejects.toThrow();
});
});
Loading

0 comments on commit 17932ff

Please sign in to comment.