mirror of
https://github.com/xfarrow/blink
synced 2025-06-27 09:03:02 +02:00
Change endpoint from persons to people
This commit is contained in:
209
backend/apis/nodejs/node_modules/bcrypt/test/async.test.js
generated
vendored
Normal file
209
backend/apis/nodejs/node_modules/bcrypt/test/async.test.js
generated
vendored
Normal file
@ -0,0 +1,209 @@
|
||||
const bcrypt = require('../bcrypt');
|
||||
|
||||
test('salt_length', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.genSalt(10, function (err, salt) {
|
||||
expect(salt).toHaveLength(29);
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('salt_only_cb', () => {
|
||||
expect.assertions(1);
|
||||
expect(() => {
|
||||
bcrypt.genSalt((err, salt) => {
|
||||
});
|
||||
}).not.toThrow();
|
||||
})
|
||||
|
||||
test('salt_rounds_is_string_number', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt('10', void 0, function (err, salt) {
|
||||
expect(err instanceof Error).toBe(true)
|
||||
expect(err.message).toBe('rounds must be a number')
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('salt_rounds_is_string_non_number', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt('z', function (err, salt) {
|
||||
expect(err instanceof Error).toBe(true)
|
||||
expect(err.message).toBe('rounds must be a number')
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('salt_minor', done => {
|
||||
expect.assertions(3);
|
||||
bcrypt.genSalt(10, 'a', function (err, value) {
|
||||
expect(value).toHaveLength(29);
|
||||
const [_, minor, salt] = value.split('$');
|
||||
expect(minor).toEqual('2a');
|
||||
expect(salt).toEqual('10');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('salt_minor_b', done => {
|
||||
expect.assertions(3);
|
||||
bcrypt.genSalt(10, 'b', function (err, value) {
|
||||
expect(value).toHaveLength(29);
|
||||
const [_, minor, salt] = value.split('$');
|
||||
expect(minor).toEqual('2b');
|
||||
expect(salt).toEqual('10');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt(10, function (err, salt) {
|
||||
bcrypt.hash('password', salt, function (err, res) {
|
||||
expect(res).toBeDefined();
|
||||
expect(err).toBeUndefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_rounds', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.hash('bacon', 8, function (err, hash) {
|
||||
expect(bcrypt.getRounds(hash)).toEqual(8);
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_empty_strings', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.genSalt(10, function (err, salt) {
|
||||
bcrypt.hash('', salt, function (err, res) {
|
||||
expect(res).toBeDefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_fails_with_empty_salt', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.hash('', '', function (err, res) {
|
||||
expect(err.message).toBe('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue')
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_no_params', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.hash(function (err, hash) {
|
||||
expect(err.message).toBe('data must be a string or Buffer and salt must either be a salt string or a number of rounds')
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_one_param', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.hash('password', function (err, hash) {
|
||||
expect(err.message).toBe('data must be a string or Buffer and salt must either be a salt string or a number of rounds');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_salt_validity', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.hash('password', '$2a$10$somesaltyvaluertsetrse', function (err, enc) {
|
||||
expect(err).toBeUndefined();
|
||||
bcrypt.hash('password', 'some$value', function (err, enc) {
|
||||
expect(err.message).toBe("Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue");
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test('verify_salt', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt(10, function (err, value) {
|
||||
const [_, version, rounds] = value.split('$');
|
||||
expect(version).toEqual('2b');
|
||||
expect(rounds).toEqual('10');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('verify_salt_min_rounds', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt(1, function (err, value) {
|
||||
const [_, version, rounds] = value.split('$');
|
||||
expect(version).toEqual('2b');
|
||||
expect(rounds).toEqual('04');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('verify_salt_max_rounds', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt(100, function (err, value) {
|
||||
const [_, version, rounds] = value.split('$');
|
||||
expect(version).toEqual('2b');
|
||||
expect(rounds).toEqual('31');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_compare', done => {
|
||||
expect.assertions(2);
|
||||
bcrypt.genSalt(10, function (err, salt) {
|
||||
bcrypt.hash("test", salt, function (err, hash) {
|
||||
bcrypt.compare("test", hash, function (err, res) {
|
||||
expect(hash).toBeDefined();
|
||||
bcrypt.compare("blah", hash, function (err, res) {
|
||||
expect(res).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_compare_empty_strings', done => {
|
||||
expect.assertions(2);
|
||||
const hash = bcrypt.hashSync("test", bcrypt.genSaltSync(10));
|
||||
|
||||
bcrypt.compare("", hash, function (err, res) {
|
||||
expect(res).toEqual(false)
|
||||
bcrypt.compare("", "", function (err, res) {
|
||||
expect(res).toEqual(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_compare_invalid_strings', done => {
|
||||
expect.assertions(2);
|
||||
const fullString = 'envy1362987212538';
|
||||
const hash = '$2a$10$XOPbrlUPQdwdJUpSrIF6X.LbE14qsMmKGhM1A8W9iqaG3vv1BD7WC';
|
||||
const wut = ':';
|
||||
bcrypt.compare(fullString, hash, function (err, res) {
|
||||
expect(res).toBe(true);
|
||||
bcrypt.compare(fullString, wut, function (err, res) {
|
||||
expect(res).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test('compare_no_params', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.compare(function (err, hash) {
|
||||
expect(err.message).toBe('data and hash arguments required');
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_compare_one_param', done => {
|
||||
expect.assertions(1);
|
||||
bcrypt.compare('password', function (err, hash) {
|
||||
expect(err.message).toBe('data and hash arguments required');
|
||||
done();
|
||||
});
|
||||
})
|
48
backend/apis/nodejs/node_modules/bcrypt/test/implementation.test.js
generated
vendored
Normal file
48
backend/apis/nodejs/node_modules/bcrypt/test/implementation.test.js
generated
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
const bcrypt = require('../bcrypt');
|
||||
|
||||
// some tests were adapted from https://github.com/riverrun/bcrypt_elixir/blob/master/test/base_test.exs
|
||||
// which are under the BSD LICENSE
|
||||
|
||||
test('openwall', () => {
|
||||
expect(bcrypt.hashSync("U*U", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW");
|
||||
expect(bcrypt.hashSync("U*U*", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK");
|
||||
expect(bcrypt.hashSync("U*U*U", "$2a$05$XXXXXXXXXXXXXXXXXXXXXO")).toStrictEqual("$2a$05$XXXXXXXXXXXXXXXXXXXXXOAcXxm9kjPGEMsLznoKqmqw7tc8WCx4a");
|
||||
expect(bcrypt.hashSync("", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.7uG0VCzI2bS7j6ymqJi9CdcdxiRTWNy");
|
||||
expect(bcrypt.hashSync("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "$2a$05$abcdefghijklmnopqrstuu")).toStrictEqual("$2a$05$abcdefghijklmnopqrstuu5s2v8.iXieOjg/.AySBTTZIIVFJeBui");
|
||||
})
|
||||
|
||||
test('openbsd', () => {
|
||||
expect(bcrypt.hashSync("000000000000000000000000000000000000000000000000000000000000000000000000", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS")
|
||||
expect(bcrypt.hashSync("000000000000000000000000000000000000000000000000000000000000000000000000", "$2b$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2b$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS")
|
||||
})
|
||||
|
||||
test('long_passwords', () => {
|
||||
// bcrypt wrap-around bug in $2a$
|
||||
expect(bcrypt.hashSync("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS")
|
||||
expect(bcrypt.hashSync("01XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "$2a$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS")
|
||||
|
||||
// tests for $2b$ which fixes wrap-around bugs
|
||||
expect(bcrypt.hashSync("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234", "$2b$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2b$05$CCCCCCCCCCCCCCCCCCCCC.XxrQqgBi/5Sxuq9soXzDtjIZ7w5pMfK")
|
||||
expect(bcrypt.hashSync("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345", "$2b$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2b$05$CCCCCCCCCCCCCCCCCCCCC.XxrQqgBi/5Sxuq9soXzDtjIZ7w5pMfK")
|
||||
})
|
||||
|
||||
test('embedded_nulls', () => {
|
||||
expect(bcrypt.hashSync("Passw\0rd123", "$2b$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2b$05$CCCCCCCCCCCCCCCCCCCCC.VHy/kzL4sCcX3Ib3wN5rNGiRt.TpfxS")
|
||||
expect(bcrypt.hashSync("Passw\0 you can literally write anything after the NUL character", "$2b$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2b$05$CCCCCCCCCCCCCCCCCCCCC.4vJLJQ6nZ/70INTjjSZWQ0iyUek92tu")
|
||||
expect(bcrypt.hashSync(Buffer.from("Passw\0 you can literally write anything after the NUL character"), "$2b$05$CCCCCCCCCCCCCCCCCCCCC.")).toStrictEqual("$2b$05$CCCCCCCCCCCCCCCCCCCCC.4vJLJQ6nZ/70INTjjSZWQ0iyUek92tu")
|
||||
})
|
||||
|
||||
test('shorten_salt_to_128_bits', () => {
|
||||
expect(bcrypt.hashSync("test", "$2a$10$1234567899123456789012")).toStrictEqual("$2a$10$123456789912345678901u.OtL1A1eGK5wmvBKUDYKvuVKI7h2XBu")
|
||||
expect(bcrypt.hashSync("U*U*", "$2a$05$CCCCCCCCCCCCCCCCCCCCCh")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCCeUQ7VjYZ2hd4bLYZdhuPpZMUpEUJDw1S")
|
||||
expect(bcrypt.hashSync("U*U*", "$2a$05$CCCCCCCCCCCCCCCCCCCCCM")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK")
|
||||
expect(bcrypt.hashSync("U*U*", "$2a$05$CCCCCCCCCCCCCCCCCCCCCA")).toStrictEqual("$2a$05$CCCCCCCCCCCCCCCCCCCCC.VGOzA784oUp/Z0DY336zx7pLYAy0lwK")
|
||||
})
|
||||
|
||||
test('consistency', () => {
|
||||
expect(bcrypt.hashSync("ππππππππ", "$2a$10$.TtQJ4Jr6isd4Hp.mVfZeu")).toStrictEqual("$2a$10$.TtQJ4Jr6isd4Hp.mVfZeuh6Gws4rOQ/vdBczhDx.19NFK0Y84Dle")
|
||||
expect(bcrypt.hashSync("p@5sw0rd", "$2b$12$zQ4CooEXdGqcwi0PHsgc8e")).toStrictEqual("$2b$12$zQ4CooEXdGqcwi0PHsgc8eAf0DLXE/XHoBE8kCSGQ97rXwuClaPam")
|
||||
expect(bcrypt.hashSync("C'est bon, la vie!", "$2b$12$cbo7LZ.wxgW4yxAA5Vqlv.")).toStrictEqual("$2b$12$cbo7LZ.wxgW4yxAA5Vqlv.KR6QFPt4qCdc9RYJNXxa/rbUOp.1sw.")
|
||||
expect(bcrypt.hashSync("ἓν οἶδα ὅτι οὐδὲν οἶδα", "$2b$12$LeHKWR2bmrazi/6P22Jpau")).toStrictEqual("$2b$12$LeHKWR2bmrazi/6P22JpauX5my/eKwwKpWqL7L5iEByBnxNc76FRW")
|
||||
expect(bcrypt.hashSync(Buffer.from("ἓν οἶδα ὅτι οὐδὲν οἶδα"), "$2b$12$LeHKWR2bmrazi/6P22Jpau")).toStrictEqual("$2b$12$LeHKWR2bmrazi/6P22JpauX5my/eKwwKpWqL7L5iEByBnxNc76FRW")
|
||||
})
|
168
backend/apis/nodejs/node_modules/bcrypt/test/promise.test.js
generated
vendored
Normal file
168
backend/apis/nodejs/node_modules/bcrypt/test/promise.test.js
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
const bcrypt = require('../bcrypt');
|
||||
const promises = require('../promises');
|
||||
|
||||
test('salt_returns_promise_on_no_args', () => {
|
||||
// make sure test passes with non-native implementations such as bluebird
|
||||
// http://stackoverflow.com/questions/27746304/how-do-i-tell-if-an-object-is-a-promise
|
||||
expect(typeof bcrypt.genSalt().then).toEqual('function')
|
||||
})
|
||||
|
||||
test('salt_returns_promise_on_null_callback', () => {
|
||||
expect(typeof bcrypt.genSalt(13, null, null).then).toEqual('function')
|
||||
})
|
||||
|
||||
test('salt_length', () => {
|
||||
return expect(bcrypt.genSalt(10)).resolves.toHaveLength(29);
|
||||
})
|
||||
|
||||
test('salt_rounds_is_string_number', () => {
|
||||
return expect(bcrypt.genSalt('10')).rejects.toThrow('rounds must be a number');
|
||||
})
|
||||
|
||||
test('salt_rounds_is_string_non_number', () => {
|
||||
return expect(bcrypt.genSalt('b')).rejects.toThrow('rounds must be a number');
|
||||
})
|
||||
|
||||
test('hash_returns_promise_on_null_callback', () => {
|
||||
expect(typeof bcrypt.hash('password', 10, null).then).toStrictEqual('function')
|
||||
})
|
||||
|
||||
test('hash', () => {
|
||||
return expect(bcrypt.genSalt(10)
|
||||
.then(salt => bcrypt.hash('password', salt))).resolves.toBeDefined()
|
||||
})
|
||||
|
||||
test('hash_rounds', () => {
|
||||
return bcrypt.hash('bacon', 8).then(hash => {
|
||||
expect(bcrypt.getRounds(hash)).toStrictEqual(8)
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_empty_strings', () => {
|
||||
expect.assertions(2);
|
||||
return Promise.all([
|
||||
expect(bcrypt.genSalt(10)
|
||||
.then(salt => bcrypt.hash('', salt)))
|
||||
.resolves.toBeDefined(),
|
||||
expect(bcrypt.hash('', '')).rejects.toThrow(''),
|
||||
]);
|
||||
})
|
||||
|
||||
test('hash_no_params', () => {
|
||||
expect.assertions(1);
|
||||
return expect(bcrypt.hash()).rejects.toThrow('data and salt arguments required');
|
||||
})
|
||||
|
||||
test('hash_one_param', () => {
|
||||
return expect(bcrypt.hash('password')).rejects.toThrow('data and salt arguments required');
|
||||
})
|
||||
|
||||
test('hash_salt_validity', () => {
|
||||
expect.assertions(2);
|
||||
return Promise.all(
|
||||
[
|
||||
expect(bcrypt.hash('password', '$2a$10$somesaltyvaluertsetrse')).resolves.toBeDefined(),
|
||||
expect(bcrypt.hash('password', 'some$value')).rejects.toThrow("Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue")
|
||||
]);
|
||||
})
|
||||
|
||||
test('verify_salt', () => {
|
||||
expect.assertions(2);
|
||||
return bcrypt.genSalt(10).then(result => {
|
||||
const [_, version, salt] = result.split('$');
|
||||
expect(version).toEqual('2b')
|
||||
expect(salt).toEqual('10')
|
||||
});
|
||||
})
|
||||
|
||||
test('verify_salt_min_rounds', () => {
|
||||
expect.assertions(2);
|
||||
return bcrypt.genSalt(1).then(value => {
|
||||
const [_, version, rounds] = value.split('$');
|
||||
expect(version).toEqual('2b');
|
||||
expect(rounds).toEqual('04');
|
||||
});
|
||||
})
|
||||
|
||||
test('verify_salt_max_rounds', () => {
|
||||
expect.assertions(2);
|
||||
return bcrypt.genSalt(100).then(value => {
|
||||
const [_, version, rounds] = value.split('$');
|
||||
expect(version).toEqual('2b');
|
||||
expect(rounds).toEqual('31');
|
||||
});
|
||||
})
|
||||
|
||||
test('hash_compare_returns_promise_on_null_callback', () => {
|
||||
expect(typeof bcrypt.compare('password', 'something', null).then).toStrictEqual('function')
|
||||
})
|
||||
|
||||
test('hash_compare', () => {
|
||||
expect.assertions(3);
|
||||
return bcrypt.genSalt(10).then(function (salt) {
|
||||
expect(salt).toHaveLength(29);
|
||||
return bcrypt.hash("test", salt);
|
||||
}).then(hash => Promise.all(
|
||||
[
|
||||
expect(bcrypt.compare("test", hash)).resolves.toEqual(true),
|
||||
expect(bcrypt.compare("blah", hash)).resolves.toEqual(false)
|
||||
]));
|
||||
})
|
||||
|
||||
test('hash_compare_empty_strings', () => {
|
||||
expect.assertions(2);
|
||||
const hash = bcrypt.hashSync("test", bcrypt.genSaltSync(10));
|
||||
return Promise.all([
|
||||
expect(bcrypt.compare("", hash)).resolves.toEqual(false),
|
||||
expect(bcrypt.compare("", "")).resolves.toEqual(false)
|
||||
]);
|
||||
})
|
||||
|
||||
test('hash_compare_invalid_strings', () => {
|
||||
const fullString = 'envy1362987212538';
|
||||
const hash = '$2a$10$XOPbrlUPQdwdJUpSrIF6X.LbE14qsMmKGhM1A8W9iqaG3vv1BD7WC';
|
||||
const wut = ':';
|
||||
return Promise.all([
|
||||
expect(bcrypt.compare(fullString, hash)).resolves.toEqual(true),
|
||||
expect(bcrypt.compare(fullString, wut)).resolves.toEqual(false),
|
||||
]);
|
||||
})
|
||||
|
||||
test('hash_compare_no_params', () => {
|
||||
expect.assertions(1);
|
||||
return expect(bcrypt.compare()).rejects.toThrow('data and hash arguments required')
|
||||
})
|
||||
|
||||
test('hash_compare_one_param', () => {
|
||||
expect.assertions(1);
|
||||
return expect(bcrypt.compare('password')).rejects.toThrow('data and hash arguments required')
|
||||
})
|
||||
|
||||
test('change_promise_impl_reject', () => {
|
||||
|
||||
promises.use({
|
||||
reject: function () {
|
||||
return 'mock';
|
||||
}
|
||||
});
|
||||
|
||||
expect(promises.reject()).toEqual('mock');
|
||||
|
||||
// need to reset the promise implementation because of require cache
|
||||
promises.use(global.Promise);
|
||||
})
|
||||
|
||||
test('change_promise_impl_promise', () => {
|
||||
|
||||
promises.use({
|
||||
reject: function (err) {
|
||||
expect(err.message).toEqual('fn must be a function');
|
||||
return 'mock';
|
||||
}
|
||||
});
|
||||
|
||||
expect(promises.promise('', '', '')).toEqual('mock');
|
||||
|
||||
// need to reset the promise implementation because of require cache
|
||||
promises.use(global.Promise);
|
||||
})
|
46
backend/apis/nodejs/node_modules/bcrypt/test/repetitions.test.js
generated
vendored
Normal file
46
backend/apis/nodejs/node_modules/bcrypt/test/repetitions.test.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
const bcrypt = require('../bcrypt');
|
||||
|
||||
const EXPECTED = 2500; //number of times to iterate these tests.)
|
||||
|
||||
test('salt_length', () => {
|
||||
expect.assertions(EXPECTED);
|
||||
|
||||
return Promise.all(Array.from({length: EXPECTED},
|
||||
() => bcrypt.genSalt(10)
|
||||
.then(salt => expect(salt).toHaveLength(29))));
|
||||
})
|
||||
|
||||
test('test_hash_length', () => {
|
||||
expect.assertions(EXPECTED);
|
||||
const SALT = '$2a$04$TnjywYklQbbZjdjBgBoA4e';
|
||||
return Promise.all(Array.from({length: EXPECTED},
|
||||
() => bcrypt.hash('test', SALT)
|
||||
.then(hash => expect(hash).toHaveLength(60))));
|
||||
})
|
||||
|
||||
test('test_compare', () => {
|
||||
expect.assertions(EXPECTED);
|
||||
const HASH = '$2a$04$TnjywYklQbbZjdjBgBoA4e9G7RJt9blgMgsCvUvus4Iv4TENB5nHy';
|
||||
return Promise.all(Array.from({length: EXPECTED},
|
||||
() => bcrypt.compare('test', HASH)
|
||||
.then(match => expect(match).toEqual(true))));
|
||||
})
|
||||
|
||||
test('test_hash_and_compare', () => {
|
||||
expect.assertions(EXPECTED * 3);
|
||||
const salt = bcrypt.genSaltSync(4)
|
||||
|
||||
return Promise.all(Array.from({length: EXPECTED},
|
||||
() => {
|
||||
const password = 'secret' + Math.random();
|
||||
return bcrypt.hash(password, salt)
|
||||
.then(hash => {
|
||||
expect(hash).toHaveLength(60);
|
||||
const goodCompare = bcrypt.compare(password, hash).then(res => expect(res).toEqual(true));
|
||||
const badCompare = bcrypt.compare('bad' + password, hash).then(res => expect(res).toEqual(false));
|
||||
|
||||
return Promise.all([goodCompare, badCompare]);
|
||||
});
|
||||
}));
|
||||
}, 10000);
|
||||
|
125
backend/apis/nodejs/node_modules/bcrypt/test/sync.test.js
generated
vendored
Normal file
125
backend/apis/nodejs/node_modules/bcrypt/test/sync.test.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
const bcrypt = require('../bcrypt')
|
||||
|
||||
test('salt_length', () => {
|
||||
const salt = bcrypt.genSaltSync(13);
|
||||
expect(salt).toHaveLength(29);
|
||||
const [_, version, rounds] = salt.split('$');
|
||||
expect(version).toStrictEqual('2b')
|
||||
expect(rounds).toStrictEqual('13')
|
||||
})
|
||||
|
||||
test('salt_no_params', () => {
|
||||
const salt = bcrypt.genSaltSync();
|
||||
const [_, version, rounds] = salt.split('$');
|
||||
expect(version).toStrictEqual('2b')
|
||||
expect(rounds).toStrictEqual('10')
|
||||
})
|
||||
|
||||
test('salt_rounds_is_string_number', () => {
|
||||
expect(() => bcrypt.genSaltSync('10')).toThrowError('rounds must be a number');
|
||||
})
|
||||
|
||||
test('salt_rounds_is_NaN', () => {
|
||||
expect(() => bcrypt.genSaltSync('b')).toThrowError("rounds must be a number");
|
||||
})
|
||||
|
||||
test('salt_minor_a', () => {
|
||||
const salt = bcrypt.genSaltSync(10, 'a');
|
||||
const [_, version, rounds] = salt.split('$');
|
||||
expect(version).toStrictEqual('2a')
|
||||
expect(rounds).toStrictEqual('10')
|
||||
})
|
||||
|
||||
test('salt_minor_b', () => {
|
||||
const salt = bcrypt.genSaltSync(10, 'b');
|
||||
const [_, version, rounds] = salt.split('$');
|
||||
expect(version).toStrictEqual('2b')
|
||||
expect(rounds).toStrictEqual('10')
|
||||
})
|
||||
|
||||
test('hash', () => {
|
||||
expect(() => bcrypt.hashSync('password', bcrypt.genSaltSync(10))).not.toThrow()
|
||||
})
|
||||
|
||||
test('hash_rounds', () => {
|
||||
const hash = bcrypt.hashSync('password', 8);
|
||||
expect(bcrypt.getRounds(hash)).toStrictEqual(8)
|
||||
})
|
||||
|
||||
test('hash_empty_string', () => {
|
||||
expect(() => bcrypt.hashSync('', bcrypt.genSaltSync(10))).not.toThrow();
|
||||
expect(() => bcrypt.hashSync('password', '')).toThrowError('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue');
|
||||
expect(() => bcrypt.hashSync('', '')).toThrowError('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue');
|
||||
})
|
||||
|
||||
test('hash_pw_no_params', () => {
|
||||
expect(() => bcrypt.hashSync()).toThrow('data and salt arguments required');
|
||||
})
|
||||
|
||||
test('hash_pw_one_param', () => {
|
||||
expect(() => bcrypt.hashSync('password')).toThrow('data and salt arguments required');
|
||||
})
|
||||
|
||||
test('hash_pw_not_hash_str', () => {
|
||||
expect(() => bcrypt.hashSync('password', {})).toThrow("data must be a string or Buffer and salt must either be a salt string or a number of rounds")
|
||||
})
|
||||
|
||||
test('hash_salt_validity', () => {
|
||||
expect(2);
|
||||
expect(bcrypt.hashSync('password', '$2a$10$somesaltyvaluertsetrse')).toBeDefined()
|
||||
expect(() => bcrypt.hashSync('password', 'some$value')).toThrow('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue')
|
||||
})
|
||||
|
||||
test('verify_salt', () => {
|
||||
const salt = bcrypt.genSaltSync(10);
|
||||
const split_salt = salt.split('$');
|
||||
expect(split_salt[1]).toStrictEqual('2b')
|
||||
expect(split_salt[2]).toStrictEqual('10')
|
||||
})
|
||||
|
||||
test('verify_salt_min_rounds', () => {
|
||||
const salt = bcrypt.genSaltSync(1);
|
||||
const split_salt = salt.split('$');
|
||||
expect(split_salt[1]).toStrictEqual('2b')
|
||||
expect(split_salt[2]).toStrictEqual('04')
|
||||
})
|
||||
|
||||
test('verify_salt_max_rounds', () => {
|
||||
const salt = bcrypt.genSaltSync(100);
|
||||
const split_salt = salt.split('$');
|
||||
expect(split_salt[1]).toStrictEqual('2b')
|
||||
expect(split_salt[2]).toStrictEqual('31')
|
||||
})
|
||||
|
||||
test('hash_compare', () => {
|
||||
const salt = bcrypt.genSaltSync(10);
|
||||
expect(29).toStrictEqual(salt.length)
|
||||
const hash = bcrypt.hashSync("test", salt);
|
||||
expect(bcrypt.compareSync("test", hash)).toBeDefined()
|
||||
expect(!(bcrypt.compareSync("blah", hash))).toBeDefined()
|
||||
})
|
||||
|
||||
test('hash_compare_empty_strings', () => {
|
||||
expect(!(bcrypt.compareSync("", "password"))).toBeDefined()
|
||||
expect(!(bcrypt.compareSync("", ""))).toBeDefined()
|
||||
expect(!(bcrypt.compareSync("password", ""))).toBeDefined()
|
||||
})
|
||||
|
||||
test('hash_compare_invalid_strings', () => {
|
||||
const fullString = 'envy1362987212538';
|
||||
const hash = '$2a$10$XOPbrlUPQdwdJUpSrIF6X.LbE14qsMmKGhM1A8W9iqaG3vv1BD7WC';
|
||||
const wut = ':';
|
||||
expect(bcrypt.compareSync(fullString, hash)).toBe(true);
|
||||
expect(bcrypt.compareSync(fullString, wut)).toBe(false);
|
||||
})
|
||||
|
||||
test('getRounds', () => {
|
||||
const hash = bcrypt.hashSync("test", bcrypt.genSaltSync(9));
|
||||
expect(9).toStrictEqual(bcrypt.getRounds(hash))
|
||||
})
|
||||
|
||||
test('getRounds', () => {
|
||||
const hash = bcrypt.hashSync("test", bcrypt.genSaltSync(9));
|
||||
expect(9).toStrictEqual(bcrypt.getRounds(hash))
|
||||
expect(() => bcrypt.getRounds('')).toThrow("invalid hash provided");
|
||||
});
|
Reference in New Issue
Block a user