Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add coraza_add_get_args to expose tx.AddGetRequestArgument #34

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
potats0 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading