From: Shravan Rangarajuvenkata (shrarang) Date: Mon, 23 Mar 2020 18:24:59 +0000 (+0000) Subject: Merge pull request #2082 in SNORT/snort3 from ~KAMURTHI/snort3:client_ut to master X-Git-Tag: 3.0.0-270~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94bb8f630e1c2bc29254ef4dd895536fc062d586;p=thirdparty%2Fsnort3.git Merge pull request #2082 in SNORT/snort3 from ~KAMURTHI/snort3:client_ut to master Squashed commit of the following: commit 366655b4b7b6468df1722d9fe33bbc43dd4b971f Author: Kanimozhi Murthi Date: Mon Mar 16 16:46:31 2020 -0400 appid: Adding UT for client_app_aim_test --- diff --git a/src/network_inspectors/appid/CMakeLists.txt b/src/network_inspectors/appid/CMakeLists.txt index 0fa1e1d6e..49e83d0f3 100644 --- a/src/network_inspectors/appid/CMakeLists.txt +++ b/src/network_inspectors/appid/CMakeLists.txt @@ -228,6 +228,7 @@ add_library(appid OBJECT target_include_directories ( appid PRIVATE ${APPID_INCLUDE_DIR} ) +add_subdirectory(client_plugins/test) add_subdirectory(service_plugins/test) add_subdirectory(detector_plugins/test) add_subdirectory(test) diff --git a/src/network_inspectors/appid/client_plugins/test/CMakeLists.txt b/src/network_inspectors/appid/client_plugins/test/CMakeLists.txt new file mode 100644 index 000000000..42f8e48fd --- /dev/null +++ b/src/network_inspectors/appid/client_plugins/test/CMakeLists.txt @@ -0,0 +1,4 @@ + +include_directories ( appid PRIVATE ${APPID_INCLUDE_DIR} ) + +add_cpputest( client_app_aim_test ) diff --git a/src/network_inspectors/appid/client_plugins/test/client_app_aim_test.cc b/src/network_inspectors/appid/client_plugins/test/client_app_aim_test.cc new file mode 100644 index 000000000..9572c2566 --- /dev/null +++ b/src/network_inspectors/appid/client_plugins/test/client_app_aim_test.cc @@ -0,0 +1,61 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License Version 2 as published +// by the Free Software Foundation. You may not use, modify or distribute +// this program under any other version of the GNU General Public License. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +//-------------------------------------------------------------------------- + +// client_app_aim_test.cc author Kani Murthi +// unit test for client_app_aim_test.cc +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "network_inspectors/appid/client_plugins/client_app_aim.cc" +#include "network_inspectors/appid/client_plugins/client_detector.cc" +#include "protocols/packet.h" +#include "client_plugin_mock.h" + +#include +#include +#include + +void ServiceDiscovery::initialize() {} +int ServiceDiscovery::fail_service(AppIdSession&, const Packet*, AppidSessionDirection, + ServiceDetector*, ServiceDiscoveryState*) { return 0; } +int ServiceDiscovery::add_service_port(AppIdDetector*, + const ServiceDetectorPort&) { return APPID_EINVALID; } + +TEST_GROUP(client_app_aim_test){}; + +TEST(client_app_aim_test, check_username) +{ + uint8_t data[] = {"test@gmail.com\0"}; + FLAPTLV tlv = {0x0001, 14}; + char buf[256]; + bool ret; + ret = check_username(data, &tlv, buf, buf + 255); + CHECK_TRUE(ret); + STRCMP_EQUAL(buf, "test@gmail.com"); + uint8_t invalid_data[] = {"test^"}; + tlv = {0x0001, 5}; + ret = check_username(invalid_data, &tlv, buf, buf + 255); + CHECK_FALSE(ret); +} + +int main(int argc, char** argv) +{ + int return_value = CommandLineTestRunner::RunAllTests(argc, argv); + return return_value; +} diff --git a/src/network_inspectors/appid/client_plugins/test/client_plugin_mock.h b/src/network_inspectors/appid/client_plugins/test/client_plugin_mock.h new file mode 100644 index 000000000..17010d100 --- /dev/null +++ b/src/network_inspectors/appid/client_plugins/test/client_plugin_mock.h @@ -0,0 +1,118 @@ +//-------------------------------------------------------------------------- +// Copyright (C) 2020-2020 Cisco and/or its affiliates. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License Version 2 as published +// by the Free Software Foundation. You may not use, modify or distribute +// this program under any other version of the GNU General Public License. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +//-------------------------------------------------------------------------- +// client_plugins_mock.h author Kani Murthi + +#ifndef CLIENT_PLUGIN_MOCK_H +#define CLIENT_PLUGIN_MOCK_H + +namespace snort +{ +// Stubs for messages +void ParseWarning(WarningGroup, const char*, ...) { } + +// Stubs for appid sessions +FlowData::FlowData(unsigned, Inspector*) { } +FlowData::~FlowData() = default; + +// Stubs for packet +Packet::Packet(bool) { } +Packet::~Packet() = default; + +Inspector::Inspector() = default; +Inspector::~Inspector() = default; +bool Inspector::likes(Packet*) { return true; } +bool Inspector::get_buf(const char*, Packet*, InspectionBuffer&) { return true; } +class StreamSplitter* Inspector::get_splitter(bool) { return nullptr; } + +// Stubs for search_tool.cc +SearchTool::SearchTool(const char*, bool) { } +SearchTool::~SearchTool() = default; + +// Stubs for util.cc +char* snort_strdup(const char* str) +{ + assert(str); + size_t n = strlen(str) + 1; + char* p = (char*)snort_alloc(n); + memcpy(p, str, n); + return p; +} +class InspectorManager +{ +public: + SO_PUBLIC static Inspector* get_inspector(const char*, bool, SnortConfig*) {return nullptr;} +}; +PegCount Module::get_global_count(char const*) const { return 0; } +void Module::show_interval_stats(std::vector >&, FILE*) {} +void Module::show_stats(){} +void Module::sum_stats(bool ){} +bool Module::set(const char*, Value&, SnortConfig*){ return false;} +void Module::reset_stats() {} +} + +SslPatternMatchers::~SslPatternMatchers() { } +SipPatternMatchers::~SipPatternMatchers() { } +HttpPatternMatchers::~HttpPatternMatchers() { } +DnsPatternMatchers::~DnsPatternMatchers() { } +void ClientDiscovery::initialize() {} + +int AppIdDetector::initialize(){return 0;} +int AppIdDetector::data_add(AppIdSession&, void*, AppIdFreeFCN){return 0;} +void* AppIdDetector::data_get(AppIdSession&) {return nullptr;} +void AppIdDetector::add_info(AppIdSession&, const char*, AppidChangeBits&){} +void AppIdDetector::add_user(AppIdSession&, const char*, AppId, bool){} +void AppIdDetector::add_payload(AppIdSession&, AppId){} +void AppIdDetector::add_app(const snort::Packet&, AppIdSession&, AppidSessionDirection, AppId, AppId, const char*, AppidChangeBits&){} +void AppIdDiscovery::add_pattern_data(AppIdDetector*, snort::SearchTool*, int, + const uint8_t* const, unsigned, unsigned){} +void AppIdDiscovery::register_detector(const std::string&, AppIdDetector*, IpProtocol){} +void add_pattern_data(AppIdDetector*, snort::SearchTool*, int, + const uint8_t* const, unsigned, unsigned) {} +void AppIdDiscovery::register_tcp_pattern(AppIdDetector*, const uint8_t* const, unsigned, + int, unsigned){} +void AppIdDiscovery::register_udp_pattern(AppIdDetector*, const uint8_t* const, unsigned, + int, unsigned){} +int AppIdDiscovery::add_service_port(AppIdDetector*, const ServiceDetectorPort&){return 0;} +void ApplicationDescriptor::set_id(const snort::Packet&, AppIdSession&, AppidSessionDirection, AppId, AppidChangeBits&){} +AppIdDiscovery::AppIdDiscovery() { } +AppIdDiscovery::~AppIdDiscovery() { } +void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { } +void show_stats(PegCount*, const PegInfo*, const IndexVec&, const char*, FILE*) { } +AppIdConfig config; +AppIdContext ctxt(config); + +// Stubs for modules, config +AppIdConfig::~AppIdConfig() = default; + +// Stubs for AppIdPegCounts +void AppIdPegCounts::inc_payload_count(AppId) { } + +THREAD_LOCAL AppIdStats appid_stats; + +// Stubs for app_info_table.cc +AppInfoTableEntry* AppInfoManager::get_app_info_entry(int) +{ + return nullptr; +} + +bool AppInfoManager::configured() +{ + return true; +} + +#endif