Skip to content

Commit 9f5275c

Browse files
committed
add test case for failed passkey authentication
1 parent 6763f16 commit 9f5275c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

exercises/02.authentication/03.solution.passkeys/tests/e2e/auth-passkeys.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async function createWebAuthnClient(page: Page) {
1414
hasResidentKey: true,
1515
hasUserVerification: true,
1616
isUserVerified: true,
17+
// Authenticator will automatically respond to the next prompt in the browser.
1718
automaticPresenceSimulation: true,
1819
},
1920
})
@@ -24,9 +25,10 @@ async function createWebAuthnClient(page: Page) {
2425
}
2526
}
2627

27-
test('authenticates using a passkey', async ({ navigate, page }) => {
28+
test('authenticates using an existing passkey', async ({ navigate, page }) => {
2829
await navigate('/login')
2930

31+
// Create a test passkey.
3032
const passkey = createTestPasskey({
3133
rpId: new URL(page.url()).hostname,
3234
})
@@ -58,3 +60,24 @@ test('authenticates using a passkey', async ({ navigate, page }) => {
5860

5961
await expect(page.getByText(user.name!)).toBeVisible()
6062
})
63+
64+
test('displays an error when authenticating via a passkey fails', async ({
65+
navigate,
66+
page,
67+
}) => {
68+
await navigate('/login')
69+
70+
const { client, authenticatorId } = await createWebAuthnClient(page)
71+
await client.send('WebAuthn.setUserVerified', {
72+
authenticatorId,
73+
isUserVerified: false,
74+
})
75+
76+
await page.getByRole('button', { name: 'Login with a passkey' }).click()
77+
78+
await expect(
79+
page.getByText(
80+
'Failed to authenticate with passkey: The operation either timed out or was not allowed',
81+
),
82+
).toBeVisible()
83+
})

0 commit comments

Comments
 (0)