@@ -538,4 +538,63 @@ describe('ExecAuth', () => {
538
538
const promise = auth . applyAuthentication ( user , opts ) ;
539
539
await rejects ( promise , { name : 'SyntaxError' } ) ;
540
540
} ) ;
541
+
542
+ it ( 'should not overwrite environment variables in process.env' , async ( ) => {
543
+ // TODO: fix this test for Windows
544
+ if ( process . platform === 'win32' ) {
545
+ return ;
546
+ }
547
+ const auth = new ExecAuth ( ) ;
548
+ let optsOut : child_process . SpawnOptions | undefined = { } ;
549
+ ( auth as any ) . execFn = (
550
+ command : string ,
551
+ args ?: readonly string [ ] ,
552
+ options ?: child_process . SpawnOptionsWithoutStdio ,
553
+ ) : child_process . ChildProcessWithoutNullStreams => {
554
+ optsOut = options ;
555
+ return {
556
+ stdout : {
557
+ setEncoding : ( ) => { } ,
558
+ on : ( _data : string , f : ( data : Buffer | string ) => void ) => {
559
+ f ( Buffer . from ( JSON . stringify ( { status : { token : 'foo' } } ) ) ) ;
560
+ } ,
561
+ } ,
562
+ stderr : {
563
+ setEncoding : ( ) => { } ,
564
+ on : ( ) => { } ,
565
+ } ,
566
+ on : ( op : string , f : any ) => {
567
+ if ( op === 'close' ) {
568
+ f ( 0 ) ;
569
+ }
570
+ } ,
571
+ } as unknown as child_process . ChildProcessWithoutNullStreams ;
572
+ } ;
573
+
574
+ process . env . DO_NO_OVERWRITE_ME = 'important' ;
575
+ const opts = { } as https . RequestOptions ;
576
+ opts . headers = { } as OutgoingHttpHeaders ;
577
+
578
+ await auth . applyAuthentication (
579
+ {
580
+ name : 'user' ,
581
+ authProvider : {
582
+ config : {
583
+ exec : {
584
+ command : 'echo' ,
585
+ env : [
586
+ {
587
+ name : 'DO_NO_OVERWRITE_ME' ,
588
+ value : 'in exec' ,
589
+ } ,
590
+ ] ,
591
+ } ,
592
+ } ,
593
+ } ,
594
+ } ,
595
+ opts ,
596
+ ) ;
597
+ strictEqual ( optsOut . env ! . DO_NO_OVERWRITE_ME , 'in exec' ) ;
598
+ strictEqual ( process . env . DO_NO_OVERWRITE_ME , 'important' ) ;
599
+ } ) ;
541
600
} ) ;
0 commit comments