Skip to content

Commit 99e0b91

Browse files
danbevMylesBorins
authored andcommitted
test: add checkMethods function for Certificate
This commit adds a checkMethods function so that it can be reused to avoid duplicating the same code for instance methods, and static methods of the Certificate object. PR-URL: #20224 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 26525ef commit 99e0b91

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

test/parallel/test-crypto-certificate.js

+7-17
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ const spkacValid = fixtures.readSync('spkac.valid');
3636
const spkacFail = fixtures.readSync('spkac.fail');
3737
const spkacPem = fixtures.readSync('spkac.pem');
3838

39-
{
40-
// Test instance methods
41-
const certificate = new Certificate();
39+
function checkMethods(certificate) {
4240

4341
assert.strictEqual(certificate.verifySpkac(spkacValid), true);
4442
assert.strictEqual(certificate.verifySpkac(spkacFail), false);
@@ -57,21 +55,13 @@ const spkacPem = fixtures.readSync('spkac.pem');
5755
}
5856

5957
{
60-
// Test static methods
61-
assert.strictEqual(Certificate.verifySpkac(spkacValid), true);
62-
assert.strictEqual(Certificate.verifySpkac(spkacFail), false);
63-
64-
assert.strictEqual(
65-
stripLineEndings(Certificate.exportPublicKey(spkacValid).toString('utf8')),
66-
stripLineEndings(spkacPem.toString('utf8'))
67-
);
68-
assert.strictEqual(Certificate.exportPublicKey(spkacFail), '');
58+
// Test instance methods
59+
checkMethods(new Certificate());
60+
}
6961

70-
assert.strictEqual(
71-
Certificate.exportChallenge(spkacValid).toString('utf8'),
72-
'fb9ab814-6677-42a4-a60c-f905d1a6924d'
73-
);
74-
assert.strictEqual(Certificate.exportChallenge(spkacFail), '');
62+
{
63+
// Test static methods
64+
checkMethods(Certificate);
7565
}
7666

7767
function stripLineEndings(obj) {

0 commit comments

Comments
 (0)