aboutsummaryrefslogtreecommitdiff
path: root/internal/authz
diff options
context:
space:
mode:
Diffstat (limited to 'internal/authz')
-rw-r--r--internal/authz/middleware.go2
-rw-r--r--internal/authz/middleware_test.go21
2 files changed, 15 insertions, 8 deletions
diff --git a/internal/authz/middleware.go b/internal/authz/middleware.go
index 41672f2..f01f262 100644
--- a/internal/authz/middleware.go
+++ b/internal/authz/middleware.go
@@ -40,7 +40,7 @@ func Authentication(authMap TokenMap, next http.Handler) http.Handler {
}
// Authorization middleware to enforce authoirzation of all requests.
-func Authorization(adminSvc *admin.Service, next http.Handler) http.Handler {
+func Authorization(adminSvc *admin.Servicer, next http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
ctx := req.Context()
urn := ctx.Value("urn")
diff --git a/internal/authz/middleware_test.go b/internal/authz/middleware_test.go
index 8dbc30f..5795b3f 100644
--- a/internal/authz/middleware_test.go
+++ b/internal/authz/middleware_test.go
@@ -7,11 +7,14 @@ import (
"net/http/httptest"
"testing"
+ "git.ofmax.li/go-git-server/internal/admin"
"github.com/casbin/casbin/v2"
)
-func junkTestHandler(rw http.ResponseWriter, req *http.Request) {
- rw.WriteHeader(http.StatusOK)
+func junkTestHandler() http.HandlerFunc {
+ return func(rw http.ResponseWriter, req *http.Request) {
+ rw.WriteHeader(http.StatusOK)
+ }
}
func TestAuthentication(t *testing.T) {
@@ -28,7 +31,7 @@ func TestAuthentication(t *testing.T) {
token string
tm TokenMap
statusCode int
- handler func(http.ResponseWriter, *http.Request)
+ handler http.HandlerFunc
}{
{
username: okUserName,
@@ -51,7 +54,7 @@ func TestAuthentication(t *testing.T) {
tm: tm,
statusCode: http.StatusForbidden,
description: "Bad usename",
- handler: junkTestHandler,
+ handler: junkTestHandler(),
},
{
username: okUserName,
@@ -59,7 +62,7 @@ func TestAuthentication(t *testing.T) {
tm: tm,
statusCode: http.StatusForbidden,
description: "Bad token",
- handler: junkTestHandler,
+ handler: junkTestHandler(),
},
}
@@ -82,7 +85,7 @@ func TestAuthentication(t *testing.T) {
func TestAuthorization(t *testing.T) {
t.Log("Starting authorization tests")
baseURL := "http://test"
- enf, err := casbin.NewEnforcer("../../auth_model.ini", "../../testpolicy.csv")
+ enf, err := casbin.NewSyncedEnforcer("../../auth_model.ini", "../../testpolicy.csv")
if err != nil {
t.Fatalf("Failed to load policies\n%s", err)
}
@@ -105,9 +108,13 @@ func TestAuthorization(t *testing.T) {
description: "an unautorized action should yield a 403",
},
}
+ svcr := &admin.Servicer{
+ enf,
+ &admin.ServerRepos{},
+ }
for _, tc := range cases {
t.Logf("test case: %s", tc.description)
- authHandler := Authorization(enf, junkTestHandler)
+ authHandler := Authorization(svcr, junkTestHandler())
recorder := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, tc.url, nil)
ctx := req.Context()