diff options
author | Matthew Miller <matthew@millerti.me> | 2020-07-28 18:31:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-28 18:31:29 -0700 |
commit | 1e353ccac44dd30bd2fb2c372f8227e5e3a0c8ba (patch) | |
tree | d813c63b6e951f82502ac9c814d38ae3b1be1319 /packages/browser/src/methods | |
parent | bc9ad0f68fc49c4ac23cd22428248faa26d3f9b6 (diff) | |
parent | b65b247afd3b8312c81bc6745ba5c20288bbeb19 (diff) |
Merge pull request #40 from MasterKale/bugfix/utf8-challenge
bugfix/utf8-challenge
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r-- | packages/browser/src/methods/startAssertion.test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAssertion.test.ts index 669e8eb..e919d18 100644 --- a/packages/browser/src/methods/startAssertion.test.ts +++ b/packages/browser/src/methods/startAssertion.test.ts @@ -17,6 +17,7 @@ const mockClientDataJSON = 'mockClientDataJSON'; const mockSignature = 'mockSignature'; const mockUserHandle = 'mockUserHandle'; +// With ASCII challenge const goodOpts1: PublicKeyCredentialRequestOptionsJSON = { challenge: 'fizz', allowCredentials: [ @@ -29,6 +30,13 @@ const goodOpts1: PublicKeyCredentialRequestOptionsJSON = { timeout: 1, }; +// With UTF-8 challenge +const goodOpts2UTF8: PublicKeyCredentialRequestOptionsJSON = { + challenge: 'やれやれだぜ', + allowCredentials: [], + timeout: 1, +}; + beforeEach(() => { mockNavigatorGet.mockReset(); mockSupportsWebauthn.mockReset(); @@ -120,3 +128,29 @@ test('should throw error if assertion is cancelled for some reason', async done done(); }); + +test('should handle UTF-8 challenges', async done => { + mockSupportsWebauthn.mockReturnValue(true); + + // Stub out a response so the method won't throw + mockNavigatorGet.mockImplementation( + (): Promise<any> => { + return new Promise(resolve => { + resolve({ + response: {}, + getClientExtensionResults: () => ({}), + }); + }); + }, + ); + + await startAssertion(goodOpts2UTF8); + + const argsPublicKey = mockNavigatorGet.mock.calls[0][0].publicKey; + + expect(JSON.stringify(argsPublicKey.challenge)).toEqual( + '{"0":227,"1":130,"2":132,"3":227,"4":130,"5":140,"6":227,"7":130,"8":132,"9":227,"10":130,"11":140,"12":227,"13":129,"14":160,"15":227,"16":129,"17":156}', + ); + + done(); +}); |