Skip to content

Commit 25d2833

Browse files
Add proper e2e tests for signup
1 parent a8c67a6 commit 25d2833

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

examples/for-tests-react-16/src/App.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,37 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
955955

956956
return { authenticationResponse: assertion, status: "OK" };
957957
},
958+
async registerCredential(...args) {
959+
log("REGISTER CREDENTIAL");
960+
961+
const registrationOptions = args[0].registrationOptions;
962+
const response = await fetch(`${getApiDomain()}/test/webauthn/create-credential`, {
963+
method: "POST",
964+
body: JSON.stringify({
965+
registerOptionsResponse: registrationOptions,
966+
rpId: "localhost",
967+
rpName: "localhost",
968+
origin: "http://localhost:3031",
969+
}),
970+
headers: {
971+
"Content-Type": "application/json",
972+
},
973+
});
974+
975+
if (!response.ok) {
976+
throw new STGeneralError("TEST ERROR: CREATING CREDENTIAL FAILED");
977+
}
978+
979+
const { credential } = await response.json();
980+
return {
981+
status: "OK",
982+
registrationResponse: credential,
983+
};
984+
},
985+
async signUp(...args) {
986+
log(`SIGN UP`);
987+
return implementation.signUp(...args);
988+
},
958989
async signIn(...args) {
959990
log(`SIGN IN`);
960991
return implementation.signIn(...args);
@@ -976,11 +1007,7 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
9761007

9771008
// We are mocking the popup since it's not possible to
9781009
// test the webauthn popup.
979-
return {
980-
status: "OK",
981-
user: {},
982-
fetchResponse: {},
983-
};
1010+
return implementation.registerCredentialWithSignUp(...args);
9841011
},
9851012
authenticateCredentialWithSignIn(...args) {
9861013
log(`AUTHENTICATE CREDENTIAL WITH SIGN IN`);

examples/for-tests/src/App.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,37 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
12121212

12131213
return { authenticationResponse: assertion, status: "OK" };
12141214
},
1215+
async registerCredential(...args) {
1216+
log("REGISTER CREDENTIAL");
1217+
1218+
const registrationOptions = args[0].registrationOptions;
1219+
const response = await fetch(`${getApiDomain()}/test/webauthn/create-credential`, {
1220+
method: "POST",
1221+
body: JSON.stringify({
1222+
registerOptionsResponse: registrationOptions,
1223+
rpId: "localhost",
1224+
rpName: "localhost",
1225+
origin: "http://localhost:3031",
1226+
}),
1227+
headers: {
1228+
"Content-Type": "application/json",
1229+
},
1230+
});
1231+
1232+
if (!response.ok) {
1233+
throw new STGeneralError("TEST ERROR: CREATING CREDENTIAL FAILED");
1234+
}
1235+
1236+
const { credential } = await response.json();
1237+
return {
1238+
status: "OK",
1239+
registrationResponse: credential,
1240+
};
1241+
},
1242+
async signUp(...args) {
1243+
log(`SIGN UP`);
1244+
return implementation.signUp(...args);
1245+
},
12151246
async signIn(...args) {
12161247
log(`SIGN IN`);
12171248
return implementation.signIn(...args);
@@ -1233,11 +1264,7 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
12331264

12341265
// We are mocking the popup since it's not possible to
12351266
// test the webauthn popup.
1236-
return {
1237-
status: "OK",
1238-
user: {},
1239-
fetchResponse: {},
1240-
};
1267+
return implementation.registerCredentialWithSignUp(...args);
12411268
},
12421269
authenticateCredentialWithSignIn(...args) {
12431270
log(`AUTHENTICATE CREDENTIAL WITH SIGN IN`);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getTestEmail,
1010
waitForSTElement,
1111
submitForm,
12+
setEnabledRecipes,
1213
} from "../helpers";
1314
import { tryWebauthnSignUp } from "./webauthn.helpers";
1415
import assert from "assert";
@@ -25,6 +26,8 @@ describe("SuperTokens Webauthn SignUp", () => {
2526
method: "POST",
2627
}).catch(console.error);
2728

29+
await setEnabledRecipes(["webauthn", "emailpassword", "session", "dashboard", "userroles"]);
30+
2831
browser = await setupBrowser();
2932
page = await browser.newPage();
3033
page.on("console", (consoleObj) => {
@@ -76,11 +79,19 @@ describe("SuperTokens Webauthn SignUp", () => {
7679

7780
// We should be in the confirmation page now.
7881
await submitForm(page);
82+
await page.waitForTimeout(2000);
83+
7984
assert.deepStrictEqual(consoleLogs, [
8085
"ST_LOGS SESSION OVERRIDE ADD_FETCH_INTERCEPTORS_AND_RETURN_MODIFIED_FETCH",
8186
"ST_LOGS SESSION OVERRIDE ADD_AXIOS_INTERCEPTORS",
8287
"ST_LOGS WEBAUTHN OVERRIDE GET REGISTER OPTIONS WITH SIGN UP",
83-
"ST_LOGS SUPERTOKENS GET_REDIRECTION_URL TO_AUTH",
88+
"ST_LOGS WEBAUTHN OVERRIDE GET REGISTER OPTIONS",
89+
"ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS",
90+
"ST_LOGS WEBAUTHN OVERRIDE REGISTER CREDENTIAL",
91+
"ST_LOGS WEBAUTHN OVERRIDE SIGN UP",
92+
"ST_LOGS WEBAUTHN PRE_API_HOOKS SIGN_UP",
93+
"ST_LOGS SESSION ON_HANDLE_EVENT SESSION_CREATED",
94+
"ST_LOGS SESSION OVERRIDE GET_USER_ID",
8495
]);
8596
});
8697
it("should recover successfully from a recoverable error", async () => {

0 commit comments

Comments
 (0)