Index: LayoutTests/crypto/clone-hmacKey.html |
diff --git a/LayoutTests/crypto/clone-hmacKey.html b/LayoutTests/crypto/clone-hmacKey.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ac26367496a6d591ed4362ba7326f2d8ce39b31f |
--- /dev/null |
+++ b/LayoutTests/crypto/clone-hmacKey.html |
@@ -0,0 +1,96 @@ |
+<!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 structured cloning of HMAC keys"); |
+ |
+jsTestIsAsync = true; |
+ |
+// Tests the 48 permutations of keys generated by: |
+// kPossibleHashAlgorithms x kPossibleExtractable x kPossibleKeyUsages x kPossibleKeyData |
+// |
+// For practical reasons these tests are not exhaustive. |
+ |
+var k128BitData = "30112233445566778899aabbccddeeff" |
+var k256BitData = "00112233445546778899aabbccddeeff000102030405060708090a0b0c0d0e0f"; |
+ |
+var kPossibleHashAlgorithms = ['SHA-1', 'SHA-256', 'SHA-512']; |
+var kPossibleExtractable = [true, false]; |
+var kPossibleKeyUsages = [[], ['sign'], ['verify'], ['sign', 'verify']]; |
+var kPossibleKeyData = [ |
+ k128BitData, |
+ k256BitData |
+]; |
+ |
+function runTest(hashName, extractable, keyUsages, keyData) |
+{ |
+ var importData = hexStringToUint8Array(keyData); |
+ var importAlgorithm = { name: 'HMAC', hash: {name: hashName } }; |
+ |
+ var results = {}; |
+ |
+ return crypto.subtle.importKey('raw', 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('raw', clonedKey); |
+ return null; |
+ }).then(function(clonedKeyData) { |
+ importedKey = results.importedKey; |
+ clonedKey = results.clonedKey; |
+ |
+ shouldEvaluateAs("importedKey.extraProperty", "hi"); |
+ shouldEvaluateAs("importedKey.type", "secret"); |
+ shouldEvaluateAs("importedKey.extractable", extractable); |
+ shouldEvaluateAs("importedKey.algorithm.name", "HMAC"); |
+ shouldEvaluateAs("importedKey.algorithm.length", importData.length * 8); |
+ shouldEvaluateAs("importedKey.algorithm.hash.name", hashName); |
+ shouldEvaluateAs("importedKey.usages.join(',')", keyUsages.join(",")); |
+ |
+ shouldBeTrue("importedKey != clonedKey"); |
+ |
+ shouldBeUndefined("clonedKey.extraProperty"); |
+ shouldEvaluateAs("clonedKey.type", "secret"); |
+ shouldEvaluateAs("clonedKey.extractable", extractable); |
+ shouldEvaluateAs("clonedKey.algorithm.name", "HMAC"); |
+ shouldEvaluateAs("clonedKey.algorithm.length", importData.length * 8); |
+ shouldEvaluateAs("clonedKey.algorithm.hash.name", hashName); |
+ shouldEvaluateAs("clonedKey.usages.join(',')", keyUsages.join(",")); |
+ |
+ logSerializedKey(importedKey); |
+ |
+ if (extractable) |
+ bytesShouldMatchHexString("Cloned key exported data", keyData, clonedKeyData); |
+ |
+ debug(""); |
+ }); |
+} |
+ |
+var lastPromise = Promise.resolve(null); |
+ |
+kPossibleHashAlgorithms.forEach(function(hashName) { |
+ kPossibleExtractable.forEach(function(extractable) { |
+ kPossibleKeyUsages.forEach(function(keyUsages) { |
+ kPossibleKeyData.forEach(function(keyData) { |
+ lastPromise = lastPromise.then(runTest.bind(null, hashName, extractable, keyUsages, keyData)); |
+ }); |
+ }); |
+ }); |
+}); |
+ |
+lastPromise.then(finishJSTest, failAndFinishJSTest); |
+ |
+</script> |
+ |
+</body> |
+</html> |