Skip to content

Commit 52c383a

Browse files
committed
add unit tests for tls-server-name
1 parent 542f037 commit 52c383a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/config_test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CoreV1Api } from './api';
1111
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config';
1212
import { Cluster, newClusters, newContexts, newUsers, User, ActionOnInvalid } from './config_types';
1313
import { ExecAuth } from './exec_auth';
14+
import { request } from 'http';
1415

1516
const kcFileName = 'testdata/kubeconfig.yaml';
1617
const 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

Comments
 (0)