Skip to content

Commit 441767a

Browse files
committed
use command as quoted string in CloudAuth
1 parent a5e4aab commit 441767a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/cloud_auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export class CloudAuth implements Authenticator {
6363
if (!cmd) {
6464
throw new Error('Token is expired!');
6565
}
66+
// Wrap cmd in quotes to make it cope with spaces in path
67+
cmd = `"${cmd}"`;
6668
const args = config['cmd-args'];
6769
if (args) {
6870
cmd = cmd + ' ' + args;

src/config_test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import { dirname, join } from 'path';
44

55
import { expect } from 'chai';
66
import mockfs = require('mock-fs');
7-
import * as requestlib from 'request';
87
import * as path from 'path';
8+
import * as requestlib from 'request';
99

10+
import * as filesystem from 'fs';
11+
import { fs } from 'mock-fs';
12+
import * as os from 'os';
1013
import { CoreV1Api } from './api';
1114
import { bufferFromFileOrString, findHomeDir, findObject, KubeConfig, makeAbsolutePath } from './config';
1215
import { Cluster, newClusters, newContexts, newUsers, User } from './config_types';
@@ -788,6 +791,39 @@ describe('KubeConfig', () => {
788791
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
789792
}
790793
});
794+
it('should exec succesfully with spaces in cmd', async () => {
795+
/**
796+
*
797+
* to test this, symlink echo to dir that has spaces:
798+
* mkdir -p /tmp/foo\ bar/
799+
* ln -s /bin/echo /tmp/foo\ bar/echo
800+
*
801+
* FIXME: Figure out a "portable" way to dynamically do this sort of symlink as part of the test case
802+
*/
803+
const config = new KubeConfig();
804+
const token = 'token';
805+
const responseStr = `{"token":{"accessToken":"${token}"}}`;
806+
config.loadFromClusterAndUser(
807+
{ skipTLSVerify: false } as Cluster,
808+
{
809+
authProvider: {
810+
name: 'azure', // aplias to gcp too as they are both handled by CloudAuth class
811+
config: {
812+
'cmd-path': '/tmp/foo bar/echo',
813+
'cmd-args': `'${responseStr}'`,
814+
'token-key': '{.token.accessToken}',
815+
'expiry-key': '{.token.token_expiry}',
816+
},
817+
},
818+
} as User,
819+
);
820+
const opts = {} as requestlib.Options;
821+
await config.applyToRequest(opts);
822+
expect(opts.headers).to.not.be.undefined;
823+
if (opts.headers) {
824+
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
825+
}
826+
});
791827
it('should exec with exec auth and env vars', async () => {
792828
const config = new KubeConfig();
793829
const token = 'token';

0 commit comments

Comments
 (0)