Handle globalAgent having a single non-array CA (#6628)

* Handle globalAgent having a single non-array CA

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Rewrite ternary as IIFE

Signed-off-by: Sebastian Malton <sebastian@malton.name>

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-11-24 11:28:33 -08:00
1 parent aedc47551a
commit 27fb128c05
1 file changed
+27 -6
@@ -22,15 +22,36 @@ const injectSystemCAsInjectable = getInjectable({
const requestSystemCAs = di.inject(requestSystemCAsInjectionToken); const requestSystemCAs = di.inject(requestSystemCAsInjectionToken);
return async () => { return async () => {
for (const cert of await requestSystemCAs()) { const certs = await requestSystemCAs();
if (isCertActive(cert)) {
if (Array.isArray(globalAgent.options.ca) && !globalAgent.options.ca.includes(cert)) { if (certs.length === 0) {
globalAgent.options.ca.push(cert); // Leave the global option alone
} else { return;
globalAgent.options.ca = [cert];
} }
const cas = (() => {
if (Array.isArray(globalAgent.options.ca)) {
return globalAgent.options.ca;
}
if (globalAgent.options.ca) {
return [globalAgent.options.ca];
}
return [];
})();
for (const cert of certs) {
if (!isCertActive(cert)) {
continue;
}
if (!cas.includes(cert)) {
cas.push(cert);
} }
} }
globalAgent.options.ca = cas;
}; };
}, },
}); });