Skip to content

Commit

Permalink
don't fail if we can get a valid WAF handle
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMuller committed Nov 9, 2023
1 parent 65b7c61 commit 5ae4897
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
5 changes: 0 additions & 5 deletions handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ func NewHandle(rules any, keyObfuscatorRegex string, valueObfuscatorRegex string
return nil, fmt.Errorf("could not decode the WAF diagnostics: %w", err)
}

if err = diags.TopLevelError(); err != nil {
defer wafLib.wafDestroy(cHandle)
return nil, err
}

return &Handle{
cHandle: cHandle,
refCounter: atomic.NewInt32(1), // We count the handle itself in the counter
Expand Down
13 changes: 5 additions & 8 deletions handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package waf

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -26,7 +25,7 @@ func TestNewHandle(t *testing.T) {
waf.Close()
})

t.Run("rejects invalid WAF input", func(t *testing.T) {
t.Run("does not return error on partially invalid input", func(t *testing.T) {
for _, field := range []string{
"custom_rules",
"exclusions",
Expand All @@ -42,13 +41,11 @@ func TestNewHandle(t *testing.T) {
// And corrupt data for one particular field...
rules[field] = 1337.42

// Now ensure the WAF init rejects it appropriately
// Now ensure the WAF init does not err out (at least 1 rule is valid in this scenario)
waf, err := NewHandle(rules, "", "")
require.Error(t, err)
require.Equal(t, fmt.Sprintf("the WAF reported a top-level error: in %#v: bad cast, expected 'array', obtained 'float'", field), err.Error())
if waf != nil {
waf.Close()
}
require.NoError(t, err)
require.NotNil(t, waf)
waf.Close()
})
}
})
Expand Down

0 comments on commit 5ae4897

Please sign in to comment.