Skip to content

Commit 7e73653

Browse files
Add tests for checking passkey not supported in UI
1 parent 1f964cc commit 7e73653

File tree

5 files changed

+98
-5
lines changed

5 files changed

+98
-5
lines changed

lib/build/webauthnprebuiltui.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ts/recipe/webauthn/components/themes/recoverAccountWithToken/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ function PasskeyRecoverAccountWithTokenTheme(props: RecoverAccountWithTokenTheme
187187
case "INVALID_AUTHENTICATOR_ERROR":
188188
setErrorMessageLabel("WEBAUTHN_ACCOUNT_RECOVERY_INVALID_AUTHENTICATOR_ERROR");
189189
break;
190-
case "WEBAUTHN_NOT_SUPPORTED_ERROR":
190+
case "WEBAUTHN_NOT_SUPPORTED":
191191
setErrorMessageLabel("WEBAUTHN_NOT_SUPPORTED_ERROR");
192192
break;
193193
default:

test/end-to-end/webauthn.recover_account.test.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe("SuperTokens Webauthn Recover Account", () => {
231231
it("should show error when generated options are invalid", async () => {
232232
// Set the error to be thrown
233233
await page.evaluateOnNewDocument(() => {
234-
localStorage.setItem("webauthnRecoverAccountErrorStatus", "INVALID_GENERATED_OPTIONS_ERROR");
234+
localStorage.setItem("webauthnRecoverAccountErrorStatus", "INVALID_OPTIONS_ERROR");
235235
});
236236

237237
// Use the token to recover the account
@@ -286,7 +286,7 @@ describe("SuperTokens Webauthn Recover Account", () => {
286286
it("should show error when generated options are not found", async () => {
287287
// Set the error to be thrown
288288
await page.evaluateOnNewDocument(() => {
289-
localStorage.setItem("webauthnRecoverAccountErrorStatus", "GENERATED_OPTIONS_NOT_FOUND_ERROR");
289+
localStorage.setItem("webauthnRecoverAccountErrorStatus", "OPTIONS_NOT_FOUND_ERROR");
290290
});
291291

292292
// Use the token to recover the account
@@ -335,5 +335,35 @@ describe("SuperTokens Webauthn Recover Account", () => {
335335
localStorage.setItem("webauthnRecoverAccountErrorStatus", undefined);
336336
});
337337
});
338+
it("should show webauthn not supported error in the same view", async () => {
339+
// Set the error to be thrown
340+
await page.evaluateOnNewDocument(() => {
341+
localStorage.setItem("webauthnRecoverAccountErrorStatus", "WEBAUTHN_NOT_SUPPORTED");
342+
});
343+
344+
const token = await getTokenFromEmail(email);
345+
assert.ok(token);
346+
assert.strictEqual(token.length, 128);
347+
348+
await openRecoveryWithToken(page, token);
349+
350+
// We should be in the recovery page now, click the continue button
351+
await submitForm(page);
352+
await new Promise((res) => setTimeout(res, 1000));
353+
354+
const errorTextContainer = await waitForSTElement(
355+
page,
356+
"[data-supertokens~='passkeyRecoverableErrorContainer']"
357+
);
358+
const errorText = await errorTextContainer.evaluate((el) => el.textContent);
359+
assert.strictEqual(
360+
errorText,
361+
"Passkey is not supported on your browser, please try with a different browser."
362+
);
363+
364+
await page.evaluateOnNewDocument(() => {
365+
localStorage.removeItem("webauthnRecoverAccountErrorStatus");
366+
});
367+
});
338368
});
339369
});

test/end-to-end/webauthn.signin.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@ describe("SuperTokens Webauthn SignIn", () => {
111111
});
112112
await tryWebauthnSignIn(page);
113113
await waitForSTElement(page, "[data-supertokens~='passkeyRecoverableErrorContainer']");
114+
115+
await page.evaluateOnNewDocument(() => {
116+
localStorage.removeItem("webauthnErrorStatus");
117+
});
118+
});
119+
it("should show not supported error in the same view", async () => {
120+
// Set the error to be thrown
121+
await page.evaluateOnNewDocument(() => {
122+
localStorage.setItem("webauthnErrorStatus", "WEBAUTHN_NOT_SUPPORTED");
123+
});
124+
await tryWebauthnSignIn(page);
125+
const errorTextContainer = await waitForSTElement(
126+
page,
127+
"[data-supertokens~='passkeyRecoverableErrorContainer']"
128+
);
129+
const errorText = await errorTextContainer.evaluate((el) => el.textContent);
130+
assert.strictEqual(
131+
errorText,
132+
"Passkey is not supported on your browser, please try with a different browser."
133+
);
134+
135+
await page.evaluateOnNewDocument(() => {
136+
localStorage.removeItem("webauthnErrorStatus");
137+
});
114138
});
115139
it("should show general error in the same view", async () => {
116140
// Set the error to be thrown
@@ -119,6 +143,10 @@ describe("SuperTokens Webauthn SignIn", () => {
119143
});
120144
await tryWebauthnSignIn(page);
121145
await waitForSTElement(page, "[data-supertokens~='passkeyRecoverableErrorContainer']");
146+
147+
await page.evaluateOnNewDocument(() => {
148+
localStorage.removeItem("throwWebauthnError");
149+
});
122150
});
123151
});
124152
});

test/end-to-end/webauthn.signup.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,36 @@ describe("SuperTokens Webauthn SignUp", () => {
192192
await submitForm(page);
193193

194194
await waitForSTElement(page, "[data-supertokens~='passkeyRecoverableErrorContainer']");
195+
196+
await page.evaluateOnNewDocument(() => {
197+
localStorage.removeItem("webauthnErrorStatus");
198+
});
199+
});
200+
it("should show not supported error in the same view", async () => {
201+
// Set the error to be thrown
202+
await page.evaluateOnNewDocument(() => {
203+
localStorage.setItem("webauthnErrorStatus", "WEBAUTHN_NOT_SUPPORTED");
204+
});
205+
206+
const email = await getTestEmail();
207+
await tryWebauthnSignUp(page, email);
208+
209+
// We should be in the confirmation page now.
210+
await submitForm(page);
211+
212+
const errorTextContainer = await waitForSTElement(
213+
page,
214+
"[data-supertokens~='passkeyRecoverableErrorContainer']"
215+
);
216+
const errorText = await errorTextContainer.evaluate((el) => el.textContent);
217+
assert.strictEqual(
218+
errorText,
219+
"Passkey is not supported on your browser, please try with a different browser."
220+
);
221+
222+
await page.evaluateOnNewDocument(() => {
223+
localStorage.removeItem("webauthnErrorStatus");
224+
});
195225
});
196226
it("should show something went wrong on general error", async () => {
197227
// Set the error to be thrown
@@ -206,6 +236,10 @@ describe("SuperTokens Webauthn SignUp", () => {
206236
await submitForm(page);
207237

208238
await waitForSTElement(page, "[data-supertokens~='somethingWentWrongContainer']");
239+
240+
await page.evaluateOnNewDocument(() => {
241+
localStorage.removeItem("throwWebauthnError");
242+
});
209243
});
210244
it("should go back to home when go back is clicked in something went wrong", async () => {
211245
// Set the error to be thrown

0 commit comments

Comments
 (0)