Skip to content

Commit 8f16a1a

Browse files
committed
Fix E2E tests
1 parent 29c008d commit 8f16a1a

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWeb-CSharp/Components/Account/Shared/PasskeySubmit.razor.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ async function requestCredential(email, mediation, signal) {
3131
return await navigator.credentials.get({ publicKey: options, mediation, signal });
3232
}
3333

34-
let passkeySubmitAbortController;
35-
3634
customElements.define('passkey-submit', class extends HTMLElement {
3735
static formAssociated = true;
3836

@@ -54,10 +52,14 @@ customElements.define('passkey-submit', class extends HTMLElement {
5452
this.tryAutofillPasskey();
5553
}
5654

55+
disconnectedCallback() {
56+
this.abortController?.abort();
57+
}
58+
5759
async obtainCredentialAndSubmit(useConditionalMediation = false) {
58-
passkeySubmitAbortController?.abort();
59-
passkeySubmitAbortController = new AbortController();
60-
const signal = passkeySubmitAbortController.signal;
60+
this.abortController?.abort();
61+
this.abortController = new AbortController();
62+
const signal = this.abortController.signal;
6163
const formData = new FormData();
6264
try {
6365
let credential;

src/ProjectTemplates/test/Templates.Blazor.Tests/BlazorTemplateTest.cs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ await Task.WhenAll(
138138

139139
if (authenticationFeatures.HasFlag(AuthenticationFeatures.RegisterAndLogIn))
140140
{
141+
// Start a new CDP session with WebAuthn enabled and add a virtual authenticator.
142+
// We do this regardless of whether we're testing passkeys, because passkey
143+
// gets attempted unconditionally on the login page, and this utilizes the WebAuthn API.
144+
await using var cdpSession = await browser.NewCDPSessionAsync(page);
145+
await cdpSession.SendAsync("WebAuthn.enable");
146+
var result = await cdpSession.SendAsync("WebAuthn.addVirtualAuthenticator", new Dictionary<string, object>
147+
{
148+
["options"] = new
149+
{
150+
protocol = "ctap2",
151+
transport = "internal",
152+
hasResidentKey = false,
153+
hasUserIdentification = true,
154+
isUserVerified = true,
155+
automaticPresenceSimulation = true,
156+
}
157+
});
158+
159+
Assert.True(result.HasValue);
160+
var authenticatorId = result.Value.GetProperty("authenticatorId").GetString();
161+
141162
await Task.WhenAll(
142163
page.WaitForURLAsync("**/Account/Login**", new() { WaitUntil = WaitUntilState.NetworkIdle }),
143164
page.ClickAsync("text=Login"));
@@ -180,25 +201,6 @@ await Task.WhenAll(
180201

181202
if (authenticationFeatures.HasFlag(AuthenticationFeatures.Passkeys))
182203
{
183-
// Start a new CDP session with WebAuthn enabled and add a virtual authenticator
184-
await using var cdpSession = await browser.NewCDPSessionAsync(page);
185-
await cdpSession.SendAsync("WebAuthn.enable");
186-
var result = await cdpSession.SendAsync("WebAuthn.addVirtualAuthenticator", new Dictionary<string, object>
187-
{
188-
["options"] = new
189-
{
190-
protocol = "ctap2",
191-
transport = "internal",
192-
hasResidentKey = false,
193-
hasUserIdentification = true,
194-
isUserVerified = true,
195-
automaticPresenceSimulation = true,
196-
}
197-
});
198-
199-
Assert.True(result.HasValue);
200-
var authenticatorId = result.Value.GetProperty("authenticatorId").GetString();
201-
202204
// Navigate to the passkey management page
203205
await Task.WhenAll(
204206
page.WaitForURLAsync("**/Account/Manage**", new() { WaitUntil = WaitUntilState.NetworkIdle }),

0 commit comments

Comments
 (0)