]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
NHI unit testing
authorTom Peters <thopeter@cisco.com>
Tue, 19 Apr 2016 18:37:51 +0000 (14:37 -0400)
committerTom Peters <thopeter@cisco.com>
Thu, 21 Apr 2016 16:25:04 +0000 (12:25 -0400)
configure.ac
src/service_inspectors/nhttp_inspect/CMakeLists.txt
src/service_inspectors/nhttp_inspect/Makefile.am
src/service_inspectors/nhttp_inspect/nhttp_module.h
src/service_inspectors/nhttp_inspect/test/CMakeLists.txt [new file with mode: 0644]
src/service_inspectors/nhttp_inspect/test/Makefile.am [new file with mode: 0644]
src/service_inspectors/nhttp_inspect/test/nhttp_uri_norm_test.cc [new file with mode: 0644]

index 0a5f2f39a8ef4fa666707cf02d11a08a0acae7e8..8faf177cd57be81a729b5c7d82a781db2088d893 100644 (file)
@@ -1126,6 +1126,7 @@ src/service_inspectors/http_inspect/Makefile \
 src/service_inspectors/imap/Makefile \
 src/service_inspectors/modbus/Makefile \
 src/service_inspectors/nhttp_inspect/Makefile \
+src/service_inspectors/nhttp_inspect/test/Makefile \
 src/service_inspectors/pop/Makefile \
 src/service_inspectors/rpc_decode/Makefile \
 src/service_inspectors/sip/Makefile \
index afa2f9724e9600f3bf33a3f0f27df844d2ab6e65..e9a985879229c4011d169242a80353e84e610ff8 100644 (file)
@@ -66,3 +66,4 @@ endif(STATIC_INSPECTORS)
 
 add_shared_library(nhttp_inspect_opt inspectors ips_nhttp.cc ips_nhttp.h)
 
+add_subdirectory ( test )
index 24f42f439ea454001c28f302945cc1f8d5684512..1632a813e04d755f48b7d0c6ead6010b78e98a7a 100644 (file)
@@ -49,3 +49,7 @@ libnhttp_inspect_opt_la_CXXFLAGS = $(AM_CXXFLAGS) -DBUILDING_SO
 libnhttp_inspect_opt_la_LDFLAGS = $(AM_LDFLAGS) -export-dynamic -shared
 libnhttp_inspect_opt_la_SOURCES = ips_nhttp.cc ips_nhttp.h
 
+if BUILD_CPPUTESTS
+SUBDIRS = test
+endif
+
index d8a8b889ee8e1f91ae71c856a60dbfd66275f150..c7823fec21122f43c8c0be9d53a10f45f7e9afcf 100644 (file)
@@ -42,16 +42,16 @@ public:
         UriParam();
         ~UriParam() { delete[] unicode_map; }
 
-        bool percent_u;
-        bool utf8;
-        bool utf8_bare_byte;
-        bool iis_unicode;
+        bool percent_u = false;
+        bool utf8 = true;
+        bool utf8_bare_byte = false;
+        bool iis_unicode = false;
         std::string iis_unicode_map_file;
-        int iis_unicode_code_page;
+        int iis_unicode_code_page = 1252;
         uint8_t* unicode_map = nullptr;
-        bool backslash_to_slash;
-        bool plus_to_space;
-        bool simplify_path;
+        bool backslash_to_slash = false;
+        bool plus_to_space = true;
+        bool simplify_path = true;
         std::bitset<256> bad_characters;
         std::bitset<256> unreserved_char;
         NHttpEnums::CharAction uri_char[256];
diff --git a/src/service_inspectors/nhttp_inspect/test/CMakeLists.txt b/src/service_inspectors/nhttp_inspect/test/CMakeLists.txt
new file mode 100644 (file)
index 0000000..809739d
--- /dev/null
@@ -0,0 +1,2 @@
+add_cpputest(nhttp_uri_norm_test nhttp_inspect framework)
+
diff --git a/src/service_inspectors/nhttp_inspect/test/Makefile.am b/src/service_inspectors/nhttp_inspect/test/Makefile.am
new file mode 100644 (file)
index 0000000..8ed6fa1
--- /dev/null
@@ -0,0 +1,21 @@
+
+AM_DEFAULT_SOURCE_EXT = .cc
+
+check_PROGRAMS = \
+nhttp_uri_norm_test
+
+TESTS = $(check_PROGRAMS)
+
+nhttp_uri_norm_test_CPPFLAGS = $(AM_CPPFLAGS) @CPPUTEST_CPPFLAGS@
+nhttp_uri_norm_test_LDADD = \
+../nhttp_uri_norm.o \
+../nhttp_module.o \
+../nhttp_test_manager.o \
+../nhttp_test_input.o \
+../nhttp_normalizers.o \
+../nhttp_str_to_code.o \
+../nhttp_field.o \
+../nhttp_tables.o \
+../../../framework/module.o \
+@CPPUTEST_LDFLAGS@
+
diff --git a/src/service_inspectors/nhttp_inspect/test/nhttp_uri_norm_test.cc b/src/service_inspectors/nhttp_inspect/test/nhttp_uri_norm_test.cc
new file mode 100644 (file)
index 0000000..9483fa9
--- /dev/null
@@ -0,0 +1,56 @@
+//--------------------------------------------------------------------------
+// Copyright (C) 2016 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.
+//--------------------------------------------------------------------------
+
+// nhttp_uri_norm_test.cc author Tom Peters <thopeter@cisco.com>
+// unit test main
+
+#include "log/messages.h"
+#include "service_inspectors/nhttp_inspect/nhttp_uri_norm.h"
+
+#include <CppUTest/CommandLineTestRunner.h>
+#include <CppUTest/TestHarness.h>
+#include <CppUTestExt/MockSupport.h>
+
+void ParseWarning(WarningGroup, const char*, ...) {}
+void ParseError(const char*, ...) {}
+void show_stats(unsigned long*, PegInfo const*, unsigned int, char const*) {}
+void show_stats(unsigned long*, PegInfo const*, std::vector<unsigned int, std::allocator<unsigned int> >&, char const*, _IO_FILE*) {}
+void Value::get_bits(std::bitset<256ul>&) const {}
+int SnortEventqAdd(unsigned int, unsigned int, RuleType) { return 0; }
+
+TEST_GROUP(nhttp_inspect_uri_norm) { };
+
+TEST(nhttp_inspect_uri_norm, normalize)
+{
+    Field input(20, (const uint8_t*) "/uri//to/%6eormalize");
+    Field result;
+    uint8_t buffer[100];
+    NHttpParaList::UriParam uri_param;
+    NHttpInfractions infractions;
+    NHttpEventGen events;
+
+    UriNormalizer::normalize(input, result, true, buffer, uri_param, infractions, events);
+    CHECK(result.length == 17);
+    CHECK(memcmp(result.start, "/uri/to/normalize", 17) == 0);
+}
+
+int main(int argc, char** argv)
+{
+    return CommandLineTestRunner::RunAllTests(argc, argv);
+}
+