增加单元测试用例StringScan.StreamScanUTF8

This commit is contained in:
zhengchao
2019-07-03 21:48:20 +06:00
parent 4c03f194ee
commit e12059c0aa
3 changed files with 1052 additions and 12 deletions

View File

@@ -555,7 +555,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "anything",
"user_region": "StringScan.UTF8EncodedURL",
"is_valid": "yes",
"groups": [
{
@@ -580,7 +580,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "NOT-logic-test1",
"user_region": "NOTLogic.OneRegion",
"is_valid": "yes",
"groups": [
{
@@ -621,7 +621,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "NOT-logic-test2",
"user_region": "NOTLogic.ScanNotAtLast",
"is_valid": "yes",
"groups": [
{
@@ -662,7 +662,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "NOT-logic-test3",
"user_region": "NOTLogic.ScanNotIP",
"is_valid": "yes",
"groups": [
{
@@ -692,7 +692,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "anything",
"user_region": "StringScan.Regex",
"is_valid": "yes",
"groups": [
{
@@ -717,7 +717,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "anything",
"user_region": "StringScan.UTF8EncodedURL",
"is_valid": "yes",
"groups": [
{
@@ -744,7 +744,7 @@
"compile_id": 148,
"service": 0,
"do_blacklist": 0,
"user_region": "APP_ID=100001;BEHAV_ID=100002",
"user_region": "StringScan.ExprPlusWithOffset",
"groups": [
{
"regions": [
@@ -770,7 +770,7 @@
"action": 1,
"do_blacklist": 1,
"do_log": 1,
"user_region": "anything",
"user_region": "StringScan.Regex",
"is_valid": "yes",
"groups": [
{
@@ -796,7 +796,7 @@
"do_blacklist": 0,
"do_log": 0,
"effective_rage": 0,
"user_region": "0",
"user_region": "StringScan.BugReport20190325",
"is_valid": "yes",
"groups": [
{
@@ -838,7 +838,7 @@
"do_blacklist": 0,
"do_log": 0,
"effective_rage": 0,
"user_region": "suffix_hit",
"user_region": "StringScan.PrefixAndSuffix",
"is_valid": "yes",
"groups": [
{
@@ -865,7 +865,7 @@
"do_blacklist": 0,
"do_log": 0,
"effective_rage": 0,
"user_region": "prefix_hit",
"user_region": "StringScan.PrefixAndSuffix",
"is_valid": "yes",
"groups": [
{
@@ -908,7 +908,7 @@
"do_blacklist": 0,
"do_log": 0,
"effective_rage": 0,
"user_region": "group_referer_group",
"user_region": "Policy.SubGroup",
"is_valid": "yes",
"groups": [
{
@@ -1040,6 +1040,32 @@
]
}
]
},
{
"compile_id": 157,
"service": 0,
"action": 0,
"do_blacklist": 0,
"do_log": 0,
"effective_rage": 0,
"user_region": "StringScan.StreamScanUTF8",
"is_valid": "yes",
"groups": [
{
"regions": [
{
"table_type": "expr",
"table_name": "TROJAN_PAYLOAD",
"table_content": {
"keywords": "我的订单",
"expr_type": "none",
"format": "none",
"match_method": "sub"
}
}
]
}
]
}
],
"plugin_table": [

View File

@@ -307,6 +307,7 @@ TEST(StringScan, BugReport20190325)
EXPECT_EQ(result[0].config_id, 150);
}
#define PrefixAndSuffixTest
TEST(StringScan, PrefixAndSuffix)
{
int ret=0;
@@ -1041,6 +1042,51 @@ TEST(StringScan, OffsetChunk1460)
test_offset_str_scan_with_chunk(1460);
return;
}
#define StringScan_StreamScanUTF8 1
TEST(StringScan, StreamScanUTF8)
{
//Bug report: https://mantis.mesalab.cn/view.php?id=712
int table_id=0,ret=0;
int read_size=0,pass_flag=0;
struct Maat_rule_t result[4];
scan_status_t mid=NULL;
const char* table_name="TROJAN_PAYLOAD";
const char* fn="./testdata/jd.com.html";
FILE* fp=fopen(fn,"r");
ASSERT_FALSE(fp==NULL);
char scan_data[2048];
table_id=Maat_table_register(g_feather,table_name);
ASSERT_GT(table_id, 0);
struct Maat_hit_detail_t *hit_detail=(struct Maat_hit_detail_t *)malloc(sizeof(struct Maat_hit_detail_t)*10);
stream_para_t sp=Maat_stream_scan_string_start(g_feather,table_id,0);
int detail_ret=0;
ASSERT_FALSE(sp==NULL);
while(0==feof(fp))
{
read_size=fread(scan_data,1,sizeof(scan_data),fp);
ret=Maat_stream_scan_string_detail(&sp,CHARSET_NONE,scan_data,read_size
,result,4,hit_detail,10
,&detail_ret,&mid);
if(ret>0)
{
pass_flag=1;
break;
}
}
EXPECT_EQ(pass_flag, 1);
EXPECT_EQ(result[0].config_id, 157);
Maat_stream_scan_string_end(&sp);
free(hit_detail);
fclose(fp);
Maat_clean_status(&mid);
return;
}
void accept_tags_entry_cb(int table_id,const char* table_line,void* u_para)
{

968
test/testdata/jd.com.html vendored Normal file

File diff suppressed because one or more lines are too long