suricata
app-layer-htp-file.c
Go to the documentation of this file.
1 
2 /* Copyright (C) 2019 Open Information Security Foundation
3  *
4  * You can copy, redistribute or modify this Program under the terms of
5  * the GNU General Public License version 2 as published by the Free
6  * Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * version 2 along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301, USA.
17  */
18 
19 #include "../app-layer-htp-file.h"
20 #include "../util-unittest.h"
21 
22 /**
23  * \test AppLayerHtpFileParseContentRangeTest01 is a test
24  * for setting up a valid range value.
25  */
26 
27 static int AppLayerHtpFileParseContentRangeTest01 (void)
28 {
29  HtpContentRange range;
30  bstr * rawvalue = bstr_dup_c("bytes 12-25/100");
31  FAIL_IF_NOT(HTPParseContentRange(rawvalue, &range) == HTP_OK);
32  FAIL_IF_NOT(range.start == 12);
33  FAIL_IF_NOT(range.end == 25);
34  FAIL_IF_NOT(range.size == 100);
35  bstr_free(rawvalue);
36  PASS;
37 }
38 
39 /**
40  * \test AppLayerHtpFileParseContentRangeTest02 is a regression test
41  * for setting up an invalid range value.
42  */
43 
44 static int AppLayerHtpFileParseContentRangeTest02 (void)
45 {
46  HtpContentRange range;
47  bstr * rawvalue = bstr_dup_c("bytes 15335424-27514354/");
48  FAIL_IF(HTPParseContentRange(rawvalue, &range) == HTP_OK);
49  bstr_free(rawvalue);
50  PASS;
51 }
52 
53 /**
54  * \test AppLayerHtpFileParseContentRangeTest03 is a regression test
55  * for setting up an invalid range value.
56  */
57 
58 static int AppLayerHtpFileParseContentRangeTest03 (void)
59 {
60  HtpContentRange range;
61  bstr * rawvalue = bstr_dup_c("bytes 15335424-");
62  FAIL_IF(HTPParseContentRange(rawvalue, &range) == HTP_OK);
63  bstr_free(rawvalue);
64  PASS;
65 }
66 
67 
68 /**
69  * \test AppLayerHtpFileParseContentRangeTest04 is a test
70  * for setting up a valid range value without the size.
71  */
72 
73 static int AppLayerHtpFileParseContentRangeTest04 (void)
74 {
75  HtpContentRange range;
76  bstr * rawvalue = bstr_dup_c("bytes 24-42/*");
77  FAIL_IF_NOT(HTPParseContentRange(rawvalue, &range) == HTP_OK);
78  FAIL_IF_NOT(range.start == 24);
79  FAIL_IF_NOT(range.end == 42);
80  bstr_free(rawvalue);
81  PASS;
82 }
83 
84 /**
85  * \brief this function registers unit tests for AppLayerHtpFile
86  */
88 {
89  UtRegisterTest("AppLayerHtpFileParseContentRangeTest01", AppLayerHtpFileParseContentRangeTest01);
90  UtRegisterTest("AppLayerHtpFileParseContentRangeTest02", AppLayerHtpFileParseContentRangeTest02);
91  UtRegisterTest("AppLayerHtpFileParseContentRangeTest03", AppLayerHtpFileParseContentRangeTest03);
92  UtRegisterTest("AppLayerHtpFileParseContentRangeTest04", AppLayerHtpFileParseContentRangeTest04);
93 }
void AppLayerHtpFileRegisterTests(void)
this function registers unit tests for AppLayerHtpFile
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:71
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
int HTPParseContentRange(bstr *rawvalue, HtpContentRange *range)
#define FAIL_IF_NOT(expr)
Fail a test if expression to true.
Definition: util-unittest.h:82