diff options
Diffstat (limited to 'packages/server/src/authentication/generateAuthenticationOptions.test.ts')
-rw-r--r-- | packages/server/src/authentication/generateAuthenticationOptions.test.ts | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/packages/server/src/authentication/generateAuthenticationOptions.test.ts b/packages/server/src/authentication/generateAuthenticationOptions.test.ts index 78c6473..9048cf5 100644 --- a/packages/server/src/authentication/generateAuthenticationOptions.test.ts +++ b/packages/server/src/authentication/generateAuthenticationOptions.test.ts @@ -1,10 +1,13 @@ jest.mock('../helpers/generateChallenge'); +import { isoBase64URL } from '../helpers/iso'; + import { generateAuthenticationOptions } from './generateAuthenticationOptions'; -test('should generate credential request options suitable for sending via JSON', () => { - const challenge = 'totallyrandomvalue'; +const challengeString = 'dG90YWxseXJhbmRvbXZhbHVl'; +const challengeBuffer = isoBase64URL.toBuffer(challengeString); +test('should generate credential request options suitable for sending via JSON', () => { const options = generateAuthenticationOptions({ allowCredentials: [ { @@ -19,12 +22,12 @@ test('should generate credential request options suitable for sending via JSON', }, ], timeout: 1, - challenge, + challenge: challengeBuffer, }); expect(options).toEqual({ // base64url-encoded - challenge: 'dG90YWxseXJhbmRvbXZhbHVl', + challenge: challengeString, allowCredentials: [ { id: 'MTIzNA', @@ -43,7 +46,7 @@ test('should generate credential request options suitable for sending via JSON', test('defaults to 60 seconds if no timeout is specified', () => { const options = generateAuthenticationOptions({ - challenge: 'totallyrandomvalue', + challenge: challengeBuffer, allowCredentials: [ { id: Buffer.from('1234', 'ascii'), type: 'public-key' }, { id: Buffer.from('5678', 'ascii'), type: 'public-key' }, @@ -55,7 +58,7 @@ test('defaults to 60 seconds if no timeout is specified', () => { test('should not set userVerification if not specified', () => { const options = generateAuthenticationOptions({ - challenge: 'totallyrandomvalue', + challenge: challengeBuffer, allowCredentials: [ { id: Buffer.from('1234', 'ascii'), type: 'public-key' }, { id: Buffer.from('5678', 'ascii'), type: 'public-key' }, @@ -86,7 +89,7 @@ test('should generate without params', () => { test('should set userVerification if specified', () => { const options = generateAuthenticationOptions({ - challenge: 'totallyrandomvalue', + challenge: challengeBuffer, allowCredentials: [ { id: Buffer.from('1234', 'ascii'), type: 'public-key' }, { id: Buffer.from('5678', 'ascii'), type: 'public-key' }, @@ -99,7 +102,7 @@ test('should set userVerification if specified', () => { test('should set extensions if specified', () => { const options = generateAuthenticationOptions({ - challenge: 'totallyrandomvalue', + challenge: challengeBuffer, allowCredentials: [ { id: Buffer.from('1234', 'ascii'), type: 'public-key' }, { id: Buffer.from('5678', 'ascii'), type: 'public-key' }, |