Greenbone Vulnerability Management Libraries 22.32.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
13{
14}
16{
17}
18
19Ensure (osp, osp_new_target_never_returns_null)
20{
21 osp_target_t *target;
22
23 target = osp_target_new (NULL, NULL, NULL, 0, 0, 0);
24 assert_that (target, is_not_null);
25 osp_target_free (target);
26}
27
28Ensure (osp, osp_new_conn_ret_null)
29{
30 assert_that (osp_connection_new ("/my/socket", 0, NULL, NULL, NULL), is_null);
31}
32
33Ensure (osp, osp_get_vts_no_vts_ret_error)
34{
35 osp_connection_t *conn = g_malloc0 (sizeof (*conn));
36 assert_that (osp_get_vts (conn, NULL), is_equal_to (1));
37 g_free (conn);
38}
39
40Ensure (osp, osp_get_vts_no_conn_ret_error)
41{
42 assert_that (osp_get_vts (NULL, NULL), is_equal_to (1));
43}
44
46{
47 osp_target_t *target;
48
49 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
50 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, TRUE);
51
52 assert_true (target->icmp);
53 assert_true (target->tcp_syn);
54 assert_true (target->tcp_ack);
55 assert_true (target->arp);
56 assert_true (target->consider_alive);
57
58 osp_target_free (target);
59}
60
62{
63 osp_target_t *target;
64 GString *target_xml;
65 gchar *expected_xml_string;
66
67 target = osp_target_new ("127.0.0.1", "123", NULL, 0, 0, 0);
68 osp_target_add_alive_test_methods (target, TRUE, TRUE, TRUE, TRUE, FALSE);
69
70 target_xml = g_string_sized_new (10240);
71
72 target_append_as_xml (target, target_xml);
73 expected_xml_string = "<target>"
74 "<hosts>127.0.0.1</hosts>"
75 "<exclude_hosts></exclude_hosts>"
76 "<finished_hosts></finished_hosts>"
77 "<ports>123</ports>"
78 "<alive_test_methods>"
79 "<icmp>1</icmp>"
80 "<tcp_syn>1</tcp_syn>"
81 "<tcp_ack>1</tcp_ack>"
82 "<arp>1</arp>"
83 "<consider_alive>0</consider_alive>"
84 "</alive_test_methods>"
85 "</target>";
86
87 assert_that (target_xml->str, is_equal_to_string (expected_xml_string));
88
89 osp_target_free (target);
90 g_string_free (target_xml, TRUE);
91}
92
93/* Test suite. */
94
95int
96main (int argc, char **argv)
97{
98 int ret;
99 TestSuite *suite;
100
101 suite = create_test_suite ();
102
103 add_test_with_context (suite, osp, osp_new_target_never_returns_null);
104 add_test_with_context (suite, osp, osp_get_vts_no_conn_ret_error);
105 add_test_with_context (suite, osp, osp_get_vts_no_vts_ret_error);
106 add_test_with_context (suite, osp, osp_new_conn_ret_null);
107 add_test_with_context (suite, osp, osp_target_add_alive_test_methods);
108 add_test_with_context (suite, osp, target_append_as_xml);
109
110 if (argc > 1)
111 ret = run_single_test (suite, argv[1], create_text_reporter ());
112 else
113 ret = run_test_suite (suite, create_text_reporter ());
114
115 destroy_test_suite (suite);
116
117 return ret;
118}
API for Open Scanner Protocol communication.
void osp_target_add_alive_test_methods(osp_target_t *target, gboolean icmp, gboolean tcp_syn, gboolean tcp_ack, gboolean arp, gboolean consider_alive)
Add alive test methods to OSP target.
Definition osp.c:1753
int osp_get_vts(osp_connection_t *connection, entity_t *vts)
Get all VTs from an OSP server.
Definition osp.c:618
void osp_target_free(osp_target_t *target)
Free an OSP target, including all added credentials.
Definition osp.c:1730
static void target_append_as_xml(osp_target_t *target, GString *xml_string)
Concatenate a target as XML.
Definition osp.c:1141
osp_target_t * osp_target_new(const char *hosts, const char *ports, const char *exclude_hosts, int alive_test, int reverse_lookup_unify, int reverse_lookup_only)
Create a new OSP target.
Definition osp.c:1691
struct osp_connection osp_connection_t
Definition osp.h:20
struct osp_target osp_target_t
Definition osp.h:24
osp_connection_t * osp_connection_new(const char *, int, const char *, const char *, const char *)
int main(int argc, char **argv)
Definition osp_tests.c:96
AfterEach(osp)
Definition osp_tests.c:15
Describe(osp)
BeforeEach(osp)
Definition osp_tests.c:12
Ensure(osp, osp_new_target_never_returns_null)
Definition osp_tests.c:19
gboolean tcp_syn
Definition osp.c:81
gboolean arp
Definition osp.c:83
gboolean icmp
Definition osp.c:80
gboolean consider_alive
Definition osp.c:84
gboolean tcp_ack
Definition osp.c:82