1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
+ using System . Net ;
4
5
using GitCredentialManager . Tests . Objects ;
5
6
using Xunit ;
6
7
@@ -427,6 +428,57 @@ public void Settings_IsWindowsIntegratedAuthenticationEnabled_ConfigNonBooleanyV
427
428
Assert . True ( settings . IsWindowsIntegratedAuthenticationEnabled ) ;
428
429
}
429
430
431
+ [ Theory ]
432
+ [ InlineData ( "" , new string [ 0 ] ) ]
433
+ [ InlineData ( " " , new string [ 0 ] ) ]
434
+ [ InlineData ( "," , new string [ 0 ] ) ]
435
+ [ InlineData ( "example.com" , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
436
+ [ InlineData ( "example.com:8080" , new [ ] { @"(\.|\:\/\/)example\.com:8080$" } ) ]
437
+ [ InlineData ( "example.com," , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
438
+ [ InlineData ( ",example.com" , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
439
+ [ InlineData ( ",example.com," , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
440
+ [ InlineData ( ".example.com" , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
441
+ [ InlineData ( "..example.com" , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
442
+ [ InlineData ( "*.example.com" , new [ ] { @"(\.|\:\/\/)example\.com$" } ) ]
443
+ [ InlineData ( "my.example.com" , new [ ] { @"(\.|\:\/\/)my\.example\.com$" } ) ]
444
+ [ InlineData ( "example.com,contoso.com,fabrikam.com" , new [ ]
445
+ {
446
+ @"(\.|\:\/\/)example\.com$" ,
447
+ @"(\.|\:\/\/)contoso\.com$" ,
448
+ @"(\.|\:\/\/)fabrikam\.com$"
449
+ } ) ]
450
+ public void Settings_ProxyConfiguration_ConvertToBypassRegexArray ( string input , string [ ] expected )
451
+ {
452
+ string [ ] actual = ProxyConfiguration . ConvertToBypassRegexArray ( input ) . ToArray ( ) ;
453
+ Assert . Equal ( expected , actual ) ;
454
+ }
455
+
456
+ [ Theory ]
457
+ [ InlineData ( "example.com" , "http://example.com" , true ) ]
458
+ [ InlineData ( "example.com" , "https://example.com" , true ) ]
459
+ [ InlineData ( "example.com" , "https://www.example.com" , true ) ]
460
+ [ InlineData ( "example.com" , "http://www.example.com:80" , true ) ]
461
+ [ InlineData ( "example.com" , "https://www.example.com:443" , true ) ]
462
+ [ InlineData ( "example.com" , "https://www.example.com:8080" , false ) ]
463
+ [ InlineData ( "example.com" , "http://notanexample.com" , false ) ]
464
+ [ InlineData ( "example.com" , "https://notanexample.com" , false ) ]
465
+ [ InlineData ( "example.com" , "https://www.notanexample.com" , false ) ]
466
+ [ InlineData ( "example.com" , "https://example.com.otherltd" , false ) ]
467
+ [ InlineData ( "example.com:8080" , "http://example.com" , false ) ]
468
+ [ InlineData ( "my.example.com" , "http://example.com" , false ) ]
469
+ public void Settings_ProxyConfiguration_ConvertToBypassRegexArray_WebProxyBypass ( string noProxy , string address , bool expected )
470
+ {
471
+ var bypassList = ProxyConfiguration . ConvertToBypassRegexArray ( noProxy ) . ToArray ( ) ;
472
+ var webProxy = new WebProxy ( "https://localhost:8080/proxy" )
473
+ {
474
+ BypassList = bypassList
475
+ } ;
476
+
477
+ bool actual = webProxy . IsBypassed ( new Uri ( address ) ) ;
478
+
479
+ Assert . Equal ( expected , actual ) ;
480
+ }
481
+
430
482
[ Fact ]
431
483
public void Settings_ProxyConfiguration_Unset_ReturnsNull ( )
432
484
{
@@ -458,11 +510,11 @@ public void Settings_ProxyConfiguration_GcmHttpConfig_ReturnsValue()
458
510
const string expectedPassword = "letmein123" ;
459
511
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
460
512
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
461
- var bypassList = new List < string > { "contoso.com" , " fabrikam.com"} ;
513
+ var expectedNoProxy = "contoso.com, fabrikam.com" ;
462
514
463
515
var envars = new TestEnvironment
464
516
{
465
- Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList ) }
517
+ Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy }
466
518
} ;
467
519
var git = new TestGit ( ) ;
468
520
git . Configuration . Global [ $ "{ section } .{ property } "] = new [ ] { settingValue . ToString ( ) } ;
@@ -478,7 +530,7 @@ public void Settings_ProxyConfiguration_GcmHttpConfig_ReturnsValue()
478
530
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
479
531
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
480
532
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
481
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
533
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
482
534
Assert . True ( actualConfig . IsDeprecatedSource ) ;
483
535
}
484
536
@@ -494,11 +546,11 @@ public void Settings_ProxyConfiguration_GcmHttpsConfig_ReturnsValue()
494
546
const string expectedPassword = "letmein123" ;
495
547
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
496
548
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
497
- var bypassList = new List < string > { "contoso.com" , " fabrikam.com"} ;
549
+ var expectedNoProxy = "contoso.com, fabrikam.com" ;
498
550
499
551
var envars = new TestEnvironment
500
552
{
501
- Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList ) }
553
+ Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy }
502
554
} ;
503
555
var git = new TestGit ( ) ;
504
556
git . Configuration . Global [ $ "{ section } .{ property } "] = new [ ] { settingValue . ToString ( ) } ;
@@ -514,7 +566,7 @@ public void Settings_ProxyConfiguration_GcmHttpsConfig_ReturnsValue()
514
566
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
515
567
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
516
568
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
517
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
569
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
518
570
Assert . True ( actualConfig . IsDeprecatedSource ) ;
519
571
}
520
572
@@ -530,11 +582,11 @@ public void Settings_ProxyConfiguration_GitHttpConfig_ReturnsValue()
530
582
const string expectedPassword = "letmein123" ;
531
583
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
532
584
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
533
- var bypassList = new List < string > { "contoso.com" , " fabrikam.com"} ;
585
+ var expectedNoProxy = "contoso.com, fabrikam.com" ;
534
586
535
587
var envars = new TestEnvironment
536
588
{
537
- Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList ) }
589
+ Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy }
538
590
} ;
539
591
var git = new TestGit ( ) ;
540
592
git . Configuration . Global [ $ "{ section } .{ property } "] = new [ ] { settingValue . ToString ( ) } ;
@@ -550,7 +602,7 @@ public void Settings_ProxyConfiguration_GitHttpConfig_ReturnsValue()
550
602
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
551
603
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
552
604
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
553
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
605
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
554
606
Assert . False ( actualConfig . IsDeprecatedSource ) ;
555
607
}
556
608
@@ -579,42 +631,6 @@ public void Settings_ProxyConfiguration_GitHttpConfig_EmptyScopedUriUnscoped_Ret
579
631
Assert . Null ( actualConfig ) ;
580
632
}
581
633
582
- [ Fact ]
583
- public void Settings_ProxyConfiguration_NoProxyMixedSplitChar_ReturnsValue ( )
584
- {
585
- const string remoteUrl = "http://example.com/foo.git" ;
586
- const string section = Constants . GitConfiguration . Http . SectionName ;
587
- const string property = Constants . GitConfiguration . Http . Proxy ;
588
- var remoteUri = new Uri ( remoteUrl ) ;
589
-
590
- const string expectedUserName = "john.doe" ;
591
- const string expectedPassword = "letmein123" ;
592
- var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
593
- var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
594
- var bypassList = new List < string > { "contoso.com" , "fabrikam.com" , "example.com" } ;
595
-
596
- var envars = new TestEnvironment
597
- {
598
- Variables = { [ Constants . EnvironmentVariables . CurlNoProxy ] = "contoso.com, fabrikam.com example.com," }
599
- } ;
600
- var git = new TestGit ( ) ;
601
- git . Configuration . Global [ $ "{ section } .{ property } "] = new [ ] { settingValue . ToString ( ) } ;
602
-
603
- var settings = new Settings ( envars , git )
604
- {
605
- RemoteUri = remoteUri
606
- } ;
607
-
608
- ProxyConfiguration actualConfig = settings . GetProxyConfiguration ( ) ;
609
-
610
- Assert . NotNull ( actualConfig ) ;
611
- Assert . Equal ( expectedAddress , actualConfig . Address ) ;
612
- Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
613
- Assert . Equal ( expectedPassword , actualConfig . Password ) ;
614
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
615
- Assert . False ( actualConfig . IsDeprecatedSource ) ;
616
- }
617
-
618
634
[ Fact ]
619
635
public void Settings_ProxyConfiguration_CurlHttpEnvar_ReturnsValue ( )
620
636
{
@@ -625,14 +641,14 @@ public void Settings_ProxyConfiguration_CurlHttpEnvar_ReturnsValue()
625
641
const string expectedPassword = "letmein123" ;
626
642
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
627
643
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
628
- var bypassList = new List < string > { "contoso.com" , " fabrikam.com"} ;
644
+ var expectedNoProxy = "contoso.com, fabrikam.com" ;
629
645
630
646
var envars = new TestEnvironment
631
647
{
632
648
Variables =
633
649
{
634
650
[ Constants . EnvironmentVariables . CurlHttpProxy ] = settingValue . ToString ( ) ,
635
- [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList )
651
+ [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy
636
652
}
637
653
} ;
638
654
var git = new TestGit ( ) ;
@@ -648,7 +664,7 @@ public void Settings_ProxyConfiguration_CurlHttpEnvar_ReturnsValue()
648
664
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
649
665
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
650
666
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
651
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
667
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
652
668
Assert . False ( actualConfig . IsDeprecatedSource ) ;
653
669
}
654
670
@@ -662,14 +678,14 @@ public void Settings_ProxyConfiguration_CurlHttpsEnvar_ReturnsValue()
662
678
const string expectedPassword = "letmein123" ;
663
679
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
664
680
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
665
- var bypassList = new List < string > { "contoso.com" , " fabrikam.com"} ;
681
+ var expectedNoProxy = "contoso.com, fabrikam.com" ;
666
682
667
683
var envars = new TestEnvironment
668
684
{
669
685
Variables =
670
686
{
671
687
[ Constants . EnvironmentVariables . CurlHttpsProxy ] = settingValue . ToString ( ) ,
672
- [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList )
688
+ [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy
673
689
}
674
690
} ;
675
691
var git = new TestGit ( ) ;
@@ -685,7 +701,7 @@ public void Settings_ProxyConfiguration_CurlHttpsEnvar_ReturnsValue()
685
701
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
686
702
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
687
703
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
688
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
704
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
689
705
Assert . False ( actualConfig . IsDeprecatedSource ) ;
690
706
}
691
707
@@ -699,14 +715,14 @@ public void Settings_TryGetProxy_CurlAllEnvar_ReturnsValue()
699
715
const string expectedPassword = "letmein123" ;
700
716
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
701
717
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
702
- var bypassList = new List < string > { "contoso.com" , " fabrikam.com"} ;
718
+ var expectedNoProxy = "contoso.com, fabrikam.com" ;
703
719
704
720
var envars = new TestEnvironment
705
721
{
706
722
Variables =
707
723
{
708
724
[ Constants . EnvironmentVariables . CurlAllProxy ] = settingValue . ToString ( ) ,
709
- [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList )
725
+ [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy
710
726
}
711
727
} ;
712
728
var git = new TestGit ( ) ;
@@ -722,7 +738,7 @@ public void Settings_TryGetProxy_CurlAllEnvar_ReturnsValue()
722
738
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
723
739
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
724
740
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
725
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
741
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
726
742
Assert . False ( actualConfig . IsDeprecatedSource ) ;
727
743
}
728
744
@@ -736,14 +752,14 @@ public void Settings_ProxyConfiguration_LegacyGcmEnvar_ReturnsValue()
736
752
const string expectedPassword = "letmein123" ;
737
753
var expectedAddress = new Uri ( "http://proxy.example.com" ) ;
738
754
var settingValue = new Uri ( "http://john.doe:[email protected] " ) ;
739
- var bypassList = new List < string > { "https:// contoso.com" , ".* fabrikam\\ .com"} ;
755
+ var expectedNoProxy = " contoso.com, fabrikam.com";
740
756
741
757
var envars = new TestEnvironment
742
758
{
743
759
Variables =
744
760
{
745
761
[ Constants . EnvironmentVariables . GcmHttpProxy ] = settingValue . ToString ( ) ,
746
- [ Constants . EnvironmentVariables . CurlNoProxy ] = string . Join ( ',' , bypassList )
762
+ [ Constants . EnvironmentVariables . CurlNoProxy ] = expectedNoProxy
747
763
}
748
764
} ;
749
765
var git = new TestGit ( ) ;
@@ -759,7 +775,7 @@ public void Settings_ProxyConfiguration_LegacyGcmEnvar_ReturnsValue()
759
775
Assert . Equal ( expectedAddress , actualConfig . Address ) ;
760
776
Assert . Equal ( expectedUserName , actualConfig . UserName ) ;
761
777
Assert . Equal ( expectedPassword , actualConfig . Password ) ;
762
- Assert . Equal ( bypassList , actualConfig . BypassHosts ) ;
778
+ Assert . Equal ( expectedNoProxy , actualConfig . NoProxyRaw ) ;
763
779
Assert . True ( actualConfig . IsDeprecatedSource ) ;
764
780
}
765
781
0 commit comments