aed97c25661629db9ac7038e1717c44848ef6ad4
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-failure-u2f-silent.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[create]] failure 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(function(t) {
8         const options = {
9             publicKey: {
10                 rp: {
11                     name: "example.com"
12                 },
13                 user: {
14                     name: "John Appleseed",
15                     id: asciiToUint8Array("123456"),
16                     displayName: "John",
17                 },
18                 challenge: asciiToUint8Array("123456"),
19                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
20                 timeout: 10
21             }
22         };
23
24         if (window.testRunner)
25             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: ["AQ=="] } });
26         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
27     }, "PublicKeyCredential's [[create]] with malformed APDU payload in a mock hid authenticator.");
28
29     promise_test(function(t) {
30         const options = {
31             publicKey: {
32                 rp: {
33                     name: "example.com"
34                 },
35                 user: {
36                     name: "John Appleseed",
37                     id: asciiToUint8Array("123456"),
38                     displayName: "John",
39                 },
40                 challenge: asciiToUint8Array("123456"),
41                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
42                 timeout: 10
43             }
44         };
45
46         if (window.testRunner)
47             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduNoErrorOnlyResponseBase64] } });
48         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
49     }, "PublicKeyCredential's [[create]] with malformed U2F register response in a mock hid authenticator.");
50
51     promise_test(function(t) {
52         const options = {
53             publicKey: {
54                 rp: {
55                     name: "example.com"
56                 },
57                 user: {
58                     name: "John Appleseed",
59                     id: asciiToUint8Array("123456"),
60                     displayName: "John",
61                 },
62                 challenge: asciiToUint8Array("123456"),
63                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
64                 timeout: 10
65             }
66         };
67
68         if (window.testRunner)
69             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduInsNotSupportedOnlyResponseBase64] } });
70         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
71     }, "PublicKeyCredential's [[create]] with register command error in a mock hid authenticator.");
72
73     promise_test(function(t) {
74         const options = {
75             publicKey: {
76                 rp: {
77                     name: "example.com"
78                 },
79                 user: {
80                     name: "John Appleseed",
81                     id: asciiToUint8Array("123456"),
82                     displayName: "John",
83                 },
84                 challenge: asciiToUint8Array("123456"),
85                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
86                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
87                 timeout: 10
88             }
89         };
90
91         if (window.testRunner)
92             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduNoErrorOnlyResponseBase64, testU2fApduInsNotSupportedOnlyResponseBase64] } });
93         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
94     }, "PublicKeyCredential's [[create]] with bogus command error in a mock hid authenticator.");
95
96     promise_test(function(t) {
97         const options = {
98             publicKey: {
99                 rp: {
100                     name: "example.com"
101                 },
102                 user: {
103                     name: "John Appleseed",
104                     id: asciiToUint8Array("123456"),
105                     displayName: "John",
106                 },
107                 challenge: asciiToUint8Array("123456"),
108                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
109                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
110             }
111         };
112
113         if (window.testRunner)
114             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduNoErrorOnlyResponseBase64, testU2fApduNoErrorOnlyResponseBase64] } });
115         return promiseRejects(t, "InvalidStateError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the authenticator.");
116     }, "PublicKeyCredential's [[create]] with first exclude credential matched in a mock hid authenticator.");
117
118     // Match the second exclude credential.
119     promise_test(function(t) {
120         const options = {
121             publicKey: {
122                 rp: {
123                     name: "example.com"
124                 },
125                 user: {
126                     name: "John Appleseed",
127                     id: asciiToUint8Array("123456"),
128                     displayName: "John",
129                 },
130                 challenge: asciiToUint8Array("123456"),
131                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
132                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }, { type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }], // The content doesn't matter.
133             }
134         };
135
136         if (window.testRunner)
137             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduWrongDataOnlyResponseBase64, testU2fApduNoErrorOnlyResponseBase64, testU2fApduNoErrorOnlyResponseBase64] } });
138         return promiseRejects(t, "InvalidStateError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the authenticator.");
139     }, "PublicKeyCredential's [[create]] with second exclude credential matched in a mock hid authenticator.");
140
141     promise_test(function(t) {
142         const options = {
143             publicKey: {
144                 rp: {
145                     name: "example.com"
146                 },
147                 user: {
148                     name: "John Appleseed",
149                     id: asciiToUint8Array("123456"),
150                     displayName: "John",
151                 },
152                 challenge: asciiToUint8Array("123456"),
153                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
154                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }],
155                 timeout: 10
156             }
157         };
158
159         if (window.testRunner)
160             testRunner.setWebAuthenticationMockConfiguration({ silentFailure: true, hid: { stage: "request", subStage: "msg", error: "malicious-payload", isU2f: true, payloadBase64: [testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fApduConditionsNotSatisfiedOnlyResponseBase64, testU2fApduNoErrorOnlyResponseBase64] } });
161         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Operation timed out.");
162     }, "PublicKeyCredential's [[create]] with first exclude credential matched in a mock hid authenticator. Test of user presence.");
163 </script>