Skip to content

Commit a05a2c9

Browse files
blakepetterssonenneitex
authored andcommitted
fix: parse project with applicationset resource (argoproj#23252)
Signed-off-by: Blake Pettersson <[email protected]> Signed-off-by: enneitex <[email protected]>
1 parent 17a4c28 commit a05a2c9

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

server/rbacpolicy/rbacpolicy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (p *RBACPolicyEnforcer) getProjectFromRequest(rvals ...any) *v1alpha1.AppPr
132132
if res, ok := rvals[1].(string); ok {
133133
if obj, ok := rvals[3].(string); ok {
134134
switch res {
135-
case rbac.ResourceApplications, rbac.ResourceRepositories, rbac.ResourceClusters, rbac.ResourceLogs, rbac.ResourceExec:
135+
case rbac.ResourceApplicationSets, rbac.ResourceApplications, rbac.ResourceRepositories, rbac.ResourceClusters, rbac.ResourceLogs, rbac.ResourceExec:
136136
if objSplit := strings.Split(obj, "/"); len(objSplit) >= 2 {
137137
return getProjectByName(objSplit[0])
138138
}

server/rbacpolicy/rbacpolicy_test.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/golang-jwt/jwt/v5"
88
"github.com/stretchr/testify/assert"
9+
"github.com/stretchr/testify/require"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/client-go/kubernetes/fake"
1112

@@ -187,11 +188,46 @@ func TestGetScopes_CustomScopes(t *testing.T) {
187188
}
188189

189190
func Test_getProjectFromRequest(t *testing.T) {
190-
fp := newFakeProj()
191-
projLister := test.NewFakeProjLister(fp)
191+
tests := []struct {
192+
name string
193+
resource string
194+
action string
195+
arg string
196+
}{
197+
{
198+
name: "valid project/repo string",
199+
resource: "repositories",
200+
action: "create",
201+
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
202+
},
203+
{
204+
name: "applicationsets with project/repo string",
205+
resource: "applicationsets",
206+
action: "create",
207+
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
208+
},
209+
{
210+
name: "applicationsets with project/repo string",
211+
resource: "applicationsets",
212+
action: "*",
213+
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
214+
},
215+
{
216+
name: "applicationsets with project/repo string",
217+
resource: "applicationsets",
218+
action: "get",
219+
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
220+
},
221+
}
192222

193-
rbacEnforcer := NewRBACPolicyEnforcer(nil, projLister)
194-
project := rbacEnforcer.getProjectFromRequest("", "repositories", "create", fp.Name+"/https://github.com/argoproj/argocd-example-apps")
223+
for _, tt := range tests {
224+
t.Run(tt.name, func(t *testing.T) {
225+
fp := newFakeProj()
226+
projLister := test.NewFakeProjLister(fp)
227+
rbacEnforcer := NewRBACPolicyEnforcer(nil, projLister)
195228

196-
assert.Equal(t, project.Name, fp.Name)
229+
project := rbacEnforcer.getProjectFromRequest("", tt.resource, tt.action, tt.arg)
230+
require.Equal(t, fp.Name, project.Name)
231+
})
232+
}
197233
}

0 commit comments

Comments
 (0)