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:
authorJaime Martinez <jmartinez@gitlab.com>2020-05-28 11:07:03 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-07-06 02:13:51 +0300
commit4f82a5659cfcec5e7782b80f0d551353cbdcc1dc (patch)
tree0b9ccdfa09a1cbf932dfd23d26506b3096ccd285 /acceptance_test.go
parentfb2c26ff998b809baddeb9618aae52c49200bc8b (diff)
Get namespace domain if auth fails for a private domain
Add acceptance test and some more domains for testing Move namespace domain serving logic Restore go.sum Remove redundant return Fix linter
Diffstat (limited to 'acceptance_test.go')
-rw-r--r--acceptance_test.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/acceptance_test.go b/acceptance_test.go
index 0ba5d18f..ada77682 100644
--- a/acceptance_test.go
+++ b/acceptance_test.go
@@ -1206,6 +1206,101 @@ func TestAccessControlUnderCustomDomain(t *testing.T) {
require.Equal(t, http.StatusOK, authrsp.StatusCode)
}
+func TestCustomErrorPageWithAuth(t *testing.T) {
+ skipUnlessEnabled(t, "not-inplace-chroot")
+ testServer := makeGitLabPagesAccessStub(t)
+ testServer.Start()
+ defer testServer.Close()
+
+ teardown := RunPagesProcessWithAuthServer(t, *pagesBinary, listeners, "", testServer.URL)
+ defer teardown()
+
+ tests := []struct {
+ name string
+ domain string
+ path string
+ expectedErrorPage string
+ }{
+ {
+ name: "private_project_authorized",
+ domain: "group.404.gitlab-example.com",
+ path: "/private_project/unknown",
+ expectedErrorPage: "Private custom 404 error page",
+ },
+ {
+ name: "public_namespace_with_private_unauthorized_project",
+ domain: "group.404.gitlab-example.com",
+ path: "/private_unauthorized/unknown",
+ expectedErrorPage: "Custom 404 group page",
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ domain := tt.domain
+ path := tt.path
+ rsp, err := GetRedirectPage(t, httpListener, domain, path)
+ require.NoError(t, err)
+ defer rsp.Body.Close()
+
+ cookie := rsp.Header.Get("Set-Cookie")
+
+ url, err := url.Parse(rsp.Header.Get("Location"))
+ require.NoError(t, err)
+
+ state := url.Query().Get("state")
+ require.Equal(t, "http://"+domain, url.Query().Get("domain"))
+
+ pagesrsp, err := GetRedirectPage(t, httpListener, url.Host, url.Path+"?"+url.RawQuery)
+ require.NoError(t, err)
+ defer pagesrsp.Body.Close()
+
+ pagescookie := pagesrsp.Header.Get("Set-Cookie")
+
+ // Go to auth page with correct state will cause fetching the token
+ authrsp, err := GetRedirectPageWithCookie(t, httpListener, "projects.gitlab-example.com", "/auth?code=1&state="+
+ state, pagescookie)
+
+ require.NoError(t, err)
+ defer authrsp.Body.Close()
+
+ url, err = url.Parse(authrsp.Header.Get("Location"))
+ require.NoError(t, err)
+
+ // Will redirect to custom domain
+ require.Equal(t, domain, url.Host)
+ require.Equal(t, "1", url.Query().Get("code"))
+ require.Equal(t, state, url.Query().Get("state"))
+
+ // Run auth callback in custom domain
+ authrsp, err = GetRedirectPageWithCookie(t, httpListener, domain, "/auth?code=1&state="+
+ state, cookie)
+
+ require.NoError(t, err)
+ defer authrsp.Body.Close()
+
+ // Will redirect to the page
+ groupCookie := authrsp.Header.Get("Set-Cookie")
+ require.Equal(t, http.StatusFound, authrsp.StatusCode)
+
+ url, err = url.Parse(authrsp.Header.Get("Location"))
+ require.NoError(t, err)
+
+ // Will redirect to custom domain error page
+ require.Equal(t, "http://"+domain+path, url.String())
+
+ // Fetch page in custom domain
+ anotherResp, err := GetRedirectPageWithCookie(t, httpListener, domain, path, groupCookie)
+ require.NoError(t, err)
+
+ require.Equal(t, http.StatusNotFound, anotherResp.StatusCode)
+
+ page, err := ioutil.ReadAll(anotherResp.Body)
+ require.NoError(t, err)
+ require.Contains(t, string(page), tt.expectedErrorPage)
+ })
+ }
+}
+
func TestAccessControlUnderCustomDomainWithHTTPSProxy(t *testing.T) {
skipUnlessEnabled(t, "not-inplace-chroot")