Skip to content

Commit

Permalink
feat: add coraza_add_get_args to expose tx.AddGetRequestArgument (#34)
Browse files Browse the repository at this point in the history
* feat: add  coraza_add_get_args to expose tx.AddGetRequestArgument

* test: add TestCoraza_add_get_args

---------

Co-authored-by: potatso <[email protected]>
  • Loading branch information
potats0 and potapo authored Jul 28, 2023
1 parent 8298ab4 commit 994164a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libcoraza/coraza.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions libcoraza/coraza_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/corazawaf/coraza/v3"
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes"
)

var waf *coraza.WAF
Expand All @@ -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)
Expand Down

0 comments on commit 994164a

Please sign in to comment.