通过原有功能的单元测试。

This commit is contained in:
zhengchao
2020-06-16 21:31:26 +08:00
parent 81a827d162
commit adf5cd8af8
23 changed files with 454 additions and 229 deletions

View File

@@ -11,7 +11,7 @@ target_link_libraries(test_maatframe maat_frame_shared gtest)
#target_link_libraries(perf_test_maatframe maat_frame_shared gtest)
configure_file(table_info.conf table_info.conf COPYONLY)
configure_file(t2_tableinfo.conf t2_tableinfo.conf COPYONLY)
configure_file(file_test_tableinfo.conf file_test_tableinfo.conf COPYONLY)
configure_file(maat_json.json maat_json.json COPYONLY)
configure_file(reset_redis4maat.sh reset_redis4maat.sh COPYONLY)
file(COPY conf DESTINATION ./)

View File

@@ -0,0 +1,27 @@
#each collumn seperate with '\t'
#id (0~65535)
#name string
#type one of ip,expr,expr_plus,digest,intval,compile or plugin
#src_charset one of GBK,BIG5,UNICODE,UTF8
#dst_charset combined by GBK,BIG5,UNICODE,UTF8,seperate with '/'
#do_merege yes or no
#cross cache 0~max
#quickswitch quickon or quick off
#id name type src_charset dst_charset do_merge cross_cache quickswitch
0 NTC_COMPILE compile UTF8 UTF8 no 0
0 WHITE_LIST_COMPILE compile UTF8 UTF8 no 0
1 NTC_GROUP2GROUP group2group --
2 NTC_GROUP2COMPILE group2compile --
3 NTC_UNIVERSAL_IP ip UTF8 UTF8 no 0
4 NTC_UNIVERSAL_PROTO_TYPE intval UTF8 UTF8 no 0
5 WHITE_LIST_IP ip UTF8 UTF8 no 0
7 NTC_HTTP_URL expr UTF8 UTF8 yes 0 quickoff
7 WHITE_LIST_DOMAIN expr UTF8 UTF8 yes 0 quickoff
8 NTC_HTTP_REQ_HDR expr_plus UTF8 UTF8 yes 0 quickoff
8 NTC_HTTP_RES_HDR expr_plus UTF8 UTF8 yes 0 quickoff
9 NTC_HTTP_REQ_BODY expr UTF8 UTF8/GBK/BIG5/UNICODE yes 0 quickoff
9 NTC_HTTP_RES_BODY expr UTF8 UTF8/GBK/BIG5/UNICODE yes 0 quickoff
11 NTC_MAIL_HDR expr_plus UTF8 UTF8/GBK yes 0 quickoff
12 NTC_MAIL_BODY expr_plus UTF8 UTF8/GBK yes 0 quickoff
13 NTC_FTP_URL expr UTF8 UTF8 yes 0 quickoff
14 NTC_FTP_CONTENT expr UTF8 UTF8 yes 0 quickoff

View File

@@ -10,11 +10,11 @@
#id name type src_charset dst_charset do_merge cross_cache quickswitch
0 NTC_COMPILE compile UTF8 UTF8 no 0
0 WHITE_LIST_COMPILE compile UTF8 UTF8 no 0
1 NTC_GROUP group UTF8 UTF8 no 0
1 WHITE_LIST_GROUP group UTF8 UTF8 no 0
2 NTC_UNIVERSAL_IP ip UTF8 UTF8 no 0
1 NTC_GROUP2GROUP group2group --
2 NTC_GROUP2COMPILE group2compile --
3 NTC_UNIVERSAL_IP ip UTF8 UTF8 no 0
3 NTC_UNIVERSAL_PROTO_TYPE intval UTF8 UTF8 no 0
4 WHITE_LIST_IP ip UTF8 UTF8 no 0
5 WHITE_LIST_IP ip UTF8 UTF8 no 0
7 NTC_HTTP_URL expr UTF8 UTF8 yes 0 quickoff
7 WHITE_LIST_DOMAIN expr UTF8 UTF8 yes 0 quickoff
8 NTC_HTTP_REQ_HDR expr_plus UTF8 UTF8 yes 0 quickoff

View File

@@ -1,6 +1,7 @@
{
"compile_table": "COMPILE",
"group_table": "GROUP",
"group2compile_table": "GROUP2COMPILE",
"group2group_table": "GROUP2GROUP",
"rules": [
{
"compile_id": 2,

View File

@@ -1,6 +1,7 @@
{
"compile_table": "COMPILE",
"group_table": "GROUP",
"group2compile_table": "GROUP2COMPILE",
"group2group_table": "GROUP2GROUP",
"rules": [
{
"compile_id": 1,

View File

@@ -1,12 +1,10 @@
{
"compile_table": "COMPILE",
"group2compile_table": "GROUP2COMPILE",
"compile_table": "COMPILE",
"group2compile_table": "GROUP2COMPILE",
"group2group_table": "GROUP2GROUP",
"groups": [
{
"group_name": "ASN1234",
"parent_group": "SRC_IP_ASN_1234",
"virtual_table":"SOURCE_IP_ASN",
"regions": [
{
"table_name": "AS_NUMBER",
@@ -22,8 +20,6 @@
},
{
"group_name": "ASN2345",
"parent_group": "DEST_IP_ASN_2345",
"virtual_table":"DESTINATION_IP_ASN",
"regions": [
{
"table_name": "AS_NUMBER",
@@ -36,6 +32,43 @@
}
}
]
},
{
"group_name": "financial-department-ip",
"regions": [
{
"table_name": "IP_CONFIG",
"table_type": "ip",
"table_content": {
"addr_type": "ipv4",
"src_ip": "192.168.40.88",
"mask_src_ip": "255.255.255.255",
"src_port": "0",
"mask_src_port": "65535",
"dst_ip": "0.0.0.0",
"mask_dst_ip": "255.255.255.255",
"dst_port": "0",
"mask_dst_port": "65535",
"protocol": 6,
"direction": "double"
}
}
]
},
{
"group_name": "Country-Sparta-IP",
"regions": [
{
"table_name": "GeoLocation",
"table_type": "string",
"table_content": {
"keywords": "Greece.Sparta",
"expr_type": "none",
"match_method": "exact",
"format": "uncase plain"
}
}
]
}
],
"rules": [
@@ -1764,16 +1797,32 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "non-top-object-as-virtual",
"user_region": "Hierarchy.TwoVirtualInOneClause",
"is_valid": "yes",
"groups": [
{
"group_name":"SRC_IP_ASN_1234",
"not_flag":0
},
"group_name":"ASN1234",
"virtual_table":"SOURCE_IP_ASN",
"not_flag":0,
"nth_clause":1
},
{
"group_name":"DEST_IP_ASN_2345",
"not_flag":0
"group_name":"financial-department-ip",
"virtual_table":"null",
"not_flag":0,
"nth_clause":1
},
{
"group_name":"Country-Sparta-IP",
"virtual_table":"SOURCE_IP_GEO",
"not_flag":0,
"nth_clause":1
},
{
"group_name":"ASN2345",
"virtual_table":"DESTINATION_IP_ASN",
"not_flag":0,
"nth_clause":2
}
]
}

View File

@@ -1,104 +0,0 @@
0000000103
828 193099 1
648 192999 1
869 193126 1
847 193114 1
620 192973 1
834 193105 1
551 170487 1
836 193106 1
723 193040 1
867 193128 1
607 192965 1
624 192976 1
991 193252 1
827 193098 1
861 193133 1
843 193112 1
854 193119 1
611 192967 1
890 193154 1
728 193039 1
980 193237 1
849 193115 1
806 193076 1
820 193091 1
8 11 1
845 193113 1
66 118 1
614 192966 1
610 192967 1
612 192966 1
855 193120 1
982 193236 1
884 193148 1
70 121 1
831 193102 1
856 193121 1
881 193145 1
838 193108 1
873 193138 1
851 193116 1
623 192976 1
68 120 1
605 192960 1
983 193236 1
993 193258 1
979 193234 1
816 193088 1
7 12 1
603 192960 1
981 193237 1
431 170435 1
846 193114 1
550 170486 1
649 192977 1
919 193171 1
864 193131 1
20 32 1
865 193130 1
724 193040 1
1021 193289 1
829 193101 1
868 193127 1
805 193077 1
613 192966 1
883 193147 1
647 193000 1
726 193039 1
862 193134 1
994 193258 1
549 170485 1
837 193107 1
863 193132 1
727 193039 1
409 441 1
833 193103 1
608 192965 1
650 193002 1
844 193112 1
625 192978 1
432 170436 1
67 116 1
891 193155 1
598 192959 1
850 193116 1
609 192967 1
835 193106 1
885 193149 1
725 193040 1
615 192968 1
886 193150 1
880 193144 1
606 192965 1
876 193140 1
1034 193294 1
840 193110 1
839 193108 1
832 193103 1
1020 193289 1
866 193129 1
604 192960 1
830 193102 1
875 193139 1
848 193115 1

View File

@@ -0,0 +1,105 @@
0000000103
828 193099 1 0 null 1
648 192999 1 0 null 1
869 193126 1 0 null 1
847 193114 1 0 null 1
620 192973 1 0 null 1
834 193105 1 0 null 1
551 170487 1 0 null 1
836 193106 1 0 null 1
723 193040 1 0 null 1
867 193128 1 0 null 1
607 192965 1 0 null 1
624 192976 1 0 null 1
991 193252 1 0 null 1
827 193098 1 0 null 1
861 193133 1 0 null 1
843 193112 1 0 null 1
854 193119 1 0 null 1
611 192967 1 0 null 1
890 193154 1 0 null 1
728 193039 1 0 null 1
980 193237 1 0 null 1
849 193115 1 0 null 1
806 193076 1 0 null 1
820 193091 1 0 null 1
8 11 1 0 null 1
845 193113 1 0 null 1
66 118 1 0 null 1
614 192966 1 0 null 1
610 192967 1 0 null 1
612 192966 1 0 null 1
855 193120 1 0 null 1
982 193236 1 0 null 1
884 193148 1 0 null 1
70 121 1 0 null 1
831 193102 1 0 null 1
856 193121 1 0 null 1
881 193145 1 0 null 1
838 193108 1 0 null 1
873 193138 1 0 null 1
851 193116 1 0 null 1
623 192976 1 0 null 1
68 120 1 0 null 1
605 192960 1 0 null 1
983 193236 1 0 null 1
993 193258 1 0 null 1
979 193234 1 0 null 1
816 193088 1 0 null 1
7 12 1 0 null 1
603 192960 1 0 null 1
981 193237 1 0 null 1
431 170435 1 0 null 1
846 193114 1 0 null 1
550 170486 1 0 null 1
649 192977 1 0 null 1
919 193171 1 0 null 1
864 193131 1 0 null 1
20 32 1 0 null 1
865 193130 1 0 null 1
724 193040 1 0 null 1
1021 19328 0 null 19 1
829 193101 1 0 null 1
868 193127 1 0 null 1
805 193077 1 0 null 1
613 192966 1 0 null 1
883 193147 1 0 null 1
647 193000 1 0 null 1
726 193039 1 0 null 1
862 193134 1 0 null 1
994 193258 1 0 null 1
549 170485 1 0 null 1
837 193107 1 0 null 1
863 193132 1 0 null 1
727 193039 1 0 null 1
409 441 1 0 null 1
833 193103 1 0 null 1
608 192965 1 0 null 1
650 193002 1 0 null 1
844 193112 1 0 null 1
625 192978 1 0 null 1
432 170436 1 0 null 1
67 116 1 0 null 1
891 193155 1 0 null 1
598 192959 1 0 null 1
850 193116 1 0 null 1
609 192967 1 0 null 1
835 193106 1 0 null 1
885 193149 1 0 null 1
725 193040 1 0 null 1
615 192968 1 0 null 1
886 193150 1 0 null 1
880 193144 1 0 null 1
606 192965 1 0 null 1
876 193140 1 0 null 1
1034 19329 0 null 14 1
840 193110 1 0 null 1
839 193108 1 0 null 1
832 193103 1 0 null 1
1020 19328 0 null 19 1
866 193129 1 0 null 1
604 192960 1 0 null 1
830 193102 1 0 null 1
875 193139 1 0 null 1
848 193115 1 0 null 1
0 null 1

View File

@@ -13,7 +13,7 @@ NTC_DNS_FAKE_IP_CB 3 ./ntcrule/full/2018-10-09/NTC_DNS_FAKE_IP_CB.0000050997
NTC_DNS_REGION 15 ./ntcrule/full/2018-10-09/NTC_DNS_REGION.0000050997
NTC_DNS_RES_STRATEGY 2 ./ntcrule/full/2018-10-09/NTC_DNS_RES_STRATEGY.0000050997
NTC_FTP_URL 5 ./ntcrule/full/2018-10-09/NTC_FTP_URL.0000050997
NTC_GROUP 103 ./ntcrule/full/2018-10-09/NTC_GROUP.0000050997
NTC_GROUP2COMPILE 103 ./ntcrule/full/2018-10-09/NTC_GROUP2COMPILE.0000050997
NTC_HTTP_REQ_BODY 4 ./ntcrule/full/2018-10-09/NTC_HTTP_REQ_BODY.0000050997
NTC_HTTP_RES_BODY 14 ./ntcrule/full/2018-10-09/NTC_HTTP_RES_BODY.0000050997
NTC_HTTP_URL 9 ./ntcrule/full/2018-10-09/NTC_HTTP_URL.0000050997

View File

@@ -52,4 +52,6 @@
29 TEST_IP_PLUGIN_WITH_EXDATA ip_plugin {"row_id":1,"ip_type":2,"start_ip":3,"end_ip":4,"valid":6} --
30 AS_NUMBER expr UTF8 UTF8 yes 0
31 SOURCE_IP_ASN virtual AS_NUMBER --
32 DESTINATION_IP_ASN virtual AS_NUMBER --
32 DESTINATION_IP_ASN virtual AS_NUMBER --
33 GeoLocation expr UTF8 UTF8 yes 0
34 SOURCE_IP_GEO virtual AS_NUMBER --

View File

@@ -401,7 +401,7 @@ TEST(StringScan, BugReport20190325)
&mid, 0);
EXPECT_EQ(ret, 1);
EXPECT_EQ(result[0].config_id, 150);
Maat_clean_status(&mid);
}
#define PrefixAndSuffixTest
TEST(StringScan, PrefixAndSuffix)
@@ -1731,9 +1731,9 @@ TEST(ScanResult, LongerServiceDefine)
free(buff);
return;
}
TEST(VirtualTable, VirtualWithPhysical)
TEST(Hierarchy, VirtualWithPhysical)
{
#define VT_VirtualWithPhysical
#define Hierarchy_VirtualWithPhysical
int ret=0, table_id=0;
const char* http_content="Batman\\:Take me Home.Superman/:Fine,stay with me.";
const char* http_url="https://blog.csdn.net/littlefang/article/details/8213058";
@@ -1760,6 +1760,7 @@ TEST(VirtualTable, VirtualWithPhysical)
EXPECT_EQ(ret, 1);
EXPECT_EQ(result[0].config_id, 160);
Maat_clean_status(&mid);
const char* should_not_hit="2018-10-05 is a keywords of table KEYWORDS_TABLE. Should not hit.";
@@ -1771,9 +1772,9 @@ TEST(VirtualTable, VirtualWithPhysical)
return;
}
TEST(VirtualTable, VirtualWithVirtual)
TEST(Hierarchy, VirtualWithVirtual)
{
#define VT_VirtualWithVirtual
#define Hierarchy_VirtualWithVirtual
int ret=0, table_id=0;
const char* http_req_hdr_ua="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36";
const char* http_resp_hdr_cookie="uid=12345678;BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; sugstore=1;";
@@ -1811,9 +1812,9 @@ TEST(VirtualTable, VirtualWithVirtual)
return;
}
TEST(VirtualTable, OneGroupInTwoVirtual)
TEST(Hierarchy, OneGroupInTwoVirtual)
{
#define VT_OneGroupInTwoVirtual
#define Hierarchy_OneGroupInTwoVirtual
int ret=0, table_id=0;
const char* http_resp_hdr_cookie="sessionid=888888;BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; sugstore=1;";
@@ -1850,31 +1851,78 @@ TEST(VirtualTable, OneGroupInTwoVirtual)
return;
}
TEST(VirtualTable, VirtualAsNonTopObject)
TEST(Hierarchy, TwoVirtualInOneClause)
{
#define VT_AsNonTopObject
#define Hierarchy_TwoVirtualInOneClause
int ret=0, table_id=0;
struct ipaddr ipv4_addr;
struct stream_tuple4_v4 v4_addr;
const char* src_asn="AS1234", *dst_asn="AS2345";
const char* my_county="Greece.Sparta";
struct Maat_rule_t result[4];
memset(result, 0, sizeof(result));
scan_status_t mid=NULL;
//--------------------------------------
// Source ASN & Dest ASN
//--------------------------------------
table_id=Maat_table_register(g_feather, "SOURCE_IP_ASN");
ASSERT_GT(table_id, 0);
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_GBK, src_asn, strlen(src_asn),
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_UTF8, src_asn, strlen(src_asn),
result, NULL, 4, &mid, 0);
EXPECT_EQ(ret, -2);
table_id=Maat_table_register(g_feather, "DESTINATION_IP_ASN");
ASSERT_GT(table_id, 0);
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_GBK, dst_asn, strlen(dst_asn),
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_UTF8, dst_asn, strlen(dst_asn),
result, NULL, 4, &mid, 0);
EXPECT_EQ(ret, 1);
EXPECT_EQ(result[0].config_id, 178);
EXPECT_EQ(result[0].config_id, 178);
Maat_clean_status(&mid);
//--------------------------------------
// Source IP & Dest ASN
//--------------------------------------
ipv4_addr_set(&ipv4_addr, &v4_addr, "192.168.40.88", 8888, "47.92.55.81", 443);
table_id=Maat_table_register(g_feather, "IP_CONFIG");
ASSERT_GT(table_id, 0);
ret=Maat_scan_proto_addr(g_feather, table_id, &ipv4_addr, 6, result, 4, &mid, 0);
EXPECT_EQ(ret, -2);
table_id=Maat_table_register(g_feather, "DESTINATION_IP_ASN");
ASSERT_GT(table_id, 0);
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_UTF8, dst_asn, strlen(dst_asn),
result, NULL, 4, &mid, 0);
EXPECT_EQ(ret, 1);
EXPECT_EQ(result[0].config_id, 178);
Maat_clean_status(&mid);
//--------------------------------------
// Source Geo & Dest ASN
//--------------------------------------
table_id=Maat_table_register(g_feather, "SOURCE_IP_GEO");
ASSERT_GT(table_id, 0);
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_UTF8, my_county, strlen(my_county),
result, NULL, 4, &mid, 0);
EXPECT_EQ(ret, -2);
table_id=Maat_table_register(g_feather, "DESTINATION_IP_ASN");
ASSERT_GT(table_id, 0);
ret=Maat_full_scan_string(g_feather, table_id, CHARSET_UTF8, dst_asn, strlen(dst_asn),
result, NULL, 4, &mid, 0);
EXPECT_EQ(ret, 1);
EXPECT_EQ(result[0].config_id, 178);
Maat_clean_status(&mid);
@@ -1890,7 +1938,7 @@ protected:
{
const char* rule_folder="./ntcrule/full/index";
logger=MESA_create_runtime_log_handle("test_maat_file.log",0);
const char* table_info="./t2_tableinfo.conf";
const char* table_info="./file_test_tableinfo.conf";
_shared_feather_f=Maat_feather(g_iThreadNum, table_info, logger);
Maat_set_feather_opt(_shared_feather_f,MAAT_OPT_INSTANCE_NAME,"files", strlen("files")+1);
Maat_set_feather_opt(_shared_feather_f, MAAT_OPT_FULL_CFG_DIR, rule_folder, strlen(rule_folder)+1);
@@ -2032,11 +2080,11 @@ int test_add_expr_command(Maat_feather_t feather,const char* region_table,int co
{
char huge_serv_def[1024*2];
memset(huge_serv_def,'s',sizeof(huge_serv_def)-1);
huge_serv_def[sizeof(huge_serv_def)-1]='\0';
struct Maat_rule_t compile;
memset(&compile,0,sizeof(compile));
memset(&compile, 0, sizeof(compile));
compile.config_id=config_id;
strcpy(compile.service_defined,"maat_command");
strcpy(compile.service_defined, "maat_command");
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile, "COMPILE", huge_serv_def, 1, label_id, timeout);
struct Maat_cmd_region region;
@@ -2053,7 +2101,7 @@ int test_add_expr_command(Maat_feather_t feather,const char* region_table,int co
struct Maat_cmd_group2compile g2c;
memset(&g2c, 0, sizeof(g2c));
g2c.group_id=Maat_cmd_get_new_group_id(feather);
g2c.table_name="GROUP";
g2c.table_name="GROUP2COMPILE";
g2c.compile_id=config_id;
g2c.Nth_clause=1;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &g2c);
@@ -2079,7 +2127,7 @@ TEST_F(MaatCmdTest, SetIP)
int ret=0;
memset(&compile, 0, sizeof(compile));
Maat_feather_t feather=MaatCmdTest::_shared_feather;
//MUST acquire by Maat_cmd_incrby to guarantee a unique compile ID.
config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
compile.config_id=config_id;
@@ -2093,10 +2141,13 @@ TEST_F(MaatCmdTest, SetIP)
g2c.group_id=Maat_cmd_get_new_group_id(feather);
g2c.compile_id=compile.config_id;
g2c.Nth_clause=1;
g2c.table_name="GROUP2COMPILE";
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &g2c);
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_before, sizeof(version_before));
EXPECT_EQ(ret, 0);
struct Maat_cmd_region region;
memset(&region, 0, sizeof(region));
@@ -2143,9 +2194,9 @@ TEST_F(MaatCmdTest, SetIP)
ret=Maat_read_state(feather,MAAT_STATE_VERSION, &version_before, sizeof(version_before));
Maat_command_raw_set_compile(feather, MAAT_OP_RENEW_TIMEOUT, &compile, "COMPILE", NULL, 1, 0, timeout+5);
Maat_command_raw_set_compile(feather, MAAT_OP_RENEW_TIMEOUT, &compile, "COMPILE", NULL, 1, 0, timeout);
sleep(timeout+5);
sleep(timeout-1);
ret=Maat_scan_proto_addr(feather,table_id,&ipv4_addr,6,&result,1, &mid,0);
EXPECT_EQ(ret, 1);
@@ -2215,7 +2266,7 @@ TEST_F(MaatCmdTest, SetExpr)
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
&result,NULL, 1,
&mid, 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(ret, -2); //compile is deleted, but region and groups are still there.
Maat_clean_status(&mid);
timeout=1;
@@ -2226,7 +2277,7 @@ TEST_F(MaatCmdTest, SetExpr)
ret=Maat_full_scan_string(feather, table_id,CHARSET_GBK, scan_data, strlen(scan_data),
&result,NULL, 1,
&mid, 0);
EXPECT_EQ(ret, 0);
EXPECT_EQ(ret, -2);
Maat_clean_status(&mid);
}
TEST_F(MaatCmdTest, RuleIDRecycle)
@@ -2262,7 +2313,7 @@ TEST_F(MaatCmdTest, RuleIDRecycle)
&result, NULL, 1,
&mid, 0);
Maat_clean_status(&mid);
EXPECT_EQ(ret, 0);
EXPECT_EQ(ret, -2);
test_add_expr_command(feather,table_name,rule_id, 0, label_id, keywords);
@@ -2320,7 +2371,8 @@ TEST_F(MaatCmdTest, SubGroup)
{
const char* table_name="HTTP_URL";
const char* group_table_name="GROUP";
const char* g2c_tn="GROUP2COMPILE";
const char* g2g_tn="GROUP2GROUP";
const char* compile_table_name="COMPILE";
const char* scan_data1="www.v2ex.com/t/573028#程序员的核心竞争力是什么";
const char* keyword1="程序员&核心竞争力";
@@ -2347,7 +2399,7 @@ TEST_F(MaatCmdTest, SubGroup)
//group1->compile1
memset(&group1, 0, sizeof(group1));
group1.group_id=Maat_cmd_get_new_group_id(feather);
group1.table_name=group_table_name;
group1.table_name=g2c_tn;
group1.compile_id=compile1.config_id;
group1.Nth_clause=1;
group1.not_flag=0;
@@ -2364,7 +2416,7 @@ TEST_F(MaatCmdTest, SubGroup)
*/
memset(&group2, 0, sizeof(group2));
group2.group_id=Maat_cmd_get_new_group_id(feather);
group2.table_name=group_table_name;
group2.table_name=g2g_tn;
group2.superior_group_id=group1.group_id;
Maat_command_raw_set_group2group(feather, MAAT_OP_ADD, &group2);
@@ -2420,7 +2472,7 @@ TEST_F(MaatCmdTest, SubGroup)
memset(&group2_g2c, 0, sizeof(group2_g2c));
group2_g2c.group_id=group2.group_id;
group2_g2c.table_name=group2.table_name;
group2_g2c.table_name=g2c_tn;
group2_g2c.compile_id=compile2.config_id;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group2_g2c);
@@ -2444,7 +2496,7 @@ TEST_F(MaatCmdTest, SubGroup)
memset(&group3, 0, sizeof(group3));
group3.group_id=Maat_cmd_get_new_group_id(feather);
group3.superior_group_id=group1.group_id;
group3.table_name=group_table_name;
group3.table_name=g2g_tn;
Maat_command_raw_set_group2group(feather, MAAT_OP_ADD, &group3);
memset(&region2, 0, sizeof(region2));
@@ -2486,12 +2538,11 @@ TEST_F(MaatCmdTest, SubGroup)
}
#define MaatCmdTest_RefGroup 0
/*
TEST_F(MaatCmdTest, RefGroup)
{
const char* table_name="HTTP_URL";
const char* group_table_name="GROUP";
const char* g2c_tn="GROUP2COMPILE";
const char* compile_table_name="COMPILE";
const char* scan_data1="m.facebook.com/help/2297503110373101?helpref=hc_nav&refid=69";
const char* keyword1="something-should-not-hit";
@@ -2501,23 +2552,23 @@ TEST_F(MaatCmdTest, RefGroup)
int table_id=0;
table_id=Maat_table_register(feather, table_name);
struct Maat_rule_t compile1;
struct Maat_group_t group1, group2;
struct Maat_region_t region1, region2;
struct Maat_cmd_group2compile group1, group2;
struct Maat_cmd_region region1, region2;
int value=0;
Maat_set_feather_opt(feather, MAAT_OPT_ENABLE_UPDATE, &value, sizeof(value));
memset(&compile1, 0, sizeof(compile1));
compile1.config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1, 0, 0);
//group1->compile1
memset(&group1, 0, sizeof(group1));
group1.group_id=Maat_cmd_get_new_group_id(feather);
group1.table_name=group_table_name;
group1.parent_id=compile1.config_id;
group1.parent_type=PARENT_TYPE_COMPILE;
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group1);
group1.table_name=g2c_tn;
group1.compile_id=compile1.config_id;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group1);
//region1->group1->compile1
@@ -2537,12 +2588,13 @@ TEST_F(MaatCmdTest, RefGroup)
value=0;
Maat_set_feather_opt(feather, MAAT_OPT_ENABLE_UPDATE, &value, sizeof(value));
//region1->group1-X-compile1
//region2->group2->compile1
// /
// /
// region2->group2
memset(&group2, 0, sizeof(group2));
group2.group_id=Maat_cmd_get_new_group_id(feather);
group2.table_name=group_table_name;
group2.parent_id=compile1.config_id;
group2.parent_type=PARENT_TYPE_COMPILE;
group2.table_name=g2c_tn;
group2.compile_id=compile1.config_id;
memset(&region2, 0, sizeof(region2));
region2.region_id=Maat_cmd_get_new_region_id(feather);
@@ -2553,10 +2605,10 @@ TEST_F(MaatCmdTest, RefGroup)
Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region2, group2.group_id);
Maat_command_raw_set_compile(feather, MAAT_OP_DEL, &compile1, compile_table_name, NULL, 1);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1);
Maat_command_raw_set_group(feather, MAAT_OP_DEL, &group1);
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group2);
Maat_command_raw_set_compile(feather, MAAT_OP_DEL, &compile1, compile_table_name, NULL, 1, 0, 0);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1, 0, 0);
Maat_command_raw_set_group2compile(feather, MAAT_OP_DEL, &group1);
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group2);
value=1;
Maat_set_feather_opt(feather, MAAT_OPT_ENABLE_UPDATE, &value, sizeof(value));
@@ -2575,31 +2627,32 @@ TEST_F(MaatCmdTest, RefGroup)
Maat_clean_status(&mid);
}
#define MaatCmdTest_VirtualTable
TEST_F(MaatCmdTest, VirtualTable)
{
Maat_feather_t feather=MaatCmdTest::_shared_feather;
const char* group_table_name="GROUP";
const char* g2c_tn="GROUP2COMPILE";
const char* compile_table_name="COMPILE";
const char* region_table_name="HTTP_SIGNATURE";
struct Maat_rule_t compile1;
struct Maat_group_t group1, group2;
struct Maat_region_t region1, region2;
struct Maat_cmd_group2compile group1, group2;
struct Maat_cmd_region region1, region2;
memset(&compile1, 0, sizeof(compile1));
compile1.config_id=(int)Maat_cmd_incrby(feather, "TEST_SEQ", 1);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 2);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 2, 0, 0);
//group1->compile1
memset(&group1, 0, sizeof(group1));
group1.group_id=Maat_cmd_get_new_group_id(feather);
group1.table_name=group_table_name;
group1.table_name=g2c_tn;
group1.virtual_table_name="HTTP_REQUEST_HEADER";
group1.parent_id=compile1.config_id;
group1.parent_type=PARENT_TYPE_COMPILE;
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group1);
group1.compile_id=compile1.config_id;
group1.Nth_clause=1;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group1);
//region1->group1->compile1
@@ -2612,17 +2665,22 @@ TEST_F(MaatCmdTest, VirtualTable)
region1.expr_rule.expr_type=EXPR_TYPE_STRING;
Maat_command_raw_set_region(feather, MAAT_OP_ADD, &region1, group1.group_id);
//group2->compile1
// region1->group1->compile1
// /
// group2-/
memset(&group2, 0, sizeof(group2));
group2.group_id=Maat_cmd_get_new_group_id(feather);
group2.table_name=group_table_name;
group2.table_name=g2c_tn;
group2.virtual_table_name="HTTP_RESPONSE_HEADER";
group2.parent_id=compile1.config_id;
group2.parent_type=PARENT_TYPE_COMPILE;
Maat_command_raw_set_group(feather, MAAT_OP_ADD, &group2);
group2.compile_id=compile1.config_id;
group2.Nth_clause=2;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group2);
//region1->group1->compile1
// /
// region2->group2-/
//region2->group2
memset(&region2, 0, sizeof(region2));
region2.region_id=Maat_cmd_get_new_region_id(feather);
region2.region_type=REGION_EXPR;
@@ -2670,9 +2728,9 @@ TEST_F(MaatCmdTest, VirtualTable)
Maat_clean_status(&mid);
//Delete group1
Maat_command_raw_set_group(feather, MAAT_OP_DEL, &group1);
Maat_command_raw_set_compile(feather, MAAT_OP_DEL, &compile1, compile_table_name, NULL, 2);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1);
Maat_command_raw_set_group2compile(feather, MAAT_OP_DEL, &group1);
Maat_command_raw_set_compile(feather, MAAT_OP_DEL, &compile1, compile_table_name, NULL, 2, 0, 0);
Maat_command_raw_set_compile(feather, MAAT_OP_ADD, &compile1, compile_table_name, NULL, 1, 0, 0);
sleep(1);
@@ -2691,7 +2749,8 @@ TEST_F(MaatCmdTest, VirtualTable)
return;
}
*/
TEST_F(MaatCmdTest, SetLines)
{
const int TEST_CMD_LINE_NUM=4;
@@ -3011,7 +3070,9 @@ TEST_F(MaatCmdTest, PluginEXData)
TEST_F(MaatCmdTest, HitPath)
{
Maat_feather_t feather=MaatCmdTest::_shared_feather;
const char* group_table_name="GROUP";
const char* g2g_tn="GROUP2GROUP";
const char* g2c_tn="GROUP2COMPILE";
const char* compile_table_name="COMPILE";
const char* table_http_sig="HTTP_SIGNATURE";
const char* table_ip="IP_CONFIG";
@@ -3030,9 +3091,10 @@ TEST_F(MaatCmdTest, HitPath)
//group1->compile1
memset(&group1, 0, sizeof(group1));
group1.group_id=Maat_cmd_get_new_group_id(feather);
group1.table_name=group_table_name;
group1.table_name=g2c_tn;
group1.virtual_table_name="HTTP_REQUEST_HEADER";
group1.compile_id=compile1.config_id;
group1.Nth_clause=1;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group1);
@@ -3049,14 +3111,15 @@ TEST_F(MaatCmdTest, HitPath)
// region1->group1->compile1
// /
// group21/
// /
// group21/
memset(&group21, 0, sizeof(group21));
group21.group_id=Maat_cmd_get_new_group_id(feather);
group21.table_name=group_table_name;
group21.table_name=g2c_tn;
group21.virtual_table_name="HTTP_RESPONSE_HEADER";
group21.compile_id=compile1.config_id;
group21.Nth_clause=2;
Maat_command_raw_set_group2compile(feather, MAAT_OP_ADD, &group21);
@@ -3066,7 +3129,7 @@ TEST_F(MaatCmdTest, HitPath)
memset(&group2, 0, sizeof(group2));
group2.group_id=Maat_cmd_get_new_group_id(feather);
group2.table_name=group_table_name;
group2.table_name=g2g_tn;
group2.superior_group_id=group21.group_id;
Maat_command_raw_set_group2group(feather, MAAT_OP_ADD, &group2);
@@ -3150,6 +3213,7 @@ TEST_F(MaatCmdTest, HitPath)
EXPECT_EQ(ret, -2);
struct Maat_hit_path_t hit_path[128];
memset(hit_path, 0, sizeof(hit_path));
int n_read=0;
n_read=Maat_get_scan_status(feather, &mid, MAAT_GET_SCAN_HIT_PATH, hit_path, sizeof(hit_path));
EXPECT_EQ(n_read, 1);
@@ -3213,7 +3277,7 @@ that the edges be all directed in the same direction.";
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
EXPECT_EQ(hit_path[path_idx].region_id, region4.region_id);
EXPECT_EQ(hit_path[path_idx].sub_group_id, group4.group_id);
EXPECT_EQ(hit_path[path_idx].top_group_id, group4.group_id);
EXPECT_EQ(hit_path[path_idx].top_group_id, -1);
EXPECT_EQ(hit_path[path_idx].virtual_table_id, 0);
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
@@ -3231,7 +3295,7 @@ that the edges be all directed in the same direction.";
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
EXPECT_EQ(hit_path[path_idx].region_id, region3.region_id);
EXPECT_EQ(hit_path[path_idx].sub_group_id, group3.group_id);
EXPECT_EQ(hit_path[path_idx].top_group_id, group3.group_id);
EXPECT_EQ(hit_path[path_idx].top_group_id, -1);
EXPECT_EQ(hit_path[path_idx].virtual_table_id, 0);
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
@@ -3245,7 +3309,7 @@ that the edges be all directed in the same direction.";
EXPECT_EQ(hit_path[path_idx].Nth_scan, Nth_scan);
EXPECT_EQ(hit_path[path_idx].region_id, region4.region_id);
EXPECT_EQ(hit_path[path_idx].sub_group_id, group4.group_id);
EXPECT_EQ(hit_path[path_idx].top_group_id, group4.group_id);
EXPECT_EQ(hit_path[path_idx].top_group_id, -1);
EXPECT_EQ(hit_path[path_idx].virtual_table_id, 0);
EXPECT_EQ(hit_path[path_idx].compile_id, -1);
Maat_stream_scan_string_end(&stream_para);