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-17 07:21:39 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-06-17 07:21:39 +0300
commita257bbf2e769f864bf59441554d19ee383eab9e0 (patch)
tree6a57f36ee2aa02427bb0018c98fa3eb54fc1debc
parent4cf524630a4cb677841d08c8dcbbb2a779d59ac1 (diff)
Update https redirect tests
-rw-r--r--shared/pages/group.https-only/project1/public.zipbin0 -> 327 bytes
-rw-r--r--shared/pages/group.https-only/project2/public.zipbin0 -> 326 bytes
-rw-r--r--test/acceptance/serving_test.go47
-rw-r--r--test/acceptance/testdata/api_responses.go17
4 files changed, 40 insertions, 24 deletions
diff --git a/shared/pages/group.https-only/project1/public.zip b/shared/pages/group.https-only/project1/public.zip
new file mode 100644
index 00000000..ac74f320
--- /dev/null
+++ b/shared/pages/group.https-only/project1/public.zip
Binary files differ
diff --git a/shared/pages/group.https-only/project2/public.zip b/shared/pages/group.https-only/project2/public.zip
new file mode 100644
index 00000000..ead779f5
--- /dev/null
+++ b/shared/pages/group.https-only/project2/public.zip
Binary files differ
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go
index 09fba7e1..32291e52 100644
--- a/test/acceptance/serving_test.go
+++ b/test/acceptance/serving_test.go
@@ -334,30 +334,35 @@ func TestHttpToHttpsRedirectEnabled(t *testing.T) {
require.Equal(t, http.StatusOK, rsp.StatusCode)
}
-func TestHttpsOnlyGroupEnabled(t *testing.T) {
- skipUnlessEnabled(t)
-
- teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "")
- defer teardown()
-
- // TODO: allow configuring HTTPS responses from stub https://gitlab.com/gitlab-org/gitlab-pages/-/issues/571
- // Related MR in progress https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/498
- rsp, err := GetRedirectPage(t, httpListener, "group.https-only.gitlab-example.com", "project1/")
- require.NoError(t, err)
- defer rsp.Body.Close()
- require.Equal(t, http.StatusMovedPermanently, rsp.StatusCode)
-}
+func TestHTTPSRedirect(t *testing.T) {
+ RunPagesProcessWithStubGitLabServer(t,
+ withListeners([]ListenSpec{httpListener}),
+ )
-func TestHttpsOnlyGroupDisabled(t *testing.T) {
- skipUnlessEnabled(t)
+ tests := map[string]struct {
+ path string
+ expectedStatus int
+ }{
+ "domain_https_only_true": {
+ path: "project1/",
+ expectedStatus: http.StatusMovedPermanently,
+ },
+ "domain_https_only_false": {
+ path: "project2/",
+ expectedStatus: http.StatusOK,
+ },
+ }
- teardown := RunPagesProcess(t, *pagesBinary, supportedListeners(), "")
- defer teardown()
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
+ // see testdata/api_responses.go for per prefix configuration response from the API
+ rsp, err := GetRedirectPage(t, httpListener, "group.https-only.gitlab-example.com", test.path)
+ require.NoError(t, err)
+ defer rsp.Body.Close()
- rsp, err := GetPageFromListener(t, httpListener, "group.https-only.gitlab-example.com", "project2/")
- require.NoError(t, err)
- defer rsp.Body.Close()
- require.Equal(t, http.StatusOK, rsp.StatusCode)
+ require.Equal(t, test.expectedStatus, rsp.StatusCode)
+ })
+ }
}
func TestHttpsOnlyProjectEnabled(t *testing.T) {
diff --git a/test/acceptance/testdata/api_responses.go b/test/acceptance/testdata/api_responses.go
index 860bd3a9..8d423716 100644
--- a/test/acceptance/testdata/api_responses.go
+++ b/test/acceptance/testdata/api_responses.go
@@ -28,6 +28,16 @@ var DomainResponses = map[string]responseFn{
"group.gitlab-example.com": generateVirtualDomainFromDir("group", "group.gitlab-example.com", nil),
"CapitalGroup.gitlab-example.com": generateVirtualDomainFromDir("CapitalGroup", "CapitalGroup.gitlab-example.com", nil),
"group.404.gitlab-example.com": generateVirtualDomainFromDir("group.404", "group.404.gitlab-example.com", nil),
+ "group.https-only.gitlab-example.com": generateVirtualDomainFromDir("group.https-only", "group.https-only.gitlab-example.com", map[string]projectConfig{
+ "/project1": {
+ projectID: 1000,
+ https: true,
+ },
+ "/project2": {
+ projectID: 1100,
+ https: false,
+ },
+ }),
"domain.404.com": customDomain(projectConfig{
projectID: 1000,
pathOnDisk: "group.404/domain.404",
@@ -85,8 +95,6 @@ func generateVirtualDomainFromDir(dir, rootDomain string, perPrefixConfig map[st
}
lookupPath := api.LookupPath{
- // TODO: allow configuring response
- // Related MR in progress https://gitlab.com/gitlab-org/gitlab-pages/-/merge_requests/498
ProjectID: cfg.projectID,
AccessControl: cfg.accessControl,
HTTPSOnly: cfg.https,
@@ -127,7 +135,10 @@ func customDomain(config projectConfig) responseFn {
ProjectID: config.projectID,
AccessControl: config.accessControl,
HTTPSOnly: config.https,
- Prefix: "/", // prefix should always be `/` for custom domains
+ // prefix should always be `/` for custom domains, otherwise `resolvePath` will try
+ // to look for files under public/prefix/ when serving content instead of just public/
+ // see internal/serving/disk/ for details
+ Prefix: "/",
Source: api.Source{
Type: "zip",
Path: fmt.Sprintf("file://%s/%s/public.zip", wd, config.pathOnDisk),