@@ -233,6 +233,49 @@ describe('ExecAuth', () => {
233233 strictEqual ( opts . headers . Authorization , undefined ) ;
234234 } ) ;
235235
236+ it ( 'should handle returned errors correctly' , async ( ) => {
237+ const auth = new ExecAuth ( ) ;
238+ ( auth as any ) . execFn = (
239+ command : string ,
240+ args ?: readonly string [ ] ,
241+ options ?: child_process . SpawnOptionsWithoutStdio ,
242+ ) : child_process . ChildProcessWithoutNullStreams => {
243+ return {
244+ stdout : {
245+ setEncoding : ( ) => { } ,
246+ on : ( ) => { } ,
247+ } ,
248+ stderr : {
249+ setEncoding : ( ) => { } ,
250+ on : ( ) => { } ,
251+ } ,
252+ on : ( op : string , f : any ) => {
253+ if ( op === 'error' ) {
254+ f ( new Error ( 'Some error!' ) ) ;
255+ }
256+ if ( op === 'close' ) {
257+ f ( 1 ) ;
258+ }
259+ } ,
260+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
261+ } ;
262+ const user = {
263+ name : 'user' ,
264+ authProvider : {
265+ config : {
266+ exec : {
267+ command : '/path/to/bin' ,
268+ } ,
269+ } ,
270+ } ,
271+ } ;
272+ const opts = { } as https . RequestOptions ;
273+ opts . headers = { } as OutgoingHttpHeaders ;
274+
275+ const promise = auth . applyAuthentication ( user , opts ) ;
276+ await rejects ( promise , { name : 'Error' } ) ;
277+ } ) ;
278+
236279 it ( 'should throw on spawnSync errors' , async ( ) => {
237280 // TODO: fix this test for Windows
238281 if ( process . platform === 'win32' ) {
@@ -444,4 +487,54 @@ describe('ExecAuth', () => {
444487 ) ;
445488 strictEqual ( opts . headers ?. Authorization , 'Bearer foo' ) ;
446489 } ) ;
490+ it ( 'should handle null credentials correctly' , async ( ) => {
491+ const auth = new ExecAuth ( ) ;
492+ // Fake out Typescript
493+ const res = ( auth as any ) . getToken ( null ) ;
494+ strictEqual ( res , null ) ;
495+ } ) ;
496+
497+ it ( 'should handle parse errors correctly' , async ( ) => {
498+ const auth = new ExecAuth ( ) ;
499+ ( auth as any ) . execFn = (
500+ command : string ,
501+ args ?: readonly string [ ] ,
502+ options ?: child_process . SpawnOptionsWithoutStdio ,
503+ ) : child_process . ChildProcessWithoutNullStreams => {
504+ return {
505+ stdout : {
506+ setEncoding : ( ) => { } ,
507+ on : ( ) => { } ,
508+ } ,
509+ stderr : {
510+ setEncoding : ( ) => { } ,
511+ on : ( ) => { } ,
512+ } ,
513+ on : ( op : string , f : any ) => {
514+ if ( op === 'data' ) {
515+ // Invalid JSON
516+ f ( 'foo' ) ;
517+ }
518+ if ( op === 'close' ) {
519+ f ( 0 ) ;
520+ }
521+ } ,
522+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
523+ } ;
524+ const user = {
525+ name : 'user' ,
526+ authProvider : {
527+ config : {
528+ exec : {
529+ command : '/path/to/bin' ,
530+ } ,
531+ } ,
532+ } ,
533+ } ;
534+ const opts = { } as https . RequestOptions ;
535+ opts . headers = { } as OutgoingHttpHeaders ;
536+
537+ const promise = auth . applyAuthentication ( user , opts ) ;
538+ await rejects ( promise , { name : 'SyntaxError' } ) ;
539+ } ) ;
447540} ) ;
0 commit comments