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:
Diffstat (limited to 'test/acceptance/acme_test.go')
-rw-r--r--test/acceptance/acme_test.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/acceptance/acme_test.go b/test/acceptance/acme_test.go
new file mode 100644
index 00000000..a0425b7d
--- /dev/null
+++ b/test/acceptance/acme_test.go
@@ -0,0 +1,73 @@
+package acceptance_test
+
+import (
+ "io/ioutil"
+ "net/http"
+ "net/url"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestAcmeChallengesWhenItIsNotConfigured(t *testing.T) {
+ skipUnlessEnabled(t)
+
+ teardown := RunPagesProcess(t, *pagesBinary, listeners, "", "")
+ 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)
+
+ 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))
+ })
+
+ t.Run("When domain folder doesn't contains requested acme challenge it returns 404",
+ func(t *testing.T) {
+ rsp, err := GetRedirectPage(t, httpListener, "withacmechallenge.domain.com",
+ notExistingAcmeTokenPath)
+
+ defer rsp.Body.Close()
+ require.NoError(t, err)
+ require.Equal(t, http.StatusNotFound, rsp.StatusCode)
+ },
+ )
+}
+
+func TestAcmeChallengesWhenItIsConfigured(t *testing.T) {
+ skipUnlessEnabled(t)
+
+ teardown := RunPagesProcess(t, *pagesBinary, listeners, "", "-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)
+
+ 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))
+ })
+
+ t.Run("When domain folder doesn't contains requested acme challenge it redirects to GitLab",
+ func(t *testing.T) {
+ rsp, err := GetRedirectPage(t, httpListener, "withacmechallenge.domain.com",
+ notExistingAcmeTokenPath)
+
+ defer rsp.Body.Close()
+ require.NoError(t, err)
+ require.Equal(t, http.StatusTemporaryRedirect, rsp.StatusCode)
+
+ url, 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")
+ },
+ )
+}