@@ -129,7 +129,7 @@ suite('Attach to process - process provider', () => {
129129 assert . deepEqual ( attachItems , expectedOutput ) ;
130130 } ) ;
131131
132- test ( 'The Windows process list command should be called if the platform is Windows' , async ( ) => {
132+ test ( 'The Windows wmic process list command should be called if the platform is Windows when powershell has not been installed ' , async ( ) => {
133133 const windowsOutput = `CommandLine=\r
134134Name=System\r
135135ProcessId=4\r
@@ -171,13 +171,25 @@ ProcessId=5912\r
171171 } ,
172172 ] ;
173173 getOSTypeStub . returns ( platform . OSType . Windows ) ;
174+ const notFoundPowerShellOutput = 'INFO: Could not find files for the given pattern(s).\r\n' ;
175+ plainExecStub
176+ . withArgs ( 'where' , [ 'powershell' ] , sinon . match . any , sinon . match . any )
177+ . resolves ( { stderr : notFoundPowerShellOutput , stdout : '' } ) ;
174178 plainExecStub
175179 . withArgs ( WmicProcessParser . wmicCommand . command , sinon . match . any , sinon . match . any , sinon . match . any )
176180 . resolves ( { stdout : windowsOutput } ) ;
177181
178- const attachItems = await provider . _getInternalProcessEntries ( WmicProcessParser . wmicCommand ) ;
179- sinon . assert . calledOnceWithExactly (
180- plainExecStub ,
182+ const attachItems = await provider . _getInternalProcessEntries ( ) ;
183+ sinon . assert . calledTwice ( plainExecStub ) ;
184+ sinon . assert . calledWithExactly (
185+ plainExecStub . firstCall ,
186+ 'where' ,
187+ [ 'powershell' ] ,
188+ sinon . match . any ,
189+ sinon . match . any ,
190+ ) ;
191+ sinon . assert . calledWithExactly (
192+ plainExecStub . secondCall ,
181193 WmicProcessParser . wmicCommand . command ,
182194 WmicProcessParser . wmicCommand . args ,
183195 sinon . match . any ,
@@ -308,7 +320,7 @@ ProcessId=5912\r
308320 getOSTypeStub . returns ( platform . OSType . Windows ) ;
309321 } ) ;
310322
311- test ( 'Items returned by getAttachItems should be sorted alphabetically' , async ( ) => {
323+ test ( 'Items returned by getAttachItems should be sorted alphabetically with wmic ' , async ( ) => {
312324 const windowsOutput = `CommandLine=\r
313325Name=System\r
314326ProcessId=4\r
@@ -359,6 +371,69 @@ ProcessId=5728\r
359371 assert . deepEqual ( output , expectedOutput ) ;
360372 } ) ;
361373
374+ test ( 'Items returned by getAttachItems should be sorted alphabetically with powershell' , async ( ) => {
375+ const windowsProcesses = [
376+ {
377+ processId : 4 ,
378+ commandLine : null ,
379+ name : 'System' ,
380+ } ,
381+ {
382+ processId : 5372 ,
383+ commandLine : null ,
384+ name : 'svchost.exe' ,
385+ } ,
386+ {
387+ processId : 5728 ,
388+ commandLine : 'sihost.exe' ,
389+ name : 'sihost.exe' ,
390+ } ,
391+ ] ;
392+ const expectedOutput : IAttachItem [ ] = [
393+ {
394+ label : 'sihost.exe' ,
395+ description : '5728' ,
396+ detail : 'sihost.exe' ,
397+ id : '5728' ,
398+ processName : 'sihost.exe' ,
399+ commandLine : 'sihost.exe' ,
400+ } ,
401+ {
402+ label : 'svchost.exe' ,
403+ description : '5372' ,
404+ detail : '' ,
405+ id : '5372' ,
406+ processName : 'svchost.exe' ,
407+ commandLine : '' ,
408+ } ,
409+ {
410+ label : 'System' ,
411+ description : '4' ,
412+ detail : '' ,
413+ id : '4' ,
414+ processName : 'System' ,
415+ commandLine : '' ,
416+ } ,
417+ ] ;
418+ const foundPowerShellOutput = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\r\n' ;
419+ plainExecStub
420+ . withArgs ( 'where' , [ 'powershell' ] , sinon . match . any , sinon . match . any )
421+ . resolves ( { stderr : '' , stdout : foundPowerShellOutput } ) ;
422+ const windowsOutput = JSON . stringify ( windowsProcesses , null , 4 ) ;
423+ plainExecStub
424+ . withArgs (
425+ PowerShellProcessParser . powerShellCommand . command ,
426+ sinon . match . any ,
427+ sinon . match . any ,
428+ sinon . match . any ,
429+ )
430+ . resolves ( { stdout : windowsOutput } ) ;
431+
432+ const output = await provider . getAttachItems ( PowerShellProcessParser . powerShellCommand ) ;
433+
434+ assert . deepEqual ( output , expectedOutput ) ;
435+ } ) ;
436+
362437 test ( 'Python processes should be at the top of the list returned by getAttachItems with wmic' , async ( ) => {
363438 const windowsOutput = `CommandLine=\r
364439Name=System\r
@@ -556,5 +631,126 @@ ProcessId=8026\r
556631
557632 assert . deepEqual ( output , expectedOutput ) ;
558633 } ) ;
634+
635+ test ( 'The Windows powershell process list command should be called if the platform is Windows when powershell has been installed' , async ( ) => {
636+ const windowsProcesses = [
637+ {
638+ processId : 4 ,
639+ commandLine : null ,
640+ name : 'System' ,
641+ } ,
642+ {
643+ processId : 5372 ,
644+ commandLine : null ,
645+ name : 'svchost.exe' ,
646+ } ,
647+ {
648+ processId : 5728 ,
649+ commandLine : 'sihost.exe' ,
650+ name : 'sihost.exe' ,
651+ } ,
652+ {
653+ processId : 5912 ,
654+ commandLine : 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc' ,
655+ name : 'svchost.exe' ,
656+ } ,
657+ {
658+ processId : 6028 ,
659+ commandLine :
660+ 'C:\\Users\\ZA139\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py' ,
661+ name : 'python.exe' ,
662+ } ,
663+ {
664+ processId : 8026 ,
665+ commandLine :
666+ 'C:\\Users\\ZA139\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py' ,
667+ name : 'python.exe' ,
668+ } ,
669+ ] ;
670+ const windowsOutput = JSON . stringify ( windowsProcesses , null , 4 ) ;
671+ const expectedOutput : IAttachItem [ ] = [
672+ {
673+ label : 'python.exe' ,
674+ description : '8026' ,
675+ detail : 'C:\\Users\\ZA139\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py' ,
676+ id : '8026' ,
677+ processName : 'python.exe' ,
678+ commandLine :
679+ 'C:\\Users\\ZA139\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py' ,
680+ } ,
681+ {
682+ label : 'python.exe' ,
683+ description : '6028' ,
684+ detail : 'C:\\Users\\ZA139\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py' ,
685+ id : '6028' ,
686+ processName : 'python.exe' ,
687+ commandLine :
688+ 'C:\\Users\\ZA139\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py' ,
689+ } ,
690+ {
691+ label : 'sihost.exe' ,
692+ description : '5728' ,
693+ detail : 'sihost.exe' ,
694+ id : '5728' ,
695+ processName : 'sihost.exe' ,
696+ commandLine : 'sihost.exe' ,
697+ } ,
698+ {
699+ label : 'svchost.exe' ,
700+ description : '5372' ,
701+ detail : '' ,
702+ id : '5372' ,
703+ processName : 'svchost.exe' ,
704+ commandLine : '' ,
705+ } ,
706+ {
707+ label : 'svchost.exe' ,
708+ description : '5912' ,
709+ detail : 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc' ,
710+ id : '5912' ,
711+ processName : 'svchost.exe' ,
712+ commandLine : 'C:\\WINDOWS\\system32\\svchost.exe -k UnistackSvcGroup -s CDPUserSvc' ,
713+ } ,
714+ {
715+ label : 'System' ,
716+ description : '4' ,
717+ detail : '' ,
718+ id : '4' ,
719+ processName : 'System' ,
720+ commandLine : '' ,
721+ } ,
722+ ] ;
723+ getOSTypeStub . returns ( platform . OSType . Windows ) ;
724+ const foundPowerShellOutput = 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\r\n' ;
725+ plainExecStub
726+ . withArgs ( 'where' , [ 'powershell' ] , sinon . match . any , sinon . match . any )
727+ . resolves ( { stderr : '' , stdout : foundPowerShellOutput } ) ;
728+ plainExecStub
729+ . withArgs (
730+ PowerShellProcessParser . powerShellCommand . command ,
731+ sinon . match . any ,
732+ sinon . match . any ,
733+ sinon . match . any ,
734+ )
735+ . resolves ( { stdout : windowsOutput } ) ;
736+
737+ const output = await provider . getAttachItems ( ) ;
738+ sinon . assert . calledTwice ( plainExecStub ) ;
739+ sinon . assert . calledWithExactly (
740+ plainExecStub . firstCall ,
741+ 'where' ,
742+ [ 'powershell' ] ,
743+ sinon . match . any ,
744+ sinon . match . any ,
745+ ) ;
746+ sinon . assert . calledWithExactly (
747+ plainExecStub . secondCall ,
748+ PowerShellProcessParser . powerShellCommand . command ,
749+ PowerShellProcessParser . powerShellCommand . args ,
750+ sinon . match . any ,
751+ sinon . match . any ,
752+ ) ;
753+ assert . deepEqual ( output , expectedOutput ) ;
754+ } ) ;
559755 } ) ;
560756} ) ;
0 commit comments