Skip to content

Commit 8645a5e

Browse files
committed
fix connection nats
Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent a859c1a commit 8645a5e

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

app/controlplane/pkg/authz/authz.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ const (
9595
RoleGroupMaintainer Role = "role:group:maintainer"
9696

9797
// Product roles
98-
9998
RoleProductViewer Role = "role:product:viewer"
10099
RoleProductAdmin Role = "role:product:admin"
101100
)

app/controlplane/pkg/biz/apitoken_integration_test.go

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222
"time"
2323

24-
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz"
2524
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
2625
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz/testhelpers"
2726
"github.com/golang-jwt/jwt/v4"
@@ -149,17 +148,21 @@ func (s *apiTokenTestSuite) TestAuthzPolicies() {
149148
token, err := s.APIToken.Create(context.Background(), randomName(), nil, nil, s.org.ID)
150149
require.NoError(s.T(), err)
151150

152-
subject := (&authz.SubjectAPIToken{ID: token.ID.String()}).String()
153-
// load the policies associated with the token from the global enforcer
154-
policies, err := s.Enforcer.GetFilteredPolicy(0, subject)
155-
s.Require().NoError(err)
156-
157-
// Check that only default policies are loaded
158-
s.Len(policies, len(s.APIToken.DefaultAuthzPolicies))
159-
for _, p := range s.APIToken.DefaultAuthzPolicies {
160-
ok, err := s.Enforcer.HasPolicy(subject, p.Resource, p.Action)
161-
s.NoError(err)
162-
s.True(ok, fmt.Sprintf("policy %s:%s not found", p.Resource, p.Action))
151+
// With the new architecture, API token policies are stored in the database, not in Casbin
152+
// Verify that the token has the default policies stored
153+
s.Require().NotNil(token.Policies)
154+
s.Len(token.Policies, len(s.APIToken.DefaultAuthzPolicies))
155+
156+
// Check that all default policies are present
157+
for _, expectedPolicy := range s.APIToken.DefaultAuthzPolicies {
158+
found := false
159+
for _, actualPolicy := range token.Policies {
160+
if actualPolicy.Resource == expectedPolicy.Resource && actualPolicy.Action == expectedPolicy.Action {
161+
found = true
162+
break
163+
}
164+
}
165+
s.True(found, fmt.Sprintf("policy %s:%s not found", expectedPolicy.Resource, expectedPolicy.Action))
163166
}
164167
}
165168

@@ -184,20 +187,6 @@ func (s *apiTokenTestSuite) TestRevoke() {
184187
s.True(biz.IsNotFound(err))
185188
})
186189

187-
s.Run("the revoked token also get its policies cleared", func() {
188-
sub := (&authz.SubjectAPIToken{ID: s.t2.ID.String()}).String()
189-
// It has the default policies
190-
gotPolicies, err := s.Enforcer.GetFilteredPolicy(0, sub)
191-
s.NoError(err)
192-
s.Len(gotPolicies, len(s.APIToken.DefaultAuthzPolicies))
193-
err = s.APIToken.Revoke(ctx, s.org.ID, s.t2.ID.String())
194-
s.NoError(err)
195-
// once revoked, the policies are cleared
196-
gotPolicies, err = s.Enforcer.GetFilteredPolicy(0, sub)
197-
s.NoError(err)
198-
s.Len(gotPolicies, 0)
199-
})
200-
201190
s.Run("token can be revoked once", func() {
202191
err := s.APIToken.Revoke(ctx, s.org.ID, s.t1.ID.String())
203192
s.NoError(err)

0 commit comments

Comments
 (0)