Skip to content

Commit 38ec8e4

Browse files
julianduqueaddaleax
authored andcommitted
test: improve test for crypto padding
Replace assert.equal with assert.strictEqual and use RegExp in assert.throws PR-URL: #9906 Reviewed-By: Colin Ihrig <[email protected]>
1 parent a771f21 commit 38ec8e4

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

test/parallel/test-crypto-padding.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -74,38 +74,44 @@ function dec(encd, pad) {
7474
* Test encryption
7575
*/
7676

77-
assert.equal(enc(ODD_LENGTH_PLAIN, true), ODD_LENGTH_ENCRYPTED);
78-
assert.equal(enc(EVEN_LENGTH_PLAIN, true), EVEN_LENGTH_ENCRYPTED);
77+
assert.strictEqual(enc(ODD_LENGTH_PLAIN, true), ODD_LENGTH_ENCRYPTED);
78+
assert.strictEqual(enc(EVEN_LENGTH_PLAIN, true), EVEN_LENGTH_ENCRYPTED);
7979

8080
assert.throws(function() {
8181
// input must have block length %
8282
enc(ODD_LENGTH_PLAIN, false);
83-
});
83+
}, /data not multiple of block length/);
8484

8585
assert.doesNotThrow(function() {
86-
assert.equal(enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD);
86+
assert.strictEqual(
87+
enc(EVEN_LENGTH_PLAIN, false), EVEN_LENGTH_ENCRYPTED_NOPAD
88+
);
8789
});
8890

8991

9092
/*
9193
* Test decryption
9294
*/
9395

94-
assert.equal(dec(ODD_LENGTH_ENCRYPTED, true), ODD_LENGTH_PLAIN);
95-
assert.equal(dec(EVEN_LENGTH_ENCRYPTED, true), EVEN_LENGTH_PLAIN);
96+
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, true), ODD_LENGTH_PLAIN);
97+
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, true), EVEN_LENGTH_PLAIN);
9698

9799
assert.doesNotThrow(function() {
98100
// returns including original padding
99-
assert.equal(dec(ODD_LENGTH_ENCRYPTED, false).length, 32);
100-
assert.equal(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
101+
assert.strictEqual(dec(ODD_LENGTH_ENCRYPTED, false).length, 32);
102+
assert.strictEqual(dec(EVEN_LENGTH_ENCRYPTED, false).length, 48);
101103
});
102104

103105
assert.throws(function() {
104106
// must have at least 1 byte of padding (PKCS):
105-
assert.equal(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN);
106-
});
107+
assert.strictEqual(
108+
dec(EVEN_LENGTH_ENCRYPTED_NOPAD, true), EVEN_LENGTH_PLAIN
109+
);
110+
}, /bad decrypt/);
107111

108112
assert.doesNotThrow(function() {
109113
// no-pad encrypted string should return the same:
110-
assert.equal(dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN);
114+
assert.strictEqual(
115+
dec(EVEN_LENGTH_ENCRYPTED_NOPAD, false), EVEN_LENGTH_PLAIN
116+
);
111117
});

0 commit comments

Comments
 (0)