diff options
author | Matt Mastracci <matthew@mastracci.com> | 2024-02-10 13:22:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-10 20:22:13 +0000 |
commit | f5e46c9bf2f50d66a953fa133161fc829cecff06 (patch) | |
tree | 8faf2f5831c1c7b11d842cd9908d141082c869a5 /cli/tests/node_compat/test/parallel/test-crypto-hkdf.js | |
parent | d2477f780630a812bfd65e3987b70c0d309385bb (diff) |
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
Diffstat (limited to 'cli/tests/node_compat/test/parallel/test-crypto-hkdf.js')
-rw-r--r-- | cli/tests/node_compat/test/parallel/test-crypto-hkdf.js | 203 |
1 files changed, 0 insertions, 203 deletions
diff --git a/cli/tests/node_compat/test/parallel/test-crypto-hkdf.js b/cli/tests/node_compat/test/parallel/test-crypto-hkdf.js deleted file mode 100644 index b5b35e3ce..000000000 --- a/cli/tests/node_compat/test/parallel/test-crypto-hkdf.js +++ /dev/null @@ -1,203 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. - -'use strict'; - -const common = require('../common'); - -if (!common.hasCrypto) - common.skip('missing crypto'); - -const { kMaxLength } = require('buffer'); -const assert = require('assert'); -const { - createSecretKey, - hkdf, - hkdfSync -} = require('crypto'); - -{ - assert.throws(() => hkdf(), { - code: 'ERR_INVALID_ARG_TYPE', - message: /The "digest" argument must be of type string/ - }); - - [1, {}, [], false, Infinity].forEach((i) => { - assert.throws(() => hkdf(i, 'a'), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "digest" argument must be of type string/ - }); - assert.throws(() => hkdfSync(i, 'a'), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "digest" argument must be of type string/ - }); - }); - - [1, {}, [], false, Infinity].forEach((i) => { - assert.throws(() => hkdf('sha256', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "ikm" argument must be / - }); - assert.throws(() => hkdfSync('sha256', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "ikm" argument must be / - }); - }); - - [1, {}, [], false, Infinity].forEach((i) => { - assert.throws(() => hkdf('sha256', 'secret', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "salt" argument must be / - }); - assert.throws(() => hkdfSync('sha256', 'secret', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "salt" argument must be / - }); - }); - - [1, {}, [], false, Infinity].forEach((i) => { - assert.throws(() => hkdf('sha256', 'secret', 'salt', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "info" argument must be / - }); - assert.throws(() => hkdfSync('sha256', 'secret', 'salt', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "info" argument must be / - }); - }); - - ['test', {}, [], false].forEach((i) => { - assert.throws(() => hkdf('sha256', 'secret', 'salt', 'info', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "length" argument must be of type number/ - }); - assert.throws(() => hkdfSync('sha256', 'secret', 'salt', 'info', i), { - code: 'ERR_INVALID_ARG_TYPE', - message: /^The "length" argument must be of type number/ - }); - }); - - assert.throws(() => hkdf('sha256', 'secret', 'salt', 'info', -1), { - code: 'ERR_OUT_OF_RANGE' - }); - assert.throws(() => hkdfSync('sha256', 'secret', 'salt', 'info', -1), { - code: 'ERR_OUT_OF_RANGE' - }); - assert.throws(() => hkdf('sha256', 'secret', 'salt', 'info', - kMaxLength + 1), { - code: 'ERR_OUT_OF_RANGE' - }); - assert.throws(() => hkdfSync('sha256', 'secret', 'salt', 'info', - kMaxLength + 1), { - code: 'ERR_OUT_OF_RANGE' - }); - - assert.throws(() => hkdfSync('unknown', 'a', '', '', 10), { - code: 'ERR_CRYPTO_INVALID_DIGEST' - }); - - assert.throws(() => hkdf('unknown', 'a', '', Buffer.alloc(1025), 10, - common.mustNotCall()), { - code: 'ERR_OUT_OF_RANGE' - }); - - assert.throws(() => hkdfSync('unknown', 'a', '', Buffer.alloc(1025), 10), { - code: 'ERR_OUT_OF_RANGE' - }); -} - -const algorithms = [ - ['sha256', 'secret', 'salt', 'info', 10], - ['sha256', '', '', '', 10], - ['sha256', '', 'salt', '', 10], - ['sha512', 'secret', 'salt', '', 15], -]; - -algorithms.forEach(([ hash, secret, salt, info, length ]) => { - { - const syncResult = hkdfSync(hash, secret, salt, info, length); - assert(syncResult instanceof ArrayBuffer); - let is_async = false; - hkdf(hash, secret, salt, info, length, - common.mustSucceed((asyncResult) => { - assert(is_async); - assert(asyncResult instanceof ArrayBuffer); - assert.deepStrictEqual(syncResult, asyncResult); - })); - // Keep this after the hkdf call above. This verifies - // that the callback is invoked asynchronously. - is_async = true; - } - - { - const buf_secret = Buffer.from(secret); - const buf_salt = Buffer.from(salt); - const buf_info = Buffer.from(info); - - const syncResult = hkdfSync(hash, buf_secret, buf_salt, buf_info, length); - hkdf(hash, buf_secret, buf_salt, buf_info, length, - common.mustSucceed((asyncResult) => { - assert.deepStrictEqual(syncResult, asyncResult); - })); - } - - { - const key_secret = createSecretKey(Buffer.from(secret)); - const buf_salt = Buffer.from(salt); - const buf_info = Buffer.from(info); - - const syncResult = hkdfSync(hash, key_secret, buf_salt, buf_info, length); - hkdf(hash, key_secret, buf_salt, buf_info, length, - common.mustSucceed((asyncResult) => { - assert.deepStrictEqual(syncResult, asyncResult); - })); - } - - { - const ta_secret = new Uint8Array(Buffer.from(secret)); - const ta_salt = new Uint16Array(Buffer.from(salt)); - const ta_info = new Uint32Array(Buffer.from(info)); - - const syncResult = hkdfSync(hash, ta_secret, ta_salt, ta_info, length); - hkdf(hash, ta_secret, ta_salt, ta_info, length, - common.mustSucceed((asyncResult) => { - assert.deepStrictEqual(syncResult, asyncResult); - })); - } - - { - const ta_secret = new Uint8Array(Buffer.from(secret)); - const ta_salt = new Uint16Array(Buffer.from(salt)); - const ta_info = new Uint32Array(Buffer.from(info)); - - const syncResult = hkdfSync( - hash, - ta_secret.buffer, - ta_salt.buffer, - ta_info.buffer, - length); - hkdf(hash, ta_secret, ta_salt, ta_info, length, - common.mustSucceed((asyncResult) => { - assert.deepStrictEqual(syncResult, asyncResult); - })); - } - - { - const ta_secret = new Uint8Array(Buffer.from(secret)); - const sa_salt = new ArrayBuffer(0); - const sa_info = new ArrayBuffer(1); - - const syncResult = hkdfSync( - hash, - ta_secret.buffer, - sa_salt, - sa_info, - length); - hkdf(hash, ta_secret, sa_salt, sa_info, length, - common.mustSucceed((asyncResult) => { - assert.deepStrictEqual(syncResult, asyncResult); - })); - } -}); |