Fix implementation of async tests

This commit is contained in:
D. Scott Boggs 2023-10-11 06:40:30 -04:00
parent e511bd485a
commit a379c994f2

View file

@ -13,7 +13,7 @@ describe('hashing and verification', function () {
salt.length.should.eq(32)
key.length.should.eq(86)
Buffer.from(key, 'base64url').length.should.eq(64)
scrypt.verify(derived, pass).should.eventually.be.true
await scrypt.verify(derived, pass).should.eventually.be.true
})
})
describe('hashSync() and sync verification', function () {
@ -31,35 +31,37 @@ describe('hashSync() and sync verification', function () {
describe('hash() error cases', function () {
it('throws an error when it receives an invalid cost value', async function () {
scrypt
await scrypt
.hash('bad password', { cost: 2.3 })
.should.be.rejectedWith(scrypt.InvalidOptions)
scrypt
await scrypt
.hash('bad password', { cost: 2 /* too small */ })
.should.be.rejectedWith(scrypt.InvalidOptions)
})
it('throws an error when it receives an invalid keyLength value', async function () {
scrypt
await scrypt
.hash('bad password', { keyLength: 2.3 })
.should.be.rejectedWith(scrypt.InvalidOptions)
})
it('throws an error when it receives an invalid saltLength value', async function () {
scrypt
await scrypt
.hash('bad password', { saltLength: 2.3 })
.should.be.rejectedWith(scrypt.InvalidOptions)
scrypt
await scrypt
.hash('bad password', { saltLength: 15 /* too small */ })
.should.be.rejectedWith(scrypt.InvalidOptions)
})
it('throws an error when the password is not the right thing', function () {
scrypt.hash(undefined).should.be.rejected
scrypt.hash(null).should.be.rejected
scrypt.hash(123.4).should.be.rejected
scrypt.hash(NaN).should.be.rejected
scrypt.hash(['some', 'arbitrary', 'values']).should.be.rejected
scrypt.hash({ some: 'arbitrary values' }).should.be.rejected
scrypt.hash(Symbol('something else')).should.be.rejected
scrypt.hash(() => "no, you can't do this either").should.be.rejected
it('throws an error when the password is not the right thing', async function () {
await Promise.all([
scrypt.hash(undefined).should.be.rejected,
scrypt.hash(null).should.be.rejected,
scrypt.hash(123.4).should.be.rejected,
scrypt.hash(NaN).should.be.rejected,
scrypt.hash(['some', 'arbitrary', 'values']).should.be.rejected,
scrypt.hash({ some: 'arbitrary values' }).should.be.rejected,
scrypt.hash(Symbol('something else')).should.be.rejected,
scrypt.hash(() => "no, you can't do this either").should.be.rejected,
])
})
})
@ -102,20 +104,22 @@ describe('hashSync() error cases', function () {
})
describe('verify() error cases', function () {
it('throws an error when the password is not the right thing', function () {
it('throws an error when the password is not the right thing', async function () {
const validHash =
'e.WCu8zB9FHLhXaAf5Svn7NE4ySqB5X45X.ZLpxVwLz1816kmshqXHn12X_4_lZD_0Yl-27KSLLzdhXJ0Fr2huSD7BvoMlBMOMUQBKyKXPzhKI01_Ot-C_w8g'
scrypt.verify(validHash, undefined).should.be.rejected
scrypt.verify(validHash, null).should.be.rejected
scrypt.verify(validHash, 123.4).should.be.rejected
scrypt.verify(validHash, NaN).should.be.rejected
scrypt.verify(validHash, ['some', 'arbitrary', 'values']).should.be.rejected
scrypt.verify(validHash, { some: 'arbitrary values' }).should.be.rejected
scrypt.verify(validHash, Symbol('something else')).should.be.rejected
await Promise.all([
scrypt.verify(validHash, undefined).should.be.rejected,
scrypt.verify(validHash, null).should.be.rejected,
scrypt.verify(validHash, 123.4).should.be.rejected,
scrypt.verify(validHash, NaN).should.be.rejected,
scrypt.verify(validHash, ['some', 'arbitrary', 'values']).should.be.rejected,
scrypt.verify(validHash, { some: 'arbitrary values' }).should.be.rejected,
scrypt.verify(validHash, Symbol('something else')).should.be.rejected,
scrypt.verify(validHash, () => "no, you can't do this either").should.be
.rejected
.rejected,
scrypt.verify(validHash, Promise.resolve("no, you can't do this either"))
.should.be.rejected
.should.be.rejected,
])
})
it('throws an error when the hash is not the expected format', async function () {
const validHash =
@ -139,7 +143,7 @@ describe('verify() error cases', function () {
await checkThrows(1234, TypeError)
await checkThrows(null, TypeError)
await checkThrows([1, 2, 3], TypeError)
scrypt.verify(
await scrypt.verify(
{
// This is technically valid, why try to prevent it? 🤷
split: () => hashParts,