-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
first persistence draft #866
Draft
jptosso
wants to merge
8
commits into
main
Choose a base branch
from
persistence
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c40c37
first persistence draft
jptosso 1b7d7ed
implement interfaces
jptosso bbe6d9c
full implementation
jptosso 59d3517
force init in tests
jptosso 9c88ae3
minor tweaks
jptosso 89268f4
ci fixes
jptosso 99e90b8
regex implementation and tests
jptosso db06ddb
fix race condition
jptosso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package plugins | ||
|
||
import ( | ||
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes" | ||
"github.com/corazawaf/coraza/v3/internal/persistence" | ||
) | ||
|
||
// RegisterPersistenceEngine registers a new persistence engine | ||
func RegisterPersistenceEngine(name string, engine plugintypes.PersistenceEngine) { | ||
persistence.Register(name, engine) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package plugintypes | ||
|
||
type PersistenceEngine interface { | ||
Open(uri string, ttl int) error | ||
Close() error | ||
Sum(collectionName string, collectionKey string, key string, sum int) error | ||
Get(collectionName string, collectionKey string, key string) (string, error) | ||
|
||
All(collectionName string, collectionKey string) (map[string]string, error) | ||
Set(collection string, collectionKey string, key string, value string) error | ||
Remove(collection string, collectionKey string, key string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package actions | ||
package actions_test | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
"github.com/corazawaf/coraza/v3" | ||
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes" | ||
"github.com/corazawaf/coraza/v3/internal/actions" | ||
) | ||
|
||
func TestInitcolInit(t *testing.T) { | ||
waf, _ := coraza.NewWAF(coraza.NewWAFConfig()) //nolint:errcheck | ||
initcol, err := actions.Get("initcol") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
t.Run("invalid argument", func(t *testing.T) { | ||
initcol := initcol() | ||
err := initcol.Init(nil, "foo") | ||
if err == nil { | ||
t.Errorf("expected error") | ||
if err := initcol.Init(&md{}, "test"); err == nil { | ||
t.Error("expected error") | ||
} | ||
}) | ||
|
||
t.Run("passing argument", func(t *testing.T) { | ||
initcol := initcol() | ||
err := initcol.Init(nil, "foo=bar") | ||
if err != nil { | ||
t.Errorf("unexpected error: %s", err.Error()) | ||
t.Run("editable variable", func(t *testing.T) { | ||
if err := initcol.Init(&md{}, "session=abcdef"); err != nil { | ||
t.Error(err) | ||
} | ||
txs := waf.NewTransaction().(plugintypes.TransactionState) | ||
initcol.Evaluate(&md{}, txs) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:build !tinygo | ||
// +build !tinygo | ||
|
||
package actions_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/corazawaf/coraza/v3" | ||
"github.com/corazawaf/coraza/v3/experimental/plugins/plugintypes" | ||
"github.com/corazawaf/coraza/v3/internal/actions" | ||
"github.com/corazawaf/coraza/v3/types/variables" | ||
) | ||
|
||
func TestPersistenceSetvar(t *testing.T) { | ||
a, err := actions.Get("setvar") | ||
if err != nil { | ||
t.Error("failed to get setvar action") | ||
} | ||
waf, err := coraza.NewWAF(coraza.NewWAFConfig().WithDirectives("SecPersistenceEngine default")) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
t.Run("SESSION should be set", func(t *testing.T) { | ||
if err := a.Init(&md{}, "SESSION.test=test"); err != nil { | ||
t.Errorf("unexpected error: %v", err) | ||
} | ||
tx := waf.NewTransaction() | ||
txs := tx.(plugintypes.TransactionState) | ||
a.Evaluate(&md{}, txs) | ||
col := txs.Collection(variables.Session) | ||
col.FindAll() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a breaking change, as it still implements Keyed and it keeps the same functions (?)