diff --git a/condition/format_json_test.go b/condition/format_json_test.go index 28c8f314..a852821b 100644 --- a/condition/format_json_test.go +++ b/condition/format_json_test.go @@ -87,3 +87,30 @@ func BenchmarkFormatJSONByte(b *testing.B) { ) } } + +func FuzzTestFormatJSON(f *testing.F) { + testcases := [][]byte{ + []byte(`{"hello":"world"}`), + []byte(`["a","b","c"]`), + []byte(`{hello:"world"}`), + []byte(`a`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newFormatJSON(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/format_mime_test.go b/condition/format_mime_test.go index 104fd7ca..14c74991 100644 --- a/condition/format_mime_test.go +++ b/condition/format_mime_test.go @@ -121,3 +121,30 @@ func BenchmarkFormatMIME(b *testing.B) { ) } } + +func FuzzTestFormatMIME(f *testing.F) { + testcases := [][]byte{ + []byte(`{"hello":"world"}`), + []byte(`["a","b","c"]`), + []byte(`{hello:"world"}`), + []byte(`a`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newFormatMIME(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/meta_all_test.go b/condition/meta_all_test.go index d636cb6f..31fdd48f 100644 --- a/condition/meta_all_test.go +++ b/condition/meta_all_test.go @@ -177,3 +177,43 @@ func TestAllCondition(t *testing.T) { }) } } + +func FuzzTestMetaAll(f *testing.F) { + testcases := [][]byte{ + []byte(`{"z":"a"}`), + []byte(`["a","a","b"]`), + []byte(`["a","a","a"]`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newMetaAll(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "@this", + }, + "conditions": []config.Config{ + { + Type: "string_contains", + Settings: map[string]interface{}{ + "value": "a", + }, + }, + }, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/meta_any_test.go b/condition/meta_any_test.go index 9ed2f46b..f706f068 100644 --- a/condition/meta_any_test.go +++ b/condition/meta_any_test.go @@ -177,3 +177,43 @@ func TestAnyCondition(t *testing.T) { }) } } + +func FuzzTestMetaAny(f *testing.F) { + testcases := [][]byte{ + []byte(`{"z":"a"}`), + []byte(`["a","b","c"]`), + []byte(`["a","a","a"]`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newMetaAny(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "@this", + }, + "conditions": []config.Config{ + { + Type: "string_contains", + Settings: map[string]interface{}{ + "value": "a", + }, + }, + }, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/meta_none_test.go b/condition/meta_none_test.go index 653431ec..b5cec470 100644 --- a/condition/meta_none_test.go +++ b/condition/meta_none_test.go @@ -177,3 +177,43 @@ func TestNoneCondition(t *testing.T) { }) } } + +func FuzzTestMetaNone(f *testing.F) { + testcases := [][]byte{ + []byte(`{"z":"a"}`), + []byte(`["b","b","b"]`), + []byte(`["a","b","c"]`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newMetaNone(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "@this", + }, + "conditions": []config.Config{ + { + Type: "string_contains", + Settings: map[string]interface{}{ + "value": "a", + }, + }, + }, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_global_unicast_test.go b/condition/network_ip_global_unicast_test.go index 71df8db8..8ca41341 100644 --- a/condition/network_ip_global_unicast_test.go +++ b/condition/network_ip_global_unicast_test.go @@ -69,3 +69,30 @@ func BenchmarkNetworkIPGlobalUnicastByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPGlobalUnicast(f *testing.F) { + testcases := [][]byte{ + []byte(`{"ip":"192.168.1.1"}`), + []byte(`{"ip":"2001:0db8:85a3:0000:0000:8a2e:0370:7334"}`), + []byte(`{"ip":"255.255.255.255"}`), + []byte(`{"ip":"::1"}`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPGlobalUnicast(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_link_local_multicast_test.go b/condition/network_ip_link_local_multicast_test.go index a4de5109..33b95bfe 100644 --- a/condition/network_ip_link_local_multicast_test.go +++ b/condition/network_ip_link_local_multicast_test.go @@ -69,3 +69,30 @@ func BenchmarkNetworkIPLinkLocalMulticastByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPLinkLocalMulticast(f *testing.F) { + testcases := [][]byte{ + []byte("224.0.0.12"), + []byte("224.0.0.1"), + []byte("239.255.255.255"), + []byte("192.168.1.1"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPLinkLocalMulticast(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_link_local_unicast_test.go b/condition/network_ip_link_local_unicast_test.go index 3b21ee4e..89d7e034 100644 --- a/condition/network_ip_link_local_unicast_test.go +++ b/condition/network_ip_link_local_unicast_test.go @@ -69,3 +69,30 @@ func BenchmarkNetworkIPLinkLocalUnicastByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPLinkLocalUnicast(f *testing.F) { + testcases := [][]byte{ + []byte("169.254.255.255"), + []byte("169.254.0.1"), + []byte("192.168.1.1"), + []byte("10.0.0.1"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPLinkLocalUnicast(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_loopback_test.go b/condition/network_ip_loopback_test.go index cd07e6bc..ac02f201 100644 --- a/condition/network_ip_loopback_test.go +++ b/condition/network_ip_loopback_test.go @@ -75,3 +75,30 @@ func BenchmarkNetworkIPLoopbackByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPLoopback(f *testing.F) { + testcases := [][]byte{ + []byte("127.0.0.1"), + []byte("8.8.8.8"), + []byte("::1"), + []byte("192.168.1.1"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPLoopback(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_multicast_test.go b/condition/network_ip_multicast_test.go index 7c7c27fc..891add80 100644 --- a/condition/network_ip_multicast_test.go +++ b/condition/network_ip_multicast_test.go @@ -69,3 +69,30 @@ func BenchmarkNetworkIPMulticastByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPMulticast(f *testing.F) { + testcases := [][]byte{ + []byte("224.0.0.12"), + []byte("239.255.255.255"), + []byte("192.168.1.1"), + []byte("10.0.0.1"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPMulticast(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_private_test.go b/condition/network_ip_private_test.go index 5d2e270e..b27d7768 100644 --- a/condition/network_ip_private_test.go +++ b/condition/network_ip_private_test.go @@ -81,3 +81,36 @@ func BenchmarkNetworkIPPrivateByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPPrivate(f *testing.F) { + testcases := [][]byte{ + []byte("8.8.8.8"), + []byte(`{"ip_address":"192.168.1.2"}`), + []byte("10.0.0.1"), + []byte("172.16.0.1"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPPrivate(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "ip_address", + }, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_unicast_test.go b/condition/network_ip_unicast_test.go index 5e35668b..b08c0161 100644 --- a/condition/network_ip_unicast_test.go +++ b/condition/network_ip_unicast_test.go @@ -69,3 +69,30 @@ func BenchmarkNetworkIPUnicastByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPUnicast(f *testing.F) { + testcases := [][]byte{ + []byte("223.255.255.255"), + []byte("192.168.1.1"), + []byte("10.0.0.1"), + []byte("8.8.8.8"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPUnicast(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_unspecified_test.go b/condition/network_ip_unspecified_test.go index 74272cad..fb961cba 100644 --- a/condition/network_ip_unspecified_test.go +++ b/condition/network_ip_unspecified_test.go @@ -69,3 +69,30 @@ func BenchmarkNetworkIPUnspecifiedByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPUnspecified(f *testing.F) { + testcases := [][]byte{ + []byte("0.0.0.0"), + []byte("192.168.1.1"), + []byte("::"), + []byte("255.255.255.255"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPUnspecified(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/network_ip_valid_test.go b/condition/network_ip_valid_test.go index 378aa83e..35ef5a24 100644 --- a/condition/network_ip_valid_test.go +++ b/condition/network_ip_valid_test.go @@ -69,3 +69,31 @@ func BenchmarkNetworkIPValidByte(b *testing.B) { ) } } + +func FuzzTestNetworkIPValid(f *testing.F) { + testcases := [][]byte{ + []byte("192.168.1.1"), + []byte("8.8.8.8"), + []byte("255.255.255.255"), + []byte("::1"), + []byte("2001:0db8:85a3:0000:0000:8a2e:0370:7334"), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNetworkIPValid(ctx, config.Config{}) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_bitwise_and_test.go b/condition/number_bitwise_and_test.go index 35f7008f..ff561d65 100644 --- a/condition/number_bitwise_and_test.go +++ b/condition/number_bitwise_and_test.go @@ -85,3 +85,34 @@ func BenchmarkNumberBitwiseAND(b *testing.B) { ) } } + +func FuzzTestNumberBitwiseAND(f *testing.F) { + testcases := [][]byte{ + []byte(`570506001`), + []byte(`123456789`), + []byte(`0`), + []byte(`18446744073709551615`), // Max uint64 value + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberBitwiseAND(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": 0x0001, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_bitwise_not_test.go b/condition/number_bitwise_not_test.go new file mode 100644 index 00000000..ef59832a --- /dev/null +++ b/condition/number_bitwise_not_test.go @@ -0,0 +1,145 @@ +package condition + +import ( + "context" + "testing" + + "github.com/brexhq/substation/v2/config" + "github.com/brexhq/substation/v2/message" +) + +var numberBitwiseNOTTests = []struct { + name string + cfg config.Config + test []byte + expected bool +}{ + { + "pass", + config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "value": "", + }, + }, + }, + []byte(`570506001`), + true, + }, + { + "pass", + config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "value": "", + }, + }, + }, + []byte(`123456789`), + true, + }, + { + "pass", + config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "value": "", + }, + }, + }, + []byte(`0`), + true, + }, + { + "fail", + config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "value": "", + }, + }, + }, + []byte(`-1`), + false, + }, +} + +func TestNumberBitwiseNOT(t *testing.T) { + ctx := context.TODO() + + for _, test := range numberBitwiseNOTTests { + t.Run(test.name, func(t *testing.T) { + message := message.New().SetData(test.test) + insp, err := newNumberBitwiseNOT(ctx, test.cfg) + if err != nil { + t.Fatal(err) + } + + check, err := insp.Condition(ctx, message) + if err != nil { + t.Error(err) + } + + if test.expected != check { + t.Errorf("expected %v, got %v, %v", test.expected, check, string(test.test)) + } + }) + } +} + +func benchmarkNumberBitwiseNOT(b *testing.B, insp *numberBitwiseNOT, message *message.Message) { + ctx := context.TODO() + for i := 0; i < b.N; i++ { + _, _ = insp.Condition(ctx, message) + } +} + +func BenchmarkNumberBitwiseNOT(b *testing.B) { + for _, test := range numberBitwiseNOTTests { + insp, err := newNumberBitwiseNOT(context.TODO(), test.cfg) + if err != nil { + b.Fatal(err) + } + + b.Run(test.name, + func(b *testing.B) { + message := message.New().SetData(test.test) + benchmarkNumberBitwiseNOT(b, insp, message) + }, + ) + } +} + +func FuzzTestNumberBitwiseNOT(f *testing.F) { + testcases := [][]byte{ + []byte(`570506001`), + []byte(`123456789`), + []byte(`0`), + []byte(`-1`), + []byte(`18446744073709551615`), // Max uint64 value + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberBitwiseNOT(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "", + }, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_bitwise_or_test.go b/condition/number_bitwise_or_test.go index 0880c9aa..bc7358f0 100644 --- a/condition/number_bitwise_or_test.go +++ b/condition/number_bitwise_or_test.go @@ -75,3 +75,35 @@ func BenchmarkNumberBitwiseOR(b *testing.B) { ) } } + +func FuzzTestNumberBitwiseOR(f *testing.F) { + testcases := [][]byte{ + []byte(`570506001`), + []byte(`123456789`), + []byte(`0`), + []byte(`-1`), + []byte(`18446744073709551615`), // Max uint64 value + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberBitwiseOR(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": 0x0001, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_bitwise_xor_test.go b/condition/number_bitwise_xor_test.go index 8d2ebdfe..a027d1a2 100644 --- a/condition/number_bitwise_xor_test.go +++ b/condition/number_bitwise_xor_test.go @@ -75,3 +75,34 @@ func BenchmarkNumberBitwiseXOR(b *testing.B) { ) } } + +func FuzzTestNumberBitwiseXOR(f *testing.F) { + testcases := [][]byte{ + []byte(`0`), + []byte(`123456789`), + []byte(`570506001`), + []byte(`18446744073709551615`), // Max uint64 value + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberBitwiseXOR(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": -1, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_equal_to_test.go b/condition/number_equal_to_test.go index 3943a60c..91f264b0 100644 --- a/condition/number_equal_to_test.go +++ b/condition/number_equal_to_test.go @@ -183,3 +183,35 @@ func BenchmarkNumberEqualTo(b *testing.B) { ) } } + +func FuzzTestNumberEqualTo(f *testing.F) { + testcases := [][]byte{ + []byte(`123`), + []byte(`456`), + []byte(`789`), + []byte(`0`), + []byte(`-123`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberEqualTo(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": 123, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_greater_than_test.go b/condition/number_greater_than_test.go index dd40ba2a..bccbf536 100644 --- a/condition/number_greater_than_test.go +++ b/condition/number_greater_than_test.go @@ -183,3 +183,37 @@ func BenchmarkNumberGreaterThan(b *testing.B) { ) } } + +func FuzzTestNumberGreaterThan(f *testing.F) { + testcases := [][]byte{ + []byte(`{"foo":1}`), + []byte(`1`), + []byte(`1.5`), + []byte(`{"foo":1.1}`), + []byte(`10`), + []byte(`-5`), + []byte(`0`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberGreaterThan(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": 1, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_length_equal_to_test.go b/condition/number_length_equal_to_test.go index 67fb1364..6331a8ca 100644 --- a/condition/number_length_equal_to_test.go +++ b/condition/number_length_equal_to_test.go @@ -111,3 +111,39 @@ func BenchmarkNumberLengthEqualTo(b *testing.B) { ) } } + +func FuzzTestNumberLengthEqualTo(f *testing.F) { + testcases := [][]byte{ + []byte(`{"a":"bcd"}`), + []byte(`bcd`), + []byte(`{"a":"bcde"}`), + []byte(`abcd`), + []byte(`{"a":""}`), + []byte(`""`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberLengthEqualTo(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "a", + }, + "value": 3, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_length_greater_than_test.go b/condition/number_length_greater_than_test.go index 251ea9e5..5f612bc8 100644 --- a/condition/number_length_greater_than_test.go +++ b/condition/number_length_greater_than_test.go @@ -111,3 +111,39 @@ func BenchmarkNumberLengthGreaterThan(b *testing.B) { ) } } + +func FuzzTestNumberLengthGreaterThan(f *testing.F) { + testcases := [][]byte{ + []byte(`{"foo":"bar"}`), + []byte(`bar`), + []byte(`{"foo":"ba"}`), + []byte(`ba`), + []byte(`{"foo":""}`), + []byte(`""`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberLengthGreaterThan(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "foo", + }, + "value": 2, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_length_less_than_test.go b/condition/number_length_less_than_test.go index a287ca35..f7c50d67 100644 --- a/condition/number_length_less_than_test.go +++ b/condition/number_length_less_than_test.go @@ -111,3 +111,39 @@ func BenchmarkNumberLengthLessThan(b *testing.B) { ) } } + +func FuzzTestNumberLengthLessThan(f *testing.F) { + testcases := [][]byte{ + []byte(`{"foo":"bar"}`), + []byte(`bar`), + []byte(`{"foo":"bars"}`), + []byte(`bars`), + []byte(`{"foo":""}`), + []byte(`""`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberLengthLessThan(ctx, config.Config{ + Settings: map[string]interface{}{ + "object": map[string]interface{}{ + "source_key": "foo", + }, + "value": 4, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/number_less_than_test.go b/condition/number_less_than_test.go index 7bffe8d7..02c28cd5 100644 --- a/condition/number_less_than_test.go +++ b/condition/number_less_than_test.go @@ -183,3 +183,37 @@ func BenchmarkNumberLessThan(b *testing.B) { ) } } + +func FuzzTestNumberLessThan(f *testing.F) { + testcases := [][]byte{ + []byte(`{"foo":1}`), + []byte(`1`), + []byte(`1.5`), + []byte(`{"foo":0.5}`), + []byte(`10`), + []byte(`-5`), + []byte(`0`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newNumberLessThan(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": 5, + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_contains_test.go b/condition/string_contains_test.go index a3f78c32..a92ac78c 100644 --- a/condition/string_contains_test.go +++ b/condition/string_contains_test.go @@ -84,3 +84,36 @@ func BenchmarkStringContains(b *testing.B) { ) } } + +func FuzzTestStringContains(f *testing.F) { + testcases := [][]byte{ + []byte(`{"foo":"bar"}`), + []byte(`bar`), + []byte(`{"foo":"baz"}`), + []byte(`baz`), + []byte(`{"foo":""}`), + []byte(`""`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringContains(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": "bar", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_ends_with_test.go b/condition/string_ends_with_test.go index a345f57e..03fd59e1 100644 --- a/condition/string_ends_with_test.go +++ b/condition/string_ends_with_test.go @@ -97,3 +97,36 @@ func BenchmarkStringEndsWith(b *testing.B) { ) } } + +func FuzzTestStringEndsWith(f *testing.F) { + testcases := [][]byte{ + []byte(`{"a":"bcde"}`), + []byte(`bcde`), + []byte(`{"a":"abcd"}`), + []byte(`abcd`), + []byte(`{"a":""}`), + []byte(`""`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringEndsWith(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": "de", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_equal_to_test.go b/condition/string_equal_to_test.go index 24e20dab..33785ca3 100644 --- a/condition/string_equal_to_test.go +++ b/condition/string_equal_to_test.go @@ -121,3 +121,36 @@ func BenchmarkStringEqualTo(b *testing.B) { ) } } + +func FuzzTestStringEqualTo(f *testing.F) { + testcases := [][]byte{ + []byte(`"abcde"`), + []byte(`"abcdef"`), + []byte(`""`), + []byte(`"abcd"`), + []byte(`"12345"`), + []byte(`"abc"`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringEqualTo(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": "abcde", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_greater_than_test.go b/condition/string_greater_than_test.go index 49fbf0f5..1b3a3ed6 100644 --- a/condition/string_greater_than_test.go +++ b/condition/string_greater_than_test.go @@ -111,3 +111,36 @@ func BenchmarkStringGreaterThan(b *testing.B) { ) } } + +func FuzzTestStringGreaterThan(f *testing.F) { + testcases := [][]byte{ + []byte(`"b"`), + []byte(`"2023-01-01T00:00:00Z"`), + []byte(`{"foo":"2023-01-01T00:00:00Z", "bar":"2022-01-01T00:00:00Z"}`), + []byte(`"a"`), + []byte(`"z"`), + []byte(`" "`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringGreaterThan(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": "a", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_less_than_test.go b/condition/string_less_than_test.go index a41be617..0c341c6e 100644 --- a/condition/string_less_than_test.go +++ b/condition/string_less_than_test.go @@ -111,3 +111,36 @@ func BenchmarkStringLessThan(b *testing.B) { ) } } + +func FuzzTestStringLessThan(f *testing.F) { + testcases := [][]byte{ + []byte(`"a"`), + []byte(`"2022-01-01T00:00:00Z"`), + []byte(`{"foo":"2022-01-01T00:00:00Z", "bar":"2023-01-01T00:00:00Z"}`), + []byte(`"b"`), + []byte(`" "`), + []byte(`"z"`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringLessThan(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": "b", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_match_test.go b/condition/string_match_test.go index 13424977..7cbfeee7 100644 --- a/condition/string_match_test.go +++ b/condition/string_match_test.go @@ -83,3 +83,35 @@ func BenchmarkStringMatchByte(b *testing.B) { ) } } + +func FuzzTestStringMatch(f *testing.F) { + testcases := [][]byte{ + []byte("Test"), + []byte("-Test"), + []byte("AnotherTest"), + []byte("123Test"), + []byte(""), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringMatch(ctx, config.Config{ + Settings: map[string]interface{}{ + "pattern": "^Test", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +} diff --git a/condition/string_starts_with_test.go b/condition/string_starts_with_test.go index ff13e75f..625b26fd 100644 --- a/condition/string_starts_with_test.go +++ b/condition/string_starts_with_test.go @@ -97,3 +97,36 @@ func BenchmarkStringStartsWith(b *testing.B) { ) } } + +func FuzzTestStringStartsWith(f *testing.F) { + testcases := [][]byte{ + []byte(`{"foo":"bar"}`), + []byte(`bar`), + []byte(`{"foo":"baz"}`), + []byte(`baz`), + []byte(`{"foo":""}`), + []byte(`""`), + } + + for _, tc := range testcases { + f.Add(tc) + } + + f.Fuzz(func(t *testing.T, data []byte) { + ctx := context.TODO() + message := message.New().SetData(data) + insp, err := newStringStartsWith(ctx, config.Config{ + Settings: map[string]interface{}{ + "value": "bar", + }, + }) + if err != nil { + return + } + + _, err = insp.Condition(ctx, message) + if err != nil { + return + } + }) +}