From 2cecc17ef069b49ae3446330291e60f228577904 Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Wed, 13 Sep 2023 12:31:00 -0700 Subject: [PATCH] add celformer unit test demonstrating string regexp in CEL expressions --- internal/celtransformer/celformer_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/internal/celtransformer/celformer_test.go b/internal/celtransformer/celformer_test.go index 10a148b1..1e89d113 100644 --- a/internal/celtransformer/celformer_test.go +++ b/internal/celtransformer/celformer_test.go @@ -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",