diff --git a/experimental/transaction.go b/experimental/transaction.go new file mode 100644 index 000000000..adf9d931e --- /dev/null +++ b/experimental/transaction.go @@ -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 +} diff --git a/experimental/transaction_test.go b/experimental/transaction_test.go new file mode 100644 index 000000000..d434e406c --- /dev/null +++ b/experimental/transaction_test.go @@ -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") + } +} diff --git a/internal/corazawaf/transaction.go b/internal/corazawaf/transaction.go index 1a4785b90..978a32272 100644 --- a/internal/corazawaf/transaction.go +++ b/internal/corazawaf/transaction.go @@ -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")