source: branches/samhain-2_2-branch/src/cutest_sh_tools.c@ 447

Last change on this file since 447 was 19, checked in by rainer, 19 years ago

Rewrite of test suite, checksum for growing logs, fix for minor bug with dead client detection.

File size: 3.1 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
9void Test_sh_tools_safe_name_01(CuTest *tc) {
10 /* xml specific */
11 char* input = strdup("hello<wo>rld\"foo&");
12 char* actual = sh_tools_safe_name(input, 1);
13#ifdef SH_USE_XML
14 char* expected = "hello=3cwo=3erld=22foo=26";
15#else
16 char* expected = "hello<wo>rld\"foo&";
17#endif
18 CuAssertStrEquals(tc, expected, actual);
19}
20
21void Test_sh_tools_safe_name_02(CuTest *tc) {
22 /* html entities */
23 char* input = strdup("hello&amp;&quot;&gt;&lt;");
24 char* actual = sh_tools_safe_name(input, 0);
25 char* expected = "hello=26=22=3e=3c";
26 CuAssertStrEquals(tc, expected, actual);
27}
28
29void Test_sh_tools_safe_name_03(CuTest *tc) {
30 char* input = strdup("\\\'hello\\");
31 char* actual = sh_tools_safe_name(input, 0);
32 char* expected = "=27hello";
33 CuAssertStrEquals(tc, expected, actual);
34
35 input = strdup("hello \"world\\\"");
36 actual = sh_tools_safe_name(input, 0);
37 expected = "hello \"world=22";
38 CuAssertStrEquals(tc, expected, actual);
39
40 input = strdup("hello\\\\");
41 actual = sh_tools_safe_name(input, 0);
42 expected = "hello=5c";
43 CuAssertStrEquals(tc, expected, actual);
44
45 input = strdup("hello\\n");
46 actual = sh_tools_safe_name(input, 0);
47 expected = "hello=0a";
48 CuAssertStrEquals(tc, expected, actual);
49}
50
51void Test_sh_tools_safe_name_04(CuTest *tc) {
52 /* invalid and valid octal code */
53 char* input = strdup("hello\\\n");
54 char* actual = sh_tools_safe_name(input, 0);
55 char* expected = "hello";
56 CuAssertStrEquals(tc, expected, actual);
57
58 input = strdup("hello\\100");
59 actual = sh_tools_safe_name(input, 0);
60 expected = "hello=40";
61 CuAssertStrEquals(tc, expected, actual);
62
63 input = strdup("h\\\"ello\\100a");
64 actual = sh_tools_safe_name(input, 0);
65 expected = "h=22ello=40a";
66 CuAssertStrEquals(tc, expected, actual);
67}
68
69void Test_sh_tools_safe_name_05(CuTest *tc) {
70 /* encoding of '=' */
71 char* input = strdup("he=llo=\"foo\"");
72 char* actual = sh_tools_safe_name(input, 0);
73 char* expected = "he=3dllo=\"foo\"";
74 CuAssertStrEquals(tc, expected, actual);
75
76 input = strdup("he=llo=<foo>");
77 actual = sh_tools_safe_name(input, 0);
78 expected = "he=3dllo=<foo>";
79 CuAssertStrEquals(tc, expected, actual);
80}
81
82void Test_sh_tools_safe_name_06(CuTest *tc) {
83 /* line break removal */
84 char* input = strdup("hello\nworld");
85 char* actual = sh_tools_safe_name(input, 0);
86 char* expected = "hello world";
87 CuAssertStrEquals(tc, expected, actual);
88}
89
90void Test_sh_tools_safe_name_07(CuTest *tc) {
91 /* non-printable chars */
92 char* input = strdup("hello world");
93 char* actual;
94 char* expected;
95
96 input[0] = 0x01;
97 input[5] = 0xFF;
98 input[10] = 0xF0;
99
100 actual = sh_tools_safe_name(input, 0);
101 expected = "=01ello=ffworl=f0";
102 CuAssertStrEquals(tc, expected, actual);
103}
104
105void Test_is_numeric_01(CuTest *tc) {
106 char* input = strdup("hello world");
107
108 CuAssertTrue(tc, !is_numeric(input));
109
110 input = strdup("127.0.0.1");
111 CuAssertTrue(tc, is_numeric(input));
112 input = strdup("127.0.0.de");
113 CuAssertTrue(tc, !is_numeric(input));
114 input = strdup("127");
115 CuAssertTrue(tc, is_numeric(input));
116}
117
Note: See TracBrowser for help on using the repository browser.