summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2022-09-27 21:10:22 -0700
committerMatthew Miller <matthew@millerti.me>2022-09-28 14:51:02 -0700
commit4ea0bd370609294e3cf70f467d234093fc6e87fb (patch)
treeba1d6e1346ba40cddc35f5a9c2f3ca68358eecc2
parenta86025d58417e729171862bdbed69795f7814452 (diff)
Remove reset() from abort service
-rw-r--r--packages/browser/src/helpers/webAuthnAbortService.test.ts20
-rw-r--r--packages/browser/src/helpers/webAuthnAbortService.ts4
-rw-r--r--packages/browser/src/methods/startAuthentication.test.ts6
-rw-r--r--packages/browser/src/methods/startAuthentication.ts2
-rw-r--r--packages/browser/src/methods/startRegistration.test.ts6
-rw-r--r--packages/browser/src/methods/startRegistration.ts2
6 files changed, 8 insertions, 32 deletions
diff --git a/packages/browser/src/helpers/webAuthnAbortService.test.ts b/packages/browser/src/helpers/webAuthnAbortService.test.ts
index f4e6344..294a894 100644
--- a/packages/browser/src/helpers/webAuthnAbortService.test.ts
+++ b/packages/browser/src/helpers/webAuthnAbortService.test.ts
@@ -20,23 +20,3 @@ test('should call abort() on existing controller when creating a new signal', ()
webauthnAbortService.createNewAbortSignal();
expect(abortSpy).toHaveBeenCalledTimes(1);
});
-
-test('should reset controller', () => {
- // Reset the service
- webauthnAbortService.reset();
-
- // Populate `.controller`
- webauthnAbortService.createNewAbortSignal();
-
- // Spy on the existing instance of AbortController
- const abortSpy = jest.fn();
- // @ts-ignore
- webauthnAbortService.controller?.abort = abortSpy;
-
- // Reset the service
- webauthnAbortService.reset();
-
- // Generate a new signal, which should NOT call `abort()` because the controller was cleared
- webauthnAbortService.createNewAbortSignal();
- expect(abortSpy).toHaveBeenCalledTimes(0);
-});
diff --git a/packages/browser/src/helpers/webAuthnAbortService.ts b/packages/browser/src/helpers/webAuthnAbortService.ts
index 268f008..479df55 100644
--- a/packages/browser/src/helpers/webAuthnAbortService.ts
+++ b/packages/browser/src/helpers/webAuthnAbortService.ts
@@ -18,10 +18,6 @@ class WebAuthnAbortService {
this.controller = new AbortController();
return this.controller.signal;
}
-
- reset() {
- this.controller = undefined;
- }
}
export const webauthnAbortService = new WebAuthnAbortService();
diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts
index 1936a9e..e112124 100644
--- a/packages/browser/src/methods/startAuthentication.test.ts
+++ b/packages/browser/src/methods/startAuthentication.test.ts
@@ -60,6 +60,10 @@ beforeEach(() => {
mockSupportsWebAuthn.mockReturnValue(true);
mockSupportsAutofill.mockResolvedValue(true);
+
+ // Reset the abort service so we get an accurate call count
+ // @ts-ignore
+ webauthnAbortService.controller = undefined;
});
afterEach(() => {
@@ -228,8 +232,6 @@ test('should support "cable" transport', async () => {
test('should cancel an existing call when executed again', async () => {
const abortSpy = jest.spyOn(AbortController.prototype, 'abort');
- // Reset the abort service so we get an accurate call count
- webauthnAbortService.reset();
// Fire off a request and immediately attempt a second one
startAuthentication(goodOpts1);
diff --git a/packages/browser/src/methods/startAuthentication.ts b/packages/browser/src/methods/startAuthentication.ts
index 4cbe688..761a96c 100644
--- a/packages/browser/src/methods/startAuthentication.ts
+++ b/packages/browser/src/methods/startAuthentication.ts
@@ -80,8 +80,6 @@ export async function startAuthentication(
credential = (await navigator.credentials.get(options)) as AuthenticationCredential;
} catch (err) {
throw identifyAuthenticationError({ error: err as Error, options });
- } finally {
- webauthnAbortService.reset();
}
if (!credential) {
diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts
index 9a7196b..2dc11be 100644
--- a/packages/browser/src/methods/startRegistration.test.ts
+++ b/packages/browser/src/methods/startRegistration.test.ts
@@ -59,6 +59,10 @@ beforeEach(() => {
});
mockSupportsWebauthn.mockReturnValue(true);
+
+ // Reset the abort service so we get an accurate call count
+ // @ts-ignore
+ webauthnAbortService.controller = undefined;
});
afterEach(() => {
@@ -215,8 +219,6 @@ test('should return "cable" transport from response', async () => {
test('should cancel an existing call when executed again', async () => {
const abortSpy = jest.spyOn(AbortController.prototype, 'abort');
- // Reset the abort service so we get an accurate call count
- webauthnAbortService.reset();
// Fire off a request and immediately attempt a second one
startRegistration(goodOpts1);
diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts
index e103c11..bc30707 100644
--- a/packages/browser/src/methods/startRegistration.ts
+++ b/packages/browser/src/methods/startRegistration.ts
@@ -46,8 +46,6 @@ export async function startRegistration(
credential = (await navigator.credentials.create(options)) as RegistrationCredential;
} catch (err) {
throw identifyRegistrationError({ error: err as Error, options });
- } finally {
- webauthnAbortService.reset();
}
if (!credential) {