Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2686] Validate user and group specified in filter config #898

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 39 additions & 2 deletions pkg/scheduler/placement/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func TestNewFilterLists(t *testing.T) {
// test simple single user or group
conf = configs.Filter{}
conf.Type = ""
conf.Users = []string{"user1"}
conf.Groups = []string{"group1"}
conf.Users = []string{"user1_a_#_b_c-d-/-e:f_@_gmail.com"}
conf.Groups = []string{"group1_a_b_c-d-e:f_gmail.com"}

filter = newFilter(conf)
if !filter.allow {
Expand Down Expand Up @@ -192,6 +192,43 @@ func TestNewFilterExceptions(t *testing.T) {
if filter.groupExp != nil || len(filter.groupList) != 1 {
t.Error("filter create did not set group filter correctly regexp not in first entry")
}

// test single invalid user or group
conf = configs.Filter{}
conf.Type = ""
conf.Users = []string{"user!1"}
conf.Groups = []string{"grou#p1"}

filter = newFilter(conf)
if !filter.allow {
t.Error("filter create did not set allow flag correctly from empty string")
}
if filter.userExp != nil || len(filter.userList) != 0 {
t.Error("filter create cannot set user filter correctly single invalid entry not regexp")
}
if filter.groupExp != nil || len(filter.groupList) != 0 {
t.Error("filter create cannot not set group filter correctly single invalid entry not regexp")
}
if filter.empty {
t.Error("filter create did not set empty flag correctly")
}

// test multiple invalid user or group
conf = configs.Filter{}
conf.Type = ""
conf.Users = []string{"use!r1", "user2"}
conf.Groups = []string{"gro!up1", "gro#up2"}

filter = newFilter(conf)
if !filter.allow {
t.Error("filter create did not set allow flag correctly from empty string")
}
if filter.userExp != nil || len(filter.userList) != 1 {
t.Error("filter create cannot set user filter correctly invalid multiple entry not regexp")
}
if filter.groupExp != nil || len(filter.groupList) != 0 {
t.Error("filter create cannot set group filter correctly invalid multiple entry not regexp")
}
}

// Test user matching
Expand Down
Loading