1 //--------------------------------------------------------------------------
2 // Copyright (C) 2019-2021 Cisco and/or its affiliates. All rights reserved.
3 //
4 // This program is free software; you can redistribute it and/or modify it
5 // under the terms of the GNU General Public License Version 2 as published
6 // by the Free Software Foundation.  You may not use, modify or distribute
7 // this program under any other version of the GNU General Public License.
8 //
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 //--------------------------------------------------------------------------
18 
19 // flow_test.cc author Prajwal Srinivas <psreenat@cisco.com>
20 // unit test main
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include "detection/detection_engine.h"
27 #include "flow/flow.h"
28 #include "flow/flow_stash.h"
29 #include "flow/ha.h"
30 #include "framework/inspector.h"
31 #include "framework/data_bus.h"
32 #include "main/snort_config.h"
33 #include "protocols/ip.h"
34 #include "protocols/layer.h"
35 #include "protocols/packet.h"
36 
37 #include <CppUTest/CommandLineTestRunner.h>
38 #include <CppUTest/TestHarness.h>
39 
40 using namespace snort;
41 
Packet(bool)42 Packet::Packet(bool) { }
43 Packet::~Packet()  = default;
44 
rem_ref()45 void Inspector::rem_ref() {}
46 
add_ref()47 void Inspector::add_ref() {}
48 
active()49 bool HighAvailabilityManager::active() { return false; }
50 
51 FlowHAState::FlowHAState() = default;
52 
reset()53 void FlowHAState::reset() {}
54 
55 FlowStash::~FlowStash() = default;
56 
reset()57 void FlowStash::reset() {}
58 
onload(Flow *)59 void DetectionEngine::onload(Flow*) {}
60 
set_next_packet(Packet *,Flow *)61 Packet* DetectionEngine::set_next_packet(Packet*, Flow*) { return nullptr; }
62 
get_context()63 IpsContext* DetectionEngine::get_context() { return nullptr; }
64 
65 DetectionEngine::DetectionEngine() = default;
66 
67 DetectionEngine::~DetectionEngine() = default;
68 
set_outer_ip_api(const Packet * const,ip::IpApi &,int8_t &)69 bool layer::set_outer_ip_api(const Packet* const, ip::IpApi&, int8_t&)
70 { return false; }
71 
ttl() const72 uint8_t ip::IpApi::ttl() const { return 0; }
73 
get_mpls_layer(const Packet * const)74 const Layer* layer::get_mpls_layer(const Packet* const) { return nullptr; }
75 
publish(const char *,Packet *,Flow *)76 void DataBus::publish(const char*, Packet*, Flow*) {}
77 
get_conf()78 const SnortConfig* SnortConfig::get_conf() { return nullptr; }
79 
TEST_GROUP(nondefault_timeout)80 TEST_GROUP(nondefault_timeout)
81 {
82     void setup() override
83     {
84     }
85 
86     void teardown() override
87     {
88     }
89 };
90 
TEST(nondefault_timeout,hard_expiration)91 TEST(nondefault_timeout, hard_expiration)
92 {
93     uint64_t validate = 100;
94     Packet pkt(false);
95     Flow *flow = new Flow();
96     DAQ_PktHdr_t pkthdr;
97 
98     pkt.pkth = &pkthdr;
99     pkthdr.ts.tv_sec = 0;
100 
101     flow->set_default_session_timeout(validate, true);
102     flow->set_hard_expiration();
103     flow->set_expire(&pkt, validate);
104 
105     CHECK( flow->is_hard_expiration() == true);
106     CHECK( flow->expire_time == validate );
107 
108     delete flow;
109 }
110 
main(int argc,char ** argv)111 int main(int argc, char** argv)
112 {
113     int return_value = CommandLineTestRunner::RunAllTests(argc, argv);
114     return return_value;
115 }
116 
117 
118