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