@@ -60,17 +60,30 @@ describe('ExecAuth', () => {
60
60
const auth = new ExecAuth ( ) ;
61
61
( auth as any ) . execFn = (
62
62
command : string ,
63
- args : string [ ] ,
64
- opts : child_process . SpawnOptions ,
65
- ) : child_process . SpawnSyncReturns < Buffer > => {
63
+ args ?: readonly string [ ] ,
64
+ options ? : child_process . SpawnOptionsWithoutStdio ,
65
+ ) : child_process . ChildProcessWithoutNullStreams => {
66
66
return {
67
- status : 0 ,
68
- stdout : Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ,
69
- } as child_process . SpawnSyncReturns < Buffer > ;
67
+ stdout : {
68
+ setEncoding : ( ) => { } ,
69
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
70
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
71
+ } ,
72
+ } ,
73
+ stderr : {
74
+ setEncoding : ( ) => { } ,
75
+ on : ( ) => { } ,
76
+ } ,
77
+ on : ( op : string , f : any ) => {
78
+ if ( op === 'close' ) {
79
+ f ( 0 ) ;
80
+ }
81
+ } ,
82
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
70
83
} ;
71
84
const opts = { } as https . RequestOptions ;
72
85
opts . headers = { } as OutgoingHttpHeaders ;
73
- auth . applyAuthentication (
86
+ await auth . applyAuthentication (
74
87
{
75
88
name : 'user' ,
76
89
authProvider : {
@@ -94,15 +107,32 @@ describe('ExecAuth', () => {
94
107
const auth = new ExecAuth ( ) ;
95
108
( auth as any ) . execFn = (
96
109
command : string ,
97
- args : string [ ] ,
98
- opts : child_process . SpawnOptions ,
99
- ) : child_process . SpawnSyncReturns < Buffer > => {
110
+ args ?: readonly string [ ] ,
111
+ options ? : child_process . SpawnOptionsWithoutStdio ,
112
+ ) : child_process . ChildProcessWithoutNullStreams => {
100
113
return {
101
- status : 0 ,
102
- stdout : Buffer . from (
103
- JSON . stringify ( { status : { clientCertificateData : 'foo' , clientKeyData : 'bar' } } ) ,
104
- ) ,
105
- } as child_process . SpawnSyncReturns < Buffer > ;
114
+ stdout : {
115
+ setEncoding : ( ) => { } ,
116
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
117
+ f (
118
+ Buffer . from (
119
+ JSON . stringify ( {
120
+ status : { clientCertificateData : 'foo' , clientKeyData : 'bar' } ,
121
+ } ) ,
122
+ ) ,
123
+ ) ;
124
+ } ,
125
+ } ,
126
+ stderr : {
127
+ setEncoding : ( ) => { } ,
128
+ on : ( ) => { } ,
129
+ } ,
130
+ on : ( op : string , f : any ) => {
131
+ if ( op === 'close' ) {
132
+ f ( 0 ) ;
133
+ }
134
+ } ,
135
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
106
136
} ;
107
137
108
138
const user = {
@@ -119,7 +149,7 @@ describe('ExecAuth', () => {
119
149
opts . headers = { } as OutgoingHttpHeaders ;
120
150
opts . headers = { } as OutgoingHttpHeaders ;
121
151
122
- auth . applyAuthentication ( user , opts ) ;
152
+ await auth . applyAuthentication ( user , opts ) ;
123
153
expect ( opts . headers . Authorization ) . to . be . undefined ;
124
154
expect ( opts . cert ) . to . equal ( 'foo' ) ;
125
155
expect ( opts . key ) . to . equal ( 'bar' ) ;
@@ -136,18 +166,33 @@ describe('ExecAuth', () => {
136
166
var tokenValue = 'foo' ;
137
167
( auth as any ) . execFn = (
138
168
command : string ,
139
- args : string [ ] ,
140
- opts : child_process . SpawnOptions ,
141
- ) : child_process . SpawnSyncReturns < Buffer > => {
169
+ args ?: readonly string [ ] ,
170
+ options ? : child_process . SpawnOptionsWithoutStdio ,
171
+ ) : child_process . ChildProcessWithoutNullStreams => {
142
172
execCount ++ ;
143
173
return {
144
- status : 0 ,
145
- stdout : Buffer . from (
146
- JSON . stringify ( {
147
- status : { token : tokenValue , expirationTimestamp : expire } ,
148
- } ) ,
149
- ) ,
150
- } as child_process . SpawnSyncReturns < Buffer > ;
174
+ stdout : {
175
+ setEncoding : ( ) => { } ,
176
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
177
+ f (
178
+ Buffer . from (
179
+ JSON . stringify ( {
180
+ status : { token : tokenValue , expirationTimestamp : expire } ,
181
+ } ) ,
182
+ ) ,
183
+ ) ;
184
+ } ,
185
+ } ,
186
+ stderr : {
187
+ setEncoding : ( ) => { } ,
188
+ on : ( ) => { } ,
189
+ } ,
190
+ on : ( op : string , f : any ) => {
191
+ if ( op === 'close' ) {
192
+ f ( 0 ) ;
193
+ }
194
+ } ,
195
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
151
196
} ;
152
197
153
198
const user = {
@@ -207,6 +252,28 @@ describe('ExecAuth', () => {
207
252
} as child_process . SpawnSyncReturns < Buffer > ;
208
253
} ;
209
254
255
+ ( auth as any ) . execFn = (
256
+ command : string ,
257
+ args ?: readonly string [ ] ,
258
+ options ?: child_process . SpawnOptionsWithoutStdio ,
259
+ ) : child_process . ChildProcessWithoutNullStreams => {
260
+ return {
261
+ stdout : {
262
+ setEncoding : ( ) => { } ,
263
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => { } ,
264
+ } ,
265
+ stderr : {
266
+ setEncoding : ( ) => { } ,
267
+ on : ( ) => { } ,
268
+ } ,
269
+ on : ( op : string , f : any ) => {
270
+ if ( op === 'error' ) {
271
+ throw new Error ( 'Error: spawnSync /path/to/bin ENOENT' ) ;
272
+ }
273
+ } ,
274
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
275
+ } ;
276
+
210
277
const user = {
211
278
name : 'user' ,
212
279
authProvider : {
@@ -230,16 +297,31 @@ describe('ExecAuth', () => {
230
297
return ;
231
298
}
232
299
const auth = new ExecAuth ( ) ;
300
+
233
301
( auth as any ) . execFn = (
234
302
command : string ,
235
- args : string [ ] ,
236
- opts : child_process . SpawnOptions ,
237
- ) : child_process . SpawnSyncReturns < Buffer > => {
303
+ args ?: readonly string [ ] ,
304
+ options ? : child_process . SpawnOptionsWithoutStdio ,
305
+ ) : child_process . ChildProcessWithoutNullStreams => {
238
306
return {
239
- status : 100 ,
240
- stdout : Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ,
241
- stderr : Buffer . from ( 'Some error!' ) ,
242
- } as child_process . SpawnSyncReturns < Buffer > ;
307
+ stdout : {
308
+ setEncoding : ( ) => { } ,
309
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
310
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
311
+ } ,
312
+ } ,
313
+ stderr : {
314
+ setEncoding : ( ) => { } ,
315
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
316
+ f ( Buffer . from ( 'Some error!' ) ) ;
317
+ } ,
318
+ } ,
319
+ on : ( op : string , f : any ) => {
320
+ if ( op === 'close' ) {
321
+ f ( 100 ) ;
322
+ }
323
+ } ,
324
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
243
325
} ;
244
326
245
327
const user = {
@@ -265,18 +347,32 @@ describe('ExecAuth', () => {
265
347
return ;
266
348
}
267
349
const auth = new ExecAuth ( ) ;
268
- let optsOut : child_process . SpawnOptions = { } ;
350
+ let optsOut : child_process . SpawnOptions | undefined = { } ;
269
351
( auth as any ) . execFn = (
270
352
command : string ,
271
- args : string [ ] ,
272
- opts : child_process . SpawnOptions ,
273
- ) : child_process . SpawnSyncReturns < Buffer > => {
274
- optsOut = opts ;
353
+ args ?: readonly string [ ] ,
354
+ options ? : child_process . SpawnOptionsWithoutStdio ,
355
+ ) : child_process . ChildProcessWithoutNullStreams => {
356
+ optsOut = options ;
275
357
return {
276
- status : 0 ,
277
- stdout : Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ,
278
- } as child_process . SpawnSyncReturns < Buffer > ;
358
+ stdout : {
359
+ setEncoding : ( ) => { } ,
360
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
361
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
362
+ } ,
363
+ } ,
364
+ stderr : {
365
+ setEncoding : ( ) => { } ,
366
+ on : ( ) => { } ,
367
+ } ,
368
+ on : ( op : string , f : any ) => {
369
+ if ( op === 'close' ) {
370
+ f ( 0 ) ;
371
+ }
372
+ } ,
373
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
279
374
} ;
375
+
280
376
process . env . BLABBLE = 'flubble' ;
281
377
const opts = { } as https . RequestOptions ;
282
378
opts . headers = { } as OutgoingHttpHeaders ;
@@ -313,16 +409,30 @@ describe('ExecAuth', () => {
313
409
const auth = new ExecAuth ( ) ;
314
410
( auth as any ) . execFn = (
315
411
command : string ,
316
- args : string [ ] ,
317
- opts : child_process . SpawnOptions ,
318
- ) : child_process . SpawnSyncReturns < Buffer > => {
412
+ args ?: readonly string [ ] ,
413
+ options ? : child_process . SpawnOptionsWithoutStdio ,
414
+ ) : child_process . ChildProcessWithoutNullStreams => {
319
415
return {
320
- status : 0 ,
321
- stdout : Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ,
322
- } as child_process . SpawnSyncReturns < Buffer > ;
416
+ stdout : {
417
+ setEncoding : ( ) => { } ,
418
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
419
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
420
+ } ,
421
+ } ,
422
+ stderr : {
423
+ setEncoding : ( ) => { } ,
424
+ on : ( ) => { } ,
425
+ } ,
426
+ on : ( op : string , f : any ) => {
427
+ if ( op === 'close' ) {
428
+ f ( 0 ) ;
429
+ }
430
+ } ,
431
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
323
432
} ;
433
+
324
434
const opts = { } as https . RequestOptions ;
325
- auth . applyAuthentication (
435
+ await auth . applyAuthentication (
326
436
{
327
437
name : 'user' ,
328
438
authProvider : {
0 commit comments