Skip to content

Commit

Permalink
webauthn: Update abort handling to take an abort reason
Browse files Browse the repository at this point in the history
AbortController now has a `reason` [1] parameter which
has been added to Web Authentication [2], Credential Management [3],
and Web OTP [4]. We should update CredentialsContainer to take
this `reason` to the promise then aborting a request.

[1] https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/reason
[2] w3c/webauthn#1706
[3] w3c/webappsec-credential-management#196
[4] WICG/web-otp#57

Bug: 1272541, 1329938
Change-Id: Idb9ef40d6a97ae240ae3a28892a426e4c0ffbfef
  • Loading branch information
amoseui authored and chromium-wpt-export-bot committed Aug 26, 2022
1 parent ad92e64 commit d42d172
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
8 changes: 8 additions & 0 deletions credential-management/otpcredential-get-basics.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@
{otp: {transport: ["sms"]}, signal: signal}));
}, 'Should abort request');

promise_test(async t => {
const controller = new AbortController();
const signal = controller.signal;

controller.abort('CustomError');
await promise_rejects_exactly(t, 'CustomError', navigator.credentials.get(
{otp: {transport: ["sms"]}, signal: signal}));
}, 'Should abort request with reason');
</script>
13 changes: 13 additions & 0 deletions secure-payment-confirmation/enrollment.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
.runTest('Payment credential does not allow residentKey to be "discouraged".', "NotSupportedError");
new CreatePaymentCredentialsTest({authenticatorAttachment: 'cross-platform'})
.runTest('Payment credential requires authenticatorAttachment to be "platform", not "cross-platform".', "NotSupportedError");

// abort creates
let abortController = new AbortController();
abortController.abort();
new CreatePaymentCredentialsTest()
.modify("options.signal", abortController.signal)
.runTest("Payment credential abort without reason", "AbortError");

abortController = new AbortController();
abortController.abort(new Error('error'));
new CreatePaymentCredentialsTest()
.modify("options.signal", abortController.signal)
.runTest("Payment credential abort reason with Error", Error);
}, {
protocol: 'ctap2_1',
transport: 'internal',
Expand Down
28 changes: 28 additions & 0 deletions webauthn/createcredential-abort.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>WebAuthn navigator.credentials.create() abort Tests</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=helpers.js></script>
<body></body>
<script>
standardSetup(function() {
"use strict";

let abortController = new AbortController();
abortController.abort();
new CreateCredentialsTest("options.signal", abortController.signal)
.runTest("navigator.credentials.create() abort without reason", "AbortError");

abortController = new AbortController();
abortController.abort(new Error('error'));
new CreateCredentialsTest("options.signal", abortController.signal)
.runTest("navigator.credentials.create() abort reason with Error", Error);
});

/* JSHINT */
/* globals standardSetup, CreateCredentialsTest */
</script>
74 changes: 74 additions & 0 deletions webauthn/getcredential-abort.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>WebAuthn navigator.credentials.get() abort Tests</title>
<meta name="timeout" content="long">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src=helpers.js></script>
<body></body>
<script>
"use strict";

virtualAuthenticatorPromiseTest(async t => {
const abortController = new AbortController();
const signal = abortController.signal;
const promise = navigator.credentials.get({
publicKey: {
challenge: new Uint8Array(),
allowCredentials: [{
id: (await createCredential()).rawId,
type: "public-key",
}]
},
signal: signal,
});
abortController.abort();
return promise_rejects_dom(t, "AbortError", promise);
}, {
protocol: "ctap1/u2f",
transport: "usb",
}, "navigator.credentials.get() abort without reason");

virtualAuthenticatorPromiseTest(async t => {
const abortController = new AbortController();
const signal = abortController.signal;
const promise = navigator.credentials.get({
publicKey: {
challenge: new Uint8Array(),
allowCredentials: [{
id: (await createCredential()).rawId,
type: "public-key",
}]
},
signal: signal,
});
abortController.abort("CustomError");
return promise_rejects_exactly(t, "CustomError", promise);
}, {
protocol: "ctap1/u2f",
transport: "usb",
}, "navigator.credentials.get() abort reason");

virtualAuthenticatorPromiseTest(async t => {
const abortController = new AbortController();
const signal = abortController.signal;
const promise = navigator.credentials.get({
publicKey: {
challenge: new Uint8Array(),
allowCredentials: [{
id: (await createCredential()).rawId,
type: "public-key",
}]
},
signal: signal,
});
abortController.abort(new Error('error'));
return promise_rejects_js(t, Error, promise);
}, {
protocol: "ctap1/u2f",
transport: "usb",
}, "navigator.credentials.get() abort reason with Error");

</script>

0 comments on commit d42d172

Please sign in to comment.