@@ -3,6 +3,7 @@ import { deepEqual, deepStrictEqual, notStrictEqual, rejects, strictEqual, throw
33import child_process from 'node:child_process' ;
44import { readFileSync } from 'node:fs' ;
55import https from 'node:https' ;
6+ import http from 'node:http' ;
67import { Agent , RequestOptions } from 'node:https' ;
78import path , { dirname , join } from 'node:path' ;
89import { fileURLToPath } from 'node:url' ;
@@ -298,7 +299,7 @@ describe('KubeConfig', () => {
298299 } ) ;
299300 } ) ;
300301
301- describe ( 'applyHTTPSOptions' , ( ) => {
302+ describe . only ( 'applyHTTPSOptions' , ( ) => {
302303 it ( 'should apply tls-server-name to https.RequestOptions' , async ( ) => {
303304 const kc = new KubeConfig ( ) ;
304305 kc . loadFromFile ( kcTlsServerNameFileName ) ;
@@ -448,6 +449,30 @@ describe('KubeConfig', () => {
448449 message : 'Unsupported proxy type' ,
449450 } ) ;
450451 } ) ;
452+ it ( 'should apply http agent if cluster.server starts with http and no proxy-url is provided' , async ( ) => {
453+ const kc = new KubeConfig ( ) ;
454+ kc . loadFromFile ( kcProxyUrl ) ;
455+ kc . setCurrentContext ( 'contextE' ) ;
456+
457+ const testServerName = 'http://example.com' ;
458+ const rc = new RequestContext ( testServerName , HttpMethod . GET ) ;
459+
460+ await kc . applySecurityAuthentication ( rc ) ;
461+
462+ strictEqual ( rc . getAgent ( ) instanceof http . Agent , true ) ;
463+ } ) ;
464+ it ( 'should apply https agent if cluster.server starts with https and no proxy-url is provided' , async ( ) => {
465+ const kc = new KubeConfig ( ) ;
466+ kc . loadFromFile ( kcProxyUrl ) ;
467+ kc . setCurrentContext ( 'contextF' ) ;
468+
469+ const testServerName = 'https://example.com' ;
470+ const rc = new RequestContext ( testServerName , HttpMethod . GET ) ;
471+
472+ await kc . applySecurityAuthentication ( rc ) ;
473+
474+ strictEqual ( rc . getAgent ( ) instanceof https . Agent , true ) ;
475+ } ) ;
451476 } ) ;
452477
453478 describe ( 'loadClusterConfigObjects' , ( ) => {
0 commit comments