@@ -2,8 +2,7 @@ use crate::common::actions::when;
22use crate :: common:: assertions:: { assert_msg_type, then} ;
33use crate :: common:: setup:: given_an_active_session;
44use crate :: common:: test_messages:: {
5- TestMessage , build_execution_report_with_incorrect_body_length,
6- build_resend_request_without_begin_seq_no,
5+ TestMessage , build_execution_report_with_incorrect_body_length, build_invalid_resend_request,
76} ;
87use hotfix:: message:: FixMessage ;
98use hotfix:: session:: Status ;
@@ -144,24 +143,28 @@ async fn test_resent_message_previously_received_is_ignored() {
144143 then ( & mut counterparty) . gets_disconnected ( ) . await ;
145144}
146145
147- /// Tests that when a counterparty sends a resend request without the required BeginSeqNo field,
148- /// the session rejects the malformed message.
146+ /// Tests that when a counterparty sends a resend request without the required field,
147+ /// the session rejects the invalid message.
149148#[ tokio:: test]
150- async fn test_resend_request_without_begin_seq_no_is_rejected ( ) {
151- let ( session, mut counterparty) = given_an_active_session ( ) . await ;
152-
153- // build a resend request message missing the required BeginSeqNo (tag 7)
154- let seq_num = counterparty. next_target_sequence_number ( ) ;
155- let invalid_resend_request = build_resend_request_without_begin_seq_no ( seq_num) ;
156- when ( & mut counterparty)
157- . sends_raw_message ( invalid_resend_request)
158- . await ;
149+ async fn test_invalid_resend_request_gets_rejected ( ) {
150+ // We run the test twice - once with an invalid BeginSeqNo and once with an invalid EndSeqNo.
151+ for ( begin_seq_no, end_seq_no) in [ ( None , Some ( 2 ) ) , ( Some ( 1 ) , None ) ] {
152+ let ( session, mut counterparty) = given_an_active_session ( ) . await ;
153+
154+ // build a resend request message missing the required BeginSeqNo (tag 7)
155+ let seq_num = counterparty. next_target_sequence_number ( ) ;
156+ let invalid_resend_request =
157+ build_invalid_resend_request ( seq_num, begin_seq_no, end_seq_no) ;
158+ when ( & mut counterparty)
159+ . sends_raw_message ( invalid_resend_request)
160+ . await ;
159161
160- // the session should reject this invalid resend request
161- then ( & mut counterparty)
162- . receives ( |msg| assert_msg_type ( msg, MsgType :: Reject ) )
163- . await ;
162+ // the session should reject this invalid resend request
163+ then ( & mut counterparty)
164+ . receives ( |msg| assert_msg_type ( msg, MsgType :: Reject ) )
165+ . await ;
164166
165- when ( & session) . requests_disconnect ( ) . await ;
166- then ( & mut counterparty) . gets_disconnected ( ) . await ;
167+ when ( & session) . requests_disconnect ( ) . await ;
168+ then ( & mut counterparty) . gets_disconnected ( ) . await ;
169+ }
167170}
0 commit comments