Skip to content

Commit

Permalink
test: add test for invalid cert string
Browse files Browse the repository at this point in the history
`tls.parseCertString()` should return an empty object if passed an
invalid cert string. This behavior is not currently tested. Add minimal
test.

PR-URL: #8179
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
  • Loading branch information
Trott authored and evanlucas committed Aug 24, 2016
1 parent a6f8379 commit b9b762f
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions test/parallel/test-tls-parse-cert-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,33 @@ require('../common');
const assert = require('assert');
const tls = require('tls');

const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' +
'CN=ca1\nemailAddress=ry@clouds.org';
const singlesOut = tls.parseCertString(singles);
assert.deepStrictEqual(singlesOut, {
C: 'US',
ST: 'CA',
L: 'SF',
O: 'Node.js Foundation',
OU: 'Node.js',
CN: 'ca1',
emailAddress: 'ry@clouds.org'
});
{
const singles = 'C=US\nST=CA\nL=SF\nO=Node.js Foundation\nOU=Node.js\n' +
'CN=ca1\nemailAddress=ry@clouds.org';
const singlesOut = tls.parseCertString(singles);
assert.deepStrictEqual(singlesOut, {
C: 'US',
ST: 'CA',
L: 'SF',
O: 'Node.js Foundation',
OU: 'Node.js',
CN: 'ca1',
emailAddress: 'ry@clouds.org'
});
}

const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' +
'CN=*.nodejs.org';
const doublesOut = tls.parseCertString(doubles);
assert.deepStrictEqual(doublesOut, {
OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ],
CN: '*.nodejs.org'
});
{
const doubles = 'OU=Domain Control Validated\nOU=PositiveSSL Wildcard\n' +
'CN=*.nodejs.org';
const doublesOut = tls.parseCertString(doubles);
assert.deepStrictEqual(doublesOut, {
OU: [ 'Domain Control Validated', 'PositiveSSL Wildcard' ],
CN: '*.nodejs.org'
});
}

{
const invalid = 'fhqwhgads';
const invalidOut = tls.parseCertString(invalid);
assert.deepStrictEqual(invalidOut, {});
}

0 comments on commit b9b762f

Please sign in to comment.