diff options
author | Matthew Miller <matthew@millerti.me> | 2023-10-02 22:34:41 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 22:34:41 -0700 |
commit | fc17d1a4c91fda50ddb07693d3aea09d74cdc3c7 (patch) | |
tree | 77a57851214b5ebb105cae182f68935461b8ba0f /packages/browser/src/helpers/webAuthnAbortService.test.ts | |
parent | 1c70e39302d81eb6fe2ba23da07c60f2dc397498 (diff) | |
parent | 3bc51ff209c71c8d2dd1e7a324eab487c5213c7f (diff) |
Merge pull request #449 from MasterKale/feat/448-manual-ceremony-cancellation
feat/448-manual-ceremony-cancellation
Diffstat (limited to 'packages/browser/src/helpers/webAuthnAbortService.test.ts')
-rw-r--r-- | packages/browser/src/helpers/webAuthnAbortService.test.ts | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/packages/browser/src/helpers/webAuthnAbortService.test.ts b/packages/browser/src/helpers/webAuthnAbortService.test.ts index 506bb2a..87d2535 100644 --- a/packages/browser/src/helpers/webAuthnAbortService.test.ts +++ b/packages/browser/src/helpers/webAuthnAbortService.test.ts @@ -1,23 +1,23 @@ -import { webauthnAbortService } from './webAuthnAbortService'; +import { WebAuthnAbortService } from './webAuthnAbortService'; test('should create a new abort signal every time', () => { - const signal1 = webauthnAbortService.createNewAbortSignal(); - const signal2 = webauthnAbortService.createNewAbortSignal(); + const signal1 = WebAuthnAbortService.createNewAbortSignal(); + const signal2 = WebAuthnAbortService.createNewAbortSignal(); expect(signal2).not.toBe(signal1); }); test('should call abort() with AbortError on existing controller when creating a new signal', () => { // Populate `.controller` - webauthnAbortService.createNewAbortSignal(); + 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; + WebAuthnAbortService.controller.abort = abortSpy; // Generate a new signal, which should call `abort()` on the existing controller - webauthnAbortService.createNewAbortSignal(); + WebAuthnAbortService.createNewAbortSignal(); expect(abortSpy).toHaveBeenCalledTimes(1); // Make sure we raise an AbortError so it can be detected correctly @@ -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(); +}); |