[WebAuthn] Move the mock testing entrance to Internals
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-get-success-u2f.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[get]] success cases with a mock u2f 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(t => {
8         const options = {
9             publicKey: {
10                 challenge: Base64URL.parse("MTIzNDU2"),
11                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
12                 timeout: 100
13             }
14         };
15
16         if (window.internals)
17             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fSignResponse] } });
18         return navigator.credentials.get(options).then(credential => {
19             return checkU2fGetAssertionResult(credential);
20         });
21     }, "PublicKeyCredential's [[get]] with minimum options in a mock hid authenticator.");
22
23     promise_test(t => {
24         const options = {
25             publicKey: {
26                 challenge: Base64URL.parse("MTIzNDU2"),
27                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
28                 timeout: 100
29             }
30         };
31
32         if (window.internals)
33             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fSignResponse] } });
34         return navigator.credentials.get(options).then(credential => {
35             return checkU2fGetAssertionResult(credential);
36         });
37     }, "PublicKeyCredential's [[get]] with more allow credentials in a mock hid authenticator.");
38
39     promise_test(t => {
40         const options = {
41             publicKey: {
42                 challenge: Base64URL.parse("MTIzNDU2"),
43                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
44                 timeout: 500
45             }
46         };
47
48         if (window.internals)
49             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fSignResponse] } });
50         return navigator.credentials.get(options).then(credential => {
51             return checkU2fGetAssertionResult(credential);
52         });
53     }, "PublicKeyCredential's [[get]] with test of user presence in a mock hid authenticator.");
54
55     // With AppID extension
56     promise_test(t => {
57         const options = {
58             publicKey: {
59                 challenge: Base64URL.parse("MTIzNDU2"),
60                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
61                 timeout: 100,
62                 extensions: { }
63             }
64         };
65
66         if (window.internals)
67             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fSignResponse] } });
68         return navigator.credentials.get(options).then(credential => {
69             return checkU2fGetAssertionResult(credential);
70         });
71     }, "PublicKeyCredential's [[get]] with empty extensions in a mock hid authenticator.");
72
73     promise_test(t => {
74         const options = {
75             publicKey: {
76                 challenge: Base64URL.parse("MTIzNDU2"),
77                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
78                 timeout: 100,
79                 extensions: { appid: "https://localhost:666/appid" }
80             }
81         };
82
83         if (window.internals)
84             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fSignResponse] } });
85         return navigator.credentials.get(options).then(credential => {
86             return checkU2fGetAssertionResult(credential);
87         });
88     }, "PublicKeyCredential's [[get]] with same site AppID but not used in a mock hid authenticator.");
89
90     promise_test(t => {
91         const options = {
92             publicKey: {
93                 challenge: Base64URL.parse("MTIzNDU2"),
94                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
95                 timeout: 100,
96                 extensions: { appid: "" }
97             }
98         };
99
100         if (window.internals)
101             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fSignResponse] } });
102         return navigator.credentials.get(options).then(credential => {
103             return checkU2fGetAssertionResult(credential, true);
104         });
105     }, "PublicKeyCredential's [[get]] with empty AppID in a mock hid authenticator.");
106
107     // FIXME: Sub domains need to be tested as well. However, localhost has no sub domains.
108     promise_test(t => {
109         const options = {
110             publicKey: {
111                 challenge: Base64URL.parse("MTIzNDU2"),
112                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
113                 timeout: 100,
114                 extensions: { appid: "https://localhost:666/appid" }
115             }
116         };
117
118         if (window.internals)
119             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fSignResponse] } });
120         return navigator.credentials.get(options).then(credential => {
121             return checkU2fGetAssertionResult(credential, true, "7eabc5cc3251bdc59115ef87b5f7ee74cb03747e39ba8341748565cc129c0719");
122         });
123     }, "PublicKeyCredential's [[get]] with an AppID in a mock hid authenticator.");
124
125     promise_test(t => {
126         const options = {
127             publicKey: {
128                 challenge: Base64URL.parse("MTIzNDU2"),
129                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
130                 timeout: 100,
131                 extensions: { appid: "" }
132             }
133         };
134
135         if (window.internals)
136             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fSignResponse] } });
137         return navigator.credentials.get(options).then(credential => {
138             return checkU2fGetAssertionResult(credential);
139         });
140     }, "PublicKeyCredential's [[get]] with multiple credentials and AppID is not used in a mock hid authenticator.");
141
142     promise_test(t => {
143         const options = {
144             publicKey: {
145                 challenge: Base64URL.parse("MTIzNDU2"),
146                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
147                 timeout: 100,
148                 extensions: { appid: "" }
149             }
150         };
151
152         if (window.internals)
153             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fSignResponse] } });
154         return navigator.credentials.get(options).then(credential => {
155             return checkU2fGetAssertionResult(credential, true);
156         });
157     }, "PublicKeyCredential's [[get]] with multiple credentials and AppID is used in a mock hid authenticator.");
158
159     promise_test(t => {
160         const options = {
161             publicKey: {
162                 challenge: Base64URL.parse("MTIzNDU2"),
163                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
164                 timeout: 100,
165                 extensions: { appid: "https://localhost:666/appid" }
166             }
167         };
168
169         if (window.internals)
170             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", canDowngrade: true, payloadBase64: [testCtapErrInvalidCredentialResponseBase64, testU2fSignResponse] } });
171         return navigator.credentials.get(options).then(credential => {
172             return checkU2fGetAssertionResult(credential);
173         });
174     }, "PublicKeyCredential's [[get]] with downgraded authenticator in a mock hid authenticator.");
175
176     promise_test(t => {
177         const options = {
178             publicKey: {
179                 challenge: Base64URL.parse("MTIzNDU2"),
180                 allowCredentials: [{ type: "public-key", id: Base64URL.parse(testU2fCredentialIdBase64) }],
181                 timeout: 100,
182                 extensions: { appid: "https://localhost:666/appid" }
183             }
184         };
185
186         if (window.internals)
187             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", canDowngrade: true, payloadBase64: [testCtapErrInvalidCredentialResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fSignResponse] } });
188         return navigator.credentials.get(options).then(credential => {
189             return checkU2fGetAssertionResult(credential, true, "7eabc5cc3251bdc59115ef87b5f7ee74cb03747e39ba8341748565cc129c0719");
190         });
191     }, "PublicKeyCredential's [[get]] with downgraded authenticator in a mock hid authenticator. (AppID)");
192
193 </script>