Skip to content

Commit

Permalink
test,crypto: update WebCryptoAPI WPT
Browse files Browse the repository at this point in the history
PR-URL: #49714
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
panva authored and ruyadorno committed Sep 28, 2023
1 parent 2cc5ad7 commit 843df1a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 171 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Last update:
- user-timing: https://github.com/web-platform-tests/wpt/tree/5ae85bf826/user-timing
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/17b7ca10fd/WebCryptoAPI
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/f4e7e32fd0/WebCryptoAPI
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/a370aad338/webidl/ecmascript-binding/es-exceptions
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/e97fac4791/webmessaging/broadcastchannel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
[true, false].forEach(function(extractable) {

// Test public keys first
[[]].forEach(function(usages) { // Only valid usages argument is empty array
allValidUsages(vector.publicUsages, true).forEach(function(usages) {
['spki', 'spki_compressed', 'jwk', 'raw', 'raw_compressed'].forEach(function(format) {
var algorithm = {name: vector.name, namedCurve: curve};
var data = keyData[curve];
Expand All @@ -88,7 +88,7 @@
['pkcs8', 'jwk'].forEach(function(format) {
var algorithm = {name: vector.name, namedCurve: curve};
var data = keyData[curve];
allValidUsages(vector.privateUsages, []).forEach(function(usages) {
allValidUsages(vector.privateUsages).forEach(function(usages) {
testFormat(format, algorithm, data, curve, usages, extractable);
});
testEmptyUsages(format, algorithm, data, curve, extractable);
Expand Down Expand Up @@ -219,46 +219,6 @@
return base64String.replace(/=/g, "");
}

// Want to test every valid combination of usages. Start by creating a list
// of all non-empty subsets to possible usages.
function allNonemptySubsetsOf(arr) {
var results = [];
var firstElement;
var remainingElements;

for(var i=0; i<arr.length; i++) {
firstElement = arr[i];
remainingElements = arr.slice(i+1);
results.push([firstElement]);

if (remainingElements.length > 0) {
allNonemptySubsetsOf(remainingElements).forEach(function(combination) {
combination.push(firstElement);
results.push(combination);
});
}
}

return results;
}

// Return a list of all valid usage combinations, given the possible ones
// and the ones that are required for a particular operation.
function allValidUsages(possibleUsages, requiredUsages) {
var allUsages = [];

allNonemptySubsetsOf(possibleUsages).forEach(function(usage) {
for (var i=0; i<requiredUsages.length; i++) {
if (!usage.includes(requiredUsages[i])) {
return;
}
}
allUsages.push(usage);
});

return allUsages;
}

// Convert method parameters to a string to uniquely name each test
function parameterString(format, compressed, data, algorithm, extractable, usages) {
if ("byteLength" in data) {
Expand Down Expand Up @@ -311,4 +271,3 @@

return "{" + keyValuePairs.join(", ") + "}";
}

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
[true, false].forEach(function(extractable) {

// Test public keys first
[[]].forEach(function(usages) { // Only valid usages argument is empty array
allValidUsages(vector.publicUsages, true).forEach(function(usages) {
['spki', 'jwk', 'raw'].forEach(function(format) {
var algorithm = {name: vector.name};
var data = keyData[vector.name];
Expand All @@ -86,7 +86,7 @@
});

// Next, test private keys
allValidUsages(vector.privateUsages, []).forEach(function(usages) {
allValidUsages(vector.privateUsages).forEach(function(usages) {
['pkcs8', 'jwk'].forEach(function(format) {
var algorithm = {name: vector.name};
var data = keyData[vector.name];
Expand Down Expand Up @@ -194,46 +194,6 @@
return base64String.replace(/=/g, "");
}

// Want to test every valid combination of usages. Start by creating a list
// of all non-empty subsets to possible usages.
function allNonemptySubsetsOf(arr) {
var results = [];
var firstElement;
var remainingElements;

for(var i=0; i<arr.length; i++) {
firstElement = arr[i];
remainingElements = arr.slice(i+1);
results.push([firstElement]);

if (remainingElements.length > 0) {
allNonemptySubsetsOf(remainingElements).forEach(function(combination) {
combination.push(firstElement);
results.push(combination);
});
}
}

return results;
}

// Return a list of all valid usage combinations, given the possible ones
// and the ones that are required for a particular operation.
function allValidUsages(possibleUsages, requiredUsages) {
var allUsages = [];

allNonemptySubsetsOf(possibleUsages).forEach(function(usage) {
for (var i=0; i<requiredUsages.length; i++) {
if (!usage.includes(requiredUsages[i])) {
return;
}
}
allUsages.push(usage);
});

return allUsages;
}

// Convert method parameters to a string to uniquely name each test
function parameterString(format, data, algorithm, extractable, usages) {
if ("byteLength" in data) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
data = jwkData(keyData, algorithm);
}
// Generate all combinations of valid usages for testing
allValidUsages(vector.legalUsages, []).forEach(function(usages) {
allValidUsages(vector.legalUsages).forEach(function(usages) {
testFormat(format, algorithm, data, keyData.length * 8, usages, extractable);
});
testEmptyUsages(format, algorithm, data, keyData.length * 8, extractable);
Expand Down Expand Up @@ -173,46 +173,6 @@
return base64String.replace(/=/g, "");
}

// Want to test every valid combination of usages. Start by creating a list
// of all non-empty subsets to possible usages.
function allNonemptySubsetsOf(arr) {
var results = [];
var firstElement;
var remainingElements;

for(var i=0; i<arr.length; i++) {
firstElement = arr[i];
remainingElements = arr.slice(i+1);
results.push([firstElement]);

if (remainingElements.length > 0) {
allNonemptySubsetsOf(remainingElements).forEach(function(combination) {
combination.push(firstElement);
results.push(combination);
});
}
}

return results;
}

// Return a list of all valid usage combinations, given the possible ones
// and the ones that are required for a particular operation.
function allValidUsages(possibleUsages, requiredUsages) {
var allUsages = [];

allNonemptySubsetsOf(possibleUsages).forEach(function(usage) {
for (var i=0; i<requiredUsages.length; i++) {
if (!usage.includes(requiredUsages[i])) {
return;
}
}
allUsages.push(usage);
});

return allUsages;
}

// Convert method parameters to a string to uniquely name each test
function parameterString(format, data, algorithm, extractable, usages) {
var result = "(" +
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/WebCryptoAPI/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function allValidUsages(validUsages, emptyIsValid, mandatoryUsages) {
}
});

if (emptyIsValid) {
if (emptyIsValid && validUsages.length !== 0) {
okaySubsets.push([]);
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wpt/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"path": "wasm/webapi"
},
"WebCryptoAPI": {
"commit": "17b7ca10fd17ab22e60d62da6bc6e7424ea52740",
"commit": "f4e7e32fd0d4937f5b024602c6bf665ebeb1fa17",
"path": "WebCryptoAPI"
},
"webidl/ecmascript-binding/es-exceptions": {
Expand Down

0 comments on commit 843df1a

Please sign in to comment.