Skip to content

Commit

Permalink
test: add checkMethods function for Certificate
Browse files Browse the repository at this point in the history
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: nodejs#20224
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
danbev committed Apr 25, 2018
1 parent c521a20 commit 95197ed
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions test/parallel/test-crypto-certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -55,21 +53,13 @@ const spkacPem = fixtures.readSync('spkac.pem');
}

{
// 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), '');
// Test instance methods
checkMethods(new Certificate());
}

assert.strictEqual(
Certificate.exportChallenge(spkacValid).toString('utf8'),
'fb9ab814-6677-42a4-a60c-f905d1a6924d'
);
assert.strictEqual(Certificate.exportChallenge(spkacFail), '');
{
// Test static methods
checkMethods(Certificate);
}

function stripLineEndings(obj) {
Expand Down

0 comments on commit 95197ed

Please sign in to comment.