aboutsummaryrefslogtreecommitdiff
path: root/internal/authz
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--internal/authz/middleware.go2
-rw-r--r--internal/authz/middleware_test.go15
2 files changed, 7 insertions, 10 deletions
diff --git a/internal/authz/middleware.go b/internal/authz/middleware.go
index f01f262..a35b6b4 100644
--- a/internal/authz/middleware.go
+++ b/internal/authz/middleware.go
@@ -43,7 +43,7 @@ func Authentication(authMap TokenMap, 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")
+ urn := ctx.Value("urn").(string)
repo := req.URL.Path
action := req.Method
ok, err := adminSvc.Enforce(urn, repo, action)
diff --git a/internal/authz/middleware_test.go b/internal/authz/middleware_test.go
index 5795b3f..cc3f6d1 100644
--- a/internal/authz/middleware_test.go
+++ b/internal/authz/middleware_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"git.ofmax.li/go-git-server/internal/admin"
- "github.com/casbin/casbin/v2"
)
func junkTestHandler() http.HandlerFunc {
@@ -85,10 +84,6 @@ func TestAuthentication(t *testing.T) {
func TestAuthorization(t *testing.T) {
t.Log("Starting authorization tests")
baseURL := "http://test"
- enf, err := casbin.NewSyncedEnforcer("../../auth_model.ini", "../../testpolicy.csv")
- if err != nil {
- t.Fatalf("Failed to load policies\n%s", err)
- }
cases := []struct {
url string
user string
@@ -108,10 +103,12 @@ func TestAuthorization(t *testing.T) {
description: "an unautorized action should yield a 403",
},
}
- svcr := &admin.Servicer{
- enf,
- &admin.ServerRepos{},
- }
+ svcr := admin.NewService(
+ "../../auth_model.ini",
+ "../../testpolicy.csv",
+ "../../gitserver.yaml",
+ "../../repos",
+ false)
for _, tc := range cases {
t.Logf("test case: %s", tc.description)
authHandler := Authorization(svcr, junkTestHandler())