Skip to content

Commit

Permalink
Add fuzz testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pkillarjun committed Nov 4, 2024
1 parent c7392e8 commit 9af7446
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ vet:
test:
MONGODB_TEST_CXN=mongodb://db:27017 go test -v -cover `go list ./... | grep -v quickfix/gen`

fuzz:
go test -fuzztime 600s -fuzz=FuzzParser .
go test -fuzztime 600s -fuzz=FuzzParseMessage .

linters-install:
@golangci-lint --version >/dev/null 2>&1 || { \
echo "installing linting tools..."; \
Expand Down
24 changes: 24 additions & 0 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,27 @@ func checkFieldString(s *MessageSuite, fields FieldMap, tag int, expected string
s.NoError(err)
s.Equal(expected, toCheck)
}

func FuzzParseMessage(f *testing.F) {

rawMsg_0 := "8=FIX.4.29=10435=D34=249=TW52=20140515-19:49:56.65956=ISLD11=10021=140=154=155=TSLA60=00010101-00:00:00.00010=039"

Check warning on line 521 in message_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var rawMsg_0 should be rawMsg0 (revive)
rawMsg_1 := "8=FIX.4.29=37235=n34=25512369=148152=20200522-07:05:33.75649=CME50=G56=OAEAAAN57=TRADE_CAPTURE143=US,IL212=261213=<RTRF>8=FIX.4.29=22535=BZ34=6549369=651852=20200522-07:05:33.74649=CME50=G56=9Q5000N57=DUMMY143=US,IL11=ACP159013113373460=20200522-07:05:33.734533=0893=Y1028=Y1300=991369=99612:325081373=31374=91375=15979=159013113373461769710=167</RTRF>10=245\""

Check warning on line 522 in message_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var rawMsg_1 should be rawMsg1 (revive)
rawMsg_2 := "8=FIX.4.29=10435=D34=249=TW52=20140515-19:49:56.65956=ISLD11=10021=140=154=155=TSLA60=00010101-00:00:00.00010=039"

Check warning on line 523 in message_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var rawMsg_2 should be rawMsg2 (revive)
rawMsg_3 := "8=FIX.4.29=12635=D34=249=TW52=20140515-19:49:56.65956=ISLD10030=CUST11=10021=140=154=155=TSLA60=00010101-00:00:00.0005050=HELLO10=039"

Check warning on line 524 in message_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var rawMsg_3 should be rawMsg3 (revive)
rawMsg_4 := "8=FIX.4.09=8135=D11=id21=338=10040=154=155=MSFT34=249=TW52=20140521-22:07:0956=ISLD10=250"

Check warning on line 525 in message_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var rawMsg_4 should be rawMsg4 (revive)

f.Add(rawMsg_0)
f.Add(rawMsg_1)
f.Add(rawMsg_2)
f.Add(rawMsg_3)
f.Add(rawMsg_4)

f.Fuzz(func(_ *testing.T, input string) {
if len(input) < 8 {
return
}

msg := NewMessage()
_ = ParseMessage(msg, bytes.NewBufferString(input))
})
}
22 changes: 22 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,25 @@ func (s *ParserSuite) TestReadMessageGrowBuffer() {
s.Equal(tc.expectedBufferLen, len(s.parser.buffer))
}
}

func FuzzParser(f *testing.F) {

stream_0 := "8=FIXT.1.19=11135=D34=449=TW52=20140511-23:10:3456=ISLD11=ID21=340=154=155=INTC60=20140511-23:10:3410=2348=FIXT.1.19=9535=D34=549=TW52=20140511-23:10:3456=ISLD11=ID21=340=154=155=INTC60=20140511-23:10:3410=198"

Check warning on line 192 in parser_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var stream_0 should be stream0 (revive)
stream_1 := "8=\x019=\x01"

Check warning on line 193 in parser_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var stream_1 should be stream1 (revive)
stream_2 := "8=\x019=9300000000000000000\x01"

Check warning on line 194 in parser_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var stream_2 should be stream2 (revive)
stream_3 := "hello8=FIX.4.09=5blah10=1038=FIX.4.09=4foo10=103"

Check warning on line 195 in parser_test.go

View workflow job for this annotation

GitHub Actions / Linter

var-naming: don't use underscores in Go names; var stream_3 should be stream3 (revive)

f.Add(stream_0)
f.Add(stream_1)
f.Add(stream_2)
f.Add(stream_3)

f.Fuzz(func(_ *testing.T, input string) {
if len(input) < 8 {
return
}

parser := newParser(strings.NewReader(input))
_, _ = parser.ReadMessage()
})
}

0 comments on commit 9af7446

Please sign in to comment.