Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cloud_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class CloudAuth implements Authenticator {
if (!cmd) {
throw new Error('Token is expired!');
}
// Wrap cmd in quotes to make it cope with spaces in path
cmd = `"${cmd}"`;
const args = config['cmd-args'];
if (args) {
cmd = cmd + ' ' + args;
Expand Down
30 changes: 29 additions & 1 deletion src/config_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { dirname, join } from 'path';

import { expect } from 'chai';
import mockfs = require('mock-fs');
import * as requestlib from 'request';
import * as path from 'path';
import * as requestlib from 'request';

import * as filesystem from 'fs';
import { fs } from 'mock-fs';
import * as os from 'os';
import { CoreV1Api } from './api';
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config';
import { Cluster, newClusters, newContexts, newUsers, User } from './config_types';
Expand Down Expand Up @@ -788,6 +791,31 @@ describe('KubeConfig', () => {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
}
});
it('should exec succesfully with spaces in cmd', async () => {
const config = new KubeConfig();
const token = 'token';
const responseStr = `{"token":{"accessToken":"${token}"}}`;
config.loadFromClusterAndUser(
{ skipTLSVerify: false } as Cluster,
{
authProvider: {
name: 'azure', // applies to gcp too as they are both handled by CloudAuth class
config: {
'cmd-path': path.join(__dirname, '..', 'test', 'echo space.js'),
'cmd-args': `'${responseStr}'`,
'token-key': '{.token.accessToken}',
'expiry-key': '{.token.token_expiry}',
},
},
} as User,
);
const opts = {} as requestlib.Options;
await config.applyToRequest(opts);
expect(opts.headers).to.not.be.undefined;
if (opts.headers) {
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
}
});
it('should exec with exec auth and env vars', async () => {
const config = new KubeConfig();
const token = 'token';
Expand Down
4 changes: 4 additions & 0 deletions test/echo space.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

// Just echo back all the args
console.log(process.argv.slice(2).join(' '))