66b5da4f3992cecf6178b7f6b63bf67e78d85236
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-failure-hid-silent.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[create]] 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    promise_test(function(t) {
8         const options = {
9             publicKey: {
10                 rp: {
11                     name: "example.com"
12                 },
13                 user: {
14                     name: "John Appleseed",
15                     id: asciiToUint8Array("123456"),
16                     displayName: "John",
17                 },
18                 challenge: asciiToUint8Array("123456"),
19                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
20                 timeout: 10
21             }
22         };
23
24         if (window.testRunner)
25             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testDummyMessagePayloadBase64] } });
26         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
27     }, "PublicKeyCredential's [[create]] with malicious payload in a mock hid authenticator.");
28
29     promise_test(function(t) {
30         const options = {
31             publicKey: {
32                 rp: {
33                     name: "example.com"
34                 },
35                 user: {
36                     name: "John Appleseed",
37                     id: asciiToUint8Array("123456"),
38                     displayName: "John",
39                 },
40                 challenge: asciiToUint8Array("123456"),
41                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
42                 authenticatorSelection: { requireResidentKey: true },
43                 timeout: 10
44             }
45         };
46
47         if (window.testRunner)
48             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
49         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
50     }, "PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator.");
51
52     promise_test(function(t) {
53         const options = {
54             publicKey: {
55                 rp: {
56                     name: "example.com"
57                 },
58                 user: {
59                     name: "John Appleseed",
60                     id: asciiToUint8Array("123456"),
61                     displayName: "John",
62                 },
63                 challenge: asciiToUint8Array("123456"),
64                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
65                 authenticatorSelection: { userVerification: "required" },
66                 timeout: 10
67             }
68         };
69
70         if (window.testRunner)
71             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
72         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
73     }, "PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator. 2");
74
75     promise_test(function(t) {
76         const options = {
77             publicKey: {
78                 rp: {
79                     name: "example.com"
80                 },
81                 user: {
82                     name: "John Appleseed",
83                     id: asciiToUint8Array("123456"),
84                     displayName: "John",
85                 },
86                 challenge: asciiToUint8Array("123456"),
87                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
88                 authenticatorSelection: { authenticatorAttachment: "cross-platform", requireResidentKey: true, userVerification: "required" },
89                 timeout: 10
90             }
91         };
92
93         if (window.testRunner)
94             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
95         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
96     }, "PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.");
97
98    promise_test(function(t) {
99        const options = {
100            publicKey: {
101                rp: {
102                    name: "example.com"
103                },
104                user: {
105                    name: "John Appleseed",
106                    id: asciiToUint8Array("123456"),
107                    displayName: "John",
108                },
109                challenge: asciiToUint8Array("123456"),
110                pubKeyCredParams: [{ type: "public-key", alg: -7 }]
111            }
112        };
113
114        if (window.testRunner)
115            testRunner.setWebAuthenticationMockConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testCtapErrCredentialExcludedOnlyResponseBase64] } });
116        return promiseRejects(t, "InvalidStateError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the authenticator.");
117    }, "PublicKeyCredential's [[create]] with InvalidStateError in a mock hid authenticator.");
118 </script>