add celformer unit test demonstrating string regexp in CEL expressions

This commit is contained in:
Ryan Richard 2023-09-13 12:31:00 -07:00
parent c52ed93bf8
commit 2cecc17ef0

View File

@ -234,6 +234,26 @@ func TestTransformer(t *testing.T) {
wantUsername: "ryan",
wantGroups: []string{"admins", "developers", "other"},
},
{
name: "can use regex on strings: when the regex matches",
username: "ryan",
groups: []string{"admins", "developers", "other"},
transforms: []CELTransformation{
&UsernameTransformation{Expression: `username.matches("^r[abcy].n$") ? "ryan-modified" : username`},
},
wantUsername: "ryan-modified",
wantGroups: []string{"admins", "developers", "other"},
},
{
name: "can use regex on strings: when the regex does not match",
username: "olive",
groups: []string{"admins", "developers", "other"},
transforms: []CELTransformation{
&UsernameTransformation{Expression: `username.matches("^r[abcy].n$") ? "ryan-modified" : username`},
},
wantUsername: "olive",
wantGroups: []string{"admins", "developers", "other"},
},
{
name: "can filter groups based on an allow list",
username: "ryan",