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
path: root/app.go
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2020-05-28 11:07:03 +0300
committerJaime Martinez <jmartinez@gitlab.com>2020-07-06 02:13:51 +0300
commit4f82a5659cfcec5e7782b80f0d551353cbdcc1dc (patch)
tree0b9ccdfa09a1cbf932dfd23d26506b3096ccd285 /app.go
parentfb2c26ff998b809baddeb9618aae52c49200bc8b (diff)
Get namespace domain if auth fails for a private domain
Add acceptance test and some more domains for testing Move namespace domain serving logic Restore go.sum Remove redundant return Fix linter
Diffstat (limited to 'app.go')
-rw-r--r--app.go28
1 files changed, 16 insertions, 12 deletions
diff --git a/app.go b/app.go
index 4ead5003..a6e6006d 100644
--- a/app.go
+++ b/app.go
@@ -95,22 +95,23 @@ func (a *theApp) domain(host string) (*domain.Domain, error) {
}
func (a *theApp) checkAuthenticationIfNotExists(domain *domain.Domain, w http.ResponseWriter, r *http.Request) bool {
- if domain == nil || !domain.HasLookupPath(r) {
+ if !domain.HasLookupPath(r) {
// Only if auth is supported
if a.Auth.IsAuthSupported() {
// To avoid user knowing if pages exist, we will force user to login and authorize pages
- if a.Auth.CheckAuthenticationWithoutProject(w, r) {
+ if contentServed, authFailed := a.Auth.CheckAuthenticationWithoutProject(w, r); contentServed {
+ return true
+ } else if authFailed && domain != nil {
+ // try to serve custom namespace not found if exists and is public
+ domain.ServeNamespaceNotFound(w, r)
return true
}
- // User is authenticated, show the 404
if domain != nil {
+ // User is authenticated, show the 404
domain.ServeNotFoundHTTP(w, r)
- } else {
- httperrors.Serve404(w)
+ return true
}
-
- return true
}
}
@@ -250,7 +251,10 @@ func (a *theApp) accessControlMiddleware(handler http.Handler) http.Handler {
// Only for projects that have access control enabled
if domain.IsAccessControlEnabled(r) {
// accessControlMiddleware
- if a.Auth.CheckAuthentication(w, r, domain) {
+ if contentServed, authFailed := a.Auth.CheckAuthentication(w, r, domain.GetProjectID(r)); contentServed {
+ return
+ } else if authFailed && domain != nil {
+ domain.ServeNamespaceNotFound(w, r)
return
}
}
@@ -274,12 +278,12 @@ func (a *theApp) serveFileOrNotFoundHandler() http.Handler {
// because the projects override the paths of the namespace project and they might be private even though
// namespace project is public.
if domain.IsNamespaceProject(r) {
- if a.Auth.CheckAuthenticationWithoutProject(w, r) {
+ if contentServed, authFailed := a.Auth.CheckAuthenticationWithoutProject(w, r); contentServed {
+ return
+ } else if authFailed {
+ httperrors.Serve404(w)
return
}
-
- domain.ServeNotFoundHTTP(w, r)
- return
}
domain.ServeNotFoundHTTP(w, r)