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>2021-06-15 08:56:21 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-06-21 03:07:54 +0300
commitacb3ab3e87e16e6f2fa5d7d03c43a7d0220e7775 (patch)
tree5bbcad6a8d47c5f9f7dcf214448e23195469b3cf /test/acceptance/acme_test.go
parent4758b49493719e3ced7ac266ad1a9664cd3e62de (diff)
Use stub in acme_test.go
Diffstat (limited to 'test/acceptance/acme_test.go')
-rw-r--r--test/acceptance/acme_test.go106
1 files changed, 68 insertions, 38 deletions
diff --git a/test/acceptance/acme_test.go b/test/acceptance/acme_test.go
index eb8f2160..c7a33796 100644
--- a/test/acceptance/acme_test.go
+++ b/test/acceptance/acme_test.go
@@ -9,65 +9,95 @@ import (
"github.com/stretchr/testify/require"
)
+const (
+ existingAcmeTokenPath = "/.well-known/acme-challenge/existingtoken"
+ notExistingAcmeTokenPath = "/.well-known/acme-challenge/notexistingtoken"
+)
+
func TestAcmeChallengesWhenItIsNotConfigured(t *testing.T) {
skipUnlessEnabled(t)
- teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "", "")
- defer teardown()
-
- t.Run("When domain folder contains requested acme challenge it responds with it", func(t *testing.T) {
- rsp, err := GetRedirectPage(t, httpListener, "withacmechallenge.domain.com",
- existingAcmeTokenPath)
+ RunPagesProcessWithStubGitLabServer(t,
+ withListeners([]ListenSpec{httpListener}),
+ )
- defer rsp.Body.Close()
- require.NoError(t, err)
- require.Equal(t, http.StatusOK, rsp.StatusCode)
- body, _ := ioutil.ReadAll(rsp.Body)
- require.Equal(t, "this is token\n", string(body))
- })
+ tests := map[string]struct {
+ token string
+ expectedStatus int
+ expectedContent string
+ }{
+ "When domain folder contains requested acme challenge it responds with it": {
+ token: existingAcmeTokenPath,
+ expectedStatus: http.StatusOK,
+ expectedContent: "this is token\n",
+ },
+ "When domain folder does not contain requested acme challenge it returns 404": {
+ token: notExistingAcmeTokenPath,
+ expectedStatus: http.StatusNotFound,
+ expectedContent: "The page you're looking for could not be found.",
+ },
+ }
- t.Run("When domain folder doesn't contains requested acme challenge it returns 404",
- func(t *testing.T) {
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
rsp, err := GetRedirectPage(t, httpListener, "withacmechallenge.domain.com",
- notExistingAcmeTokenPath)
+ test.token)
defer rsp.Body.Close()
require.NoError(t, err)
- require.Equal(t, http.StatusNotFound, rsp.StatusCode)
- },
- )
+ require.Equal(t, test.expectedStatus, rsp.StatusCode)
+ body, err := ioutil.ReadAll(rsp.Body)
+ require.NoError(t, err)
+
+ require.Contains(t, string(body), test.expectedContent)
+ })
+ }
}
func TestAcmeChallengesWhenItIsConfigured(t *testing.T) {
skipUnlessEnabled(t)
- teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "", "-gitlab-server=https://gitlab-acme.com")
- defer teardown()
-
- t.Run("When domain folder contains requested acme challenge it responds with it", func(t *testing.T) {
- rsp, err := GetRedirectPage(t, httpListener, "withacmechallenge.domain.com",
- existingAcmeTokenPath)
+ RunPagesProcessWithStubGitLabServer(t,
+ withListeners([]ListenSpec{httpListener}),
+ withExtraArgument("gitlab-server", "https://gitlab-acme.com"),
+ )
- defer rsp.Body.Close()
- require.NoError(t, err)
- require.Equal(t, http.StatusOK, rsp.StatusCode)
- body, _ := ioutil.ReadAll(rsp.Body)
- require.Equal(t, "this is token\n", string(body))
- })
+ tests := map[string]struct {
+ token string
+ expectedStatus int
+ expectedContent string
+ expectedLocation string
+ }{
+ "When domain folder contains requested acme challenge it responds with it": {
+ token: existingAcmeTokenPath,
+ expectedStatus: http.StatusOK,
+ expectedContent: "this is token\n",
+ },
+ "When domain folder doesn't contains requested acme challenge it redirects to GitLab": {
+ token: notExistingAcmeTokenPath,
+ expectedStatus: http.StatusTemporaryRedirect,
+ expectedContent: "",
+ expectedLocation: "https://gitlab-acme.com/-/acme-challenge?domain=withacmechallenge.domain.com&token=notexistingtoken",
+ },
+ }
- t.Run("When domain folder doesn't contains requested acme challenge it redirects to GitLab",
- func(t *testing.T) {
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
rsp, err := GetRedirectPage(t, httpListener, "withacmechallenge.domain.com",
- notExistingAcmeTokenPath)
+ test.token)
defer rsp.Body.Close()
require.NoError(t, err)
- require.Equal(t, http.StatusTemporaryRedirect, rsp.StatusCode)
+ require.Equal(t, test.expectedStatus, rsp.StatusCode)
+ body, err := ioutil.ReadAll(rsp.Body)
+ require.NoError(t, err)
+
+ require.Contains(t, string(body), test.expectedContent)
- url, err := url.Parse(rsp.Header.Get("Location"))
+ redirectURL, err := url.Parse(rsp.Header.Get("Location"))
require.NoError(t, err)
- require.Equal(t, url.String(), "https://gitlab-acme.com/-/acme-challenge?domain=withacmechallenge.domain.com&token=notexistingtoken")
- },
- )
+ require.Equal(t, redirectURL.String(), test.expectedLocation)
+ })
+ }
}