From 91252ac93d6a728505f44b879721043c9a1a79ce Mon Sep 17 00:00:00 2001 From: Peter Grlica Date: Mon, 22 Aug 2022 14:41:33 +0200 Subject: [PATCH] Fixed apigw payload processer invalid function registration --- pkg/apigw/filter/processer.go | 4 +++- pkg/apigw/filter/processer_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/apigw/filter/processer.go b/pkg/apigw/filter/processer.go index 2f40a107a..0d6577412 100644 --- a/pkg/apigw/filter/processer.go +++ b/pkg/apigw/filter/processer.go @@ -203,7 +203,9 @@ func (h *processerPayload) Merge(params []byte) (types.Handler, error) { return nil, errors.New("could not register function, body empty") } - h.fn, _ = h.vm.RegisterFunction(h.params.Func) + if h.fn, err = h.vm.RegisterFunction(h.params.Func); err != nil { + return nil, fmt.Errorf("could not register function, invalid body: %s", err) + } return h, err } diff --git a/pkg/apigw/filter/processer_test.go b/pkg/apigw/filter/processer_test.go index 3129fc117..7e4e2fa0b 100644 --- a/pkg/apigw/filter/processer_test.go +++ b/pkg/apigw/filter/processer_test.go @@ -162,6 +162,15 @@ func Test_processerPayload(t *testing.T) { params: prepareFuncPayload(t, ``), errv: `could not register function, body empty`, }, + { + name: "payload processer invalid body", + rq: &http.Request{ + Method: "POST", + Body: ioutil.NopCloser(strings.NewReader(`[{"name":"johnny", "surname":"mnemonic"},{"name":"johnny", "surname":"knoxville"}]`)), + }, + params: prepareFuncPayload(t, `.foo`), + errv: `could not register function, invalid body: could not transform payload: Unexpected "."`, + }, } )