From ef147e31496b367a00c84571ab6b9456ef6da472 Mon Sep 17 00:00:00 2001 From: potatso Date: Tue, 18 Jul 2023 12:09:21 +0800 Subject: [PATCH 1/2] feat: add coraza_add_get_args to expose tx.AddGetRequestArgument --- libcoraza/coraza.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libcoraza/coraza.go b/libcoraza/coraza.go index 6fad0a2..aab96ce 100644 --- a/libcoraza/coraza.go +++ b/libcoraza/coraza.go @@ -153,6 +153,13 @@ func coraza_append_request_body(t C.coraza_transaction_t, data *C.uchar, length return 0 } +//export coraza_add_get_args +func coraza_add_get_args(t C.coraza_transaction_t, name *C.char, value *C.char) C.int { + tx := ptrToTransaction(t) + tx.AddGetRequestArgument(C.GoString(name), C.GoString(value)) + return 0 +} + //export coraza_add_response_header func coraza_add_response_header(t C.coraza_transaction_t, name *C.char, name_len C.int, value *C.char, value_len C.int) C.int { tx := ptrToTransaction(t) From 62a5bc9cefad3e7dd54d5351eb74109a560adc9f Mon Sep 17 00:00:00 2001 From: potatso Date: Tue, 18 Jul 2023 20:32:35 +0800 Subject: [PATCH 2/2] test: add TestCoraza_add_get_args --- libcoraza/coraza_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libcoraza/coraza_test.go b/libcoraza/coraza_test.go index e7789d8..fb9b03c 100644 --- a/libcoraza/coraza_test.go +++ b/libcoraza/coraza_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/corazawaf/coraza/v3" + "github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes" ) var waf *coraza.WAF @@ -23,6 +24,29 @@ func TestWafIsConsistent(t *testing.T) { func TestAddRulesToWaf(t *testing.T) { } +func TestCoraza_add_get_args(t *testing.T) { + waf := coraza_new_waf() + tt := coraza_new_transaction(waf, nil) + coraza_add_get_args(tt, stringToC("aa"), stringToC("bb")) + tx := ptrToTransaction(tt) + txi := tx.(plugintypes.TransactionState) + argsGet := txi.Variables().ArgsGet() + value := argsGet.Get("aa") + if len(value) != 1 && value[0] != "bb" { + t.Fatal("coraza_add_get_args can't add args") + } + coraza_add_get_args(tt, stringToC("dd"), stringToC("ee")) + value = argsGet.Get("dd") + if len(value) != 1 && value[0] != "ee" { + t.Fatal("coraza_add_get_args can't add args with another key") + } + coraza_add_get_args(tt, stringToC("aa"), stringToC("cc")) + value = argsGet.Get("aa") + if len(value) != 2 && value[0] != "bb" && value[1] != "cc" { + t.Fatal("coraza_add_get_args can't add args with same key more than once") + } +} + func TestTransactionInitialization(t *testing.T) { waf := coraza_new_waf() tt := coraza_new_transaction(waf, nil)