forked from samanhappy/mcphub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxyTrust.test.ts
More file actions
50 lines (37 loc) · 1.47 KB
/
Copy pathproxyTrust.test.ts
File metadata and controls
50 lines (37 loc) · 1.47 KB
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
import { resolveTrustProxySetting } from '../../src/utils/proxyTrust.js';
describe('resolveTrustProxySetting', () => {
const originalEnv = process.env;
beforeEach(() => {
jest.resetModules();
process.env = { ...originalEnv };
delete process.env.TRUST_PROXY;
delete process.env.KUBERNETES_SERVICE_HOST;
});
afterAll(() => {
process.env = originalEnv;
});
it('returns false by default outside container environments', () => {
expect(resolveTrustProxySetting(process.env, () => false)).toBe(false);
});
it('trusts a single proxy by default inside Docker-like environments', () => {
expect(resolveTrustProxySetting(process.env, () => true)).toBe(1);
});
it('trusts a single proxy by default inside Kubernetes environments', () => {
process.env.KUBERNETES_SERVICE_HOST = '10.96.0.1';
expect(resolveTrustProxySetting(process.env, () => false)).toBe(1);
});
it('allows explicitly disabling trust proxy', () => {
process.env.TRUST_PROXY = 'false';
expect(resolveTrustProxySetting(process.env, () => true)).toBe(false);
});
it('parses numeric trust proxy hop counts', () => {
process.env.TRUST_PROXY = '2';
expect(resolveTrustProxySetting(process.env, () => false)).toBe(2);
});
it('passes through named proxy presets', () => {
process.env.TRUST_PROXY = 'loopback, linklocal, uniquelocal';
expect(resolveTrustProxySetting(process.env, () => false)).toBe(
'loopback, linklocal, uniquelocal',
);
});
});