Add more tests for SubtleCrypto::importKey and SubtleCrypto::exportKey
[WebKit-https.git] / LayoutTests / crypto / subtle / hmac-import-jwk-key-export-jwk-key.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test-pre.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10
11 <script>
12 description("Test importing a JWK HMAC key with SHA-1 and then export it in JWK format");
13
14 jsTestIsAsync = true;
15
16 var jwkKey = {
17     kty: "oct",
18     k: "vgJ5AXWT3Fm2w_zZCRF4UVwo53rIhwqLm6b9Tq4m1c53dr94eqPlxt99yb9RCjCFDa2C56K448xe4V964xFucg",
19     alg: "HS1",
20     key_ops: ["sign", "verify"],
21     ext: true,
22 };
23 var extractable = true;
24
25 debug("Importing a key...");
26 crypto.subtle.importKey("jwk", jwkKey, {name: "hmac", hash: "sha-1"}, extractable, ["sign", "verify"]).then(function(cryptoKey) {
27     debug("Exporting a key...");
28     return crypto.subtle.exportKey("jwk", cryptoKey);
29 }).then(function(result) {
30     exportedJwkKey = result;
31
32     shouldBe("exportedJwkKey.kty", "jwkKey.kty");
33     shouldBe("exportedJwkKey.k", "jwkKey.k");
34     shouldBe("exportedJwkKey.alg", "jwkKey.alg");
35     shouldBe("exportedJwkKey.key_ops", "jwkKey.key_ops");
36     shouldBe("exportedJwkKey.ext", "jwkKey.ext");
37
38     finishJSTest();
39 });
40
41 </script>
42
43 <script src="../../resources/js-test-post.js"></script>
44 </body>
45 </html>