@@ -60,17 +60,28 @@ 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
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
69
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
70
+ } ,
71
+ } ,
72
+ stderr : {
73
+ on : ( ) => { } ,
74
+ } ,
75
+ on : ( op : string , f : any ) => {
76
+ if ( op === 'close' ) {
77
+ f ( 0 ) ;
78
+ }
79
+ } ,
80
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
70
81
} ;
71
82
const opts = { } as https . RequestOptions ;
72
83
opts . headers = { } as OutgoingHttpHeaders ;
73
- auth . applyAuthentication (
84
+ await auth . applyAuthentication (
74
85
{
75
86
name : 'user' ,
76
87
authProvider : {
@@ -94,15 +105,30 @@ describe('ExecAuth', () => {
94
105
const auth = new ExecAuth ( ) ;
95
106
( auth as any ) . execFn = (
96
107
command : string ,
97
- args : string [ ] ,
98
- opts : child_process . SpawnOptions ,
99
- ) : child_process . SpawnSyncReturns < Buffer > => {
108
+ args ?: readonly string [ ] ,
109
+ options ? : child_process . SpawnOptionsWithoutStdio ,
110
+ ) : child_process . ChildProcessWithoutNullStreams => {
100
111
return {
101
- status : 0 ,
102
- stdout : Buffer . from (
103
- JSON . stringify ( { status : { clientCertificateData : 'foo' , clientKeyData : 'bar' } } ) ,
104
- ) ,
105
- } as child_process . SpawnSyncReturns < Buffer > ;
112
+ stdout : {
113
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
114
+ f (
115
+ Buffer . from (
116
+ JSON . stringify ( {
117
+ status : { clientCertificateData : 'foo' , clientKeyData : 'bar' } ,
118
+ } ) ,
119
+ ) ,
120
+ ) ;
121
+ } ,
122
+ } ,
123
+ stderr : {
124
+ on : ( ) => { } ,
125
+ } ,
126
+ on : ( op : string , f : any ) => {
127
+ if ( op === 'close' ) {
128
+ f ( 0 ) ;
129
+ }
130
+ } ,
131
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
106
132
} ;
107
133
108
134
const user = {
@@ -119,7 +145,7 @@ describe('ExecAuth', () => {
119
145
opts . headers = { } as OutgoingHttpHeaders ;
120
146
opts . headers = { } as OutgoingHttpHeaders ;
121
147
122
- auth . applyAuthentication ( user , opts ) ;
148
+ await auth . applyAuthentication ( user , opts ) ;
123
149
expect ( opts . headers . Authorization ) . to . be . undefined ;
124
150
expect ( opts . cert ) . to . equal ( 'foo' ) ;
125
151
expect ( opts . key ) . to . equal ( 'bar' ) ;
@@ -136,18 +162,31 @@ describe('ExecAuth', () => {
136
162
var tokenValue = 'foo' ;
137
163
( auth as any ) . execFn = (
138
164
command : string ,
139
- args : string [ ] ,
140
- opts : child_process . SpawnOptions ,
141
- ) : child_process . SpawnSyncReturns < Buffer > => {
165
+ args ?: readonly string [ ] ,
166
+ options ? : child_process . SpawnOptionsWithoutStdio ,
167
+ ) : child_process . ChildProcessWithoutNullStreams => {
142
168
execCount ++ ;
143
169
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 > ;
170
+ stdout : {
171
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
172
+ f (
173
+ Buffer . from (
174
+ JSON . stringify ( {
175
+ status : { token : tokenValue , expirationTimestamp : expire } ,
176
+ } ) ,
177
+ ) ,
178
+ ) ;
179
+ } ,
180
+ } ,
181
+ stderr : {
182
+ on : ( ) => { } ,
183
+ } ,
184
+ on : ( op : string , f : any ) => {
185
+ if ( op === 'close' ) {
186
+ f ( 0 ) ;
187
+ }
188
+ } ,
189
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
151
190
} ;
152
191
153
192
const user = {
@@ -207,6 +246,26 @@ describe('ExecAuth', () => {
207
246
} as child_process . SpawnSyncReturns < Buffer > ;
208
247
} ;
209
248
249
+ ( auth as any ) . execFn = (
250
+ command : string ,
251
+ args ?: readonly string [ ] ,
252
+ options ?: child_process . SpawnOptionsWithoutStdio ,
253
+ ) : child_process . ChildProcessWithoutNullStreams => {
254
+ return {
255
+ stdout : {
256
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => { } ,
257
+ } ,
258
+ stderr : {
259
+ on : ( ) => { } ,
260
+ } ,
261
+ on : ( op : string , f : any ) => {
262
+ if ( op === 'error' ) {
263
+ throw new Error ( 'Error: spawnSync /path/to/bin ENOENT' ) ;
264
+ }
265
+ } ,
266
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
267
+ } ;
268
+
210
269
const user = {
211
270
name : 'user' ,
212
271
authProvider : {
@@ -230,16 +289,29 @@ describe('ExecAuth', () => {
230
289
return ;
231
290
}
232
291
const auth = new ExecAuth ( ) ;
292
+
233
293
( auth as any ) . execFn = (
234
294
command : string ,
235
- args : string [ ] ,
236
- opts : child_process . SpawnOptions ,
237
- ) : child_process . SpawnSyncReturns < Buffer > => {
295
+ args ?: readonly string [ ] ,
296
+ options ? : child_process . SpawnOptionsWithoutStdio ,
297
+ ) : child_process . ChildProcessWithoutNullStreams => {
238
298
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 > ;
299
+ stdout : {
300
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
301
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
302
+ } ,
303
+ } ,
304
+ stderr : {
305
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
306
+ f ( Buffer . from ( 'Some error!' ) ) ;
307
+ } ,
308
+ } ,
309
+ on : ( op : string , f : any ) => {
310
+ if ( op === 'close' ) {
311
+ f ( 100 ) ;
312
+ }
313
+ } ,
314
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
243
315
} ;
244
316
245
317
const user = {
@@ -265,18 +337,30 @@ describe('ExecAuth', () => {
265
337
return ;
266
338
}
267
339
const auth = new ExecAuth ( ) ;
268
- let optsOut : child_process . SpawnOptions = { } ;
340
+ let optsOut : child_process . SpawnOptions | undefined = { } ;
269
341
( auth as any ) . execFn = (
270
342
command : string ,
271
- args : string [ ] ,
272
- opts : child_process . SpawnOptions ,
273
- ) : child_process . SpawnSyncReturns < Buffer > => {
274
- optsOut = opts ;
343
+ args ?: readonly string [ ] ,
344
+ options ? : child_process . SpawnOptionsWithoutStdio ,
345
+ ) : child_process . ChildProcessWithoutNullStreams => {
346
+ optsOut = options ;
275
347
return {
276
- status : 0 ,
277
- stdout : Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ,
278
- } as child_process . SpawnSyncReturns < Buffer > ;
348
+ stdout : {
349
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
350
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
351
+ } ,
352
+ } ,
353
+ stderr : {
354
+ on : ( ) => { } ,
355
+ } ,
356
+ on : ( op : string , f : any ) => {
357
+ if ( op === 'close' ) {
358
+ f ( 0 ) ;
359
+ }
360
+ } ,
361
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
279
362
} ;
363
+
280
364
process . env . BLABBLE = 'flubble' ;
281
365
const opts = { } as https . RequestOptions ;
282
366
opts . headers = { } as OutgoingHttpHeaders ;
@@ -313,16 +397,28 @@ describe('ExecAuth', () => {
313
397
const auth = new ExecAuth ( ) ;
314
398
( auth as any ) . execFn = (
315
399
command : string ,
316
- args : string [ ] ,
317
- opts : child_process . SpawnOptions ,
318
- ) : child_process . SpawnSyncReturns < Buffer > => {
400
+ args ?: readonly string [ ] ,
401
+ options ? : child_process . SpawnOptionsWithoutStdio ,
402
+ ) : child_process . ChildProcessWithoutNullStreams => {
319
403
return {
320
- status : 0 ,
321
- stdout : Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ,
322
- } as child_process . SpawnSyncReturns < Buffer > ;
404
+ stdout : {
405
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
406
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
407
+ } ,
408
+ } ,
409
+ stderr : {
410
+ on : ( ) => { } ,
411
+ } ,
412
+ on : ( op : string , f : any ) => {
413
+ if ( op === 'close' ) {
414
+ f ( 0 ) ;
415
+ }
416
+ } ,
417
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
323
418
} ;
419
+
324
420
const opts = { } as https . RequestOptions ;
325
- auth . applyAuthentication (
421
+ await auth . applyAuthentication (
326
422
{
327
423
name : 'user' ,
328
424
authProvider : {
0 commit comments