From c3e5aeb31d7e7508a809c364353ff9a67b306d3d Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Thu, 16 Apr 2020 16:51:24 -0700 Subject: [PATCH] Add a test for exec token caching and fix the implementation. --- src/config.ts | 1 + src/config_test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/config.ts b/src/config.ts index 43638cfb46..e190aeed81 100644 --- a/src/config.ts +++ b/src/config.ts @@ -531,6 +531,7 @@ export function findObject(list: T[], name: string, key: string for (const obj of list) { if (obj.name === name) { if (obj[key]) { + obj[key].name = name; return obj[key]; } return obj; diff --git a/src/config_test.ts b/src/config_test.ts index ae7edfe399..4135f5c5db 100644 --- a/src/config_test.ts +++ b/src/config_test.ts @@ -924,6 +924,32 @@ describe('KubeConfig', () => { expect(opts.headers.Authorization).to.equal(`Bearer ${token}`); } }); + it('should cache exec with name', async () => { + const config = new KubeConfig(); + const token = 'token'; + const responseStr = `{ + "apiVersion": "client.authentication.k8s.io/v1beta1", + "kind": "ExecCredential", + "status": { + "token": "${token}" + } + }`; + config.loadFromClusterAndUser( + { skipTLSVerify: false } as Cluster, + { + name: 'exec', + exec: { + command: 'echo', + args: [`${responseStr}`], + }, + } as User, + ); + // TODO: inject the exec command here? + const opts = {} as requestlib.Options; + await config.applyToRequest(opts); + expect((KubeConfig as any).authenticators[1].tokenCache['exec']).to.deep.equal(JSON.parse(responseStr)); + }); + it('should throw with no command.', () => { const config = new KubeConfig(); config.loadFromClusterAndUser(