Skip to content

Commit 413499b

Browse files
committed
chore: cleanup obsolete tests and consolidate mocks
Removed obsolete test for database sync behavior and consolidated to mockery v3 mocks package. Changes: - Removed TestSyncMultipleEnforcers (tested database sync, no longer relevant with in-memory enforcer) - Migrated casbackend_test.go to use mocks package instead of mocks_test.go - Deleted pkg/biz/mocks_test.go (replaced by pkg/biz/mocks/ package) - Added mockery v3 and API token policies notes to CLAUDE.md Signed-off-by: Miguel Martinez <miguel@chainloop.dev>
1 parent 91ea013 commit 413499b

File tree

4 files changed

+7
-1941
lines changed

4 files changed

+7
-1941
lines changed

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ The project heavily uses code generation:
217217
- **Wire**: Dependency injection
218218
- **Ent**: ORM models and queries
219219
- **Buf**: Protobuf tooling and validation
220+
- **Mockery v3**: Test mocks - add interface to `.mockery.yml`, run `mockery` from that directory
220221

221222
Always run `make generate` after modifying .proto files or Ent schemas.
222223

224+
**API Token Policies**: If modifying `DefaultAuthzPolicies` in `pkg/biz/apitoken.go`, create a migration to update existing tokens' `policies` field - they're stored in DB, not loaded dynamically.
225+
223226
## Contract-Based Development
224227

225228
Workflow Contracts define the structure and requirements for CI/CD attestations. They specify what materials must be collected and policies that must be evaluated.

app/controlplane/pkg/authz/authz_test.go

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -24,124 +24,6 @@ import (
2424
"github.com/stretchr/testify/require"
2525
)
2626

27-
28-
// simulate 2 enforcers on the same database (by acting on the same file enforcer)
29-
func TestSyncMultipleEnforcers(t *testing.T) {
30-
testCases := []struct {
31-
name string
32-
newEnforcerConfig *Config
33-
expectErr bool
34-
numPolicies int
35-
numSubjects int
36-
numAdminActions int
37-
}{
38-
{
39-
name: "empty config",
40-
newEnforcerConfig: &Config{},
41-
expectErr: false,
42-
numPolicies: 3,
43-
numSubjects: 2,
44-
numAdminActions: 2,
45-
},
46-
{
47-
name: "new actions on different resources for same roles",
48-
newEnforcerConfig: &Config{
49-
ManagedResources: []string{ResourceGroup},
50-
RolesMap: map[Role][]*Policy{
51-
RoleAdmin: {{
52-
Resource: ResourceGroup,
53-
Action: ActionCreate,
54-
}},
55-
},
56-
},
57-
expectErr: false,
58-
numPolicies: 4,
59-
numSubjects: 2,
60-
numAdminActions: 3,
61-
},
62-
{
63-
name: "new actions on different resources for new roles",
64-
newEnforcerConfig: &Config{
65-
ManagedResources: []string{ResourceGroup},
66-
RolesMap: map[Role][]*Policy{
67-
RoleProjectAdmin: {{
68-
Resource: ResourceGroup,
69-
Action: ActionCreate,
70-
}},
71-
},
72-
},
73-
expectErr: false,
74-
numSubjects: 3,
75-
numPolicies: 4,
76-
numAdminActions: 2,
77-
},
78-
{
79-
name: "reset admin actions on same resource, collision",
80-
newEnforcerConfig: &Config{
81-
ManagedResources: []string{ResourceWorkflow},
82-
RolesMap: map[Role][]*Policy{
83-
RoleAdmin: {}, // this should remove all admin actions from enforcer
84-
},
85-
},
86-
expectErr: false,
87-
numSubjects: 1,
88-
numPolicies: 1,
89-
numAdminActions: 0,
90-
},
91-
}
92-
93-
for _, tc := range testCases {
94-
t.Run(tc.name, func(t *testing.T) {
95-
e, c := testEnforcer(t)
96-
defer c.Close()
97-
98-
// initial import
99-
err := syncRBACRoles(e, &Config{
100-
ManagedResources: []string{ResourceWorkflow, ResourceWorkflowRun},
101-
RolesMap: map[Role][]*Policy{
102-
RoleAdmin: {{
103-
Resource: ResourceWorkflow,
104-
Action: ActionCreate,
105-
}, {
106-
Resource: ResourceWorkflow,
107-
Action: ActionDelete,
108-
}},
109-
RoleOrgMember: {{
110-
Resource: ResourceWorkflowRun,
111-
Action: ActionList,
112-
}},
113-
},
114-
})
115-
require.NoError(t, err)
116-
117-
// sync with test case config
118-
err = syncRBACRoles(e, tc.newEnforcerConfig)
119-
if tc.expectErr {
120-
assert.Error(t, err)
121-
return
122-
}
123-
assert.NoError(t, err)
124-
125-
policies, err := e.GetPolicy()
126-
assert.NoError(t, err)
127-
assert.Len(t, policies, tc.numPolicies)
128-
129-
adminCount := 0
130-
for _, r := range policies {
131-
if r[0] == string(RoleAdmin) {
132-
adminCount++
133-
}
134-
}
135-
assert.Equal(t, tc.numAdminActions, adminCount)
136-
137-
subs, err := e.GetAllSubjects()
138-
assert.NoError(t, err)
139-
assert.Len(t, subs, tc.numSubjects) // We need to count the Viewer role
140-
})
141-
}
142-
}
143-
144-
14527
func TestSyncRBACRoles(t *testing.T) {
14628
e, closer := testEnforcer(t)
14729
defer closer.Close()

app/controlplane/pkg/biz/casbackend_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2024 The Chainloop Authors.
2+
// Copyright 2024-2025 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
24+
bizMocks "github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz/mocks"
2425
backends "github.com/chainloop-dev/chainloop/pkg/blobmanager"
2526
blobM "github.com/chainloop-dev/chainloop/pkg/blobmanager/mocks"
2627
"github.com/chainloop-dev/chainloop/pkg/credentials"
@@ -36,7 +37,7 @@ type casBackendTestSuite struct {
3637
validUUID uuid.UUID
3738
invalidUUID string
3839
useCase *biz.CASBackendUseCase
39-
repo *biz.MockCASBackendRepo
40+
repo *bizMocks.CASBackendRepo
4041
credsRW *credentialsM.ReaderWriter
4142
backendProvider *blobM.Provider
4243
}
@@ -277,7 +278,7 @@ func (s *casBackendTestSuite) resetMock() {
277278
func (s *casBackendTestSuite) SetupTest() {
278279
s.validUUID = uuid.New()
279280
s.invalidUUID = "deadbeef"
280-
s.repo = biz.NewMockCASBackendRepo(s.T())
281+
s.repo = bizMocks.NewCASBackendRepo(s.T())
281282
s.credsRW = credentialsM.NewReaderWriter(s.T())
282283
s.backendProvider = blobM.NewProvider(s.T())
283284
var err error

0 commit comments

Comments
 (0)