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

Side by Side Diff: components/webcrypto/algorithms/aes_cbc_unittest.cc

Issue 2889163002: Remove raw DictionaryValue::Set in //components (Closed)
Patch Set: Nits Created 3 years, 6 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits.h> 5 #include <limits.h>
6 #include <stddef.h> 6 #include <stddef.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility>
10
9 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
10 #include "base/values.h" 13 #include "base/values.h"
11 #include "components/webcrypto/algorithm_dispatch.h" 14 #include "components/webcrypto/algorithm_dispatch.h"
12 #include "components/webcrypto/algorithms/test_helpers.h" 15 #include "components/webcrypto/algorithms/test_helpers.h"
13 #include "components/webcrypto/crypto_data.h" 16 #include "components/webcrypto/crypto_data.h"
14 #include "components/webcrypto/status.h" 17 #include "components/webcrypto/status.h"
15 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 18 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
16 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" 19 #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h"
17 20
18 namespace webcrypto { 21 namespace webcrypto {
19 22
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 0, &key)); 215 0, &key));
213 } 216 }
214 217
215 // If key_ops is specified but empty, no key usages are allowed for the key. 218 // If key_ops is specified but empty, no key usages are allowed for the key.
216 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) { 219 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkEmptyKeyOps) {
217 blink::WebCryptoKey key; 220 blink::WebCryptoKey key;
218 base::DictionaryValue dict; 221 base::DictionaryValue dict;
219 dict.SetString("kty", "oct"); 222 dict.SetString("kty", "oct");
220 dict.SetBoolean("ext", false); 223 dict.SetBoolean("ext", false);
221 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); 224 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg");
222 dict.Set("key_ops", new base::ListValue); // Takes ownership. 225 dict.Set("key_ops", base::MakeUnique<base::ListValue>());
223 226
224 // The JWK does not contain encrypt usages. 227 // The JWK does not contain encrypt usages.
225 EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(), 228 EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(),
226 ImportKeyJwkFromDict( 229 ImportKeyJwkFromDict(
227 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), 230 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc),
228 false, blink::kWebCryptoKeyUsageEncrypt, &key)); 231 false, blink::kWebCryptoKeyUsageEncrypt, &key));
229 232
230 // The JWK does not contain sign usage (nor is it applicable). 233 // The JWK does not contain sign usage (nor is it applicable).
231 EXPECT_EQ(Status::ErrorCreateKeyBadUsages(), 234 EXPECT_EQ(Status::ErrorCreateKeyBadUsages(),
232 ImportKeyJwkFromDict( 235 ImportKeyJwkFromDict(
(...skipping 20 matching lines...) Expand all
253 ImportKeyJwkFromDict( 256 ImportKeyJwkFromDict(
254 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), 257 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc),
255 false, blink::kWebCryptoKeyUsageVerify, &key)); 258 false, blink::kWebCryptoKeyUsageVerify, &key));
256 } 259 }
257 260
258 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) { 261 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsEncryptDecrypt) {
259 blink::WebCryptoKey key; 262 blink::WebCryptoKey key;
260 base::DictionaryValue dict; 263 base::DictionaryValue dict;
261 dict.SetString("kty", "oct"); 264 dict.SetString("kty", "oct");
262 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); 265 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg");
263 base::ListValue* key_ops = new base::ListValue; 266 base::ListValue* key_ops =
264 dict.Set("key_ops", key_ops); // Takes ownership. 267 dict.SetList("key_ops", base::MakeUnique<base::ListValue>());
265 268
266 key_ops->AppendString("encrypt"); 269 key_ops->AppendString("encrypt");
267 270
268 EXPECT_EQ(Status::Success(), 271 EXPECT_EQ(Status::Success(),
269 ImportKeyJwkFromDict( 272 ImportKeyJwkFromDict(
270 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), 273 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc),
271 false, blink::kWebCryptoKeyUsageEncrypt, &key)); 274 false, blink::kWebCryptoKeyUsageEncrypt, &key));
272 275
273 EXPECT_EQ(blink::kWebCryptoKeyUsageEncrypt, key.Usages()); 276 EXPECT_EQ(blink::kWebCryptoKeyUsageEncrypt, key.Usages());
274 277
(...skipping 16 matching lines...) Expand all
291 EXPECT_EQ(blink::kWebCryptoKeyUsageEncrypt | blink::kWebCryptoKeyUsageDecrypt, 294 EXPECT_EQ(blink::kWebCryptoKeyUsageEncrypt | blink::kWebCryptoKeyUsageDecrypt,
292 key.Usages()); 295 key.Usages());
293 } 296 }
294 297
295 // Test failure if input usage is NOT a strict subset of the JWK usage. 298 // Test failure if input usage is NOT a strict subset of the JWK usage.
296 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) { 299 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkKeyOpsNotSuperset) {
297 blink::WebCryptoKey key; 300 blink::WebCryptoKey key;
298 base::DictionaryValue dict; 301 base::DictionaryValue dict;
299 dict.SetString("kty", "oct"); 302 dict.SetString("kty", "oct");
300 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); 303 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg");
301 base::ListValue* key_ops = new base::ListValue; 304 auto key_ops = base::MakeUnique<base::ListValue>();
302 dict.Set("key_ops", key_ops); // Takes ownership.
303
304 key_ops->AppendString("encrypt"); 305 key_ops->AppendString("encrypt");
306 dict.Set("key_ops", std::move(key_ops));
305 307
306 EXPECT_EQ( 308 EXPECT_EQ(
307 Status::ErrorJwkKeyopsInconsistent(), 309 Status::ErrorJwkKeyopsInconsistent(),
308 ImportKeyJwkFromDict( 310 ImportKeyJwkFromDict(
309 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), false, 311 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), false,
310 blink::kWebCryptoKeyUsageEncrypt | blink::kWebCryptoKeyUsageDecrypt, 312 blink::kWebCryptoKeyUsageEncrypt | blink::kWebCryptoKeyUsageDecrypt,
311 &key)); 313 &key));
312 } 314 }
313 315
314 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) { 316 TEST_F(WebCryptoAesCbcTest, ImportKeyJwkUseEnc) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 359
358 // Fail on inconsistent key_ops - asking for "encrypt" however JWK contains 360 // Fail on inconsistent key_ops - asking for "encrypt" however JWK contains
359 // only "foo". 361 // only "foo".
360 TEST_F(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) { 362 TEST_F(WebCryptoAesCbcTest, ImportJwkKeyOpsLacksUsages) {
361 blink::WebCryptoKey key; 363 blink::WebCryptoKey key;
362 364
363 base::DictionaryValue dict; 365 base::DictionaryValue dict;
364 dict.SetString("kty", "oct"); 366 dict.SetString("kty", "oct");
365 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg"); 367 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg");
366 368
367 base::ListValue* key_ops = new base::ListValue; 369 auto key_ops = base::MakeUnique<base::ListValue>();
368 // Note: the following call makes dict assume ownership of key_ops.
369 dict.Set("key_ops", key_ops);
370 key_ops->AppendString("foo"); 370 key_ops->AppendString("foo");
371 dict.Set("key_ops", std::move(key_ops));
371 EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(), 372 EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(),
372 ImportKeyJwkFromDict( 373 ImportKeyJwkFromDict(
373 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc), 374 dict, CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc),
374 false, blink::kWebCryptoKeyUsageEncrypt, &key)); 375 false, blink::kWebCryptoKeyUsageEncrypt, &key));
375 } 376 }
376 377
377 TEST_F(WebCryptoAesCbcTest, ImportExportJwk) { 378 TEST_F(WebCryptoAesCbcTest, ImportExportJwk) {
378 const blink::WebCryptoAlgorithm algorithm = 379 const blink::WebCryptoAlgorithm algorithm =
379 CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc); 380 CreateAlgorithm(blink::kWebCryptoAlgorithmIdAesCbc);
380 381
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 EXPECT_EQ(public_key_spki, unwrapped_public_key_spki); 562 EXPECT_EQ(public_key_spki, unwrapped_public_key_spki);
562 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8); 563 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8);
563 564
564 EXPECT_NE(public_key_spki, wrapped_public_key); 565 EXPECT_NE(public_key_spki, wrapped_public_key);
565 EXPECT_NE(private_key_pkcs8, wrapped_private_key); 566 EXPECT_NE(private_key_pkcs8, wrapped_private_key);
566 } 567 }
567 568
568 } // namespace 569 } // namespace
569 570
570 } // namespace webcrypto 571 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/url_matcher/url_matcher_factory_unittest.cc ('k') | components/webcrypto/algorithms/aes_kw_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698