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

Fix expires-on case on Azure auth #753

Merged
merged 2 commits into from Dec 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/azure_auth.ts
Expand Up @@ -57,7 +57,8 @@ export class AzureAuth implements Authenticator {
return false;
}

const expiration = expiry ? Date.parse(expiry) : new Date(parseInt(expiresOn!, 10));
const expiresOnDate = expiresOn ? new Date(parseInt(expiresOn, 10) * 1000) : undefined;
const expiration = expiry ? Date.parse(expiry) : expiresOnDate!;
if (expiration < Date.now()) {
return true;
}
Expand Down
19 changes: 19 additions & 0 deletions src/azure_auth_test.ts
Expand Up @@ -168,6 +168,25 @@ describe('AzureAuth', () => {
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith(/Failed to refresh token/);
});

it('should exec when no cmd and token is not expired', async () => {
const config = new KubeConfig();
const expireOn = new Date().getTime() / 1000 + 1000;
config.loadFromClusterAndUser(
{ skipTLSVerify: false } as Cluster,
{
authProvider: {
name: 'azure',
config: {
'access-token': 'token',
'expires-on': expireOn.toString(),
},
},
} as User,
);
const opts = {} as requestlib.Options;
await config.applyToRequest(opts);
});

it('should exec with expired token', async () => {
// TODO: fix this test for Windows
if (process.platform === 'win32') {
Expand Down