6a8c35813ee2ad727bbc56611a8b2cb90adbaf64
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-success-hid.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[create]] success 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 src="./resources/cbor.js"></script>
7 <script>
8     // Default mock configuration. Tests need to override if they need different configuration.
9     if (window.testRunner)
10         testRunner.setWebAuthenticationMockConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: [testCreationMessageBase64] } });
11
12     promise_test(t => {
13         const options = {
14             publicKey: {
15                 rp: {
16                     name: "localhost",
17                 },
18                 user: {
19                     name: "John Appleseed",
20                     id: Base64URL.parse(testUserhandleBase64),
21                     displayName: "Appleseed",
22                 },
23                 challenge: Base64URL.parse("MTIzNDU2"),
24                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
25                 timeout: 100
26             }
27         };
28
29         return navigator.credentials.create(options).then(credential => {
30             checkCtapMakeCredentialResult(credential);
31         });
32     }, "PublicKeyCredential's [[create]] with minimum options in a mock hid authenticator.");
33
34     promise_test(t => {
35         const options = {
36             publicKey: {
37                 rp: {
38                     name: "localhost",
39                 },
40                 user: {
41                     name: "John Appleseed",
42                     id: Base64URL.parse(testUserhandleBase64),
43                     displayName: "Appleseed",
44                 },
45                 challenge: Base64URL.parse("MTIzNDU2"),
46                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
47                 authenticatorSelection: { authenticatorAttachment: "cross-platform" },
48                 timeout: 100
49             }
50         };
51
52         return navigator.credentials.create(options).then(credential => {
53             checkCtapMakeCredentialResult(credential);
54         });
55     }, "PublicKeyCredential's [[create]] with authenticatorSelection { 'cross-platform' } in a mock hid authenticator.");
56
57     promise_test(t => {
58         const options = {
59             publicKey: {
60                 rp: {
61                     name: "localhost",
62                 },
63                 user: {
64                     name: "John Appleseed",
65                     id: Base64URL.parse(testUserhandleBase64),
66                     displayName: "Appleseed",
67                 },
68                 challenge: Base64URL.parse("MTIzNDU2"),
69                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
70                 authenticatorSelection: { requireResidentKey: false },
71                 timeout: 100
72             }
73         };
74
75         return navigator.credentials.create(options).then(credential => {
76             checkCtapMakeCredentialResult(credential);
77         });
78     }, "PublicKeyCredential's [[create]] with requireResidentKey { false } in a mock hid authenticator.");
79
80     promise_test(t => {
81         const options = {
82             publicKey: {
83                 rp: {
84                     name: "localhost",
85                 },
86                 user: {
87                     name: "John Appleseed",
88                     id: Base64URL.parse(testUserhandleBase64),
89                     displayName: "Appleseed",
90                 },
91                 challenge: Base64URL.parse("MTIzNDU2"),
92                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
93                 authenticatorSelection: { userVerification: "preferred" },
94                 timeout: 100
95             }
96         };
97
98         return navigator.credentials.create(options).then(credential => {
99             checkCtapMakeCredentialResult(credential);
100         });
101     }, "PublicKeyCredential's [[create]] with userVerification { 'preferred' } in a mock hid authenticator.");
102
103     promise_test(t => {
104         const options = {
105             publicKey: {
106                 rp: {
107                     name: "localhost",
108                 },
109                 user: {
110                     name: "John Appleseed",
111                     id: Base64URL.parse(testUserhandleBase64),
112                     displayName: "Appleseed",
113                 },
114                 challenge: Base64URL.parse("MTIzNDU2"),
115                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
116                 authenticatorSelection: { userVerification: "discouraged" },
117                 timeout: 100
118             }
119         };
120
121         return navigator.credentials.create(options).then(credential => {
122             checkCtapMakeCredentialResult(credential);
123         });
124     }, "PublicKeyCredential's [[create]] with userVerification { 'discouraged' } in a mock hid authenticator.");
125
126     promise_test(t => {
127         const options = {
128             publicKey: {
129                 rp: {
130                     name: "localhost",
131                 },
132                 user: {
133                     name: "John Appleseed",
134                     id: Base64URL.parse(testUserhandleBase64),
135                     displayName: "Appleseed",
136                 },
137                 challenge: Base64URL.parse("MTIzNDU2"),
138                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
139                 authenticatorSelection: { authenticatorAttachment: "cross-platform", requireResidentKey: false, userVerification: "preferred" },
140                 timeout: 100
141             }
142         };
143
144         return navigator.credentials.create(options).then(credential => {
145             checkCtapMakeCredentialResult(credential);
146         });
147     }, "PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.");
148
149     promise_test(t => {
150         const options = {
151             publicKey: {
152                 rp: {
153                     name: "localhost",
154                 },
155                 user: {
156                     name: "John Appleseed",
157                     id: Base64URL.parse(testUserhandleBase64),
158                     displayName: "Appleseed",
159                 },
160                 challenge: Base64URL.parse("MTIzNDU2"),
161                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
162                 timeout: 100
163             }
164         };
165
166         promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "This request has been voided by a new request.");
167         return navigator.credentials.create(options).then(credential => {
168             checkCtapMakeCredentialResult(credential);
169         });
170     }, "PublicKeyCredential's [[create]] with two consecutive requests.");
171
172     promise_test(t => {
173         const options = {
174             publicKey: {
175                 rp: {
176                     name: "localhost",
177                 },
178                 user: {
179                     name: "John Appleseed",
180                     id: Base64URL.parse(testUserhandleBase64),
181                     displayName: "Appleseed",
182                 },
183                 challenge: Base64URL.parse("MTIzNDU2"),
184                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
185                 attestation: "none",
186                 timeout: 100
187             }
188         };
189
190         return navigator.credentials.create(options).then(credential => {
191             checkCtapMakeCredentialResult(credential);
192         });
193     }, "PublicKeyCredential's [[create]] with none attestation in a mock hid authenticator.");
194
195     promise_test(t => {
196         const options = {
197             publicKey: {
198                 rp: {
199                     name: "localhost",
200                 },
201                 user: {
202                     name: "John Appleseed",
203                     id: Base64URL.parse(testUserhandleBase64),
204                     displayName: "Appleseed",
205                 },
206                 challenge: Base64URL.parse("MTIzNDU2"),
207                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
208                 attestation: "direct",
209                 timeout: 100
210             }
211         };
212
213         return navigator.credentials.create(options).then(credential => {
214             checkCtapMakeCredentialResult(credential, false);
215         });
216     }, "PublicKeyCredential's [[create]] with direct attestation in a mock hid authenticator.");
217
218     promise_test(t => {
219         const options = {
220             publicKey: {
221                 rp: {
222                     name: "localhost",
223                 },
224                 user: {
225                     name: "John Appleseed",
226                     id: Base64URL.parse(testUserhandleBase64),
227                     displayName: "Appleseed",
228                 },
229                 challenge: Base64URL.parse("MTIzNDU2"),
230                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
231                 attestation: "indirect",
232                 timeout: 100
233             }
234         };
235
236         return navigator.credentials.create(options).then(credential => {
237             checkCtapMakeCredentialResult(credential, false);
238         });
239     }, "PublicKeyCredential's [[create]] with indirect attestation in a mock hid authenticator.");
240
241     // When RP ID is not google.com, googleLegacyAppidSupport should not have any effects.
242     promise_test(t => {
243         const options = {
244             publicKey: {
245                 rp: {
246                     name: "localhost",
247                 },
248                 user: {
249                     name: "John Appleseed",
250                     id: Base64URL.parse(testUserhandleBase64),
251                     displayName: "Appleseed",
252                 },
253                 challenge: Base64URL.parse("MTIzNDU2"),
254                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
255                 extensions: { googleLegacyAppidSupport: true },
256                 timeout: 100
257             }
258         };
259
260         return navigator.credentials.create(options).then(credential => {
261             checkCtapMakeCredentialResult(credential);
262         });
263     }, "PublicKeyCredential's [[create]] with googleLegacyAppidSupport extension in a mock hid authenticator.");
264
265     promise_test(t => {
266         const options = {
267             publicKey: {
268                 rp: {
269                     name: "localhost",
270                 },
271                 user: {
272                     name: "John Appleseed",
273                     id: Base64URL.parse(testUserhandleBase64),
274                     displayName: "Appleseed",
275                 },
276                 challenge: Base64URL.parse("MTIzNDU2"),
277                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
278                 extensions: { googleLegacyAppidSupport: true, appid: "" },
279                 timeout: 100
280             }
281         };
282
283         return navigator.credentials.create(options).then(credential => {
284             checkCtapMakeCredentialResult(credential);
285         });
286     }, "PublicKeyCredential's [[create]] with googleLegacyAppidSupport and appid extensions in a mock hid authenticator.");
287 </script>