From 94c3b3430a488fa4745f0e2ecb26aba400f446c3 Mon Sep 17 00:00:00 2001 From: Matthew Orris <1466844+mattheworris@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:23:19 -0600 Subject: [PATCH] fix: update ExamplePayloadLoginStatic and test cases --- libraries/js/src/mocks/payloads.ts | 13 ++++++++++--- libraries/js/src/payloads.test.ts | 2 +- libraries/js/src/response.test.ts | 8 ++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libraries/js/src/mocks/payloads.ts b/libraries/js/src/mocks/payloads.ts index ebc86dc..1ab5c87 100644 --- a/libraries/js/src/mocks/payloads.ts +++ b/libraries/js/src/mocks/payloads.ts @@ -73,18 +73,25 @@ export const ExamplePayloadLoginExpired = (): SiwfResponsePayloadLogin => ({ }, }); -// TODO: This test case is broken because now the domain is extracted from the URL, so isn't localhost export const ExamplePayloadLoginStatic: SiwfResponsePayloadLogin = { signature: { algo: 'SR25519', encoding: 'base16', encodedValue: - '0x84a4e03344b07d64087ebdf47b2c8c679aa7de78179689988992609f1b83c34f6086c7de99ef41c5325cce64d148624e716c605d355f22d1281f6d23f546f584', + '0xe261698297111834e68b4152bf1f89819e886b6528f6fff45715f7781d0f1e7dc4007ccfed1e85b8c603c0fea2f7abf22bfe6336869ad21f11a09a114452c680', }, type: 'login', payload: { message: - 'localhost wants you to sign in with your Frequency account:\nf6akufkq9Lex6rT8RCEDRuoZQRgo5pWiRzeo81nmKNGWGNJdJ\n\n\n\nURI: https://testnet.frequencyaccess.com/signin/confirm\nNonce: N6rLwqyz34oUxJEXJ\nIssued At: 2024-03-05T23:18:03.041Z\nExpiration Time: 2060-03-05T23:23:03.041Z', + 'your-app.com wants you to sign in with your Frequency account:\n' + + 'f6akufkq9Lex6rT8RCEDRuoZQRgo5pWiRzeo81nmKNGWGNJdJ\n' + + '\n' + + '\n' + + '\n' + + 'URI: https://your-app.com/signin/callback\n' + + 'Nonce: N6rLwqyz34oUxJEXJ\n' + + 'Issued At: 2024-10-29T19:17:27.077Z\n' + + 'Expiration Time: 2060-03-05T23:23:03.041Z', }, }; diff --git a/libraries/js/src/payloads.test.ts b/libraries/js/src/payloads.test.ts index 32f36e2..1e9dcd2 100644 --- a/libraries/js/src/payloads.test.ts +++ b/libraries/js/src/payloads.test.ts @@ -216,7 +216,7 @@ Issued At: 2024-10-10T18:40:37.344099626Z`, userPublicKey: ExampleUserPublicKey, payloads: [ExamplePayloadLoginStatic], }, - 'testnet.frequencyaccess.com' + 'your-app.com' ) ).resolves.toBeUndefined(); }); diff --git a/libraries/js/src/response.test.ts b/libraries/js/src/response.test.ts index 32af5b9..cd9c7c4 100644 --- a/libraries/js/src/response.test.ts +++ b/libraries/js/src/response.test.ts @@ -20,7 +20,7 @@ describe('getLoginResult', () => { } as any); await expect( - getLoginResult('fakeAuthCode', { loginMsgUri: 'testnet.frequencyaccess.com' }) + getLoginResult('fakeAuthCode', { loginMsgUri: 'your-app.com' }) ).to.resolves.toMatchObject(example); }); @@ -65,13 +65,13 @@ describe('validateSiwfResponse', () => { it('can handle a JSON strigified base64url encoded value', async () => { const example = await ExampleLogin(); await expect( - validateSiwfResponse(base64url(JSON.stringify(example)), 'testnet.frequencyaccess.com') + validateSiwfResponse(base64url(JSON.stringify(example)), 'your-app.com') ).to.resolves.toMatchObject(example); }); it('can handle an object value', async () => { const example = await ExampleLogin(); - await expect(validateSiwfResponse(example, 'testnet.frequencyaccess.com')).to.resolves.toMatchObject(example); + await expect(validateSiwfResponse(example, 'your-app.com')).to.resolves.toMatchObject(example); }); it('throws on a null value', async () => { @@ -90,7 +90,7 @@ describe('validateSiwfResponse', () => { it('throws on a bad domain', async () => { const example = await ExampleLogin(); await expect(validateSiwfResponse(base64url(JSON.stringify(example)), 'bad.example.xyz')).to.rejects.toThrowError( - 'Message does not match expected domain. Domain: testnet.frequencyaccess.com Expected: bad.example.xyz' + 'Message does not match expected domain. Domain: your-app.com Expected: bad.example.xyz' ); });