Greenbone Vulnerability Management Libraries 22.32.0
vtparser_tests.c File Reference
#include "../base/nvti.h"
#include "vtparser.c"
#include <cgreen/assertions.h>
#include <cgreen/cgreen.h>
#include <cgreen/constraint_syntax_helpers.h>
#include <cgreen/internal/c_assertions.h>
#include <cgreen/mocks.h>
Include dependency graph for vtparser_tests.c:

Go to the source code of this file.

Macros

#define VT_NAME   "Example: Security Advisory for eg (EXAMPLE-2025-cb7b)"
#define VT

Functions

 Describe (vtparser)
 BeforeEach (vtparser)
 AfterEach (vtparser)
static FILE * memopen (const gchar *str)
 Ensure (vtparser, parse_vt_json_parses_a_vt)
int main (int argc, char **argv)

Macro Definition Documentation

◆ VT

#define VT

Definition at line 17 of file vtparser_tests.c.

17#define VT \
18 "{" \
19 " \"oid\": \"1.3.6.1.4.1.25623.1.0.877440\"," \
20 " \"name\": \"" VT_NAME "\"," \
21 " \"filename\": \"2020/fedora/gb_fedora_2020_cb7b7181a0_sox_fc30.nasl\"," \
22 " \"tag\": {" \
23 " \"affected\": \"'sox' package(s) on Fedora 30.\"," \
24 " \"creation_date\": 1581134661," \
25 " \"cvss_base_vector\": \"AV:N/AC:L/Au:N/C:N/I:N/A:P\"," \
26 " \"insight\": \"SoX (Sound eXchange) is a sound file format...\"," \
27 " \"last_modification\": 1626919250," \
28 " \"qod_type\": \"package\"," \
29 " \"severity_date\": 1624547760," \
30 " \"severity_origin\": \"NVD\"," \
31 " \"severity_vector\": \"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H\"," \
32 " \"solution\": \"Please install the updated package(s).\"," \
33 " \"solution_type\": \"VendorFix\"," \
34 " \"summary\": \"The remote host is missing an update for ...\"" \
35 " }," \
36 " \"dependencies\": [" \
37 " \"gather-package-list.nasl\"" \
38 " ]," \
39 " \"required_keys\": []," \
40 " \"mandatory_keys\": [" \
41 " \"ssh/login/fedora\"," \
42 " \"ssh/login/rpms\"," \
43 " \"ssh/login/release=FC30\"" \
44 " ]," \
45 " \"excluded_keys\": []," \
46 " \"required_ports\": []," \
47 " \"required_udp_ports\": []," \
48 " \"references\": [" \
49 " {" \
50 " \"class\": \"cve\"," \
51 " \"id\": \"CVE-2017-18189\"" \
52 " }," \
53 " {" \
54 " \"class\": \"2020-cb7b7181a0\"," \
55 " \"id\": \"FEDORA\"" \
56 " }," \
57 " {" \
58 " \"class\": \"https://example.org/ann/EG-IZ3CX\"," \
59 " \"id\": \"URL\"" \
60 " }" \
61 " ]," \
62 " \"preferences\": []," \
63 " \"category\": \"gather_info\"," \
64 " \"family\": \"Fedora Local Security Checks\"" \
65 " }"

Referenced by Ensure().

◆ VT_NAME

#define VT_NAME   "Example: Security Advisory for eg (EXAMPLE-2025-cb7b)"

Definition at line 15 of file vtparser_tests.c.

Referenced by Ensure().

Function Documentation

◆ AfterEach()

AfterEach ( vtparser )

Definition at line 72 of file vtparser_tests.c.

73{
74}

◆ BeforeEach()

BeforeEach ( vtparser )

Definition at line 68 of file vtparser_tests.c.

69{
70}

◆ Describe()

Describe ( vtparser )

◆ Ensure()

Ensure ( vtparser ,
parse_vt_json_parses_a_vt  )

Definition at line 84 of file vtparser_tests.c.

85{
88 FILE *file;
89 nvti_t *nvt;
90 gchar *refs;
91
92 file = memopen ("[" VT "]");
93 assert_that (file, is_not_null);
94
96
97 gvm_json_pull_parser_init (&parser, file);
98
99 gvm_json_pull_parser_next (&parser, &event);
100
101 parse_vt_json (&parser, &event, &nvt);
102 assert_that (nvt, is_not_null);
103 assert_that (nvti_name (nvt), is_equal_to_string (VT_NAME));
104 refs = nvti_refs (nvt, NULL, NULL, 1);
105 assert_that (refs,
106 is_equal_to_string ("cve:CVE-2017-18189,"
107 " 2020-cb7b7181a0:FEDORA,"
108 " https://example.org/ann/EG-IZ3CX:URL"));
109 g_free (refs);
110 nvti_free (nvt);
111
114 fclose (file);
115}
void gvm_json_pull_parser_cleanup(gvm_json_pull_parser_t *parser)
Frees the data of a JSON pull parser.
Definition jsonpull.c:120
void gvm_json_pull_event_cleanup(gvm_json_pull_event_t *event)
Frees all data of JSON pull event data structure.
Definition jsonpull.c:61
void gvm_json_pull_parser_next(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event)
Get the next event from a JSON pull parser.
Definition jsonpull.c:669
void gvm_json_pull_parser_init(gvm_json_pull_parser_t *parser, FILE *input_stream)
Initializes a JSON pull parser with default buffer sizes.
Definition jsonpull.c:109
void gvm_json_pull_event_init(gvm_json_pull_event_t *event)
Initializes a JSON pull event data structure.
Definition jsonpull.c:50
gchar * nvti_refs(const nvti_t *n, const gchar *type, const gchar *exclude_types, guint use_types)
Get references as string.
Definition nvti.c:766
struct nvti nvti_t
The structure of a information record that corresponds to a NVT.
gchar * nvti_name(const nvti_t *n)
Get the name.
Definition nvti.c:625
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
Definition nvti.c:570
Event generated by the JSON pull parser.
Definition jsonpull.h:59
A json pull parser.
Definition jsonpull.h:86
int parse_vt_json(gvm_json_pull_parser_t *parser, gvm_json_pull_event_t *event, nvti_t **nvt)
Parse a VT element given in json format.
Definition vtparser.c:239
#define VT
static FILE * memopen(const gchar *str)
#define VT_NAME

References gvm_json_pull_event_cleanup(), gvm_json_pull_event_init(), gvm_json_pull_parser_cleanup(), gvm_json_pull_parser_init(), gvm_json_pull_parser_next(), memopen(), nvti_free(), nvti_name(), nvti_refs(), parse_vt_json(), VT, and VT_NAME.

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 120 of file vtparser_tests.c.

121{
122 int ret;
123 TestSuite *suite;
124
125 suite = create_test_suite ();
126
127 add_test_with_context (suite, vtparser, parse_vt_json_parses_a_vt);
128
129 if (argc > 1)
130 ret = run_single_test (suite, argv[1], create_text_reporter ());
131 else
132 ret = run_test_suite (suite, create_text_reporter ());
133
134 destroy_test_suite (suite);
135
136 return ret;
137}

◆ memopen()

FILE * memopen ( const gchar * str)
static

Definition at line 77 of file vtparser_tests.c.

78{
79 return fmemopen ((void *) str, strlen (str), "r");
80}

Referenced by Ensure().

Here is the caller graph for this function: