@@ -43,7 +43,6 @@ static char *_github_ssh_privkey = NULL;
43
43
static char * _github_ssh_passphrase = NULL ;
44
44
static char * _github_ssh_remotehostkey = NULL ;
45
45
46
- static int _orig_proxies_need_reset = 0 ;
47
46
static char * _orig_http_proxy = NULL ;
48
47
static char * _orig_https_proxy = NULL ;
49
48
static char * _orig_no_proxy = NULL ;
@@ -99,10 +98,12 @@ void test_online_clone__initialize(void)
99
98
_github_ssh_passphrase = cl_getenv ("GITTEST_GITHUB_SSH_PASSPHRASE" );
100
99
_github_ssh_remotehostkey = cl_getenv ("GITTEST_GITHUB_SSH_REMOTE_HOSTKEY" );
101
100
101
+ _orig_http_proxy = cl_getenv ("HTTP_PROXY" );
102
+ _orig_https_proxy = cl_getenv ("HTTPS_PROXY" );
103
+ _orig_no_proxy = cl_getenv ("NO_PROXY" );
104
+
102
105
if (_remote_expectcontinue )
103
106
git_libgit2_opts (GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE , 1 );
104
-
105
- _orig_proxies_need_reset = 0 ;
106
107
}
107
108
108
109
void test_online_clone__cleanup (void )
@@ -140,15 +141,13 @@ void test_online_clone__cleanup(void)
140
141
git__free (_github_ssh_passphrase );
141
142
git__free (_github_ssh_remotehostkey );
142
143
143
- if (_orig_proxies_need_reset ) {
144
- cl_setenv ("HTTP_PROXY" , _orig_http_proxy );
145
- cl_setenv ("HTTPS_PROXY" , _orig_https_proxy );
146
- cl_setenv ("NO_PROXY" , _orig_no_proxy );
144
+ cl_setenv ("HTTP_PROXY" , _orig_http_proxy );
145
+ cl_setenv ("HTTPS_PROXY" , _orig_https_proxy );
146
+ cl_setenv ("NO_PROXY" , _orig_no_proxy );
147
147
148
- git__free (_orig_http_proxy );
149
- git__free (_orig_https_proxy );
150
- git__free (_orig_no_proxy );
151
- }
148
+ git__free (_orig_http_proxy );
149
+ git__free (_orig_https_proxy );
150
+ git__free (_orig_no_proxy );
152
151
153
152
git_libgit2_opts (GIT_OPT_SET_SSL_CERT_LOCATIONS , NULL , NULL );
154
153
git_libgit2_opts (GIT_OPT_SET_SERVER_TIMEOUT , 0 );
@@ -968,6 +967,79 @@ static int proxy_cert_cb(git_cert *cert, int valid, const char *host, void *payl
968
967
return valid ? 0 : GIT_ECERTIFICATE ;
969
968
}
970
969
970
+ void test_online_clone__proxy_http_host_port_in_opts (void )
971
+ {
972
+ if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass )
973
+ cl_skip ();
974
+
975
+ if (_remote_proxy_scheme && strcmp (_remote_proxy_scheme , "http" ) != 0 )
976
+ cl_skip ();
977
+
978
+ g_options .fetch_opts .proxy_opts .type = GIT_PROXY_SPECIFIED ;
979
+ g_options .fetch_opts .proxy_opts .url = _remote_proxy_host ;
980
+ g_options .fetch_opts .proxy_opts .credentials = proxy_cred_cb ;
981
+
982
+ called_proxy_creds = 0 ;
983
+ cl_git_pass (git_clone (& g_repo , "https://github.com/libgit2/TestGitRepository" , "./foo" , & g_options ));
984
+ cl_assert (called_proxy_creds == 1 );
985
+ }
986
+
987
+ void test_online_clone__proxy_http_host_port_in_env (void )
988
+ {
989
+ if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass )
990
+ cl_skip ();
991
+
992
+ if (_remote_proxy_scheme && strcmp (_remote_proxy_scheme , "http" ) != 0 )
993
+ cl_skip ();
994
+
995
+ cl_setenv ("HTTP_PROXY" , _remote_proxy_host );
996
+ cl_setenv ("HTTPS_PROXY" , _remote_proxy_host );
997
+ cl_setenv ("NO_PROXY" , NULL );
998
+
999
+ g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
1000
+ g_options .fetch_opts .proxy_opts .credentials = proxy_cred_cb ;
1001
+
1002
+ called_proxy_creds = 0 ;
1003
+ cl_git_pass (git_clone (& g_repo , "https://github.com/libgit2/TestGitRepository" , "./foo" , & g_options ));
1004
+ cl_assert (called_proxy_creds == 1 );
1005
+ }
1006
+
1007
+ static int repository_create_with_proxy (
1008
+ git_repository * * out ,
1009
+ const char * path ,
1010
+ int bare ,
1011
+ void * payload )
1012
+ {
1013
+ git_repository * repo ;
1014
+ git_config * config ;
1015
+ char * value = (char * )payload ;
1016
+
1017
+ cl_git_pass (git_repository_init (& repo , path , bare ));
1018
+ cl_git_pass (git_repository_config (& config , repo ));
1019
+
1020
+ cl_git_pass (git_config_set_string (config , "http.proxy" , value ));
1021
+
1022
+ git_config_free (config );
1023
+
1024
+ * out = repo ;
1025
+ return 0 ;
1026
+ }
1027
+
1028
+ void test_online_clone__proxy_http_host_port_in_config (void )
1029
+ {
1030
+ if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass )
1031
+ cl_skip ();
1032
+
1033
+ g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
1034
+ g_options .fetch_opts .proxy_opts .credentials = proxy_cred_cb ;
1035
+ g_options .repository_cb = repository_create_with_proxy ;
1036
+ g_options .repository_cb_payload = _remote_proxy_host ;
1037
+
1038
+ called_proxy_creds = 0 ;
1039
+ cl_git_pass (git_clone (& g_repo , "https://github.com/libgit2/TestGitRepository" , "./foo" , & g_options ));
1040
+ cl_assert (called_proxy_creds == 1 );
1041
+ }
1042
+
971
1043
void test_online_clone__proxy_invalid_url (void )
972
1044
{
973
1045
g_options .fetch_opts .proxy_opts .type = GIT_PROXY_SPECIFIED ;
@@ -1003,7 +1075,7 @@ void test_online_clone__proxy_credentials_request(void)
1003
1075
git_str_dispose (& url );
1004
1076
}
1005
1077
1006
- void test_online_clone__proxy_credentials_in_url (void )
1078
+ void test_online_clone__proxy_credentials_in_well_formed_url (void )
1007
1079
{
1008
1080
git_str url = GIT_STR_INIT ;
1009
1081
@@ -1024,17 +1096,35 @@ void test_online_clone__proxy_credentials_in_url(void)
1024
1096
git_str_dispose (& url );
1025
1097
}
1026
1098
1027
- void test_online_clone__proxy_credentials_in_environment (void )
1099
+ void test_online_clone__proxy_credentials_in_host_port_format (void )
1028
1100
{
1029
1101
git_str url = GIT_STR_INIT ;
1030
1102
1031
1103
if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass )
1032
1104
cl_skip ();
1033
1105
1034
- _orig_http_proxy = cl_getenv ("HTTP_PROXY" );
1035
- _orig_https_proxy = cl_getenv ("HTTPS_PROXY" );
1036
- _orig_no_proxy = cl_getenv ("NO_PROXY" );
1037
- _orig_proxies_need_reset = 1 ;
1106
+ if (_remote_proxy_scheme && strcmp (_remote_proxy_scheme , "http" ) != 0 )
1107
+ cl_skip ();
1108
+
1109
+ cl_git_pass (git_str_printf (& url , "%s:%s@%s" ,
1110
+ _remote_proxy_user , _remote_proxy_pass , _remote_proxy_host ));
1111
+
1112
+ g_options .fetch_opts .proxy_opts .type = GIT_PROXY_SPECIFIED ;
1113
+ g_options .fetch_opts .proxy_opts .url = url .ptr ;
1114
+ g_options .fetch_opts .proxy_opts .certificate_check = proxy_cert_cb ;
1115
+ called_proxy_creds = 0 ;
1116
+ cl_git_pass (git_clone (& g_repo , "http://github.com/libgit2/TestGitRepository" , "./foo" , & g_options ));
1117
+ cl_assert (called_proxy_creds == 0 );
1118
+
1119
+ git_str_dispose (& url );
1120
+ }
1121
+
1122
+ void test_online_clone__proxy_credentials_in_environment (void )
1123
+ {
1124
+ git_str url = GIT_STR_INIT ;
1125
+
1126
+ if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass )
1127
+ cl_skip ();
1038
1128
1039
1129
g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
1040
1130
g_options .fetch_opts .proxy_opts .certificate_check = proxy_cert_cb ;
0 commit comments