OpenVAS Scanner 22.7.9
ipc_openvas_tests.c File Reference
#include "ipc_openvas.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Include dependency graph for ipc_openvas_tests.c:

Go to the source code of this file.

Functions

 Describe (ipc_openvas)
 
 BeforeEach (ipc_openvas)
 
 AfterEach (ipc_openvas)
 
 Ensure (ipc_openvas, ipc_data_from_json_ua_ok)
 
 Ensure (ipc_openvas, ipc_data_from_json_hostname_ok)
 
 Ensure (ipc_openvas, ipc_data_from_json_parse_error)
 
 Ensure (ipc_openvas, ipc_data_from_json_parse_many_objects)
 
int main (int argc, char **argv)
 

Function Documentation

◆ AfterEach()

AfterEach ( ipc_openvas  )

Definition at line 15 of file ipc_openvas_tests.c.

16{
17}

◆ BeforeEach()

BeforeEach ( ipc_openvas  )

Definition at line 12 of file ipc_openvas_tests.c.

13{
14}

◆ Describe()

Describe ( ipc_openvas  )

◆ Ensure() [1/4]

Ensure ( ipc_openvas  ,
ipc_data_from_json_hostname_ok   
)

Definition at line 43 of file ipc_openvas_tests.c.

44{
45 ipc_data_t *data_s = NULL;
46 ipc_data_t *data_r = NULL;
47 gchar *hn = "localhost";
48 gchar *hns = "TLS certificate";
49
50 // Preapre data to be sent
51 data_s = g_malloc0 (sizeof (ipc_data_t *));
52 data_s = ipc_data_type_from_hostname (hns, strlen (hns), hn, strlen (hn));
53
54 const char *json = ipc_data_to_json (data_s);
55 ipc_data_destroy (&data_s);
56 assert_that (data_s, is_null);
57
58 // Read received data
59 data_r = g_malloc0 (sizeof (ipc_data_t));
60 data_r = ipc_data_from_json (json, strlen (json));
61 assert_that (ipc_get_hostname_from_data (data_r),
62 is_equal_to_string ("localhost"));
63 assert_that (ipc_get_hostname_source_from_data (data_r),
64 is_equal_to_string ("TLS certificate"));
65
66 ipc_data_destroy (&data_r);
67 assert_that (data_r, is_null);
68}
struct ipc_data * ipc_data_type_from_hostname(const char *source, size_t source_len, const char *hostname, size_t hostname_len)
initializes ipc_data for a hostname data.
Definition: ipc_openvas.c:124
gchar * ipc_get_hostname_from_data(ipc_data_t *data)
Get the hostname from IPC data.
Definition: ipc_openvas.c:73
void ipc_data_destroy(ipc_data_t **data)
destroys ipc_data.
Definition: ipc_openvas.c:224
struct ipc_data * ipc_data_from_json(const char *json, size_t len)
transforms json string to a ipc_data struct
Definition: ipc_openvas.c:319
gchar * ipc_get_hostname_source_from_data(ipc_data_t *data)
Get the vhost hostname source from IPC data.
Definition: ipc_openvas.c:89
const char * ipc_data_to_json(struct ipc_data *data)
transforms ipc_data to a json string
Definition: ipc_openvas.c:251

References ipc_data_destroy(), ipc_data_from_json(), ipc_data_to_json(), ipc_data_type_from_hostname(), ipc_get_hostname_from_data(), and ipc_get_hostname_source_from_data().

Here is the call graph for this function:

◆ Ensure() [2/4]

Ensure ( ipc_openvas  ,
ipc_data_from_json_parse_error   
)

Definition at line 70 of file ipc_openvas_tests.c.

71{
72 ipc_data_t *data_r = NULL;
73 char *json_fake = NULL;
74
75 // malformed json string
76 json_fake = g_strdup (
77 "{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] (X11, U; Greenbone OS "
78 "22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] (X11, U; "
79 "Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] "
80 "(X11, U; Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 "
81 "[en] (X11, U; Greenbone OS "
82 "22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] (X11, U; "
83 "Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] "
84 "(X11, U; Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 "
85 "[en] (X11, U; Greenbone OS "
86 "22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] (X11, U; "
87 "Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] "
88 "(X11, U; Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 "
89 "[en] (X11, U; Greenbone OS "
90 "22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] (X11, U; "
91 "Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 [en] "
92 "(X11, U; Greenbone OS 22.04.4)\"}{\"type\":1,\"user-agent\":\"Mozilla/5.0 "
93 "[en] (X11, U; Greenbone OS 22.04.4)\"}{\"type\":");
94
95 // Read received data
96 data_r = g_malloc0 (sizeof (ipc_data_t *));
97 data_r = ipc_data_from_json (json_fake, strlen (json_fake));
98 assert_that (ipc_get_hostname_from_data (data_r), is_null);
99 assert_that (ipc_get_hostname_source_from_data (data_r), is_null);
100 assert_that (data_r, is_null);
101}

References ipc_data_from_json(), ipc_get_hostname_from_data(), and ipc_get_hostname_source_from_data().

Here is the call graph for this function:

◆ Ensure() [3/4]

Ensure ( ipc_openvas  ,
ipc_data_from_json_parse_many_objects   
)

Definition at line 103 of file ipc_openvas_tests.c.

104{
105 ipc_data_t *data_r = NULL;
106 char *json_fake = NULL;
107
108 // malformed json string
109 json_fake =
110 g_strdup ("{\"type\":0,\"source\":\"TLS "
111 "certificate\",\"hostname\":\"localhost\"}{\"type\":1,\"user-"
112 "agent\":\"Mozilla/5.0 [en] (X11, U; Greenbone OS "
113 "22.04.4)\"}");
114
115 // Read received data
116 data_r = g_malloc0 (sizeof (ipc_data_t *));
117 data_r = ipc_data_from_json (json_fake, strlen (json_fake));
118
119 assert_that (ipc_get_hostname_from_data (data_r),
120 is_equal_to_string ("localhost"));
121 assert_that (ipc_get_hostname_source_from_data (data_r),
122 is_equal_to_string ("TLS certificate"));
123
124 ipc_data_destroy (&data_r);
125 assert_that (data_r, is_null);
126}

References ipc_data_destroy(), ipc_data_from_json(), ipc_get_hostname_from_data(), and ipc_get_hostname_source_from_data().

Here is the call graph for this function:

◆ Ensure() [4/4]

Ensure ( ipc_openvas  ,
ipc_data_from_json_ua_ok   
)

Definition at line 19 of file ipc_openvas_tests.c.

20{
21 ipc_data_t *data_s = NULL;
22 ipc_data_t *data_r = NULL;
23 gchar *ua = "localhost";
24
25 // Preapre data to be sent
26 data_s = g_malloc0 (sizeof (ipc_data_t *));
27 data_s = ipc_data_type_from_user_agent (ua, strlen (ua));
28
29 const char *json = ipc_data_to_json (data_s);
30 ipc_data_destroy (&data_s);
31 assert_that (data_s, is_null);
32
33 // Read received data
34 data_r = g_malloc0 (sizeof (ipc_data_t));
35 data_r = ipc_data_from_json (json, strlen (json));
36 assert_that (ipc_get_user_agent_from_data (data_r),
37 is_equal_to_string ("localhost"));
38
39 ipc_data_destroy (&data_r);
40 assert_that (data_s, is_null);
41}
struct ipc_data * ipc_data_type_from_user_agent(const char *user_agent, size_t user_agent_len)
initializes ipc_data for the User-Agent.
Definition: ipc_openvas.c:173
gchar * ipc_get_user_agent_from_data(ipc_data_t *data)
Get the User-Agent from IPC data.
Definition: ipc_openvas.c:105

References ipc_data_destroy(), ipc_data_from_json(), ipc_data_to_json(), ipc_data_type_from_user_agent(), and ipc_get_user_agent_from_data().

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 129 of file ipc_openvas_tests.c.

130{
131 TestSuite *suite;
132
133 suite = create_test_suite ();
134
135 add_test_with_context (suite, ipc_openvas, ipc_data_from_json_ua_ok);
136 add_test_with_context (suite, ipc_openvas, ipc_data_from_json_hostname_ok);
137 add_test_with_context (suite, ipc_openvas, ipc_data_from_json_parse_error);
138 add_test_with_context (suite, ipc_openvas,
139 ipc_data_from_json_parse_many_objects);
140
141 if (argc > 1)
142 return run_single_test (suite, argv[1], create_text_reporter ());
143
144 return run_test_suite (suite, create_text_reporter ());
145}