fastbcrypt 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +6 -0
- package/.editorconfig +19 -0
- package/.github/workflows/build-pack-publish.yml +110 -0
- package/.github/workflows/ci.yaml +42 -0
- package/CHANGELOG.md +191 -0
- package/Dockerfile +57 -0
- package/Dockerfile-alpine +41 -0
- package/ISSUE_TEMPLATE.md +18 -0
- package/LICENSE +19 -0
- package/Makefile +19 -0
- package/README.md +342 -2
- package/SECURITY.md +5 -0
- package/bcrypt.js +242 -0
- package/binding.gyp +49 -0
- package/build-all.sh +37 -0
- package/examples/async_compare.js +28 -0
- package/examples/forever_gen_salt.js +8 -0
- package/package.json +54 -4
- package/prebuilds/darwin-arm64/bcrypt.node +0 -0
- package/prebuilds/darwin-x64/bcrypt.node +0 -0
- package/prebuilds/linux-arm/bcrypt.glibc.node +0 -0
- package/prebuilds/linux-arm/bcrypt.musl.node +0 -0
- package/prebuilds/linux-arm64/bcrypt.glibc.node +0 -0
- package/prebuilds/linux-arm64/bcrypt.musl.node +0 -0
- package/prebuilds/linux-x64/bcrypt.glibc.node +0 -0
- package/prebuilds/linux-x64/bcrypt.musl.node +0 -0
- package/prebuilds/win32-arm64/bcrypt.node +0 -0
- package/prebuilds/win32-x64/bcrypt.node +0 -0
- package/promises.js +45 -0
- package/src/bcrypt.cc +315 -0
- package/src/bcrypt_node.cc +288 -0
- package/src/blowfish.cc +679 -0
- package/src/node_blf.h +132 -0
- package/test/async.test.js +209 -0
- package/test/implementation.test.js +48 -0
- package/test/promise.test.js +168 -0
- package/test/repetitions.test.js +55 -0
- package/test/sync.test.js +125 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const fastbcrypt = require('..')
|
|
2
|
+
|
|
3
|
+
test('salt_length', () => {
|
|
4
|
+
const salt = fastbcrypt.genSaltSync(13);
|
|
5
|
+
expect(salt).toHaveLength(29);
|
|
6
|
+
const [_, version, rounds] = salt.split('$');
|
|
7
|
+
expect(version).toStrictEqual('2b')
|
|
8
|
+
expect(rounds).toStrictEqual('13')
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('salt_no_params', () => {
|
|
12
|
+
const salt = fastbcrypt.genSaltSync();
|
|
13
|
+
const [_, version, rounds] = salt.split('$');
|
|
14
|
+
expect(version).toStrictEqual('2b')
|
|
15
|
+
expect(rounds).toStrictEqual('10')
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('salt_rounds_is_string_number', () => {
|
|
19
|
+
expect(() => fastbcrypt.genSaltSync('10')).toThrowError('rounds must be a number');
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('salt_rounds_is_NaN', () => {
|
|
23
|
+
expect(() => fastbcrypt.genSaltSync('b')).toThrowError("rounds must be a number");
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('salt_minor_a', () => {
|
|
27
|
+
const salt = fastbcrypt.genSaltSync(10, 'a');
|
|
28
|
+
const [_, version, rounds] = salt.split('$');
|
|
29
|
+
expect(version).toStrictEqual('2a')
|
|
30
|
+
expect(rounds).toStrictEqual('10')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
test('salt_minor_b', () => {
|
|
34
|
+
const salt = fastbcrypt.genSaltSync(10, 'b');
|
|
35
|
+
const [_, version, rounds] = salt.split('$');
|
|
36
|
+
expect(version).toStrictEqual('2b')
|
|
37
|
+
expect(rounds).toStrictEqual('10')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('hash', () => {
|
|
41
|
+
expect(() => fastbcrypt.hashSync('password', fastbcrypt.genSaltSync(10))).not.toThrow()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test('hash_rounds', () => {
|
|
45
|
+
const hash = fastbcrypt.hashSync('password', 8);
|
|
46
|
+
expect(fastbcrypt.getRounds(hash)).toStrictEqual(8)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('hash_empty_string', () => {
|
|
50
|
+
expect(() => fastbcrypt.hashSync('', fastbcrypt.genSaltSync(10))).not.toThrow();
|
|
51
|
+
expect(() => fastbcrypt.hashSync('password', '')).toThrowError('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue');
|
|
52
|
+
expect(() => fastbcrypt.hashSync('', '')).toThrowError('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue');
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test('hash_pw_no_params', () => {
|
|
56
|
+
expect(() => fastbcrypt.hashSync()).toThrow('data and salt arguments required');
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('hash_pw_one_param', () => {
|
|
60
|
+
expect(() => fastbcrypt.hashSync('password')).toThrow('data and salt arguments required');
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
test('hash_pw_not_hash_str', () => {
|
|
64
|
+
expect(() => fastbcrypt.hashSync('password', {})).toThrow("data must be a string or Buffer and salt must either be a salt string or a number of rounds")
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test('hash_salt_validity', () => {
|
|
68
|
+
expect(2);
|
|
69
|
+
expect(fastbcrypt.hashSync('password', '$2a$10$somesaltyvaluertsetrse')).toBeDefined()
|
|
70
|
+
expect(() => fastbcrypt.hashSync('password', 'some$value')).toThrow('Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
test('verify_salt', () => {
|
|
74
|
+
const salt = fastbcrypt.genSaltSync(10);
|
|
75
|
+
const split_salt = salt.split('$');
|
|
76
|
+
expect(split_salt[1]).toStrictEqual('2b')
|
|
77
|
+
expect(split_salt[2]).toStrictEqual('10')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('verify_salt_min_rounds', () => {
|
|
81
|
+
const salt = fastbcrypt.genSaltSync(1);
|
|
82
|
+
const split_salt = salt.split('$');
|
|
83
|
+
expect(split_salt[1]).toStrictEqual('2b')
|
|
84
|
+
expect(split_salt[2]).toStrictEqual('04')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('verify_salt_max_rounds', () => {
|
|
88
|
+
const salt = fastbcrypt.genSaltSync(100);
|
|
89
|
+
const split_salt = salt.split('$');
|
|
90
|
+
expect(split_salt[1]).toStrictEqual('2b')
|
|
91
|
+
expect(split_salt[2]).toStrictEqual('31')
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('hash_compare', () => {
|
|
95
|
+
const salt = fastbcrypt.genSaltSync(10);
|
|
96
|
+
expect(29).toStrictEqual(salt.length)
|
|
97
|
+
const hash = fastbcrypt.hashSync("test", salt);
|
|
98
|
+
expect(fastbcrypt.compareSync("test", hash)).toBeDefined()
|
|
99
|
+
expect(!(fastbcrypt.compareSync("blah", hash))).toBeDefined()
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('hash_compare_empty_strings', () => {
|
|
103
|
+
expect(!(fastbcrypt.compareSync("", "password"))).toBeDefined()
|
|
104
|
+
expect(!(fastbcrypt.compareSync("", ""))).toBeDefined()
|
|
105
|
+
expect(!(fastbcrypt.compareSync("password", ""))).toBeDefined()
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('hash_compare_invalid_strings', () => {
|
|
109
|
+
const fullString = 'envy1362987212538';
|
|
110
|
+
const hash = '$2a$10$XOPbrlUPQdwdJUpSrIF6X.LbE14qsMmKGhM1A8W9iqaG3vv1BD7WC';
|
|
111
|
+
const wut = ':';
|
|
112
|
+
expect(fastbcrypt.compareSync(fullString, hash)).toBe(true);
|
|
113
|
+
expect(fastbcrypt.compareSync(fullString, wut)).toBe(false);
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test('getRounds', () => {
|
|
117
|
+
const hash = fastbcrypt.hashSync("test", fastbcrypt.genSaltSync(9));
|
|
118
|
+
expect(9).toStrictEqual(fastbcrypt.getRounds(hash))
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('getRounds', () => {
|
|
122
|
+
const hash = fastbcrypt.hashSync("test", fastbcrypt.genSaltSync(9));
|
|
123
|
+
expect(9).toStrictEqual(fastbcrypt.getRounds(hash))
|
|
124
|
+
expect(() => fastbcrypt.getRounds('')).toThrow("invalid hash provided");
|
|
125
|
+
});
|