-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Expand file tree
/
Copy pathtest-tls-get-ca-certificates-x509-option.js
More file actions
72 lines (60 loc) · 1.76 KB
/
test-tls-get-ca-certificates-x509-option.js
File metadata and controls
72 lines (60 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
const { X509Certificate } = require('crypto');
const tlsCommon = require('../common/tls');
const expectedPems = tls.getCACertificates({ type: 'default', format: 'pem' });
{
const certs = tls.getCACertificates({ type: 'default', format: 'x509' });
assert.strictEqual(certs.length, expectedPems.length);
const certsRaw = certs.map((c) => c.raw);
tlsCommon.assertEqualCerts(certsRaw, expectedPems);
for (const cert of certs) {
assert.ok(cert instanceof X509Certificate);
}
}
{
const certs = tls.getCACertificates({ type: 'default', format: 'buffer' });
assert.strictEqual(certs.length, expectedPems.length);
tlsCommon.assertEqualCerts(certs, expectedPems);
for (const cert of certs) {
assert.ok(Buffer.isBuffer(cert));
}
}
{
const certs = tls.getCACertificates({ type: 'default' });
assert.strictEqual(certs.length, expectedPems.length);
for (const cert of certs) {
assert.strictEqual(typeof cert, 'string');
assert.ok(cert.includes('-----BEGIN CERTIFICATE-----'));
}
}
{
assert.throws(() => {
tls.getCACertificates({ type: 'default', format: 'invalid' });
}, {
name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: /must be one of/
});
}
{
const certs = tls.getCACertificates({ format: 'buffer' });
assert.ok(Array.isArray(certs));
assert.ok(certs.length > 0);
for (const cert of certs) {
assert.ok(Buffer.isBuffer(cert));
}
}
{
assert.throws(() => {
tls.getCACertificates({ type: 'invalid', format: 'buffer' });
}, {
name: 'TypeError',
code: 'ERR_INVALID_ARG_VALUE',
message: /The argument 'type' is invalid/
});
}