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

Unified Diff: LayoutTests/crypto/import-aes-key-bad-length.html

Issue 206483010: [webcrypto] Refactor some layout tests. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | « LayoutTests/crypto/exportKey.html ('k') | LayoutTests/crypto/import-aes-key-bad-length-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/crypto/import-aes-key-bad-length.html
diff --git a/LayoutTests/crypto/import-aes-key-bad-length.html b/LayoutTests/crypto/import-aes-key-bad-length.html
new file mode 100644
index 0000000000000000000000000000000000000000..e9455d6dbc40671418a5b38724d3f6324072bfd2
--- /dev/null
+++ b/LayoutTests/crypto/import-aes-key-bad-length.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../resources/js-test.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Tests importing an AES key from raw with wrong length");
+
+jsTestIsAsync = true;
+
+// -------------------------------------------------
+// Failed key import.
+// -------------------------------------------------
+
+// Supported key lengths are 16 (128-bit), 32 (256-bit), 24 (192-bit),
+// Try key lengths that are off by 1 from the supported ones.
+var kUnsupportedKeyLengths = [
+ 0, 1, 15, 17, 31, 33, 23, 25, 64
+];
+
+// Not exhaustive
+var kAesAlgorithms = [
+ "AES-CBC", "AES-GCM", "AES-KW"
+];
+
+function testInvalidKeyImport(algorithmName, keyLengthBytes)
+{
+ var algorithm = {name: algorithmName};
+ var keyData = new Uint8Array(keyLengthBytes);
+
+ var usages = ['encrypt', 'decrypt'];
+ var extractable = false;
+
+ return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usages).then(function(result) {
+ debug("FAIL: Successfully imported " + algorithmName + " key of length " + keyData.byteLength + " bytes");
+ }, function(result) {
+ debug("PASS: Failed to import " + algorithmName + " key of length " + keyData.byteLength + " bytes");
+ });
+}
+
+var lastPromise = Promise.resolve(null);
+
+kAesAlgorithms.forEach(function(algorithmName) {
+ kUnsupportedKeyLengths.forEach(function(keyLengthBytes) {
+ lastPromise = lastPromise.then(testInvalidKeyImport.bind(null, algorithmName, keyLengthBytes));
+ });
+});
+
+lastPromise.then(finishJSTest, failAndFinishJSTest);
+
+</script>
+
+</body>
+</html>
« no previous file with comments | « LayoutTests/crypto/exportKey.html ('k') | LayoutTests/crypto/import-aes-key-bad-length-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698