@@ -301,8 +301,10 @@ describe('KubeConfig', () => {
301301 const kc = new KubeConfig ( ) ;
302302 kc . loadFromFile ( kcTlsServerNameFileName ) ;
303303
304+ const requestContext = new RequestContext ( 'https://kube.example.com' , HttpMethod . GET ) ;
304305 const opts : https . RequestOptions = { } ;
305306 await kc . applyToHTTPSOptions ( opts ) ;
307+ await kc . applySecurityAuthentication ( requestContext ) ;
306308
307309 const expectedAgent = new https . Agent ( {
308310 ca : Buffer . from ( 'CADATA2' , 'utf-8' ) ,
@@ -322,6 +324,8 @@ describe('KubeConfig', () => {
322324 } ;
323325
324326 assertRequestOptionsEqual ( opts , expectedOptions ) ;
327+ console . log ( requestContext . getAgent ( ) ) ;
328+ strictEqual ( ( requestContext . getAgent ( ) ! as any ) . options . servername , 'kube.example2.com' ) ;
325329 } ) ;
326330 it ( 'should apply cert configs' , async ( ) => {
327331 const kc = new KubeConfig ( ) ;
@@ -1630,5 +1634,60 @@ describe('KubeConfig', () => {
16301634 strictEqual ( inputData ! . toString ( ) , data ) ;
16311635 mockfs . restore ( ) ;
16321636 } ) ;
1637+ it ( 'should try to load from WSL on Windows with wsl.exe not working' , ( ) => {
1638+ const kc = new KubeConfig ( ) ;
1639+ const commands : { command : string ; args : string [ ] } [ ] = [ ] ;
1640+ ( kc as any ) . spawnSync = ( cmd : string , args : string [ ] ) => {
1641+ commands . push ( { command : cmd , args } ) ;
1642+ return { status : 1 , stderr : 'some error' } ;
1643+ } ;
1644+ kc . loadFromDefault ( undefined , false , 'win32' ) ;
1645+ strictEqual ( commands . length , 2 ) ;
1646+ for ( let i = 0 ; i < commands . length ; i ++ ) {
1647+ strictEqual ( commands [ i ] . command , 'wsl.exe' ) ;
1648+ }
1649+ } ) ;
1650+ it ( 'should try to load from WSL on Windows with $KUBECONFIG' , ( ) => {
1651+ const kc = new KubeConfig ( ) ;
1652+ const test_path = 'C:\\Users\\user\\.kube\\config' ;
1653+ const configData = readFileSync ( kcFileName ) ;
1654+ const commands : { command : string ; args : string [ ] } [ ] = [ ] ;
1655+ const results : { status : number ; stderr : string ; stdout : string } [ ] = [
1656+ { status : 0 , stderr : '' , stdout : test_path } ,
1657+ { status : 0 , stderr : '' , stdout : configData . toString ( ) } ,
1658+ ] ;
1659+ let ix = 0 ;
1660+ ( kc as any ) . spawnSync = ( cmd : string , args : string [ ] ) => {
1661+ commands . push ( { command : cmd , args } ) ;
1662+ return results [ ix ++ ] ;
1663+ } ;
1664+ kc . loadFromDefault ( undefined , false , 'win32' ) ;
1665+ strictEqual ( commands . length , 2 ) ;
1666+ for ( let i = 0 ; i < commands . length ; i ++ ) {
1667+ strictEqual ( commands [ i ] . command , 'wsl.exe' ) ;
1668+ }
1669+ validateFileLoad ( kc ) ;
1670+ } ) ;
1671+ it ( 'should try to load from WSL on Windows without $KUBECONFIG' , ( ) => {
1672+ const kc = new KubeConfig ( ) ;
1673+ const configData = readFileSync ( kcFileName ) ;
1674+ const commands : { command : string ; args : string [ ] } [ ] = [ ] ;
1675+ const results : { status : number ; stderr : string ; stdout : string } [ ] = [
1676+ { status : 1 , stderr : 'Some Error' , stdout : '' } ,
1677+ { status : 0 , stderr : '' , stdout : configData . toString ( ) } ,
1678+ { status : 0 , stderr : '' , stdout : 'C:\\wsldata\\.kube' } ,
1679+ ] ;
1680+ let ix = 0 ;
1681+ ( kc as any ) . spawnSync = ( cmd : string , args : string [ ] ) => {
1682+ commands . push ( { command : cmd , args } ) ;
1683+ return results [ ix ++ ] ;
1684+ } ;
1685+ kc . loadFromDefault ( undefined , false , 'win32' ) ;
1686+ strictEqual ( commands . length , 3 ) ;
1687+ for ( let i = 0 ; i < commands . length ; i ++ ) {
1688+ strictEqual ( commands [ i ] . command , 'wsl.exe' ) ;
1689+ }
1690+ validateFileLoad ( kc ) ;
1691+ } ) ;
16331692 } ) ;
16341693} ) ;
0 commit comments