[WebAuthN] Import a JS CBOR coder
[WebKit-https.git] / LayoutTests / http / wpt / webauthn / public-key-credential-create-failure-local.https.html
1 <!DOCTYPE html>
2 <title>Web Authentication API: PublicKeyCredential's [[create]] failure cases with a mock local 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({ local: { acceptAuthentication: false, acceptAttestation: false } });
10
11     promise_test(t => {
12         const options = {
13             publicKey: {
14                 rp: {
15                     name: "example.com"
16                 },
17                 user: {
18                     name: "John Appleseed",
19                     id: Base64URL.parse(testUserhandleBase64),
20                     displayName: "John",
21                 },
22                 challenge: asciiToUint8Array("123456"),
23                 pubKeyCredParams: [{ type: "public-key", alg: -35 }, { type: "public-key", alg: -257 }], // ES384, RS256
24             }
25         };
26         return promiseRejects(t, "NotSupportedError", navigator.credentials.create(options), "The platform attached authenticator doesn't support any provided PublicKeyCredentialParameters.");
27     }, "PublicKeyCredential's [[create]] with unsupported public key credential parameters in a mock local authenticator.");
28
29     promise_test(t => {
30         const options = {
31             publicKey: {
32                 rp: {
33                     name: "example.com"
34                 },
35                 user: {
36                     name: "John Appleseed",
37                     id: Base64URL.parse(testUserhandleBase64),
38                     displayName: "John",
39                 },
40                 challenge: asciiToUint8Array("123456"),
41                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
42                 excludeCredentials: [{ type: "public-key", id: Base64URL.parse(testCredentialIdBase64) }]
43             }
44         };
45         if (window.testRunner)
46             testRunner.addTestKeyToKeychain(testES256PrivateKeyBase64, testRpId, testUserhandleBase64);
47         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the platform attached authenticator.").then(() => {
48             if (window.testRunner)
49                 testRunner.cleanUpKeychain(testRpId);
50         });
51     }, "PublicKeyCredential's [[create]] with matched exclude credentials in a mock local authenticator.");
52
53     promise_test(t => {
54         const options = {
55             publicKey: {
56                 rp: {
57                     name: "example.com"
58                 },
59                 user: {
60                     name: "John Appleseed",
61                     id: Base64URL.parse(testUserhandleBase64),
62                     displayName: "John",
63                 },
64                 challenge: asciiToUint8Array("123456"),
65                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
66                 excludeCredentials: [
67                     { type: "public-key", id: Base64URL.parse(testCredentialIdBase64), transports: ["usb"] },
68                     { type: "public-key", id: Base64URL.parse(testCredentialIdBase64), transports: ["nfc"] },
69                     { type: "public-key", id: Base64URL.parse(testCredentialIdBase64), transports: ["ble"] },
70                     { type: "public-key", id: Base64URL.parse(testCredentialIdBase64), transports: ["internal"] }
71                 ]
72             }
73         };
74         if (window.testRunner)
75             testRunner.addTestKeyToKeychain(testES256PrivateKeyBase64, testRpId, testUserhandleBase64);
76         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "At least one credential matches an entry of the excludeCredentials list in the platform attached authenticator.").then(() => {
77             if (window.testRunner)
78                 testRunner.cleanUpKeychain(testRpId);
79         });
80     }, "PublicKeyCredential's [[create]] with matched exclude credentials in a mock local authenticator. 2nd");
81
82     promise_test(t => {
83         const options = {
84             publicKey: {
85                 rp: {
86                     name: "example.com"
87                 },
88                 user: {
89                     name: "John Appleseed",
90                     id: Base64URL.parse(testUserhandleBase64),
91                     displayName: "John",
92                 },
93                 challenge: asciiToUint8Array("123456"),
94                 pubKeyCredParams: [{ type: "public-key", alg: -7 }]
95             }
96         };
97         return promiseRejects(t, "NotAllowedError", navigator.credentials.create(options), "Couldn't get user consent.");
98     }, "PublicKeyCredential's [[create]] without user consent in a mock local authenticator.");
99
100     promise_test(t => {
101         const options = {
102             publicKey: {
103                 rp: {
104                     name: "example.com"
105                 },
106                 user: {
107                     name: "John Appleseed",
108                     id: Base64URL.parse(testUserhandleBase64),
109                     displayName: "John",
110                 },
111                 challenge: asciiToUint8Array("123456"),
112                 pubKeyCredParams: [{ type: "public-key", alg: -7 }]
113             }
114         };
115         if (window.testRunner)
116             testRunner.setWebAuthenticationMockConfiguration({ local: { acceptAuthentication: true, acceptAttestation: false } });
117         return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error.");
118     }, "PublicKeyCredential's [[create]] without attestation in a mock local authenticator.");
119
120     promise_test(t => {
121         const options = {
122             publicKey: {
123                 rp: {
124                     name: "example.com"
125                 },
126                 user: {
127                     name: "John Appleseed",
128                     id: Base64URL.parse(testUserhandleBase64),
129                     displayName: "John",
130                 },
131                 challenge: asciiToUint8Array("123456"),
132                 pubKeyCredParams: [{ type: "public-key", alg: -7 }]
133             }
134         };
135         if (window.testRunner) {
136             testRunner.setWebAuthenticationMockConfiguration({ local: { acceptAuthentication: true, acceptAttestation: false } });
137             testRunner.addTestKeyToKeychain(testES256PrivateKeyBase64, testRpId, testUserhandleBase64);
138         }
139         return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error.").then(() => {
140             if (window.testRunner)
141                 assert_false(testRunner.keyExistsInKeychain(testRpId, testUserhandleBase64));
142         });
143     }, "PublicKeyCredential's [[create]] deleting old credential in a mock local authenticator.");
144 </script>