[WebAuthn] Move the mock testing entrance to Internals
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-get-failure-hid.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[get]] failure cases with a mock hid authenticator.</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script src="./resources/util.js"></script>
6 <script>
7     // Default mock configuration. Tests need to override if they need different configuration.
8     if (window.internals)
9         internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload" } });
10
11     promise_test(t => {
12         const options = {
13             publicKey: {
14                 challenge: asciiToUint8Array("123456"),
15                 allowCredentials: [
16                     { type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["nfc"] },
17                     { type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["ble"] },
18                     { type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["internal"] }
19                 ],
20                 timeout: 10
21             }
22         };
23
24         return promiseRejects(t, "NotAllowedError", navigator.credentials.get(options), "Operation timed out.");
25     }, "PublicKeyCredential's [[get]] with timeout in a mock hid authenticator.");
26
27     promise_test(function(t) {
28         const options = {
29             publicKey: {
30                 challenge: asciiToUint8Array("123456")
31             }
32         };
33
34         if (window.internals)
35             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testDummyMessagePayloadBase64] } });
36         return promiseRejects(t, "UnknownError", navigator.credentials.get(options), "Unknown internal error. Error code: 255");
37     }, "PublicKeyCredential's [[get]] with malicious payload in a mock hid authenticator.");
38
39     promise_test(function(t) {
40         const options = {
41             publicKey: {
42                 challenge: asciiToUint8Array("123456"),
43                 userVerification: "required"
44             }
45         };
46
47         if (window.internals)
48             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
49         return promiseRejects(t, "UnknownError", navigator.credentials.get(options), "Unknown internal error. Error code: 43");
50     }, "PublicKeyCredential's [[get]] with unsupported options in a mock hid authenticator.");
51
52     promise_test(function(t) {
53         const options = {
54             publicKey: {
55                 challenge: asciiToUint8Array("123456")
56             }
57         };
58
59         if (window.internals)
60             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testCtapErrInvalidCredentialResponseBase64] } });
61         return promiseRejects(t, "UnknownError", navigator.credentials.get(options), "Unknown internal error. Error code: 34");
62     }, "PublicKeyCredential's [[get]] with authenticator downgrade failed in a mock hid authenticator.");
63
64     promise_test(function(t) {
65         const options = {
66             publicKey: {
67                 challenge: asciiToUint8Array("123456"),
68                 extensions: { appid: "" }
69             }
70         };
71
72         if (window.internals)
73             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", canDowngrade: true, payloadBase64: [testCtapErrInvalidCredentialResponseBase64] } });
74         return promiseRejects(t, "NotSupportedError", navigator.credentials.get(options), "Cannot convert the request to U2F command.");
75     }, "PublicKeyCredential's [[get]] with authenticator downgrade succeeded and then U2F failed in a mock hid authenticator. 2");
76 </script>