Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / crypto / subtle / hmac / export-key.html
blob62c149fd3e094930ade61288ec3625b137aa7e4b
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script src="../resources/common.js"></script>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
11 <script>
12 description("Test exporting an AES key.");
14 jsTestIsAsync = true;
16 var extractable = true;
17 var nonExtractable = false;
19 var jwkKey = {
20 "kty": "oct",
21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
24 debug("Importing a JWK key...");
25 crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: "SHA-256"} }, extractable, ["sign", "verify"]).then(function(result) {
26 key = result;
28 return crypto.subtle.exportKey(null, key);
29 }).then(failAndFinishJSTest, function(result) {
30 logError(result);
31 return crypto.subtle.exportKey(undefined, key);
32 }).then(failAndFinishJSTest, function(result) {
33 logError(result);
34 return crypto.subtle.exportKey({}, key);
35 }).then(failAndFinishJSTest, function(result) {
36 logError(result);
37 return crypto.subtle.exportKey("", key);
38 }).then(failAndFinishJSTest, function(result) {
39 logError(result);
40 return crypto.subtle.exportKey("foobar", key);
41 }).then(failAndFinishJSTest, function(result) {
42 logError(result);
44 debug("Exporting the key as raw data...");
45 return crypto.subtle.exportKey("raw", key);
46 }, failAndFinishJSTest).then(function(result) {
47 exportedData = result;
48 shouldBe("bytesToHexString(new Uint8Array(exportedData))", "'6a18e49feff7f3b7e09ec89b7f6deab2f6a18e49feff7f3b7e09ec89b7f6deab'");
50 debug("Exporting the key as JWK...");
51 return crypto.subtle.exportKey("jwk", key);
52 }).then(function(result) {
53 exportedJWK = result;
54 shouldBe("exportedJWK.kty", "'oct'");
55 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'");
56 shouldBe("exportedJWK.alg", "'HS256'");
57 shouldBe("exportedJWK.ext", "true");
58 shouldBe("exportedJWK.use", "undefined");
59 shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
61 debug("\nImporting a key that's not extractable...");
62 return crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: "SHA-256"} }, nonExtractable, ["sign", "verify"]);
63 }, failAndFinishJSTest).then(function(result) {
64 key = result;
66 debug("\nTrying to export as raw...");
67 return crypto.subtle.exportKey("raw", key);
68 }).then(function(result) {
69 testFailed("Promise wasn't rejected");
70 finishJSTest();
71 }, function(result) {
72 logError(result);
73 testPassed("Rejected, as expected");
75 debug("Trying to export as jwk...");
76 return crypto.subtle.exportKey("jwk", key);
77 }).then(function(result) {
78 testFailed("Promise wasn't rejected");
79 finishJSTest();
80 }, function(result) {
81 logError(result);
82 testPassed("Rejected, as expected");
84 finishJSTest();
85 });
86 </script>
88 </body>
89 </html>