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

Side by Side Diff: LayoutTests/crypto/subtle/clone-rsaHashedKey-public.html

Issue 958353003: [WebCrypto] Move cloneKey test to respective algorithm directory (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 <script src="resources/common.js"></script>
6 <script src="resources/keys.js"></script>
7 </head>
8 <body>
9 <p id="description"></p>
10 <div id="console"></div>
11
12 <script>
13 description("Tests structured cloning of RSA public keys (with a hash)");
14
15 jsTestIsAsync = true;
16
17 // Tests the 12 permutations of keys generated by:
18 // kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossible KeyData x kPossibleHashAlgorithms
19 //
20 // For practical reasons these tests are not exhaustive.
21
22 var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5'];
23 var kPossibleExtractable = [true, false];
24 var kPossibleKeyUsages = [[], ['verify']];
25 var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
26
27 var kPossibleKeyData = [
28 kKeyData.rsa2,
29 kKeyData.rsa3
30 ];
31
32 function runTest(algorithmName, hashName, extractable, keyUsages, keyData)
33 {
34 var importData = hexStringToUint8Array(keyData.spki);
35 var importAlgorithm = { name: algorithmName, hash: {name: hashName} };
36
37 var results = {};
38
39 return crypto.subtle.importKey('spki', importData, importAlgorithm, extracta ble, keyUsages).then(function(importedKey) {
40 results.importedKey = importedKey;
41 importedKey.extraProperty = 'hi';
42 return cloneKey(importedKey);
43 }).then(function(clonedKey) {
44 results.clonedKey = clonedKey;
45 if (extractable)
46 return crypto.subtle.exportKey('spki', clonedKey);
47 return null;
48 }).then(function(clonedKeyData) {
49 importedKey = results.importedKey;
50 clonedKey = results.clonedKey;
51
52 shouldEvaluateAs("importedKey.extraProperty", "hi");
53 shouldEvaluateAs("importedKey.type", "public");
54 shouldEvaluateAs("importedKey.extractable", extractable);
55 shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
56 shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusL engthBits);
57 bytesShouldMatchHexString("importedKey.algorithm.publicExponent", keyDat a.publicExponent, importedKey.algorithm.publicExponent);
58 shouldEvaluateAs("importedKey.algorithm.hash.name", hashName);
59 shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(","));
60
61 shouldNotBe("importedKey", "clonedKey");
62
63 shouldBeUndefined("clonedKey.extraProperty");
64 shouldEvaluateAs("clonedKey.type", "public");
65 shouldEvaluateAs("clonedKey.extractable", extractable);
66 shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
67 shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLen gthBits);
68 bytesShouldMatchHexString("clonedKey.algorithm.publicExponent", keyData. publicExponent, clonedKey.algorithm.publicExponent);
69 shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName);
70 shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(","));
71
72 logSerializedKey(importedKey);
73
74 if (extractable)
75 bytesShouldMatchHexString("Cloned key exported data", keyData.spki, clonedKeyData);
76
77 debug("");
78 });
79 }
80
81 var lastPromise = Promise.resolve(null);
82
83 kPossibleAlgorithms.forEach(function(algorithmName) {
84 kPossibleExtractable.forEach(function(extractable) {
85 kPossibleKeyUsages.forEach(function(keyUsages) {
86 kPossibleKeyData.forEach(function(keyData) {
87 kPossibleHashAlgorithms.forEach(function(hashName) {
88 lastPromise = lastPromise.then(runTest.bind(null, algorithmN ame, hashName, extractable, keyUsages, keyData));
89 });
90 });
91 });
92 });
93 });
94
95 lastPromise.then(finishJSTest, failAndFinishJSTest);
96
97 </script>
98
99 </body>
100 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698