@@ -3,7 +3,8 @@ import * as https from 'https';
3
3
import { join } from 'path' ;
4
4
import { RequestOptions } from 'https' ;
5
5
6
- import { expect } from 'chai' ;
6
+ import { expect , use } from 'chai' ;
7
+ import chaiAsPromised from 'chai-as-promised'
7
8
import mockfs = require( 'mock-fs' ) ;
8
9
import * as path from 'path' ;
9
10
@@ -12,6 +13,7 @@ import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolu
12
13
import { Cluster , newClusters , newContexts , newUsers , User , ActionOnInvalid } from './config_types' ;
13
14
import { ExecAuth } from './exec_auth' ;
14
15
import { HttpMethod } from '.' ;
16
+ import { assertRequestOptionsEqual } from '../test/match-buffer' ;
15
17
16
18
const kcFileName = 'testdata/kubeconfig.yaml' ;
17
19
const kc2FileName = 'testdata/kubeconfig-2.yaml' ;
@@ -23,6 +25,8 @@ const kcNoUserFileName = 'testdata/empty-user-kubeconfig.yaml';
23
25
const kcInvalidContextFileName = 'testdata/empty-context-kubeconfig.yaml' ;
24
26
const kcInvalidClusterFileName = 'testdata/empty-cluster-kubeconfig.yaml' ;
25
27
28
+ use ( chaiAsPromised )
29
+
26
30
/* tslint:disable: no-empty */
27
31
describe ( 'Config' , ( ) => { } ) ;
28
32
@@ -243,9 +247,9 @@ describe('KubeConfig', () => {
243
247
244
248
expect ( opts ) . to . deep . equal ( {
245
249
headers : { } ,
246
- ca : new Buffer ( 'CADATA2' , 'utf-8' ) ,
247
- cert : new Buffer ( 'USER2_CADATA' , 'utf-8' ) ,
248
- key : new Buffer ( 'USER2_CKDATA' , 'utf-8' ) ,
250
+ ca : Buffer . from ( 'CADATA2' , 'utf-8' ) ,
251
+ cert : Buffer . from ( 'USER2_CADATA' , 'utf-8' ) ,
252
+ key : Buffer . from ( 'USER2_CKDATA' , 'utf-8' ) ,
249
253
rejectUnauthorized : false ,
250
254
} ) ;
251
255
} ) ;
@@ -261,17 +265,24 @@ describe('KubeConfig', () => {
261
265
const rc = new RequestContext ( testServerName1 , HttpMethod . GET ) ;
262
266
await kc . applySecurityAuthentication ( rc ) ;
263
267
await kc . applytoHTTPSOptions ( opts ) ;
264
- expect ( opts ) . to . deep . equal ( {
268
+ const expectedCA = Buffer . from ( 'CADATA2' , 'utf-8' )
269
+ const expectedAgent = new https . Agent ( {
270
+ ca : expectedCA ,
271
+ cert : undefined ,
272
+ key : undefined ,
273
+ passphrase : undefined ,
274
+ pfx : undefined ,
275
+ rejectUnauthorized : false ,
276
+ } )
277
+ let expectedOptions : https . RequestOptions = {
278
+ auth : 'foo:bar' ,
265
279
headers : { } ,
266
- ca : new Buffer ( 'CADATA2' , 'utf-8' ) ,
267
- auth : {
268
- username : 'foo' ,
269
- password : 'bar' ,
270
- } ,
271
- url : 'https://company.com' ,
272
- strictSSL : false ,
273
280
rejectUnauthorized : false ,
274
- } ) ;
281
+ servername : 'https://company.com' ,
282
+ agent : expectedAgent ,
283
+ }
284
+
285
+ assertRequestOptionsEqual ( opts , expectedOptions )
275
286
} ) ;
276
287
} ) ;
277
288
0 commit comments