Skip to content

Commit 4fb94f1

Browse files
Add init tests for sign in for webauthn
1 parent f81fa58 commit 4fb94f1

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,13 @@ export async function tryWebauthnSignUp(page, email) {
1414
await submitForm(page);
1515
await new Promise((res) => setTimeout(res, 1000));
1616
}
17+
18+
export async function tryWebauthnSignIn(page) {
19+
await Promise.all([
20+
page.goto(`${TEST_CLIENT_BASE_URL}/auth?authRecipe=webauthn`),
21+
page.waitForNavigation({ waitUntil: "networkidle0" }),
22+
]);
23+
24+
await submitForm(page);
25+
await new Promise((res) => setTimeout(res, 1000));
26+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import fetch from "isomorphic-fetch";
2+
import { TEST_SERVER_BASE_URL } from "../constants";
3+
import {
4+
backendBeforeEach,
5+
setupBrowser,
6+
screenshotOnFailure,
7+
clearBrowserCookiesWithoutAffectingConsole,
8+
toggleSignInSignUp,
9+
getTestEmail,
10+
waitForSTElement,
11+
submitForm,
12+
} from "../helpers";
13+
import { tryWebauthnSignIn } from "./webauthn.helpers";
14+
import assert from "assert";
15+
16+
describe("SuperTokens Webauthn SignIn", () => {
17+
let browser;
18+
let page;
19+
let consoleLogs = [];
20+
21+
before(async function () {
22+
await backendBeforeEach();
23+
24+
await fetch(`${TEST_SERVER_BASE_URL}/startst`, {
25+
method: "POST",
26+
}).catch(console.error);
27+
28+
browser = await setupBrowser();
29+
page = await browser.newPage();
30+
page.on("console", (consoleObj) => {
31+
const log = consoleObj.text();
32+
if (log.startsWith("ST_LOGS")) {
33+
consoleLogs.push(log);
34+
}
35+
});
36+
});
37+
38+
after(async function () {
39+
await browser.close();
40+
await fetch(`${TEST_SERVER_BASE_URL}/after`, {
41+
method: "POST",
42+
}).catch(console.error);
43+
44+
await fetch(`${TEST_SERVER_BASE_URL}/stopst`, {
45+
method: "POST",
46+
}).catch(console.error);
47+
});
48+
49+
afterEach(function () {
50+
return screenshotOnFailure(this, browser);
51+
});
52+
53+
beforeEach(async function () {
54+
consoleLogs = [];
55+
consoleLogs = await clearBrowserCookiesWithoutAffectingConsole(page, consoleLogs);
56+
await toggleSignInSignUp(page);
57+
});
58+
59+
describe("SignIn test", () => {
60+
it("should be able to sign in with webauthn", async () => {
61+
await tryWebauthnSignIn(page);
62+
assert.deepStrictEqual(consoleLogs, [
63+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
64+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
65+
"ST_LOGS WEBAUTHN OVERRIDE AUTHENTICATE CREDENTIAL WITH SIGN IN",
66+
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH",
67+
]);
68+
});
69+
it("should recover successfully from a recoverable error", async () => {
70+
// Set the error to be thrown
71+
await page.evaluateOnNewDocument(() => {
72+
localStorage.setItem("webauthnErrorStatus", "FAILED_TO_AUTHENTICATE_USER");
73+
});
74+
await tryWebauthnSignIn(page);
75+
await waitForSTElement(page, "[data-supertokens~='passkeyRecoverableErrorContainer']");
76+
77+
// Remove the error and retry
78+
await page.evaluateOnNewDocument(() => {
79+
localStorage.removeItem("webauthnErrorStatus");
80+
});
81+
82+
await submitForm(page);
83+
assert.deepStrictEqual(consoleLogs, [
84+
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
85+
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
86+
"ST_LOGS WEBAUTHN OVERRIDE AUTHENTICATE CREDENTIAL WITH SIGN IN",
87+
"ST_LOGS WEBAUTHN OVERRIDE AUTHENTICATE CREDENTIAL WITH SIGN IN",
88+
]);
89+
});
90+
it("should show recoverable error in the same view", async () => {
91+
// Set the error to be thrown
92+
await page.evaluateOnNewDocument(() => {
93+
localStorage.setItem("webauthnErrorStatus", "FAILED_TO_AUTHENTICATE_USER");
94+
});
95+
await tryWebauthnSignIn(page);
96+
await waitForSTElement(page, "[data-supertokens~='passkeyRecoverableErrorContainer']");
97+
});
98+
});
99+
});

0 commit comments

Comments
 (0)