Skip to content

Commit

Permalink
Split WebCryptoAPI generateKey tests into one test file per algorithm…
Browse files Browse the repository at this point in the history
… name

MozReview-Commit-ID: FVHQoZDV5eI

Upstreamed from https://bugzilla.mozilla.org/show_bug.cgi?id=1279799
  • Loading branch information
jgraham committed Jun 29, 2016
1 parent 7a5872c commit 4ab1a79
Show file tree
Hide file tree
Showing 45 changed files with 675 additions and 1 deletion.
3 changes: 3 additions & 0 deletions WebCryptoAPI/generateKey/failures.js
Expand Up @@ -35,6 +35,9 @@ function run_test(algorithmNames) {
];

var testVectors = [];
if (algorithmNames && !Array.isArray(algorithmNames)) {
algorithmNames = [algorithmNames];
};
allTestVectors.forEach(function(vector) {
if (!algorithmNames || algorithmNames.includes(vector.name)) {
testVectors.push(vector);
Expand Down
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_AES-CBC.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["AES-CBC"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_AES-CTR.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["AES-CTR"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_AES-GCM.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["AES-GCM"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_AES-KW.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["AES-KW"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_ECDH.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["ECDH"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_ECDSA.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["ECDSA"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_HMAC.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["HMAC"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_RSA-OAEP.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["RSA-OAEP"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_RSA-PSS.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["RSA-PSS"]);
done();
6 changes: 6 additions & 0 deletions WebCryptoAPI/generateKey/failures_RSASSA-PKCS1-v1_5.worker.js
@@ -0,0 +1,6 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("failures.js");
run_test(["RSASSA-PKCS1-v1_5"]);
done();
11 changes: 10 additions & 1 deletion WebCryptoAPI/generateKey/successes.js
Expand Up @@ -16,7 +16,7 @@ function run_test(algorithmNames) {
// helper functions that generate all possible test parameters for
// different situations.

var testVectors = [ // Parameters that should work for generateKey
var allTestVectors = [ // Parameters that should work for generateKey
{name: "AES-CTR", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
{name: "AES-CBC", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
{name: "AES-GCM", resultType: CryptoKey, usages: ["encrypt", "decrypt", "wrapKey", "unwrapKey"], mandatoryUsages: []},
Expand All @@ -29,6 +29,15 @@ function run_test(algorithmNames) {
{name: "ECDH", resultType: "CryptoKeyPair", usages: ["deriveKey", "deriveBits"], mandatoryUsages: ["deriveKey", "deriveBits"]}
];

var testVectors = [];
if (algorithmNames && !Array.isArray(algorithmNames)) {
algorithmNames = [algorithmNames];
};
allTestVectors.forEach(function(vector) {
if (!algorithmNames || algorithmNames.includes(vector.name)) {
testVectors.push(vector);
}
});

function parameterString(algorithm, extractable, usages) {
var result = "(" +
Expand Down
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_AES-CBC.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["AES-CBC"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_AES-CTR.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["AES-CTR"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_AES-GCM.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["AES-GCM"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_AES-KW.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["AES-KW"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_ECDH.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["ECDH"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_ECDSA.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["ECDSA"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_HMAC.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["HMAC"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_RSA-OAEP.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["RSA-OAEP"]);
done();
7 changes: 7 additions & 0 deletions WebCryptoAPI/generateKey/successes_RSA-PSS.worker.js
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["RSA-PSS"]);
done();
@@ -0,0 +1,7 @@
// <meta> timeout=long
importScripts("/resources/testharness.js");
importScripts("../util/helpers.js");
importScripts("successes.js");

run_test(["RSASSA-PKCS1-v1_5"]);
done();
23 changes: 23 additions & 0 deletions WebCryptoAPI/generateKey/test_aes-cbc.html
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() Successful Calls</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="successes.js"></script>

<h1>generateKey Tests for Good Parameters</h1>
<p>
<strong>Warning!</strong> RSA key generation is intrinsically
very slow, so the related tests can take up to
several minutes to complete, depending on browser!
</p>

<div id="log"></div>
<script>
run_test("AES-CBC");
</script>
23 changes: 23 additions & 0 deletions WebCryptoAPI/generateKey/test_aes-ctr.html
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() Successful Calls</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="successes.js"></script>

<h1>generateKey Tests for Good Parameters</h1>
<p>
<strong>Warning!</strong> RSA key generation is intrinsically
very slow, so the related tests can take up to
several minutes to complete, depending on browser!
</p>

<div id="log"></div>
<script>
run_test("AES-CTR");
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_AES-CBC.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["AES-CBC"]);
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_AES-CTR.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["AES-CTR"]);
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_AES-GCM.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["AES-GCM"]);
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_AES-KW.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["AES-KW"]);
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_ECDH.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["ECDH"]);
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_ECDSA.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["ECDSA"]);
</script>
18 changes: 18 additions & 0 deletions WebCryptoAPI/generateKey/test_failures_HMAC.html
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>WebCryptoAPI: generateKey() for Failures</title>
<link rel="author" title="Charles Engelke" href="mailto:w3c@engelke.com">
<link rel="help" href="https://www.w3.org/TR/WebCryptoAPI/#dfn-SubtleCrypto-method-generateKey">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="/WebCryptoAPI/util/helpers.js"></script>
<script src="failures.js"></script>

<h1>generateKey Tests for Bad Parameters</h1>

<div id="log"></div>
<script>
run_test(["HMAC"]);
</script>

1 comment on commit 4ab1a79

@engelke
Copy link
Contributor

@engelke engelke commented on 4ab1a79 Jul 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original, "unsplit" files should be removed now.

  • test_successes.html
  • test_failures.html
  • successes.worker.js
  • failures.worker.js

Please sign in to comment.