File tree Expand file tree Collapse file tree 4 files changed +70
-2
lines changed Expand file tree Collapse file tree 4 files changed +70
-2
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,5 @@ coverage/*
1010examples /package-lock.json
1111.nyc_output
1212kubernetes-client-node- * .tgz
13+ ** /* .swp
1314
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { User } from './config_types';
55
66export class ExecAuth implements Authenticator {
77 private readonly tokenCache : { [ key : string ] : any } = { } ;
8+ private execFn : ( cmd : string , opts : shell . ExecOpts ) => shell . ShellReturnValue = shell . exec ;
89
910 public isAuthProvider ( user : User ) {
1011 if ( ! user ) {
@@ -53,11 +54,11 @@ export class ExecAuth implements Authenticator {
5354 }
5455 let opts : shell . ExecOpts ;
5556 if ( exec . env ) {
56- const env = { } ;
57+ const env = process . env ;
5758 exec . env . forEach ( ( elt ) => ( env [ elt . name ] = elt . value ) ) ;
5859 opts = { env } ;
5960 }
60- const result = shell . exec ( cmd , opts ) ;
61+ const result = this . execFn ( cmd , opts ) ;
6162 if ( result . code === 0 ) {
6263 const obj = JSON . parse ( result . stdout ) ;
6364 this . tokenCache [ user . name ] = obj ;
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai' ;
2+ import { ExecAuth } from './exec_auth' ;
3+ import * as shell from 'shelljs' ;
4+
5+ describe ( 'ExecAuth' , ( ) => {
6+ it ( 'should correctly exec' , async ( ) => {
7+ const auth = new ExecAuth ( ) ;
8+ ( auth as any ) . execFn = ( command : string , opts : shell . ExecOpts ) : shell . ShellReturnValue => {
9+ return {
10+ code : 0 ,
11+ stdout : JSON . stringify ( { status : { token : 'foo' } } )
12+ } as shell . ShellReturnValue ;
13+ } ;
14+
15+ const token = auth . getToken ( {
16+ name : 'user' ,
17+ authProvider : {
18+ config : {
19+ exec : {
20+ command : 'echo'
21+ }
22+ }
23+ }
24+ } ) ;
25+ expect ( token ) . to . equal ( 'Bearer foo' ) ;
26+ } ) ;
27+
28+ it ( 'should exec with env vars' , async ( ) => {
29+ const auth = new ExecAuth ( ) ;
30+ var optsOut : shell . ExecOpts = { } ;
31+ ( auth as any ) . execFn = ( command : string , opts : shell . ExecOpts ) : shell . ShellReturnValue => {
32+ optsOut = opts
33+ return {
34+ code : 0 ,
35+ stdout : JSON . stringify ( { status : { token : 'foo' } } )
36+ } as shell . ShellReturnValue ;
37+ } ;
38+ process . env . BLABBLE = 'flubble' ;
39+ const token = auth . getToken ( {
40+ name : 'user' ,
41+ authProvider : {
42+ config : {
43+ exec : {
44+ command : 'echo' ,
45+ env : [ {
46+ name : 'foo' ,
47+ value : 'bar'
48+ } ]
49+ }
50+ }
51+ }
52+ } ) ;
53+ expect ( optsOut . env . foo ) . to . equal ( 'bar' ) ;
54+ expect ( optsOut . env . PATH ) . to . equal ( process . env . PATH ) ;
55+ expect ( optsOut . env . BLABBLE ) . to . equal ( process . env . BLABBLE ) ;
56+ } ) ;
57+ } ) ;
You can’t perform that action at this time.
0 commit comments