Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb1c0bd

Browse filesBrowse files
nodejs-github-botaduh95
authored andcommitted
test: update WPT for WebCryptoAPI to 42e47329fd
PR-URL: #62048 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 2f9c085 commit fb1c0bd
Copy full SHA for fb1c0bd

14 files changed

+679-58Lines changed: 679 additions & 58 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/fixtures/wpt/README.md‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/README.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Last update:
3434
- wasm/jsapi: https://github.com/web-platform-tests/wpt/tree/cde25e7e3c/wasm/jsapi
3535
- wasm/webapi: https://github.com/web-platform-tests/wpt/tree/fd1b23eeaa/wasm/webapi
3636
- web-locks: https://github.com/web-platform-tests/wpt/tree/10a122a6bc/web-locks
37-
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/7cbe7e8ed9/WebCryptoAPI
37+
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/42e47329fd/WebCryptoAPI
3838
- webidl/ecmascript-binding/es-exceptions: https://github.com/web-platform-tests/wpt/tree/2f96fa1996/webidl/ecmascript-binding/es-exceptions
3939
- webmessaging/broadcastchannel: https://github.com/web-platform-tests/wpt/tree/6495c91853/webmessaging/broadcastchannel
4040
- webstorage: https://github.com/web-platform-tests/wpt/tree/1d2c5fb36a/webstorage
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/digest/cshake.tentative.https.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/digest/cshake.tentative.https.any.js
+35-19Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,42 @@ Object.keys(digestedData).forEach(function (alg) {
171171
});
172172
}, alg + ' with ' + length + ' bit output and ' + size + ' source data');
173173

174-
promise_test(function (test) {
175-
var buffer = new Uint8Array(sourceData[size]);
176-
return crypto.subtle
177-
.digest({ name: alg, length: length }, buffer)
178-
.then(function (result) {
179-
// Alter the buffer after calling digest
180-
if (buffer.length > 0) {
174+
if (sourceData[size].length > 0) {
175+
promise_test(function (test) {
176+
var buffer = new Uint8Array(sourceData[size]);
177+
// Alter the buffer before calling digest
178+
buffer[0] = ~buffer[0];
179+
return crypto.subtle
180+
.digest({
181+
get name() {
182+
// Alter the buffer back while calling digest
183+
buffer[0] = sourceData[size][0];
184+
return alg;
185+
},
186+
length
187+
}, buffer)
188+
.then(function (result) {
189+
assert_true(
190+
equalBuffers(result, digestedData[alg][length][size]),
191+
'digest matches expected'
192+
);
193+
});
194+
}, alg + ' with ' + length + ' bit output and ' + size + ' source data and altered buffer during call');
195+
196+
promise_test(function (test) {
197+
var buffer = new Uint8Array(sourceData[size]);
198+
return crypto.subtle
199+
.digest({ name: alg, length: length }, buffer)
200+
.then(function (result) {
201+
// Alter the buffer after calling digest
181202
buffer[0] = ~buffer[0];
182-
}
183-
assert_true(
184-
equalBuffers(result, digestedData[alg][length][size]),
185-
'digest matches expected'
186-
);
187-
});
188-
}, alg +
189-
' with ' +
190-
length +
191-
' bit output and ' +
192-
size +
193-
' source data and altered buffer after call');
203+
assert_true(
204+
equalBuffers(result, digestedData[alg][length][size]),
205+
'digest matches expected'
206+
);
207+
});
208+
}, alg + ' with ' + length + ' bit output and ' + size + ' source data and altered buffer after call');
209+
}
194210
});
195211
});
196212
});
Collapse file

‎test/fixtures/wpt/WebCryptoAPI/digest/digest.https.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/digest/digest.https.any.js
+31-13Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,37 @@
8383
return promise;
8484
}, mixedCase + " with " + size + " source data");
8585

86-
promise_test(function(test) {
87-
var copiedBuffer = copyBuffer(sourceData[size]);
88-
var promise = subtle.digest({name: upCase}, copiedBuffer)
89-
.then(function(result) {
90-
assert_true(equalBuffers(result, digestedData[alg][size]), "digest() yielded expected result for " + alg + ":" + size);
91-
}, function(err) {
92-
assert_unreached("digest() threw an error for " + alg + ":" + size + " - " + err.message);
93-
});
94-
95-
copiedBuffer[0] = 255 - copiedBuffer;
96-
return promise;
97-
}, upCase + " with " + size + " source data and altered buffer after call");
98-
86+
if (sourceData[size].length > 0) {
87+
promise_test(function(test) {
88+
var copiedBuffer = copyBuffer(sourceData[size]);
89+
copiedBuffer[0] = 255 - copiedBuffer[0];
90+
var promise = subtle.digest({
91+
get name() {
92+
copiedBuffer[0] = sourceData[size][0];
93+
return upCase;
94+
}
95+
}, copiedBuffer)
96+
.then(function(result) {
97+
assert_true(equalBuffers(result, digestedData[alg][size]), "digest() yielded expected result for " + alg + ":" + size);
98+
}, function(err) {
99+
assert_unreached("digest() threw an error for " + alg + ":" + size + " - " + err.message);
100+
});
101+
return promise;
102+
}, upCase + " with " + size + " source data and altered buffer during call");
103+
104+
promise_test(function(test) {
105+
var copiedBuffer = copyBuffer(sourceData[size]);
106+
var promise = subtle.digest({name: upCase}, copiedBuffer)
107+
.then(function(result) {
108+
assert_true(equalBuffers(result, digestedData[alg][size]), "digest() yielded expected result for " + alg + ":" + size);
109+
}, function(err) {
110+
assert_unreached("digest() threw an error for " + alg + ":" + size + " - " + err.message);
111+
});
112+
113+
copiedBuffer[0] = 255 - copiedBuffer[0];
114+
return promise;
115+
}, upCase + " with " + size + " source data and altered buffer after call");
116+
}
99117
});
100118
});
101119

Collapse file

‎test/fixtures/wpt/WebCryptoAPI/digest/sha3.tentative.https.any.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/digest/sha3.tentative.https.any.js
+32-12Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,39 @@ Object.keys(sourceData).forEach(function (size) {
109109
});
110110
}, alg + ' with ' + size + ' source data');
111111

112-
promise_test(function (test) {
113-
var buffer = new Uint8Array(sourceData[size]);
114-
return crypto.subtle.digest(alg, buffer).then(function (result) {
115-
// Alter the buffer after calling digest
116-
if (buffer.length > 0) {
112+
if (sourceData[size].length > 0) {
113+
promise_test(function (test) {
114+
var buffer = new Uint8Array(sourceData[size]);
115+
// Alter the buffer before calling digest
116+
buffer[0] = ~buffer[0];
117+
return crypto.subtle
118+
.digest({
119+
get name() {
120+
// Alter the buffer back while calling digest
121+
buffer[0] = sourceData[size][0];
122+
return alg;
123+
}
124+
}, buffer)
125+
.then(function (result) {
126+
assert_true(
127+
equalBuffers(result, digestedData[alg][size]),
128+
'digest matches expected'
129+
);
130+
});
131+
}, alg + ' with ' + size + ' source data and altered buffer during call');
132+
133+
promise_test(function (test) {
134+
var buffer = new Uint8Array(sourceData[size]);
135+
return crypto.subtle.digest(alg, buffer).then(function (result) {
136+
// Alter the buffer after calling digest
117137
buffer[0] = ~buffer[0];
118-
}
119-
assert_true(
120-
equalBuffers(result, digestedData[alg][size]),
121-
'digest matches expected'
122-
);
123-
});
124-
}, alg + ' with ' + size + ' source data and altered buffer after call');
138+
assert_true(
139+
equalBuffers(result, digestedData[alg][size]),
140+
'digest matches expected'
141+
);
142+
});
143+
}, alg + ' with ' + size + ' source data and altered buffer after call');
144+
}
125145
});
126146
});
127147

Collapse file

‎test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes.js‎

Copy file name to clipboardExpand all lines: test/fixtures/wpt/WebCryptoAPI/encrypt_decrypt/aes.js
+69-5Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,38 @@ function run_test() {
3535
all_promises.push(promise);
3636
});
3737

38+
// Check for successful encryption even if the buffer is changed while calling encrypt.
39+
passingVectors.forEach(function(vector) {
40+
var plaintext = copyBuffer(vector.plaintext);
41+
plaintext[0] = 255 - plaintext[0];
42+
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
43+
.then(function(vector) {
44+
promise_test(function(test) {
45+
var operation = subtle.encrypt({
46+
...vector.algorithm,
47+
get name() {
48+
plaintext[0] = vector.plaintext[0];
49+
return vector.algorithm.name;
50+
}
51+
}, vector.key, plaintext)
52+
.then(function(result) {
53+
assert_true(equalBuffers(result, vector.result), "Should return expected result");
54+
}, function(err) {
55+
assert_unreached("encrypt error for test " + vector.name + ": " + err.message);
56+
});
57+
return operation;
58+
}, vector.name + " with altered plaintext during call");
59+
}, function(err) {
60+
// We need a failed test if the importVectorKey operation fails, so
61+
// we know we never tested encryption
62+
promise_test(function(test) {
63+
assert_unreached("importKey failed for " + vector.name);
64+
}, "importKey step: " + vector.name + " with altered plaintext during call");
65+
});
66+
67+
all_promises.push(promise);
68+
});
69+
3870
// Check for successful encryption even if the buffer is changed after calling encrypt.
3971
passingVectors.forEach(function(vector) {
4072
var plaintext = copyBuffer(vector.plaintext);
@@ -49,13 +81,13 @@ function run_test() {
4981
});
5082
plaintext[0] = 255 - plaintext[0];
5183
return operation;
52-
}, vector.name + " with altered plaintext");
84+
}, vector.name + " with altered plaintext after call");
5385
}, function(err) {
5486
// We need a failed test if the importVectorKey operation fails, so
5587
// we know we never tested encryption
5688
promise_test(function(test) {
5789
assert_unreached("importKey failed for " + vector.name);
58-
}, "importKey step: " + vector.name + " with altered plaintext");
90+
}, "importKey step: " + vector.name + " with altered plaintext after call");
5991
});
6092

6193
all_promises.push(promise);
@@ -84,7 +116,39 @@ function run_test() {
84116
all_promises.push(promise);
85117
});
86118

87-
// Check for successful decryption even if ciphertext is altered.
119+
// Check for successful decryption even if ciphertext is altered while calling encrypt.
120+
passingVectors.forEach(function(vector) {
121+
var ciphertext = copyBuffer(vector.result);
122+
ciphertext[0] = 255 - ciphertext[0];
123+
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
124+
.then(function(vector) {
125+
promise_test(function(test) {
126+
var operation = subtle.decrypt({
127+
...vector.algorithm,
128+
get name() {
129+
ciphertext[0] = vector.result[0];
130+
return vector.algorithm.name;
131+
}
132+
}, vector.key, ciphertext)
133+
.then(function(result) {
134+
assert_true(equalBuffers(result, vector.plaintext), "Should return expected result");
135+
}, function(err) {
136+
assert_unreached("decrypt error for test " + vector.name + ": " + err.message);
137+
});
138+
return operation;
139+
}, vector.name + " decryption with altered ciphertext during call");
140+
}, function(err) {
141+
// We need a failed test if the importVectorKey operation fails, so
142+
// we know we never tested encryption
143+
promise_test(function(test) {
144+
assert_unreached("importKey failed for " + vector.name);
145+
}, "importKey step for decryption: " + vector.name + " with altered ciphertext during call");
146+
});
147+
148+
all_promises.push(promise);
149+
});
150+
151+
// Check for successful decryption even if ciphertext is altered after calling encrypt.
88152
passingVectors.forEach(function(vector) {
89153
var ciphertext = copyBuffer(vector.result);
90154
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
@@ -98,13 +162,13 @@ function run_test() {
98162
});
99163
ciphertext[0] = 255 - ciphertext[0];
100164
return operation;
101-
}, vector.name + " decryption with altered ciphertext");
165+
}, vector.name + " decryption with altered ciphertext after call");
102166
}, function(err) {
103167
// We need a failed test if the importVectorKey operation fails, so
104168
// we know we never tested encryption
105169
promise_test(function(test) {
106170
assert_unreached("importKey failed for " + vector.name);
107-
}, "importKey step for decryption: " + vector.name + " with altered ciphertext");
171+
}, "importKey step for decryption: " + vector.name + " with altered ciphertext after call");
108172
});
109173

110174
all_promises.push(promise);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.