diff options
Diffstat (limited to 'packages/browser/src')
4 files changed, 25 insertions, 22 deletions
diff --git a/packages/browser/src/helpers/__jest__/generateCustomError.ts b/packages/browser/src/helpers/__jest__/generateCustomError.ts index f4b3250..7c018ca 100644 --- a/packages/browser/src/helpers/__jest__/generateCustomError.ts +++ b/packages/browser/src/helpers/__jest__/generateCustomError.ts @@ -1,8 +1,8 @@ /** * Create "custom errors" to help emulate WebAuthn API errors -*/ + */ type WebAuthnErrorName = - 'AbortError' + | 'AbortError' | 'ConstraintError' | 'InvalidStateError' | 'NotAllowedError' diff --git a/packages/browser/src/helpers/identifyRegistrationError.ts b/packages/browser/src/helpers/identifyRegistrationError.ts index 5b560e1..8976602 100644 --- a/packages/browser/src/helpers/identifyRegistrationError.ts +++ b/packages/browser/src/helpers/identifyRegistrationError.ts @@ -27,13 +27,13 @@ export function identifyRegistrationError({ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4) return new WebAuthnError( 'Discoverable credentials were required but no available authenticator supported it', - 'ConstraintError' + 'ConstraintError', ); } else if (publicKey.authenticatorSelection?.userVerification === 'required') { // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5) return new WebAuthnError( 'User verification was required but no available authenticator supported it', - 'ConstraintError' + 'ConstraintError', ); } } else if (error.name === 'InvalidStateError') { @@ -44,7 +44,8 @@ export function identifyRegistrationError({ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20) // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 21) return new WebAuthnError( - 'User clicked cancel, or the registration ceremony timed out', 'NotAllowedError' + 'User clicked cancel, or the registration ceremony timed out', + 'NotAllowedError', ); } else if (error.name === 'NotSupportedError') { const validPubKeyCredParams = publicKey.pubKeyCredParams.filter( @@ -55,14 +56,14 @@ export function identifyRegistrationError({ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10) return new WebAuthnError( 'No entry in pubKeyCredParams was of type "public-key"', - 'NotSupportedError' + 'NotSupportedError', ); } // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2) return new WebAuthnError( 'No available authenticator supported any of the specified pubKeyCredParams algorithms', - 'NotSupportedError' + 'NotSupportedError', ); } else if (error.name === 'SecurityError') { const effectiveDomain = window.location.hostname; @@ -73,7 +74,7 @@ export function identifyRegistrationError({ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8) return new WebAuthnError( `The RP ID "${publicKey.rp.id}" is invalid for this domain`, - 'SecurityError' + 'SecurityError', ); } } else if (error.name === 'TypeError') { @@ -86,7 +87,7 @@ export function identifyRegistrationError({ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8) return new WebAuthnError( 'The authenticator was unable to process the specified options, or could not create a new credential', - 'UnknownError' + 'UnknownError', ); } diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts index e6ac9c7..31ace90 100644 --- a/packages/browser/src/methods/startAuthentication.test.ts +++ b/packages/browser/src/methods/startAuthentication.test.ts @@ -214,15 +214,16 @@ test('should support "cable" transport', async () => { allowCredentials: [ { ...goodOpts1.allowCredentials![0], - transports: ["cable"], + transports: ['cable'], }, - ] + ], }; await startAuthentication(opts); - expect(mockNavigatorGet.mock.calls[0][0].publicKey.allowCredentials[0].transports[0]) - .toEqual("cable"); + expect(mockNavigatorGet.mock.calls[0][0].publicKey.allowCredentials[0].transports[0]).toEqual( + 'cable', + ); }); test('should cancel an existing call when executed again', async () => { @@ -242,9 +243,9 @@ test('should set up autofill a.k.a. Conditional UI', async () => { allowCredentials: [ { ...goodOpts1.allowCredentials![0], - transports: ["cable"], + transports: ['cable'], }, - ] + ], }; document.body.innerHTML = ` <form> diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts index 1ca9e62..381830e 100644 --- a/packages/browser/src/methods/startRegistration.test.ts +++ b/packages/browser/src/methods/startRegistration.test.ts @@ -106,7 +106,7 @@ test('should return base64url-encoded response values', async () => { expect(response.response.clientDataJSON).toEqual('bW9ja0NsaWU'); }); -test('should throw error if WebAuthn isn\'t supported', async () => { +test("should throw error if WebAuthn isn't supported", async () => { mockSupportsWebauthn.mockReturnValue(false); await expect(startRegistration(goodOpts1)).rejects.toThrow( @@ -183,15 +183,16 @@ test('should support "cable" transport in excludeCredentials', async () => { excludeCredentials: [ { ...goodOpts1.excludeCredentials![0], - transports: ["cable"], + transports: ['cable'], }, - ] + ], }; await startRegistration(opts); - expect(mockNavigatorCreate.mock.calls[0][0].publicKey.excludeCredentials[0].transports[0]) - .toEqual("cable"); + expect( + mockNavigatorCreate.mock.calls[0][0].publicKey.excludeCredentials[0].transports[0], + ).toEqual('cable'); }); test('should return "cable" transport from response', async () => { @@ -201,7 +202,7 @@ test('should return "cable" transport from response', async () => { response: { attestationObject: Buffer.from(mockAttestationObject, 'ascii'), clientDataJSON: Buffer.from(mockClientDataJSON, 'ascii'), - getTransports: () => (["cable"]), + getTransports: () => ['cable'], }, getClientExtensionResults: () => ({}), type: 'webauthn.create', @@ -209,7 +210,7 @@ test('should return "cable" transport from response', async () => { const response = await startRegistration(goodOpts1); - expect(response.transports).toEqual(["cable"]); + expect(response.transports).toEqual(['cable']); }); test('should cancel an existing call when executed again', async () => { |