@nivinjoseph/n-sec 5.0.5 → 6.0.2
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/.vscode/settings.json +111 -0
- package/.yarn/releases/yarn-4.0.2.cjs +893 -0
- package/.yarnrc.yml +3 -0
- package/dist/api-security/alg-type.d.ts +1 -0
- package/dist/api-security/alg-type.d.ts.map +1 -0
- package/dist/api-security/alg-type.js +2 -5
- package/dist/api-security/alg-type.js.map +1 -1
- package/dist/api-security/claim.d.ts +1 -0
- package/dist/api-security/claim.d.ts.map +1 -0
- package/dist/api-security/claim.js +5 -9
- package/dist/api-security/claim.js.map +1 -1
- package/dist/api-security/claims-identity.d.ts +2 -1
- package/dist/api-security/claims-identity.d.ts.map +1 -0
- package/dist/api-security/claims-identity.js +4 -8
- package/dist/api-security/claims-identity.js.map +1 -1
- package/dist/api-security/expired-token-exception.d.ts +1 -0
- package/dist/api-security/expired-token-exception.d.ts.map +1 -0
- package/dist/api-security/expired-token-exception.js +5 -9
- package/dist/api-security/expired-token-exception.js.map +1 -1
- package/dist/api-security/invalid-token-exception.d.ts +1 -0
- package/dist/api-security/invalid-token-exception.d.ts.map +1 -0
- package/dist/api-security/invalid-token-exception.js +7 -11
- package/dist/api-security/invalid-token-exception.js.map +1 -1
- package/dist/api-security/json-web-token.d.ts +3 -2
- package/dist/api-security/json-web-token.d.ts.map +1 -0
- package/dist/api-security/json-web-token.js +39 -43
- package/dist/api-security/json-web-token.js.map +1 -1
- package/dist/api-security/security-token.d.ts +1 -0
- package/dist/api-security/security-token.d.ts.map +1 -0
- package/dist/api-security/security-token.js +6 -10
- package/dist/api-security/security-token.js.map +1 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +16 -20
- package/dist/bin.js.map +1 -1
- package/dist/crypto/asymmetric-encryption.d.ts +2 -0
- package/dist/crypto/asymmetric-encryption.d.ts.map +1 -0
- package/dist/crypto/asymmetric-encryption.js +1 -1
- package/dist/crypto/asymmetric-encryption.js.map +1 -1
- package/dist/crypto/crypto-exception.d.ts +1 -0
- package/dist/crypto/crypto-exception.d.ts.map +1 -0
- package/dist/crypto/crypto-exception.js +2 -6
- package/dist/crypto/crypto-exception.js.map +1 -1
- package/dist/crypto/digital-signature.d.ts +2 -0
- package/dist/crypto/digital-signature.d.ts.map +1 -0
- package/dist/crypto/digital-signature.js +1 -1
- package/dist/crypto/digital-signature.js.map +1 -1
- package/dist/crypto/hash.d.ts +1 -0
- package/dist/crypto/hash.d.ts.map +1 -0
- package/dist/crypto/hash.js +7 -11
- package/dist/crypto/hash.js.map +1 -1
- package/dist/crypto/hmac.d.ts +1 -0
- package/dist/crypto/hmac.d.ts.map +1 -0
- package/dist/crypto/hmac.js +6 -10
- package/dist/crypto/hmac.js.map +1 -1
- package/dist/crypto/symmetric-encryption.d.ts +1 -0
- package/dist/crypto/symmetric-encryption.d.ts.map +1 -0
- package/dist/crypto/symmetric-encryption.js +13 -17
- package/dist/crypto/symmetric-encryption.js.map +1 -1
- package/dist/index.d.ts +13 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -28
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.json +2 -1
- package/eslint.config.js +591 -0
- package/package.json +24 -24
- package/src/api-security/claims-identity.ts +1 -1
- package/src/api-security/json-web-token.ts +21 -21
- package/src/bin.ts +2 -1
- package/src/crypto/hash.ts +9 -9
- package/src/crypto/hmac.ts +7 -7
- package/src/crypto/symmetric-encryption.ts +11 -11
- package/src/index.ts +17 -18
- package/test/asymmetric-encryption.test.ts +37 -37
- package/test/digital-signature.test.ts +22 -22
- package/test/hash.test.ts +109 -109
- package/test/hmac.test.ts +56 -55
- package/test/json-web-token.test.ts +95 -95
- package/test/other.test.ts +8 -7
- package/test/symmetric-encryption.test.ts +49 -48
- package/tsconfig.json +8 -5
- package/.eslintignore +0 -2
- package/.eslintrc +0 -335
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// import "@nivinjoseph/n-ext";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
//
|
|
7
|
+
// await describe("digitalSignature", () =>
|
|
8
8
|
// {
|
|
9
|
-
//
|
|
9
|
+
// await describe("sign", () =>
|
|
10
10
|
// {
|
|
11
|
-
// test("should return string value thats is not null, empty, whitespace, same as value or key pair when invoked with key pair and value", async () =>
|
|
11
|
+
// await test("should return string value thats is not null, empty, whitespace, same as value or key pair when invoked with key pair and value", async () =>
|
|
12
12
|
// {
|
|
13
13
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
14
14
|
// let value = "some value";
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// });
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
// // test("should throw CryptoException when KeyPair is null", async () =>
|
|
22
|
+
// // await test("should throw CryptoException when KeyPair is null", async () =>
|
|
23
23
|
// // {
|
|
24
24
|
// // try
|
|
25
25
|
// // {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
// // assert.ok(false);
|
|
35
35
|
// // });
|
|
36
36
|
|
|
37
|
-
// // test("should throw CryptoException when KeyPair is undefined", async () =>
|
|
37
|
+
// // await test("should throw CryptoException when KeyPair is undefined", async () =>
|
|
38
38
|
// // {
|
|
39
39
|
// // try
|
|
40
40
|
// // {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
// // assert.ok(false);
|
|
50
50
|
// // });
|
|
51
51
|
|
|
52
|
-
// // test("should throw CryptoException when value is null", async () =>
|
|
52
|
+
// // await test("should throw CryptoException when value is null", async () =>
|
|
53
53
|
// // {
|
|
54
54
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
55
55
|
// // try
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
// // assert.ok(false);
|
|
66
66
|
// // });
|
|
67
67
|
|
|
68
|
-
// // test("should throw CryptoException when value is undefined", async () =>
|
|
68
|
+
// // await test("should throw CryptoException when value is undefined", async () =>
|
|
69
69
|
// // {
|
|
70
70
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
71
71
|
// // try
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
// // assert.ok(false);
|
|
82
82
|
// // });
|
|
83
83
|
|
|
84
|
-
// // test("should throw CryptoException when value is empty string", async () =>
|
|
84
|
+
// // await test("should throw CryptoException when value is empty string", async () =>
|
|
85
85
|
// // {
|
|
86
86
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
87
87
|
// // try
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
// // assert.ok(false);
|
|
98
98
|
// // });
|
|
99
99
|
|
|
100
|
-
// // test("should throw CryptoException when keyPair is empty string", async () =>
|
|
100
|
+
// // await test("should throw CryptoException when keyPair is empty string", async () =>
|
|
101
101
|
// // {
|
|
102
102
|
// // try
|
|
103
103
|
// // {
|
|
@@ -113,9 +113,9 @@
|
|
|
113
113
|
// // });
|
|
114
114
|
// });
|
|
115
115
|
|
|
116
|
-
//
|
|
116
|
+
// await describe("verify", () =>
|
|
117
117
|
// {
|
|
118
|
-
// test("should return true when called with public key of key pair, value and signature of value generated using key pair", async () =>
|
|
118
|
+
// await test("should return true when called with public key of key pair, value and signature of value generated using key pair", async () =>
|
|
119
119
|
// {
|
|
120
120
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
121
121
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
// Assert.strictEqual(verification, true);
|
|
126
126
|
// });
|
|
127
127
|
|
|
128
|
-
// test("should return false when called with unrelated public key, value and signature", async () =>
|
|
128
|
+
// await test("should return false when called with unrelated public key, value and signature", async () =>
|
|
129
129
|
// {
|
|
130
130
|
// let keyPair1 = await AsymmetricEncryption.generateKeyPair();
|
|
131
131
|
// let keyPair2 = await AsymmetricEncryption.generateKeyPair();
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
// Assert.strictEqual(verification, false);
|
|
137
137
|
// });
|
|
138
138
|
|
|
139
|
-
// test("should return false when called with tampered value", async () =>
|
|
139
|
+
// await test("should return false when called with tampered value", async () =>
|
|
140
140
|
// {
|
|
141
141
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
142
142
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
// Assert.strictEqual(verification, false);
|
|
148
148
|
// });
|
|
149
149
|
|
|
150
|
-
// test("should return false when called with a tampered signature", async () =>
|
|
150
|
+
// await test("should return false when called with a tampered signature", async () =>
|
|
151
151
|
// {
|
|
152
152
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
153
153
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
// // test("successfully verify the signed", async () =>
|
|
163
|
+
// // await test("successfully verify the signed", async () =>
|
|
164
164
|
// // {
|
|
165
165
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
166
166
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
// // Assert.ok(verify);
|
|
170
170
|
// // });
|
|
171
171
|
|
|
172
|
-
// // test("un-verify modified signature", async () =>
|
|
172
|
+
// // await test("un-verify modified signature", async () =>
|
|
173
173
|
// // {
|
|
174
174
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
175
175
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
// // Assert.ok(!verify);
|
|
180
180
|
// // });
|
|
181
181
|
|
|
182
|
-
// // test("un-verify when wrong public key is given", async () =>
|
|
182
|
+
// // await test("un-verify when wrong public key is given", async () =>
|
|
183
183
|
// // {
|
|
184
184
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
185
185
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
// // Assert.ok(!verify);
|
|
190
190
|
// // });
|
|
191
191
|
|
|
192
|
-
// // test("should throw CryptoException when public key is null", async () =>
|
|
192
|
+
// // await test("should throw CryptoException when public key is null", async () =>
|
|
193
193
|
// // {
|
|
194
194
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
195
195
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
// // Assert.ok(false);
|
|
207
207
|
// // });
|
|
208
208
|
|
|
209
|
-
// // test("should throw CryptoException when value is null", async () =>
|
|
209
|
+
// // await test("should throw CryptoException when value is null", async () =>
|
|
210
210
|
// // {
|
|
211
211
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
212
212
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
// // Assert.ok(false);
|
|
225
225
|
// // });
|
|
226
226
|
|
|
227
|
-
// // test("should throw CryptoException when value is empty string", async () =>
|
|
227
|
+
// // await test("should throw CryptoException when value is empty string", async () =>
|
|
228
228
|
// // {
|
|
229
229
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
230
230
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -242,7 +242,7 @@
|
|
|
242
242
|
// // Assert.ok(false);
|
|
243
243
|
// // });
|
|
244
244
|
|
|
245
|
-
// // test("should throw CryptoException when signature is null", async () =>
|
|
245
|
+
// // await test("should throw CryptoException when signature is null", async () =>
|
|
246
246
|
// // {
|
|
247
247
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
248
248
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -259,7 +259,7 @@
|
|
|
259
259
|
// // Assert.ok(false);
|
|
260
260
|
// // });
|
|
261
261
|
|
|
262
|
-
// // test("should throw CryptoException when value, key pair and signature are all null", async () =>
|
|
262
|
+
// // await test("should throw CryptoException when value, key pair and signature are all null", async () =>
|
|
263
263
|
// // {
|
|
264
264
|
// // try
|
|
265
265
|
// // {
|
package/test/hash.test.ts
CHANGED
|
@@ -1,49 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { describe, test } from "node:test";
|
|
2
|
+
import assert from "node:assert";
|
|
3
|
+
import { Hash } from "./../src/index.js";
|
|
3
4
|
import "@nivinjoseph/n-ext";
|
|
4
5
|
// import { CryptoException } from "./../src/crypto-exception";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
await describe("Hash", async () =>
|
|
7
8
|
{
|
|
8
|
-
|
|
9
|
+
await describe("create", async () =>
|
|
9
10
|
{
|
|
10
|
-
test("must return a string value that is not null, empty, whitespace or same as input when called with a valid input", () =>
|
|
11
|
+
await test("must return a string value that is not null, empty, whitespace or same as input when called with a valid input", () =>
|
|
11
12
|
{
|
|
12
13
|
const input = "hello world";
|
|
13
14
|
const hash = Hash.create(input);
|
|
14
15
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
|
|
17
|
+
assert.notStrictEqual(hash, input);
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
test("multiple invocations with the same input must return the same output", () =>
|
|
19
|
+
|
|
20
|
+
await test("multiple invocations with the same input must return the same output", () =>
|
|
20
21
|
{
|
|
21
22
|
const input = "hello world";
|
|
22
23
|
const hash1 = Hash.create(input);
|
|
23
24
|
const hash2 = Hash.create(input);
|
|
24
|
-
|
|
25
|
+
assert.strictEqual(hash1, hash2);
|
|
25
26
|
});
|
|
26
|
-
|
|
27
|
-
test("multiple invocations with the different inputs must return different outputs", () =>
|
|
27
|
+
|
|
28
|
+
await test("multiple invocations with the different inputs must return different outputs", () =>
|
|
28
29
|
{
|
|
29
30
|
const input1 = "hello world";
|
|
30
31
|
const hash1 = Hash.create(input1);
|
|
31
32
|
const input2 = "goodbye world";
|
|
32
33
|
const hash2 = Hash.create(input2);
|
|
33
|
-
|
|
34
|
+
assert.notStrictEqual(hash1, hash2);
|
|
34
35
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// test("successfully create a hash twice with different values", async () =>
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// await test("successfully create a hash twice with different values", async () =>
|
|
38
39
|
// {
|
|
39
40
|
// let hash1 = await Hash.create("hello world");
|
|
40
41
|
// let hash2 = await Hash.create("hello world2");
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
42
|
+
// assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
|
|
43
|
+
// assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
|
|
44
|
+
// assert.notStrictEqual(hash1, hash2);
|
|
44
45
|
// });
|
|
45
|
-
|
|
46
|
-
// test("should throw CryptoException when value is null", async () =>
|
|
46
|
+
|
|
47
|
+
// await test("should throw CryptoException when value is null", async () =>
|
|
47
48
|
// {
|
|
48
49
|
// try
|
|
49
50
|
// {
|
|
@@ -51,14 +52,14 @@ suite("Hash", () =>
|
|
|
51
52
|
// }
|
|
52
53
|
// catch (exception)
|
|
53
54
|
// {
|
|
54
|
-
//
|
|
55
|
-
//
|
|
55
|
+
// assert.ok(exception instanceof CryptoException);
|
|
56
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
56
57
|
// return;
|
|
57
58
|
// }
|
|
58
|
-
//
|
|
59
|
+
// assert.ok(false);
|
|
59
60
|
// });
|
|
60
|
-
|
|
61
|
-
// test("should throw CryptoException when value is undefined", async () =>
|
|
61
|
+
|
|
62
|
+
// await test("should throw CryptoException when value is undefined", async () =>
|
|
62
63
|
// {
|
|
63
64
|
// try
|
|
64
65
|
// {
|
|
@@ -66,14 +67,14 @@ suite("Hash", () =>
|
|
|
66
67
|
// }
|
|
67
68
|
// catch (exception)
|
|
68
69
|
// {
|
|
69
|
-
//
|
|
70
|
-
//
|
|
70
|
+
// assert.ok(exception instanceof CryptoException);
|
|
71
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
71
72
|
// return;
|
|
72
73
|
// }
|
|
73
|
-
//
|
|
74
|
+
// assert.ok(false);
|
|
74
75
|
// });
|
|
75
|
-
|
|
76
|
-
// test("should throw CryptoException when value is empty string", async () =>
|
|
76
|
+
|
|
77
|
+
// await test("should throw CryptoException when value is empty string", async () =>
|
|
77
78
|
// {
|
|
78
79
|
// try
|
|
79
80
|
// {
|
|
@@ -81,51 +82,51 @@ suite("Hash", () =>
|
|
|
81
82
|
// }
|
|
82
83
|
// catch (exception)
|
|
83
84
|
// {
|
|
84
|
-
//
|
|
85
|
-
//
|
|
85
|
+
// assert.ok(exception instanceof CryptoException);
|
|
86
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
86
87
|
// return;
|
|
87
88
|
// }
|
|
88
|
-
//
|
|
89
|
+
// assert.ok(false);
|
|
89
90
|
// });
|
|
90
|
-
|
|
91
|
+
|
|
91
92
|
});
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
await describe("createUsingSalt", async () =>
|
|
94
95
|
{
|
|
95
|
-
test("must return a string value that is not null, empty, whitespace or same as input or salt when called with a valid input and salt", () =>
|
|
96
|
+
await test("must return a string value that is not null, empty, whitespace or same as input or salt when called with a valid input and salt", () =>
|
|
96
97
|
{
|
|
97
98
|
const input = "hello world";
|
|
98
99
|
const salt = "salt";
|
|
99
100
|
const hash = Hash.createUsingSalt(input, salt);
|
|
100
101
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
|
|
103
|
+
assert.notStrictEqual(hash, input);
|
|
104
|
+
assert.notStrictEqual(hash, salt);
|
|
104
105
|
});
|
|
105
106
|
|
|
106
|
-
test("multiple invocations with the same input and salt must return the same output", () =>
|
|
107
|
+
await test("multiple invocations with the same input and salt must return the same output", () =>
|
|
107
108
|
{
|
|
108
109
|
const input = "hello world";
|
|
109
110
|
const salt = "salt";
|
|
110
111
|
const hash1 = Hash.createUsingSalt(input, salt);
|
|
111
112
|
const hash2 = Hash.createUsingSalt(input, salt);
|
|
112
|
-
|
|
113
|
+
assert.strictEqual(hash1, hash2);
|
|
113
114
|
});
|
|
114
115
|
|
|
115
|
-
test("multiple invocations with different inputs and different salts must return different outputs", () =>
|
|
116
|
+
await test("multiple invocations with different inputs and different salts must return different outputs", () =>
|
|
116
117
|
{
|
|
117
118
|
const input1 = "hello world";
|
|
118
119
|
const salt1 = "salt-1";
|
|
119
120
|
const hash1 = Hash.createUsingSalt(input1, salt1);
|
|
120
|
-
|
|
121
|
+
|
|
121
122
|
const input2 = "goodbye world";
|
|
122
123
|
const salt2 = "salt-2";
|
|
123
124
|
const hash2 = Hash.createUsingSalt(input2, salt2);
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
|
|
126
|
+
assert.notStrictEqual(hash1, hash2);
|
|
126
127
|
});
|
|
127
|
-
|
|
128
|
-
test("multiple invocations with different inputs and the same salt must return different outputs", () =>
|
|
128
|
+
|
|
129
|
+
await test("multiple invocations with different inputs and the same salt must return different outputs", () =>
|
|
129
130
|
{
|
|
130
131
|
const input1 = "hello world";
|
|
131
132
|
const salt1 = "salt-1";
|
|
@@ -134,10 +135,10 @@ suite("Hash", () =>
|
|
|
134
135
|
const input2 = "goodbye world";
|
|
135
136
|
const hash2 = Hash.createUsingSalt(input2, salt1);
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
assert.notStrictEqual(hash1, hash2);
|
|
138
139
|
});
|
|
139
|
-
|
|
140
|
-
test("multiple invocations with the same input and different salts must return different outputs", () =>
|
|
140
|
+
|
|
141
|
+
await test("multiple invocations with the same input and different salts must return different outputs", () =>
|
|
141
142
|
{
|
|
142
143
|
const input = "hello world";
|
|
143
144
|
const salt1 = "salt-1";
|
|
@@ -146,63 +147,62 @@ suite("Hash", () =>
|
|
|
146
147
|
const salt2 = "salt-2";
|
|
147
148
|
const hash2 = Hash.createUsingSalt(input, salt2);
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
assert.notStrictEqual(hash1, hash2);
|
|
150
151
|
});
|
|
151
|
-
|
|
152
|
-
test("regex issue", () =>
|
|
152
|
+
|
|
153
|
+
await test("regex issue", () =>
|
|
153
154
|
{
|
|
154
155
|
let password = "YQAt3TPI7s1YXyClbQ2$&JdHOKZJ@z4!";
|
|
155
156
|
password = password.trim();
|
|
156
157
|
|
|
157
158
|
const createdAt = Date.now();
|
|
158
159
|
const username = "defaultUser";
|
|
159
|
-
|
|
160
|
+
|
|
160
161
|
const salt = (createdAt % 2) === 0
|
|
161
162
|
? `${username.base64Decode()}${createdAt}`
|
|
162
163
|
: `${createdAt}${username.base64Decode()}`;
|
|
163
164
|
|
|
164
|
-
|
|
165
|
+
Hash.createUsingSalt(password, salt);
|
|
165
166
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
// test("successfully create a hash", async () =>
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
// await test("successfully create a hash", async () =>
|
|
172
172
|
// {
|
|
173
173
|
// let hash = await Hash.createUsingSalt("hello world", "some-salt");
|
|
174
|
-
//
|
|
175
|
-
//
|
|
174
|
+
// assert.ok(hash !== null && !hash.isEmptyOrWhiteSpace());
|
|
175
|
+
// assert.notStrictEqual("hello world", hash);
|
|
176
176
|
// });
|
|
177
177
|
|
|
178
|
-
// test("successfully create a hash twice with same values and same salt", async () =>
|
|
178
|
+
// await test("successfully create a hash twice with same values and same salt", async () =>
|
|
179
179
|
// {
|
|
180
180
|
// let hash1 = await Hash.createUsingSalt("hello world", "some-salt");
|
|
181
181
|
// let hash2 = await Hash.createUsingSalt("hello world", "some-salt");
|
|
182
|
-
//
|
|
183
|
-
//
|
|
184
|
-
//
|
|
182
|
+
// assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
|
|
183
|
+
// assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
|
|
184
|
+
// assert.strictEqual(hash1, hash2);
|
|
185
185
|
// });
|
|
186
|
-
|
|
187
|
-
// test("successfully create a hash twice with same values and different salt", async () =>
|
|
186
|
+
|
|
187
|
+
// await test("successfully create a hash twice with same values and different salt", async () =>
|
|
188
188
|
// {
|
|
189
189
|
// let hash1 = await Hash.createUsingSalt("hello world", "some-salt");
|
|
190
190
|
// let hash2 = await Hash.createUsingSalt("hello world", "some-other-salt");
|
|
191
|
-
//
|
|
192
|
-
//
|
|
193
|
-
//
|
|
191
|
+
// assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
|
|
192
|
+
// assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
|
|
193
|
+
// assert.notStrictEqual(hash1, hash2);
|
|
194
194
|
// });
|
|
195
|
-
|
|
196
|
-
// test("successfully create a hash twice with different values same salt", async () =>
|
|
195
|
+
|
|
196
|
+
// await test("successfully create a hash twice with different values same salt", async () =>
|
|
197
197
|
// {
|
|
198
198
|
// let hash1 = await Hash.createUsingSalt("hello world", "some-salt");
|
|
199
199
|
// let hash2 = await Hash.createUsingSalt("hello world2", "some-salt");
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
//
|
|
200
|
+
// assert.ok(hash1 !== null && !hash1.isEmptyOrWhiteSpace());
|
|
201
|
+
// assert.ok(hash2 !== null && !hash2.isEmptyOrWhiteSpace());
|
|
202
|
+
// assert.notStrictEqual(hash1, hash2);
|
|
203
203
|
// });
|
|
204
|
-
|
|
205
|
-
// test("should throw CryptoException when value is null", async () =>
|
|
204
|
+
|
|
205
|
+
// await test("should throw CryptoException when value is null", async () =>
|
|
206
206
|
// {
|
|
207
207
|
// try
|
|
208
208
|
// {
|
|
@@ -210,14 +210,14 @@ suite("Hash", () =>
|
|
|
210
210
|
// }
|
|
211
211
|
// catch (exception)
|
|
212
212
|
// {
|
|
213
|
-
//
|
|
214
|
-
//
|
|
213
|
+
// assert.ok(exception instanceof CryptoException);
|
|
214
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
215
215
|
// return;
|
|
216
216
|
// }
|
|
217
|
-
//
|
|
217
|
+
// assert.ok(false);
|
|
218
218
|
// });
|
|
219
|
-
|
|
220
|
-
// test("should throw CryptoException when value is undefined", async () =>
|
|
219
|
+
|
|
220
|
+
// await test("should throw CryptoException when value is undefined", async () =>
|
|
221
221
|
// {
|
|
222
222
|
// try
|
|
223
223
|
// {
|
|
@@ -225,14 +225,14 @@ suite("Hash", () =>
|
|
|
225
225
|
// }
|
|
226
226
|
// catch (exception)
|
|
227
227
|
// {
|
|
228
|
-
//
|
|
229
|
-
//
|
|
228
|
+
// assert.ok(exception instanceof CryptoException);
|
|
229
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
230
230
|
// return;
|
|
231
231
|
// }
|
|
232
|
-
//
|
|
232
|
+
// assert.ok(false);
|
|
233
233
|
// });
|
|
234
|
-
|
|
235
|
-
// test("should throw CryptoException when salt is null", async () =>
|
|
234
|
+
|
|
235
|
+
// await test("should throw CryptoException when salt is null", async () =>
|
|
236
236
|
// {
|
|
237
237
|
// try
|
|
238
238
|
// {
|
|
@@ -240,14 +240,14 @@ suite("Hash", () =>
|
|
|
240
240
|
// }
|
|
241
241
|
// catch (exception)
|
|
242
242
|
// {
|
|
243
|
-
//
|
|
244
|
-
//
|
|
243
|
+
// assert.ok(exception instanceof CryptoException);
|
|
244
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
245
245
|
// return;
|
|
246
246
|
// }
|
|
247
|
-
//
|
|
247
|
+
// assert.ok(false);
|
|
248
248
|
// });
|
|
249
|
-
|
|
250
|
-
// test("should throw CryptoException when salt is undefined", async () =>
|
|
249
|
+
|
|
250
|
+
// await test("should throw CryptoException when salt is undefined", async () =>
|
|
251
251
|
// {
|
|
252
252
|
// try
|
|
253
253
|
// {
|
|
@@ -255,14 +255,14 @@ suite("Hash", () =>
|
|
|
255
255
|
// }
|
|
256
256
|
// catch (exception)
|
|
257
257
|
// {
|
|
258
|
-
//
|
|
259
|
-
//
|
|
258
|
+
// assert.ok(exception instanceof CryptoException);
|
|
259
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
260
260
|
// return;
|
|
261
261
|
// }
|
|
262
|
-
//
|
|
262
|
+
// assert.ok(false);
|
|
263
263
|
// });
|
|
264
|
-
|
|
265
|
-
// test("should throw CryptoException when salt is empty string", async () =>
|
|
264
|
+
|
|
265
|
+
// await test("should throw CryptoException when salt is empty string", async () =>
|
|
266
266
|
// {
|
|
267
267
|
// try
|
|
268
268
|
// {
|
|
@@ -270,14 +270,14 @@ suite("Hash", () =>
|
|
|
270
270
|
// }
|
|
271
271
|
// catch (exception)
|
|
272
272
|
// {
|
|
273
|
-
//
|
|
274
|
-
//
|
|
273
|
+
// assert.ok(exception instanceof CryptoException);
|
|
274
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
275
275
|
// return;
|
|
276
276
|
// }
|
|
277
|
-
//
|
|
277
|
+
// assert.ok(false);
|
|
278
278
|
// });
|
|
279
|
-
|
|
280
|
-
// test("should throw CryptoException when value is empty string", async () =>
|
|
279
|
+
|
|
280
|
+
// await test("should throw CryptoException when value is empty string", async () =>
|
|
281
281
|
// {
|
|
282
282
|
// try
|
|
283
283
|
// {
|
|
@@ -285,11 +285,11 @@ suite("Hash", () =>
|
|
|
285
285
|
// }
|
|
286
286
|
// catch (exception)
|
|
287
287
|
// {
|
|
288
|
-
//
|
|
289
|
-
//
|
|
288
|
+
// assert.ok(exception instanceof CryptoException);
|
|
289
|
+
// assert.strictEqual(exception.message, "Parameter count mismatch.");
|
|
290
290
|
// return;
|
|
291
291
|
// }
|
|
292
|
-
//
|
|
292
|
+
// assert.ok(false);
|
|
293
293
|
// });
|
|
294
294
|
});
|
|
295
295
|
});
|