From 14d2055e8bef41185a9abee2f388a8cabcdada64 Mon Sep 17 00:00:00 2001 From: Ludovic Audibert Date: Wed, 8 Dec 2021 15:21:03 +0100 Subject: [PATCH 1/2] Fix expires-on case on Azure auth --- src/azure_auth.ts | 3 ++- src/azure_auth_test.ts | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/azure_auth.ts b/src/azure_auth.ts index 8fe7f139612..085c8bca37a 100644 --- a/src/azure_auth.ts +++ b/src/azure_auth.ts @@ -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; } diff --git a/src/azure_auth_test.ts b/src/azure_auth_test.ts index 97a5d952323..a1f2b318c1b 100644 --- a/src/azure_auth_test.ts +++ b/src/azure_auth_test.ts @@ -168,6 +168,26 @@ 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; + console.log('expireOn',expireOn) + 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') { From 5ae6ad8b94f90b4b86eaa36dbe377e88d44d8b69 Mon Sep 17 00:00:00 2001 From: Ludovic Audibert Date: Fri, 10 Dec 2021 10:22:24 +0100 Subject: [PATCH 2/2] Fixed format for azure_auth_test.ts --- src/azure_auth_test.ts | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/azure_auth_test.ts b/src/azure_auth_test.ts index a1f2b318c1b..39944a38deb 100644 --- a/src/azure_auth_test.ts +++ b/src/azure_auth_test.ts @@ -169,23 +169,22 @@ describe('AzureAuth', () => { }); it('should exec when no cmd and token is not expired', async () => { - const config = new KubeConfig(); - const expireOn = (new Date().getTime() / 1000) + 1000; - console.log('expireOn',expireOn) - 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); + 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 () => {