|
1 | 1 | import { after, before, beforeEach, describe, it, mock } from 'node:test'; |
2 | | -import { deepEqual, deepStrictEqual, notStrictEqual, rejects, strictEqual, throws } from 'node:assert'; |
| 2 | +import assert, { |
| 3 | + deepEqual, |
| 4 | + deepStrictEqual, |
| 5 | + notStrictEqual, |
| 6 | + rejects, |
| 7 | + strictEqual, |
| 8 | + throws, |
| 9 | +} from 'node:assert'; |
3 | 10 | import child_process from 'node:child_process'; |
4 | 11 | import { readFileSync } from 'node:fs'; |
5 | 12 | import https from 'node:https'; |
| 13 | +import http from 'node:http'; |
6 | 14 | import { Agent, RequestOptions } from 'node:https'; |
7 | 15 | import path, { dirname, join } from 'node:path'; |
8 | 16 | import { fileURLToPath } from 'node:url'; |
@@ -449,6 +457,40 @@ describe('KubeConfig', () => { |
449 | 457 | message: 'Unsupported proxy type', |
450 | 458 | }); |
451 | 459 | }); |
| 460 | + it('should apply http agent if cluster.server starts with http and no proxy-url is provided', async () => { |
| 461 | + const kc = new KubeConfig(); |
| 462 | + kc.loadFromFile(kcProxyUrl); |
| 463 | + kc.setCurrentContext('contextE'); |
| 464 | + |
| 465 | + const testServerName = 'http://example.com'; |
| 466 | + const rc = new RequestContext(testServerName, HttpMethod.GET); |
| 467 | + |
| 468 | + await kc.applySecurityAuthentication(rc); |
| 469 | + |
| 470 | + strictEqual(rc.getAgent() instanceof http.Agent, true); |
| 471 | + }); |
| 472 | + it('should throw an error if cluster.server starts with http, no proxy-url is provided and insecure-skip-tls-verify is not set', async () => { |
| 473 | + const kc = new KubeConfig(); |
| 474 | + kc.loadFromFile(kcProxyUrl); |
| 475 | + kc.setCurrentContext('contextF'); |
| 476 | + |
| 477 | + const testServerName = 'http://example.com'; |
| 478 | + const rc = new RequestContext(testServerName, HttpMethod.GET); |
| 479 | + |
| 480 | + await assert.rejects(kc.applySecurityAuthentication(rc), Error); |
| 481 | + }); |
| 482 | + it('should apply https agent if cluster.server starts with https and no proxy-url is provided', async () => { |
| 483 | + const kc = new KubeConfig(); |
| 484 | + kc.loadFromFile(kcProxyUrl); |
| 485 | + kc.setCurrentContext('contextG'); |
| 486 | + |
| 487 | + const testServerName = 'https://example.com'; |
| 488 | + const rc = new RequestContext(testServerName, HttpMethod.GET); |
| 489 | + |
| 490 | + await kc.applySecurityAuthentication(rc); |
| 491 | + |
| 492 | + strictEqual(rc.getAgent() instanceof https.Agent, true); |
| 493 | + }); |
452 | 494 | }); |
453 | 495 |
|
454 | 496 | describe('loadClusterConfigObjects', () => { |
|
0 commit comments