okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-023-int into f-023-guifcb0c2d0e

main
1.9 KiB42 linesraw
1// #3722: the host trusts the operating system's certificates in addition to Node's bundled list, and only adds to it.
2import test from 'node:test';
3import assert from 'node:assert/strict';
4import { useSystemCertificates } from '../server/system-ca.mjs';
5import { agentEnvironment } from '../server/agent/harness-runtime.mjs';
6
7const fake = (system, bundled = ['B1', 'B2']) => {
8  const calls = [];
9  return { calls, getCACertificates: kind => (kind === 'system' ? system : bundled), setDefaultCACertificates: list => calls.push(list) };
10};
11
12test('system roots are added to the bundled ones', () => {
13  const tls = fake(['S1', 'B1']);
14  assert.equal(useSystemCertificates(tls, {}), 'system');
15  assert.deepEqual(tls.calls, [['B1', 'B2', 'S1']]);
16});
17
18test('an empty or unreadable system store, or an older Node, changes nothing and never throws', () => {
19  const empty = fake([]);
20  assert.equal(useSystemCertificates(empty, {}), 'bundled');
21  assert.equal(empty.calls.length, 0);
22  assert.equal(useSystemCertificates({}, {}), 'bundled');
23  assert.equal(useSystemCertificates({ getCACertificates() { throw new Error('store'); }, setDefaultCACertificates() {} }, {}), 'bundled');
24});
25
26test('STRATA_NO_SYSTEM_CA=1 leaves Node as it was', () => {
27  const tls = fake(['S1']);
28  assert.equal(useSystemCertificates(tls, { STRATA_NO_SYSTEM_CA: '1' }), 'bundled');
29  assert.equal(tls.calls.length, 0);
30});
31
32test('the real Node of this machine can read its system store', () => {
33  const tls = process.getBuiltinModule?.('node:tls');
34  if (typeof tls?.getCACertificates !== 'function') return;
35  assert.ok(Array.isArray(tls.getCACertificates('system')));
36});
37
38test('the agent process is started with NODE_USE_SYSTEM_CA=1, and no switch turns verification off', () => {
39  const env = agentEnvironment({ PATH: 'x' }, {});
40  assert.equal(env.NODE_USE_SYSTEM_CA, '1');
41  assert.ok(!('NODE_TLS_REJECT_UNAUTHORIZED' in env));
42});