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

Unified Diff: LayoutTests/crypto/aes-key-algorithm-mismatch.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
Index: LayoutTests/crypto/aes-key-algorithm-mismatch.html
diff --git a/LayoutTests/crypto/exportKey.html b/LayoutTests/crypto/aes-key-algorithm-mismatch.html
similarity index 20%
copy from LayoutTests/crypto/exportKey.html
copy to LayoutTests/crypto/aes-key-algorithm-mismatch.html
index 314ef16af2b22b433abab5bfc505f63908509f3b..9d97be3c1f1b0cac349a5e49617c9a8269fbc064 100644
--- a/LayoutTests/crypto/exportKey.html
+++ b/LayoutTests/crypto/aes-key-algorithm-mismatch.html
@@ -9,35 +9,30 @@
<div id="console"></div>
<script>
-description("Tests cypto.subtle.exportKey.");
+description("Call encrypt using the wrong AES key");
jsTestIsAsync = true;
-addTask(importTestKeys().then(function(result) {
- keys = result;
+var keyData = hexStringToUint8Array("2b7e151628aed2a6abf7158809cf4f3c");
+var data = asciiToUint8Array("hello");
+var aesCbcKey = null;
- // Invalid export formats.
- shouldRejectPromiseWithNull("crypto.subtle.exportKey(3, keys.aesCbcJustDecrypt)");
- shouldRejectPromiseWithNull("crypto.subtle.exportKey(null, keys.aesCbcJustDecrypt)");
- shouldRejectPromiseWithNull("crypto.subtle.exportKey('invalid', keys.aesCbcJustDecrypt)");
+Promise.resolve(null).then(function(result) {
+ var usages = ['encrypt', 'decrypt'];
+ var extractable = false;
+ var algorithm = {name: 'aes-gcm'};
- // Invalid keys
- shouldThrow("crypto.subtle.exportKey('raw', null)");
- shouldThrow("crypto.subtle.exportKey('raw', 3)");
-
- shouldBe("keys.aesCbcJustDecrypt.extractable", "false")
- shouldRejectPromiseWithNull("crypto.subtle.exportKey('raw', keys.aesCbcJustDecrypt)");
-
- return crypto.subtle.exportKey('raw', keys.aesCbc);
+ return crypto.subtle.importKey('raw', keyData, algorithm, extractable, usages);
}).then(function(result) {
- bytesShouldMatchHexString("Key bytes", "3136206279746573206f66206b657921", result);
-
- return crypto.subtle.exportKey('spki', keys.rsaSsaSha1Public);
-}).then(function(result) {
- bytesShouldMatchHexString("Key bytes", kPublicKeySpkiDerHex, result);
-}));
-
-completeTestWhenAllTasksDone();
+ key = result;
+ shouldEvaluateAs("key.algorithm.name", "AES-GCM");
+
+ // Can't use an AES-KW key for AES-CBC (even though both are AES keys).
+ return crypto.subtle.encrypt({name: 'AES-CBC', iv: new Uint8Array(16)}, key, data);
+}).then(failAndFinishJSTest, function(result) {
+ error = result;
+ shouldBeNull("error");
+}).then(finishJSTest, failAndFinishJSTest);
</script>

Powered by Google App Engine
This is Rietveld 408576698