global-agent 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitignore CHANGED
@@ -5,8 +5,6 @@ node_modules
5
5
  .*
6
6
  !.babelrc
7
7
  !.editorconfig
8
- !.eslintignore
9
- !.eslintrc
10
8
  !.github
11
9
  !.gitignore
12
10
  !.npmignore
package/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # global-agent
2
2
 
3
- [![Coveralls](https://img.shields.io/coveralls/gajus/global-agent.svg?style=flat-square)](https://coveralls.io/github/gajus/global-agent)
4
3
  [![NPM version](http://img.shields.io/npm/v/global-agent.svg?style=flat-square)](https://www.npmjs.org/package/global-agent)
5
4
  [![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
6
5
  [![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)
package/package.json CHANGED
@@ -2,18 +2,7 @@
2
2
  "author": {
3
3
  "email": "gajus@gajus.com",
4
4
  "name": "Gajus Kuizinas",
5
- "url": "http://gajus.com"
6
- },
7
- "ava": {
8
- "extensions": [
9
- "ts"
10
- ],
11
- "files": [
12
- "test/global-agent/**/*"
13
- ],
14
- "require": [
15
- "ts-node/register/transpile-only"
16
- ]
5
+ "url": "https://gajus.com"
17
6
  },
18
7
  "dependencies": {
19
8
  "es6-error": "^4.1.1",
@@ -25,14 +14,12 @@
25
14
  },
26
15
  "description": "Global HTTP/HTTPS proxy configurable using environment variables.",
27
16
  "devDependencies": {
28
- "@ava/babel": "^2.0.0",
29
17
  "@babel/cli": "^7.14.8",
30
18
  "@babel/core": "^7.14.8",
31
19
  "@babel/node": "^7.14.7",
32
20
  "@babel/plugin-transform-flow-strip-types": "^7.14.5",
33
21
  "@babel/preset-env": "^7.14.8",
34
22
  "@babel/register": "^7.14.5",
35
- "@istanbuljs/nyc-config-typescript": "^1.0.1",
36
23
  "@semantic-release/commit-analyzer": "^13.0.1",
37
24
  "@semantic-release/github": "^12.0.3",
38
25
  "@semantic-release/npm": "^13.1.3",
@@ -41,24 +28,20 @@
41
28
  "@types/request": "^2.48.6",
42
29
  "@types/semver": "^7.3.8",
43
30
  "@types/sinon": "^10.0.2",
44
- "ava": "^3.15.0",
45
31
  "axios": "^0.21.1",
46
- "babel-plugin-istanbul": "^6.0.0",
47
32
  "babel-plugin-transform-export-default-name": "^2.1.0",
48
- "coveralls": "^3.1.1",
49
33
  "del-cli": "^4.0.1",
50
- "eslint": "^7.31.0",
51
- "eslint-config-canonical": "^26.2.3",
52
34
  "get-port": "^5.1.1",
53
35
  "got": "^11.8.2",
54
36
  "husky": "^7.0.1",
55
- "nyc": "^15.1.0",
37
+ "oxlint": "^1.43.0",
56
38
  "pem": "^1.14.4",
57
39
  "request": "^2.88.2",
58
40
  "semantic-release": "^25.0.3",
59
41
  "sinon": "^11.1.2",
60
42
  "ts-node": "^10.1.0",
61
- "typescript": "^4.3.5"
43
+ "typescript": "^4.3.5",
44
+ "vitest": "^4.0.18"
62
45
  },
63
46
  "engines": {
64
47
  "node": ">=10.0"
@@ -77,20 +60,16 @@
77
60
  "license": "BSD-3-Clause",
78
61
  "main": "./dist/src/index.js",
79
62
  "name": "global-agent",
80
- "nyc": {
81
- "extends": "@istanbuljs/nyc-config-typescript",
82
- "all": true
83
- },
84
63
  "repository": {
85
64
  "type": "git",
86
65
  "url": "https://github.com/gajus/global-agent"
87
66
  },
88
67
  "scripts": {
89
68
  "build": "del-cli ./dist && tsc",
90
- "lint": "eslint ./src ./test && tsc",
91
- "test": "ava --verbose --serial",
69
+ "lint": "oxlint ./src && tsc",
70
+ "test": "vitest run",
92
71
  "create-readme": "gitdown ./.README/README.md --output-file ./README.md"
93
72
  },
94
73
  "typings": "./dist/src/index.d.ts",
95
- "version": "4.1.0"
74
+ "version": "4.1.1"
96
75
  }
package/src/Logger.ts CHANGED
@@ -9,7 +9,7 @@ export type Logger = {
9
9
  warn: LogMethod,
10
10
  };
11
11
 
12
- // eslint-disable-next-line @typescript-eslint/no-empty-function
12
+ // oxlint-disable-next-line @typescript-eslint/no-empty-function
13
13
  const noop = () => {};
14
14
 
15
15
  const createNoopLogger = (): Logger => {
@@ -108,7 +108,7 @@ abstract class Agent {
108
108
  * Evaluate value for tls reject unauthorized variable
109
109
  */
110
110
  public getRejectUnauthorized () {
111
- // eslint-disable-next-line node/no-process-env
111
+ // oxlint-disable-next-line node/no-process-env
112
112
  const rejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
113
113
  let returnValue = true;
114
114
  if (typeof rejectUnauthorized === 'boolean') {
@@ -136,7 +136,7 @@ abstract class Agent {
136
136
  } else if (request.method === 'CONNECT') {
137
137
  requestUrl = 'https://' + request.path;
138
138
  } else {
139
- requestUrl = this.protocol + '//' + (configuration.hostname ?? configuration.host) + (configuration.port === 80 ?? configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
139
+ requestUrl = this.protocol + '//' + (configuration.hostname ?? configuration.host) + (configuration.port === 80 || configuration.port === 443 ? '' : ':' + configuration.port) + request.path;
140
140
  }
141
141
 
142
142
  // If a request should go to a local socket, proxying it through an HTTP
@@ -6,11 +6,12 @@ import http from 'http';
6
6
  import https from 'https';
7
7
  import net from 'net';
8
8
  import {
9
- serial,
10
- before,
11
9
  afterEach,
10
+ beforeAll,
12
11
  beforeEach,
13
- } from 'ava';
12
+ expect,
13
+ test,
14
+ } from 'vitest';
14
15
  import axios from 'axios';
15
16
  import getPort from 'get-port';
16
17
  import got from 'got';
@@ -19,7 +20,7 @@ import makeRequest from 'request';
19
20
  import {
20
21
  stub,
21
22
  } from 'sinon';
22
- import createGlobalProxyAgent from '../../../src/factories/createGlobalProxyAgent';
23
+ import createGlobalProxyAgent from './createGlobalProxyAgent';
23
24
 
24
25
  type ProxyServerType = {
25
26
  port: number,
@@ -57,7 +58,7 @@ const defaultHttpAgent = http.globalAgent;
57
58
  const defaultHttpsAgent = https.globalAgent;
58
59
 
59
60
  // Backup original value of NODE_TLS_REJECT_UNAUTHORIZED
60
- // eslint-disable-next-line node/no-process-env
61
+ // oxlint-disable-next-line node/no-process-env
61
62
  const defaultNodeTlsRejectUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
62
63
 
63
64
  let lastPort = 3_000;
@@ -101,7 +102,7 @@ const generateCertificates = (): Promise<{
101
102
  });
102
103
  };
103
104
 
104
- before(async () => {
105
+ beforeAll(async () => {
105
106
  // Pre-generate certificates
106
107
  await generateCertificates();
107
108
  });
@@ -131,7 +132,7 @@ afterEach(() => {
131
132
  localHttpsServers = [];
132
133
 
133
134
  // Reset NODE_TLS_REJECT_UNAUTHORIZED to original value
134
- // eslint-disable-next-line node/no-process-env
135
+ // oxlint-disable-next-line node/no-process-env
135
136
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = defaultNodeTlsRejectUnauthorized;
136
137
  });
137
138
 
@@ -291,7 +292,7 @@ const createHttpServer = async (): Promise<HttpServerType> => {
291
292
  return localHttpServer;
292
293
  };
293
294
 
294
- serial('proxies HTTP request', async (t) => {
295
+ test('proxies HTTP request', async () => {
295
296
  const globalProxyAgent = createGlobalProxyAgent();
296
297
 
297
298
  const proxyServer = await createProxyServer();
@@ -302,10 +303,10 @@ serial('proxies HTTP request', async (t) => {
302
303
  http.get('http://127.0.0.1', createHttpResponseResolver(resolve));
303
304
  });
304
305
 
305
- t.is(response.body, 'OK');
306
+ expect(response.body).toBe('OK');
306
307
  });
307
308
 
308
- serial('proxies HTTP request with proxy-authorization header', async (t) => {
309
+ test('proxies HTTP request with proxy-authorization header', async () => {
309
310
  const globalProxyAgent = createGlobalProxyAgent();
310
311
 
311
312
  const beforeSendRequest = stub().callsFake(() => {
@@ -328,45 +329,45 @@ serial('proxies HTTP request with proxy-authorization header', async (t) => {
328
329
  http.get('http://127.0.0.1', createHttpResponseResolver(resolve));
329
330
  });
330
331
 
331
- t.is(response.body, 'OK');
332
+ expect(response.body).toBe('OK');
332
333
 
333
- t.is(beforeSendRequest.firstCall.args[0].requestOptions.headers['proxy-authorization'], 'Basic Zm9v');
334
+ expect(beforeSendRequest.firstCall.args[0].requestOptions.headers['proxy-authorization']).toBe('Basic Zm9v');
334
335
  });
335
336
 
336
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = undefined', async (t) => {
337
- // eslint-disable-next-line node/no-process-env
338
- const {NODE_TLS_REJECT_UNAUTHORIZED, ...restEnvironments} = process.env; // eslint-disable-line @typescript-eslint/no-unused-vars
339
- // eslint-disable-next-line node/no-process-env
337
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = undefined', async () => {
338
+ // oxlint-disable-next-line node/no-process-env
339
+ const {NODE_TLS_REJECT_UNAUTHORIZED, ...restEnvironments} = process.env; // oxlint-disable-line @typescript-eslint/no-unused-vars
340
+ // oxlint-disable-next-line node/no-process-env
340
341
  process.env = restEnvironments;
341
- // eslint-disable-next-line node/no-process-env
342
+ // oxlint-disable-next-line node/no-process-env
342
343
  process.env.GLOBAL_AGENT_FORCE_GLOBAL_AGENT = 'true';
343
344
  const globalProxyAgent = createGlobalProxyAgent();
344
345
  const proxyServer = await createProxyServer();
345
346
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
346
347
  const globalAgent: any = https.globalAgent;
347
- t.is(globalAgent.getRejectUnauthorized(), true);
348
+ expect(globalAgent.getRejectUnauthorized()).toBe(true);
348
349
 
349
350
  const response: HttpResponseType = await new Promise((resolve) => {
350
351
  http.get('http://127.0.0.1', createHttpResponseResolver(resolve));
351
352
  });
352
353
 
353
- t.is(response.body, 'OK');
354
+ expect(response.body).toBe('OK');
354
355
  });
355
356
 
356
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = null', async (t) => {
357
- // eslint-disable-next-line node/no-process-env
357
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = null', async () => {
358
+ // oxlint-disable-next-line node/no-process-env
358
359
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 'null';
359
360
  const globalProxyAgent = createGlobalProxyAgent();
360
361
  const proxyServer = await createProxyServer();
361
362
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
362
363
 
363
364
  const globalAgent: any = https.globalAgent;
364
- t.is(globalAgent.getRejectUnauthorized(), false);
365
+ expect(globalAgent.getRejectUnauthorized()).toBe(false);
365
366
  });
366
367
 
367
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = 1', async (t) => {
368
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = 1', async () => {
368
369
  // @ts-expect-error it is expected as we wanted to set process variable with int
369
- // eslint-disable-next-line node/no-process-env
370
+ // oxlint-disable-next-line node/no-process-env
370
371
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 1;
371
372
  const globalProxyAgent = createGlobalProxyAgent();
372
373
 
@@ -375,12 +376,12 @@ serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = 1'
375
376
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
376
377
 
377
378
  const globalAgent: any = https.globalAgent;
378
- t.is(globalAgent.getRejectUnauthorized(), true);
379
+ expect(globalAgent.getRejectUnauthorized()).toBe(true);
379
380
  });
380
381
 
381
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = 0', async (t) => {
382
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = 0', async () => {
382
383
  // @ts-expect-error it is expected as we wanted to set process variable with int
383
- // eslint-disable-next-line node/no-process-env
384
+ // oxlint-disable-next-line node/no-process-env
384
385
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
385
386
  const globalProxyAgent = createGlobalProxyAgent();
386
387
 
@@ -389,74 +390,74 @@ serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = 0'
389
390
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
390
391
 
391
392
  const globalAgent: any = https.globalAgent;
392
- t.is(globalAgent.getRejectUnauthorized(), false);
393
+ expect(globalAgent.getRejectUnauthorized()).toBe(false);
393
394
  });
394
395
 
395
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = true', async (t) => {
396
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = true', async () => {
396
397
  // @ts-expect-error it is expected as we wanted to set process variable with boolean
397
- // eslint-disable-next-line node/no-process-env
398
+ // oxlint-disable-next-line node/no-process-env
398
399
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = true;
399
400
  const globalProxyAgent = createGlobalProxyAgent();
400
401
  const proxyServer = await createProxyServer();
401
402
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
402
403
 
403
404
  const globalAgent: any = https.globalAgent;
404
- t.is(globalAgent.getRejectUnauthorized(), true);
405
+ expect(globalAgent.getRejectUnauthorized()).toBe(true);
405
406
  });
406
407
 
407
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = false', async (t) => {
408
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = false', async () => {
408
409
  // @ts-expect-error it is expected as we wanted to set process variable with boolean
409
- // eslint-disable-next-line node/no-process-env
410
+ // oxlint-disable-next-line node/no-process-env
410
411
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = false;
411
412
  const globalProxyAgent = createGlobalProxyAgent();
412
413
  const proxyServer = await createProxyServer();
413
414
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
414
415
 
415
416
  const globalAgent: any = https.globalAgent;
416
- t.is(globalAgent.getRejectUnauthorized(), false);
417
+ expect(globalAgent.getRejectUnauthorized()).toBe(false);
417
418
  });
418
419
 
419
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = yes', async (t) => {
420
- // eslint-disable-next-line node/no-process-env
420
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = yes', async () => {
421
+ // oxlint-disable-next-line node/no-process-env
421
422
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 'yes';
422
423
  const globalProxyAgent = createGlobalProxyAgent();
423
424
  const proxyServer = await createProxyServer();
424
425
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
425
426
 
426
427
  const globalAgent: any = https.globalAgent;
427
- t.is(globalAgent.getRejectUnauthorized(), true);
428
+ expect(globalAgent.getRejectUnauthorized()).toBe(true);
428
429
  });
429
430
 
430
- serial('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = no', async (t) => {
431
- // eslint-disable-next-line node/no-process-env
431
+ test('Test reject unauthorized variable when NODE_TLS_REJECT_UNAUTHORIZED = no', async () => {
432
+ // oxlint-disable-next-line node/no-process-env
432
433
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = 'no';
433
434
  const globalProxyAgent = createGlobalProxyAgent();
434
435
  const proxyServer = await createProxyServer();
435
436
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
436
437
 
437
438
  const globalAgent: any = https.globalAgent;
438
- t.is(globalAgent.getRejectUnauthorized(), false);
439
+ expect(globalAgent.getRejectUnauthorized()).toBe(false);
439
440
  });
440
441
 
441
- serial('Test addCACertificates and clearCACertificates methods', async (t) => {
442
+ test('Test addCACertificates and clearCACertificates methods', async () => {
442
443
  const globalProxyAgent = createGlobalProxyAgent();
443
444
 
444
445
  const proxyServer = await createProxyServer();
445
446
 
446
447
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
447
448
  const globalAgent: any = https.globalAgent;
448
- t.is(globalAgent.ca, undefined);
449
+ expect(globalAgent.ca).toBe(undefined);
449
450
  globalAgent.addCACertificates(['test-ca-certficate1', 'test-ca-certficate2']);
450
451
  globalAgent.addCACertificates(['test-ca-certficate3']);
451
452
  const result = ['test-ca-certficate1', 'test-ca-certficate2', 'test-ca-certficate3'];
452
- t.is(globalAgent.ca.length, result.length);
453
- t.is(JSON.stringify(globalAgent.ca), JSON.stringify(result));
453
+ expect(globalAgent.ca.length).toBe(result.length);
454
+ expect(JSON.stringify(globalAgent.ca)).toBe(JSON.stringify(result));
454
455
  globalAgent.clearCACertificates();
455
- t.is(globalAgent.ca, undefined);
456
+ expect(globalAgent.ca).toBe(undefined);
456
457
  });
457
458
 
458
- serial('Test addCACertificates when passed ca is a string', async (t) => {
459
- // eslint-disable-next-line node/no-process-env
459
+ test('Test addCACertificates when passed ca is a string', async () => {
460
+ // oxlint-disable-next-line node/no-process-env
460
461
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
461
462
  const globalProxyAgent = createGlobalProxyAgent();
462
463
 
@@ -464,18 +465,18 @@ serial('Test addCACertificates when passed ca is a string', async (t) => {
464
465
 
465
466
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
466
467
  const globalAgent: any = https.globalAgent;
467
- t.is(globalAgent.ca, undefined);
468
+ expect(globalAgent.ca).toBe(undefined);
468
469
  globalAgent.addCACertificates('test-ca-certficate1');
469
470
  globalAgent.addCACertificates('test-ca-certficate2');
470
- t.is(globalAgent.ca, 'test-ca-certficate1test-ca-certficate2');
471
+ expect(globalAgent.ca).toBe('test-ca-certficate1test-ca-certficate2');
471
472
  const response: HttpResponseType = await new Promise((resolve) => {
472
473
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
473
474
  });
474
- t.is(response.body, 'OK');
475
+ expect(response.body).toBe('OK');
475
476
  });
476
477
 
477
- serial('Test addCACertificates when input ca is a string and existing ca is array', async (t) => {
478
- // eslint-disable-next-line node/no-process-env
478
+ test('Test addCACertificates when input ca is a string and existing ca is array', async () => {
479
+ // oxlint-disable-next-line node/no-process-env
479
480
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
480
481
  const globalProxyAgent = createGlobalProxyAgent({ca: ['test-ca']});
481
482
 
@@ -483,18 +484,18 @@ serial('Test addCACertificates when input ca is a string and existing ca is arra
483
484
 
484
485
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
485
486
  const globalAgent: any = https.globalAgent;
486
- t.is(globalAgent.ca.length, 1);
487
+ expect(globalAgent.ca.length).toBe(1);
487
488
  globalAgent.addCACertificates('test-ca-certficate1');
488
- t.is(globalAgent.ca.length, 1);
489
- t.is(JSON.stringify(globalAgent.ca), JSON.stringify(['test-ca']));
489
+ expect(globalAgent.ca.length).toBe(1);
490
+ expect(JSON.stringify(globalAgent.ca)).toBe(JSON.stringify(['test-ca']));
490
491
  const response: HttpResponseType = await new Promise((resolve) => {
491
492
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
492
493
  });
493
- t.is(response.body, 'OK');
494
+ expect(response.body).toBe('OK');
494
495
  });
495
496
 
496
- serial('Test addCACertificates when input ca array is null or undefined', async (t) => {
497
- // eslint-disable-next-line node/no-process-env
497
+ test('Test addCACertificates when input ca array is null or undefined', async () => {
498
+ // oxlint-disable-next-line node/no-process-env
498
499
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
499
500
  const globalProxyAgent = createGlobalProxyAgent();
500
501
 
@@ -502,18 +503,18 @@ serial('Test addCACertificates when input ca array is null or undefined', async
502
503
 
503
504
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
504
505
  const globalAgent: any = https.globalAgent;
505
- t.is(globalAgent.ca, undefined);
506
+ expect(globalAgent.ca).toBe(undefined);
506
507
  globalAgent.addCACertificates(undefined);
507
508
  globalAgent.addCACertificates(null);
508
- t.is(globalAgent.ca, undefined);
509
+ expect(globalAgent.ca).toBe(undefined);
509
510
  const response: HttpResponseType = await new Promise((resolve) => {
510
511
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
511
512
  });
512
- t.is(response.body, 'OK');
513
+ expect(response.body).toBe('OK');
513
514
  });
514
515
 
515
- serial('Test initializing ca certificate property while creating global proxy agent', async (t) => {
516
- // eslint-disable-next-line node/no-process-env
516
+ test('Test initializing ca certificate property while creating global proxy agent', async () => {
517
+ // oxlint-disable-next-line node/no-process-env
517
518
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
518
519
  const globalProxyAgent = createGlobalProxyAgent({ca: ['test-ca']});
519
520
 
@@ -521,19 +522,19 @@ serial('Test initializing ca certificate property while creating global proxy ag
521
522
 
522
523
  globalProxyAgent.HTTP_PROXY = proxyServer.url;
523
524
  const globalAgent: any = https.globalAgent;
524
- t.is(globalAgent.ca.length, 1);
525
+ expect(globalAgent.ca.length).toBe(1);
525
526
  globalAgent.addCACertificates(['test-ca1']);
526
- t.is(globalAgent.ca.length, 2);
527
- t.is(globalAgent.ca[0], 'test-ca');
528
- t.is(globalAgent.ca[1], 'test-ca1');
527
+ expect(globalAgent.ca.length).toBe(2);
528
+ expect(globalAgent.ca[0]).toBe('test-ca');
529
+ expect(globalAgent.ca[1]).toBe('test-ca1');
529
530
  const response: HttpResponseType = await new Promise((resolve) => {
530
531
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
531
532
  });
532
- t.is(response.body, 'OK');
533
+ expect(response.body).toBe('OK');
533
534
  });
534
535
 
535
- serial('proxies HTTPS request', async (t) => {
536
- // eslint-disable-next-line node/no-process-env
536
+ test('proxies HTTPS request', async () => {
537
+ // oxlint-disable-next-line node/no-process-env
537
538
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
538
539
  const globalProxyAgent = createGlobalProxyAgent();
539
540
 
@@ -545,11 +546,11 @@ serial('proxies HTTPS request', async (t) => {
545
546
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
546
547
  });
547
548
 
548
- t.is(response.body, 'OK');
549
+ expect(response.body).toBe('OK');
549
550
  });
550
551
 
551
- serial('proxies HTTPS request with proxy-authorization header', async (t) => {
552
- // eslint-disable-next-line node/no-process-env
552
+ test('proxies HTTPS request with proxy-authorization header', async () => {
553
+ // oxlint-disable-next-line node/no-process-env
553
554
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
554
555
  const globalProxyAgent = createGlobalProxyAgent();
555
556
 
@@ -565,23 +566,23 @@ serial('proxies HTTPS request with proxy-authorization header', async (t) => {
565
566
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
566
567
  });
567
568
 
568
- t.is(response.body, 'OK');
569
+ expect(response.body).toBe('OK');
569
570
 
570
- t.is(onConnect.firstCall.args[0].headers['proxy-authorization'], 'Basic Zm9v');
571
+ expect(onConnect.firstCall.args[0].headers['proxy-authorization']).toBe('Basic Zm9v');
571
572
  });
572
573
 
573
- serial('does not produce unhandled rejection when cannot connect to proxy', async (t) => {
574
+ test('does not produce unhandled rejection when cannot connect to proxy', async () => {
574
575
  const globalProxyAgent = createGlobalProxyAgent();
575
576
 
576
577
  const port = await getNextPort();
577
578
 
578
579
  globalProxyAgent.HTTP_PROXY = 'http://127.0.0.1:' + port;
579
580
 
580
- await t.throwsAsync(got('http://127.0.0.1'));
581
+ await expect(got('http://127.0.0.1')).rejects.toThrow();
581
582
  });
582
583
 
583
- serial('proxies HTTPS request with dedicated proxy', async (t) => {
584
- // eslint-disable-next-line node/no-process-env
584
+ test('proxies HTTPS request with dedicated proxy', async () => {
585
+ // oxlint-disable-next-line node/no-process-env
585
586
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
586
587
  const globalProxyAgent = createGlobalProxyAgent();
587
588
 
@@ -593,10 +594,10 @@ serial('proxies HTTPS request with dedicated proxy', async (t) => {
593
594
  https.get('https://127.0.0.1', createHttpResponseResolver(resolve));
594
595
  });
595
596
 
596
- t.is(response.body, 'OK');
597
+ expect(response.body).toBe('OK');
597
598
  });
598
599
 
599
- serial('ignores dedicated HTTPS proxy for HTTP urls', async (t) => {
600
+ test('ignores dedicated HTTPS proxy for HTTP urls', async () => {
600
601
  const globalProxyAgent = createGlobalProxyAgent();
601
602
 
602
603
  const proxyServer = await createProxyServer();
@@ -608,10 +609,10 @@ serial('ignores dedicated HTTPS proxy for HTTP urls', async (t) => {
608
609
  http.get('http://127.0.0.1', {}, createHttpResponseResolver(resolve));
609
610
  });
610
611
 
611
- t.is(response.body, 'OK');
612
+ expect(response.body).toBe('OK');
612
613
  });
613
614
 
614
- serial('forwards requests matching NO_PROXY', async (t) => {
615
+ test('forwards requests matching NO_PROXY', async () => {
615
616
  const globalProxyAgent = createGlobalProxyAgent();
616
617
 
617
618
  const proxyServer = await createProxyServer();
@@ -624,10 +625,10 @@ serial('forwards requests matching NO_PROXY', async (t) => {
624
625
  http.get(httpServer.url, createHttpResponseResolver(resolve));
625
626
  });
626
627
 
627
- t.is(response.body, 'DIRECT');
628
+ expect(response.body).toBe('DIRECT');
628
629
  });
629
630
 
630
- serial('forwards requests that go to a socket', async (t) => {
631
+ test('forwards requests that go to a socket', async () => {
631
632
  const globalProxyAgent = createGlobalProxyAgent();
632
633
 
633
634
  // not relevant as traffic shouldn't go through proxy
@@ -639,9 +640,6 @@ serial('forwards requests that go to a socket', async (t) => {
639
640
  serverResponse.end();
640
641
  });
641
642
 
642
- t.teardown(() => {
643
- server.close();
644
- });
645
643
  server.listen('/tmp/test.sock');
646
644
 
647
645
  const response: HttpResponseType = await new Promise((resolve) => {
@@ -650,10 +648,13 @@ serial('forwards requests that go to a socket', async (t) => {
650
648
  socketPath: '/tmp/test.sock',
651
649
  }, createHttpResponseResolver(resolve));
652
650
  });
653
- t.is(response.body, 'OK');
651
+
652
+ server.close();
653
+
654
+ expect(response.body).toBe('OK');
654
655
  });
655
656
 
656
- serial('proxies HTTP request (using http.get(host))', async (t) => {
657
+ test('proxies HTTP request (using http.get(host))', async () => {
657
658
  const globalProxyAgent = createGlobalProxyAgent();
658
659
 
659
660
  const proxyServer = await createProxyServer();
@@ -666,10 +667,10 @@ serial('proxies HTTP request (using http.get(host))', async (t) => {
666
667
  }, createHttpResponseResolver(resolve));
667
668
  });
668
669
 
669
- t.is(response.body, 'OK');
670
+ expect(response.body).toBe('OK');
670
671
  });
671
672
 
672
- serial('proxies HTTP request (using got)', async (t) => {
673
+ test('proxies HTTP request (using got)', async () => {
673
674
  const globalProxyAgent = createGlobalProxyAgent();
674
675
 
675
676
  const proxyServer = await createProxyServer();
@@ -678,11 +679,11 @@ serial('proxies HTTP request (using got)', async (t) => {
678
679
 
679
680
  const response = await got('http://127.0.0.1');
680
681
 
681
- t.is(response.body, 'OK');
682
+ expect(response.body).toBe('OK');
682
683
  });
683
684
 
684
- serial('proxies HTTPS request (using got)', async (t) => {
685
- // eslint-disable-next-line node/no-process-env
685
+ test('proxies HTTPS request (using got)', async () => {
686
+ // oxlint-disable-next-line node/no-process-env
686
687
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
687
688
  const globalProxyAgent = createGlobalProxyAgent();
688
689
 
@@ -692,10 +693,10 @@ serial('proxies HTTPS request (using got)', async (t) => {
692
693
 
693
694
  const response = await got('https://127.0.0.1');
694
695
 
695
- t.is(response.body, 'OK');
696
+ expect(response.body).toBe('OK');
696
697
  });
697
698
 
698
- serial('proxies HTTP request (using axios)', async (t) => {
699
+ test('proxies HTTP request (using axios)', async () => {
699
700
  const globalProxyAgent = createGlobalProxyAgent();
700
701
 
701
702
  const proxyServer = await createProxyServer();
@@ -704,11 +705,11 @@ serial('proxies HTTP request (using axios)', async (t) => {
704
705
 
705
706
  const response = await axios.get('http://127.0.0.1');
706
707
 
707
- t.is(response.data, 'OK');
708
+ expect(response.data).toBe('OK');
708
709
  });
709
710
 
710
- serial('proxies HTTPS request (using axios)', async (t) => {
711
- // eslint-disable-next-line node/no-process-env
711
+ test('proxies HTTPS request (using axios)', async () => {
712
+ // oxlint-disable-next-line node/no-process-env
712
713
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
713
714
  const globalProxyAgent = createGlobalProxyAgent();
714
715
 
@@ -718,10 +719,10 @@ serial('proxies HTTPS request (using axios)', async (t) => {
718
719
 
719
720
  const response = await axios.get('https://127.0.0.1');
720
721
 
721
- t.is(response.data, 'OK');
722
+ expect(response.data).toBe('OK');
722
723
  });
723
724
 
724
- serial('proxies HTTP request (using request)', async (t) => {
725
+ test('proxies HTTP request (using request)', async () => {
725
726
  const globalProxyAgent = createGlobalProxyAgent();
726
727
 
727
728
  const proxyServer = await createProxyServer();
@@ -730,17 +731,17 @@ serial('proxies HTTP request (using request)', async (t) => {
730
731
 
731
732
  const response = await new Promise((resolve) => {
732
733
  makeRequest('http://127.0.0.1', (error, requestResponse, body) => {
733
- t.is(error, null);
734
+ expect(error).toBe(null);
734
735
 
735
736
  resolve(body);
736
737
  });
737
738
  });
738
739
 
739
- t.is(response, 'OK');
740
+ expect(response).toBe('OK');
740
741
  });
741
742
 
742
- serial('proxies HTTPS request (using request)', async (t) => {
743
- // eslint-disable-next-line node/no-process-env
743
+ test('proxies HTTPS request (using request)', async () => {
744
+ // oxlint-disable-next-line node/no-process-env
744
745
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
745
746
  const globalProxyAgent = createGlobalProxyAgent();
746
747
 
@@ -750,11 +751,11 @@ serial('proxies HTTPS request (using request)', async (t) => {
750
751
 
751
752
  const response = await new Promise((resolve) => {
752
753
  makeRequest('https://127.0.0.1', (error, requestResponse, body) => {
753
- t.is(error, null);
754
+ expect(error).toBe(null);
754
755
 
755
756
  resolve(body);
756
757
  });
757
758
  });
758
759
 
759
- t.is(response, 'OK');
760
+ expect(response).toBe('OK');
760
761
  });
@@ -45,7 +45,7 @@ const defaultConfigurationInput = {
45
45
  };
46
46
 
47
47
  const createConfiguration = (configurationInput: ProxyAgentConfigurationInputType): ProxyAgentConfigurationType => {
48
- // eslint-disable-next-line node/no-process-env
48
+ // oxlint-disable-next-line node/no-process-env
49
49
  const environment = process.env;
50
50
 
51
51
  const defaultConfiguration = {
@@ -69,13 +69,13 @@ export default (configurationInput: ProxyAgentConfigurationInputType = defaultCo
69
69
 
70
70
  const proxyController = createProxyController();
71
71
 
72
- // eslint-disable-next-line node/no-process-env
72
+ // oxlint-disable-next-line node/no-process-env
73
73
  proxyController.HTTP_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTP_PROXY'] ?? null;
74
74
 
75
- // eslint-disable-next-line node/no-process-env
75
+ // oxlint-disable-next-line node/no-process-env
76
76
  proxyController.HTTPS_PROXY = process.env[configuration.environmentVariableNamespace + 'HTTPS_PROXY'] ?? null;
77
77
 
78
- // eslint-disable-next-line node/no-process-env
78
+ // oxlint-disable-next-line node/no-process-env
79
79
  proxyController.NO_PROXY = process.env[configuration.environmentVariableNamespace + 'NO_PROXY'] ?? null;
80
80
 
81
81
  log.info({
@@ -0,0 +1,38 @@
1
+ import {
2
+ expect,
3
+ test,
4
+ } from 'vitest';
5
+ import createProxyController from './createProxyController';
6
+
7
+ test('sets HTTP_PROXY', () => {
8
+ const globalAgentGlobal = createProxyController();
9
+
10
+ globalAgentGlobal.HTTP_PROXY = 'http://127.0.0.1';
11
+
12
+ expect(globalAgentGlobal.HTTP_PROXY).toBe('http://127.0.0.1');
13
+ });
14
+
15
+ test('sets HTTPS_PROXY', () => {
16
+ const globalAgentGlobal = createProxyController();
17
+
18
+ globalAgentGlobal.HTTPS_PROXY = 'http://127.0.0.1';
19
+
20
+ expect(globalAgentGlobal.HTTPS_PROXY).toBe('http://127.0.0.1');
21
+ });
22
+
23
+ test('sets NO_PROXY', () => {
24
+ const globalAgentGlobal = createProxyController();
25
+
26
+ globalAgentGlobal.NO_PROXY = '*';
27
+
28
+ expect(globalAgentGlobal.NO_PROXY).toBe('*');
29
+ });
30
+
31
+ test('throws an error if unknown property is set', () => {
32
+ const globalAgentGlobal = createProxyController();
33
+
34
+ expect(() => {
35
+ // @ts-expect-error expected unknown property.
36
+ globalAgentGlobal.FOO = 'BAR';
37
+ }).toThrow('Cannot set an unmapped property "FOO".');
38
+ });
@@ -19,7 +19,7 @@ const KNOWN_PROPERTY_NAMES = [
19
19
  ];
20
20
 
21
21
  export default (): ProxyController => {
22
- // eslint-disable-next-line fp/no-proxy
22
+ // oxlint-disable-next-line fp/no-proxy
23
23
  return new Proxy({
24
24
  HTTP_PROXY: null,
25
25
  HTTPS_PROXY: null,
@@ -0,0 +1,77 @@
1
+ import {
2
+ expect,
3
+ test,
4
+ } from 'vitest';
5
+ import isUrlMatchingNoProxy from './isUrlMatchingNoProxy';
6
+
7
+ test('returns `true` if hosts match', () => {
8
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com')).toBe(true);
9
+ });
10
+
11
+ test('returns `true` if hosts match (IP)', () => {
12
+ expect(isUrlMatchingNoProxy('http://127.0.0.1/', '127.0.0.1')).toBe(true);
13
+ });
14
+
15
+ test('returns `true` if hosts match (using asterisk wildcard)', () => {
16
+ expect(isUrlMatchingNoProxy('http://bar.foo.com/', '*.foo.com')).toBe(true);
17
+ });
18
+
19
+ test('returns `true` if domain matches (using dot wildcard)', () => {
20
+ expect(isUrlMatchingNoProxy('http://foo.com/', '.foo.com')).toBe(true);
21
+ });
22
+
23
+ test('returns `true` if subdomain matches (using dot wildcard)', () => {
24
+ expect(isUrlMatchingNoProxy('http://bar.foo.com/', '.foo.com')).toBe(true);
25
+ });
26
+
27
+ test('returns `true` if hosts match (*) and ports match', () => {
28
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', '*:8080')).toBe(true);
29
+ });
30
+
31
+ test('returns `true` if hosts and ports match', () => {
32
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8080')).toBe(true);
33
+ });
34
+
35
+ test('returns `true` if hosts match and NO_PROXY does not define port', () => {
36
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com')).toBe(true);
37
+ });
38
+
39
+ test('returns `true` if hosts (IP) and ports match', () => {
40
+ expect(isUrlMatchingNoProxy('http://127.0.0.1:8080/', '127.0.0.1:8080')).toBe(true);
41
+ });
42
+
43
+ test('returns `false` if hosts match and ports do not match (diffferent port)', () => {
44
+ expect(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8000')).toBe(false);
45
+ });
46
+
47
+ test('returns `false` if hosts match and ports do not match (port not present subject)', () => {
48
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com:8000')).toBe(false);
49
+ });
50
+
51
+ test('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', () => {
52
+ expect(isUrlMatchingNoProxy('http://foo.com:8000/', 'foo.com')).toBe(true);
53
+ });
54
+
55
+ test('returns `true` if hosts match in one of multiple rules separated with a comma', () => {
56
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'bar.org,foo.com,baz.io')).toBe(true);
57
+ });
58
+
59
+ test('returns `true` if hosts match in one of multiple rules separated with a comma and a space', () => {
60
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'bar.org, foo.com, baz.io')).toBe(true);
61
+ });
62
+
63
+ test('returns `true` if hosts match in one of multiple rules separated with a space', () => {
64
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'bar.org foo.com baz.io')).toBe(true);
65
+ });
66
+
67
+ test('handles trailing newline in NO_PROXY', () => {
68
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com\n')).toBe(true);
69
+ });
70
+
71
+ test('handles trailing whitespace in NO_PROXY', () => {
72
+ expect(isUrlMatchingNoProxy('http://foo.com/', 'foo.com ')).toBe(true);
73
+ });
74
+
75
+ test('handles leading whitespace in NO_PROXY', () => {
76
+ expect(isUrlMatchingNoProxy('http://foo.com/', ' foo.com')).toBe(true);
77
+ });
@@ -6,7 +6,7 @@ import {
6
6
  export default (subjectUrl: string, noProxy: string) => {
7
7
  const subjectUrlTokens = new URL(subjectUrl);
8
8
 
9
- const rules = noProxy.split(/[\s,]+/);
9
+ const rules = noProxy.split(/[\s,]+/).filter(Boolean);
10
10
 
11
11
  for (const rule of rules) {
12
12
  const ruleMatch = rule
@@ -0,0 +1,35 @@
1
+ import {
2
+ expect,
3
+ test,
4
+ } from 'vitest';
5
+ import parseProxyUrl from './parseProxyUrl';
6
+
7
+ test('extracts hostname', () => {
8
+ expect(parseProxyUrl('http://0.0.0.0').hostname).toBe('0.0.0.0');
9
+ });
10
+
11
+ test('extracts port', () => {
12
+ expect(parseProxyUrl('http://0.0.0.0:3000').port).toBe(3_000);
13
+ });
14
+
15
+ test('extracts authorization', () => {
16
+ expect(parseProxyUrl('http://foo:bar@0.0.0.0').authorization).toBe('foo:bar');
17
+ });
18
+
19
+ test('throws an error if protocol is not "http:"', () => {
20
+ expect(() => {
21
+ parseProxyUrl('https://0.0.0.0:3000');
22
+ }).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
23
+ });
24
+
25
+ test('throws an error if query is present', () => {
26
+ expect(() => {
27
+ parseProxyUrl('http://0.0.0.0:3000/?foo=bar');
28
+ }).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
29
+ });
30
+
31
+ test('throws an error if hash is present', () => {
32
+ expect(() => {
33
+ parseProxyUrl('http://0.0.0.0:3000/#foo');
34
+ }).toThrow('Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
35
+ });
@@ -0,0 +1,11 @@
1
+ import {defineConfig} from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ include: ['src/**/*.test.ts'],
6
+ isolate: false,
7
+ sequence: {
8
+ concurrent: false,
9
+ },
10
+ },
11
+ });
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- /bootstrap.js
package/.eslintrc DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "extends": [
3
- "canonical",
4
- "canonical/node",
5
- "canonical/typescript"
6
- ],
7
- "parserOptions": {
8
- "project": "./tsconfig.json"
9
- },
10
- "root": true,
11
- "rules": {
12
- "@typescript-eslint/prefer-regexp-exec": 0,
13
- "class-methods-use-this": 0,
14
- "fp/no-class": 0,
15
- "fp/no-events": 0,
16
- "fp/no-this": 0,
17
- "import/no-cycle": 0,
18
- "no-continue": 0,
19
- "no-restricted-syntax": 0,
20
- "no-unused-expressions": [
21
- 2,
22
- {
23
- "allowTaggedTemplates": true
24
- }
25
- ]
26
- }
27
- }
package/test/.eslintrc DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "rules": {
3
- "ava/use-test": 0,
4
- "filenames/match-regex": 0,
5
- "flowtype/no-flow-fix-me-comments": 0,
6
- "flowtype/no-weak-types": 0,
7
- "id-length": 0,
8
- "node/no-unpublished-import": 0
9
- }
10
- }
@@ -1,37 +0,0 @@
1
- import test from 'ava';
2
- import createProxyController from '../../../src/factories/createProxyController';
3
-
4
- test('sets HTTP_PROXY', (t) => {
5
- const globalAgentGlobal = createProxyController();
6
-
7
- globalAgentGlobal.HTTP_PROXY = 'http://127.0.0.1';
8
-
9
- t.is(globalAgentGlobal.HTTP_PROXY, 'http://127.0.0.1');
10
- });
11
-
12
- test('sets HTTPS_PROXY', (t) => {
13
- const globalAgentGlobal = createProxyController();
14
-
15
- globalAgentGlobal.HTTPS_PROXY = 'http://127.0.0.1';
16
-
17
- t.is(globalAgentGlobal.HTTPS_PROXY, 'http://127.0.0.1');
18
- });
19
-
20
- test('sets NO_PROXY', (t) => {
21
- const globalAgentGlobal = createProxyController();
22
-
23
- globalAgentGlobal.NO_PROXY = '*';
24
-
25
- t.is(globalAgentGlobal.NO_PROXY, '*');
26
- });
27
-
28
- test('throws an error if unknown property is set', (t) => {
29
- const globalAgentGlobal = createProxyController();
30
-
31
- const error = t.throws(() => {
32
- // @ts-expect-error expected unknown property.
33
- globalAgentGlobal.FOO = 'BAR';
34
- });
35
-
36
- t.is(error.message, 'Cannot set an unmapped property "FOO".');
37
- });
@@ -1,62 +0,0 @@
1
- import test from 'ava';
2
- import isUrlMatchingNoProxy from '../../../src/utilities/isUrlMatchingNoProxy';
3
-
4
- test('returns `true` if hosts match', (t) => {
5
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'foo.com'));
6
- });
7
-
8
- test('returns `true` if hosts match (IP)', (t) => {
9
- t.assert(isUrlMatchingNoProxy('http://127.0.0.1/', '127.0.0.1'));
10
- });
11
-
12
- test('returns `true` if hosts match (using asterisk wildcard)', (t) => {
13
- t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '*.foo.com'));
14
- });
15
-
16
- test('returns `true` if domain matches (using dot wildcard)', (t) => {
17
- t.assert(isUrlMatchingNoProxy('http://foo.com/', '.foo.com'));
18
- });
19
-
20
- test('returns `true` if subdomain matches (using dot wildcard)', (t) => {
21
- t.assert(isUrlMatchingNoProxy('http://bar.foo.com/', '.foo.com'));
22
- });
23
-
24
- test('returns `true` if hosts match (*) and ports match', (t) => {
25
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', '*:8080'));
26
- });
27
-
28
- test('returns `true` if hosts and ports match', (t) => {
29
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8080'));
30
- });
31
-
32
- test('returns `true` if hosts match and NO_PROXY does not define port', (t) => {
33
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com'));
34
- });
35
-
36
- test('returns `true` if hosts (IP) and ports match', (t) => {
37
- t.assert(isUrlMatchingNoProxy('http://127.0.0.1:8080/', '127.0.0.1:8080'));
38
- });
39
-
40
- test('returns `false` if hosts match and ports do not match (diffferent port)', (t) => {
41
- t.assert(isUrlMatchingNoProxy('http://foo.com:8080/', 'foo.com:8000') === false);
42
- });
43
-
44
- test('returns `false` if hosts match and ports do not match (port not present subject)', (t) => {
45
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'foo.com:8000') === false);
46
- });
47
-
48
- test('returns `true` if hosts match and ports do not match (port not present NO_PROXY)', (t) => {
49
- t.assert(isUrlMatchingNoProxy('http://foo.com:8000/', 'foo.com'));
50
- });
51
-
52
- test('returns `true` if hosts match in one of multiple rules separated with a comma', (t) => {
53
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org,foo.com,baz.io'));
54
- });
55
-
56
- test('returns `true` if hosts match in one of multiple rules separated with a comma and a space', (t) => {
57
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org, foo.com, baz.io'));
58
- });
59
-
60
- test('returns `true` if hosts match in one of multiple rules separated with a space', (t) => {
61
- t.assert(isUrlMatchingNoProxy('http://foo.com/', 'bar.org foo.com baz.io'));
62
- });
@@ -1,38 +0,0 @@
1
- import test from 'ava';
2
- import parseProxyUrl from '../../../src/utilities/parseProxyUrl';
3
-
4
- test('extracts hostname', (t) => {
5
- t.is(parseProxyUrl('http://0.0.0.0').hostname, '0.0.0.0');
6
- });
7
-
8
- test('extracts port', (t) => {
9
- t.is(parseProxyUrl('http://0.0.0.0:3000').port, 3_000);
10
- });
11
-
12
- test('extracts authorization', (t) => {
13
- t.is(parseProxyUrl('http://foo:bar@0.0.0.0').authorization, 'foo:bar');
14
- });
15
-
16
- test('throws an error if protocol is not "http:"', (t) => {
17
- const error = t.throws(() => {
18
- parseProxyUrl('https://0.0.0.0:3000');
19
- });
20
-
21
- t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL protocol must be "http:".');
22
- });
23
-
24
- test('throws an error if query is present', (t) => {
25
- const error = t.throws(() => {
26
- parseProxyUrl('http://0.0.0.0:3000/?foo=bar');
27
- });
28
-
29
- t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have query.');
30
- });
31
-
32
- test('throws an error if hash is present', (t) => {
33
- const error = t.throws(() => {
34
- parseProxyUrl('http://0.0.0.0:3000/#foo');
35
- });
36
-
37
- t.is(error.message, 'Unsupported `GLOBAL_AGENT.HTTP_PROXY` configuration value: URL must not have hash.');
38
- });