Skip to content

Commit 4bece05

Browse files
panvaMoLow
authored andcommitted
test,crypto: update WebCryptoAPI WPT
PR-URL: #47921 Refs: #47864 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ea543d9 commit 4bece05

File tree

7 files changed

+79
-22
lines changed

7 files changed

+79
-22
lines changed

test/fixtures/wpt/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Last update:
3131
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
3232
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3333
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
34-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/188993d46b/WebCryptoAPI
34+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/17b7ca10fd/WebCryptoAPI
3535
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
3636

3737
[Web Platform Tests]: https://github.com/web-platform-tests/wpt

test/fixtures/wpt/WebCryptoAPI/generateKey/failures.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function run_test(algorithmNames) {
204204
});
205205

206206

207-
// The last thing that should be checked is an empty usages (for secret keys).
207+
// The last thing that should be checked is empty usages (disallowed for secret and private keys).
208208
testVectors.forEach(function(vector) {
209209
var name = vector.name;
210210

test/fixtures/wpt/WebCryptoAPI/import_export/ec_importKey.https.any.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@
8585
});
8686

8787
// Next, test private keys
88-
allValidUsages(vector.privateUsages, []).forEach(function(usages) {
89-
['pkcs8', 'jwk'].forEach(function(format) {
90-
var algorithm = {name: vector.name, namedCurve: curve};
91-
var data = keyData[curve];
92-
88+
['pkcs8', 'jwk'].forEach(function(format) {
89+
var algorithm = {name: vector.name, namedCurve: curve};
90+
var data = keyData[curve];
91+
allValidUsages(vector.privateUsages, []).forEach(function(usages) {
9392
testFormat(format, algorithm, data, curve, usages, extractable);
9493
});
94+
testEmptyUsages(format, algorithm, data, curve, extractable);
9595
});
9696
});
9797

@@ -136,6 +136,21 @@
136136
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, compressed, keyData, algorithm, extractable, usages));
137137
}
138138

139+
// Test importKey with a given key format and other parameters but with empty usages.
140+
// Should fail with SyntaxError
141+
function testEmptyUsages(format, algorithm, data, keySize, extractable) {
142+
const keyData = data[format];
143+
const usages = [];
144+
promise_test(function(test) {
145+
return subtle.importKey(format, keyData, algorithm, extractable, usages).
146+
then(function(key) {
147+
assert_unreached("importKey succeeded but should have failed with SyntaxError");
148+
}, function(err) {
149+
assert_equals(err.name, "SyntaxError", "Should throw correct error, not " + err.name + ": " + err.message);
150+
});
151+
}, "Empty Usages: " + keySize.toString() + " bits " + parameterString(format, false, keyData, algorithm, extractable, usages));
152+
}
153+
139154

140155

141156
// Helper methods follow:

test/fixtures/wpt/WebCryptoAPI/import_export/okp_importKey_failures.js

+13
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ function run_test(algorithmNames) {
132132
});
133133
});
134134

135+
// Algorithms normalize okay, but usages bad (empty).
136+
// Should fail due to SyntaxError
137+
testVectors.forEach(function(vector) {
138+
var name = vector.name;
139+
validKeyData.filter((test) => test.format === 'pkcs8' || (test.format === 'jwk' && test.data.d)).forEach(function(test) {
140+
allAlgorithmSpecifiersFor(name).forEach(function(algorithm) {
141+
[true, false].forEach(function(extractable) {
142+
testError(test.format, algorithm, test.data, name, [/* Empty usages */], extractable, "SyntaxError", "Empty usages");
143+
});
144+
});
145+
});
146+
});
147+
135148
// Algorithms normalize okay, usages ok. The length of the key must thouw a DataError exception.
136149
testVectors.forEach(function(vector) {
137150
var name = vector.name;

test/fixtures/wpt/WebCryptoAPI/import_export/rsa_importKey.https.any.js

+19-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/wpt/WebCryptoAPI/import_export/symmetric_importKey.https.any.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@
4141
}
4242

4343
rawKeyData.forEach(function(keyData) {
44-
// Generate all combinations of valid usages for testing
45-
allValidUsages(vector.legalUsages, []).forEach(function(usages) {
46-
// Try each legal value of the extractable parameter
47-
vector.extractable.forEach(function(extractable) {
48-
vector.formats.forEach(function(format) {
49-
var data = keyData;
50-
if (format === "jwk") {
51-
data = jwkData(keyData, algorithm);
52-
}
44+
// Try each legal value of the extractable parameter
45+
vector.extractable.forEach(function(extractable) {
46+
vector.formats.forEach(function(format) {
47+
var data = keyData;
48+
if (format === "jwk") {
49+
data = jwkData(keyData, algorithm);
50+
}
51+
// Generate all combinations of valid usages for testing
52+
allValidUsages(vector.legalUsages, []).forEach(function(usages) {
5353
testFormat(format, algorithm, data, keyData.length * 8, usages, extractable);
5454
});
55+
testEmptyUsages(format, algorithm, data, keyData.length * 8, extractable);
5556
});
5657
});
5758

@@ -90,6 +91,20 @@
9091
}, "Good parameters: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, extractable, usages));
9192
}
9293

94+
// Test importKey with a given key format and other parameters but with empty usages.
95+
// Should fail with SyntaxError
96+
function testEmptyUsages(format, algorithm, keyData, keySize, extractable) {
97+
const usages = [];
98+
promise_test(function(test) {
99+
return subtle.importKey(format, keyData, algorithm, extractable, usages).
100+
then(function(key) {
101+
assert_unreached("importKey succeeded but should have failed with SyntaxError");
102+
}, function(err) {
103+
assert_equals(err.name, "SyntaxError", "Should throw correct error, not " + err.name + ": " + err.message);
104+
});
105+
}, "Empty Usages: " + keySize.toString() + " bits " + parameterString(format, keyData, algorithm, extractable, usages));
106+
}
107+
93108

94109

95110
// Helper methods follow:

test/fixtures/wpt/versions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"path": "wasm/webapi"
8585
},
8686
"WebCryptoAPI": {
87-
"commit": "188993d46b95c9c0414ba2cef8751f5e19d3d498",
87+
"commit": "17b7ca10fd17ab22e60d62da6bc6e7424ea52740",
8888
"path": "WebCryptoAPI"
8989
},
9090
"webidl/ecmascript-binding/es-exceptions": {

0 commit comments

Comments
 (0)