Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Object.ts and get unit tests runnable again #829

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/azure_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class AzureAuth implements Authenticator {
try {
output = proc.execSync(cmd);
} catch (err) {
throw new Error('Failed to refresh token: ' + err.message);
throw new Error('Failed to refresh token: ' + err);
}

const resultObj = JSON.parse(output);
Expand Down
94 changes: 48 additions & 46 deletions src/gcp_auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import { join } from 'path';
import { User, Cluster } from './config_types';
import { GoogleCloudPlatformAuth } from './gcp_auth';
import { KubeConfig } from './config';
import { HttpMethod, RequestContext } from './gen';

describe('GoogleCloudPlatformAuth', () => {
const testUrl1 = 'https://test-gcp.com';
var auth: GoogleCloudPlatformAuth;
beforeEach(() => {
auth = new GoogleCloudPlatformAuth();
Expand Down Expand Up @@ -53,18 +55,18 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)

await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()).to.not.be.undefined;
if (requestContext.getHeaders()) {
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
}
opts.headers = [];
opts.headers.Host = 'foo.com';
await config.applyToRequest(opts);
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
});
requestContext.setUrl('foo.com')
//opts.headers.Host = 'foo.com';
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
});

it('should populate from auth provider without expirty', async () => {
const config = new KubeConfig();
Expand All @@ -80,12 +82,12 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;

await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()).to.not.be.undefined;
if (requestContext.getHeaders()) {
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
}
});

Expand All @@ -103,10 +105,10 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)

await config.applyToRequest(opts);
expect(opts.rejectUnauthorized).to.equal(false);
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()['rejectUnauthorized']).to.equal(false);
});

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

await config.applyToRequest(opts);
expect(opts.rejectUnauthorized).to.equal(undefined);
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()['rejectUnauthorized']).to.equal(undefined);
});

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

return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith('Token is expired!');
return expect(config.applySecurityAuthentication(requestContext)).to.eventually.be.rejectedWith('Token is expired!');
});

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

it('should exec with expired token', async () => {
Expand All @@ -191,11 +193,11 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;
await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()).to.not.be.undefined;
if (requestContext.getHeaders()) {
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
}
});
it('should exec without access-token', async () => {
Expand All @@ -220,11 +222,11 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;
await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()).to.not.be.undefined;
if (requestContext.getHeaders()) {
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
}
});
it('should exec without access-token', async () => {
Expand All @@ -249,11 +251,11 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;
await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()).to.not.be.undefined;
if (requestContext.getHeaders()) {
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
}
});
it('should exec succesfully with spaces in cmd', async () => {
Expand All @@ -278,11 +280,11 @@ describe('GoogleCloudPlatformAuth', () => {
},
} as User,
);
const opts = {} as requestlib.Options;
await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
let requestContext = new RequestContext(testUrl1, HttpMethod.GET)
await config.applySecurityAuthentication(requestContext);
expect(requestContext.getHeaders()).to.not.be.undefined;
if (requestContext.getHeaders()) {
expect(requestContext.getHeaders()['Authorization']).to.equal(`Bearer ${token}`);
}
});
});
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export * from './yaml';
export * from './log';
export * from './informer';
export * from './top';
export * from './object';
export * from './cp';
export * from './patch';
export * from './metrics';
Expand Down
2 changes: 1 addition & 1 deletion src/integration_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('FullRequest', () => {
.get('/api/v1/namespaces/default/pods')
.reply(200, result);

const promise = k8sApi.listNamespacedPod('default');
const promise = k8sApi.listNamespacedPod({namespace:'default'});

return expect(promise)
.to.eventually.have.property('body')
Expand Down
5 changes: 3 additions & 2 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { KubeConfig } from './config';
import { HttpException, ApiException, V1Status } from './gen';
import { ObjectSerializer } from './util';
import fetch from 'node-fetch'
import { RequestOptions } from 'https';

export interface Usage {
cpu: string;
Expand Down Expand Up @@ -85,9 +86,9 @@ export class Metrics {
throw new Error('No currently active cluster');
}

const requestOptions: request.Options = {
const requestOptions: RequestOptions = {
method: 'GET',
uri: cluster.server + path,
servername: cluster.server + path,
};

const requestURL = cluster.server + path;
Expand Down
Loading