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

Unified Diff: LayoutTests/crypto/normalize-algorithm.html

Issue 20914002: Revert "WebCrypto: Add the Key parameter to a number of operations." (r155013). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 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 | Source/modules/crypto/SubtleCrypto.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/crypto/normalize-algorithm.html
diff --git a/LayoutTests/crypto/normalize-algorithm.html b/LayoutTests/crypto/normalize-algorithm.html
index 9a869c0171fcb7f595dc0cc3e20a00e5efe63bbc..edea0aeb101be9723a12bf5fa69af79ffa24cf99 100644
--- a/LayoutTests/crypto/normalize-algorithm.html
+++ b/LayoutTests/crypto/normalize-algorithm.html
@@ -10,152 +10,124 @@
<script>
description("Tests algorithm normalization.");
-jsTestIsAsync = true;
-
// -------------------------------
// Helpers to return a normalized algorithm identifier.
// -------------------------------
-key = null;
-
-function normalizeDigest(algorithmIdentifier)
-{
+function normalizeDigest(algorithmIdentifier) {
return crypto.subtle.digest(algorithmIdentifier).algorithm;
}
-function normalizeEncrypt(algorithmIdentifier)
-{
+function normalizeEncrypt(algorithmIdentifier) {
+ // TODO(eroman): Use a valid key.
+ var key;
return crypto.subtle.encrypt(algorithmIdentifier, key).algorithm;
}
-function normalizeSign(algorithmIdentifier)
-{
+function normalizeSign(algorithmIdentifier) {
+ // TODO(eroman): Use a valid key.
+ var key;
return crypto.subtle.sign(algorithmIdentifier, key).algorithm;
}
-function runTests()
-{
- // -------------------------------
- // Case insensitivity of "name"
- // -------------------------------
- algorithm = normalizeDigest({name: "SHA-1"});
- shouldBe("algorithm.name", "'SHA-1'");
- algorithm = normalizeDigest({name: "sHa-256"});
- shouldBe("algorithm.name", "'SHA-256'");
-
- // -------------------------------
- // Failures if "name" is invalid
- // -------------------------------
- shouldThrow("normalizeDigest({})");
- shouldThrow("normalizeDigest({name: null})");
- shouldThrow("normalizeDigest({name: -1})");
- shouldThrow("normalizeDigest({name: ''})");
- shouldThrow("normalizeDigest({name: 'nosuchalgorithm'})");
- shouldThrow("normalizeDigest({name: '\\u0189'})");
-
- // -------------------------------
- // Failures if the algorithm identifier is not an object
- // -------------------------------
- shouldThrow("normalizeDigest(null)");
- shouldThrow("normalizeDigest(0)");
- shouldThrow("normalizeDigest(undefined)");
- shouldThrow("normalizeDigest('')");
-
- // -------------------------------
- // Skip unrecognized parameters.
- // -------------------------------
- algorithm = normalizeDigest({name: "sHa-1", noSuchParam: 3});
- shouldBeUndefined("algorithm.noSuchParam");
-
- // -------------------------------
- // Normalized algorithm COPIES all data
- // -------------------------------
- originalIv = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
- algorithm = normalizeEncrypt({ name: "aes-cbc", iv: originalIv });
-
- // Make sure it constructed the normalized result.
- shouldBe("algorithm.name", "'AES-CBC'");
- shouldBe("algorithm.iv.length", "16");
- shouldBe("algorithm.iv[3]", "3");
-
- // Mutate the original (un-normalized) algorithm. Verify that this doesn't affect the normalized output.
- originalIv[3] = 0;
- shouldBe("algorithm.iv[3]", "3");
-
- // -------------------------------
- // AES-CBC normalization failures
- // -------------------------------
-
- // The "iv" MUST be 16 bytes long.
- rawAlgorithm = {
- name: "AES-CBC",
- iv: new Uint8Array([1, 2, 3])
- };
- shouldThrow("normalizeEncrypt(rawAlgorithm)");
-
- // -------------------------------
- // Normalize a normalized algorithm (SHA-384)
- // -------------------------------
- algorithm = normalizeDigest({name: "sHa-384"});
- shouldBe("algorithm.name", "'SHA-384'");
- algorithm = normalizeDigest(algorithm);
- shouldBe("algorithm.name", "'SHA-384'");
-
- // -------------------------------
- // Normalize a normalized algorithm (AES-CBC, encrypt)
- // -------------------------------
- algorithm = normalizeEncrypt({ name: "aEs-cbc", iv: originalIv });
- // Make sure it constructed the normalized result.
- shouldBe("algorithm.name", "'AES-CBC'");
- shouldBe("algorithm.iv.length", "16");
- shouldBe("algorithm.iv[1]", "1");
- algorithm = normalizeEncrypt(algorithm);
- shouldBe("algorithm.name", "'AES-CBC'");
- shouldBe("algorithm.iv.length", "16");
- shouldBe("algorithm.iv[1]", "1");
-
- // -------------------------------
- // Unsupported operation on algorithm
- // -------------------------------
- shouldThrow("normalizeEncrypt({ name: 'SHA-1' })");
- shouldThrow("normalizeDigest({ name: 'AES-CBC', iv: originalIv })");
-
- // -------------------------------
- // Normalize HMAC
- // -------------------------------
- shouldThrow("normalizeSign({name: 'hmac'})"); // Missing "hash"
- shouldThrow("normalizeSign({name: 'hmac', hash: 'foo'})"); // Not a valid "hash"
- shouldThrow("normalizeSign({name: 'hmac', hash: { name: 'AES-CBC', iv: originalIv }})"); // Not a valid "hash"
-
- validHmacSha1 = {name: 'hmac', hash: {name: 'Sha-1'}};
- algorithm = normalizeSign(validHmacSha1);
- shouldBe("algorithm.name", "'HMAC'");
- shouldBe("algorithm.hash.name", "'SHA-1'");
-
- shouldThrow("normalizeEncrypt(validHmacSha1)"); // Not defined for encrypt()
-}
+// -------------------------------
+// Case insensitivity of "name"
+// -------------------------------
+algorithm = normalizeDigest({name: "SHA-1"});
+shouldBe("algorithm.name", "'SHA-1'");
+algorithm = normalizeDigest({name: "sHa-256"});
+shouldBe("algorithm.name", "'SHA-256'");
-function keyImported(newKey)
-{
- key = newKey;
- runTests();
- finishJSTest();
-}
+// -------------------------------
+// Failures if "name" is invalid
+// -------------------------------
+shouldThrow("normalizeDigest({})");
+shouldThrow("normalizeDigest({name: null})");
+shouldThrow("normalizeDigest({name: -1})");
+shouldThrow("normalizeDigest({name: ''})");
+shouldThrow("normalizeDigest({name: 'nosuchalgorithm'})");
+shouldThrow("normalizeDigest({name: '\\u0189'})");
-function failedKeyImport(value)
-{
- debug("Failed importing key: " + value);
- finishJSTest();
-}
+// -------------------------------
+// Failures if the algorithm identifier is not an object
+// -------------------------------
+shouldThrow("normalizeDigest(null)");
+shouldThrow("normalizeDigest(0)");
+shouldThrow("normalizeDigest(undefined)");
+shouldThrow("normalizeDigest('')");
+
+// -------------------------------
+// Skip unrecognized parameters.
+// -------------------------------
+algorithm = normalizeDigest({name: "sHa-1", noSuchParam: 3});
+shouldBeUndefined("algorithm.noSuchParam");
+
+// -------------------------------
+// Normalized algorithm COPIES all data
+// -------------------------------
+originalIv = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
+algorithm = normalizeEncrypt({ name: "aes-cbc", iv: originalIv });
+
+// Make sure it constructed the normalized result.
+shouldBe("algorithm.name", "'AES-CBC'");
+shouldBe("algorithm.iv.length", "16");
+shouldBe("algorithm.iv[3]", "3");
+
+// Mutate the original (un-normalized) algorithm. Verify that this doesn't affect the normalized output.
+originalIv[3] = 0;
+shouldBe("algorithm.iv[3]", "3");
+
+// -------------------------------
+// AES-CBC normalization failures
+// -------------------------------
+
+// The "iv" MUST be 16 bytes long.
+rawAlgorithm = {
+ name: "AES-CBC",
+ iv: new Uint8Array([1, 2, 3])
+};
+shouldThrow("normalizeEncrypt(rawAlgorithm)");
+
+// -------------------------------
+// Normalize a normalized algorithm (SHA-384)
+// -------------------------------
+algorithm = normalizeDigest({name: "sHa-384"});
+shouldBe("algorithm.name", "'SHA-384'");
+algorithm = normalizeDigest(algorithm);
+shouldBe("algorithm.name", "'SHA-384'");
+
+// -------------------------------
+// Normalize a normalized algorithm (AES-CBC, encrypt)
+// -------------------------------
+algorithm = normalizeEncrypt({ name: "aEs-cbc", iv: originalIv });
+// Make sure it constructed the normalized result.
+shouldBe("algorithm.name", "'AES-CBC'");
+shouldBe("algorithm.iv.length", "16");
+shouldBe("algorithm.iv[1]", "1");
+algorithm = normalizeEncrypt(algorithm);
+shouldBe("algorithm.name", "'AES-CBC'");
+shouldBe("algorithm.iv.length", "16");
+shouldBe("algorithm.iv[1]", "1");
+
+// -------------------------------
+// Unsupported operation on algorithm
+// -------------------------------
+shouldThrow("normalizeEncrypt({ name: 'SHA-1' })");
+shouldThrow("normalizeDigest({ name: 'AES-CBC', iv: originalIv })");
+
+// -------------------------------
+// Normalize HMAC
+// -------------------------------
+shouldThrow("normalizeSign({name: 'hmac'})"); // Missing "hash"
+shouldThrow("normalizeSign({name: 'hmac', hash: 'foo'})"); // Not a valid "hash"
+shouldThrow("normalizeSign({name: 'hmac', hash: { name: 'AES-CBC', iv: originalIv }})"); // Not a valid "hash"
-// This is a bogus key import, however the mock constructs something usable.
-keyFormat = "spki";
-data = new Uint8Array([]);
-algorithm = {name: "Sha-256"};
-extractable = false;
-keyUsages = [];
+validHmacSha1 = {name: 'hmac', hash: {name: 'Sha-1'}};
+algorithm = normalizeSign(validHmacSha1);
+shouldBe("algorithm.name", "'HMAC'");
+shouldBe("algorithm.hash.name", "'SHA-1'");
-crypto.subtle.importKey(keyFormat, data, algorithm, extractable, keyUsages).then(keyImported, failedKeyImport);
+shouldThrow("normalizeEncrypt(validHmacSha1)"); // Not defined for encrypt()
</script>
« no previous file with comments | « no previous file | Source/modules/crypto/SubtleCrypto.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698