46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
/* eslint-disable no-magic-numbers */
|
|
// @ts-nocheck
|
|
'use strict';
|
|
|
|
const test = require ('ava');
|
|
const crypto = require ('../index');
|
|
|
|
test ('encryption', (t) => {
|
|
const enc = crypto.encrypt_aes ('foo', 'bar');
|
|
t.is (typeof enc, 'string');
|
|
});
|
|
|
|
test ('decryption', (t) => {
|
|
const enc = crypto.encrypt_aes ('foo', 'bar');
|
|
const dec = crypto.decrypt_aes (enc, 'bar');
|
|
t.is (dec, 'foo');
|
|
});
|
|
|
|
test ('fail decryption', (t) => {
|
|
const enc = crypto.encrypt_aes ('foo', 'bar');
|
|
const dec = crypto.decrypt_aes (enc, 'baz');
|
|
t.is (dec, null);
|
|
});
|
|
|
|
test ('rethrow decryption', (t) => {
|
|
const enc = crypto.encrypt_aes ('foo', 'bar');
|
|
t.throws (() => {
|
|
const dec = crypto.decrypt_aes (enc, 'baz', true);
|
|
});
|
|
});
|
|
|
|
test ('unique crypto strings', (t) => {
|
|
const enc = [
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar'),
|
|
crypto.encrypt_aes ('foo', 'bar')
|
|
];
|
|
const unique = enc.filter ((v, i) => enc.indexOf (v) === i).length;
|
|
t.is (unique, 8);
|
|
});
|