Automatic update from web-platform-tests [WebCryptoAPI] Improve test coverage and reduce duplication (#61397) * [WebCryptoAPI] Fix byte utility assertions * [WebCryptoAPI] Check CryptoKey usages exactly * [WebCryptoAPI] Await ML-KEM key exports * [WebCryptoAPI] Verify generated EdDSA signatures * [WebCryptoAPI] Check complete derived keys * [WebCryptoAPI] Scope ECDH test state locally * [WebCryptoAPI] Scope CFRG test state locally * [WebCryptoAPI] Test all invalid key usages * [WebCryptoAPI] Simplify resolved vector promises * [WebCryptoAPI] Preserve vector setup rejections * [WebCryptoAPI] Restore key test timeouts * [WebCryptoAPI] Clarify EdDSA input snapshot tests * [WebCryptoAPI] Modernize simple JavaScript idioms * [WebCryptoAPI] Share ML key import tests * [WebCryptoAPI] Share generateKey algorithm data * [WebCryptoAPI] Replace stale generateKey generator * [WebCryptoAPI] Share RSA key fixtures * [WebCryptoAPI] Share ML-DSA key fixtures * [WebCryptoAPI] Share AES test fixtures * [WebCryptoAPI] Share supports test runner * [WebCryptoAPI] Share XOF digest test runner * [WebCryptoAPI] Encode buffer views as raw bytes * [WebCryptoAPI] Check CryptoKey algorithm members * [WebCryptoAPI] Share ECDH test fixtures * [WebCryptoAPI] Share MAC sign and verify tests * [WebCryptoAPI] Share KDF derivation tests * [WebCryptoAPI] Share EC and OKP key fixtures * [WebCryptoAPI] Share ECDH derivation tests * [WebCryptoAPI] Share digest tests and source data * [WebCryptoAPI] Share asymmetric signature tests -- wpt-commits: 82c3d9069cf2e93e5528a1f428fa122bd9af651d wpt-pr: 61397
78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
// Step 1.
|
|
test(function() {
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
self.crypto.getRandomValues(new Float16Array(6))
|
|
}, "Float16Array")
|
|
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
const len = 65536 / Float16Array.BYTES_PER_ELEMENT + 1;
|
|
self.crypto.getRandomValues(new Float16Array(len));
|
|
}, "Float16Array (too long)")
|
|
}, "Float16 arrays");
|
|
|
|
test(function() {
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
self.crypto.getRandomValues(new Float32Array(6))
|
|
}, "Float32Array")
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
self.crypto.getRandomValues(new Float64Array(6))
|
|
}, "Float64Array")
|
|
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
const len = 65536 / Float32Array.BYTES_PER_ELEMENT + 1;
|
|
self.crypto.getRandomValues(new Float32Array(len));
|
|
}, "Float32Array (too long)")
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
const len = 65536 / Float64Array.BYTES_PER_ELEMENT + 1;
|
|
self.crypto.getRandomValues(new Float64Array(len))
|
|
}, "Float64Array (too long)")
|
|
}, "Float arrays");
|
|
|
|
test(function() {
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
self.crypto.getRandomValues(new DataView(new ArrayBuffer(6)))
|
|
}, "DataView")
|
|
|
|
assert_throws_dom("TypeMismatchError", function() {
|
|
self.crypto.getRandomValues(new DataView(new ArrayBuffer(65536 + 1)))
|
|
}, "DataView (too long)")
|
|
}, "DataView");
|
|
|
|
const arrays = [
|
|
'Int8Array',
|
|
'Int16Array',
|
|
'Int32Array',
|
|
'BigInt64Array',
|
|
'Uint8Array',
|
|
'Uint8ClampedArray',
|
|
'Uint16Array',
|
|
'Uint32Array',
|
|
'BigUint64Array',
|
|
];
|
|
|
|
for (const array of arrays) {
|
|
const ctor = globalThis[array];
|
|
|
|
test(function() {
|
|
assert_equals(self.crypto.getRandomValues(new ctor(8)).constructor,
|
|
ctor, "crypto.getRandomValues(new " + array + "(8))")
|
|
}, "Integer array: " + array);
|
|
|
|
test(function() {
|
|
const maxlength = 65536 / ctor.BYTES_PER_ELEMENT;
|
|
assert_throws_quotaexceedederror(() => {
|
|
self.crypto.getRandomValues(new ctor(maxlength + 1));
|
|
}, null, null, "crypto.getRandomValues length over 65536");
|
|
}, "Large length: " + array);
|
|
|
|
test(function() {
|
|
assert_true(self.crypto.getRandomValues(new ctor(0)).length === 0)
|
|
}, "Null arrays: " + array);
|
|
|
|
test(function() {
|
|
class Buffer extends ctor {}
|
|
// Must not throw for the test to pass
|
|
self.crypto.getRandomValues(new Buffer(256));
|
|
}, "Subclass of " + array);
|
|
}
|