mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-30 11:37:16 +02:00
LibWeb: Re-Import encrypt_decrypt WPT tests
This commit is contained in:
committed by
Jelle Raaijmakers
parent
30d528d3c0
commit
8baad1dc4c
Notes:
github-actions[bot]
2026-03-06 13:24:14 +00:00
Author: https://github.com/mikiubo Commit: https://github.com/LadybirdBrowser/ladybird/commit/8baad1dc4c7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8263 Reviewed-by: https://github.com/gmta ✅
@@ -35,6 +35,38 @@ function run_test() {
|
||||
all_promises.push(promise);
|
||||
});
|
||||
|
||||
// Check for successful encryption even if the buffer is changed while calling encrypt.
|
||||
passingVectors.forEach(function(vector) {
|
||||
var plaintext = copyBuffer(vector.plaintext);
|
||||
plaintext[0] = 255 - plaintext[0];
|
||||
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
|
||||
.then(function(vector) {
|
||||
promise_test(function(test) {
|
||||
var operation = subtle.encrypt({
|
||||
...vector.algorithm,
|
||||
get name() {
|
||||
plaintext[0] = vector.plaintext[0];
|
||||
return vector.algorithm.name;
|
||||
}
|
||||
}, vector.key, plaintext)
|
||||
.then(function(result) {
|
||||
assert_true(equalBuffers(result, vector.result), "Should return expected result");
|
||||
}, function(err) {
|
||||
assert_unreached("encrypt error for test " + vector.name + ": " + err.message);
|
||||
});
|
||||
return operation;
|
||||
}, vector.name + " with altered plaintext during call");
|
||||
}, function(err) {
|
||||
// We need a failed test if the importVectorKey operation fails, so
|
||||
// we know we never tested encryption
|
||||
promise_test(function(test) {
|
||||
assert_unreached("importKey failed for " + vector.name);
|
||||
}, "importKey step: " + vector.name + " with altered plaintext during call");
|
||||
});
|
||||
|
||||
all_promises.push(promise);
|
||||
});
|
||||
|
||||
// Check for successful encryption even if the buffer is changed after calling encrypt.
|
||||
passingVectors.forEach(function(vector) {
|
||||
var plaintext = copyBuffer(vector.plaintext);
|
||||
@@ -49,13 +81,13 @@ function run_test() {
|
||||
});
|
||||
plaintext[0] = 255 - plaintext[0];
|
||||
return operation;
|
||||
}, vector.name + " with altered plaintext");
|
||||
}, vector.name + " with altered plaintext after call");
|
||||
}, function(err) {
|
||||
// We need a failed test if the importVectorKey operation fails, so
|
||||
// we know we never tested encryption
|
||||
promise_test(function(test) {
|
||||
assert_unreached("importKey failed for " + vector.name);
|
||||
}, "importKey step: " + vector.name + " with altered plaintext");
|
||||
}, "importKey step: " + vector.name + " with altered plaintext after call");
|
||||
});
|
||||
|
||||
all_promises.push(promise);
|
||||
@@ -84,7 +116,39 @@ function run_test() {
|
||||
all_promises.push(promise);
|
||||
});
|
||||
|
||||
// Check for successful decryption even if ciphertext is altered.
|
||||
// Check for successful decryption even if ciphertext is altered while calling encrypt.
|
||||
passingVectors.forEach(function(vector) {
|
||||
var ciphertext = copyBuffer(vector.result);
|
||||
ciphertext[0] = 255 - ciphertext[0];
|
||||
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
|
||||
.then(function(vector) {
|
||||
promise_test(function(test) {
|
||||
var operation = subtle.decrypt({
|
||||
...vector.algorithm,
|
||||
get name() {
|
||||
ciphertext[0] = vector.result[0];
|
||||
return vector.algorithm.name;
|
||||
}
|
||||
}, vector.key, ciphertext)
|
||||
.then(function(result) {
|
||||
assert_true(equalBuffers(result, vector.plaintext), "Should return expected result");
|
||||
}, function(err) {
|
||||
assert_unreached("decrypt error for test " + vector.name + ": " + err.message);
|
||||
});
|
||||
return operation;
|
||||
}, vector.name + " decryption with altered ciphertext during call");
|
||||
}, function(err) {
|
||||
// We need a failed test if the importVectorKey operation fails, so
|
||||
// we know we never tested encryption
|
||||
promise_test(function(test) {
|
||||
assert_unreached("importKey failed for " + vector.name);
|
||||
}, "importKey step for decryption: " + vector.name + " with altered ciphertext during call");
|
||||
});
|
||||
|
||||
all_promises.push(promise);
|
||||
});
|
||||
|
||||
// Check for successful decryption even if ciphertext is altered after calling encrypt.
|
||||
passingVectors.forEach(function(vector) {
|
||||
var ciphertext = copyBuffer(vector.result);
|
||||
var promise = importVectorKey(vector, ["encrypt", "decrypt"])
|
||||
@@ -98,13 +162,13 @@ function run_test() {
|
||||
});
|
||||
ciphertext[0] = 255 - ciphertext[0];
|
||||
return operation;
|
||||
}, vector.name + " decryption with altered ciphertext");
|
||||
}, vector.name + " decryption with altered ciphertext after call");
|
||||
}, function(err) {
|
||||
// We need a failed test if the importVectorKey operation fails, so
|
||||
// we know we never tested encryption
|
||||
promise_test(function(test) {
|
||||
assert_unreached("importKey failed for " + vector.name);
|
||||
}, "importKey step for decryption: " + vector.name + " with altered ciphertext");
|
||||
}, "importKey step for decryption: " + vector.name + " with altered ciphertext after call");
|
||||
});
|
||||
|
||||
all_promises.push(promise);
|
||||
|
||||
Reference in New Issue
Block a user