projects
/
squeep-mystery-box
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c4bbf34
)
cleanup tests
author
Justin Wind
<justin.wind+git@gmail.com>
Sat, 4 Mar 2023 19:27:12 +0000
(11:27 -0800)
committer
Justin Wind
<justin.wind+git@gmail.com>
Sat, 4 Mar 2023 19:27:12 +0000
(11:27 -0800)
test/lib/mystery-box.js
patch
|
blob
|
history
diff --git
a/test/lib/mystery-box.js
b/test/lib/mystery-box.js
index a48bad847e18a795ac3b1b9692e053d44f4efb42..2f2b734e0a3271c47530b90d11b03664d59a2383 100644
(file)
--- a/
test/lib/mystery-box.js
+++ b/
test/lib/mystery-box.js
@@
-8,7
+8,6
@@
const MysteryBox = require('../../lib/mystery-box');
const stubLogger = require('../stub-logger');
describe('MysteryBox', function () {
const stubLogger = require('../stub-logger');
describe('MysteryBox', function () {
- const noExpectedException = 'did not get expected exception';
let mb, options, object;
beforeEach(function () {
options = {
let mb, options, object;
beforeEach(function () {
options = {
@@
-22,12
+21,7
@@
describe('MysteryBox', function () {
describe('constructor', function () {
it('needs a secret', async function () {
options = {};
describe('constructor', function () {
it('needs a secret', async function () {
options = {};
- try {
- mb = new MysteryBox(stubLogger, options);
- assert.fail(noExpectedException);
- } catch (e) {
- assert.strictEqual(e.message, 'missing encryption secret', noExpectedException);
- }
+ assert.rejects(() => new MysteryBox(stubLogger, options));
});
it('accepts multiple secrets', async function () {
});
it('accepts multiple secrets', async function () {
@@
-47,42
+41,23
@@
describe('MysteryBox', function () {
});
it('covers options', function () {
});
it('covers options', function () {
- try {
- mb = new MysteryBox(stubLogger);
- assert.fail(noExpectedException);
- } catch (e) {
- assert.strictEqual(e.message, 'missing encryption secret', noExpectedException);
- }
+ assert.rejects(() => new MysteryBox(stubLogger));
});
it('covers bad flags', function () {
options.defaultFlags = 300;
});
it('covers bad flags', function () {
options.defaultFlags = 300;
- try {
- mb = new MysteryBox(stubLogger, options);
- assert.fail(noExpectedException);
- } catch (e) {
- assert(e instanceof RangeError, noExpectedException);
- }
+ assert.rejects(() => new MysteryBox(stubLogger, options), RangeError);
});
it('covers missing ciphers', function () {
sinon.stub(MysteryBox._test.crypto, 'getCiphers').returns(['rot13']);
});
it('covers missing ciphers', function () {
sinon.stub(MysteryBox._test.crypto, 'getCiphers').returns(['rot13']);
- try {
- mb = new MysteryBox(stubLogger, options);
- assert.fail(noExpectedException);
- } catch (e) {
- assert.strictEqual(e.message, 'no supported versions available', noExpectedException);
- }
+ assert.rejects(() => new MysteryBox(stubLogger, options));
});
}); // constructor
describe('_keyFromSecret', function () {
it('covers invalid', async function () {
});
}); // constructor
describe('_keyFromSecret', function () {
it('covers invalid', async function () {
- try {
- await MysteryBox._keyFromSecret('unknown deriver', 'secret', 'salt', 32);
- } catch (e) {
- assert(e instanceof RangeError);
- }
+ assert.rejects(() => MysteryBox._keyFromSecret('unknown deriver', 'secret', 'salt', 32), RangeError);
});
}); // _keyFromSecret
});
}); // _keyFromSecret
@@
-92,24
+67,14
@@
describe('MysteryBox', function () {
});
it('covers packing unsupported version', async function () {
});
it('covers packing unsupported version', async function () {
- try {
- await mb.pack({}, 0);
- assert.fail(noExpectedException);
- } catch (e) {
- assert(e instanceof RangeError, noExpectedException);
- }
+ assert.rejects(() => mb.pack({}, 0), RangeError);
});
it('covers unpacking unsupported version', async function () {
const badBuffer = Buffer.alloc(128);
badBuffer.writeUInt8(0, 0); // No such thing as version 0
const badPayload = badBuffer.toString('base64');
});
it('covers unpacking unsupported version', async function () {
const badBuffer = Buffer.alloc(128);
badBuffer.writeUInt8(0, 0); // No such thing as version 0
const badPayload = badBuffer.toString('base64');
- try {
- await mb.unpack(badPayload);
- assert.fail(noExpectedException);
- } catch (e) {
- assert(e instanceof RangeError, noExpectedException);
- }
+ assert.rejects(() => mb.unpack(badPayload), RangeError);
});
it('encrypts and decrypts default version', async function () {
});
it('encrypts and decrypts default version', async function () {
@@
-156,12
+121,7
@@
describe('MysteryBox', function () {
flarp: 13,
};
const oldEncrypted = await oldmb.pack(object);
flarp: 13,
};
const oldEncrypted = await oldmb.pack(object);
- try {
- await newmb.unpack(oldEncrypted);
- assert.fail(noExpectedException);
- } catch (e) {
- assert(e instanceof Error);
- }
+ assert.rejects(() => newmb.unpack(oldEncrypted));
});
it('encrypts and decrypts all available versions +brotli', async function () {
});
it('encrypts and decrypts all available versions +brotli', async function () {
@@
-221,23
+181,13
@@
describe('MysteryBox', function () {
});
it('handles undefined', async function () {
});
it('handles undefined', async function () {
- try {
- await mb.unpack();
- assert.fail(noExpectedException);
- } catch (e) {
- assert(e instanceof RangeError, noExpectedException);
- }
+ assert.rejects(() => mb.unpack(), RangeError);
});
it('handles incomplete', async function () {
this.slow(500);
const encryptedResult = await mb.pack({ foo: 'bar' });
});
it('handles incomplete', async function () {
this.slow(500);
const encryptedResult = await mb.pack({ foo: 'bar' });
- try {
- await mb.unpack(encryptedResult.slice(0, 6));
- assert.fail(noExpectedException);
- } catch (e) {
- assert(e instanceof RangeError, noExpectedException);
- }
+ assert.rejects(() => mb.unpack(encryptedResult.slice(0, 6)), RangeError);
});
}); // pack, unpack
});
}); // pack, unpack