[WebAuthN] Support CTAP HID authenticators on macOS
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-get-success-hid.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[get]] 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>
7     // Default mock configuration. Tests need to override if they need different configuration.
8     if (window.testRunner)
9         testRunner.setWebAuthenticationMockConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", payloadBase64: testAssertionMessageBase64 } });
10
11     function checkResult(credential)
12     {
13         // Check respond
14         assert_array_equals(Base64URL.parse(credential.id), Base64URL.parse(testHidCredentialIdBase64));
15         assert_equals(credential.type, 'public-key');
16         assert_array_equals(new Uint8Array(credential.rawId), Base64URL.parse(testHidCredentialIdBase64));
17         assert_equals(bytesToASCIIString(credential.response.clientDataJSON), '{"type":"webauthn.get","challenge":"MTIzNDU2","origin":"https://localhost:9443","hashAlgorithm":"SHA-256"}');
18         assert_equals(bytesToHexString(credential.response.userHandle), "00");
19
20         // Check authData
21         const authData = decodeAuthData(new Uint8Array(credential.response.authenticatorData), false);
22         assert_equals(bytesToHexString(authData.rpIdHash), "46cc7fb9679d55b2db9092e1c8d9e5e1d02b7580f0b4812c770962e1e48f5ad8");
23         assert_equals(authData.flags, 1);
24         assert_equals(authData.counter, 80);
25     }
26
27     promise_test(t => {
28         const options = {
29             publicKey: {
30                 challenge: Base64URL.parse("MTIzNDU2")
31             }
32         };
33
34         return navigator.credentials.get(options).then(credential => {
35             return checkResult(credential);
36         });
37     }, "PublicKeyCredential's [[get]] with minimum options in a mock hid authenticator.");
38
39     promise_test(t => {
40         const options = {
41             publicKey: {
42                 challenge: Base64URL.parse("MTIzNDU2"),
43                 allowCredentials: [
44                     { type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["usb"] }
45                 ]
46             }
47         };
48
49         return navigator.credentials.get(options).then(credential => {
50             return checkResult(credential);
51         });
52     }, "PublicKeyCredential's [[get]] with matched allow credentials in a mock hid authenticator.");
53
54     promise_test(t => {
55         const options = {
56             publicKey: {
57                 challenge: Base64URL.parse("MTIzNDU2"),
58                 userVerification: "preferred"
59             }
60         };
61
62         return navigator.credentials.get(options).then(credential => {
63             return checkResult(credential);
64         });
65     }, "PublicKeyCredential's [[get]] with userVerification { preferred } in a mock hid authenticator.");
66
67     promise_test(t => {
68         const options = {
69             publicKey: {
70                 challenge: Base64URL.parse("MTIzNDU2"),
71                 userVerification: "discouraged"
72             }
73         };
74
75         return navigator.credentials.get(options).then(credential => {
76             return checkResult(credential);
77         });
78     }, "PublicKeyCredential's [[get]] with userVerification { discouraged } in a mock hid authenticator.");
79
80     promise_test(t => {
81         const options = {
82             publicKey: {
83                 challenge: Base64URL.parse("MTIzNDU2"),
84                 allowCredentials: [
85                     { type: "public-key", id: Base64URL.parse(testHidCredentialIdBase64), transports: ["usb"] }
86                 ],
87                 userVerification: "preferred"
88             }
89         };
90
91         return navigator.credentials.get(options).then(credential => {
92             return checkResult(credential);
93         });
94     }, "PublicKeyCredential's [[get]] with mixed options in a mock hid authenticator.");
95 </script>