Skip to content

Commit

Permalink
test(rfc5424): add fuzzing test for parmeter escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota authored and leodido committed Sep 18, 2024
1 parent 12554a4 commit 46afcec
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rfc5424/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package rfc5424

import (
"testing"
"time"

"github.com/stretchr/testify/require"
)

func FuzzParameterEscaping(f *testing.F) {
for _, r := range []string{
``,
`{"escape\x20me": [""]}`,
`хлеб`, // test unicode
`🇺🇬👁️‍🗨️`, // test grapheme cluster
} {
f.Add(r)
}

f.Fuzz(func(t *testing.T, payload string) {
msg := new(SyslogMessage)
msg.SetPriority(1)
msg.SetVersion(1)
msg.SetTimestamp(time.Now().Format(time.RFC3339))
msg.SetMessage("hello")
msg.SetParameter("general@0", "payload", payload)

data, err := msg.String()
require.NoError(t, err)

parsed, err := NewParser().Parse([]byte(data))
require.NoError(t, err)
require.Equal(t, msg, parsed)
})
}

0 comments on commit 46afcec

Please sign in to comment.