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

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

Issue 20475004: WebCrypto: Properly normalize algorithm for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 4 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 | « no previous file | LayoutTests/crypto/importKey-expected.txt » ('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 </head> 5 </head>
6 <body> 6 <body>
7 <p id="description"></p> 7 <p id="description"></p>
8 <div id="console"></div> 8 <div id="console"></div>
9 9
10 <script> 10 <script>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 debug(" rejected with value of " + value); 44 debug(" rejected with value of " + value);
45 startNextTest(); 45 startNextTest();
46 } 46 }
47 47
48 function failHandler(value) 48 function failHandler(value)
49 { 49 {
50 testFailed(value); 50 testFailed(value);
51 startNextTest(); 51 startNextTest();
52 } 52 }
53 53
54 aesCbc = { name: 'aes-cbc' };
55
54 allTests = [ 56 allTests = [
55 function() 57 function()
56 { 58 {
57 keyFormat = "raw"; 59 keyFormat = "raw";
58 data = asciiToArrayBuffer("private"); 60 data = asciiToArrayBuffer("private");
59 algorithm = {name: "Sha-256"}; 61 algorithm = { name: 'hmac', hash: { name: 'sha-256' } };
60 extractable = true; 62 extractable = true;
61 // Note there are duplicates 63 // Note there are duplicates
62 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign']; 64 keyUsages = ['encrypt', 'encrypt', 'encrypt', 'sign'];
63 65
64 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then( 66 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
65 function(value) { 67 function(value) {
66 key = value; 68 key = value;
67 shouldBe("key.type", "'private'") 69 shouldBe("key.type", "'private'")
68 shouldBe("key.extractable", "true") 70 shouldBe("key.extractable", "true")
69 shouldBe("key.algorithm.name", "'SHA-256'") 71 shouldBe("key.algorithm.name", "'HMAC'")
72 shouldBe("key.algorithm.hash.name", "'SHA-256'")
70 shouldBe("key.usages.join(',')", "'encrypt,sign'") 73 shouldBe("key.usages.join(',')", "'encrypt,sign'")
71 74
72 startNextTest(); 75 startNextTest();
73 }, failHandler); 76 }, failHandler);
74 }, 77 },
75 78
76 // Same test as above, but with an keyUsages. 79 // Same test as above, but with an keyUsages, and AES-CBC.
77 function() 80 function()
78 { 81 {
79 keyFormat = "raw"; 82 keyFormat = "raw";
80 data = asciiToArrayBuffer("private"); 83 data = asciiToArrayBuffer("private");
81 algorithm = {name: "Sha-256"}; 84 algorithm = aesCbc;
82 extractable = true; 85 extractable = true;
83 keyUsages = []; 86 keyUsages = [];
84 87
85 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then( 88 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
86 function(value) { 89 function(value) {
87 key = value; 90 key = value;
88 shouldBe("key.type", "'private'") 91 shouldBe("key.type", "'private'")
89 shouldBe("key.extractable", "true") 92 shouldBe("key.extractable", "true")
90 shouldBe("key.algorithm.name", "'SHA-256'") 93 shouldBe("key.algorithm.name", "'AES-CBC'")
91 shouldBe("key.usages.join(',')", "''") 94 shouldBe("key.usages.join(',')", "''")
92 95
93 startNextTest(); 96 startNextTest();
94 }, failHandler); 97 }, failHandler);
95 }, 98 },
96 99
97 // Same test as above, but with extractable = false. 100 // Same test as above, but with extractable = false.
98 function() 101 function()
99 { 102 {
100 keyFormat = "raw"; 103 keyFormat = "raw";
101 data = asciiToArrayBuffer("private"); 104 data = asciiToArrayBuffer("private");
102 algorithm = {name: "Sha-256"}; 105 algorithm = aesCbc;
103 extractable = false; 106 extractable = false;
104 keyUsages = []; 107 keyUsages = [];
105 108
106 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then( 109 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
107 function(value) { 110 function(value) {
108 key = value; 111 key = value;
109 shouldBe("key.type", "'private'") 112 shouldBe("key.type", "'private'")
110 shouldBe("key.extractable", "false") 113 shouldBe("key.extractable", "false")
111 shouldBe("key.algorithm.name", "'SHA-256'") 114 shouldBe("key.algorithm.name", "'AES-CBC'")
112 shouldBe("key.usages.join(',')", "''") 115 shouldBe("key.usages.join(',')", "''")
113 116
114 startNextTest(); 117 startNextTest();
115 }, failHandler); 118 }, failHandler);
116 }, 119 },
117 120
118 // Same test as above, but with key.type of public. 121 // Same test as above, but with key.type of public.
119 function() 122 function()
120 { 123 {
121 keyFormat = "raw"; 124 keyFormat = "raw";
122 data = asciiToArrayBuffer("public"); 125 data = asciiToArrayBuffer("public");
123 algorithm = {name: "Sha-256"}; 126 algorithm = aesCbc;
124 extractable = false; 127 extractable = false;
125 keyUsages = []; 128 keyUsages = [];
126 129
127 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then( 130 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
128 function(value) { 131 function(value) {
129 key = value; 132 key = value;
130 shouldBe("key.type", "'public'") 133 shouldBe("key.type", "'public'")
131 shouldBe("key.extractable", "false") 134 shouldBe("key.extractable", "false")
132 shouldBe("key.algorithm.name", "'SHA-256'") 135 shouldBe("key.algorithm.name", "'AES-CBC'")
133 shouldBe("key.usages.join(',')", "''") 136 shouldBe("key.usages.join(',')", "''")
134 137
135 startNextTest(); 138 startNextTest();
136 }, failHandler); 139 }, failHandler);
137 }, 140 },
138 141
139 // Same test as above, but with keyFormat = spki 142 // Same test as above, but with keyFormat = spki
140 function() 143 function()
141 { 144 {
142 keyFormat = "spki"; 145 keyFormat = "spki";
143 data = asciiToArrayBuffer("public"); 146 data = asciiToArrayBuffer("public");
144 algorithm = {name: "Sha-256"}; 147 algorithm = aesCbc;
145 extractable = false; 148 extractable = false;
146 keyUsages = []; 149 keyUsages = [];
147 150
148 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then( 151 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
149 function(value) { 152 function(value) {
150 key = value; 153 key = value;
151 shouldBe("key.type", "'public'") 154 shouldBe("key.type", "'public'")
152 shouldBe("key.extractable", "false") 155 shouldBe("key.extractable", "false")
153 shouldBe("key.algorithm.name", "'SHA-256'") 156 shouldBe("key.algorithm.name", "'AES-CBC'")
154 shouldBe("key.usages.join(',')", "''") 157 shouldBe("key.usages.join(',')", "''")
155 158
156 startNextTest(); 159 startNextTest();
157 }, failHandler); 160 }, failHandler);
158 }, 161 },
159 162
160 function() 163 function()
161 { 164 {
162 keyFormat = "spki"; 165 keyFormat = "spki";
163 data = asciiToArrayBuffer("reject"); 166 data = asciiToArrayBuffer("reject");
164 algorithm = {name: "Sha-256"}; 167 algorithm = aesCbc;
165 extractable = false; 168 extractable = false;
166 keyUsages = []; 169 keyUsages = [];
167 170
168 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then( 171 crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsag es).then(
169 failHandler, 172 failHandler,
170 function(value) { 173 function(value) {
171 debug("rejected with " + value); 174 debug("rejected with " + value);
172 startNextTest(); 175 startNextTest();
173 }); 176 });
174 }, 177 },
175 178
176 function() 179 function()
177 { 180 {
178 keyFormat = "spki"; 181 keyFormat = "spki";
179 data = asciiToArrayBuffer("throw"); 182 data = asciiToArrayBuffer("throw");
180 algorithm = {name: "Sha-256"}; 183 algorithm = aesCbc;
181 extractable = false; 184 extractable = false;
182 keyUsages = []; 185 keyUsages = [];
183 186
184 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extract able, keyUsages)"); 187 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extract able, keyUsages)");
185 startNextTest(); 188 startNextTest();
186 }, 189 },
187 190
188 function() 191 function()
189 { 192 {
190 keyFormat = "raw"; 193 keyFormat = "raw";
191 data = asciiToArrayBuffer(""); 194 data = asciiToArrayBuffer("");
192 algorithm = {name: 'sha-256'}; 195 algorithm = aesCbc;
193 extractable = true; 196 extractable = true;
194 197
195 // Note contains duplicates and invalid entries. 198 // Note contains duplicates and invalid entries.
196 keyUsages = []; 199 keyUsages = [];
197 200
198 // Invalid format. 201 // Invalid format.
199 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extractable, keyUsages)"); 202 shouldThrow("crypto.subtle.importKey('invalid format', data, algorithm, extractable, keyUsages)");
200 203
201 // Invalid key usage. 204 // Invalid key usage.
202 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extract able, ['SIGN'])"); 205 shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extract able, ['SIGN'])");
203 206
204 // Undefined key usage. 207 // Undefined key usage.
205 // FIXME: http://crbug.com/262383 208 // FIXME: http://crbug.com/262383
206 //shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extra ctable, undefined)"); 209 //shouldThrow("crypto.subtle.importKey(keyFormat, data, algorithm, extra ctable, undefined)");
207 210
208 // Invalid data 211 // Invalid data
209 shouldThrow("crypto.subtle.importKey(keyFormat, [], algorithm, extractab le, keyUsages)"); 212 shouldThrow("crypto.subtle.importKey(keyFormat, [], algorithm, extractab le, keyUsages)");
210 shouldThrow("crypto.subtle.importKey(keyFormat, null, algorithm, extract able, keyUsages)"); 213 shouldThrow("crypto.subtle.importKey(keyFormat, null, algorithm, extract able, keyUsages)");
211 214
215 // Missing hash parameter for HMAC.
216 invalidHmac = { name: 'hmac' };
217 shouldThrow("crypto.subtle.importKey(keyFormat, data, invalidHmac, extra ctable, keyUsages)");
218
219 // SHA-1 doesn't support the importKey operation.
220 sha1 = { name: 'sha-1' };
221 shouldThrow("crypto.subtle.importKey(keyFormat, data, sha1, extractable, keyUsages)");
222
212 startNextTest(); 223 startNextTest();
213 }, 224 },
214 225
215 ]; 226 ];
216 227
217 // Begin! 228 // Begin!
218 startNextTest(); 229 startNextTest();
219 </script> 230 </script>
220 231
221 <script src="../fast/js/resources/js-test-post.js"></script> 232 <script src="../fast/js/resources/js-test-post.js"></script>
222 </body> 233 </body>
223 </html> 234 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/crypto/importKey-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698