Skip to content

Commit 9e10c20

Browse files
authored
Merge pull request #352 from jnummelin/fix/whitespace-in-commands-for-gcp-and-azure
Use command as quoted string in CloudAuth
2 parents a5e4aab + 2e9dbfa commit 9e10c20

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-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: 29 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,31 @@ describe('KubeConfig', () => {
788791
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
789792
}
790793
});
794+
it('should exec succesfully with spaces in cmd', async () => {
795+
const config = new KubeConfig();
796+
const token = 'token';
797+
const responseStr = `{"token":{"accessToken":"${token}"}}`;
798+
config.loadFromClusterAndUser(
799+
{ skipTLSVerify: false } as Cluster,
800+
{
801+
authProvider: {
802+
name: 'azure', // applies to gcp too as they are both handled by CloudAuth class
803+
config: {
804+
'cmd-path': path.join(__dirname, '..', 'test', 'echo space.js'),
805+
'cmd-args': `'${responseStr}'`,
806+
'token-key': '{.token.accessToken}',
807+
'expiry-key': '{.token.token_expiry}',
808+
},
809+
},
810+
} as User,
811+
);
812+
const opts = {} as requestlib.Options;
813+
await config.applyToRequest(opts);
814+
expect(opts.headers).to.not.be.undefined;
815+
if (opts.headers) {
816+
expect(opts.headers.Authorization).to.equal(`Bearer ${token}`);
817+
}
818+
});
791819
it('should exec with exec auth and env vars', async () => {
792820
const config = new KubeConfig();
793821
const token = 'token';

test/echo space.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
3+
// Just echo back all the args
4+
console.log(process.argv.slice(2).join(' '))

0 commit comments

Comments
 (0)