Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: LayoutTests/crypto/hmac-export-key.html

Issue 770363002: [WebCrypto] Crypto tests updated to use KeyUsage (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../resources/js-test.js"></script> 4 <script src="../resources/js-test.js"></script>
5 <script src="resources/common.js"></script> 5 <script src="resources/common.js"></script>
6 </head> 6 </head>
7 <body> 7 <body>
8 <p id="description"></p> 8 <p id="description"></p>
9 <div id="console"></div> 9 <div id="console"></div>
10 10
11 <script> 11 <script>
12 description("Test exporting an AES key."); 12 description("Test exporting an AES key.");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 var extractable = true; 16 var extractable = true;
17 var nonExtractable = false; 17 var nonExtractable = false;
18 18
19 var jwkKey = { 19 var jwkKey = {
20 "kty": "oct", 20 "kty": "oct",
21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs" 21 "k": "ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs"
22 }; 22 };
23 23
24 debug("Importing a JWK key..."); 24 debug("Importing a JWK key...");
25 crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: "SHA-256"} } , extractable, ["sign", "verify"]).then(function(result) { 25 crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: "SHA-256"} } , extractable, ["sign", "verify"]).then(function(result) {
26 key = result; 26 key = result;
27 console.log(JSON.stringify(result));
27 28
28 return crypto.subtle.exportKey(null, key); 29 return crypto.subtle.exportKey(null, key);
29 }).then(failAndFinishJSTest, function(result) { 30 }).then(failAndFinishJSTest, function(result) {
30 logError(result); 31 logError(result);
31 return crypto.subtle.exportKey(undefined, key); 32 return crypto.subtle.exportKey(undefined, key);
32 }).then(failAndFinishJSTest, function(result) { 33 }).then(failAndFinishJSTest, function(result) {
33 logError(result); 34 logError(result);
34 return crypto.subtle.exportKey({}, key); 35 return crypto.subtle.exportKey({}, key);
35 }).then(failAndFinishJSTest, function(result) { 36 }).then(failAndFinishJSTest, function(result) {
36 logError(result); 37 logError(result);
(...skipping 18 matching lines...) Expand all
55 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'"); 56 shouldBe("exportedJWK.k", "'ahjkn-_387fgnsibf23qsvahjkn-_387fgnsibf23qs'");
56 shouldBe("exportedJWK.alg", "'HS256'"); 57 shouldBe("exportedJWK.alg", "'HS256'");
57 shouldBe("exportedJWK.ext", "true"); 58 shouldBe("exportedJWK.ext", "true");
58 shouldBe("exportedJWK.use", "undefined"); 59 shouldBe("exportedJWK.use", "undefined");
59 shouldBe("exportedJWK.key_ops", "['sign', 'verify']"); 60 shouldBe("exportedJWK.key_ops", "['sign', 'verify']");
60 61
61 debug("\nImporting a key that's not extractable..."); 62 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 return crypto.subtle.importKey("jwk", jwkKey, { name: "HMAC", hash: {name: " SHA-256"} }, nonExtractable, ["sign", "verify"]);
63 }, failAndFinishJSTest).then(function(result) { 64 }, failAndFinishJSTest).then(function(result) {
64 key = result; 65 key = result;
65 66 console.log(JSON.stringify(result));
66 debug("\nTrying to export as raw..."); 67 debug("\nTrying to export as raw...");
67 return crypto.subtle.exportKey("raw", key); 68 return crypto.subtle.exportKey("raw", key);
68 }).then(function(result) { 69 }).then(function(result) {
69 testFailed("Promise wasn't rejected"); 70 testFailed("Promise wasn't rejected");
70 finishJSTest(); 71 finishJSTest();
71 }, function(result) { 72 }, function(result) {
72 logError(result); 73 logError(result);
73 testPassed("Rejected, as expected"); 74 testPassed("Rejected, as expected");
74 75
75 debug("Trying to export as jwk..."); 76 debug("Trying to export as jwk...");
76 return crypto.subtle.exportKey("jwk", key); 77 return crypto.subtle.exportKey("jwk", key);
77 }).then(function(result) { 78 }).then(function(result) {
78 testFailed("Promise wasn't rejected"); 79 testFailed("Promise wasn't rejected");
79 finishJSTest(); 80 finishJSTest();
80 }, function(result) { 81 }, function(result) {
81 logError(result); 82 logError(result);
82 testPassed("Rejected, as expected"); 83 testPassed("Rejected, as expected");
83 84
84 finishJSTest(); 85 finishJSTest();
85 }); 86 });
86 </script> 87 </script>
87 88
88 </body> 89 </body>
89 </html> 90 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698