okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
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' ]) => { 8const calls = []; 9return { calls, getCACertificates :kind => ( kind === 'system' ?system :bundled ), setDefaultCACertificates :list => calls . push ( list ) }; 10}; 11 12test ( 'system roots are added to the bundled ones' , () => { 13const tls = fake ([ 'S1' , 'B1' ]); 14assert . equal ( useSystemCertificates ( tls , {}), 'system' ); 15assert . deepEqual ( tls . calls , [[ 'B1' , 'B2' , 'S1' ]]); 16}); 17 18test ( 'an empty or unreadable system store, or an older Node, changes nothing and never throws' , () => { 19const empty = fake ([]); 20assert . equal ( useSystemCertificates ( empty , {}), 'bundled' ); 21assert . equal ( empty . calls . length , 0 ); 22assert . equal ( useSystemCertificates ({}, {}), 'bundled' ); 23assert . equal ( useSystemCertificates ({ getCACertificates () { throw new Error ( 'store' ); }, setDefaultCACertificates () {} }, {}), 'bundled' ); 24}); 25 26test ( 'STRATA_NO_SYSTEM_CA=1 leaves Node as it was' , () => { 27const tls = fake ([ 'S1' ]); 28assert . equal ( useSystemCertificates ( tls , { STRATA_NO_SYSTEM_CA :'1' }), 'bundled' ); 29assert . equal ( tls . calls . length , 0 ); 30}); 31 32test ( 'the real Node of this machine can read its system store' , () => { 33const tls = process . getBuiltinModule ?.( 'node:tls' ); 34if ( typeof tls ?. getCACertificates !== 'function' ) return ; 35assert . 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' , () => { 39const env = agentEnvironment ({ PATH :'x' }, {}); 40assert . equal ( env . NODE_USE_SYSTEM_CA , '1' ); 41assert . ok ( ! ( 'NODE_TLS_REJECT_UNAUTHORIZED' in env )); 42});