From 8b7432db827a0ede8e9bc81d1a2ba84f0a903ce6 Mon Sep 17 00:00:00 2001 From: Alex Schneider Date: Tue, 19 Jan 2021 10:27:49 +0100 Subject: [PATCH] More tests --- internal/test/test_backend.go | 3 + server/http_integration_test.go | 21 +++++ .../integration/endpoint_eval/12_couper.hcl | 80 ++++--------------- 3 files changed, 39 insertions(+), 65 deletions(-) diff --git a/internal/test/test_backend.go b/internal/test/test_backend.go index 6d296dc80..9d6242a09 100644 --- a/internal/test/test_backend.go +++ b/internal/test/test_backend.go @@ -75,6 +75,9 @@ func createAnythingHandler(status int) func(rw http.ResponseWriter, req *http.Re rw.Header().Set("Content-Length", strconv.Itoa(len(respContent))) rw.Header().Set("Content-Type", "application/json") + rw.Header().Set("Remove-Me-1", "r1") + rw.Header().Set("Remove-Me-2", "r2") + rw.WriteHeader(status) _, _ = rw.Write(respContent) } diff --git a/server/http_integration_test.go b/server/http_integration_test.go index 2b77abf5e..7ced2777b 100644 --- a/server/http_integration_test.go +++ b/server/http_integration_test.go @@ -713,6 +713,27 @@ func TestHTTPServer_RequestHeaders(t *testing.T) { res, err := client.Do(req) helper.Must(err) + if r1 := res.Header.Get("Remove-Me-1"); r1 != "" { + t.Errorf("Unexpected header %s", r1) + } + if r2 := res.Header.Get("Remove-Me-2"); r2 != "" { + t.Errorf("Unexpected header %s", r2) + } + + if s1 := res.Header.Get("Set-Me-1"); s1 != "s1" { + t.Errorf("Missing or invalid header Set-Me-1: %s", s1) + } + if s2 := res.Header.Get("Set-Me-2"); s2 != "s2" { + t.Errorf("Missing or invalid header Set-Me-2: %s", s2) + } + + if a1 := res.Header.Get("Add-Me-1"); a1 != "a1" { + t.Errorf("Missing or invalid header Add-Me-1: %s", a1) + } + if a2 := res.Header.Get("Add-Me-2"); a2 != "a2" { + t.Errorf("Missing or invalid header Add-Me-2: %s", a2) + } + resBytes, err := ioutil.ReadAll(res.Body) helper.Must(err) diff --git a/server/testdata/integration/endpoint_eval/12_couper.hcl b/server/testdata/integration/endpoint_eval/12_couper.hcl index 2d97419f2..6a313bd40 100644 --- a/server/testdata/integration/endpoint_eval/12_couper.hcl +++ b/server/testdata/integration/endpoint_eval/12_couper.hcl @@ -23,75 +23,17 @@ server "api" { aeb_empty = "" "${req.query.aeb[0]}" = "aeb" } - } - remove_request_headers = [ "ae_del" ] - set_request_headers = { - ae_string = "str" - ae_multi = ["str1", "str2"] - ae_a_and_b = "A&B" - ae_noop = req.headers.noop - ae_null = null - ae_empty = "" - xxx = "zzz" - "${req.query.ae[0]}" = "ae" - } - add_request_headers = { - ae_string = "str" - ae_multi = ["str3", "str4"] - ae_a_and_b = "A&B" - ae_noop = req.headers.noop - ae_null = null - ae_empty = "" - xxx = "ccc" - "${req.query.ae[0]}" = "ae" + remove_response_headers = [ "Remove-Me-2" ] + set_response_headers = { + "Set-Me-2" = "s2" + } + add_response_headers = { + "Add-Me-2" = "a2" + } } } } - -# TODO: free-endpoints -# endpoint "/free/endpoint" { -# backend { -# origin = "https://w11w.de" -# hostname = "w11w.de" - -# remove_request_headers = [ "feb_del" ] -# set_request_headers = { -# feb_string = "str" -# feb_multi = ["str1", "str2"] -# feb_a_and_b = "A&B" -# feb_noop = req.headers.noop -# feb_null = null -# feb_empty = "" -# } -# add_request_headers = { -# feb_string = "str" -# feb_multi = ["str3", "str4"] -# feb_a_and_b = "A&B" -# feb_noop = req.headers.noop -# feb_null = null -# feb_empty = "" -# } -# } - -# remove_request_headers = [ "fe_del" ] -# set_request_headers = { -# fe_String = "str" -# fe_multi = ["str1", "str2"] -# fe_a_and_b = "A&B" -# fe_noop = req.headers.noop -# fe_null = null -# fe_empty = "" -# } -# add_request_headers = { -# fe_String = "str" -# fe_multi = ["str3", "str4"] -# fe_a_and_b = "A&B" -# fe_noop = req.headers.noop -# fe_null = null -# fe_empty = "" -# } -# } } definitions { @@ -121,5 +63,13 @@ definitions { xxx = "eee" "${req.query.def[0]}" = "def" } + + remove_response_headers = [ "remove-me-1" ] + set_response_headers = { + "set-me-1" = "s1" + } + add_response_headers = { + "add-me-1" = "a1" + } } }