summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src')
-rw-r--r--packages/browser/src/helpers/browserSupportsWebAuthn.test.ts10
-rw-r--r--packages/browser/src/helpers/browserSupportsWebAuthnAutofill.ts11
-rw-r--r--packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts3
-rw-r--r--packages/browser/src/helpers/platformAuthenticatorIsAvailable.ts4
-rw-r--r--packages/browser/src/helpers/webAuthnAbortService.test.ts2
-rw-r--r--packages/browser/src/helpers/webAuthnError.ts5
-rw-r--r--packages/browser/src/methods/startAuthentication.test.ts12
-rw-r--r--packages/browser/src/methods/startRegistration.test.ts16
-rw-r--r--packages/browser/src/setupTests.ts2
9 files changed, 34 insertions, 31 deletions
diff --git a/packages/browser/src/helpers/browserSupportsWebAuthn.test.ts b/packages/browser/src/helpers/browserSupportsWebAuthn.test.ts
index 195f089..639bd2f 100644
--- a/packages/browser/src/helpers/browserSupportsWebAuthn.test.ts
+++ b/packages/browser/src/helpers/browserSupportsWebAuthn.test.ts
@@ -10,13 +10,19 @@ test("should return true when browser supports WebAuthn", () => {
});
test("should return false when browser does not support WebAuthn", () => {
- delete (window as any).PublicKeyCredential;
+ // This looks weird but it appeases the linter so it's _fiiiine_
+ delete (window as { PublicKeyCredential: unknown }).PublicKeyCredential;
expect(browserSupportsWebAuthn()).toBe(false);
});
test("should return false when window is undefined", () => {
// Make window undefined as it is in node environments.
- const windowSpy = jest.spyOn<any, "window">(global, "window", "get");
+ const windowSpy = jest.spyOn<typeof globalThis, "window">(
+ global,
+ "window",
+ "get",
+ );
+ // @ts-ignore: Intentionally making window unavailable
windowSpy.mockImplementation(() => undefined);
expect(window).toBe(undefined);
diff --git a/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.ts b/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.ts
index b3b1e86..621ab9a 100644
--- a/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.ts
+++ b/packages/browser/src/helpers/browserSupportsWebAuthnAutofill.ts
@@ -4,7 +4,7 @@ import { PublicKeyCredentialFuture } from "@simplewebauthn/typescript-types";
* Determine if the browser supports conditional UI, so that WebAuthn credentials can
* be shown to the user in the browser's typical password autofill popup.
*/
-export async function browserSupportsWebAuthnAutofill(): Promise<boolean> {
+export function browserSupportsWebAuthnAutofill(): Promise<boolean> {
/**
* I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
* TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
@@ -14,8 +14,9 @@ export async function browserSupportsWebAuthnAutofill(): Promise<boolean> {
const globalPublicKeyCredential = window
.PublicKeyCredential as unknown as PublicKeyCredentialFuture;
- return (
- globalPublicKeyCredential.isConditionalMediationAvailable !== undefined &&
- globalPublicKeyCredential.isConditionalMediationAvailable()
- );
+ if (globalPublicKeyCredential.isConditionalMediationAvailable === undefined) {
+ return new Promise((resolve) => resolve(false));
+ }
+
+ return globalPublicKeyCredential.isConditionalMediationAvailable();
}
diff --git a/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts b/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
index 3024420..6b3e90c 100644
--- a/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
+++ b/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
@@ -26,7 +26,8 @@ test("should return false when platform authenticator is unavailable", async ()
});
test("should return false when browser does not support WebAuthn", async () => {
- delete (window as any).PublicKeyCredential;
+ // This looks weird but it appeases the linter so it's _fiiiine_
+ delete (window as { PublicKeyCredential: unknown }).PublicKeyCredential;
const isAvailable = await platformAuthenticatorIsAvailable();
expect(isAvailable).toEqual(false);
diff --git a/packages/browser/src/helpers/platformAuthenticatorIsAvailable.ts b/packages/browser/src/helpers/platformAuthenticatorIsAvailable.ts
index 319825b..d188669 100644
--- a/packages/browser/src/helpers/platformAuthenticatorIsAvailable.ts
+++ b/packages/browser/src/helpers/platformAuthenticatorIsAvailable.ts
@@ -6,9 +6,9 @@ import { browserSupportsWebAuthn } from "./browserSupportsWebAuthn";
*
* This method will _not_ be able to tell you the name of the platform authenticator.
*/
-export async function platformAuthenticatorIsAvailable(): Promise<boolean> {
+export function platformAuthenticatorIsAvailable(): Promise<boolean> {
if (!browserSupportsWebAuthn()) {
- return false;
+ return new Promise((resolve) => resolve(false));
}
return PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
diff --git a/packages/browser/src/helpers/webAuthnAbortService.test.ts b/packages/browser/src/helpers/webAuthnAbortService.test.ts
index c1607e6..e8d358e 100644
--- a/packages/browser/src/helpers/webAuthnAbortService.test.ts
+++ b/packages/browser/src/helpers/webAuthnAbortService.test.ts
@@ -13,7 +13,7 @@ test("should call abort() with AbortError on existing controller when creating a
// Spy on the existing instance of AbortController
const abortSpy = jest.fn();
- // @ts-ignore
+ // @ts-ignore: Ignore the fact that `controller` is private
webauthnAbortService.controller.abort = abortSpy;
// Generate a new signal, which should call `abort()` on the existing controller
diff --git a/packages/browser/src/helpers/webAuthnError.ts b/packages/browser/src/helpers/webAuthnError.ts
index 5960821..3f25a54 100644
--- a/packages/browser/src/helpers/webAuthnError.ts
+++ b/packages/browser/src/helpers/webAuthnError.ts
@@ -29,11 +29,6 @@ export class WebAuthnError extends Error {
cause: Error;
name?: string;
}) {
- /**
- * `cause` is supported in evergreen browsers, but not IE10, so this ts-ignore is to
- * help Rollup complete the ES5 build.
- */
- // @ts-ignore
super(message, { cause });
this.name = name ?? cause.name;
this.code = code;
diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts
index 62f3061..73770d8 100644
--- a/packages/browser/src/methods/startAuthentication.test.ts
+++ b/packages/browser/src/methods/startAuthentication.test.ts
@@ -50,7 +50,7 @@ const goodOpts2UTF8: PublicKeyCredentialRequestOptionsJSON = {
beforeEach(() => {
// Stub out a response so the method won't throw
- mockNavigatorGet.mockImplementation((): Promise<any> => {
+ mockNavigatorGet.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({
response: {},
@@ -63,7 +63,7 @@ beforeEach(() => {
mockSupportsAutofill.mockResolvedValue(true);
// Reset the abort service so we get an accurate call count
- // @ts-ignore
+ // @ts-ignore: Ignore the fact that `controller` is private
webauthnAbortService.controller = undefined;
});
@@ -188,9 +188,9 @@ test("should send extensions to authenticator if present in options", async () =
const extensions: AuthenticationExtensionsClientInputs = {
credProps: true,
appid: "appidHere",
- // @ts-ignore
+ // @ts-ignore: Send arbitrary extensions
uvm: true,
- // @ts-ignore
+ // @ts-ignore: Send arbitrary extensions
appidExclude: "appidExcludeHere",
};
const optsWithExts: PublicKeyCredentialRequestOptionsJSON = {
@@ -221,7 +221,7 @@ test("should include extension results", async () => {
};
// Mock extension return values from authenticator
- mockNavigatorGet.mockImplementation((): Promise<any> => {
+ mockNavigatorGet.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({ response: {}, getClientExtensionResults: () => extResults });
});
@@ -324,7 +324,7 @@ test("should throw error if no acceptable <input> is found", async () => {
test("should return authenticatorAttachment if present", async () => {
// Mock extension return values from authenticator
- mockNavigatorGet.mockImplementation((): Promise<any> => {
+ mockNavigatorGet.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({
response: {},
diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts
index d9ea0f7..c094278 100644
--- a/packages/browser/src/methods/startRegistration.test.ts
+++ b/packages/browser/src/methods/startRegistration.test.ts
@@ -53,7 +53,7 @@ const goodOpts1: PublicKeyCredentialCreationOptionsJSON = {
beforeEach(() => {
// Stub out a response so the method won't throw
- mockNavigatorCreate.mockImplementation((): Promise<any> => {
+ mockNavigatorCreate.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({ response: {}, getClientExtensionResults: () => ({}) });
});
@@ -62,7 +62,7 @@ beforeEach(() => {
mockSupportsWebauthn.mockReturnValue(true);
// Reset the abort service so we get an accurate call count
- // @ts-ignore
+ // @ts-ignore: Ignore the fact that `controller` is private
webauthnAbortService.controller = undefined;
});
@@ -146,9 +146,9 @@ test("should send extensions to authenticator if present in options", async () =
const extensions: AuthenticationExtensionsClientInputs = {
credProps: true,
appid: "appidHere",
- // @ts-ignore
+ // @ts-ignore: Send arbitrary extensions
uvm: true,
- // @ts-ignore
+ // @ts-ignore: Send arbitrary extensions
appidExclude: "appidExcludeHere",
};
const optsWithExts: PublicKeyCredentialCreationOptionsJSON = {
@@ -181,7 +181,7 @@ test("should include extension results", async () => {
};
// Mock extension return values from authenticator
- mockNavigatorCreate.mockImplementation((): Promise<any> => {
+ mockNavigatorCreate.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({ response: {}, getClientExtensionResults: () => extResults });
});
@@ -247,7 +247,7 @@ test("should cancel an existing call when executed again", async () => {
test("should return authenticatorAttachment if present", async () => {
// Mock extension return values from authenticator
- mockNavigatorCreate.mockImplementation((): Promise<any> => {
+ mockNavigatorCreate.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({
response: {},
@@ -269,7 +269,7 @@ test("should return convenience values if getters present", async () => {
* that's already buried in the response.
*/
// Mock extension return values from authenticator
- mockNavigatorCreate.mockImplementation((): Promise<any> => {
+ mockNavigatorCreate.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({
response: {
@@ -296,7 +296,7 @@ test("should not return convenience values if getters missing", async () => {
* that's already buried in the response.
*/
// Mock extension return values from authenticator
- mockNavigatorCreate.mockImplementation((): Promise<any> => {
+ mockNavigatorCreate.mockImplementation((): Promise<unknown> => {
return new Promise((resolve) => {
resolve({
response: {},
diff --git a/packages/browser/src/setupTests.ts b/packages/browser/src/setupTests.ts
index e5d5807..09ae162 100644
--- a/packages/browser/src/setupTests.ts
+++ b/packages/browser/src/setupTests.ts
@@ -7,7 +7,7 @@
* JSDom doesn't seem to support `credentials`, so let's define them here so we can mock their
* implementations in specific tests.
*/
-Object.defineProperty(window.navigator, "credentials", {
+Object.defineProperty(globalThis.window.navigator, "credentials", {
writable: true,
value: {
create: jest.fn(),