Skip to content

Commit

Permalink
Merge pull request #753 from laudibert/master
Browse files Browse the repository at this point in the history
Fix expires-on case on Azure auth
  • Loading branch information
k8s-ci-robot committed Dec 11, 2021
2 parents eae3e8d + 5ae6ad8 commit 6131bae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit 6131bae

Please sign in to comment.