suricata
detect-http2.c
Go to the documentation of this file.
1 /* Copyright (C) 2020 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "../suricata-common.h"
19 
20 #include "../detect-engine.h"
21 
22 #include "../detect-http2.h"
23 
24 #include "../util-unittest.h"
25 
26 /**
27  * \test signature with a valid http2.frametype value.
28  */
29 
30 static int DetectHTTP2frameTypeParseTest01 (void)
31 {
34 
36  "alert http2 any any -> any any (http2.frametype:GOAWAY; sid:1; rev:1;)");
37  FAIL_IF_NULL(sig);
38 
40  PASS;
41 }
42 
43 /**
44  * \brief this function registers unit tests for DetectHTTP2frameType
45  */
47 {
48  UtRegisterTest("DetectHTTP2frameTypeParseTest01", DetectHTTP2frameTypeParseTest01);
49 }
50 
51 /**
52  * \test signature with a valid http2.errorcode value.
53  */
54 
55 static int DetectHTTP2errorCodeParseTest01 (void)
56 {
59 
61  "alert http2 any any -> any any (http2.errorcode:NO_ERROR; sid:1; rev:1;)");
62  FAIL_IF_NULL(sig);
63 
65  PASS;
66 }
67 
69 {
70  UtRegisterTest("DetectHTTP2errorCodeParseTest01", DetectHTTP2errorCodeParseTest01);
71 }
72 
73 /**
74  * \test signature with a valid http2.priority value.
75  */
76 
77 static int DetectHTTP2priorityParseTest01 (void)
78 {
81 
83  "alert http2 any any -> any any (http2.priority:>100; sid:1; rev:1;)");
84  FAIL_IF_NULL(sig);
85 
87  PASS;
88 }
89 
91 {
92  UtRegisterTest("DetectHTTP2priorityParseTest01", DetectHTTP2priorityParseTest01);
93 }
94 
95 /**
96  * \test signature with a valid http2.window value.
97  */
98 
99 static int DetectHTTP2windowParseTest01 (void)
100 {
103 
105  "alert http2 any any -> any any (http2.window:<42; sid:1; rev:1;)");
106  FAIL_IF_NULL(sig);
107 
109  PASS;
110 }
111 
113 {
114  UtRegisterTest("DetectHTTP2windowParseTest01", DetectHTTP2windowParseTest01);
115 }
116 
117 
118 /**
119  * \test signature with a valid http2.settings value.
120  */
121 
122 static int DetectHTTP2settingsParseTest01 (void)
123 {
126 
128  "alert http2 any any -> any any (http2.settings:SETTINGS_MAX_HEADER_LIST_SIZE >1024; sid:1; rev:1;)");
129  FAIL_IF_NULL(sig);
130 
132  PASS;
133 }
134 
136 {
137  UtRegisterTest("DetectHTTP2settingsParseTest01", DetectHTTP2settingsParseTest01);
138 }
139 
140 
141 /**
142 * \test signature with a valid http2.size_update value.
143 */
144 
145 static int DetectHTTP2sizeUpdateParseTest01 (void)
146 {
149 
151  "alert http2 any any -> any any (http2.size_update:>4096; sid:1; rev:1;)");
152  FAIL_IF_NULL(sig);
153 
155  PASS;
156 }
157 
159 {
160  UtRegisterTest("DetectHTTP2sizeUpdateParseTest01", DetectHTTP2sizeUpdateParseTest01);
161 }
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
DetectHTTP2priorityRegisterTests
void DetectHTTP2priorityRegisterTests(void)
Definition: detect-http2.c:90
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:841
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2611
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:2587
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:17
DetectHTTP2sizeUpdateRegisterTests
void DetectHTTP2sizeUpdateRegisterTests(void)
Definition: detect-http2.c:158
DetectHTTP2settingsRegisterTests
void DetectHTTP2settingsRegisterTests(void)
Definition: detect-http2.c:135
DetectHTTP2windowRegisterTests
void DetectHTTP2windowRegisterTests(void)
Definition: detect-http2.c:112
DetectHTTP2errorCodeRegisterTests
void DetectHTTP2errorCodeRegisterTests(void)
Definition: detect-http2.c:68
Signature_
Signature container.
Definition: detect.h:601
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2572
DetectHTTP2frameTypeRegisterTests
void DetectHTTP2frameTypeRegisterTests(void)
this function registers unit tests for DetectHTTP2frameType
Definition: detect-http2.c:46