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
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