Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jrschumacher committed Nov 15, 2024
1 parent bda1a28 commit 900c4bb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions service/internal/auth/casbin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,27 +460,32 @@ func (s *AuthnCasbinSuite) Test_ExtendDefaultPolicies_MalformedErrors() {
func (s *AuthnCasbinSuite) Test_SetPolicy() {
enforcer, err := NewCasbinEnforcer(CasbinConfig{}, logger.CreateTestLogger())
s.Require().NoError(err)
tok := s.newTokWithDefaultClaim(true, false, false)

// Org-admin role
err = enforcer.SetPolicy(strings.Join([]string{
"p, role:org-admin, new.service.*, *, allow",
"p, role:admin, new.hello.*, *, allow",
"p, role:standard, new.hello.*, read, allow",
"p, role:standard, new.hello.*, write, deny",
}, "\n"))
s.Require().NoError(err)

// allowed role for new policy is allowed
allowed, err := enforcer.Enforce(tok, "new.service.DoSomething", "read")
s.Require().NoError(err)
s.True(allowed)
// unauthorized role
tok := s.newTokWithDefaultClaim(false, false)
allowed, err := enforcer.Enforce(tok, "new.hello.World", "read")
s.Require().Error(err)
s.False(allowed)
allowed, err = enforcer.Enforce(tok, "new.hello.World", "write")
s.Require().Error(err)
s.False(allowed)
allowed, err = enforcer.Enforce(tok, "new.service.DoSomething", "read")
s.Require().Error(err)
s.False(allowed)
allowed, err = enforcer.Enforce(tok, "new.service.DoSomething", "write")
s.Require().NoError(err)
s.True(allowed)
s.Require().Error(err)
s.False(allowed)

// other roles denied new policy: admin
tok = s.newTokWithDefaultClaim(false, true, false)
tok = s.newTokWithDefaultClaim(true, false)
allowed, err = enforcer.Enforce(tok, "new.hello.World", "read")
s.Require().NoError(err)
s.True(allowed)
Expand All @@ -495,7 +500,7 @@ func (s *AuthnCasbinSuite) Test_SetPolicy() {
s.False(allowed)

// other roles denied new policy: standard
tok = s.newTokWithDefaultClaim(false, false, true)
tok = s.newTokWithDefaultClaim(false, true)
allowed, err = enforcer.Enforce(tok, "new.hello.World", "read")
s.Require().NoError(err)
s.True(allowed)
Expand Down

0 comments on commit 900c4bb

Please sign in to comment.