Greenbone Vulnerability Management Libraries  22.8.0
osp_tests.c
Go to the documentation of this file.
1 /* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  */
5 
6 #include "osp.c"
7 
8 #include <cgreen/cgreen.h>
9 #include <cgreen/mocks.h>
10 
11 Describe (osp);
13 {
14 }
15 AfterEach (osp)
16 {
17 }
18 
19 Ensure (osp, osp_new_target_never_returns_null)
20 {
21  assert_that (osp_target_new (NULL, NULL, NULL, 0, 0, 0), is_not_null);
22 }
23 
24 Ensure (osp, osp_new_conn_ret_null)
25 {
26  assert_that (osp_connection_new ("/my/socket", 0, NULL, NULL, NULL), is_null);
27 }
28 
29 Ensure (osp, osp_get_vts_no_vts_ret_error)
30 {
31  osp_connection_t *conn = g_malloc0 (sizeof (*conn));
32  assert_that (osp_get_vts (conn, NULL), is_equal_to (1));
33 }
34 
35 Ensure (osp, osp_get_vts_no_conn_ret_error)
36 {
37  assert_that (osp_get_vts (NULL, NULL), is_equal_to (1));
38 }
39 
41 {
42  osp_target_t *target;
43 
44  target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
45  osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, TRUE);
46 
47  assert_true (target->icmp);
48  assert_true (target->tcp_syn);
49  assert_true (target->tcp_ack);
50  assert_true (target->arp);
51  assert_true (target->consider_alive);
52 
53  osp_target_free (target);
54 }
55 
57 {
58  osp_target_t *target;
59  GString *target_xml;
60  gchar *expected_xml_string;
61 
62  target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
63  osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, FALSE);
64 
65  target_xml = g_string_sized_new (10240);
66 
67  target_append_as_xml (target, target_xml);
68  expected_xml_string = "<target>"
69  "<hosts>127.0.0.1</hosts>"
70  "<exclude_hosts></exclude_hosts>"
71  "<finished_hosts></finished_hosts>"
72  "<ports>123</ports>"
73  "<alive_test_methods>"
74  "<icmp>1</icmp>"
75  "<tcp_syn>1</tcp_syn>"
76  "<tcp_ack>1</tcp_ack>"
77  "<arp>1</arp>"
78  "<consider_alive>0</consider_alive>"
79  "</alive_test_methods>"
80  "</target>";
81 
82  assert_that (target_xml->str, is_equal_to_string (expected_xml_string));
83 
84  osp_target_free (target);
85 }
86 
87 /* Test suite. */
88 
89 int
90 main (int argc, char **argv)
91 {
92  TestSuite *suite;
93 
94  suite = create_test_suite ();
95 
96  add_test_with_context (suite, osp, osp_new_target_never_returns_null);
97  add_test_with_context (suite, osp, osp_get_vts_no_conn_ret_error);
98  add_test_with_context (suite, osp, osp_get_vts_no_vts_ret_error);
99  add_test_with_context (suite, osp, osp_new_conn_ret_null);
100  add_test_with_context (suite, osp, osp_target_add_alive_test_methods);
101  add_test_with_context (suite, osp, target_append_as_xml);
102 
103  if (argc > 1)
104  return run_single_test (suite, argv[1], create_text_reporter ());
105 
106  return run_test_suite (suite, create_text_reporter ());
107 }
main
int main(int argc, char **argv)
Definition: osp_tests.c:90
osp_target::tcp_syn
gboolean tcp_syn
Definition: osp.c:81
osp_connection_new
osp_connection_t * osp_connection_new(const char *, int, const char *, const char *, const char *)
Describe
Describe(osp)
osp.c
API for Open Scanner Protocol communication.
osp_target::consider_alive
gboolean consider_alive
Definition: osp.c:84
osp_target::tcp_ack
gboolean tcp_ack
Definition: osp.c:82
osp_target_free
void osp_target_free(osp_target_t *)
osp_get_vts
int osp_get_vts(osp_connection_t *connection, entity_t *vts)
Get all VTs from an OSP server.
Definition: osp.c:621
target_append_as_xml
static void target_append_as_xml(osp_target_t *target, GString *xml_string)
Concatenate a target as XML.
Definition: osp.c:1144
osp_target::icmp
gboolean icmp
Definition: osp.c:80
osp_target_new
osp_target_t * osp_target_new(const char *, const char *, const char *, int, int, int)
osp_target
Struct holding target information.
Definition: osp.c:71
Ensure
Ensure(osp, osp_new_target_never_returns_null)
Definition: osp_tests.c:19
osp_target::arp
gboolean arp
Definition: osp.c:83
AfterEach
AfterEach(osp)
Definition: osp_tests.c:15
BeforeEach
BeforeEach(osp)
Definition: osp_tests.c:12
osp_connection
Struct holding options for OSP connection.
Definition: osp.c:36
osp_target_add_alive_test_methods
void osp_target_add_alive_test_methods(osp_target_t *, gboolean, gboolean, gboolean, gboolean, gboolean)