|
|
@@ -534,6 +534,73 @@ func TestRequestBuilder_AllowPrivateConfiguredProxy(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestRequestBuilder_AllowPrivateEnvironmentProxy(t *testing.T) {
|
|
|
+ configureFetcherAllowPrivateNetworksOption(t, "0")
|
|
|
+
|
|
|
+ targetURL := "http://feed.invalid/rss.xml"
|
|
|
+ proxyRequests := make(chan string, 1)
|
|
|
+ proxyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ select {
|
|
|
+ case proxyRequests <- r.URL.String():
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ w.WriteHeader(http.StatusOK)
|
|
|
+ }))
|
|
|
+ defer proxyServer.Close()
|
|
|
+
|
|
|
+ t.Setenv("HTTP_PROXY", proxyServer.URL)
|
|
|
+
|
|
|
+ resp, err := NewRequestBuilder().ExecuteRequest(targetURL)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Expected request through the environment proxy to succeed: %v", err)
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+
|
|
|
+ select {
|
|
|
+ case gotURL := <-proxyRequests:
|
|
|
+ if gotURL != targetURL {
|
|
|
+ t.Fatalf("Expected proxy request URL to be %q, got %q", targetURL, gotURL)
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ t.Fatal("Expected request to be sent through the environment proxy")
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func TestRequestBuilder_RefusePrivateNetworkWhenExcludedFromEnvironmentProxy(t *testing.T) {
|
|
|
+ configureFetcherAllowPrivateNetworksOption(t, "0")
|
|
|
+
|
|
|
+ privateServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ w.WriteHeader(http.StatusOK)
|
|
|
+ }))
|
|
|
+ defer privateServer.Close()
|
|
|
+
|
|
|
+ proxyRequests := make(chan string, 1)
|
|
|
+ proxyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ select {
|
|
|
+ case proxyRequests <- r.URL.String():
|
|
|
+ default:
|
|
|
+ }
|
|
|
+
|
|
|
+ w.WriteHeader(http.StatusOK)
|
|
|
+ }))
|
|
|
+ defer proxyServer.Close()
|
|
|
+
|
|
|
+ t.Setenv("HTTP_PROXY", proxyServer.URL)
|
|
|
+ t.Setenv("NO_PROXY", "feed.invalid")
|
|
|
+
|
|
|
+ _, err := NewRequestBuilder().ExecuteRequest("http://feed.invalid/rss.xml")
|
|
|
+ if err == nil {
|
|
|
+ t.Fatal("Expected request excluded from the environment proxy to fail")
|
|
|
+ }
|
|
|
+
|
|
|
+ select {
|
|
|
+ case gotURL := <-proxyRequests:
|
|
|
+ t.Fatalf("Expected request to bypass the environment proxy, but the proxy received %q", gotURL)
|
|
|
+ default:
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestRequestBuilder_RefusePrivateNetworkOnRedirect(t *testing.T) {
|
|
|
configureFetcherAllowPrivateNetworksOption(t, "0")
|
|
|
|