OpenVAS Scanner  7.0.1~git
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)
 
int __wrap_redis_push_str (kb_t kb, const char *name, const char *value)
 
 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_push_str()

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

Definition at line 39 of file attack_tests.c.

40 {
41  (void) kb; /* Used. */
42  given_name = g_strdup (name);
43  given_value = g_strdup (value);
44  mock ();
45  return 0;
46 }

References given_name, given_value, and name.

Referenced by Ensure().

Here is the caller graph for this function:

◆ AfterEach()

AfterEach ( attack  )

Definition at line 29 of file attack_tests.c.

30 {
31 }

◆ BeforeEach()

BeforeEach ( attack  )

Definition at line 26 of file attack_tests.c.

27 {
28 }

◆ Describe()

Describe ( attack  )

◆ Ensure() [1/3]

Ensure ( attack  ,
comm_send_status_error_if_hostname_too_big   
)

Definition at line 61 of file attack_tests.c.

62 {
63  struct kb kb_struct;
64  kb_t kb;
65  gchar *long_host;
66  int index;
67 
68  /* Create a dummy kb. */
69  kb = &kb_struct;
70 
71  long_host = g_malloc (2049);
72  for (index = 0; index < 2049; index++)
73  long_host[index] = 'a';
74  long_host[2048] = '\0';
75 
76  never_expect (__wrap_redis_push_str);
77  assert_that (comm_send_status (kb, long_host, 0, 100), is_equal_to (-1));
78 
79  g_free (long_host);
80 }

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 48 of file attack_tests.c.

49 {
50  struct kb kb_struct;
51  kb_t kb;
52 
53  /* Create a dummy kb. */
54  kb = &kb_struct;
55 
56  never_expect (__wrap_redis_push_str);
57  assert_that (comm_send_status (NULL, "example", 0, 100), is_equal_to (-1));
58  assert_that (comm_send_status (kb, NULL, 0, 100), is_equal_to (-1));
59 }

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 82 of file attack_tests.c.

83 {
84  struct kb kb_struct;
85  struct kb_operations kb_ops_struct;
86  kb_t kb;
87 
88  /* Create a dummy kb. */
89  kb = &kb_struct;
90 
91  /* We can't wrap kb_item_push_str because it is inline, so we have to do
92  * a little hacking. */
93  kb_ops_struct.kb_push_str = __wrap_redis_push_str;
94  kb->kb_ops = &kb_ops_struct;
95 
96  expect (__wrap_redis_push_str);
97  assert_that (comm_send_status (kb, "127.0.0.1", 11, 67), is_equal_to (0));
98  assert_that (strcmp (given_name, "internal/status"), is_equal_to (0));
99  assert_that (strcmp (given_value, "11/67"), is_equal_to (0));
100 
101  g_free (given_name);
102  g_free (given_value);
103 }

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

Here is the call graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 106 of file attack_tests.c.

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

Variable Documentation

◆ given_name

gchar* given_name = NULL

Definition at line 35 of file attack_tests.c.

Referenced by __wrap_redis_push_str(), and Ensure().

◆ given_value

gchar* given_value = NULL

Definition at line 36 of file attack_tests.c.

Referenced by __wrap_redis_push_str(), and Ensure().

comm_send_status
static int comm_send_status(kb_t kb, char *hostname, int curr, int max)
Sends the status of a host's scan.
Definition: attack.c:156
name
const char * name
Definition: nasl_init.c:377
given_name
gchar * given_name
Definition: attack_tests.c:35
given_value
gchar * given_value
Definition: attack_tests.c:36
__wrap_redis_push_str
int __wrap_redis_push_str(kb_t kb, const char *name, const char *value)
Definition: attack_tests.c:39