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

Side by Side Diff: LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js

Issue 958353003: [WebCrypto] Move cloneKey test to respective algorithm directory (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated as per the review Created 5 years, 9 months 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 if (self.importScripts) {
2 <html> 2 importScripts('common.js');
3 <head> 3 }
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>
10 4
11 <script> 5 function runCloneSymmetricTests(algorithmName, extractable, keyUsages, keyData, hashName, keyHasLength)
12 description("Tests structured cloning of AES keys");
13
14 jsTestIsAsync = true;
15
16 // Tests the 32 permutations of keys generated by:
17 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData
18 //
19 // For practical reasons these tests are not exhaustive.
20
21 var k128BitData = "30112233445566778899aabbccddeeff"
22 var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0 e0f";
23
24 var kPossibleAlgorithms = ['AES-CBC', 'AES-GCM'];
25 var kPossibleExtractable = [true, false];
26 var kPossibleKeyUsages = [['encrypt'], ['decrypt', 'wrapKey'], ['encrypt', 'wrap Key', 'unwrapKey']];
27 var kPossibleKeyData = [k128BitData, k256BitData];
28
29 function runTest(algorithmName, extractable, keyUsages, keyData)
30 { 6 {
31 var importData = hexStringToUint8Array(keyData); 7 var importData = hexStringToUint8Array(keyData);
32 var importAlgorithm = { name: algorithmName }; 8 var importAlgorithm = { name: algorithmName };
9 if (hashName)
10 importAlgorithm.hash = { name: hashName };
33 11
34 var results = {}; 12 var results = {};
35 13
36 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) { 14 return crypto.subtle.importKey('raw', importData, importAlgorithm, extractab le, keyUsages).then(function(importedKey) {
37 results.importedKey = importedKey; 15 results.importedKey = importedKey;
38 importedKey.extraProperty = 'hi'; 16 importedKey.extraProperty = 'hi';
39 return cloneKey(importedKey); 17 return cloneKey(importedKey);
40 }).then(function(clonedKey) { 18 }).then(function(clonedKey) {
41 results.clonedKey = clonedKey; 19 results.clonedKey = clonedKey;
42 if (extractable) 20 if (extractable)
43 return crypto.subtle.exportKey('raw', clonedKey); 21 return crypto.subtle.exportKey('raw', clonedKey);
44 return null; 22 return null;
45 }).then(function(clonedKeyData) { 23 }).then(function(clonedKeyData) {
46 importedKey = results.importedKey; 24 importedKey = results.importedKey;
47 clonedKey = results.clonedKey; 25 clonedKey = results.clonedKey;
48 26
49 shouldEvaluateAs("importedKey.extraProperty", "hi"); 27 shouldEvaluateAs("importedKey.extraProperty", "hi");
50 shouldEvaluateAs("importedKey.type", "secret"); 28 shouldEvaluateAs("importedKey.type", "secret");
51 shouldEvaluateAs("importedKey.extractable", extractable); 29 shouldEvaluateAs("importedKey.extractable", extractable);
52 shouldEvaluateAs("importedKey.algorithm.name", algorithmName); 30 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
53 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8); 31 if (keyHasLength)
32 shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8);
33 if (algorithmName === "HMAC")
eroman 2015/03/10 00:11:06 I suggest doing a case-insensitive match here: v
34 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
54 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); 35 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
55 36
56 shouldNotBe("importedKey", "clonedKey"); 37 shouldNotBe("importedKey", "clonedKey");
57 38
58 shouldBeUndefined("clonedKey.extraProperty"); 39 shouldBeUndefined("clonedKey.extraProperty");
59 shouldEvaluateAs("clonedKey.type", "secret"); 40 shouldEvaluateAs("clonedKey.type", "secret");
60 shouldEvaluateAs("clonedKey.extractable", extractable); 41 shouldEvaluateAs("clonedKey.extractable", extractable);
61 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName); 42 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
62 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8); 43 if (keyHasLength)
44 shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8 );
45 if (algorithmName === "HMAC")
eroman 2015/03/10 00:11:06 if (expectingHash) so the algorithm name comparis
46 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
63 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); 47 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
64 48
65 logSerializedKey(importedKey); 49 logSerializedKey(importedKey);
66 50
67 if (extractable) 51 if (extractable)
68 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData); 52 bytesShouldMatchHexString("Cloned key exported data", keyData, clone dKeyData);
69 53
70 debug(""); 54 debug("");
71 }); 55 });
72 } 56 }
73 57
74 var lastPromise = Promise.resolve(null); 58 function testCloneSymmetricKeys(algorithmName, possibleHashAlgorithms, possibleE xtractable, possibleKeyUsages, possibleKeyData, keyHasLength)
59 {
60 var lastPromise = Promise.resolve(null);
75 61
76 kPossibleAlgorithms.forEach(function(algorithmName) { 62 possibleHashAlgorithms.forEach(function(hashName) {
77 kPossibleExtractable.forEach(function(extractable) { 63 possibleExtractable.forEach(function(extractable) {
78 kPossibleKeyUsages.forEach(function(keyUsages) { 64 possibleKeyUsages.forEach(function(keyUsages) {
79 kPossibleKeyData.forEach(function(keyData) { 65 possibleKeyData.forEach(function(keyData) {
80 lastPromise = lastPromise.then(runTest.bind(null, algorithmName, extractable, keyUsages, keyData)); 66 lastPromise = lastPromise.then(runCloneSymmetricTests.bind(n ull, algorithmName, extractable, keyUsages, keyData, hashName, keyHasLength));
67 });
81 }); 68 });
82 }); 69 });
83 }); 70 });
84 });
85 71
86 lastPromise.then(finishJSTest, failAndFinishJSTest); 72 return lastPromise;
87 73 }
88 </script>
89
90 </body>
91 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698