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

Side by Side Diff: LayoutTests/crypto/importKey.html

Issue 39093002: [webcrypto] Add some more layouttests for crypto.subtle.digest() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/crypto/encrypt-decrypt.html ('k') | LayoutTests/crypto/resources/common.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../fast/js/resources/js-test-pre.js"></script> 4 <script src="../fast/js/resources/js-test-pre.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("Tests cypto.subtle.importKey."); 12 description("Tests cypto.subtle.importKey.");
13 13
14 jsTestIsAsync = true; 14 jsTestIsAsync = true;
15 15
16 aesCbc = {name: 'aes-cbc'}; 16 aesCbc = {name: 'aes-cbc'};
17 17
18 Promise.resolve(null).then(function() { 18 Promise.resolve(null).then(function() {
19 keyFormat = "raw"; 19 keyFormat = "raw";
20 data = asciiToArrayBuffer("raw bytes for key"); 20 data = asciiToUint8Array("raw bytes for key");
21 algorithm = { name: 'hmac', hash: { name: 'sha-256' } }; 21 algorithm = { name: 'hmac', hash: { name: 'sha-256' } };
22 extractable = true; 22 extractable = true;
23 // Note there are duplicates 23 // Note there are duplicates
24 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign']; 24 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign'];
25 25
26 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 26 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
27 }).then(function(result) { 27 }).then(function(result) {
28 key = result; 28 key = result;
29 shouldBe("key.type", "'secret'") 29 shouldBe("key.type", "'secret'")
30 shouldBe("key.extractable", "true") 30 shouldBe("key.extractable", "true")
31 shouldBe("key.algorithm.name", "'HMAC'") 31 shouldBe("key.algorithm.name", "'HMAC'")
32 shouldBe("key.algorithm.hash.name", "'SHA-256'") 32 shouldBe("key.algorithm.hash.name", "'SHA-256'")
33 shouldBe("key.usages.join(',')", "'encrypt,sign'") 33 shouldBe("key.usages.join(',')", "'encrypt,sign'")
34 34
35 // Same test as above, but with an keyUsages, and AES-CBC. 35 // Same test as above, but with an keyUsages, and AES-CBC.
36 keyFormat = "raw"; 36 keyFormat = "raw";
37 data = asciiToArrayBuffer("16 bytes of key!"); 37 data = asciiToUint8Array("16 bytes of key!");
38 algorithm = aesCbc; 38 algorithm = aesCbc;
39 extractable = true; 39 extractable = true;
40 keyUsages = []; 40 keyUsages = [];
41 41
42 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 42 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
43 }).then(function(result) { 43 }).then(function(result) {
44 key = result; 44 key = result;
45 shouldBe("key.type", "'secret'") 45 shouldBe("key.type", "'secret'")
46 shouldBe("key.extractable", "true") 46 shouldBe("key.extractable", "true")
47 shouldBe("key.algorithm.name", "'AES-CBC'") 47 shouldBe("key.algorithm.name", "'AES-CBC'")
48 shouldBe("key.usages.join(',')", "''") 48 shouldBe("key.usages.join(',')", "''")
49 49
50 // Same test as above, but with extractable = false. 50 // Same test as above, but with extractable = false.
51 keyFormat = "raw"; 51 keyFormat = "raw";
52 data = asciiToArrayBuffer("16 bytes of key!"); 52 data = asciiToUint8Array("16 bytes of key!");
53 algorithm = aesCbc; 53 algorithm = aesCbc;
54 extractable = false; 54 extractable = false;
55 keyUsages = []; 55 keyUsages = [];
56 56
57 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 57 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
58 }).then(function(result) { 58 }).then(function(result) {
59 key = result; 59 key = result;
60 shouldBe("key.type", "'secret'") 60 shouldBe("key.type", "'secret'")
61 shouldBe("key.extractable", "false") 61 shouldBe("key.extractable", "false")
62 shouldBe("key.algorithm.name", "'AES-CBC'") 62 shouldBe("key.algorithm.name", "'AES-CBC'")
63 shouldBe("key.usages.join(',')", "''") 63 shouldBe("key.usages.join(',')", "''")
64 64
65 // Same test as above, but with key.type of public. 65 // Same test as above, but with key.type of public.
66 keyFormat = "raw"; 66 keyFormat = "raw";
67 data = asciiToArrayBuffer("16 bytes of key!"); 67 data = asciiToUint8Array("16 bytes of key!");
68 algorithm = aesCbc; 68 algorithm = aesCbc;
69 extractable = false; 69 extractable = false;
70 keyUsages = []; 70 keyUsages = [];
71 71
72 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 72 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
73 }).then(function(result) { 73 }).then(function(result) {
74 key = result; 74 key = result;
75 shouldBe("key.type", "'secret'") 75 shouldBe("key.type", "'secret'")
76 shouldBe("key.extractable", "false") 76 shouldBe("key.extractable", "false")
77 shouldBe("key.algorithm.name", "'AES-CBC'") 77 shouldBe("key.algorithm.name", "'AES-CBC'")
78 shouldBe("key.usages.join(',')", "''") 78 shouldBe("key.usages.join(',')", "''")
79 79
80 // Same test as above, but with keyFormat = spki 80 // Same test as above, but with keyFormat = spki
81 keyFormat = "spki"; 81 keyFormat = "spki";
82 data = asciiToArrayBuffer("16 bytes of key!"); 82 data = asciiToUint8Array("16 bytes of key!");
83 algorithm = aesCbc; 83 algorithm = aesCbc;
84 extractable = false; 84 extractable = false;
85 keyUsages = []; 85 keyUsages = [];
86 86
87 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages); 87 return crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyU sages);
88 }).then(undefined, function(result) { 88 }).then(undefined, function(result) {
89 // TODO(eroman): Only "raw" key format is supported at the moment. 89 // TODO(eroman): Only "raw" key format is supported at the moment.
90 debug("rejected with " + result); 90 debug("rejected with " + result);
91 91
92 keyFormat = "raw"; 92 keyFormat = "raw";
93 data = asciiToArrayBuffer(""); 93 data = asciiToUint8Array("");
94 algorithm = aesCbc; 94 algorithm = aesCbc;
95 extractable = true; 95 extractable = true;
96 keyUsages = []; 96 keyUsages = [];
97 97
98 // Invalid format. 98 // Invalid format.
99 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extr actable, keyUsages)"); 99 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extr actable, keyUsages)");
100 100
101 // Invalid key usage. 101 // Invalid key usage.
102 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extractable , ['SIGN'])"); 102 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extractable , ['SIGN'])");
103 103
(...skipping 14 matching lines...) Expand all
118 118
119 // SHA-1 doesn't support the importKey operation. 119 // SHA-1 doesn't support the importKey operation.
120 shouldThrow("crypto.subtle.importKey(keyFormat, data, {name: 'sha-1'}, extra ctable, keyUsages)"); 120 shouldThrow("crypto.subtle.importKey(keyFormat, data, {name: 'sha-1'}, extra ctable, keyUsages)");
121 }).then(finishJSTest, failAndFinishJSTest); 121 }).then(finishJSTest, failAndFinishJSTest);
122 122
123 </script> 123 </script>
124 124
125 <script src="../fast/js/resources/js-test-post.js"></script> 125 <script src="../fast/js/resources/js-test-post.js"></script>
126 </body> 126 </body>
127 </html> 127 </html>
OLDNEW
« no previous file with comments | « LayoutTests/crypto/encrypt-decrypt.html ('k') | LayoutTests/crypto/resources/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698