diff options
author | Filip Aleksic <faleksic@gitlab.com> | 2022-07-25 10:24:42 +0300 |
---|---|---|
committer | Filip Aleksic <faleksic@gitlab.com> | 2022-07-25 10:24:42 +0300 |
commit | 0d6d9e4fe46e6f087249ed05e88321c4b1575d69 (patch) | |
tree | 10b053ca03a1d24d36dde590a0d8f28a52418e6c | |
parent | 5e5e6c995d7bf6b52a438635b5f1e53dcc983eba (diff) |
Acceptance tests for acme challenge redirectdont-redirect-acme-challange
-rw-r--r-- | shared/pages/acme-challenge/project/public.zip | bin | 0 -> 528 bytes | |||
-rw-r--r-- | shared/pages/acme-challenge/project/public/_redirects | 1 | ||||
-rw-r--r-- | shared/pages/acme-challenge/project/public/index.html | 1 | ||||
-rw-r--r-- | test/acceptance/redirects_test.go | 46 | ||||
-rw-r--r-- | test/gitlabstub/api_responses.go | 4 |
5 files changed, 52 insertions, 0 deletions
diff --git a/shared/pages/acme-challenge/project/public.zip b/shared/pages/acme-challenge/project/public.zip Binary files differnew file mode 100644 index 00000000..f65fb214 --- /dev/null +++ b/shared/pages/acme-challenge/project/public.zip diff --git a/shared/pages/acme-challenge/project/public/_redirects b/shared/pages/acme-challenge/project/public/_redirects new file mode 100644 index 00000000..f8243379 --- /dev/null +++ b/shared/pages/acme-challenge/project/public/_redirects @@ -0,0 +1 @@ +/* /index.html 200
\ No newline at end of file diff --git a/shared/pages/acme-challenge/project/public/index.html b/shared/pages/acme-challenge/project/public/index.html new file mode 100644 index 00000000..2ba249c7 --- /dev/null +++ b/shared/pages/acme-challenge/project/public/index.html @@ -0,0 +1 @@ +acme-challenge-project
\ No newline at end of file diff --git a/test/acceptance/redirects_test.go b/test/acceptance/redirects_test.go index a2bdde53..6ccaabbb 100644 --- a/test/acceptance/redirects_test.go +++ b/test/acceptance/redirects_test.go @@ -105,3 +105,49 @@ func TestRedirect(t *testing.T) { }) } } + +func TestAcmeChallengesNoRedirection(t *testing.T) { + const existingAcmeTokenPath = "/.well-known/acme-challenge/some-path" + const homepage = "/index.html" + + RunPagesProcess(t, + withListeners([]ListenSpec{httpListener}), + withExtraArgument("gitlab-server", "https://gitlab-acme.com"), + ) + + tests := []struct { + host string + path string + expectedStatus int + expectedLocation string + }{ + // Wildcard redirect should not redirect acme challenge + { + host: "acme-challenge.example.com", + path: existingAcmeTokenPath, + expectedStatus: http.StatusOK, + expectedLocation: existingAcmeTokenPath, + }, + // It should redirect everything else + { + host: "acme-challenge.example.com", + path: "/example", + expectedStatus: http.StatusMovedPermanently, + expectedLocation: homepage, + }, + } + + for _, tt := range tests { + t.Run(fmt.Sprintf("%s%s -> %s (%d)", tt.host, tt.path, tt.expectedLocation, tt.expectedStatus), func(t *testing.T) { + rsp, err := GetRedirectPage(t, httpListener, tt.host, tt.path) + require.NoError(t, err) + testhelpers.Close(t, rsp.Body) + + // If we expect a redirect, check if we redirected properly + if tt.expectedStatus == http.StatusMovedPermanently { + require.Equal(t, tt.expectedLocation, rsp.Header.Get("Location")) + } + require.Equal(t, tt.expectedStatus, rsp.StatusCode) + }) + } +} diff --git a/test/gitlabstub/api_responses.go b/test/gitlabstub/api_responses.go index 3ebf4e1f..f739b92e 100644 --- a/test/gitlabstub/api_responses.go +++ b/test/gitlabstub/api_responses.go @@ -110,6 +110,10 @@ var domainResponses = map[string]responseFn{ accessControl: true, pathOnDisk: "group.auth/private.project", }), + "acme-challenge.example.com": customDomain(projectConfig{ + projectID: 1000, + pathOnDisk: "acme-challenge/project", + }), // NOTE: before adding more domains here, generate the zip archive by running (per project) // make zip PROJECT_SUBDIR=group/serving // make zip PROJECT_SUBDIR=group/project2 |