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

Unified Diff: content/child/webcrypto/shared_crypto_unittest.cc

Issue 308183003: [webcrypto] Don't fail JWK import if key_ops contains an unrecognized value. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/child/webcrypto/webcrypto_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/shared_crypto_unittest.cc
diff --git a/content/child/webcrypto/shared_crypto_unittest.cc b/content/child/webcrypto/shared_crypto_unittest.cc
index c10f5b1a140e650f4f418d1e64dc96dc8cf92836..81877f651b1d0c65b006ed5448abb625fc618c99 100644
--- a/content/child/webcrypto/shared_crypto_unittest.cc
+++ b/content/child/webcrypto/shared_crypto_unittest.cc
@@ -1397,16 +1397,55 @@ TEST_F(SharedCryptoTest, ImportJwkFailures) {
ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key));
RestoreJwkOctDictionary(&dict);
- // Fail on invalid key_ops (wrong element value).
+ // Fail on inconsistent key_ops - asking for "encrypt" however JWK contains
+ // only "foo".
base::ListValue* key_ops = new base::ListValue;
// Note: the following call makes dict assume ownership of key_ops.
dict.Set("key_ops", key_ops);
key_ops->AppendString("foo");
- EXPECT_EQ(Status::ErrorJwkUnrecognizedKeyop(),
+ EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(),
ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key));
RestoreJwkOctDictionary(&dict);
}
+// Import a JWK with unrecognized values for "key_ops".
+TEST_F(SharedCryptoTest, ImportJwkUnrecognizedKeyOps) {
+ blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
+ blink::WebCryptoAlgorithm algorithm =
+ CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc);
+ blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt;
+
+ base::DictionaryValue dict;
+ RestoreJwkOctDictionary(&dict);
+
+ base::ListValue* key_ops = new base::ListValue;
+ dict.Set("key_ops", key_ops);
+ key_ops->AppendString("foo");
+ key_ops->AppendString("bar");
+ key_ops->AppendString("baz");
+ key_ops->AppendString("encrypt");
+ EXPECT_EQ(Status::Success(),
+ ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key));
+}
+
+// Import a JWK with a value in key_ops array that is not a string.
+TEST_F(SharedCryptoTest, ImportJwkNonStringKeyOp) {
+ blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
+ blink::WebCryptoAlgorithm algorithm =
+ CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc);
+ blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt;
+
+ base::DictionaryValue dict;
+ RestoreJwkOctDictionary(&dict);
+
+ base::ListValue* key_ops = new base::ListValue;
+ dict.Set("key_ops", key_ops);
+ key_ops->AppendString("encrypt");
+ key_ops->AppendInteger(3);
+ EXPECT_EQ(Status::ErrorJwkPropertyWrongType("key_ops[1]", "string"),
+ ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key));
+}
+
TEST_F(SharedCryptoTest, ImportJwkOctFailures) {
base::DictionaryValue dict;
RestoreJwkOctDictionary(&dict);
« no previous file with comments | « no previous file | content/child/webcrypto/webcrypto_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698