1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const proxy_1 = require("./proxy");
|
4 | beforeEach(() => {
|
5 | proxy_1.default.env = {};
|
6 | });
|
7 | test('returns nothing', () => {
|
8 | expect(proxy_1.default.agent(true)).toBeUndefined();
|
9 | });
|
10 | describe('with proxies', () => {
|
11 | beforeEach(() => {
|
12 | proxy_1.default.env.HTTP_PROXY = 'http://user:pass@foo.com';
|
13 | proxy_1.default.env.HTTPS_PROXY = 'https://user:pass@bar.com';
|
14 | });
|
15 | test('has http properties', () => {
|
16 | expect(proxy_1.default.agent(false)).toMatchObject({
|
17 | options: {
|
18 | proxy: {
|
19 | host: 'foo.com',
|
20 | port: '8080',
|
21 | proxyAuth: 'user:pass',
|
22 | },
|
23 | },
|
24 | proxyOptions: {
|
25 | host: 'foo.com',
|
26 | port: '8080',
|
27 | proxyAuth: 'user:pass',
|
28 | },
|
29 | });
|
30 | });
|
31 | test('has https properties', () => {
|
32 | expect(proxy_1.default.agent(true)).toMatchObject({
|
33 | defaultPort: 443,
|
34 | options: {
|
35 | proxy: {
|
36 | host: 'bar.com',
|
37 | port: '8080',
|
38 | proxyAuth: 'user:pass',
|
39 | },
|
40 | },
|
41 | proxyOptions: {
|
42 | host: 'bar.com',
|
43 | port: '8080',
|
44 | proxyAuth: 'user:pass',
|
45 | },
|
46 | });
|
47 | });
|
48 | });
|
49 | describe('with http proxy only', () => {
|
50 | beforeEach(() => {
|
51 | proxy_1.default.env.HTTP_PROXY = 'http://user:pass@foo.com';
|
52 | });
|
53 | test('has agent', () => {
|
54 | expect(proxy_1.default.agent(true)).toMatchObject({
|
55 | defaultPort: 443,
|
56 | options: {
|
57 | proxy: {
|
58 | host: 'foo.com',
|
59 | port: '8080',
|
60 | proxyAuth: 'user:pass',
|
61 | },
|
62 | },
|
63 | proxyOptions: {
|
64 | host: 'foo.com',
|
65 | port: '8080',
|
66 | proxyAuth: 'user:pass',
|
67 | },
|
68 | });
|
69 | });
|
70 | });
|
71 | describe('with no_proxy', () => {
|
72 | beforeEach(() => {
|
73 | proxy_1.default.env.HTTP_PROXY = 'http://user:pass@foo.com';
|
74 | proxy_1.default.env.NO_PROXY = 'some.com,test-domain.com';
|
75 | });
|
76 | test('is an exact match of no_proxy', () => {
|
77 | expect(proxy_1.default.agent(false, 'test-domain.com')).toBeUndefined();
|
78 | });
|
79 | test('is a subdomain of no_proxy', () => {
|
80 | expect(proxy_1.default.agent(false, 'something.prod.test-domain.com')).toBeUndefined();
|
81 | });
|
82 | test('should be proxied', () => {
|
83 | expect(proxy_1.default.agent(false, 'proxied-domain.com')).toMatchObject({
|
84 | options: {
|
85 | proxy: {
|
86 | host: 'foo.com',
|
87 | port: '8080',
|
88 | proxyAuth: 'user:pass',
|
89 | },
|
90 | },
|
91 | proxyOptions: {
|
92 | host: 'foo.com',
|
93 | port: '8080',
|
94 | proxyAuth: 'user:pass',
|
95 | },
|
96 | });
|
97 | });
|
98 | });
|
99 | describe('proxy dodging', () => {
|
100 | test('not set should proxy', () => {
|
101 | proxy_1.default.env.NO_PROXY = '';
|
102 | expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(false);
|
103 | expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(false);
|
104 | });
|
105 | test('wildcard proxies any', () => {
|
106 | proxy_1.default.env.NO_PROXY = '*';
|
107 | expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true);
|
108 | expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(true);
|
109 | });
|
110 | test('exact domain should also match subdomains', () => {
|
111 | proxy_1.default.env.NO_PROXY = 'test-domain.com';
|
112 | expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true);
|
113 | expect(proxy_1.default.shouldDodgeProxy('anything.test-domain.com')).toBe(true);
|
114 | expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(false);
|
115 | expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(false);
|
116 | });
|
117 | test('any sub domain should include the domain itself', () => {
|
118 | proxy_1.default.env.NO_PROXY = '.test-domain.com';
|
119 | expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true);
|
120 | expect(proxy_1.default.shouldDodgeProxy('anything.test-domain.com')).toBe(true);
|
121 | expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(false);
|
122 | expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(false);
|
123 | });
|
124 | test('multiple domains', () => {
|
125 | proxy_1.default.env.NO_PROXY = '.test-domain.com, .other-domain.com';
|
126 | expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true);
|
127 | expect(proxy_1.default.shouldDodgeProxy('anything.test-domain.com')).toBe(true);
|
128 | expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(true);
|
129 | expect(proxy_1.default.shouldDodgeProxy('anything.other-domain.com')).toBe(true);
|
130 | });
|
131 | test('match any subdomains', () => {
|
132 | proxy_1.default.env.NO_PROXY = '.test-domain.com, other-domain.com';
|
133 | expect(proxy_1.default.shouldDodgeProxy('test-domain.com')).toBe(true);
|
134 | expect(proxy_1.default.shouldDodgeProxy('something.something-else.anything.test-domain.com')).toBe(true);
|
135 | expect(proxy_1.default.shouldDodgeProxy('other-domain.com')).toBe(true);
|
136 | expect(proxy_1.default.shouldDodgeProxy('something.anything.other-domain.com')).toBe(true);
|
137 | });
|
138 | });
|