X-Git-Url: http://git.squeep.com/?p=squeep-mystery-box;a=blobdiff_plain;f=test%2Flib%2Fmystery-box.js;h=802d8b3da8e1bb03e46475ed904c306535ec1336;hp=a6e69b91f25ae0553dee526649e9ae51e103ef14;hb=5c90dcd8088365a17f699dd683958536bc33c08c;hpb=5029da9845bcd89324e1e6ae95d94caa9febd9e8 diff --git a/test/lib/mystery-box.js b/test/lib/mystery-box.js index a6e69b9..802d8b3 100644 --- a/test/lib/mystery-box.js +++ b/test/lib/mystery-box.js @@ -30,6 +30,23 @@ describe('MysteryBox', function () { } }); + 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); @@ -106,6 +123,38 @@ describe('MysteryBox', function () { 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 = { @@ -172,6 +221,7 @@ describe('MysteryBox', function () { }); it('handles incomplete', async function () { + this.slow(500); const encryptedResult = await mb.pack({ foo: 'bar' }); try { await mb.unpack(encryptedResult.slice(0, 6));