1 /*
2 * Copyright (c) 2018 Balabit
3 * Copyright (c) 2013 Gergely Nagy <algernon@balabit.hu>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * As an additional exemption you are allowed to compile & link against the
20 * OpenSSL libraries as published by the OpenSSL project. See the file
21 * COPYING for details.
22 *
23 */
24 #include "filter/filter-expr.h"
25 #include "filter/filter-re.h"
26 #include "filter/filter-pri.h"
27 #include "filter/filter-op.h"
28 #include "filter/filter-cmp.h"
29 #include "filter/filter-expr-grammar.h"
30 #include "cfg.h"
31 #include "test_filters_common.h"
32
33 #include <criterion/criterion.h>
34 #include <criterion/parameterized.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <stdio.h>
38
39 TestSuite(filter, .init = setup, .fini = teardown);
40
41 typedef struct _FilterParamFopCmp
42 {
43 const gchar *msg;
44 const gchar *template1;
45 const gchar *template2;
46 gint op;
47 gboolean expected_result;
48 } FilterParamFopCmp;
49
50
ParameterizedTestParameters(filter,test_filter_fop_cmp)51 ParameterizedTestParameters(filter, test_filter_fop_cmp)
52 {
53 static FilterParamFopCmp test_data_list[] =
54 {
55 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "7", .op = KW_NUM_EQ, .expected_result = TRUE},
56 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "5", .op = KW_NUM_NE, .expected_result = TRUE},
57 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "8", .op = KW_NUM_LT, .expected_result = TRUE},
58 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "10", .op = KW_NUM_LT, .expected_result = TRUE},
59 /* 7 lt 10 is FALSE as 10 orders lower when interpreted as a string */
60 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "10", .op = KW_LT, .expected_result = FALSE},
61 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "5", .op = KW_NUM_GT, .expected_result = TRUE},
62 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "7", .op = KW_NUM_GE, .expected_result = TRUE},
63 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "$LEVEL_NUM", .template2 = "7", .op = KW_NUM_LE, .expected_result = TRUE},
64 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "korte", .op = KW_LT, .expected_result = TRUE},
65 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "korte", .op = KW_LE, .expected_result = TRUE},
66 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "korte", .op = KW_EQ, .expected_result = FALSE},
67 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "korte", .op = KW_NE, .expected_result = TRUE},
68 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "korte", .op = KW_GE, .expected_result = FALSE},
69 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "korte", .op = KW_GT, .expected_result = FALSE},
70 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "korte", .template2 = "alma", .op = KW_LT, .expected_result = FALSE},
71 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "korte", .template2 = "alma", .op = KW_LE, .expected_result = FALSE},
72 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "korte", .template2 = "alma", .op = KW_EQ, .expected_result = FALSE},
73 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "korte", .template2 = "alma", .op = KW_NE, .expected_result = TRUE},
74 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "korte", .template2 = "alma", .op = KW_GE, .expected_result = TRUE},
75 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "korte", .template2 = "alma", .op = KW_GT, .expected_result = TRUE},
76 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "alma", .op = KW_LT, .expected_result = FALSE},
77 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "alma", .op = KW_LE, .expected_result = TRUE},
78 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "alma", .op = KW_EQ, .expected_result = TRUE},
79 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "alma", .op = KW_NE, .expected_result = FALSE},
80 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "alma", .op = KW_GE, .expected_result = TRUE},
81 {.msg = "<15>Oct 15 16:17:01 host openvpn[2499]: PTHREAD support initialized", .template1 = "alma", .template2 = "alma", .op = KW_GT, .expected_result = FALSE},
82 };
83
84 return cr_make_param_array(FilterParamFopCmp, test_data_list, G_N_ELEMENTS(test_data_list));
85 }
86
ParameterizedTest(FilterParamFopCmp * param,filter,test_filter_fop_cmp)87 ParameterizedTest(FilterParamFopCmp *param, filter, test_filter_fop_cmp)
88 {
89 FilterExprNode *filter = fop_cmp_new(create_template(param->template1), create_template(param->template2), param->op);
90 testcase(param->msg, filter, param->expected_result);
91 }
92