@@ -114,6 +114,63 @@ pub struct SessionConfig {
114114
115115 /// The schedule configuration for the session
116116 pub schedule : Option < ScheduleConfig > ,
117+
118+ /// The validation configuration for the session
119+ #[ serde( default ) ]
120+ pub validation : ValidationConfig ,
121+ }
122+
123+ #[ derive( Clone , Debug , Deserialize ) ]
124+ /// The configuration of validation rules.
125+ pub struct ValidationConfig {
126+ /// Specifies whether unknown user-defined tags (>= 5000) should cause the message to be rejected.
127+ #[ serde( default = "default_true" ) ]
128+ pub validate_user_defined_fields : bool ,
129+ }
130+
131+ impl ValidationConfig {
132+ pub fn builder ( ) -> VerificationConfigBuilder {
133+ VerificationConfigBuilder :: default ( )
134+ }
135+ }
136+
137+ impl Default for ValidationConfig {
138+ fn default ( ) -> Self {
139+ VerificationConfigBuilder :: default ( ) . build ( )
140+ }
141+ }
142+
143+ pub struct VerificationConfigBuilder {
144+ validate_user_defined_fields : bool ,
145+ }
146+
147+ impl Default for VerificationConfigBuilder {
148+ fn default ( ) -> Self {
149+ Self {
150+ validate_user_defined_fields : true ,
151+ }
152+ }
153+ }
154+
155+ impl VerificationConfigBuilder {
156+ pub fn new ( ) -> Self {
157+ Self :: default ( )
158+ }
159+
160+ pub fn validate_user_defined_fields ( mut self , value : bool ) -> Self {
161+ self . validate_user_defined_fields = value;
162+ self
163+ }
164+
165+ pub fn build ( self ) -> ValidationConfig {
166+ ValidationConfig {
167+ validate_user_defined_fields : self . validate_user_defined_fields ,
168+ }
169+ }
170+ }
171+
172+ fn default_true ( ) -> bool {
173+ true
117174}
118175
119176/// Errors that may occur when loading configuration.
@@ -170,6 +227,7 @@ reset_on_logon = false
170227 assert_eq ! ( session_config. tls_config, Some ( expected_tls_config) ) ;
171228 assert_eq ! ( session_config. reconnect_interval, 30 ) ;
172229 assert_eq ! ( session_config. logon_timeout, 10 ) ;
230+ assert ! ( session_config. validation. validate_user_defined_fields) ;
173231 }
174232
175233 #[ test]
@@ -439,6 +497,45 @@ end_day = "Friday"
439497 assert_eq ! ( session_config. reconnect_interval, 15 ) ;
440498 }
441499
500+ #[ test]
501+ fn test_verification_config_defaults_when_omitted ( ) {
502+ let config_contents = r#"
503+ [[sessions]]
504+ begin_string = "FIX.4.4"
505+ sender_comp_id = "send-comp-id"
506+ target_comp_id = "target-comp-id"
507+ connection_port = 443
508+ connection_host = "127.0.0.1"
509+ heartbeat_interval = 30
510+ "# ;
511+
512+ let config: Config = toml:: from_str ( config_contents) . unwrap ( ) ;
513+ let session_config = config. sessions . first ( ) . unwrap ( ) ;
514+
515+ assert ! ( session_config. validation. validate_user_defined_fields) ;
516+ }
517+
518+ #[ test]
519+ fn test_verification_config_can_disable_user_defined_field_validation ( ) {
520+ let config_contents = r#"
521+ [[sessions]]
522+ begin_string = "FIX.4.4"
523+ sender_comp_id = "send-comp-id"
524+ target_comp_id = "target-comp-id"
525+ connection_port = 443
526+ connection_host = "127.0.0.1"
527+ heartbeat_interval = 30
528+
529+ [sessions.validation]
530+ validate_user_defined_fields = false
531+ "# ;
532+
533+ let config: Config = toml:: from_str ( config_contents) . unwrap ( ) ;
534+ let session_config = config. sessions . first ( ) . unwrap ( ) ;
535+
536+ assert ! ( !session_config. validation. validate_user_defined_fields) ;
537+ }
538+
442539 #[ test]
443540 fn test_load_from_path_success ( ) {
444541 let config_contents = r#"
0 commit comments