mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

This API allows dynamically configuring CA certificates that will be used by the Node.js TLS clients by default. Once called, the provided certificates will become the default CA certificate list returned by `tls.getCACertificates('default')` and used by TLS connections that don't specify their own CA certificates. This function only affects the current Node.js thread. PR-URL: https://github.com/nodejs/node/pull/58822 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
// Flags: --no-use-system-ca
|
|
'use strict';
|
|
|
|
// This tests tls.setDefaultCACertificates() support ArrayBufferView.
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto) common.skip('missing crypto');
|
|
|
|
const tls = require('tls');
|
|
const fixtures = require('../common/fixtures');
|
|
const { assertEqualCerts } = require('../common/tls');
|
|
|
|
const fixtureCert = fixtures.readKey('fake-startcom-root-cert.pem');
|
|
|
|
// Should accept Buffer.
|
|
tls.setDefaultCACertificates([Buffer.from(fixtureCert)]);
|
|
const result = tls.getCACertificates('default');
|
|
assertEqualCerts(result, [fixtureCert]);
|
|
|
|
// Reset it to empty.
|
|
tls.setDefaultCACertificates([]);
|
|
assertEqualCerts(tls.getCACertificates('default'), []);
|
|
|
|
// Should accept Uint8Array.
|
|
const encoder = new TextEncoder();
|
|
const uint8Cert = encoder.encode(fixtureCert);
|
|
tls.setDefaultCACertificates([uint8Cert]);
|
|
const uint8Result = tls.getCACertificates('default');
|
|
assertEqualCerts(uint8Result, [fixtureCert]);
|
|
|
|
// Reset it to empty.
|
|
tls.setDefaultCACertificates([]);
|
|
assertEqualCerts(tls.getCACertificates('default'), []);
|
|
|
|
// Should accept DataView.
|
|
const dataViewCert = new DataView(uint8Cert.buffer, uint8Cert.byteOffset, uint8Cert.byteLength);
|
|
tls.setDefaultCACertificates([dataViewCert]);
|
|
const dataViewResult = tls.getCACertificates('default');
|
|
assertEqualCerts(dataViewResult, [fixtureCert]);
|