-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
system-ca.test.ts
63 lines (48 loc) · 2.04 KB
/
system-ca.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import https from "https";
import { DSTRootCAX3 } from "./is-cert-active";
import assert from "assert";
import { describeIf } from "../../test-utils/skippers";
import { platform } from "process";
import { getDiForUnitTesting } from "../../main/getDiForUnitTesting";
import injectSystemCAsOnMacOSInjectable from "./inject-system-cas-on-macos.injectable";
import injectSystemCAsOnWindowsInjectable from "./inject-system-cas-on-windows.injectable";
describe("CA tests", () => {
let injectSystemCAsOnMacOS: () => Promise<void>;
let injectSystemCAsOnWindows: () => Promise<void>;
beforeEach(() => {
const di = getDiForUnitTesting();
di.unoverride(injectSystemCAsOnMacOSInjectable);
di.permitSideEffects(injectSystemCAsOnMacOSInjectable);
injectSystemCAsOnMacOS = di.inject(injectSystemCAsOnMacOSInjectable);
di.unoverride(injectSystemCAsOnWindowsInjectable);
di.permitSideEffects(injectSystemCAsOnWindowsInjectable);
injectSystemCAsOnWindows = di.inject(injectSystemCAsOnWindowsInjectable);
});
// for reset https.globalAgent.options.ca after testing
let _ca: string | Buffer | (string | Buffer)[] | undefined;
beforeEach(() => {
_ca = https.globalAgent.options.ca;
});
afterEach(() => {
https.globalAgent.options.ca = _ca;
});
describeIf(platform === "darwin")("on macos", () => {
it("shouldn't included the expired DST Root CA X3 on Mac", async () => {
await injectSystemCAsOnMacOS();
const injected = https.globalAgent.options.ca;
assert(injected);
expect(injected.includes(DSTRootCAX3)).toBeFalsy();
});
});
describeIf(platform === "win32")("on windows", () => {
it("shouldn't included the expired DST Root CA X3 on Windows", async () => {
await injectSystemCAsOnWindows();
const injected = https.globalAgent.options.ca as (string | Buffer)[];
expect(injected.includes(DSTRootCAX3)).toBeFalsy();
});
});
});