From 87f337f82b1054c55456be834ae00f3ae9dd75f0 Mon Sep 17 00:00:00 2001 From: Antoine Cormouls Date: Mon, 7 Dec 2020 17:12:12 +0100 Subject: review fxes --- .../browser/src/methods/startAssertion.test.ts | 47 +++++++++++++--------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'packages/browser/src/methods') 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 => { + 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 => { -- cgit v1.2.3