OpenVAS Scanner 23.32.3
table_driven_lsc_tests.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Greenbone AG
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later
4 */
5
6#include "table_driven_lsc.c"
7
8#include <cgreen/cgreen.h>
9#include <cgreen/constraint_syntax_helpers.h>
10#include <cgreen/mocks.h>
11#include <sys/cdefs.h>
12
15{
16}
18{
19}
20
21static char *resp_str = "{"
22 "\"1.3.6.1.4.1.25623.1.1.7.2.2023.0988598199100\": ["
23 "{"
24 "\"name\": \"grafana8\","
25 "\"installed_version\": \"8.5.23\","
26 "\"fixed_version\": {"
27 "\"version\": \"8.5.24\","
28 "\"specifier\": \">=\""
29 "}"
30 "},"
31 "{"
32 "\"name\": \"grafana9\","
33 "\"installed_version\": \"9.4.7\","
34 "\"fixed_version\": {"
35 "\"start\": \"9.4.0\","
36 "\"end\": \"9.4.9\""
37 "}"
38 "}"
39 "],"
40 "\"1.3.6.1.4.1.25623.1.1.7.2.2023.10089729899100\": ["
41 "{"
42 "\"name\": \"gitlab-ce\","
43 "\"installed_version\": \"16.0.1\","
44 "\"fixed_version\": {"
45 "\"start\": \"16.0.0\","
46 "\"end\": \"16.0.7\""
47 "}"
48 "}"
49 "]"
50 "}";
51
52Ensure (lsc, make_pkg_in_json)
53{
54 char *pkglist = "pkg1.2.3\npkg4.5.6\nfoo-24\nbar-35";
55 char *json = "[\"pkg1.2.3\",\"pkg4.5.6\",\"foo-24\",\"bar-35\"]";
56
57 assert_that (strcmp (make_package_list_as_json_str (pkglist), json),
58 is_equal_to (0));
59}
60
61Ensure (lsc, process_resp)
62{
64
66 assert_that ((*advisories).count, is_equal_to (2));
67
68 assert_that ((*advisories).advisories[0]->count, is_equal_to (2));
69 assert_that ((*advisories).advisories[0]->pkgs[0]->type,
70 is_equal_to (SINGLE));
71 assert_that (
72 strcmp ((*advisories).advisories[0]->pkgs[0]->pkg_name, "grafana8"),
73 is_equal_to (0));
74 assert_that (
75 strcmp ((*advisories).advisories[0]->pkgs[0]->install_version, "8.5.23"),
76 is_equal_to (0));
77 assert_that (
78 strcmp ((*advisories).advisories[0]->pkgs[1]->pkg_name, "grafana9"),
79 is_equal_to (0));
80 assert_that (
81 strcmp ((*advisories).advisories[0]->pkgs[1]->install_version, "9.4.7"),
82 is_equal_to (0));
83
84 assert_that ((*advisories).advisories[0]->pkgs[1]->type, is_equal_to (RANGE));
85
86 assert_that ((*advisories).advisories[1]->count, is_equal_to (1));
87 assert_that ((*advisories).advisories[0]->pkgs[1]->type, is_equal_to (RANGE));
88
90}
91
92int
93main (int argc, char **argv)
94{
95 int ret;
96 TestSuite *suite;
97
98 suite = create_test_suite ();
99
100 add_test_with_context (suite, lsc, process_resp);
101 add_test_with_context (suite, lsc, make_pkg_in_json);
102 if (argc > 1)
103 ret = run_single_test (suite, argv[1], create_text_reporter ());
104 else
105 ret = run_test_suite (suite, create_text_reporter ());
106
107 destroy_test_suite (suite);
108
109 return ret;
110}
advisories_t * process_notus_response(const gchar *resp, const size_t len)
Process a json object which contains advisories and vulnerable packages.
static gchar * make_package_list_as_json_str(const char *packages)
Build a json array from the package list to start a table drive LSC.
void advisories_free(advisories_t *advisories)
Free()'s an advisories.
struct advisories advisories_t
@ SINGLE
@ RANGE
static char * resp_str
int main(int argc, char **argv)
BeforeEach(lsc)
AfterEach(lsc)
Ensure(lsc, make_pkg_in_json)
Describe(lsc)