Greenbone Vulnerability Management Libraries 22.32.0
nvti_tests.c File Reference
#include "nvti.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Include dependency graph for nvti_tests.c:

Go to the source code of this file.

Functions

 Describe (nvti)
 BeforeEach (nvti)
 AfterEach (nvti)
 Ensure (nvti, nvti_new_never_returns_null)
 Ensure (nvti, nvti_parse_timestamp)
 Ensure (nvti, nvti_set_solution_method_correct)
 Ensure (nvti, nvti_get_tag_gets_correct_value_one_tag)
 Ensure (nvti, nvti_get_tag_gets_correct_value_many_tags)
 Ensure (nvti, nvti_get_tag_handles_empty_tag)
 Ensure (nvti, nvti_get_tag_handles_null_nvti)
 Ensure (nvti, nvti_get_tag_handles_null_name)
 Ensure (nvti, nvtis_add_does_not_use_oid_as_key)
 Ensure (nvti, nvti_get_severity_vector_both)
 Ensure (nvti, nvti_get_severity_vector_no_cvss_base)
 Ensure (nvti, nvti_get_severity_vector_no_severity_vector)
int main (int argc, char **argv)

Function Documentation

◆ AfterEach()

AfterEach ( nvti )

Definition at line 15 of file nvti_tests.c.

16{
17}

◆ BeforeEach()

BeforeEach ( nvti )

Definition at line 12 of file nvti_tests.c.

13{
14}

◆ Describe()

Describe ( nvti )

◆ Ensure() [1/12]

Ensure ( nvti ,
nvti_get_severity_vector_both  )

Definition at line 157 of file nvti_tests.c.

158{
159 nvti_t *nvti;
160 gchar *vector;
161
162 nvti = nvti_new ();
163 nvti_set_tag (nvti, "cvss_base_vector=DEF");
164 nvti_set_tag (nvti, "severity_vector=ABC");
165
167
168 assert_that (vector, is_equal_to_string ("ABC"));
169
170 g_free (vector);
171 nvti_free (nvti);
172}
nvti_t * nvti_new(void)
Create a new (empty) nvti structure.
Definition nvti.c:559
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
int nvti_set_tag(nvti_t *n, const gchar *tag)
Set the tags of a NVT.
Definition nvti.c:1625
gchar * nvti_severity_vector_from_tag(const nvti_t *n)
Get the severity score.
Definition nvti.c:900
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition nvti.c:570
The structure of a information record that corresponds to a NVT.
Definition nvti.c:358

References nvti_free(), nvti_new(), nvti_set_tag(), and nvti_severity_vector_from_tag().

Here is the call graph for this function:

◆ Ensure() [2/12]

Ensure ( nvti ,
nvti_get_severity_vector_no_cvss_base  )

Definition at line 174 of file nvti_tests.c.

175{
176 nvti_t *nvti;
177 gchar *vector;
178
179 nvti = nvti_new ();
180 nvti_set_tag (nvti, "severity_vector=ABC");
181
183
184 assert_that (vector, is_equal_to_string ("ABC"));
185
186 g_free (vector);
187 nvti_free (nvti);
188}

References nvti_free(), nvti_new(), nvti_set_tag(), and nvti_severity_vector_from_tag().

Here is the call graph for this function:

◆ Ensure() [3/12]

Ensure ( nvti ,
nvti_get_severity_vector_no_severity_vector  )

Definition at line 190 of file nvti_tests.c.

191{
192 nvti_t *nvti;
193 gchar *vector;
194
195 nvti = nvti_new ();
196 nvti_set_tag (nvti, "cvss_base_vector=DEF");
197
199 assert_that (vector, is_equal_to_string ("DEF"));
200
201 g_free (vector);
202 nvti_free (nvti);
203}

References nvti_free(), nvti_new(), nvti_set_tag(), and nvti_severity_vector_from_tag().

Here is the call graph for this function:

◆ Ensure() [4/12]

Ensure ( nvti ,
nvti_get_tag_gets_correct_value_many_tags  )

Definition at line 82 of file nvti_tests.c.

83{
84 nvti_t *nvti;
85 gchar *tag;
86
87 nvti = nvti_new ();
88 nvti_set_tag (nvti, "a=1|b=2|c=3");
89 tag = nvti_get_tag (nvti, "b");
90
91 assert_that (tag, is_equal_to_string ("2"));
92
93 g_free (tag);
95}
gchar * nvti_get_tag(const nvti_t *n, const gchar *name)
Get a tag value by a tag name.
Definition nvti.c:982

References nvti_free(), nvti_get_tag(), nvti_new(), and nvti_set_tag().

Here is the call graph for this function:

◆ Ensure() [5/12]

Ensure ( nvti ,
nvti_get_tag_gets_correct_value_one_tag  )

Definition at line 67 of file nvti_tests.c.

68{
69 nvti_t *nvti;
70 gchar *tag;
71
72 nvti = nvti_new ();
73 nvti_set_tag (nvti, "a=1");
74 tag = nvti_get_tag (nvti, "a");
75
76 assert_that (tag, is_equal_to_string ("1"));
77
78 g_free (tag);
80}

References nvti_free(), nvti_get_tag(), nvti_new(), and nvti_set_tag().

Here is the call graph for this function:

◆ Ensure() [6/12]

Ensure ( nvti ,
nvti_get_tag_handles_empty_tag  )

Definition at line 97 of file nvti_tests.c.

98{
99 nvti_t *nvti;
100
101 nvti = nvti_new ();
102
103 assert_that (nvti_get_tag (nvti, "b"), is_null);
104
105 nvti_free (nvti);
106}

References nvti_free(), nvti_get_tag(), and nvti_new().

Here is the call graph for this function:

◆ Ensure() [7/12]

Ensure ( nvti ,
nvti_get_tag_handles_null_name  )

Definition at line 113 of file nvti_tests.c.

114{
115 nvti_t *nvti;
116
117 nvti = nvti_new ();
118 nvti_set_tag (nvti, "example=1");
119
120 assert_that (nvti_get_tag (nvti, NULL), is_null);
121
122 nvti_free (nvti);
123}

References nvti_free(), nvti_get_tag(), nvti_new(), and nvti_set_tag().

Here is the call graph for this function:

◆ Ensure() [8/12]

Ensure ( nvti ,
nvti_get_tag_handles_null_nvti  )

Definition at line 108 of file nvti_tests.c.

109{
110 assert_that (nvti_get_tag (NULL, "example"), is_null);
111}

References nvti_get_tag().

Here is the call graph for this function:

◆ Ensure() [9/12]

Ensure ( nvti ,
nvti_new_never_returns_null  )

Definition at line 21 of file nvti_tests.c.

22{
23 nvti_t *nvti;
24
25 nvti = nvti_new ();
26 assert_that (nvti, is_not_null);
28}

References nvti_free(), and nvti_new().

Here is the call graph for this function:

◆ Ensure() [10/12]

Ensure ( nvti ,
nvti_parse_timestamp  )

Definition at line 32 of file nvti_tests.c.

33{
34 setenv ("TZ", "utc 0", 1);
35 tzset ();
36
37 assert_that (
38 parse_nvt_timestamp ("2018-09-07 11:08:31 +0200 (Fri, 07 Sep 2018)"),
39 is_equal_to (1536311311));
40 assert_that_double (
41 parse_nvt_timestamp ("2022-05-31 20:54:22 +0100 (Tue, 31 May 2022)"),
42 is_equal_to_double (1654026862));
43 assert_that_double (parse_nvt_timestamp ("2012-09-23 02:15:34 +0400"),
44 is_equal_to_double (1348352134));
45 assert_that_double (parse_nvt_timestamp ("Fri Feb 10 16:09:30 2023 +0100"),
46 is_equal_to_double (1676041770));
47}
static time_t parse_nvt_timestamp(const gchar *str_time)
Try convert an NVT tag time string into epoch time or return 0 upon parse errors.
Definition nvti.c:295

References parse_nvt_timestamp().

Here is the call graph for this function:

◆ Ensure() [11/12]

Ensure ( nvti ,
nvti_set_solution_method_correct  )

Definition at line 51 of file nvti_tests.c.

52{
53 nvti_t *nvti;
54 gchar *solution_method;
55
56 nvti = nvti_new ();
57 nvti_set_solution_method (nvti, "DebianAPTUpgrade");
58 solution_method = nvti_solution_method (nvti);
59
60 assert_that (solution_method, is_equal_to_string ("DebianAPTUpgrade"));
61
63}
gchar * nvti_solution_method(const nvti_t *n)
Get the solution method.
Definition nvti.c:952
int nvti_set_solution_method(nvti_t *n, const gchar *solution_method)
Set the solution method of a NVT.
Definition nvti.c:1534

References nvti_free(), nvti_new(), nvti_set_solution_method(), and nvti_solution_method().

Here is the call graph for this function:

◆ Ensure() [12/12]

Ensure ( nvti ,
nvtis_add_does_not_use_oid_as_key  )

Definition at line 127 of file nvti_tests.c.

128{
129 nvtis_t *nvtis;
130 nvti_t *nvti;
131 gchar *oid;
132
133 nvtis = nvtis_new ();
134
135 nvti = nvti_new ();
136 nvti_set_oid (nvti, "1");
137
138 oid = nvti_oid (nvti);
139
140 /* This should not use the pointer nvti->oid as the key, because nvti_set_oid
141 * could free nvti->oid. */
142 nvtis_add (nvtis, nvti);
143
144 /* Change the first character of the OID. */
145 *oid = '2';
146
147 /* To check that the key is not the same pointer as nvti->oid, check
148 * that changing the first character of nvti->oid did not affect the key. */
149 assert_that (nvtis_lookup (nvtis, "1"), is_not_null);
150 assert_that (nvtis_lookup (nvtis, "2"), is_null);
151
152 nvtis_free (nvtis);
153}
nvtis_t * nvtis_new(void)
Make a collection of NVT Infos.
Definition nvti.c:2208
int nvti_set_oid(nvti_t *n, const gchar *oid)
Set the OID of a NVT Info.
Definition nvti.c:1214
gchar * nvti_oid(const nvti_t *n)
Get the OID string.
Definition nvti.c:611
nvti_t * nvtis_lookup(nvtis_t *nvtis, const char *oid)
Add an NVT Info to a collection of NVT Infos.
Definition nvti.c:2250
void nvtis_add(nvtis_t *nvtis, nvti_t *nvti)
Add an NVT Info to a collection of NVT Infos.
Definition nvti.c:2233
void nvtis_free(nvtis_t *nvtis)
Free a collection of NVT Infos.
Definition nvti.c:2220
GHashTable nvtis_t
A collection of information records corresponding to NVTs.
Definition nvti.h:252

References nvti_new(), nvti_oid(), nvti_set_oid(), nvtis_add(), nvtis_free(), nvtis_lookup(), and nvtis_new().

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 208 of file nvti_tests.c.

209{
210 int ret;
211 TestSuite *suite;
212
213 suite = create_test_suite ();
214
215 add_test_with_context (suite, nvti, nvti_new_never_returns_null);
216
217 add_test_with_context (suite, nvti, nvti_get_tag_gets_correct_value_one_tag);
218 add_test_with_context (suite, nvti,
219 nvti_get_tag_gets_correct_value_many_tags);
220 add_test_with_context (suite, nvti, nvti_get_tag_handles_empty_tag);
221 add_test_with_context (suite, nvti, nvti_get_tag_handles_null_nvti);
222 add_test_with_context (suite, nvti, nvti_get_tag_handles_null_name);
223
224 add_test_with_context (suite, nvti, nvti_set_solution_method_correct);
225
226 add_test_with_context (suite, nvti, nvtis_add_does_not_use_oid_as_key);
227
228 add_test_with_context (suite, nvti, nvti_get_severity_vector_both);
229 add_test_with_context (suite, nvti,
230 nvti_get_severity_vector_no_severity_vector);
231 add_test_with_context (suite, nvti, nvti_get_severity_vector_no_cvss_base);
232 add_test_with_context (suite, nvti, nvti_parse_timestamp);
233
234 if (argc > 1)
235 ret = run_single_test (suite, argv[1], create_text_reporter ());
236 else
237 ret = run_test_suite (suite, create_text_reporter ());
238
239 destroy_test_suite (suite);
240
241 return ret;
242}