From eabd6a0ad4fe0bde0c344b0c3086c480b0b6bc4e Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 6 Sep 2018 11:00:17 -0700 Subject: [PATCH] improve gateway options test Unfortunately, this doesn't really test the *actual* gateway config as it uses the options specified by the test. However, it's a step in the right direction. License: MIT Signed-off-by: Steven Allen --- core/corehttp/gateway_test.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 211da131a3f..ebc312a0d1b 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -128,9 +128,9 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core dh.Handler, err = makeHandler(n, ts.Listener, - VersionOption(), IPNSHostnameOption(), GatewayOption(false, "/ipfs", "/ipns"), + VersionOption(), ) if err != nil { t.Fatal(err) @@ -290,6 +290,23 @@ func TestIPNSHostnameRedirect(t *testing.T) { } else if hdr[0] != "/good-prefix/foo/" { t.Errorf("location header is %v, expected /good-prefix/foo/", hdr[0]) } + + // make sure /version isn't exposed + req, err = http.NewRequest("GET", ts.URL+"/version", nil) + if err != nil { + t.Fatal(err) + } + req.Host = "example.net" + req.Header.Set("X-Ipfs-Gateway-Prefix", "/good-prefix") + + res, err = doWithoutRedirect(req) + if err != nil { + t.Fatal(err) + } + + if res.StatusCode != 404 { + t.Fatalf("expected a 404 error, got: %s", res.Status) + } } func TestIPNSHostnameBacklinks(t *testing.T) {