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:
-rw-r--r--domain.go20
-rw-r--r--domain_test.go44
-rw-r--r--domains_test.go2
-rw-r--r--shared/pages/group.404/domain.404/config.json7
-rw-r--r--shared/pages/group.404/domain.404/public/404.html1
-rw-r--r--shared/pages/group.404/group.404.test.io/public/404.html1
-rw-r--r--shared/pages/group.404/project.404.symlink/public/404.html1
-rw-r--r--shared/pages/group.404/project.404/public/404.html1
-rw-r--r--shared/pages/group.404/project.no.404/public/index.html1
9 files changed, 65 insertions, 13 deletions
diff --git a/domain.go b/domain.go
index 49df3762..43191937 100644
--- a/domain.go
+++ b/domain.go
@@ -68,10 +68,10 @@ func (d *domain) serveCustomFile(w http.ResponseWriter, r *http.Request, code in
return nil
}
-func (d *domain) resolvePath(projectName, subPath string) (fullPath string, err error) {
+func (d *domain) resolvePath(projectName string, subPath ...string) (fullPath string, err error) {
publicPath := filepath.Join(d.Group, projectName, "public")
- fullPath = filepath.Join(publicPath, subPath)
+ fullPath = filepath.Join(publicPath, filepath.Join(subPath...))
fullPath, err = filepath.EvalSymlinks(fullPath)
if err != nil {
return
@@ -132,8 +132,8 @@ func (d *domain) checkPath(w http.ResponseWriter, r *http.Request, path string)
return
}
-func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName, subPath string) error {
- path, err := d.resolvePath(projectName, subPath)
+func (d *domain) tryFile(w http.ResponseWriter, r *http.Request, projectName string, subPath ...string) error {
+ path, err := d.resolvePath(projectName, subPath...)
if err != nil {
return err
}
@@ -149,14 +149,8 @@ func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) {
split := strings.SplitN(r.URL.Path, "/", 3)
// Try to serve file for http://group.example.com/subpath/... => /group/subpath/...
- if len(split) >= 2 {
- subPath := ""
- if len(split) >= 3 {
- subPath = split[2]
- }
- if d.tryFile(w, r, split[1], subPath) == nil {
- return
- }
+ if len(split) >= 2 && d.tryFile(w, r, split[1], split[2:]...) == nil {
+ return
}
// Try to serve file for http://group.example.com/... => /group/group.example.com/...
@@ -170,7 +164,7 @@ func (d *domain) serveFromGroup(w http.ResponseWriter, r *http.Request) {
}
// Try serving not found page for http://group.example.com/ => /group/group.example.com/404.html
- if r.Host != "" && d.tryFile(w, r, strings.ToLower(r.Host), r.URL.Path) == nil {
+ if r.Host != "" && d.tryNotFound(w, r, strings.ToLower(r.Host)) == nil {
return
}
diff --git a/domain_test.go b/domain_test.go
index 4af2feb5..d1dca06e 100644
--- a/domain_test.go
+++ b/domain_test.go
@@ -2,6 +2,8 @@ package main
import (
"github.com/stretchr/testify/assert"
+ "net/http"
+ "net/url"
"testing"
)
@@ -46,6 +48,48 @@ func TestDomainServeHTTP(t *testing.T) {
assert.HTTPError(t, testDomain.ServeHTTP, "GET", "/not-existing-file", nil)
}
+func testHTTP404(t *testing.T, handler http.HandlerFunc, mode, url string, values url.Values, str interface{}) bool {
+ if !assert.HTTPError(t, handler, mode, url, values) {
+ return false
+ }
+ if !assert.HTTPBodyContains(t, handler, mode, url, values, str) {
+ return false
+ }
+ return true
+}
+
+func TestGroup404ServeHTTP(t *testing.T) {
+ setUpTests()
+
+ testGroup := &domain{
+ Group: "group.404",
+ Project: "",
+ }
+
+ testHTTP404(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/project.404/not/existing-file", nil, "Custom 404 project page")
+ testHTTP404(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/project.404/", nil, "Custom 404 project page")
+ testHTTP404(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/project.no.404/not/existing-file", nil, "Custom 404 group page")
+ testHTTP404(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/not/existing-file", nil, "Custom 404 group page")
+ testHTTP404(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/not-existing-file", nil, "Custom 404 group page")
+ testHTTP404(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/", nil, "Custom 404 group page")
+ assert.HTTPBodyNotContains(t, testGroup.ServeHTTP, "GET", "http://group.404.test.io/project.404.symlink/not/existing-file", nil, "Custom 404 project page")
+}
+
+func TestDomain404ServeHTTP(t *testing.T) {
+ setUpTests()
+
+ testDomain := &domain{
+ Group: "group.404",
+ Project: "domain.404",
+ Config: &domainConfig{
+ Domain: "domain.404.com",
+ },
+ }
+
+ testHTTP404(t, testDomain.ServeHTTP, "GET", "http://group.404.test.io/not-existing-file", nil, "Custom 404 group page")
+ testHTTP404(t, testDomain.ServeHTTP, "GET", "http://group.404.test.io/", nil, "Custom 404 group page")
+}
+
func TestGroupCertificate(t *testing.T) {
testGroup := &domain{
Group: "group",
diff --git a/domains_test.go b/domains_test.go
index 8c3b1e5e..5a2882d6 100644
--- a/domains_test.go
+++ b/domains_test.go
@@ -29,6 +29,8 @@ func TestReadProjects(t *testing.T) {
"group.internal.test.io",
"test.domain.com", // from config.json
"other.domain.com",
+ "domain.404.com",
+ "group.404.test.io",
}
for _, expected := range domains {
diff --git a/shared/pages/group.404/domain.404/config.json b/shared/pages/group.404/domain.404/config.json
new file mode 100644
index 00000000..c2adb9f6
--- /dev/null
+++ b/shared/pages/group.404/domain.404/config.json
@@ -0,0 +1,7 @@
+{
+ "Domains": [
+ {
+ "Domain": "domain.404.com"
+ }
+ ]
+}
diff --git a/shared/pages/group.404/domain.404/public/404.html b/shared/pages/group.404/domain.404/public/404.html
new file mode 100644
index 00000000..454a3d50
--- /dev/null
+++ b/shared/pages/group.404/domain.404/public/404.html
@@ -0,0 +1 @@
+Custom 404 group page
diff --git a/shared/pages/group.404/group.404.test.io/public/404.html b/shared/pages/group.404/group.404.test.io/public/404.html
new file mode 100644
index 00000000..454a3d50
--- /dev/null
+++ b/shared/pages/group.404/group.404.test.io/public/404.html
@@ -0,0 +1 @@
+Custom 404 group page
diff --git a/shared/pages/group.404/project.404.symlink/public/404.html b/shared/pages/group.404/project.404.symlink/public/404.html
new file mode 100644
index 00000000..896a32d0
--- /dev/null
+++ b/shared/pages/group.404/project.404.symlink/public/404.html
@@ -0,0 +1 @@
+Custom 404 project page
diff --git a/shared/pages/group.404/project.404/public/404.html b/shared/pages/group.404/project.404/public/404.html
new file mode 100644
index 00000000..896a32d0
--- /dev/null
+++ b/shared/pages/group.404/project.404/public/404.html
@@ -0,0 +1 @@
+Custom 404 project page
diff --git a/shared/pages/group.404/project.no.404/public/index.html b/shared/pages/group.404/project.no.404/public/index.html
new file mode 100644
index 00000000..896c9cfc
--- /dev/null
+++ b/shared/pages/group.404/project.no.404/public/index.html
@@ -0,0 +1 @@
+Index page