| Index: LayoutTests/crypto/normalize-algorithm.html
|
| diff --git a/LayoutTests/crypto/normalize-algorithm.html b/LayoutTests/crypto/normalize-algorithm.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4d9ea45816d62bbcae8b4aafedc765722c010f94
|
| --- /dev/null
|
| +++ b/LayoutTests/crypto/normalize-algorithm.html
|
| @@ -0,0 +1,116 @@
|
| +<!DOCTYPE html>
|
| +<html>
|
| +<head>
|
| +<script src="../fast/js/resources/js-test-pre.js"></script>
|
| +</head>
|
| +<body>
|
| +<p id="description"></p>
|
| +<div id="console"></div>
|
| +
|
| +<script>
|
| +description("Tests algorithm normalization.");
|
| +
|
| +// -------------------------------
|
| +// Helpers to return a normalized algorithm identifier.
|
| +// -------------------------------
|
| +
|
| +function normalizeDigest(algorithmIdentifier) {
|
| + return crypto.subtle.digest(algorithmIdentifier).algorithm;
|
| +}
|
| +
|
| +function normalizeEncrypt(algorithmIdentifier) {
|
| + // TODO(eroman): Use a valid key.
|
| + var key;
|
| + return crypto.subtle.encrypt(algorithmIdentifier, key).algorithm;
|
| +}
|
| +
|
| +// -------------------------------
|
| +// 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 })");
|
| +
|
| +</script>
|
| +
|
| +<script src="../fast/js/resources/js-test-post.js"></script>
|
| +</body>
|
| +</html>
|
|
|