Skip to content

Commit a24a706

Browse files
committed
Add test case for invalid EndSeqNo in resend requests
1 parent 21737c6 commit a24a706

2 files changed

Lines changed: 34 additions & 22 deletions

File tree

crates/hotfix/tests/common/test_messages.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,23 @@ pub fn replace_field_value(raw_message: &mut Vec<u8>, tag: u32, new_value: &[u8]
375375
}
376376

377377
/// Builds a resend request message without the required BeginSeqNo field.
378-
pub fn build_resend_request_without_begin_seq_no(msg_seq_num: u64) -> Vec<u8> {
378+
pub fn build_invalid_resend_request(
379+
msg_seq_num: u64,
380+
begin_seq_no: Option<u64>,
381+
end_seq_no: Option<u64>,
382+
) -> Vec<u8> {
379383
let mut msg = Message::new("FIX.4.4", "2"); // MsgType 2 = ResendRequest
380384
msg.set(fix44::SENDER_COMP_ID, COUNTERPARTY_COMP_ID);
381385
msg.set(fix44::TARGET_COMP_ID, OUR_COMP_ID);
382386
msg.set(fix44::MSG_SEQ_NUM, msg_seq_num);
383387
msg.set(fix44::SENDING_TIME, Timestamp::utc_now());
384-
// Intentionally omit BeginSeqNo (tag 7)
385-
msg.set(fix44::END_SEQ_NO, 2);
388+
389+
if let Some(begin_seq_no) = begin_seq_no {
390+
msg.set(fix44::BEGIN_SEQ_NO, begin_seq_no);
391+
}
392+
if let Some(end_seq_no) = end_seq_no {
393+
msg.set(fix44::END_SEQ_NO, end_seq_no);
394+
}
386395

387396
msg.encode(&Config::default()).unwrap()
388397
}

crates/hotfix/tests/session_test_cases/resend_tests.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::common::actions::when;
22
use crate::common::assertions::{assert_msg_type, then};
33
use crate::common::setup::given_an_active_session;
44
use 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
};
87
use hotfix::message::FixMessage;
98
use 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

Comments
 (0)