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