Skip to content

Commit a510a5c

Browse files
authored
Merge pull request #829 from davidgamero/davidgamero/get-unit-tests-running
remove Object.ts and get unit tests runnable again
2 parents 99368ce + 45b2682 commit a510a5c

File tree

9 files changed

+56
-2718
lines changed

9 files changed

+56
-2718
lines changed

src/azure_auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class AzureAuth implements Authenticator {
8282
try {
8383
output = proc.execSync(cmd);
8484
} catch (err) {
85-
throw new Error('Failed to refresh token: ' + err.message);
85+
throw new Error('Failed to refresh token: ' + err);
8686
}
8787

8888
const resultObj = JSON.parse(output);

src/gcp_auth_test.ts

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { join } from 'path';
55
import { User, Cluster } from './config_types';
66
import { GoogleCloudPlatformAuth } from './gcp_auth';
77
import { KubeConfig } from './config';
8+
import { HttpMethod, RequestContext } from './gen';
89

910
describe('GoogleCloudPlatformAuth', () => {
11+
const testUrl1 = 'https://test-gcp.com';
1012
var auth: GoogleCloudPlatformAuth;
1113
beforeEach(() => {
1214
auth = new GoogleCloudPlatformAuth();
@@ -53,18 +55,18 @@ describe('GoogleCloudPlatformAuth', () => {
5355
},
5456
} as User,
5557
);
56-
const opts = {} as requestlib.Options;
58+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
5759

58-
await config.applyToRequest(opts);
59-
expect(opts.headers).to.not.be.undefined;
60-
if (opts.headers) {
61-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
60+
await config.applySecurityAuthentication(requestContext);
61+
expect(requestContext.getHeaders()).to.not.be.undefined;
62+
if (requestContext.getHeaders()) {
63+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
6264
}
63-
opts.headers = [];
64-
opts.headers.Host = 'foo.com';
65-
await config.applyToRequest(opts);
66-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
67-
});
65+
requestContext.setUrl('foo.com')
66+
//opts.headers.Host = 'foo.com';
67+
await config.applySecurityAuthentication(requestContext);
68+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
69+
});
6870

6971
it('should populate from auth provider without expirty', async () => {
7072
const config = new KubeConfig();
@@ -80,12 +82,12 @@ describe('GoogleCloudPlatformAuth', () => {
8082
},
8183
} as User,
8284
);
83-
const opts = {} as requestlib.Options;
84-
85-
await config.applyToRequest(opts);
86-
expect(opts.headers).to.not.be.undefined;
87-
if (opts.headers) {
88-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
85+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
86+
87+
await config.applySecurityAuthentication(requestContext);
88+
expect(requestContext.getHeaders()).to.not.be.undefined;
89+
if (requestContext.getHeaders()) {
90+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
8991
}
9092
});
9193

@@ -103,10 +105,10 @@ describe('GoogleCloudPlatformAuth', () => {
103105
},
104106
} as User,
105107
);
106-
const opts = {} as requestlib.Options;
108+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
107109

108-
await config.applyToRequest(opts);
109-
expect(opts.rejectUnauthorized).to.equal(false);
110+
await config.applySecurityAuthentication(requestContext);
111+
expect(requestContext.getHeaders()['rejectUnauthorized']).to.equal(false);
110112
});
111113

112114
it('should not set rejectUnauthorized if skipTLSVerify is not set', async () => {
@@ -125,10 +127,10 @@ describe('GoogleCloudPlatformAuth', () => {
125127
},
126128
} as User,
127129
);
128-
const opts = {} as requestlib.Options;
130+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
129131

130-
await config.applyToRequest(opts);
131-
expect(opts.rejectUnauthorized).to.equal(undefined);
132+
await config.applySecurityAuthentication(requestContext);
133+
expect(requestContext.getHeaders()['rejectUnauthorized']).to.equal(undefined);
132134
});
133135

134136
it('should throw with expired token and no cmd', () => {
@@ -144,9 +146,9 @@ describe('GoogleCloudPlatformAuth', () => {
144146
},
145147
} as User,
146148
);
147-
const opts = {} as requestlib.Options;
149+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
148150

149-
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith('Token is expired!');
151+
return expect(config.applySecurityAuthentication(requestContext)).to.eventually.be.rejectedWith('Token is expired!');
150152
});
151153

152154
it('should throw with bad command', () => {
@@ -164,8 +166,8 @@ describe('GoogleCloudPlatformAuth', () => {
164166
},
165167
} as User,
166168
);
167-
const opts = {} as requestlib.Options;
168-
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith(/Failed to refresh token/);
169+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
170+
return expect(config.applySecurityAuthentication(requestContext)).to.eventually.be.rejectedWith(/Failed to refresh token/);
169171
});
170172

171173
it('should exec with expired token', async () => {
@@ -191,11 +193,11 @@ describe('GoogleCloudPlatformAuth', () => {
191193
},
192194
} as User,
193195
);
194-
const opts = {} as requestlib.Options;
195-
await config.applyToRequest(opts);
196-
expect(opts.headers).to.not.be.undefined;
197-
if (opts.headers) {
198-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
196+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
197+
await config.applySecurityAuthentication(requestContext);
198+
expect(requestContext.getHeaders()).to.not.be.undefined;
199+
if (requestContext.getHeaders()) {
200+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
199201
}
200202
});
201203
it('should exec without access-token', async () => {
@@ -220,11 +222,11 @@ describe('GoogleCloudPlatformAuth', () => {
220222
},
221223
} as User,
222224
);
223-
const opts = {} as requestlib.Options;
224-
await config.applyToRequest(opts);
225-
expect(opts.headers).to.not.be.undefined;
226-
if (opts.headers) {
227-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
225+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
226+
await config.applySecurityAuthentication(requestContext);
227+
expect(requestContext.getHeaders()).to.not.be.undefined;
228+
if (requestContext.getHeaders()) {
229+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
228230
}
229231
});
230232
it('should exec without access-token', async () => {
@@ -249,11 +251,11 @@ describe('GoogleCloudPlatformAuth', () => {
249251
},
250252
} as User,
251253
);
252-
const opts = {} as requestlib.Options;
253-
await config.applyToRequest(opts);
254-
expect(opts.headers).to.not.be.undefined;
255-
if (opts.headers) {
256-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
254+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
255+
await config.applySecurityAuthentication(requestContext);
256+
expect(requestContext.getHeaders()).to.not.be.undefined;
257+
if (requestContext.getHeaders()) {
258+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
257259
}
258260
});
259261
it('should exec succesfully with spaces in cmd', async () => {
@@ -278,11 +280,11 @@ describe('GoogleCloudPlatformAuth', () => {
278280
},
279281
} as User,
280282
);
281-
const opts = {} as requestlib.Options;
282-
await config.applyToRequest(opts);
283-
expect(opts.headers).to.not.be.undefined;
284-
if (opts.headers) {
285-
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
283+
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
284+
await config.applySecurityAuthentication(requestContext);
285+
expect(requestContext.getHeaders()).to.not.be.undefined;
286+
if (requestContext.getHeaders()) {
287+
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
286288
}
287289
});
288290
});

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export * from './yaml';
1010
export * from './log';
1111
export * from './informer';
1212
export * from './top';
13-
export * from './object';
1413
export * from './cp';
1514
export * from './patch';
1615
export * from './metrics';

src/integration_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('FullRequest', () => {
4242
.get('/api/v1/namespaces/default/pods')
4343
.reply(200, result);
4444

45-
const promise = k8sApi.listNamespacedPod('default');
45+
const promise = k8sApi.listNamespacedPod({namespace:'default'});
4646

4747
return expect(promise)
4848
.to.eventually.have.property('body')

src/metrics.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { KubeConfig } from './config';
44
import { HttpException, ApiException, V1Status } from './gen';
55
import { ObjectSerializer } from './util';
66
import fetch from 'node-fetch'
7+
import { RequestOptions } from 'https';
78

89
export interface Usage {
910
cpu: string;
@@ -85,9 +86,9 @@ export class Metrics {
8586
throw new Error('No currently active cluster');
8687
}
8788

88-
const requestOptions: request.Options = {
89+
const requestOptions: RequestOptions = {
8990
method: 'GET',
90-
uri: cluster.server + path,
91+
servername: cluster.server + path,
9192
};
9293

9394
const requestURL = cluster.server + path;

0 commit comments

Comments
 (0)