diff options
author | Matthew Miller <matthew@millerti.me> | 2023-09-28 23:49:55 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2023-09-28 23:50:01 -0700 |
commit | 75e07cfbedab2ceb80ef7f39486e7aed5ef7975c (patch) | |
tree | 880df606defbf358fc74c70903e5d5cea92a798e /packages/browser/src/helpers/webAuthnAbortService.test.ts | |
parent | daf1104c9bb635ecdcff994b4b1d76f202d09eaa (diff) |
Add new method to manually cancel active ceremony
Diffstat (limited to 'packages/browser/src/helpers/webAuthnAbortService.test.ts')
-rw-r--r-- | packages/browser/src/helpers/webAuthnAbortService.test.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/webAuthnAbortService.test.ts b/packages/browser/src/helpers/webAuthnAbortService.test.ts index a538dff..fd2ca7a 100644 --- a/packages/browser/src/helpers/webAuthnAbortService.test.ts +++ b/packages/browser/src/helpers/webAuthnAbortService.test.ts @@ -25,3 +25,26 @@ test('should call abort() with AbortError on existing controller when creating a expect(abortReason).toBeInstanceOf(Error); expect(abortReason.name).toEqual('AbortError'); }); + +test('should cancel active WebAuthn ceremony when manually cancelled', () => { + // Populate `.controller` + WebauthnAbortService.createNewAbortSignal(); + + // Spy on the existing instance of AbortController + const abortSpy = jest.fn(); + // @ts-ignore: Ignore the fact that `controller` is private + WebauthnAbortService.controller.abort = abortSpy; + + // Cancel the in-flight ceremony, which should call `abort()` on the existing controller + WebauthnAbortService.cancelCeremony(); + expect(abortSpy).toHaveBeenCalledTimes(1); + + // Make sure we raise an AbortError so it can be detected correctly + const abortReason = abortSpy.mock.calls[0][0]; + expect(abortReason).toBeInstanceOf(Error); + expect(abortReason.name).toEqual('AbortError'); + + // Ensure that we don't set up a new AbortController because it's unnecessary to do so + // @ts-ignore: Ignore the fact that `controller` is private + expect(WebauthnAbortService.controller).toBeUndefined(); +}); |