-
Notifications
You must be signed in to change notification settings - Fork 460
Client handshake tests #2265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Client handshake tests #2265
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c34bc13
Test suite start
colinclerk f452b26
feat(backend,nextjs,utils): Fix jest
nikosdouvlis 47b4045
first test
colinclerk e2855ae
Fix bug in jwks cache for multiple runtime keys
colinclerk 58d1a7a
Add all the tests, including many failing
colinclerk ebd429b
Add all the tests, including many failing
colinclerk 4c0f2e0
fix(shared): Correctly construct proxy URL
brkalow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // @ts-ignore ignore types | ||
| import * as jwt from 'jsonwebtoken'; | ||
| // @ts-ignore ignore types | ||
| import * as uuid from 'uuid'; | ||
|
|
||
| const rsaPairs = { | ||
| a: { | ||
| private: `-----BEGIN RSA PRIVATE KEY----- | ||
| MIIEowIBAAKCAQEAlRVgJiQJ0nfuctIVSLnFJlAC76YPKly8Y5xrY36ADo472G1w | ||
| FpeiykQRyDdGOwrkJBEVmLpAybV4yTgQFpQ0A4YzeDlKKkOxBhCmuANZXluAm2MW | ||
| 3ehNAm0svievMfKtG6UjjYz6v67U9Om/oMt1ehsOmR8MrDYvs3Wy+dxYpZaxyn6w | ||
| ajL7GkICHxc8cGsI/MBZr9jKtKyzFY++r8TQKAJwn9TcSQljRivomz1wQvjtdLnq | ||
| ZSLP3BFQB7e7DuM6SBsodIHhk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ltxq | ||
| kiivGXNxiUNpQNeuJHxnbkYenJ1qDUhoNJFNhDmbBFEPReh2hN5ekq+xSmi+3qKv | ||
| AlxiED6yZdqecdoyANoGrGcWMsYH5d5DAvxmnJkMRJHjBMiovlLK7KIOZz8oY4RB | ||
| aFMBAoGBAJ8UoGHwz7AdOLAldGY3c0HzaH1NaGrZoocSH19XI3ZYr8Qvl2XUww9G | ||
| UC1OG4e2PtZ8PINQGIYPacUaab5Yg1tOmxBoAx4gUkpgyjtSm2ZPd4EUVOdylU3E | ||
| aFa08+0FF7mqqJTgz5XlvHMrCcUTsJ9u+e05rr1G1PHsATuuMD9m | ||
| -----END RSA PRIVATE KEY-----`, | ||
| public: { | ||
| kty: 'RSA', | ||
| n: 'lRVgJiQJ0nfuctIVSLnFJlAC76YPKly8Y5xrY36ADo472G1wFpeiykQRyDdGOwrkJBEVmLpAybV4yTgQFpQ0A4YzeDlKKkOxBhCmuANZXluAm2MW3ehNAm0svievMfKtG6UjjYz6v67U9Om_oMt1ehsOmR8MrDYvs3Wy-dxYpZaxyn6wajL7GkICHxc8cGsI_MBZr9jKtKyzFY--r8TQKAJwn9TcSQljRivomz1wQvjtdLnqZSLP3BFQB7e7DuM6SBsodIHhkVEVK2EaGVLOY-ifAITt7MqEcvast14AP0rICBSqvbQQjZuwLgIrlJgqvJ4YBRfIaIx_qQzs0-eFtw', | ||
| e: 'AQAB', | ||
| }, | ||
| }, | ||
| b: { | ||
| private: `-----BEGIN RSA PRIVATE KEY----- | ||
| MIIEowIBAAKCAQEAt9zSYl1hFhFKXvv8uJcT2X15iOqi1mTtxqVxNDnzPQSj1RSa | ||
| Jryjhkzpyd16c+PDo+FFtMgZTUv6Z2hr5QYMuAjlsM+apHmfE8MRMQRQHXNF0+sE | ||
| Bd1241W0mL7fId2ZChaGgufFOGFl2Obby56FH4Z86lCFi7Z4Ow7TBSpVSN598OKH | ||
| oVKwbYOVPKtmWBar0JeCPVpng4Ntx7kvuHGdFSoJ8z8+Uy5ybLl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3vW/5HMHJ+QKBgQCNema7pq3Ulq5a2n2vgp9GgJn5RXW+lGOG1Mbg | ||
| vmJMlv1qpAUJ5bmUqdBYWlEKkSxzIs4JifUwC/jXEcVyfS/GyommVBkzMEg672U9 | ||
| pyEe34Xs4oFpHYlOX3cprnQeV+WOSJFqHrKNZuxgD6ik3MmjxhV3GXXugYzQNFWH | ||
| NRr6IwKBgH9aN5mY4fcVL76mMEVZ5BIHE+JpPMZ6OOamOHAiA5jrWRX4aRMICq3t | ||
| cKVfcj/M4dyBuRV5EW1y1m2QhRECFPSKpScykpD9nyCb+XqbMSLH+f+j1BGfLKWl | ||
| t5o8u/dlwJ1fGGday48gs/hA4V/F9zDjecNkYWUB/wUwVStqZljn | ||
| -----END RSA PRIVATE KEY-----`, | ||
| public: { | ||
| kty: 'RSA', | ||
| n: 't9zSYl1hFhFKXvv8uJcT2X15iOqi1mTtxqVxNDnzPQSj1RSaJryjhkzpyd16c-PDo-FFtMgZTUv6Z2hr5QYMuAjlsM-apHmfE8MRMQRQHXNF0-sEBd1241W0mL7fId2ZChaGgufFOGFl2Obby56FH4Z86lCFi7Z4Ow7TBSpVSN598OKHoVKwbYOVPKtmWBar0JeCPVpng4Ntx7kvuHGdFSoJ8z8-Uy5ybLlk1qSlQ5lsymfWhxs0C9j7_x_h24n9jUbq51pzx2URcsEi0Wbuv26Ba0Q4v1ySl0I6IM5Xemwrzjo1H6kz6IYldqPtTwkzhJSnJvJFzKJZn3hH9N-rGw', | ||
| e: 'AQAB', | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const allConfigs: any = []; | ||
|
|
||
| export function generateConfig({ mode, matchedKeys = true }: { mode: 'test' | 'live'; matchedKeys?: boolean }) { | ||
| const ins_id = uuid.v4(); | ||
| const pkHost = `clerk.${uuid.v4()}.com`; | ||
| const pk = `pk_${mode}_${btoa(`${pkHost}$`)}`; | ||
| const sk = `sk_${mode}_${uuid.v4()}`; | ||
| const rsa = matchedKeys | ||
| ? rsaPairs.a | ||
| : { | ||
| private: rsaPairs.a.private, | ||
| public: rsaPairs.b.public, | ||
| }; | ||
| const jwks = { | ||
| keys: [ | ||
| { | ||
| ...rsa.public, | ||
| kid: ins_id, | ||
| use: 'sig', | ||
| alg: 'RS256', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| type Claims = { | ||
| sub: string; | ||
| iat: number; | ||
| exp: number; | ||
| nbf: number; | ||
| }; | ||
| const generateToken = ({ state }: { state: 'active' | 'expired' | 'early' }) => { | ||
| let claims = { sub: 'user_12345' } as Claims; | ||
|
|
||
| const now = Math.floor(Date.now() / 1000); | ||
| if (state === 'active') { | ||
| claims.iat = now; | ||
| claims.nbf = now - 10; | ||
| claims.exp = now + 60; | ||
| } else if (state === 'expired') { | ||
| claims.iat = now - 600; | ||
| claims.nbf = now - 10 - 600; | ||
| claims.exp = now + 60 - 600; | ||
| } else if (state === 'early') { | ||
| claims.iat = now + 600; | ||
| claims.nbf = now - 10 + 600; | ||
| claims.exp = now + 60 + 600; | ||
| } | ||
| return { | ||
| token: jwt.sign(claims, rsa.private, { | ||
| algorithm: 'RS256', | ||
| header: { kid: ins_id }, | ||
| }), | ||
| claims, | ||
| }; | ||
| }; | ||
| const config = Object.freeze({ | ||
| pk, | ||
| sk, | ||
| generateToken, | ||
| jwks, | ||
| pkHost, | ||
| }); | ||
| allConfigs.push(config); | ||
| return config; | ||
| } | ||
|
|
||
| export function getJwksFromSecretKey(sk: any) { | ||
| return allConfigs.find((x: any) => x.sk === sk)?.jwks; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
| module.exports = { | ||
| extensionsToTreatAsEsm: ['.ts'], | ||
| testRegex: ['handshake.test.tsx?$'], | ||
| moduleNameMapper: { | ||
| '^(\\.{1,2}/.*)\\.js$': '$1', | ||
| }, | ||
| transform: { | ||
| // '^.+\\.[tj]sx?$' to process js/ts with `ts-jest` | ||
| // '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest` | ||
| '^.+\\.tsx?$': [ | ||
| 'ts-jest', | ||
| { | ||
| diagnostics: false, | ||
| useESM: true, | ||
| }, | ||
| ], | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this change will not work for tests running in our CICD and will break the integration tests. As far as i know we don't depend on
yalcin the integration tests.cc: @nikosdouvlis