const value = '🏴☠️ Hello, world!';
suite('encryptRaw and decryptRaw', { concurrency: true }, () => {
- test('works on simple string', { concurrency: true }, async () => {
+ test('works on simple string', async () => {
deepStrictEqual(await encryptRaw({ version, prf, value }).then(value => decryptRaw({ prf, value })), value);
});
});
suite('encryptRaw', { concurrency: true }, () => {
- test('throws on invalid version', { concurrency: true }, async () => {
+ test('throws on invalid version', async () => {
// @ts-expect-error
await rejects(encryptRaw({ version: 'INVALID', prf, value }), { name: 'TypeError', message: 'envpass version "INVALID" is not supported.' });
});
- test('throws on invalid prf', { concurrency: true }, async () => {
+ test('throws on invalid prf', async () => {
// @ts-expect-error
await rejects(encryptRaw({ version, prf: 'INVALID', value }), { name: 'TypeError', message: 'prf "INVALID" is not an ArrayBuffer or Uint8Array.' });
});
- test('throws on invalid value', { concurrency: true }, async () => {
+ test('throws on invalid value', async () => {
// @ts-expect-error
await rejects(encryptRaw({ version, prf, value: {} }), { name: 'TypeError', message: 'Value "{}" is not a string.' });
});
- test('output value does not have base64 padding', { concurrency: true }, async () => {
+ test('output value does not have base64 padding', async () => {
for (const value of ['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa']) {
const output = await encryptRaw({ version, prf, value });
notDeepStrictEqual(output.at(-1), '=');
suite('decryptRaw', { concurrency: true }, () => {
const value = 'envpass:v1:AAA';
- test('throws on invalid prf', { concurrency: true }, async () => {
+ test('throws on invalid prf', async () => {
// @ts-expect-error
await rejects(decryptRaw({ prf: 'INVALID', value }), { name: 'TypeError', message: 'prf "INVALID" is not an ArrayBuffer or Uint8Array.' });
});
- test('throws on invalid value', { concurrency: true }, async () => {
+ test('throws on invalid value', async () => {
// @ts-expect-error
await rejects(decryptRaw({ prf, value: {} }), { name: 'TypeError', message: 'Value "{}" is not a string.' });
});
- test('throws on invalid magic in value', { concurrency: true }, async () => {
+ test('throws on invalid magic in value', async () => {
// @ts-expect-error
await rejects(decryptRaw({ prf, value: 'INVALID:v1:AAA' }), { name: 'TypeError', message: 'Value "INVALID:v1:AAA" is not an envpass encrypted value.' });
});
- test('throws on invalid version in value', { concurrency: true }, async () => {
+ test('throws on invalid version in value', async () => {
// @ts-expect-error
await rejects(decryptRaw({ prf, value: 'envpass:INVALID:AAA' }), { name: 'TypeError', message: 'envpass version "INVALID" is not supported.' });
});
- test('throws on invalid (non-base64) string in value', { concurrency: true }, async () => {
+ test('throws on invalid (non-base64) string in value', async () => {
await rejects(decryptRaw({ prf, value: 'envpass:v1:🏴☠️' }), { name: 'SyntaxError', message: 'Found a character that cannot be part of a valid base64 string.' });
});
});
\ No newline at end of file
{ name: 'simple object', obj: { a: '1', b: '2', c: '3' }, str: 'a=1\nb=2\nc=3\n' },
];
for (const { name, obj, str } of vectors) {
- test(`converts: ${name}`, { concurrency: true }, () => {
+ test(`converts: ${name}`, () => {
deepStrictEqual(toEnvString(obj), str);
});
- test(`inverses parseEnv for: ${name}`, { concurrency: true }, () => {
+ test(`inverses parseEnv for: ${name}`, () => {
deepStrictEqual(toEnvString(parseEnv(str)), str);
});
- test(`is inverse of parseEnv for: ${name}`, { concurrency: true }, () => {
+ test(`is inverse of parseEnv for: ${name}`, () => {
const env = Object.create(null);
Object.assign(env, obj);
deepStrictEqual(parseEnv(toEnvString(env)), env);
{ name: 'rejects leading whitespace', input: ' envpass:v1:rXAhBNXZFsLl8EtZm3GHAZttZyLYP3j97Yy4qly53wBodRyyKYi8PlxjOlggc7mVLA/HoME4QSKdhuEs3C4UKvo0J3ZAV+JbrzfZbsBJ3tvvG4/UEVxB1+0IPoUyjhoO' },
];
for (const { name, input } of rejects) {
- test(name, { concurrency: true }, () => {
+ test(name, () => {
deepStrictEqual(parseEnvpassEncrypted(input), null);
});
}
{ name: 'accepts envpass encrypted string', input: 'envpass:v1:rXAhBNXZFsLl8EtZm3GHAZttZyLYP3j97Yy4qly53wBodRyyKYi8PlxjOlggc7mVLA/HoME4QSKdhuEs3C4UKvo0J3ZAV+JbrzfZbsBJ3tvvG4/UEVxB1+0IPoUyjhoO' },
];
for (const { name, input } of accepts) {
- test(name, { concurrency: true }, () => {
+ test(name, () => {
deepStrictEqual(parseEnvpassEncrypted(input), input);
});
}
});
suite('InputError', { concurrency: true }, () => {
- test('is throwable', { concurrency: true }, () => {
+ test('is throwable', () => {
throws(() => { throw new InputError(); }, InputError);
});
- test('inherits Error', { concurrency: true }, () => {
+ test('inherits Error', () => {
ok(new InputError() instanceof Error);
});
- test('sets name to "InputError"', { concurrency: true }, () => {
+ test('sets name to "InputError"', () => {
deepStrictEqual(new InputError().name, 'InputError');
});
- test('accepts string message', { concurrency: true }, () => {
+ test('accepts string message', () => {
const msg = 'TEST';
deepStrictEqual(new InputError(msg).message, msg);
});