OpenVAS Scanner 23.40.3
attack_tests.c File Reference
#include "attack.c"
#include <cgreen/cgreen.h>
#include <cgreen/mocks.h>
Include dependency graph for attack_tests.c:

Go to the source code of this file.

Functions

 Describe (attack)
 BeforeEach (attack)
 AfterEach (attack)
static int __wrap_redis_push_str (kb_t kb, const char *name, const char *value)
static int __wrap_redis_lnk_reset (kb_t kb)
 Ensure (attack, comm_send_status_returns_neg1_for_null_args)
 Ensure (attack, comm_send_status_error_if_hostname_too_big)
 Ensure (attack, comm_send_status_sends_correct_text)
int main (int argc, char **argv)

Variables

gchar * given_name = NULL
gchar * given_value = NULL

Function Documentation

◆ __wrap_redis_lnk_reset()

int __wrap_redis_lnk_reset ( kb_t kb)
static

Definition at line 35 of file attack_tests.c.

36{
37 (void) kb; /* Used. */
38 mock ();
39 return 0;
40}

Referenced by Ensure().

Here is the caller graph for this function:

◆ __wrap_redis_push_str()

int __wrap_redis_push_str ( kb_t kb,
const char * name,
const char * value )
static

Definition at line 25 of file attack_tests.c.

26{
27 (void) kb; /* Used. */
28 given_name = g_strdup (name);
29 given_value = g_strdup (value);
30 mock ();
31 return 0;
32}
gchar * given_value
gchar * given_name
const char * name
Definition nasl_init.c:440

References given_name, given_value, and name.

Referenced by Ensure(), Ensure(), and Ensure().

Here is the caller graph for this function:

◆ AfterEach()

AfterEach ( attack )

Definition at line 15 of file attack_tests.c.

16{
17}

◆ BeforeEach()

BeforeEach ( attack )

Definition at line 12 of file attack_tests.c.

13{
14}

◆ Describe()

Describe ( attack )

◆ Ensure() [1/3]

Ensure ( attack ,
comm_send_status_error_if_hostname_too_big  )

Definition at line 55 of file attack_tests.c.

56{
57 struct kb kb_struct;
58 kb_t kb;
59 gchar *long_host;
60 int index;
61
62 /* Create a dummy kb. */
63 kb = &kb_struct;
64
65 long_host = g_malloc (2049);
66 for (index = 0; index < 2049; index++)
67 long_host[index] = 'a';
68 long_host[2048] = '\0';
69
70 never_expect (__wrap_redis_push_str);
71 assert_that (comm_send_status (kb, long_host, 0, 100), is_equal_to (-1));
72
73 g_free (long_host);
74}
static int comm_send_status(kb_t main_kb, char *ip_str, int curr, int max)
Sends the progress status of of a host's scan.
Definition attack.c:205
static int __wrap_redis_push_str(kb_t kb, const char *name, const char *value)

References __wrap_redis_push_str(), and comm_send_status().

Here is the call graph for this function:

◆ Ensure() [2/3]

Ensure ( attack ,
comm_send_status_returns_neg1_for_null_args  )

Definition at line 42 of file attack_tests.c.

43{
44 struct kb kb_struct;
45 kb_t kb;
46
47 /* Create a dummy kb. */
48 kb = &kb_struct;
49
50 never_expect (__wrap_redis_push_str);
51 assert_that (comm_send_status (NULL, "example", 0, 100), is_equal_to (-1));
52 assert_that (comm_send_status (kb, NULL, 0, 100), is_equal_to (-1));
53}

References __wrap_redis_push_str(), and comm_send_status().

Here is the call graph for this function:

◆ Ensure() [3/3]

Ensure ( attack ,
comm_send_status_sends_correct_text  )

Definition at line 76 of file attack_tests.c.

77{
78 struct kb kb_struct;
79 struct kb_operations kb_ops_struct;
80 kb_t kb;
81
82 /* Create a dummy kb. */
83 kb = &kb_struct;
84
85 /* We can't wrap kb_item_push_str because it is inline, so we have to do
86 * a little hacking. */
87 kb_ops_struct.kb_push_str = __wrap_redis_push_str;
88 kb_ops_struct.kb_lnk_reset = __wrap_redis_lnk_reset;
89 kb->kb_ops = &kb_ops_struct;
90
91 set_main_kb (kb);
92 expect (__wrap_redis_push_str);
94 assert_that (comm_send_status (kb, "127.0.0.1", 11, 67), is_equal_to (0));
95 assert_that (strcmp (given_name, "internal/status"), is_equal_to (0));
96 assert_that (strcmp (given_value, "127.0.0.1/11/67"), is_equal_to (0));
97
98 g_free (given_name);
99 g_free (given_value);
100}
static int __wrap_redis_lnk_reset(kb_t kb)
void set_main_kb(kb_t kb)
sets the shared database between ospd and openvas as a main_kb for further usage. @description this s...
Definition kb_cache.c:27

References __wrap_redis_lnk_reset(), __wrap_redis_push_str(), comm_send_status(), given_name, given_value, and set_main_kb().

Here is the call graph for this function:

◆ main()

int main ( int argc,
char ** argv )

Definition at line 103 of file attack_tests.c.

104{
105 int ret;
106 TestSuite *suite;
107
108 suite = create_test_suite ();
109
110 add_test_with_context (suite, attack,
111 comm_send_status_returns_neg1_for_null_args);
112 add_test_with_context (suite, attack,
113 comm_send_status_error_if_hostname_too_big);
114 add_test_with_context (suite, attack, comm_send_status_sends_correct_text);
115
116 if (argc > 1)
117 ret = run_single_test (suite, argv[1], create_text_reporter ());
118 else
119 ret = run_test_suite (suite, create_text_reporter ());
120
121 destroy_test_suite (suite);
122
123 return ret;
124}

Variable Documentation

◆ given_name

gchar* given_name = NULL

Definition at line 21 of file attack_tests.c.

Referenced by __wrap_redis_push_str(), and Ensure().

◆ given_value

gchar* given_value = NULL

Definition at line 22 of file attack_tests.c.

Referenced by __wrap_redis_push_str(), and Ensure().