@@ -788,8 +788,10 @@ public void Settings_ProxyConfiguration_Precedence_ReturnsValue()
788
788
// 2. Standard Git configuration
789
789
// http.proxy
790
790
// 3. cURL environment variables
791
+ // http_proxy
791
792
// HTTPS_PROXY
792
- // HTTP_PROXY
793
+ // http_proxy (note that uppercase HTTP_PROXY is not supported by libcurl)
794
+ // all_proxy
793
795
// ALL_PROXY
794
796
// 4. GCM proxy environment variable (deprecated)
795
797
// GCM_HTTP_PROXY
@@ -820,15 +822,71 @@ void RunTest(Uri expectedValue)
820
822
envars . Variables [ Constants . EnvironmentVariables . CurlHttpProxy ] = value2 . ToString ( ) ;
821
823
RunTest ( value2 ) ;
822
824
823
- // Test case 2: http.proxy > cURL environment variables
824
- string httpProxyKey = $ "{ Constants . GitConfiguration . Http . SectionName } .{ Constants . GitConfiguration . Http . Proxy } ";
825
- git . Configuration . Global [ httpProxyKey ] = new [ ] { value3 . ToString ( ) } ;
826
- RunTest ( value3 ) ;
825
+ // Test case 2: http.proxy > cURL environment variables
826
+ string httpProxyKey = $ "{ Constants . GitConfiguration . Http . SectionName } .{ Constants . GitConfiguration . Http . Proxy } ";
827
+ git . Configuration . Global [ httpProxyKey ] = new [ ] { value3 . ToString ( ) } ;
828
+ RunTest ( value3 ) ;
827
829
828
- // Test case 3: credential.httpProxy > http.proxy
829
- string credentialProxyKey = $ "{ Constants . GitConfiguration . Credential . SectionName } .{ Constants . GitConfiguration . Credential . HttpProxy } ";
830
- git . Configuration . Global [ credentialProxyKey ] = new [ ] { value4 . ToString ( ) } ;
831
- RunTest ( value4 ) ;
830
+ // Test case 3: credential.httpProxy > http.proxy
831
+ string credentialProxyKey = $ "{ Constants . GitConfiguration . Credential . SectionName } .{ Constants . GitConfiguration . Credential . HttpProxy } ";
832
+ git . Configuration . Global [ credentialProxyKey ] = new [ ] { value4 . ToString ( ) } ;
833
+ RunTest ( value4 ) ;
834
+ }
835
+
836
+ [ Fact ]
837
+ public void Settings_ProxyConfiguration_CurlEnvarPrecedence_PrefersLowercase ( )
838
+ {
839
+ // Expected precedence:
840
+ // https_proxy
841
+ // HTTPS_PROXY
842
+ // http_proxy (note that uppercase HTTP_PROXY is not supported by libcurl)
843
+ // all_proxy
844
+ // ALL_PROXY
845
+
846
+ const string remoteUrl = "https://example.com/foo.git" ;
847
+ var remoteUri = new Uri ( remoteUrl ) ;
848
+
849
+ var value1 = new Uri ( "http://proxy1.example.com" ) ;
850
+ var value2 = new Uri ( "http://proxy2.example.com" ) ;
851
+
852
+ // The differentiation between upper- and lowercase environment variables is not possible
853
+ // on some platforms (Windows) so force the comparer to case-sensitive in the test so we
854
+ // can run this on all platforms.
855
+ var envars = new TestEnvironment ( envarComparer : StringComparer . Ordinal ) ;
856
+ var git = new TestGit ( ) ;
857
+
858
+ void RunTest ( Uri expectedValue )
859
+ {
860
+ var settings = new Settings ( envars , git )
861
+ {
862
+ RemoteUri = remoteUri
863
+ } ;
864
+ ProxyConfiguration actualConfig = settings . GetProxyConfiguration ( ) ;
865
+ Assert . Equal ( expectedValue , actualConfig . Address ) ;
866
+ }
867
+
868
+ // Test case 1: https_proxy > HTTPS_PROXY
869
+ envars . Variables [ Constants . EnvironmentVariables . CurlHttpsProxy ] = value1 . ToString ( ) ;
870
+ envars . Variables [ Constants . EnvironmentVariables . CurlHttpsProxyUpper ] = value2 . ToString ( ) ;
871
+ RunTest ( value1 ) ;
872
+
873
+ // Test case 2a: https_proxy > http_proxy
874
+ envars . Variables . Clear ( ) ;
875
+ envars . Variables [ Constants . EnvironmentVariables . CurlHttpsProxy ] = value1 . ToString ( ) ;
876
+ envars . Variables [ Constants . EnvironmentVariables . CurlHttpProxy ] = value2 . ToString ( ) ;
877
+ RunTest ( value1 ) ;
878
+
879
+ // Test case 2b: HTTPS_PROXY > http_proxy
880
+ envars . Variables . Clear ( ) ;
881
+ envars . Variables [ Constants . EnvironmentVariables . CurlHttpsProxyUpper ] = value1 . ToString ( ) ;
882
+ envars . Variables [ Constants . EnvironmentVariables . CurlHttpProxy ] = value2 . ToString ( ) ;
883
+ RunTest ( value1 ) ;
884
+
885
+ // Test case 3: all_proxy > ALL_PROXY
886
+ envars . Variables . Clear ( ) ;
887
+ envars . Variables [ Constants . EnvironmentVariables . CurlAllProxy ] = value1 . ToString ( ) ;
888
+ envars . Variables [ Constants . EnvironmentVariables . CurlAllProxyUpper ] = value2 . ToString ( ) ;
889
+ RunTest ( value1 ) ;
832
890
}
833
891
834
892
[ Fact ]
0 commit comments