[WebAuthn] Move the mock testing entrance to Internals
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-success-u2f.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[create]] 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 src="./resources/cbor.js"></script>
7 <script>
8     promise_test(t => {
9         const options = {
10             publicKey: {
11                 rp: {
12                     name: "localhost",
13                 },
14                 user: {
15                     name: "John Appleseed",
16                     id: Base64URL.parse(testUserhandleBase64),
17                     displayName: "Appleseed",
18                 },
19                 challenge: Base64URL.parse("MTIzNDU2"),
20                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
21             }
22         };
23
24         if (window.internals)
25             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
26         return navigator.credentials.create(options).then(credential => {
27             checkU2fMakeCredentialResult(credential);
28         });
29     }, "PublicKeyCredential's [[create]] with minimum options in a mock u2f authenticator.");
30
31     promise_test(t => {
32         const options = {
33             publicKey: {
34                 rp: {
35                     name: "localhost",
36                 },
37                 user: {
38                     name: "John Appleseed",
39                     id: Base64URL.parse(testUserhandleBase64),
40                     displayName: "Appleseed",
41                 },
42                 challenge: Base64URL.parse("MTIzNDU2"),
43                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
44                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
45             }
46         };
47
48         if (window.internals)
49             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fRegisterResponse] } });
50         return navigator.credentials.create(options).then(credential => {
51             checkU2fMakeCredentialResult(credential);
52         });
53     }, "PublicKeyCredential's [[create]] with excludeCredentials in a mock u2f authenticator.");
54
55     promise_test(t => {
56         const options = {
57             publicKey: {
58                 rp: {
59                     name: "localhost",
60                 },
61                 user: {
62                     name: "John Appleseed",
63                     id: Base64URL.parse(testUserhandleBase64),
64                     displayName: "Appleseed",
65                 },
66                 challenge: Base64URL.parse("MTIzNDU2"),
67                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
68                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }], // The content doesn't matter.
69             }
70         };
71
72         if (window.internals)
73             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduWrongDataOnlyResponseBase64, testU2fRegisterResponse] } });
74         return navigator.credentials.create(options).then(credential => {
75             checkU2fMakeCredentialResult(credential);
76         });
77     }, "PublicKeyCredential's [[create]] with excludeCredentials in a mock u2f authenticator. 2");
78
79     promise_test(t => {
80         const options = {
81             publicKey: {
82                 rp: {
83                     name: "localhost",
84                 },
85                 user: {
86                     name: "John Appleseed",
87                     id: Base64URL.parse(testUserhandleBase64),
88                     displayName: "Appleseed",
89                 },
90                 challenge: Base64URL.parse("MTIzNDU2"),
91                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
92             }
93         };
94
95         if (window.internals)
96             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fRegisterResponse] } });
97         return navigator.credentials.create(options).then(credential => {
98             checkU2fMakeCredentialResult(credential);
99         });
100     }, "PublicKeyCredential's [[create]] with test of user presence in a mock u2f authenticator.");
101
102     promise_test(t => {
103         const options = {
104             publicKey: {
105                 rp: {
106                     name: "localhost",
107                 },
108                 user: {
109                     name: "John Appleseed",
110                     id: Base64URL.parse(testUserhandleBase64),
111                     displayName: "Appleseed",
112                 },
113                 challenge: Base64URL.parse("MTIzNDU2"),
114                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
115                 attestation: "none",
116             }
117         };
118
119         if (window.internals)
120             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
121         return navigator.credentials.create(options).then(credential => {
122             checkU2fMakeCredentialResult(credential);
123         });
124     }, "PublicKeyCredential's [[create]] with none attestation in a mock u2f 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                 attestation: "indirect",
140             }
141         };
142
143         if (window.internals)
144             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
145         return navigator.credentials.create(options).then(credential => {
146             checkU2fMakeCredentialResult(credential, false);
147         });
148     }, "PublicKeyCredential's [[create]] with indirect attestation in a mock u2f authenticator.");
149
150     promise_test(t => {
151         const options = {
152             publicKey: {
153                 rp: {
154                     name: "localhost",
155                 },
156                 user: {
157                     name: "John Appleseed",
158                     id: Base64URL.parse(testUserhandleBase64),
159                     displayName: "Appleseed",
160                 },
161                 challenge: Base64URL.parse("MTIzNDU2"),
162                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
163                 attestation: "direct",
164             }
165         };
166
167         if (window.internals)
168             internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "success", isU2f: true, payloadBase64: [testU2fRegisterResponse] } });
169         return navigator.credentials.create(options).then(credential => {
170             checkU2fMakeCredentialResult(credential, false);
171         });
172     }, "PublicKeyCredential's [[create]] with direct attestation in a mock u2f authenticator.");
173 </script>