Skip to content

Commit 6131bae

Browse files
authored
Merge pull request #753 from laudibert/master
Fix expires-on case on Azure auth
2 parents eae3e8d + 5ae6ad8 commit 6131bae

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/azure_auth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ export class AzureAuth implements Authenticator {
5757
return false;
5858
}
5959

60-
const expiration = expiry ? Date.parse(expiry) : new Date(parseInt(expiresOn!, 10));
60+
const expiresOnDate = expiresOn ? new Date(parseInt(expiresOn, 10) * 1000) : undefined;
61+
const expiration = expiry ? Date.parse(expiry) : expiresOnDate!;
6162
if (expiration < Date.now()) {
6263
return true;
6364
}

src/azure_auth_test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,25 @@ describe('AzureAuth', () => {
168168
return expect(config.applyToRequest(opts)).to.eventually.be.rejectedWith(/Failed to refresh token/);
169169
});
170170

171+
it('should exec when no cmd and token is not expired', async () => {
172+
const config = new KubeConfig();
173+
const expireOn = new Date().getTime() / 1000 + 1000;
174+
config.loadFromClusterAndUser(
175+
{ skipTLSVerify: false } as Cluster,
176+
{
177+
authProvider: {
178+
name: 'azure',
179+
config: {
180+
'access-token': 'token',
181+
'expires-on': expireOn.toString(),
182+
},
183+
},
184+
} as User,
185+
);
186+
const opts = {} as requestlib.Options;
187+
await config.applyToRequest(opts);
188+
});
189+
171190
it('should exec with expired token', async () => {
172191
// TODO: fix this test for Windows
173192
if (process.platform === 'win32') {

0 commit comments

Comments
 (0)