Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ const (
TimeStampPrecision string = "TimeStampPrecision"
MaxLatency string = "MaxLatency"
PersistMessages string = "PersistMessages"
RejectInvalidMessage string = "RejectInvalidMessage"
)
8 changes: 8 additions & 0 deletions config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ If set to N, fields that are out of order (i.e. body fields in the header, or he

Defaults to Y.

RejectInvalidMessage

If RejectInvalidMessage is set to N, zero errors will be thrown on reception of message that fails data dictionary validation. Valid Values:
Y
N

Defaults to Y.

CheckLatency

If set to Y, messages must be received from the counterparty within a defined number of seconds. It is useful to turn this off if a system uses localtime for it's timestamps instead of GMT. Valid Values:
Expand Down
6 changes: 6 additions & 0 deletions session_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func (f sessionFactory) newSession(
}
}

if settings.HasSetting(config.RejectInvalidMessage) {
if validatorSettings.RejectInvalidMessage, err = settings.BoolSetting(config.RejectInvalidMessage); err != nil {
return
}
}

if sessionID.IsFIXT() {
if s.DefaultApplVerID, err = settings.Setting(config.DefaultApplVerID); err != nil {
return
Expand Down
17 changes: 12 additions & 5 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ type validator interface {

type validatorSettings struct {
CheckFieldsOutOfOrder bool
RejectInvalidMessage bool

}

//Default configuration for message validation.
//See http://www.quickfixengine.org/quickfix/doc/html/configuration.html.
var defaultValidatorSettings = validatorSettings{
CheckFieldsOutOfOrder: true,
RejectInvalidMessage: true,
}

type fixValidator struct {
Expand Down Expand Up @@ -74,14 +77,18 @@ func validateFIX(d *datadictionary.DataDictionary, settings validatorSettings, m
}
}

if err := validateFields(d, d, msgType, msg); err != nil {
return err
}
if settings.RejectInvalidMessage {
if err := validateFields(d, d, msgType, msg); err != nil {
return err
}

if err := validateWalk(d, d, msgType, msg); err != nil {
return err
if err := validateWalk(d, d, msgType, msg); err != nil {
return err
}
}



return nil
}

Expand Down
39 changes: 39 additions & 0 deletions validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestValidate(t *testing.T) {
tcTagIsDefinedForMessage(),
tcFieldNotFoundBody(),
tcFieldNotFoundHeader(),
tcInvalidTagCheckDisabled(),
tcInvalidTagCheckEnabled(),
}

msg := NewMessage()
Expand Down Expand Up @@ -378,6 +380,43 @@ func tcTagSpecifiedOutOfRequiredOrderTrailer() validateTest {
}
}

func tcInvalidTagCheckDisabled() validateTest {
dict, _ := datadictionary.Parse("spec/FIX40.xml")
validator := &fixValidator{dict, defaultValidatorSettings}
validator.settings.RejectInvalidMessage = false

builder := createFIX40NewOrderSingle()
tag := Tag(9999)
builder.Body.SetField(tag, FIXString("hello"))
msgBytes := builder.build()

return validateTest{
TestName: "Invalid Tag Check - Disabled",
Validator: validator,
MessageBytes: msgBytes,
DoNotExpectReject: true,
}
}

func tcInvalidTagCheckEnabled() validateTest {
dict, _ := datadictionary.Parse("spec/FIX40.xml")
validator := &fixValidator{dict, defaultValidatorSettings}
validator.settings.RejectInvalidMessage = true

builder := createFIX40NewOrderSingle()
tag := Tag(9999)
builder.Body.SetField(tag, FIXString("hello"))
msgBytes := builder.build()

return validateTest{
TestName: "Invalid Tag Check - Enabled",
Validator: validator,
MessageBytes: msgBytes,
DoNotExpectReject: false,
ExpectedRefTagID: &tag,
}
}

func tcTagSpecifiedOutOfRequiredOrderDisabledHeader() validateTest {
dict, _ := datadictionary.Parse("spec/FIX40.xml")
validator := &fixValidator{dict, defaultValidatorSettings}
Expand Down