OpenVAS Scanner  22.7.9
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()

static 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()

static 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 }

References given_name, given_value, and name.

Referenced by 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 }

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);
93  expect (__wrap_redis_lnk_reset);
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 }

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  TestSuite *suite;
106 
107  suite = create_test_suite ();
108 
109  add_test_with_context (suite, attack,
110  comm_send_status_returns_neg1_for_null_args);
111  add_test_with_context (suite, attack,
112  comm_send_status_error_if_hostname_too_big);
113  add_test_with_context (suite, attack, comm_send_status_sends_correct_text);
114 
115  if (argc > 1)
116  return run_single_test (suite, argv[1], create_text_reporter ());
117 
118  return run_test_suite (suite, create_text_reporter ());
119 }

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().

comm_send_status
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:204
name
const char * name
Definition: nasl_init.c:411
given_name
gchar * given_name
Definition: attack_tests.c:21
given_value
gchar * given_value
Definition: attack_tests.c:22
set_main_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
__wrap_redis_lnk_reset
static int __wrap_redis_lnk_reset(kb_t kb)
Definition: attack_tests.c:35
__wrap_redis_push_str
static int __wrap_redis_push_str(kb_t kb, const char *name, const char *value)
Definition: attack_tests.c:25