Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/rbacpolicy/rbacpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (p *RBACPolicyEnforcer) getProjectFromRequest(rvals ...any) *v1alpha1.AppPr
if res, ok := rvals[1].(string); ok {
if obj, ok := rvals[3].(string); ok {
switch res {
case rbac.ResourceApplications, rbac.ResourceRepositories, rbac.ResourceClusters, rbac.ResourceLogs, rbac.ResourceExec:
case rbac.ResourceApplicationSets, rbac.ResourceApplications, rbac.ResourceRepositories, rbac.ResourceClusters, rbac.ResourceLogs, rbac.ResourceExec:
if objSplit := strings.Split(obj, "/"); len(objSplit) >= 2 {
return getProjectByName(objSplit[0])
}
Expand Down
46 changes: 41 additions & 5 deletions server/rbacpolicy/rbacpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/golang-jwt/jwt/v5"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"

Expand Down Expand Up @@ -187,11 +188,46 @@ func TestGetScopes_CustomScopes(t *testing.T) {
}

func Test_getProjectFromRequest(t *testing.T) {
fp := newFakeProj()
projLister := test.NewFakeProjLister(fp)
tests := []struct {
name string
resource string
action string
arg string
}{
{
name: "valid project/repo string",
resource: "repositories",
action: "create",
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
},
{
name: "applicationsets with project/repo string",
resource: "applicationsets",
action: "create",
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
},
{
name: "applicationsets with project/repo string",
resource: "applicationsets",
action: "*",
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
},
{
name: "applicationsets with project/repo string",
resource: "applicationsets",
action: "get",
arg: newFakeProj().Name + "/https://github.com/argoproj/argocd-example-apps",
},
}

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

assert.Equal(t, project.Name, fp.Name)
project := rbacEnforcer.getProjectFromRequest("", tt.resource, tt.action, tt.arg)
require.Equal(t, fp.Name, project.Name)
})
}
}
Loading