summaryrefslogtreecommitdiffstats
path: root/dom/u2f/tests/frame_override_request.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /dom/u2f/tests/frame_override_request.html
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/u2f/tests/frame_override_request.html')
-rw-r--r--dom/u2f/tests/frame_override_request.html87
1 files changed, 87 insertions, 0 deletions
diff --git a/dom/u2f/tests/frame_override_request.html b/dom/u2f/tests/frame_override_request.html
new file mode 100644
index 0000000000..176bcf086f
--- /dev/null
+++ b/dom/u2f/tests/frame_override_request.html
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<head>
+ <title>Test for overriding U2F requests</title>
+ <script type="text/javascript" src="frame_utils.js"></script>
+ <script type="text/javascript" src="u2futil.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+ <h1>Test for overriding U2F requests</h1>
+ <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1420906">Mozilla Bug 1420906</a>
+
+ <script class="testbody" type="text/javascript">
+ "use strict";
+
+ // Last request status.
+ let status = "";
+
+ // Start a new MakeCredential() request.
+ async function requestMakeCredential(status_value) {
+ let appId = window.location.origin;
+ let challenge = crypto.getRandomValues(new Uint8Array(16));
+
+ let request = {
+ version: "U2F_V2",
+ challenge: bytesToBase64UrlSafe(challenge),
+ };
+
+ u2f.register(appId, [request], [], result => {
+ local_ok(result.errorCode, "request aborted");
+ status = status_value;
+ });
+
+ // Wait a tick to let the statemachine start.
+ await Promise.resolve();
+ }
+
+ // Start a new GetAssertion() request.
+ async function requestGetAssertion(status_value) {
+ let appId = window.location.origin;
+ let challenge = crypto.getRandomValues(new Uint8Array(16));
+ let keyHandle = crypto.getRandomValues(new Uint8Array(16));
+
+ let key = {
+ version: "U2F_V2",
+ keyHandle: bytesToBase64UrlSafe(keyHandle)
+ };
+
+ u2f.sign(appId, bytesToBase64UrlSafe(challenge), [key], result => {
+ local_ok(result.errorCode, "request aborted");
+ status = status_value;
+ });
+
+ // Wait a tick to let the statemachine start.
+ await Promise.resolve();
+ }
+
+ // Test that .create() and .get() requests override any pending requests.
+ (async function () {
+ // Request a new credential.
+ await requestMakeCredential("aborted1");
+
+ // Request another credential, the new request will abort.
+ await requestMakeCredential("aborted2");
+ local_is(status, "aborted2", "second request aborted");
+
+ // Request an assertion, the new request will still abort.
+ await requestGetAssertion("aborted3");
+ local_is(status, "aborted3", "third request aborted");
+
+ // Request another assertion, this fourth request will abort.
+ await requestGetAssertion("aborted4");
+ local_is(status, "aborted4", "fourth request aborted");
+
+ // Request another credential, the fifth request will still abort. Why
+ // do we keep trying? Well, the test originally looked like this, and
+ // let's face it, it's kinda funny.
+ await requestMakeCredential("aborted5");
+ local_is(status, "aborted5", "fifth request aborted");
+
+ local_finished();
+ })();
+ </script>
+
+</body>
+</html>