@@ -408,6 +408,107 @@ suite('CommandLineAutoApprover', () => {
408
408
ok ( ! isAutoApproved ( '[Get-Content' ) ) ;
409
409
ok ( ! isAutoApproved ( 'foo' ) ) ;
410
410
} ) ;
411
+
412
+ test ( 'should be case-insensitive for PowerShell commands' , ( ) => {
413
+ setAutoApprove ( {
414
+ "Get-ChildItem" : true ,
415
+ "Get-Content" : true ,
416
+ "Remove-Item" : false
417
+ } ) ;
418
+
419
+ // Test various case combinations for allowed commands
420
+ ok ( isAutoApproved ( 'Get-ChildItem' ) ) ;
421
+ ok ( isAutoApproved ( 'get-childitem' ) ) ;
422
+ ok ( isAutoApproved ( 'GET-CHILDITEM' ) ) ;
423
+ ok ( isAutoApproved ( 'Get-childitem' ) ) ;
424
+ ok ( isAutoApproved ( 'get-ChildItem' ) ) ;
425
+
426
+ ok ( isAutoApproved ( 'Get-Content file.txt' ) ) ;
427
+ ok ( isAutoApproved ( 'get-content file.txt' ) ) ;
428
+ ok ( isAutoApproved ( 'GET-CONTENT file.txt' ) ) ;
429
+ ok ( isAutoApproved ( 'Get-content file.txt' ) ) ;
430
+
431
+ // Test various case combinations for denied commands
432
+ ok ( ! isAutoApproved ( 'Remove-Item file.txt' ) ) ;
433
+ ok ( ! isAutoApproved ( 'remove-item file.txt' ) ) ;
434
+ ok ( ! isAutoApproved ( 'REMOVE-ITEM file.txt' ) ) ;
435
+ ok ( ! isAutoApproved ( 'Remove-item file.txt' ) ) ;
436
+ } ) ;
437
+
438
+ test ( 'should be case-insensitive for PowerShell aliases' , ( ) => {
439
+ setAutoApprove ( {
440
+ "ls" : true ,
441
+ "dir" : true ,
442
+ "rm" : false ,
443
+ "del" : false
444
+ } ) ;
445
+
446
+ // Test case-insensitive matching for aliases
447
+ ok ( isAutoApproved ( 'ls' ) ) ;
448
+ ok ( isAutoApproved ( 'LS' ) ) ;
449
+ ok ( isAutoApproved ( 'Ls' ) ) ;
450
+
451
+ ok ( isAutoApproved ( 'dir' ) ) ;
452
+ ok ( isAutoApproved ( 'DIR' ) ) ;
453
+ ok ( isAutoApproved ( 'Dir' ) ) ;
454
+
455
+ ok ( ! isAutoApproved ( 'rm file.txt' ) ) ;
456
+ ok ( ! isAutoApproved ( 'RM file.txt' ) ) ;
457
+ ok ( ! isAutoApproved ( 'Rm file.txt' ) ) ;
458
+
459
+ ok ( ! isAutoApproved ( 'del file.txt' ) ) ;
460
+ ok ( ! isAutoApproved ( 'DEL file.txt' ) ) ;
461
+ ok ( ! isAutoApproved ( 'Del file.txt' ) ) ;
462
+ } ) ;
463
+
464
+ test ( 'should be case-insensitive with regex patterns' , ( ) => {
465
+ setAutoApprove ( {
466
+ "/^Get-/" : true ,
467
+ "/Remove-Item|rm/" : false
468
+ } ) ;
469
+
470
+ // Test case-insensitive regex matching (should work even without 'i' flag in PowerShell)
471
+ ok ( isAutoApproved ( 'Get-ChildItem' ) ) ;
472
+ ok ( isAutoApproved ( 'get-childitem' ) ) ;
473
+ ok ( isAutoApproved ( 'GET-PROCESS' ) ) ;
474
+ ok ( isAutoApproved ( 'Get-Location' ) ) ;
475
+
476
+ ok ( ! isAutoApproved ( 'Remove-Item file.txt' ) ) ;
477
+ ok ( ! isAutoApproved ( 'remove-item file.txt' ) ) ;
478
+ ok ( ! isAutoApproved ( 'rm file.txt' ) ) ;
479
+ ok ( ! isAutoApproved ( 'RM file.txt' ) ) ;
480
+ } ) ;
481
+
482
+ test ( 'should handle case-insensitive PowerShell commands on different OS' , ( ) => {
483
+ setAutoApprove ( {
484
+ "Get-Process" : true ,
485
+ "Stop-Process" : false
486
+ } ) ;
487
+
488
+ // Test on Windows
489
+ os = OperatingSystem . Windows ;
490
+ ok ( isAutoApproved ( 'Get-Process' ) ) ;
491
+ ok ( isAutoApproved ( 'get-process' ) ) ;
492
+ ok ( isAutoApproved ( 'GET-PROCESS' ) ) ;
493
+ ok ( ! isAutoApproved ( 'Stop-Process' ) ) ;
494
+ ok ( ! isAutoApproved ( 'stop-process' ) ) ;
495
+
496
+ // Test on Linux (PowerShell Core)
497
+ os = OperatingSystem . Linux ;
498
+ ok ( isAutoApproved ( 'Get-Process' ) ) ;
499
+ ok ( isAutoApproved ( 'get-process' ) ) ;
500
+ ok ( isAutoApproved ( 'GET-PROCESS' ) ) ;
501
+ ok ( ! isAutoApproved ( 'Stop-Process' ) ) ;
502
+ ok ( ! isAutoApproved ( 'stop-process' ) ) ;
503
+
504
+ // Test on macOS (PowerShell Core)
505
+ os = OperatingSystem . Macintosh ;
506
+ ok ( isAutoApproved ( 'Get-Process' ) ) ;
507
+ ok ( isAutoApproved ( 'get-process' ) ) ;
508
+ ok ( isAutoApproved ( 'GET-PROCESS' ) ) ;
509
+ ok ( ! isAutoApproved ( 'Stop-Process' ) ) ;
510
+ ok ( ! isAutoApproved ( 'stop-process' ) ) ;
511
+ } ) ;
411
512
} ) ;
412
513
413
514
suite ( 'isCommandLineAutoApproved - matchCommandLine functionality' , ( ) => {
0 commit comments