diff --git a/go.mod b/go.mod index d600ded..88eaaf0 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,7 @@ require ( github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230615193820-9185820289ce // indirect github.com/nspcc-dev/rfc6979 v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/twmb/murmur3 v1.1.8 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/goleak v1.2.1 // indirect diff --git a/go.sum b/go.sum index 754d2d7..f9212b2 100644 Binary files a/go.sum and b/go.sum differ diff --git a/netmap/policy_decode_test.go b/netmap/policy_decode_test.go index f42d3b5..536d66b 100644 --- a/netmap/policy_decode_test.go +++ b/netmap/policy_decode_test.go @@ -7,50 +7,50 @@ import ( "github.com/stretchr/testify/require" ) -func TestDecodeString(t *testing.T) { - testCases := []string{ - `REP 2 +var validPlacementPolicy = []string{ + `REP 2 CBF 2 SELECT 2 FROM *`, - `REP 1 IN X + `REP 1 IN X CBF 1 SELECT 2 IN SAME Location FROM * AS X`, - `REP 1 IN X + `REP 1 IN X REP 2 IN Y CBF 1 SELECT 2 FROM * AS X SELECT 3 FROM * AS Y`, - `REP 1 IN X + `REP 1 IN X SELECT 2 IN City FROM Good AS X FILTER Country EQ RU AS FromRU FILTER Country EQ EN AS FromEN FILTER @FromRU AND @FromEN AND Rating GT 7 AS Good`, - `REP 7 IN SPB + `REP 7 IN SPB SELECT 1 IN City FROM SPBSSD AS SPB FILTER City EQ SPB AND SSD EQ true OR City EQ SPB AND Rating GE 5 AS SPBSSD`, - `REP 7 IN SPB + `REP 7 IN SPB SELECT 1 IN City FROM SPBSSD AS SPB FILTER NOT (NOT (City EQ SPB) AND SSD EQ true OR City EQ SPB AND Rating GE 5) AS SPBSSD`, - `REP 1 IN FNODE + `REP 1 IN FNODE CBF 1 SELECT 1 FROM F AS FNODE FILTER Node EQ '10.78.8.11' AS F`, - `UNIQUE + `UNIQUE REP 1 REP 1`, - `EC 1.2 IN X + `EC 1.2 IN X SELECT 3 IN City FROM * AS X`, - } +} +func TestDecodeString(t *testing.T) { var p PlacementPolicy - for _, testCase := range testCases { + for _, testCase := range validPlacementPolicy { require.NoError(t, p.DecodeString(testCase), "unable parse %s", testCase) var b strings.Builder require.NoError(t, p.WriteStringTo(&b)) diff --git a/netmap/policy_fuzz.go b/netmap/policy_fuzz.go new file mode 100644 index 0000000..40088e9 --- /dev/null +++ b/netmap/policy_fuzz.go @@ -0,0 +1,14 @@ +//go:build gofuzz +// +build gofuzz + +package netmap + +func DoFuzzPlacementPolicyDecode(data []byte) int { + p := string(data) + if p == "" { + return 0 + } + var pp PlacementPolicy + _ = pp.DecodeString(p) + return 1 +} diff --git a/netmap/policy_fuzz_test.go b/netmap/policy_fuzz_test.go new file mode 100644 index 0000000..35b69a4 --- /dev/null +++ b/netmap/policy_fuzz_test.go @@ -0,0 +1,17 @@ +//go:build gofuzz +// +build gofuzz + +package netmap + +import ( + "testing" +) + +func FuzzDecodeString(f *testing.F) { + for _, pp := range validPlacementPolicy { + f.Add([]byte(pp)) + } + f.Fuzz(func(t *testing.T, data []byte) { + DoFuzzPlacementPolicyDecode(data) + }) +}