From 2c0d264bdea7f8f9cc2811d182d06e930733928b Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Fri, 8 Jan 2021 00:31:46 +0100 Subject: [PATCH] test: false for isHTTPSRequest As suggested in https://github.com/ipfs/go-ipfs/pull/7847#discussion_r551933162 --- core/corehttp/hostname.go | 2 +- core/corehttp/hostname_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/corehttp/hostname.go b/core/corehttp/hostname.go index 7e2d07821c7..3ce1d08c26d 100644 --- a/core/corehttp/hostname.go +++ b/core/corehttp/hostname.go @@ -414,7 +414,7 @@ func toDNSLabel(rootID string, rootCID cid.Cid) (dnsCID string, err error) { } // Returns true if HTTP request involves TLS certificate. -// See https://github.com/ipfs/in-web-browsers/issues/169 to uderstand how it +// See https://github.com/ipfs/in-web-browsers/issues/169 to understand how it // impacts DNSLink websites on public gateways. func isHTTPSRequest(r *http.Request) bool { // X-Forwarded-Proto if added by a reverse proxy diff --git a/core/corehttp/hostname_test.go b/core/corehttp/hostname_test.go index f469a7720cd..3ece5e88f8f 100644 --- a/core/corehttp/hostname_test.go +++ b/core/corehttp/hostname_test.go @@ -106,6 +106,9 @@ func TestIsHTTPSRequest(t *testing.T) { httpsRequest := httptest.NewRequest("GET", "https://https-request-stub.example.com", nil) httpsProxiedRequest := httptest.NewRequest("GET", "http://proxied-https-request-stub.example.com", nil) httpsProxiedRequest.Header.Set("X-Forwarded-Proto", "https") + httpProxiedRequest := httptest.NewRequest("GET", "http://proxied-http-request-stub.example.com", nil) + httpProxiedRequest.Header.Set("X-Forwarded-Proto", "http") + oddballRequest := httptest.NewRequest("GET", "foo://127.0.0.1:8080", nil) for _, test := range []struct { in *http.Request out bool @@ -113,6 +116,8 @@ func TestIsHTTPSRequest(t *testing.T) { {httpRequest, false}, {httpsRequest, true}, {httpsProxiedRequest, true}, + {httpProxiedRequest, false}, + {oddballRequest, false}, } { out := isHTTPSRequest(test.in) if out != test.out {