source: trunk/src/cutest_sh_tools.c@ 526

Last change on this file since 526 was 449, checked in by katerina, 11 years ago

More fixes for ticket #350 (ipv6 this time).

File size: 4.0 KB
Line 
1
2#include "config_xor.h"
3
4#include <string.h>
5#include "CuTest.h"
6#include "samhain.h"
7#include "sh_tools.h"
8#include "sh_ipvx.h"
9
10void Test_sh_tools_safe_name_01(CuTest *tc) {
11 /* xml specific */
12 char* input = strdup("hello<wo>rld\"foo&");
13 char* actual = sh_tools_safe_name(input, 1);
14#ifdef SH_USE_XML
15 char* expected = "hello=3cwo=3erld=22foo=26";
16#else
17 char* expected = "hello<wo>rld\"foo&";
18#endif
19 CuAssertStrEquals(tc, expected, actual);
20}
21
22void Test_sh_tools_safe_name_02(CuTest *tc) {
23 /* html entities */
24 char* input = strdup("hello&amp;&quot;&gt;&lt;");
25 char* actual = sh_tools_safe_name(input, 0);
26 char* expected = "hello=26=22=3e=3c";
27 CuAssertStrEquals(tc, expected, actual);
28}
29
30void Test_sh_tools_safe_name_03(CuTest *tc) {
31 char* input = strdup("\\\'hello\\");
32 char* actual = sh_tools_safe_name(input, 0);
33 char* expected = "=27hello";
34 CuAssertStrEquals(tc, expected, actual);
35
36 input = strdup("hello \"world\\\"");
37 actual = sh_tools_safe_name(input, 0);
38 expected = "hello \"world=22";
39 CuAssertStrEquals(tc, expected, actual);
40
41 input = strdup("hello\\\\");
42 actual = sh_tools_safe_name(input, 0);
43 expected = "hello=5c";
44 CuAssertStrEquals(tc, expected, actual);
45
46 input = strdup("hello\\n");
47 actual = sh_tools_safe_name(input, 0);
48 expected = "hello=0a";
49 CuAssertStrEquals(tc, expected, actual);
50}
51
52void Test_sh_tools_safe_name_04(CuTest *tc) {
53 /* invalid and valid octal code */
54 char* input = strdup("hello\\\n");
55 char* actual = sh_tools_safe_name(input, 0);
56 char* expected = "hello";
57 CuAssertStrEquals(tc, expected, actual);
58
59 input = strdup("hello\\100");
60 actual = sh_tools_safe_name(input, 0);
61 expected = "hello=40";
62 CuAssertStrEquals(tc, expected, actual);
63
64 input = strdup("h\\\"ello\\100a");
65 actual = sh_tools_safe_name(input, 0);
66 expected = "h=22ello=40a";
67 CuAssertStrEquals(tc, expected, actual);
68}
69
70void Test_sh_tools_safe_name_05(CuTest *tc) {
71 /* encoding of '=' */
72 char* input = strdup("he=llo=\"foo\"");
73 char* actual = sh_tools_safe_name(input, 0);
74 char* expected = "he=3dllo=\"foo\"";
75 CuAssertStrEquals(tc, expected, actual);
76
77 input = strdup("he=llo=<foo>");
78 actual = sh_tools_safe_name(input, 0);
79 expected = "he=3dllo=<foo>";
80 CuAssertStrEquals(tc, expected, actual);
81}
82
83void Test_sh_tools_safe_name_06(CuTest *tc) {
84 /* line break removal */
85 char* input = strdup("hello\nworld");
86 char* actual = sh_tools_safe_name(input, 0);
87 char* expected = "hello world";
88 CuAssertStrEquals(tc, expected, actual);
89}
90
91void Test_sh_tools_safe_name_07(CuTest *tc) {
92 /* non-printable chars */
93 char* input = strdup("hello world");
94 char* actual;
95 char* expected;
96
97 input[0] = 0x01;
98 input[5] = 0xFF;
99 input[10] = 0xF0;
100
101 actual = sh_tools_safe_name(input, 0);
102 expected = "=01ello=ffworl=f0";
103 CuAssertStrEquals(tc, expected, actual);
104}
105
106void Test_is_numeric_01(CuTest *tc) {
107 char* input = strdup("hello world");
108
109 CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
110
111 input = strdup("127.0.0.1");
112 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
113 input = strdup("127.0.0.de");
114 CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
115 input = strdup("127");
116 CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
117#if defined(USE_IPVX)
118 input = strdup("::1");
119 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
120 input = strdup("2002:c0a8:101::42");
121 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
122 input = strdup("2003:dead:beef:4dad:23:46:bb:101");
123 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
124 input = strdup("::192:168:0:1::");
125 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
126 input = strdup("1:1:192:168:0:1:1:1");
127 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
128 input = strdup("1:1:192:168:0:1:1:1:0");
129 CuAssertTrue(tc, !sh_ipvx_is_numeric(input));
130 input = strdup("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
131 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
132 input = strdup("2001:db8:85a3:0:0:8a2e:370:7334");
133 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
134 input = strdup("2001:db8:85a3::8a2e:370:7334");
135 CuAssertTrue(tc, sh_ipvx_is_numeric(input));
136#endif
137}
138
Note: See TracBrowser for help on using the repository browser.