Skip to content

Commit

Permalink
Handle globalAgent having a single non-array CA (lensapp#6628)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Nokel81 authored Nov 24, 2022
1 parent aedc475 commit 27fb128
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/common/certificate-authorities/inject-system-cas.injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,36 @@ const injectSystemCAsInjectable = getInjectable({
const requestSystemCAs = di.inject(requestSystemCAsInjectionToken);

return async () => {
for (const cert of await requestSystemCAs()) {
if (isCertActive(cert)) {
if (Array.isArray(globalAgent.options.ca) && !globalAgent.options.ca.includes(cert)) {
globalAgent.options.ca.push(cert);
} else {
globalAgent.options.ca = [cert];
}
const certs = await requestSystemCAs();

if (certs.length === 0) {
// Leave the global option alone
return;
}

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;
};
},
});
Expand Down

0 comments on commit 27fb128

Please sign in to comment.