Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update test-crypto-aes-wrap to use node:test #55110

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 61 additions & 54 deletions test/parallel/test-crypto-aes-wrap.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,69 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const { describe, it } = require('node:test');

const assert = require('assert');
const crypto = require('crypto');
// Disabling the unnecessary lint rule here. We're testing the common.hasCrypto
// in the skip option of the describe block.
/* eslint-disable node-core/crypto-check */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why don't we just skip crypto on the python runner? This would avoid spawning those threads?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely worthwhile.


const test = [
{
algorithm: 'aes128-wrap',
key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
iv: '3fd838af4093d749',
text: '12345678123456781234567812345678'
},
{
algorithm: 'id-aes128-wrap-pad',
key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
iv: '3fd838af',
text: '12345678123456781234567812345678123'
},
{
algorithm: 'aes192-wrap',
key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
iv: '3fd838af4093d749',
text: '12345678123456781234567812345678'
},
{
algorithm: 'id-aes192-wrap-pad',
key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
iv: '3fd838af',
text: '12345678123456781234567812345678123'
},
{
algorithm: 'aes256-wrap',
key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
iv: '3fd838af4093d749',
text: '12345678123456781234567812345678'
},
{
algorithm: 'id-aes256-wrap-pad',
key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
iv: '3fd838af',
text: '12345678123456781234567812345678123'
},
];
describe('aes wrap', { skip: !common.hasCrypto }, () => {
const crypto = require('crypto');
const test = [
{
algorithm: 'aes128-wrap',
key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
iv: '3fd838af4093d749',
text: '12345678123456781234567812345678'
},
{
algorithm: 'id-aes128-wrap-pad',
key: 'b26f309fbe57e9b3bb6ae5ef31d54450',
iv: '3fd838af',
text: '12345678123456781234567812345678123'
},
{
algorithm: 'aes192-wrap',
key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
iv: '3fd838af4093d749',
text: '12345678123456781234567812345678'
},
{
algorithm: 'id-aes192-wrap-pad',
key: '40978085d68091f7dfca0d7dfc7a5ee76d2cc7f2f345a304',
iv: '3fd838af',
text: '12345678123456781234567812345678123'
},
{
algorithm: 'aes256-wrap',
key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
iv: '3fd838af4093d749',
text: '12345678123456781234567812345678'
},
{
algorithm: 'id-aes256-wrap-pad',
key: '29c9eab5ed5ad44134a1437fe2e673b4d88a5b7c72e68454fea08721392b7323',
iv: '3fd838af',
text: '12345678123456781234567812345678123'
},
];

test.forEach((data) => {
const cipher = crypto.createCipheriv(
data.algorithm,
Buffer.from(data.key, 'hex'),
Buffer.from(data.iv, 'hex'));
const ciphertext = cipher.update(data.text, 'utf8');
test.forEach((data) => {
it(`${data.algorithm}`, async (t) => {
const cipher = crypto.createCipheriv(
data.algorithm,
Buffer.from(data.key, 'hex'),
Buffer.from(data.iv, 'hex'));
const ciphertext = cipher.update(data.text, 'utf8');

const decipher = crypto.createDecipheriv(
data.algorithm,
Buffer.from(data.key, 'hex'),
Buffer.from(data.iv, 'hex'));
const msg = decipher.update(ciphertext, 'buffer', 'utf8');
const decipher = crypto.createDecipheriv(
data.algorithm,
Buffer.from(data.key, 'hex'),
Buffer.from(data.iv, 'hex'));
const msg = decipher.update(ciphertext, 'buffer', 'utf8');

assert.strictEqual(msg, data.text, `${data.algorithm} test case failed`);
t.assert.strictEqual(msg, data.text);
});
});
});

/* eslint-enable node-core/crypto-check */
Loading
Loading