From 1a1d771e1b04da142e4b3bbfbbad539eef651550 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Sat, 25 Apr 2020 13:18:58 -0400 Subject: [PATCH] addition ilink3 tests --- .../actors/ilink3/test/IL3TestExchange.h | 25 +++-- .../actors/ilink3/test/ILinkGWTests.cpp | 95 +++++++++++++++---- src/server/sparkd/cmds/CMECertCmd.cpp | 2 + 3 files changed, 94 insertions(+), 28 deletions(-) diff --git a/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h b/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h index fc5b662de..c1c5f60c0 100644 --- a/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h +++ b/src/lib/orderman/actors/ilink3/test/IL3TestExchange.h @@ -16,11 +16,13 @@ struct TestExchangeConnection : public IL3Connection { bool connected; IL3TestExchange& exchange; IL3ConnectionHandler* handler; + bool is_backup; TestExchangeConnection(IL3TestExchange& te) : connected(false), exchange(te), - handler(nullptr) + handler(nullptr), + is_backup(false) {} void connect(IL3ConnectionHandler& h) override { @@ -34,7 +36,7 @@ struct TestExchangeConnection : public IL3Connection { connected = false; if (handler) handler->on_disconnect(); } - void failover() override {} + void failover() override { is_backup = ! is_backup; } void send(const std::string_view data) { REQUIRE(connected); consume_messages(exchange, data.data(), data.size(), dispatch_exchange_message); @@ -66,6 +68,7 @@ struct ExchangeOrder { struct TestExchangeConfig { bool reject_negotiate; std::string expected_firm; + bool reject_establish; }; struct IL3TestExchange { @@ -135,11 +138,19 @@ struct IL3TestExchange { } void handle(const iLinkBinary::Establish503& msg) { log("-> Establish"); - this->expected_seq = msg.nextSeqNo(); - auto resp = buffer.frame(); - resp.nextSeqNo(this->sequence); - resp.keepAliveInterval(30000); - respond("<- EstablishAck"); + if (config.reject_establish) { + auto resp = buffer.frame(); + resp.errorCodes(42); + resp.putReason("Invalid Establish"); + respond("<- Terminate"); + } + else { + this->expected_seq = msg.nextSeqNo(); + auto resp = buffer.frame(); + resp.nextSeqNo(this->sequence); + resp.keepAliveInterval(30000); + respond("<- EstablishAck"); + } } void handle(const iLinkBinary::Sequence506& msg) { log("-> Sequence"); diff --git a/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp b/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp index 564035dac..5c8dc0f6a 100644 --- a/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp +++ b/src/lib/orderman/actors/ilink3/test/ILinkGWTests.cpp @@ -220,32 +220,85 @@ TEST_CASE("ilink3 receive buffer", "[ilink3][execution]") { // https://www.cmegroup.com/tools-information/webhelp/autocert-ilink/Content/ACPiLinkUserManual.pdf // -TEST_CASE("ilink3Login", "[ilink3][execution]") { - SECTION("New Session") { - // Simplest scenario. Log in with no messages to replay - IL3TestExchange exchange; - // simulated socket transport - auto& connection = exchange.connect(); - // New session starts at 1 - Session session { 1234, 1, 1 }; +TEST_CASE("BeginningOfWeekLogon", "[ilink3][cert]") { + // Simplest scenario. Log in with no replay + + IL3TestExchange exchange; + auto& connection = exchange.connect(); + // New session starts at 1 + Session session { 1234, 1, 1 }; + Config config { std::nullopt, "NGG", "004", false }; + ILinkGW gw { connection, session, config }; + + gw.connect(); + exchange.do_work(); + REQUIRE(exchange.session == session.uuid); + REQUIRE(exchange.expected_seq == session.to_sequence); + REQUIRE(exchange.msg_log == "-> Negotiate <- NegotiationResponse -> Establish <- EstablishAck -> Sequence <- Sequence "); +} + +TEST_CASE("PrimaryGatewayConnectionEnforcement", "[ilink3][il3cert]") { + // TODO: Not sure what segment 99 is +} + +TEST_CASE("MidWeekKeyRotation", "[ilink3][il3cert]") { + // TODO: need 2 key pairs +} + +TEST_CASE("Re-SettingUUID", "[ilink3][il3cert]") { + // -> Establish w/ existing session + // <- receive a terminate + // Negotiate a new session id + // -> Negotiate + // -> Establish + // -> Sequence + IL3TestExchange exchange; + exchange.config.reject_establish = true; + auto& connection = exchange.connect(); + // Existing session starts >1. Will attempt to establish + { + Session session { 1234, /*out*/ 5, /*in*/ 17 }; Config config { std::nullopt, "NGG", "004", false }; ILinkGW gw { connection, session, config }; - gw.connect(); - for (auto x = 0; x < 10; ++x) { exchange.do_work(); } - REQUIRE(exchange.session == session.uuid); - REQUIRE(exchange.expected_seq == session.to_sequence); - REQUIRE(exchange.msg_log == "-> Negotiate <- NegotiationResponse -> Establish <- EstablishAck -> Sequence <- Sequence "); - } - SECTION("Existing Session") { - // Log in and get notified of an old session - // Old session does *NOT* have new messages so do not attempt replay - } - SECTION("Previous Session has messages") { - } - SECTION("Reconnect w/ missing messages") { + exchange.do_work(); + REQUIRE(gw.state() == State::ERROR); + REQUIRE(exchange.msg_log == "-> Establish <- Terminate "); } + + exchange.config.reject_establish = false; + Session session { 4321, 1, 1 }; + Config config { std::nullopt, "NGG", "004", false }; + ILinkGW gw { connection, session, config }; + // send establish + gw.connect(); + exchange.do_work(); + REQUIRE(gw.state() == State::READY); + REQUIRE(exchange.msg_log == "-> Establish <- Terminate -> Negotiate <- NegotiationResponse -> Establish <- EstablishAck -> Sequence <- Sequence "); } +TEST_CASE("VerifySequenceWarningKeepAliveIntervalLapsingProcedure", "[ilink3][il3cert]") { } +TEST_CASE("BeginningOfWeekConnectionwithGTOrders", "[ilink3][il3cert]") { } +TEST_CASE("MidWeekConnection", "[ilink3][il3cert]") { } +TEST_CASE("ProcessingMessageGaps", "[ilink3][il3cert]") { } +TEST_CASE("ReceivingAndProcessingMultipleGaps", "[ilink3][il3cert]") { } +TEST_CASE("Bi-DirectionalGaps", "[ilink3][il3cert]") { } +TEST_CASE("ProcessRealtimeMessagesDuringResendResponse", "[ilink3][il3cert]") { } +TEST_CASE("ProcessRealtimeMessagesforFAKFOK", "[ilink3][il3cert]") { } +TEST_CASE("LimitOrder", "[ilink3][il3cert]") { } +TEST_CASE("MarketOrder", "[ilink3][il3cert]") { } +TEST_CASE("StopLimitOrder", "[ilink3][il3cert]") { } +TEST_CASE("StopOrder", "[ilink3][il3cert]") { } +TEST_CASE("OutrightCompleteOrder", "[ilink3][il3cert]") { } +TEST_CASE("SpreadCompleteOrder", "[ilink3][il3cert]") { } +TEST_CASE("ManageGTC-GTDOrderLifetime", "[ilink3][il3cert]") { } +TEST_CASE("FAKOrderTest", "[ilink3][il3cert]") { } +TEST_CASE("MultipleCancelReplace", "[ilink3][il3cert]") { } +TEST_CASE("CancelReplacewithIFM", "[ilink3][il3cert]") { } +TEST_CASE("ManageMaximumQuantityDisplayWithOnDemand", "[ilink3][il3cert]") { } +TEST_CASE("ManagedMaximumQuanityDisplayWithCancelReplace", "[ilink3][il3cert]") { } +TEST_CASE("ManualOrderIndicatorForSemiAutomatedSystem", "[ilink3][il3cert]") { } +TEST_CASE("ProcessingRejectsTest", "[ilink3][il3cert]") { } +TEST_CASE("MSGWFailoverFromPrimaryToBackup", "[ilink3][il3cert]") { } api::Security test_future() { api::Security s; diff --git a/src/server/sparkd/cmds/CMECertCmd.cpp b/src/server/sparkd/cmds/CMECertCmd.cpp index e67f29ce0..877688e94 100644 --- a/src/server/sparkd/cmds/CMECertCmd.cpp +++ b/src/server/sparkd/cmds/CMECertCmd.cpp @@ -27,6 +27,8 @@ int CMECert::execute(const std::vector&) { Config config { std::nullopt, "NGG", "004", false }; Reactor reactor; auto& connection = reactor.register_connection({ + // local dev + TCPEndpoint { "127.0.0.1", 64530 }, // General NRCERT not AutoCert+ // {"69.50.112.184", 64530}, // {"69.50.112.185", 64530},