Skip to content

Commit 29ea9ad

Browse files
committed
test: expand getCACertificates() with 'as' option and invalid inputs
1 parent 6971091 commit 29ea9ad

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed
Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
23
const common = require('../common');
34
if (!common.hasCrypto)
45
common.skip('missing crypto');
@@ -7,15 +8,55 @@ const assert = require('assert');
78
const tls = require('tls');
89
const { X509Certificate } = require('crypto');
910

10-
function testX509Option() {
11+
{
1112
const certs = tls.getCACertificates({ type: 'default', as: 'x509' });
1213

1314
assert.ok(Array.isArray(certs), 'should return an array');
1415
assert.ok(certs.length > 0, 'should return non-empty array');
1516
assert.ok(certs[0] instanceof X509Certificate,
1617
'each cert should be instance of X509Certificate');
1718

18-
assert.match(certs[0].serialNumber, /^[0-9A-F]+$/i, 'serialNumber should be hex string');
19+
assert.match(certs[0].serialNumber, /^[0-9A-F]+$/i,
20+
'serialNumber should be hex string');
21+
}
22+
23+
{
24+
const certs = tls.getCACertificates({ type: 'default', as: 'buffer' });
25+
assert.ok(Array.isArray(certs));
26+
assert.ok(certs.length > 0);
27+
assert.ok(Buffer.isBuffer(certs[0]));
28+
}
29+
30+
{
31+
const certs = tls.getCACertificates({ type: 'default' });
32+
assert.ok(Array.isArray(certs));
33+
assert.ok(certs.length > 0);
34+
assert.ok(Buffer.isBuffer(certs[0]));
1935
}
2036

21-
testX509Option();
37+
{
38+
assert.throws(() => {
39+
tls.getCACertificates({ type: 'default', as: 'invalid' });
40+
}, {
41+
name: 'TypeError',
42+
code: 'ERR_INVALID_ARG_VALUE',
43+
message: /must be one of/
44+
});
45+
}
46+
47+
{
48+
const certs = tls.getCACertificates({ as: 'buffer' });
49+
assert.ok(Array.isArray(certs));
50+
assert.ok(certs.length > 0);
51+
assert.ok(Buffer.isBuffer(certs[0]));
52+
}
53+
54+
{
55+
assert.throws(() => {
56+
tls.getCACertificates({ type: 'invalid', as: 'buffer' });
57+
}, {
58+
name: 'TypeError',
59+
code: 'ERR_INVALID_ARG_VALUE',
60+
message: "The argument 'type' is invalid. Received 'invalid'"
61+
});
62+
}

0 commit comments

Comments
 (0)