Skip to content

Commit

Permalink
fix: update ExamplePayloadLoginStatic and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworris committed Oct 30, 2024
1 parent 999b3bc commit 94c3b34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
13 changes: 10 additions & 3 deletions libraries/js/src/mocks/payloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
};

Expand Down
2 changes: 1 addition & 1 deletion libraries/js/src/payloads.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ Issued At: 2024-10-10T18:40:37.344099626Z`,
userPublicKey: ExampleUserPublicKey,
payloads: [ExamplePayloadLoginStatic],
},
'testnet.frequencyaccess.com'
'your-app.com'
)
).resolves.toBeUndefined();
});
Expand Down
8 changes: 4 additions & 4 deletions libraries/js/src/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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'
);
});

Expand Down

0 comments on commit 94c3b34

Please sign in to comment.