diff options
author | Matthew Miller <matthew@millerti.me> | 2022-04-11 20:56:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-11 20:56:47 -0700 |
commit | 338f0543ac7b5844116d5ec081cc964232de3ae8 (patch) | |
tree | 9e412c0fa8b21efd92bcf89f06416be96c607a9e /packages/browser/src/methods/startAuthentication.test.ts | |
parent | 575175622b58eedd0fbd6a239cece731c494f4ea (diff) | |
parent | e6a2e0243d3f6e5ec000c39d5eb9e2758bb236d0 (diff) |
Merge pull request #194 from MasterKale/fix/browser-tests
fix/browser-tests
Diffstat (limited to 'packages/browser/src/methods/startAuthentication.test.ts')
-rw-r--r-- | packages/browser/src/methods/startAuthentication.test.ts | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts index 4be0ad6..848e9db 100644 --- a/packages/browser/src/methods/startAuthentication.test.ts +++ b/packages/browser/src/methods/startAuthentication.test.ts @@ -9,6 +9,7 @@ import { browserSupportsWebauthn } from '../helpers/browserSupportsWebauthn'; import utf8StringToBuffer from '../helpers/utf8StringToBuffer'; import bufferToBase64URLString from '../helpers/bufferToBase64URLString'; import { WebAuthnError } from '../helpers/structs'; +import { generateCustomError } from '../helpers/__jest__/generateCustomError'; import startAuthentication from './startAuthentication'; @@ -203,6 +204,8 @@ test('should include extension results when no extensions specified', async () = describe('WebAuthnError', () => { describe('AbortError', () => { + const AbortError = generateCustomError('AbortError'); + /** * We can't actually test this because nothing in startAuthentication() propagates the abort * signal. But if you invoked WebAuthn via this and then manually sent an abort signal I guess @@ -211,7 +214,7 @@ describe('WebAuthnError', () => { * As a matter of fact I couldn't actually get any browser to respect the abort signal... */ test.skip('should identify abort signal', async () => { - mockNavigatorGet.mockRejectedValueOnce(new AbortError()); + mockNavigatorGet.mockRejectedValueOnce(AbortError); const rejected = await expect(startAuthentication(goodOpts1)).rejects; rejected.toThrow(WebAuthnError); @@ -221,8 +224,10 @@ describe('WebAuthnError', () => { }); describe('NotAllowedError', () => { + const NotAllowedError = generateCustomError('NotAllowedError'); + test('should identify unrecognized allowed credentials', async () => { - mockNavigatorGet.mockRejectedValueOnce(new NotAllowedError()); + mockNavigatorGet.mockRejectedValueOnce(NotAllowedError); const rejected = await expect(startAuthentication(goodOpts1)).rejects; rejected.toThrow(WebAuthnError); @@ -231,7 +236,7 @@ describe('WebAuthnError', () => { }); test('should identify cancellation or timeout', async () => { - mockNavigatorGet.mockRejectedValueOnce(new NotAllowedError()); + mockNavigatorGet.mockRejectedValueOnce(NotAllowedError); const opts = { ...goodOpts1, @@ -247,6 +252,8 @@ describe('WebAuthnError', () => { }); describe('SecurityError', () => { + const SecurityError = generateCustomError('SecurityError'); + let _originalHostName: string; beforeEach(() => { @@ -260,7 +267,7 @@ describe('WebAuthnError', () => { test('should identify invalid domain', async () => { window.location.hostname = '1.2.3.4'; - mockNavigatorGet.mockRejectedValueOnce(new SecurityError()); + mockNavigatorGet.mockRejectedValueOnce(SecurityError); const rejected = await expect(startAuthentication(goodOpts1)).rejects; rejected.toThrowError(WebAuthnError); @@ -272,7 +279,7 @@ describe('WebAuthnError', () => { test('should identify invalid RP ID', async () => { window.location.hostname = 'simplewebauthn.com'; - mockNavigatorGet.mockRejectedValueOnce(new SecurityError()); + mockNavigatorGet.mockRejectedValueOnce(SecurityError); const rejected = await expect(startAuthentication(goodOpts1)).rejects; rejected.toThrowError(WebAuthnError); @@ -283,8 +290,10 @@ describe('WebAuthnError', () => { }); describe('UnknownError', () => { + const UnknownError = generateCustomError('UnknownError'); + test('should identify potential authenticator issues', async () => { - mockNavigatorGet.mockRejectedValueOnce(new UnknownError()); + mockNavigatorGet.mockRejectedValueOnce(UnknownError); const rejected = await expect(startAuthentication(goodOpts1)).rejects; rejected.toThrow(WebAuthnError); |