@@ -43,7 +43,6 @@ static char *_github_ssh_privkey = NULL;
4343static char * _github_ssh_passphrase = NULL ;
4444static char * _github_ssh_remotehostkey = NULL ;
4545
46- static int _orig_proxies_need_reset = 0 ;
4746static char * _orig_http_proxy = NULL ;
4847static char * _orig_https_proxy = NULL ;
4948static char * _orig_no_proxy = NULL ;
@@ -99,10 +98,12 @@ void test_online_clone__initialize(void)
9998 _github_ssh_passphrase = cl_getenv ("GITTEST_GITHUB_SSH_PASSPHRASE" );
10099 _github_ssh_remotehostkey = cl_getenv ("GITTEST_GITHUB_SSH_REMOTE_HOSTKEY" );
101100
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+
102105 if (_remote_expectcontinue )
103106 git_libgit2_opts (GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE , 1 );
104-
105- _orig_proxies_need_reset = 0 ;
106107}
107108
108109void test_online_clone__cleanup (void )
@@ -140,15 +141,13 @@ void test_online_clone__cleanup(void)
140141 git__free (_github_ssh_passphrase );
141142 git__free (_github_ssh_remotehostkey );
142143
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 );
147147
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 );
152151
153152 git_libgit2_opts (GIT_OPT_SET_SSL_CERT_LOCATIONS , NULL , NULL );
154153 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
968967 return valid ? 0 : GIT_ECERTIFICATE ;
969968}
970969
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+
9711043void test_online_clone__proxy_invalid_url (void )
9721044{
9731045 g_options .fetch_opts .proxy_opts .type = GIT_PROXY_SPECIFIED ;
@@ -1003,7 +1075,7 @@ void test_online_clone__proxy_credentials_request(void)
10031075 git_str_dispose (& url );
10041076}
10051077
1006- void test_online_clone__proxy_credentials_in_url (void )
1078+ void test_online_clone__proxy_credentials_in_well_formed_url (void )
10071079{
10081080 git_str url = GIT_STR_INIT ;
10091081
@@ -1024,17 +1096,35 @@ void test_online_clone__proxy_credentials_in_url(void)
10241096 git_str_dispose (& url );
10251097}
10261098
1027- void test_online_clone__proxy_credentials_in_environment (void )
1099+ void test_online_clone__proxy_credentials_in_host_port_format (void )
10281100{
10291101 git_str url = GIT_STR_INIT ;
10301102
10311103 if (!_remote_proxy_host || !_remote_proxy_user || !_remote_proxy_pass )
10321104 cl_skip ();
10331105
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 ();
10381128
10391129 g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
10401130 g_options .fetch_opts .proxy_opts .certificate_check = proxy_cert_cb ;
0 commit comments