Skip to content

Commit 824b8f5

Browse files
authored
fix: diagnostics decoder improperly sets RulesData with ExclusionData diags (#134)
## Summary - fix ExclusionData not set by decoder - add unit test for ExclusionData diagnostics ## Testing - `go test ./...` *(fails: no route to host)* ------ https://chatgpt.com/codex/tasks/task_b_684bd9514c1883288b790c72b6b57d5e
1 parent 5bcb13a commit 824b8f5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

decoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func decodeDiagnostics(obj *bindings.WAFObject) (Diagnostics, error) {
7171
case "rules_data":
7272
diags.RulesData, err = decodeFeature(objElem)
7373
case "exclusion_data":
74-
diags.RulesData, err = decodeFeature(objElem)
74+
diags.ExclusionData, err = decodeFeature(objElem)
7575
case "rules_override":
7676
diags.RulesOverrides, err = decodeFeature(objElem)
7777
case "processors":

diagnostics_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
//go:build (amd64 || arm64) && (linux || darwin) && !go1.25 && !datadog.no_waf && (cgo || appsec)
7+
8+
package libddwaf
9+
10+
import (
11+
"runtime"
12+
"testing"
13+
14+
"github.com/stretchr/testify/require"
15+
)
16+
17+
func TestDecodeDiagnosticsExclusionData(t *testing.T) {
18+
var pinner runtime.Pinner
19+
defer pinner.Unpin()
20+
21+
encoder, err := newEncoder(newUnlimitedEncoderConfig(&pinner))
22+
require.NoError(t, err)
23+
24+
obj, err := encoder.Encode(map[string]any{
25+
"exclusion_data": map[string]any{
26+
"loaded": []any{"id1"},
27+
},
28+
})
29+
require.NoError(t, err)
30+
31+
diags, err := decodeDiagnostics(obj)
32+
require.NoError(t, err)
33+
require.NotNil(t, diags.ExclusionData)
34+
require.Contains(t, diags.ExclusionData.Loaded, "id1")
35+
}

0 commit comments

Comments
 (0)