suricata
app-layer-htp-file.c
Go to the documentation of this file.
1 /* Copyright (C) 2019 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 "../app-layer-htp-file.h"
19 #include "../util-unittest.h"
20 
21 /**
22  * \test AppLayerHtpFileParseContentRangeTest01 is a test
23  * for setting up a valid range value.
24  */
25 
26 static int AppLayerHtpFileParseContentRangeTest01 (void)
27 {
28  HTTPContentRange range;
29  bstr * rawvalue = bstr_dup_c("bytes 12-25/100");
30  FAIL_IF_NOT(HTPParseContentRange(rawvalue, &range) == 0);
31  FAIL_IF_NOT(range.start == 12);
32  FAIL_IF_NOT(range.end == 25);
33  FAIL_IF_NOT(range.size == 100);
34  bstr_free(rawvalue);
35  PASS;
36 }
37 
38 /**
39  * \test AppLayerHtpFileParseContentRangeTest02 is a regression test
40  * for setting up an invalid range value.
41  */
42 
43 static int AppLayerHtpFileParseContentRangeTest02 (void)
44 {
45  HTTPContentRange range;
46  bstr * rawvalue = bstr_dup_c("bytes 15335424-27514354/");
47  FAIL_IF(HTPParseContentRange(rawvalue, &range) == 0);
48  bstr_free(rawvalue);
49  PASS;
50 }
51 
52 /**
53  * \test AppLayerHtpFileParseContentRangeTest03 is a regression test
54  * for setting up an invalid range value.
55  */
56 
57 static int AppLayerHtpFileParseContentRangeTest03 (void)
58 {
59  HTTPContentRange range;
60  bstr * rawvalue = bstr_dup_c("bytes 15335424-");
61  FAIL_IF(HTPParseContentRange(rawvalue, &range) == 0);
62  bstr_free(rawvalue);
63  PASS;
64 }
65 
66 
67 /**
68  * \test AppLayerHtpFileParseContentRangeTest04 is a test
69  * for setting up a valid range value without the size.
70  */
71 
72 static int AppLayerHtpFileParseContentRangeTest04 (void)
73 {
74  HTTPContentRange range;
75  bstr * rawvalue = bstr_dup_c("bytes 24-42/*");
76  FAIL_IF_NOT(HTPParseContentRange(rawvalue, &range) == 0);
77  FAIL_IF_NOT(range.start == 24);
78  FAIL_IF_NOT(range.end == 42);
79  bstr_free(rawvalue);
80  PASS;
81 }
82 
83 /**
84  * \brief this function registers unit tests for AppLayerHtpFile
85  */
87 {
88  UtRegisterTest("AppLayerHtpFileParseContentRangeTest01", AppLayerHtpFileParseContentRangeTest01);
89  UtRegisterTest("AppLayerHtpFileParseContentRangeTest02", AppLayerHtpFileParseContentRangeTest02);
90  UtRegisterTest("AppLayerHtpFileParseContentRangeTest03", AppLayerHtpFileParseContentRangeTest03);
91  UtRegisterTest("AppLayerHtpFileParseContentRangeTest04", AppLayerHtpFileParseContentRangeTest04);
92 }
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
HTPParseContentRange
int HTPParseContentRange(bstr *rawvalue, HTTPContentRange *range)
Definition: app-layer-htp-file.c:96
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
AppLayerHtpFileRegisterTests
void AppLayerHtpFileRegisterTests(void)
this function registers unit tests for AppLayerHtpFile
Definition: app-layer-htp-file.c:86
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71