@@ -36,6 +36,7 @@ static char *_remote_expectcontinue = NULL;
3636static int _orig_proxies_need_reset = 0 ;
3737static char * _orig_http_proxy = NULL ;
3838static char * _orig_https_proxy = NULL ;
39+ static char * _orig_no_proxy = NULL ;
3940
4041static int ssl_cert (git_cert * cert , int valid , const char * host , void * payload )
4142{
@@ -110,9 +111,11 @@ void test_online_clone__cleanup(void)
110111 if (_orig_proxies_need_reset ) {
111112 cl_setenv ("HTTP_PROXY" , _orig_http_proxy );
112113 cl_setenv ("HTTPS_PROXY" , _orig_https_proxy );
114+ cl_setenv ("NO_PROXY" , _orig_no_proxy );
113115
114116 git__free (_orig_http_proxy );
115117 git__free (_orig_https_proxy );
118+ git__free (_orig_no_proxy );
116119 }
117120
118121 git_libgit2_opts (GIT_OPT_SET_SSL_CERT_LOCATIONS , NULL , NULL );
@@ -854,6 +857,7 @@ void test_online_clone__proxy_credentials_in_environment(void)
854857
855858 _orig_http_proxy = cl_getenv ("HTTP_PROXY" );
856859 _orig_https_proxy = cl_getenv ("HTTPS_PROXY" );
860+ _orig_no_proxy = cl_getenv ("NO_PROXY" );
857861 _orig_proxies_need_reset = 1 ;
858862
859863 g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
@@ -865,6 +869,7 @@ void test_online_clone__proxy_credentials_in_environment(void)
865869
866870 cl_setenv ("HTTP_PROXY" , url .ptr );
867871 cl_setenv ("HTTPS_PROXY" , url .ptr );
872+ cl_setenv ("NO_PROXY" , NULL );
868873
869874 cl_git_pass (git_clone (& g_repo , "http://github.com/libgit2/TestGitRepository" , "./foo" , & g_options ));
870875
@@ -893,6 +898,67 @@ void test_online_clone__proxy_credentials_in_url_https(void)
893898 git_buf_dispose (& url );
894899}
895900
901+ struct no_proxy_test_entry {
902+ char no_proxy [128 ];
903+ bool bypass ;
904+ };
905+
906+ static struct no_proxy_test_entry no_proxy_test_entries [] = {
907+ {"*" , true},
908+ {"github.com" , true},
909+ {"github.com:443" , true},
910+ {"github.com:80" , false},
911+ {".github.com" , false},
912+ {"*.github.com" , false},
913+ {".com" , true},
914+ {"*.com" , true},
915+ {".com:443" , true},
916+ {"*.com:443" , true},
917+ {".com:80" , false},
918+ {"*.com:80" , false},
919+ {"" , false}
920+ };
921+
922+ void test_online_clone__no_proxy_in_environment (void )
923+ {
924+ int error = 0 ;
925+ unsigned int i ;
926+ git_buf proxy_url = GIT_BUF_INIT ;
927+
928+ _orig_http_proxy = cl_getenv ("HTTP_PROXY" );
929+ _orig_https_proxy = cl_getenv ("HTTPS_PROXY" );
930+ _orig_no_proxy = cl_getenv ("NO_PROXY" );
931+ _orig_proxies_need_reset = 1 ;
932+
933+ g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
934+ g_options .fetch_opts .proxy_opts .certificate_check = proxy_cert_cb ;
935+
936+ cl_git_pass (git_buf_printf (& proxy_url , "http://does-not-exists.example.org:1234/" ));
937+
938+ cl_setenv ("HTTP_PROXY" , proxy_url .ptr );
939+ cl_setenv ("HTTPS_PROXY" , proxy_url .ptr );
940+
941+
942+ for (i = 0 ; i < ARRAY_SIZE (no_proxy_test_entries ); ++ i ) {
943+ cl_setenv ("NO_PROXY" , no_proxy_test_entries [i ].no_proxy );
944+ error = git_clone (& g_repo , "https://github.com/libgit2/TestGitRepository" , "./foo" , & g_options );
945+
946+ if (no_proxy_test_entries [i ].bypass ) {
947+ cl_assert_ (error == 0 , no_proxy_test_entries [i ].no_proxy );
948+ } else {
949+ cl_assert_ (error == -1 , no_proxy_test_entries [i ].no_proxy );
950+ }
951+
952+ if (g_repo ) {
953+ git_repository_free (g_repo );
954+ g_repo = NULL ;
955+ }
956+ cl_fixture_cleanup ("./foo" );
957+ }
958+
959+ git_buf_dispose (& proxy_url );
960+ }
961+
896962void test_online_clone__proxy_auto_not_detected (void )
897963{
898964 g_options .fetch_opts .proxy_opts .type = GIT_PROXY_AUTO ;
0 commit comments