@@ -11,6 +11,7 @@ import { CoreV1Api } from './api';
1111import { bufferFromFileOrString , findHomeDir , findObject , KubeConfig , makeAbsolutePath } from './config' ;
1212import { Cluster , newClusters , newContexts , newUsers , User , ActionOnInvalid } from './config_types' ;
1313import { ExecAuth } from './exec_auth' ;
14+ import { request } from 'http' ;
1415
1516const kcFileName = 'testdata/kubeconfig.yaml' ;
1617const kc2FileName = 'testdata/kubeconfig-2.yaml' ;
@@ -240,6 +241,44 @@ describe('KubeConfig', () => {
240241 } ) ;
241242
242243 describe ( 'applyHTTPSOptions' , ( ) => {
244+ it ( 'should apply tls-server-name to https.RequestOptions' , async ( ) => {
245+ const kc = new KubeConfig ( ) ;
246+ kc . loadFromFile ( kcTlsServerNameFileName ) ;
247+
248+ const opts : https . RequestOptions = { } ;
249+ await kc . applytoHTTPSOptions ( opts ) ;
250+
251+ expect ( opts ) . to . deep . equal ( {
252+ headers : { } ,
253+ ca : new Buffer ( 'CADATA2' , 'utf-8' ) ,
254+ cert : new Buffer ( 'USER_CADATA' , 'utf-8' ) ,
255+ key : new Buffer ( 'USER_CKDATA' , 'utf-8' ) ,
256+ rejectUnauthorized : false ,
257+ servername : 'kube.example2.com' ,
258+ } ) ;
259+ } ) ;
260+ it ( 'should apply tls-server-name to request.Options' , async ( ) => {
261+ const kc = new KubeConfig ( ) ;
262+ kc . loadFromFile ( kcTlsServerNameFileName ) ;
263+
264+ const opts : requestlib . Options = {
265+ url : 'https://company.com' ,
266+ } ;
267+ await kc . applyToRequest ( opts ) ;
268+
269+ expect ( opts ) . to . deep . equal ( {
270+ url : 'https://company.com' ,
271+ headers : { } ,
272+ ca : new Buffer ( 'CADATA2' , 'utf-8' ) ,
273+ cert : new Buffer ( 'USER_CADATA' , 'utf-8' ) ,
274+ key : new Buffer ( 'USER_CKDATA' , 'utf-8' ) ,
275+ rejectUnauthorized : false ,
276+ strictSSL : false ,
277+ agentOptions : {
278+ servername : 'kube.example2.com' ,
279+ } ,
280+ } ) ;
281+ } ) ;
243282 it ( 'should apply cert configs' , ( ) => {
244283 const kc = new KubeConfig ( ) ;
245284 kc . loadFromFile ( kcFileName ) ;
0 commit comments