18#include "../util-unittest.h"
20#define TEST_OK(str, m, lo, hi) \
22 DetectU64Data *bsz = DetectU64Parse((str)); \
24 FAIL_IF_NOT(bsz->mode == (m)); \
25 DetectBsizeFree(NULL, bsz); \
26 SCLogDebug("str %s OK", (str)); \
28#define TEST_FAIL(str) \
30 DetectU64Data *bsz = DetectU64Parse((str)); \
31 FAIL_IF_NOT_NULL(bsz); \
34static int DetectBsizeTest01(
void)
51static int DetectBsizeTest02(
void)
69static int DetectBsizeTest03(
void)
86static int DetectBsizeTest04(
void)
99#define TEST_OK(rule) \
101 DetectEngineCtx *de_ctx = DetectEngineCtxInit(); \
102 FAIL_IF_NULL(de_ctx); \
103 SCLogNotice("rule: %s", rule); \
104 Signature *s = DetectEngineAppendSig(de_ctx, (rule)); \
106 DetectEngineCtxFree(de_ctx); \
109#define TEST_FAIL(rule) \
111 DetectEngineCtx *de_ctx = DetectEngineCtxInit(); \
112 FAIL_IF_NULL(de_ctx); \
113 SCLogNotice("rule: %s", rule); \
114 Signature *s = DetectEngineAppendSig(de_ctx, (rule)); \
115 FAIL_IF_NOT_NULL(s); \
116 DetectEngineCtxFree(de_ctx); \
119static int DetectBsizeSigTest01(
void)
121 TEST_OK(
"alert http any any -> any any (http_request_line; bsize:10; sid:1;)");
122 TEST_OK(
"alert http any any -> any any (file_data; bsize:>1000; sid:2;)");
125 TEST_OK(
"alert http any any -> any any (http.uri; content:\"/index.php\"; bsize:>1024; "
127 TEST_OK(
"alert http any any -> any any (http.uri; content:\"abcdefgh123456\"; bsize:<20; "
129 TEST_OK(
"alert http any any -> any any (http.uri; content:\"abcdefgh123456\"; bsize:15<>25; "
131 TEST_OK(
"alert http any any -> any any (http.uri; content:\"abcdefgh123456\"; bsize:10<>15; "
134 TEST_FAIL(
"alert tcp any any -> any any (content:\"abc\"; bsize:10; sid:3;)");
135 TEST_FAIL(
"alert http any any -> any any (content:\"GET\"; http_method; bsize:10; sid:4;)");
136 TEST_FAIL(
"alert http any any -> any any (http_request_line; content:\"GET\"; bsize:<10>; "
139 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abcdefgh123456\"; bsize:2; "
141 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abcdefgh123456\"; bsize:<13; "
144 "alert http any any -> any any (http.uri; content:\"abcdef\"; content: \"g\"; bsize:1; "
147 "alert http any any -> any any (http.uri; content:\"abcdef\"; content: \"g\"; bsize:4; "
149 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abcdefghi123456\"; offset:12; "
150 "bsize:3; sid:14;)");
151 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abc\"; offset:3; depth:3; "
152 "bsize:3; sid:15;)");
153 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abcdef\"; content: \"gh\"; "
154 "bsize:1; sid:16;)");
155 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abc\"; offset:3; bsize:3; "
157 TEST_FAIL(
"alert http any any -> any any (http.uri; content:\"abc\"; offset:65535; bsize:3; "
159 TEST_FAIL(
"alert http any any -> any any (http.user_agent; content:\"Suricata-UA\"; bsize:11; "
160 "content:!\"abc\"; distance:2; within:3; sid: 19;)");
167static void DetectBsizeRegisterTests(
void)
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define PASS
Pass the test.
#define TEST_OK(str, m, lo, hi)