Skip to content

Commit

Permalink
Fix roles filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
gzdunek authored and github-actions committed Apr 29, 2024
1 parent 0bbcbea commit 5084576
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions api/types/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const (

// Match checks if the given role matches this filter.
func (f *RoleFilter) Match(role *RoleV6) bool {
if f.SkipSystemRoles {
return !IsSystemResource(role)
if f.SkipSystemRoles && IsSystemResource(role) {
return false
}

if len(f.SearchKeywords) != 0 {
Expand Down
26 changes: 25 additions & 1 deletion api/types/role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,17 @@ func TestRoleFilterMatch(t *testing.T) {
shouldMatch: true,
},
{
name: "correct search keyword should match the role",
name: "correct search keyword should match the regular role",
role: &regularRole,
filter: &RoleFilter{SearchKeywords: []string{"appr"}},
shouldMatch: true,
},
{
name: "correct search keyword should match the system role",
role: &systemRole,
filter: &RoleFilter{SearchKeywords: []string{"bot"}},
shouldMatch: true,
},
{
name: "incorrect search keyword shouldn't match the role",
role: &regularRole,
Expand All @@ -489,6 +495,24 @@ func TestRoleFilterMatch(t *testing.T) {
filter: &RoleFilter{SkipSystemRoles: true},
shouldMatch: true,
},
{
name: "skip system roles filter and incorrect search keywords shouldn't match the regular role",
role: &regularRole,
filter: &RoleFilter{SkipSystemRoles: true, SearchKeywords: []string{"xyz"}},
shouldMatch: false,
},
{
name: "skip system roles filter and correct search keywords shouldn't match the system role",
role: &systemRole,
filter: &RoleFilter{SkipSystemRoles: true, SearchKeywords: []string{"bot"}},
shouldMatch: false,
},
{
name: "skip system roles filter and correct search keywords should match the regular role",
role: &regularRole,
filter: &RoleFilter{SkipSystemRoles: true, SearchKeywords: []string{"appr"}},
shouldMatch: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 5084576

Please sign in to comment.