From 69e02ea03064bb08b7b53638f3c2a1ef9508d5cf Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 2 Jul 2020 18:32:51 +0100 Subject: [PATCH] Fix the declarations for compareSecret. compareSecret in both its forms was declared as returning a String not a Bool. This fixes both of these. --- pkg/interceptors/cel/cel_test.go | 10 +++++++++- pkg/interceptors/cel/triggers.go | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/interceptors/cel/cel_test.go b/pkg/interceptors/cel/cel_test.go index 36dcf21cb..2d54d61e9 100644 --- a/pkg/interceptors/cel/cel_test.go +++ b/pkg/interceptors/cel/cel_test.go @@ -189,10 +189,18 @@ func TestInterceptor_ExecuteTrigger(t *testing.T) { payload: ioutil.NopCloser(bytes.NewBufferString(`{"count":1,"measure":1.7}`)), want: []byte(`{"count":1,"measure":1.7}`), }, + { + name: "validating a secret", + CEL: &triggersv1.CELInterceptor{ + Filter: "header.canonical('X-Secret-Token').compareSecret('token', 'test-secret', 'testing-ns') && body.count == 1.0", + }, + payload: ioutil.NopCloser(bytes.NewBufferString(`{"count":1,"measure":1.7}`)), + want: []byte(`{"count":1,"measure":1.7}`), + }, { name: "validating a secret in the default namespace", CEL: &triggersv1.CELInterceptor{ - Filter: "header.canonical('X-Secret-Token').compareSecret('token', 'test-secret')", + Filter: "header.canonical('X-Secret-Token').compareSecret('token', 'test-secret') && body.count == 1.0", }, payload: ioutil.NopCloser(bytes.NewBufferString(`{"count":1,"measure":1.7}`)), want: []byte(`{"count":1,"measure":1.7}`), diff --git a/pkg/interceptors/cel/triggers.go b/pkg/interceptors/cel/triggers.go index 4eaa85200..6c83aebb9 100644 --- a/pkg/interceptors/cel/triggers.go +++ b/pkg/interceptors/cel/triggers.go @@ -178,7 +178,7 @@ func (triggersLib) CompileOptions() []cel.EnvOption { []*exprpb.Type{decls.String, decls.Int}, decls.String)), decls.NewFunction("compareSecret", decls.NewInstanceOverload("compareSecret_string_string_string", - []*exprpb.Type{decls.String, decls.String, decls.String, decls.String}, decls.String)), + []*exprpb.Type{decls.String, decls.String, decls.String, decls.String}, decls.Bool)), decls.NewFunction("parseJSON", decls.NewInstanceOverload("parseJSON_string", []*exprpb.Type{decls.String}, mapStrDyn)), @@ -190,7 +190,7 @@ func (triggersLib) CompileOptions() []cel.EnvOption { []*exprpb.Type{decls.String}, mapStrDyn)), decls.NewFunction("compareSecret", decls.NewInstanceOverload("compareSecret_string_string", - []*exprpb.Type{decls.String, decls.String, decls.String}, decls.String)))} + []*exprpb.Type{decls.String, decls.String, decls.String}, decls.Bool)))} } func (t triggersLib) ProgramOptions() []cel.ProgramOption {