summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt42
-rw-r--r--test/conflist.inf8
-rw-r--r--test/empty_array.json1
-rw-r--r--test/http_test_plug.cpp118
-rw-r--r--test/http_test_plug.inf11
-rw-r--r--test/pcap/http_get/http-get.pcapbin0 -> 35841 bytes
-rw-r--r--test/pcap/http_get/http_result.json25
-rw-r--r--test/pcap/http_post/http-post-url-encode.pcapbin0 -> 79756 bytes
-rw-r--r--test/pcap/http_post/http_result.json25
-rw-r--r--test/test_protocol_run.zipbin0 -> 795325 bytes
10 files changed, 230 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..7149fed
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,42 @@
+cmake_minimum_required (VERSION 2.8)
+
+project(${lib_name}_test)
+
+include(ExternalProject)
+#### Protoco_test_run
+
+
+ExternalProject_Add(ProtoTest PREFIX ProtoTest
+ URL ${CMAKE_CURRENT_SOURCE_DIR}/test_protocol_run.zip
+ URL_MD5 71d8284b59af0286b5f31f0a3160bc44
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
+ CONFIGURE_COMMAND ""
+ BUILD_COMMAND ""
+ INSTALL_COMMAND ""
+ COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/conf/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/bin/http/${lib_name}.conf <SOURCE_DIR>/conf/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/bin/http/${lib_name}_main.conf <SOURCE_DIR>/conf/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/conflist.inf <SOURCE_DIR>/plug/
+ COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/plug/protocol/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/bin/${lib_name}.inf <SOURCE_DIR>/plug/protocol/${lib_name}/
+ COMMAND ${CMAKE_COMMAND} -E make_directory <SOURCE_DIR>/plug/business/${lib_name}_test_plug/
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/test/${lib_name}_test_plug.inf <SOURCE_DIR>/plug/business/${lib_name}_test_plug/)
+
+ExternalProject_Get_Property(ProtoTest INSTALL_DIR)
+ExternalProject_Get_Property(ProtoTest SOURCE_DIR)
+set(PROTO_TEST_RUN_DIR ${SOURCE_DIR})
+
+add_executable(proto_test_main IMPORTED GLOBAL)
+add_dependencies(proto_test_main ProtoTest)
+set_property(TARGET proto_test_main PROPERTY IMPORTED_LOCATION ${SOURCE_DIR}/test_protocol_plug_main)
+
+
+add_library(${lib_name}_test_plug SHARED ${lib_name}_test_plug.cpp)
+target_link_libraries(${lib_name}_test_plug MESA_prof_load cjson)
+set_target_properties(${lib_name}_test_plug PROPERTIES PREFIX "")
+
+add_test(NAME COPY_SO COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/${lib_name}.so ${PROTO_TEST_RUN_DIR}/plug/protocol/${lib_name}/${lib_name}.so")
+add_test(NAME COPY_TEST_SO COMMAND sh -c "cp ${CMAKE_CURRENT_BINARY_DIR}/${lib_name}_test_plug.so ${PROTO_TEST_RUN_DIR}/plug/business/${lib_name}_test_plug/${lib_name}_test_plug.so")
+
+add_test(NAME RUN_HTTP_GET_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/pcap/http_get/http_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/http_get/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})
+add_test(NAME RUN_HTTP_POST_TEST COMMAND proto_test_main ${CMAKE_CURRENT_SOURCE_DIR}/pcap/http_post/http_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/pcap/http_post/ -name *.pcap|sort -V" WORKING_DIRECTORY ${PROTO_TEST_RUN_DIR})
diff --git a/test/conflist.inf b/test/conflist.inf
new file mode 100644
index 0000000..97e3aee
--- /dev/null
+++ b/test/conflist.inf
@@ -0,0 +1,8 @@
+[platform]
+
+[protocol]
+./plug/protocol/http/http.inf
+
+
+[business]
+./plug/business/http_test_plug/http_test_plug.inf
diff --git a/test/empty_array.json b/test/empty_array.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/test/empty_array.json
@@ -0,0 +1 @@
+[] \ No newline at end of file
diff --git a/test/http_test_plug.cpp b/test/http_test_plug.cpp
new file mode 100644
index 0000000..9d3a3d8
--- /dev/null
+++ b/test/http_test_plug.cpp
@@ -0,0 +1,118 @@
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <assert.h>
+
+#include "cJSON.h"
+#include "http.h"
+#include "MESA_prof_load.h"
+#include <MESA/stream.h>
+
+extern "C" int commit_test_result_json(cJSON *node, const char *name);
+
+static int g_result_count = 1;
+
+int check_field(char *src, int src_len, char *dst, int dst_len)
+{
+ if(src==NULL || dst==NULL || src_len==0 || dst_len==0 || src_len!=dst_len)
+ {
+ assert(0);
+ }
+
+ assert(!memcmp(src, dst, src_len));
+
+ return 0;
+}
+
+int http_field_add_to_json(cJSON *object, const char *name, char *value, char length)
+{
+ if(value!=NULL && length>0)
+ {
+ char *tmp=(char *)calloc(1, length+1);
+ memcpy(tmp, value, length);
+ cJSON_AddStringToObject(object, name, tmp);
+ free(tmp);
+ tmp=NULL;
+ }
+
+ return 0;
+}
+
+extern "C" unsigned char HTTP_TEST_PLUG_ENTRY(stSessionInfo *session_info, void **pme, int thread_seq, struct streaminfo *a_tcp, void *a_packet)
+{
+ assert(NULL != session_info || pme != NULL);
+
+ cJSON *ctx = (cJSON *)*pme;
+
+ if (session_info->session_state & SESSION_STATE_PENDING)
+ {
+ if (*pme == NULL)
+ {
+ ctx = cJSON_CreateObject();
+ *pme = (void *)ctx;
+ cJSON_AddStringToObject(ctx, "Tuple4", printaddr(&a_tcp->addr, a_tcp->threadnum));
+ }
+ }
+
+ int length=0;
+ char *url=NULL, *host=NULL;
+ void *parser_result=NULL;
+
+ switch (session_info->prot_flag)
+ {
+ case HTTP_URI:
+ http_field_add_to_json(ctx, "http_uri", (char *)session_info->buf, session_info->buflen);
+ break;
+ case HTTP_HOST:
+ length=http_host_parser((const char *)a_tcp->ptcpdetail->pdata, a_tcp->ptcpdetail->datalen, a_tcp->curdir, &host);
+ check_field((char *)session_info->buf, session_info->buflen, host, length);
+
+ parser_result=http_field_parser((const char *)a_tcp->ptcpdetail->pdata, a_tcp->ptcpdetail->datalen, a_tcp->curdir);
+ length=http_get_filed_result(parser_result, HTTP_HOST, &host);
+ check_field((char *)session_info->buf, session_info->buflen, host, length);
+
+ http_field_add_to_json(ctx, "http_host", host, length);
+ http_free_filed_result(parser_result);
+ break;
+ case HTTP_MESSAGE_URL:
+ parser_result=http_field_parser((const char *)a_tcp->ptcpdetail->pdata, a_tcp->ptcpdetail->datalen, a_tcp->curdir);
+ length=http_get_filed_result(parser_result, HTTP_MESSAGE_URL, &url);
+ check_field((char *)session_info->buf, session_info->buflen, url, length);
+
+ http_field_add_to_json(ctx, "http_url", url, length);
+ http_free_filed_result(parser_result);
+ break;
+ default:
+ break;
+ }
+
+ if(session_info->session_state&SESSION_STATE_CLOSE)
+ {
+ if(ctx)
+ {
+ char result_name[16]="";
+ sprintf(result_name,"HTTP_RESULT_%d", g_result_count);
+ commit_test_result_json(ctx, result_name);
+ g_result_count+=1;
+ }
+ *pme = NULL;
+ return PROT_STATE_DROPME;
+
+ }
+
+ return PROT_STATE_GIVEME;
+
+}
+
+extern "C" int HTTP_TEST_PLUG_INIT()
+{
+ return 0;
+}
+
+extern "C" void HTTP_TEST_PLUG_DESTROY(void)
+{
+ return ;
+}/*CHAR_DESTRORY*/
+
+
+
diff --git a/test/http_test_plug.inf b/test/http_test_plug.inf
new file mode 100644
index 0000000..61ca4cb
--- /dev/null
+++ b/test/http_test_plug.inf
@@ -0,0 +1,11 @@
+[PLUGINFO]
+PLUGNAME=HTTP_TEST_PLUG
+SO_PATH=./plug/business/http_test_plug/http_test_plug.so
+INIT_FUNC=HTTP_TEST_PLUG_INIT
+DESTROY_FUNC=HTTP_TEST_PLUG_DESTROY
+
+[HTTP]
+FUNC_FLAG=ALL
+FUNC_NAME=HTTP_TEST_PLUG_ENTRY
+
+
diff --git a/test/pcap/http_get/http-get.pcap b/test/pcap/http_get/http-get.pcap
new file mode 100644
index 0000000..9c0d2e7
--- /dev/null
+++ b/test/pcap/http_get/http-get.pcap
Binary files differ
diff --git a/test/pcap/http_get/http_result.json b/test/pcap/http_get/http_result.json
new file mode 100644
index 0000000..6394263
--- /dev/null
+++ b/test/pcap/http_get/http_result.json
@@ -0,0 +1,25 @@
+[{
+ "Tuple4": "192.168.50.18.60400>192.168.42.1.80",
+ "http_uri": "/account/login.htm",
+ "http_host": "test.pro.testin.cn",
+ "http_url": "test.pro.testin.cn/account/login.htm",
+ "name": "HTTP_RESULT_1"
+ }, {
+ "Tuple4": "192.168.50.18.60400>192.168.42.1.80",
+ "http_uri": "/enterprise/index.htm",
+ "http_host": "test.pro.testin.cn",
+ "http_url": "test.pro.testin.cn/enterprise/index.htm",
+ "name": "HTTP_RESULT_2"
+ }, {
+ "Tuple4": "192.168.50.18.60400>192.168.42.1.80",
+ "http_uri": "/enterprise/into.htm?eid=1",
+ "http_host": "test.pro.testin.cn",
+ "http_url": "test.pro.testin.cn/enterprise/into.htm?eid=1",
+ "name": "HTTP_RESULT_3"
+ }, {
+ "Tuple4": "192.168.50.18.60400>192.168.42.1.80",
+ "http_uri": "/realmachine/index.htm",
+ "http_host": "test.pro.testin.cn",
+ "http_url": "test.pro.testin.cn/realmachine/index.htm",
+ "name": "HTTP_RESULT_4"
+}]
diff --git a/test/pcap/http_post/http-post-url-encode.pcap b/test/pcap/http_post/http-post-url-encode.pcap
new file mode 100644
index 0000000..0eae429
--- /dev/null
+++ b/test/pcap/http_post/http-post-url-encode.pcap
Binary files differ
diff --git a/test/pcap/http_post/http_result.json b/test/pcap/http_post/http_result.json
new file mode 100644
index 0000000..951f9bb
--- /dev/null
+++ b/test/pcap/http_post/http_result.json
@@ -0,0 +1,25 @@
+[{
+ "Tuple4": "192.168.32.18.63316>221.238.248.3.8000",
+ "http_uri": "/m_fullsearch/full_search1.jsp",
+ "http_host": "sou.qhnews.com:8000",
+ "http_url": "sou.qhnews.com:8000/m_fullsearch/full_search1.jsp",
+ "name": "HTTP_RESULT_1"
+ }, {
+ "Tuple4": "192.168.32.18.63316>221.238.248.3.8000",
+ "http_uri": "/m_fullsearch/css/css.css",
+ "http_host": "sou.qhnews.com:8000",
+ "http_url": "sou.qhnews.com:8000/m_fullsearch/css/css.css",
+ "name": "HTTP_RESULT_2"
+ }, {
+ "Tuple4": "192.168.32.18.63316>221.238.248.3.8000",
+ "http_uri": "/m_fullsearch/dwr/util.js",
+ "http_host": "sou.qhnews.com:8000",
+ "http_url": "sou.qhnews.com:8000/m_fullsearch/dwr/util.js",
+ "name": "HTTP_RESULT_3"
+ }, {
+ "Tuple4": "192.168.32.18.63316>221.238.248.3.8000",
+ "http_uri": "/m_fullsearch/dwr/call/plaincall/DwrChannel.getChild.dwr",
+ "http_host": "sou.qhnews.com:8000",
+ "http_url": "sou.qhnews.com:8000/m_fullsearch/dwr/call/plaincall/DwrChannel.getChild.dwr",
+ "name": "HTTP_RESULT_4"
+}]
diff --git a/test/test_protocol_run.zip b/test/test_protocol_run.zip
new file mode 100644
index 0000000..996f3fa
--- /dev/null
+++ b/test/test_protocol_run.zip
Binary files differ