Skip to content

Commit c3e5aeb

Browse files
committed
Add a test for exec token caching and fix the implementation.
1 parent 76d8776 commit c3e5aeb

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ export function findObject<T extends Named>(list: T[], name: string, key: string
531531
for (const obj of list) {
532532
if (obj.name === name) {
533533
if (obj[key]) {
534+
obj[key].name = name;
534535
return obj[key];
535536
}
536537
return obj;

src/config_test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,32 @@ describe('KubeConfig', () => {
924924
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
925925
}
926926
});
927+
it('should cache exec with name', async () => {
928+
const config = new KubeConfig();
929+
const token = 'token';
930+
const responseStr = `{
931+
"apiVersion": "client.authentication.k8s.io/v1beta1",
932+
"kind": "ExecCredential",
933+
"status": {
934+
"token": "${token}"
935+
}
936+
}`;
937+
config.loadFromClusterAndUser(
938+
{ skipTLSVerify: false } as Cluster,
939+
{
940+
name: 'exec',
941+
exec: {
942+
command: 'echo',
943+
args: [`${responseStr}`],
944+
},
945+
} as User,
946+
);
947+
// TODO: inject the exec command here?
948+
const opts = {} as requestlib.Options;
949+
await config.applyToRequest(opts);
950+
expect((KubeConfig as any).authenticators[1].tokenCache['exec']).to.deep.equal(JSON.parse(responseStr));
951+
});
952+
927953
it('should throw with no command.', () => {
928954
const config = new KubeConfig();
929955
config.loadFromClusterAndUser(

0 commit comments

Comments
 (0)