Skip to content

Commit

Permalink
implement TX v4 experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
jptosso committed Nov 6, 2024
1 parent de409e3 commit b1a31a5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions experimental/transaction.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0

package experimental

import "github.com/corazawaf/coraza/v3/types"

type Transaction interface {
types.Transaction
UnixTimestamp() int64
}
26 changes: 26 additions & 0 deletions experimental/transaction_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0

package experimental_test

import (
"testing"

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

func TestTxTimestamp(t *testing.T) {
waf, err := coraza.NewWAF(coraza.NewWAFConfig())
if err != nil {
panic(err)
}
tx := waf.NewTransaction()
tx2, ok := tx.(experimental.Transaction)
if !ok {
t.Error("Transaction does not implement experimental.Transaction")
}
if tx2.UnixTimestamp() == 0 {
t.Error("Timestamp should not be 0")
}
}
4 changes: 4 additions & 0 deletions internal/corazawaf/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,10 @@ func (tx *Transaction) String() string {
return res.String()
}

func (tx *Transaction) UnixTimestamp() int64 {
return tx.Timestamp
}

// generateRequestBodyError generates all the error variables for the request body parser
func (tx *Transaction) generateRequestBodyError(err error) {
tx.variables.reqbodyError.Set("1")
Expand Down

0 comments on commit b1a31a5

Please sign in to comment.