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

Unified Diff: LayoutTests/crypto/subtle/resources/rsa-cloneKey.js

Issue 958353003: [WebCrypto] Move cloneKey test to respective algorithm directory (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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/subtle/resources/rsa-cloneKey.js
diff --git a/LayoutTests/crypto/subtle/clone-rsaHashedKey-public.html b/LayoutTests/crypto/subtle/resources/rsa-cloneKey.js
similarity index 50%
rename from LayoutTests/crypto/subtle/clone-rsaHashedKey-public.html
rename to LayoutTests/crypto/subtle/resources/rsa-cloneKey.js
index 4b4cbe2457aa3346f1a9e168f9ae7a35d26c5743..889b0a96cd3aaa7aef7e5ce84f6a39d44158850d 100644
--- a/LayoutTests/crypto/subtle/clone-rsaHashedKey-public.html
+++ b/LayoutTests/crypto/subtle/resources/rsa-cloneKey.js
@@ -1,56 +1,29 @@
-<!DOCTYPE html>
-<html>
-<head>
-<script src="../../resources/js-test.js"></script>
-<script src="resources/common.js"></script>
-<script src="resources/keys.js"></script>
-</head>
-<body>
-<p id="description"></p>
-<div id="console"></div>
-
-<script>
-description("Tests structured cloning of RSA public keys (with a hash)");
-
-jsTestIsAsync = true;
-
-// Tests the 12 permutations of keys generated by:
-// kPossibleAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyData x kPossibleHashAlgorithms
-//
-// For practical reasons these tests are not exhaustive.
-
-var kPossibleAlgorithms = ['RSASSA-PKCS1-v1_5'];
-var kPossibleExtractable = [true, false];
-var kPossibleKeyUsages = [[], ['verify']];
-var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
-
-var kPossibleKeyData = [
- kKeyData.rsa2,
- kKeyData.rsa3
-];
+if (self.importScripts) {
+ importScripts('common.js');
+}
-function runTest(algorithmName, hashName, extractable, keyUsages, keyData)
+function runCloneRSATests(format, algorithmName, hashName, keyType, extractable, keyUsages, keyData)
{
- var importData = hexStringToUint8Array(keyData.spki);
- var importAlgorithm = { name: algorithmName, hash: {name: hashName} };
+ var importData = hexStringToUint8Array(keyData[format]);
+ var importAlgorithm = { name: algorithmName, hash: { name: hashName } };
var results = {};
- return crypto.subtle.importKey('spki', importData, importAlgorithm, extractable, keyUsages).then(function(importedKey) {
+ return crypto.subtle.importKey(format, importData, importAlgorithm, extractable, keyUsages).then(function(importedKey) {
results.importedKey = importedKey;
importedKey.extraProperty = 'hi';
return cloneKey(importedKey);
}).then(function(clonedKey) {
results.clonedKey = clonedKey;
if (extractable)
- return crypto.subtle.exportKey('spki', clonedKey);
+ return crypto.subtle.exportKey(format, clonedKey);
return null;
}).then(function(clonedKeyData) {
importedKey = results.importedKey;
clonedKey = results.clonedKey;
shouldEvaluateAs("importedKey.extraProperty", "hi");
- shouldEvaluateAs("importedKey.type", "public");
+ shouldEvaluateAs("importedKey.type", keyType);
shouldEvaluateAs("importedKey.extractable", extractable);
shouldEvaluateAs("importedKey.algorithm.name", algorithmName);
shouldEvaluateAs("importedKey.algorithm.modulusLength", keyData.modulusLengthBits);
@@ -61,7 +34,7 @@ function runTest(algorithmName, hashName, extractable, keyUsages, keyData)
shouldNotBe("importedKey", "clonedKey");
shouldBeUndefined("clonedKey.extraProperty");
- shouldEvaluateAs("clonedKey.type", "public");
+ shouldEvaluateAs("clonedKey.type", keyType);
shouldEvaluateAs("clonedKey.extractable", extractable);
shouldEvaluateAs("clonedKey.algorithm.name", algorithmName);
shouldEvaluateAs("clonedKey.algorithm.modulusLength", keyData.modulusLengthBits);
@@ -72,29 +45,37 @@ function runTest(algorithmName, hashName, extractable, keyUsages, keyData)
logSerializedKey(importedKey);
if (extractable)
- bytesShouldMatchHexString("Cloned key exported data", keyData.spki, clonedKeyData);
+ bytesShouldMatchHexString("Cloned key exported data", keyData[format], clonedKeyData);
debug("");
});
}
-var lastPromise = Promise.resolve(null);
-
-kPossibleAlgorithms.forEach(function(algorithmName) {
- kPossibleExtractable.forEach(function(extractable) {
- kPossibleKeyUsages.forEach(function(keyUsages) {
- kPossibleKeyData.forEach(function(keyData) {
- kPossibleHashAlgorithms.forEach(function(hashName) {
- lastPromise = lastPromise.then(runTest.bind(null, algorithmName, hashName, extractable, keyUsages, keyData));
+function testCloneRSAKeys(format, algorithmName, possibleKeyUsages, keyType, possibleKeyData)
+{
+ var lastPromise = Promise.resolve(null);
+ var kPossibleExtractable = [true, false];
+ var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512'];
+
+ kPossibleHashAlgorithms.forEach(function(hashName) {
+ kPossibleExtractable.forEach(function(extractable) {
+ possibleKeyUsages.forEach(function(keyUsages) {
+ possibleKeyData.forEach(function(keyData) {
+ lastPromise = lastPromise.then(runCloneRSATests.bind(null, format, algorithmName, hashName, keyType, extractable, keyUsages, keyData));
});
});
});
});
-});
-lastPromise.then(finishJSTest, failAndFinishJSTest);
+ return lastPromise;
+}
-</script>
+function testCloneRSAPublicKeys(algorithmName, possibleKeyUsages, keyData)
+{
+ return testCloneRSAKeys("spki", algorithmName, possibleKeyUsages, "public", keyData);
+}
-</body>
-</html>
+function testCloneRSAPrivateKeys(algorithmName, possibleKeyUsages, keyData)
+{
+ return testCloneRSAKeys("pkcs8", algorithmName, possibleKeyUsages, "private", keyData);
+}
« no previous file with comments | « LayoutTests/crypto/subtle/resources/ec-cloneKey.js ('k') | LayoutTests/crypto/subtle/resources/symmetric-cloneKey.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698