[WebAuthN] Import a JS CBOR coder
[WebKit-https.git] / LayoutTests / http / wpt / credential-management / credentialscontainer-store-basics.https.html
1 <!DOCTYPE html>
2 <title>Credential Management API: store() basics.</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script>
6     const testES256PrivateKeyBase64 =
7         "BDj/zxSkzKgaBuS3cdWDF558of8AaIpgFpsjF/Qm1749VBJPgqUIwfhWHJ91nb7U" +
8         "PH76c0+WFOzZKslPyyFse4goGIW2R7k9VHLPEZl5nfnBgEVFh5zev+/xpHQIvuq6" +
9         "RQ==";
10     const testAttestationCertificateBase64 =
11         "MIIB6jCCAZCgAwIBAgIGAWHAxcjvMAoGCCqGSM49BAMCMFMxJzAlBgNVBAMMHkJh" +
12         "c2ljIEF0dGVzdGF0aW9uIFVzZXIgU3ViIENBMTETMBEGA1UECgwKQXBwbGUgSW5j" +
13         "LjETMBEGA1UECAwKQ2FsaWZvcm5pYTAeFw0xODAyMjMwMzM3MjJaFw0xODAyMjQw" +
14         "MzQ3MjJaMGoxIjAgBgNVBAMMGTAwMDA4MDEwLTAwMEE0OUEyMzBBMDIxM0ExGjAY" +
15         "BgNVBAsMEUJBQSBDZXJ0aWZpY2F0aW9uMRMwEQYDVQQKDApBcHBsZSBJbmMuMRMw" +
16         "EQYDVQQIDApDYWxpZm9ybmlhMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEvCje" +
17         "Pzr6Sg76XMoHuGabPaG6zjpLFL8Zd8/74Hh5PcL2Zq+o+f7ENXX+7nEXXYt0S8Ux" +
18         "5TIRw4hgbfxXQbWLEqM5MDcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBPAw" +
19         "FwYJKoZIhvdjZAgCBAowCKEGBAR0ZXN0MAoGCCqGSM49BAMCA0gAMEUCIAlK8A8I" +
20         "k43TbvKuYGHZs1DTgpTwmKTBvIUw5bwgZuYnAiEAtuJjDLKbGNJAJFMi5deEBqno" +
21         "pBTCqbfbDJccfyQpjnY=";
22     const testAttestationIssuingCACertificateBase64 =
23         "MIICIzCCAaigAwIBAgIIeNjhG9tnDGgwCgYIKoZIzj0EAwIwUzEnMCUGA1UEAwwe" +
24         "QmFzaWMgQXR0ZXN0YXRpb24gVXNlciBSb290IENBMRMwEQYDVQQKDApBcHBsZSBJ" +
25         "bmMuMRMwEQYDVQQIDApDYWxpZm9ybmlhMB4XDTE3MDQyMDAwNDIwMFoXDTMyMDMy" +
26         "MjAwMDAwMFowUzEnMCUGA1UEAwweQmFzaWMgQXR0ZXN0YXRpb24gVXNlciBTdWIg" +
27         "Q0ExMRMwEQYDVQQKDApBcHBsZSBJbmMuMRMwEQYDVQQIDApDYWxpZm9ybmlhMFkw" +
28         "EwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEoSZ/1t9eBAEVp5a8PrXacmbGb8zNC1X3" +
29         "StLI9YO6Y0CL7blHmSGmjGWTwD4Q+i0J2BY3+bPHTGRyA9jGB3MSbaNmMGQwEgYD" +
30         "VR0TAQH/BAgwBgEB/wIBADAfBgNVHSMEGDAWgBSD5aMhnrB0w/lhkP2XTiMQdqSj" +
31         "8jAdBgNVHQ4EFgQU5mWf1DYLTXUdQ9xmOH/uqeNSD80wDgYDVR0PAQH/BAQDAgEG" +
32         "MAoGCCqGSM49BAMCA2kAMGYCMQC3M360LLtJS60Z9q3vVjJxMgMcFQ1roGTUcKqv" +
33         "W+4hJ4CeJjySXTgq6IEHn/yWab4CMQCm5NnK6SOSK+AqWum9lL87W3E6AA1f2TvJ" +
34         "/hgok/34jr93nhS87tOQNdxDS8zyiqw=";
35     const testRpId = "localhost";
36     function asciiToUint8Array(str)
37     {
38         var chars = [];
39         for (var i = 0; i < str.length; ++i)
40             chars.push(str.charCodeAt(i));
41         return new Uint8Array(chars);
42     }
43
44     promise_test(async function(t) {
45         const options = {
46             publicKey: {
47                 rp: {
48                     name: "localhost",
49                 },
50                 user: {
51                     name: "John Appleseed",
52                     id: asciiToUint8Array("123456"),
53                     displayName: "Appleseed",
54                 },
55                 challenge: asciiToUint8Array("123456"),
56                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
57             }
58         };
59         // A mock attestation object
60         if (window.testRunner)
61             testRunner.setWebAuthenticationMockConfiguration({
62                 local: {
63                     acceptAuthentication: true,
64                     acceptAttestation: true,
65                     privateKeyBase64: testES256PrivateKeyBase64,
66                     userCertificateBase64: testAttestationCertificateBase64,
67                     intermediateCACertificateBase64: testAttestationIssuingCACertificateBase64
68                 }
69             });
70         const credential = await navigator.credentials.create(options);
71
72         return promise_rejects(t, "NotSupportedError",
73             navigator.credentials.store(credential)).then(() => {
74                 if (window.testRunner)
75                     testRunner.cleanUpKeychain(testRpId);
76         });
77     }, "navigator.credentials.store().");
78 </script>