[WebAuthn] Move the mock testing entrance to Internals
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-failure-hid.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     // Default mock configuration. Tests need to override it if they need different configuration.
8     if (window.internals)
9         internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload" } });
10
11     promise_test(function(t) {
12         const options = {
13             publicKey: {
14                 rp: {
15                     name: "example.com"
16                 },
17                 user: {
18                     name: "John Appleseed",
19                     id: asciiToUint8Array("123456"),
20                     displayName: "John",
21                 },
22                 challenge: asciiToUint8Array("123456"),
23                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
24                 timeout: 10,
25                 authenticatorSelection: { authenticatorAttachment: "platform" }
26             }
27         };
28
29         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
30     }, "PublicKeyCredential's [[create]] with timeout in a mock hid authenticator.");
31
32     promise_test(function(t) {
33         const options = {
34             publicKey: {
35                 rp: {
36                     name: "example.com"
37                 },
38                 user: {
39                     name: "John Appleseed",
40                     id: asciiToUint8Array("123456"),
41                     displayName: "John",
42                 },
43                 challenge: asciiToUint8Array("123456"),
44                 pubKeyCredParams: [{ type: "public-key", alg: -7 }]
45             }
46         };
47
48         if (window.internals)
49             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testDummyMessagePayloadBase64] } });
50         return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error. Error code: 255");
51     }, "PublicKeyCredential's [[create]] with malicious payload in a mock hid authenticator.");
52
53     promise_test(function(t) {
54         const options = {
55             publicKey: {
56                 rp: {
57                     name: "example.com"
58                 },
59                 user: {
60                     name: "John Appleseed",
61                     id: asciiToUint8Array("123456"),
62                     displayName: "John",
63                 },
64                 challenge: asciiToUint8Array("123456"),
65                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
66                 authenticatorSelection: { requireResidentKey: true }
67             }
68         };
69
70         if (window.internals)
71             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
72         return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error. Error code: 43");
73     }, "PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator.");
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: { userVerification: "required" }
89             }
90         };
91
92         if (window.internals)
93             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
94         return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error. Error code: 43");
95     }, "PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator. 2");
96
97     promise_test(function(t) {
98         const options = {
99             publicKey: {
100                 rp: {
101                     name: "example.com"
102                 },
103                 user: {
104                     name: "John Appleseed",
105                     id: asciiToUint8Array("123456"),
106                     displayName: "John",
107                 },
108                 challenge: asciiToUint8Array("123456"),
109                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
110                 timeout: 10,
111                 authenticatorSelection: { authenticatorAttachment: "platform", requireResidentKey: true, userVerification: "required" }
112             }
113         };
114
115         if (window.internals)
116             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
117         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
118     }, "PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.");
119
120     promise_test(function(t) {
121         const options = {
122             publicKey: {
123                 rp: {
124                     name: "example.com"
125                 },
126                 user: {
127                     name: "John Appleseed",
128                     id: asciiToUint8Array("123456"),
129                     displayName: "John",
130                 },
131                 challenge: asciiToUint8Array("123456"),
132                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
133                 authenticatorSelection: { authenticatorAttachment: "cross-platform", requireResidentKey: true, userVerification: "required" }
134             }
135         };
136
137         if (window.internals)
138             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
139         return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error. Error code: 43");
140     }, "PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator. 2");
141
142     promise_test(function(t) {
143         const options = {
144             publicKey: {
145                 rp: {
146                     name: "example.com"
147                 },
148                 user: {
149                     name: "John Appleseed",
150                     id: asciiToUint8Array("123456"),
151                     displayName: "John",
152                 },
153                 challenge: asciiToUint8Array("123456"),
154                 pubKeyCredParams: [{ type: "public-key", alg: -7 }]
155             }
156         };
157
158         if (window.internals)
159             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "malicious-payload", payloadBase64: [testCtapErrCredentialExcludedOnlyResponseBase64] } });
160         return promiseRejects(t, "InvalidStateError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the authenticator.");
161     }, "PublicKeyCredential's [[create]] with InvalidStateError in a mock hid authenticator.");
162 </script>