Skip to content

Commit

Permalink
Merge pull request kubernetes-client#352 from jnummelin/fix/whitespac…
Browse files Browse the repository at this point in the history
…e-in-commands-for-gcp-and-azure

Use command as quoted string in CloudAuth
  • Loading branch information
k8s-ci-robot authored Oct 13, 2019
2 parents a5e4aab + 2e9dbfa commit 9e10c20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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(' '))

0 comments on commit 9e10c20

Please sign in to comment.