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:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-09-21 17:17:03 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-09-22 13:08:27 +0300
commit079f5e979142bceeeb6506c4d31d7c9f1488ce78 (patch)
tree1d0f83071f8978594dbe1a7c43b3d112f6073839 /internal/auth
parente33a670211b5a63b5db4c024b95ec2d96d2ef463 (diff)
Separate domain config source from a domain
Diffstat (limited to 'internal/auth')
-rw-r--r--internal/auth/auth.go8
-rw-r--r--internal/auth/auth_test.go10
2 files changed, 9 insertions, 9 deletions
diff --git a/internal/auth/auth.go b/internal/auth/auth.go
index 77bc7d8e..154d86da 100644
--- a/internal/auth/auth.go
+++ b/internal/auth/auth.go
@@ -19,10 +19,10 @@ import (
log "github.com/sirupsen/logrus"
"gitlab.com/gitlab-org/labkit/errortracking"
- "gitlab.com/gitlab-org/gitlab-pages/internal/domain"
"gitlab.com/gitlab-org/gitlab-pages/internal/httperrors"
"gitlab.com/gitlab-org/gitlab-pages/internal/httptransport"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/source/dirs"
"golang.org/x/crypto/hkdf"
)
@@ -108,7 +108,7 @@ func (a *Auth) checkSession(w http.ResponseWriter, r *http.Request) (*sessions.S
}
// TryAuthenticate tries to authenticate user and fetch access token if request is a callback to auth
-func (a *Auth) TryAuthenticate(w http.ResponseWriter, r *http.Request, dm domain.Map, lock *sync.RWMutex) bool {
+func (a *Auth) TryAuthenticate(w http.ResponseWriter, r *http.Request, dm dirs.Map, lock *sync.RWMutex) bool {
if a == nil {
return false
@@ -200,7 +200,7 @@ func (a *Auth) checkAuthenticationResponse(session *sessions.Session, w http.Res
http.Redirect(w, r, redirectURI, 302)
}
-func (a *Auth) domainAllowed(domain string, dm domain.Map, lock *sync.RWMutex) bool {
+func (a *Auth) domainAllowed(domain string, dm dirs.Map, lock *sync.RWMutex) bool {
lock.RLock()
defer lock.RUnlock()
@@ -209,7 +209,7 @@ func (a *Auth) domainAllowed(domain string, dm domain.Map, lock *sync.RWMutex) b
return domain == a.pagesDomain || strings.HasSuffix("."+domain, a.pagesDomain) || present
}
-func (a *Auth) handleProxyingAuth(session *sessions.Session, w http.ResponseWriter, r *http.Request, dm domain.Map, lock *sync.RWMutex) bool {
+func (a *Auth) handleProxyingAuth(session *sessions.Session, w http.ResponseWriter, r *http.Request, dm dirs.Map, lock *sync.RWMutex) bool {
// If request is for authenticating via custom domain
if shouldProxyAuth(r) {
domain := r.URL.Query().Get("domain")
diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go
index 8be5e835..8102a5d1 100644
--- a/internal/auth/auth_test.go
+++ b/internal/auth/auth_test.go
@@ -11,8 +11,8 @@ import (
"github.com/gorilla/sessions"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitlab-pages/internal/domain"
"gitlab.com/gitlab-org/gitlab-pages/internal/request"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/source/dirs"
)
func createAuth(t *testing.T) *Auth {
@@ -55,7 +55,7 @@ func TestTryAuthenticate(t *testing.T) {
require.NoError(t, err)
r := request.WithHTTPSFlag(&http.Request{URL: reqURL}, true)
- require.Equal(t, false, auth.TryAuthenticate(result, r, make(domain.Map), &sync.RWMutex{}))
+ require.Equal(t, false, auth.TryAuthenticate(result, r, make(dirs.Map), &sync.RWMutex{}))
}
func TestTryAuthenticateWithError(t *testing.T) {
@@ -66,7 +66,7 @@ func TestTryAuthenticateWithError(t *testing.T) {
require.NoError(t, err)
r := request.WithHTTPSFlag(&http.Request{URL: reqURL}, true)
- require.Equal(t, true, auth.TryAuthenticate(result, r, make(domain.Map), &sync.RWMutex{}))
+ require.Equal(t, true, auth.TryAuthenticate(result, r, make(dirs.Map), &sync.RWMutex{}))
require.Equal(t, 401, result.Code)
}
@@ -83,7 +83,7 @@ func TestTryAuthenticateWithCodeButInvalidState(t *testing.T) {
session.Values["state"] = "state"
session.Save(r, result)
- require.Equal(t, true, auth.TryAuthenticate(result, r, make(domain.Map), &sync.RWMutex{}))
+ require.Equal(t, true, auth.TryAuthenticate(result, r, make(dirs.Map), &sync.RWMutex{}))
require.Equal(t, 401, result.Code)
}
@@ -123,7 +123,7 @@ func testTryAuthenticateWithCodeAndState(t *testing.T, https bool) {
})
result := httptest.NewRecorder()
- require.Equal(t, true, auth.TryAuthenticate(result, r, make(domain.Map), &sync.RWMutex{}))
+ require.Equal(t, true, auth.TryAuthenticate(result, r, make(dirs.Map), &sync.RWMutex{}))
require.Equal(t, 302, result.Code)
require.Equal(t, "https://pages.gitlab-example.com/project/", result.Header().Get("Location"))
require.Equal(t, 600, result.Result().Cookies()[0].MaxAge)