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: https://github.com/nodejs/node/pull/20224
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Daniel Bevenius 2018-04-23 14:54:23 +02:00
parent c521a20f43
commit 95197ed2b0

View File

@ -34,9 +34,7 @@ const spkacValid = fixtures.readSync('spkac.valid');
const spkacFail = fixtures.readSync('spkac.fail');
const spkacPem = fixtures.readSync('spkac.pem');
{
// Test instance methods
const certificate = new Certificate();
function checkMethods(certificate) {
assert.strictEqual(certificate.verifySpkac(spkacValid), true);
assert.strictEqual(certificate.verifySpkac(spkacFail), false);
@ -54,22 +52,14 @@ const spkacPem = fixtures.readSync('spkac.pem');
assert.strictEqual(certificate.exportChallenge(spkacFail), '');
}
{
// Test instance methods
checkMethods(new Certificate());
}
{
// Test static methods
assert.strictEqual(Certificate.verifySpkac(spkacValid), true);
assert.strictEqual(Certificate.verifySpkac(spkacFail), false);
assert.strictEqual(
stripLineEndings(Certificate.exportPublicKey(spkacValid).toString('utf8')),
stripLineEndings(spkacPem.toString('utf8'))
);
assert.strictEqual(Certificate.exportPublicKey(spkacFail), '');
assert.strictEqual(
Certificate.exportChallenge(spkacValid).toString('utf8'),
'fb9ab814-6677-42a4-a60c-f905d1a6924d'
);
assert.strictEqual(Certificate.exportChallenge(spkacFail), '');
checkMethods(Certificate);
}
function stripLineEndings(obj) {