Skip to content

Commit 465d7d2

Browse files
Add support for testing register options throwing error for recovery with token
1 parent e3eb497 commit 465d7d2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

examples/for-tests/src/App.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,18 @@ function getWebauthnConfigs({ throwWebauthnError, webauthnErrorStatus }) {
11621162
...implementation,
11631163
getRegisterOptions(...args) {
11641164
log(`GET REGISTER OPTIONS`);
1165+
1166+
if (throwWebauthnError) {
1167+
throw new STGeneralError("TEST ERROR");
1168+
}
1169+
1170+
// Return error status if the user passed that.
1171+
if (webauthnErrorStatus) {
1172+
return {
1173+
status: webauthnErrorStatus,
1174+
};
1175+
}
1176+
11651177
return implementation.getRegisterOptions(...args);
11661178
},
11671179
async getSignInOptions(...args) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,25 @@ describe("SuperTokens Webauthn Recover Account", () => {
207207
"ST_LOGS WEBAUTHN PRE_API_HOOKS REGISTER_OPTIONS",
208208
]);
209209
});
210+
it("should show error when webauthn error is thrown", async () => {
211+
// Set the error to be thrown
212+
await page.evaluateOnNewDocument(() => {
213+
localStorage.setItem("throwWebauthnError", "true");
214+
});
215+
216+
// Use the token to recover the account
217+
await openRecoveryWithToken(page, "test");
218+
219+
const errorTextContainer = await waitForSTElement(
220+
page,
221+
"[data-supertokens~='passkeyRecoverableErrorContainer']"
222+
);
223+
const errorText = await errorTextContainer.evaluate((el) => el.textContent);
224+
assert.strictEqual(errorText, "Something went wrong, please refresh the page or reach out to support.");
225+
226+
await page.evaluateOnNewDocument(() => {
227+
localStorage.setItem("throwWebauthnError", undefined);
228+
});
229+
});
210230
});
211231
});

0 commit comments

Comments
 (0)