}
});
+ it('accepts multiple secrets', async function () {
+ this.slow(500);
+ options = {
+ encryptionSecret: ['first poor secret', 'second poor secret'],
+ };
+ mb = new MysteryBox(stubLogger, options);
+ object = {
+ foo: 'bar',
+ baz: 'quux',
+ flarp: 13,
+ };
+ const encryptedResult = await mb.pack(object);
+ const decryptedResult = await mb.unpack(encryptedResult);
+ assert.deepStrictEqual(decryptedResult, object);
+
+ });
+
it('covers options', function () {
try {
mb = new MysteryBox(stubLogger);
assert.deepStrictEqual(decryptedResult, object);
});
+ it('decrypts secondary (older) secret', async function () {
+ this.slow(500);
+ const oldmb = new MysteryBox(stubLogger, { encryptionSecret: 'old secret' });
+ const newmb = new MysteryBox(stubLogger, { encryptionSecret: ['new secret', 'old secret'] });
+ object = {
+ foo: 'bar',
+ baz: 'quux',
+ flarp: 13,
+ };
+ const oldEncrypted = await oldmb.pack(object);
+ const newDecrypted = await newmb.unpack(oldEncrypted);
+ assert.deepStrictEqual(newDecrypted, object);
+ });
+
+ it('fails to decrypt invalid secret', async function () {
+ this.slow(500);
+ const oldmb = new MysteryBox(stubLogger, { encryptionSecret: 'very old secret' });
+ const newmb = new MysteryBox(stubLogger, { encryptionSecret: ['new secret', 'old secret'] });
+ object = {
+ foo: 'bar',
+ baz: 'quux',
+ flarp: 13,
+ };
+ const oldEncrypted = await oldmb.pack(object);
+ try {
+ await newmb.unpack(oldEncrypted);
+ assert.fail(noExpectedException);
+ } catch (e) {
+ assert(e instanceof Error);
+ }
+ });
+
it('encrypts and decrypts all available versions +brotli', async function () {
Object.keys(mb.versionParameters).map((v) => Number(v)).forEach(async (version) => {
object = {
});
it('handles incomplete', async function () {
+ this.slow(500);
const encryptedResult = await mb.pack({ foo: 'bar' });
try {
await mb.unpack(encryptedResult.slice(0, 6));