diff options
author | Antoine Cormouls <contact.antoine.cormouls@gmail.com> | 2020-12-07 17:12:12 +0100 |
---|---|---|
committer | Antoine Cormouls <contact.antoine.cormouls@gmail.com> | 2020-12-07 17:12:12 +0100 |
commit | 87f337f82b1054c55456be834ae00f3ae9dd75f0 (patch) | |
tree | 89da7362d1da66d41628671bf1604a115f7be9a1 /packages/browser/src/methods | |
parent | 624de782a8bda1e313e839d114a44b79c359a3e5 (diff) |
review fxes
Diffstat (limited to 'packages/browser/src/methods')
-rw-r--r-- | packages/browser/src/methods/startAssertion.test.ts | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/packages/browser/src/methods/startAssertion.test.ts b/packages/browser/src/methods/startAssertion.test.ts index 0a8a16f..c74b88f 100644 --- a/packages/browser/src/methods/startAssertion.test.ts +++ b/packages/browser/src/methods/startAssertion.test.ts @@ -39,18 +39,6 @@ const goodOpts2UTF8: PublicKeyCredentialRequestOptionsJSON = { timeout: 1, }; -// Without allow credentials -const goodOpts3: PublicKeyCredentialRequestOptionsJSON = { - challenge: bufferToBase64URLString(toUint8Array('fizz')), - timeout: 1, -}; - -const goodOpts4: PublicKeyCredentialRequestOptionsJSON = { - challenge: bufferToBase64URLString(toUint8Array('fizz')), - timeout: 1, - allowCredentials: [], -}; - beforeEach(() => { mockNavigatorGet.mockReset(); mockSupportsWebauthn.mockReset(); @@ -99,14 +87,35 @@ test('should support optional allowCredential', async () => { }, ); - await startAssertion(goodOpts3); - let allowCredentials = mockNavigatorGet.mock.calls[0][0].allowCredentials; - expect(allowCredentials).toEqual(undefined); + await startAssertion({ + challenge: bufferToBase64URLString(toUint8Array('fizz')), + timeout: 1, + }); + + expect(mockNavigatorGet.mock.calls[0][0].allowCredentials).toEqual(undefined); +}); + +test('should convert allow allowCredential to undefined when empty', async () => { + mockSupportsWebauthn.mockReturnValue(true); + + // Stub out a response so the method won't throw + mockNavigatorGet.mockImplementation( + (): Promise<any> => { + return new Promise(resolve => { + resolve({ + response: {}, + getClientExtensionResults: () => ({}), + }); + }); + }, + ); - // Should convert empty array to undefined - await startAssertion(goodOpts4); - allowCredentials = mockNavigatorGet.mock.calls[1][0].allowCredentials; - expect(allowCredentials).toEqual(undefined); + await startAssertion({ + challenge: bufferToBase64URLString(toUint8Array('fizz')), + timeout: 1, + allowCredentials: [], + }); + expect(mockNavigatorGet.mock.calls[0][0].allowCredentials).toEqual(undefined); }); test('should return base64url-encoded response values', async done => { |