Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Shushlin <vshushlin@gitlab.com>2019-08-21 19:00:52 +0300
committerNick Thomas <nick@gitlab.com>2019-08-21 19:00:52 +0300
commit8e390bd9884461ebd4e0663cba391a86a7b2ef5b (patch)
tree7855531881f831d884266e6a47a3b77ecfa6b750 /helpers_test.go
parentf8dabe33aee2931bcd060f7a13663eef0a0c8d9c (diff)
Fix https downgrade for pages behind proxy
We can't rely on r.TLS when pages are served behind proxy So we save https flag to a context for later usage Right now I'm trying to keep changes to a minimum since I'm planning to backport this to older versions That's why https flag is not refactored throughout the codebase The alternative way would be to use gorilla's proxy headers I'm planning to refactor to that version later
Diffstat (limited to 'helpers_test.go')
-rw-r--r--helpers_test.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/helpers_test.go b/helpers_test.go
index 61fa5279..ad7c65f1 100644
--- a/helpers_test.go
+++ b/helpers_test.go
@@ -314,15 +314,31 @@ func GetRedirectPage(t *testing.T, spec ListenSpec, host, urlsuffix string) (*ht
return GetRedirectPageWithCookie(t, spec, host, urlsuffix, "")
}
+func GetProxyRedirectPageWithCookie(t *testing.T, spec ListenSpec, host string, urlsuffix string, cookie string, https bool) (*http.Response, error) {
+ schema := "http"
+ if https {
+ schema = "https"
+ }
+ header := http.Header{
+ "X-Forwarded-Proto": []string{schema},
+ "X-Forwarded-Host": []string{host},
+ "cookie": []string{cookie},
+ }
+
+ return GetRedirectPageWithHeaders(t, spec, host, urlsuffix, header)
+}
+
func GetRedirectPageWithCookie(t *testing.T, spec ListenSpec, host, urlsuffix string, cookie string) (*http.Response, error) {
+ return GetRedirectPageWithHeaders(t, spec, host, urlsuffix, http.Header{"cookie": []string{cookie}})
+}
+
+func GetRedirectPageWithHeaders(t *testing.T, spec ListenSpec, host, urlsuffix string, header http.Header) (*http.Response, error) {
url := spec.URL(urlsuffix)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
- if cookie != "" {
- req.Header.Set("Cookie", cookie)
- }
+ req.Header = header
req.Host = host