OpenVPN
Macros | Functions | Variables
test_push_update_msg.c File Reference
#include <stdlib.h>
#include <stdarg.h>
#include <setjmp.h>
#include <cmocka.h>
#include "push.h"
#include "options_util.h"
#include "multi.h"
#include "push_util.c"
Include dependency graph for test_push_update_msg.c:

Go to the source code of this file.

Macros

#define PUSH_BUNDLE_SIZE_TEST   184
 
#define expect_control_channel_strings(res)
 

Functions

static void reset_route_counters (void)
 
bool apply_push_options (struct context *c, struct options *options, struct buffer *buf, uint64_t permission_mask, uint64_t *option_types_found, struct env_set *es, bool is_update)
 
int process_incoming_push_msg (struct context *c, const struct buffer *buffer, bool honor_received_options, uint64_t permission_mask, uint64_t *option_types_found)
 
const char * tls_common_name (const struct tls_multi *multi, const bool null)
 Returns the common name field for the given tunnel.
 
bool send_control_channel_string (struct context *c, const char *str, msglvl_t msglevel)
 
struct multi_instancelookup_by_cid (struct multi_context *m, const unsigned long cid)
 
bool mroute_extract_openvpn_sockaddr (struct mroute_addr *addr, const struct openvpn_sockaddr *osaddr, bool use_port)
 
static void test_incoming_push_message_basic (void **state)
 
static void test_incoming_push_message_error1 (void **state)
 
static void test_incoming_push_message_error2 (void **state)
 
static void test_incoming_push_message_1 (void **state)
 
static void test_incoming_push_message_bad_format (void **state)
 
static void test_incoming_push_message_not_updatable_option (void **state)
 
static void test_incoming_push_message_mix (void **state)
 
static void test_incoming_push_message_mix2 (void **state)
 
static void test_incoming_push_continuation_route_accumulation (void **state)
 Test that routes accumulate correctly across multiple continuation messages.
 
static void test_send_push_msg0 (void **state)
 
static void test_send_push_msg1 (void **state)
 
static void test_send_push_msg2 (void **state)
 
static void test_send_push_msg3 (void **state)
 
static void test_send_push_msg4 (void **state)
 
static void test_send_push_msg5 (void **state)
 
static void test_send_push_msg6 (void **state)
 
static void test_send_push_msg7 (void **state)
 
static void test_send_push_msg8 (void **state)
 
static void test_send_push_msg9 (void **state)
 
static void test_send_push_msg10 (void **state)
 
static void test_send_push_msg11 (void **state)
 
static void test_send_push_msg12 (void **state)
 
static void test_send_push_msg13 (void **state)
 
static void test_send_push_msg14 (void **state)
 
static int setup2 (void **state)
 
static int teardown2 (void **state)
 
static int setup (void **state)
 
static int teardown (void **state)
 
int main (void)
 

Variables

static int route_reset_count = 0
 
static int route_add_count = 0
 
char * r0 []
 
char * r1 []
 
char * r3 []
 
char * r4 []
 
char * r5 []
 
char * r6 []
 
char * r7 []
 
char * r8 []
 
char * r9 []
 
char * r11 []
 
char * r12 []
 
char * r13 []
 
char * r14 []
 
const char * msg0 = "redirect-gateway local,route 192.168.1.0 255.255.255.0"
 
const char * msg1
 
const char * msg2 = ""
 
const char * msg3 = ",,"
 
const char * msg4
 
const char * msg5
 
const char * msg6
 
const char * msg7 = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"
 
const char * msg8
 
const char * msg9 = ","
 
const char * msg10
 
const char * msg11
 
const char * msg12 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,abc"
 
const char * msg13 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,"
 
const char * msg14 = "a,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,a"
 

Macro Definition Documentation

◆ expect_control_channel_strings

#define expect_control_channel_strings (   res)
Value:
do \
{ \
for (int j = 0; res[j] != NULL; j++) \
{ \
expect_string(send_control_channel_string, str, res[j]); \
} \
} while (0)
bool send_control_channel_string(struct context *c, const char *str, msglvl_t msglevel)

Definition at line 454 of file test_push_update_msg.c.

◆ PUSH_BUNDLE_SIZE_TEST

#define PUSH_BUNDLE_SIZE_TEST   184

Definition at line 452 of file test_push_update_msg.c.

Function Documentation

◆ apply_push_options()

bool apply_push_options ( struct context c,
struct options options,
struct buffer buf,
uint64_t  permission_mask,
uint64_t *  option_types_found,
struct env_set es,
bool  is_update 
)

◆ lookup_by_cid()

struct multi_instance * lookup_by_cid ( struct multi_context m,
const unsigned long  cid 
)

Definition at line 137 of file test_push_update_msg.c.

References multi_context::instances.

◆ main()

int main ( void  )

◆ mroute_extract_openvpn_sockaddr()

bool mroute_extract_openvpn_sockaddr ( struct mroute_addr addr,
const struct openvpn_sockaddr osaddr,
bool  use_port 
)

Definition at line 143 of file test_push_update_msg.c.

◆ process_incoming_push_msg()

int process_incoming_push_msg ( struct context c,
const struct buffer buffer,
bool  honor_received_options,
uint64_t  permission_mask,
uint64_t *  option_types_found 
)

◆ reset_route_counters()

static void reset_route_counters ( void  )
static

◆ send_control_channel_string()

bool send_control_channel_string ( struct context c,
const char *  str,
msglvl_t  msglevel 
)

Definition at line 130 of file test_push_update_msg.c.

References buffer::len.

◆ setup()

static int setup ( void **  state)
static

Definition at line 625 of file test_push_update_msg.c.

References context::options, options::pull, and options::route_nopull.

Referenced by main().

◆ setup2()

static int setup2 ( void **  state)
static

◆ teardown()

static int teardown ( void **  state)
static

Definition at line 635 of file test_push_update_msg.c.

Referenced by main().

◆ teardown2()

static int teardown2 ( void **  state)
static

Definition at line 613 of file test_push_update_msg.c.

References multi_context::instances.

Referenced by main().

◆ test_incoming_push_continuation_route_accumulation()

static void test_incoming_push_continuation_route_accumulation ( void **  state)
static

Test that routes accumulate correctly across multiple continuation messages.

This test exposes a bug where update_options_found is reset to 0 for each continuation message, causing routes to be reset on each message instead of accumulating.

Expected behavior: routes should only be reset ONCE (when the first route is received), then all subsequent routes should accumulate.

Current bug: routes are reset on the first route of EACH continuation message.

Definition at line 296 of file test_push_update_msg.c.

References alloc_buf(), buf_write(), free_buf(), buffer::len, process_incoming_push_msg(), pull_permission_mask(), PUSH_MSG_CONTINUATION, PUSH_MSG_UPDATE, reset_route_counters(), route_add_count, and route_reset_count.

Referenced by main().

◆ test_incoming_push_message_1()

static void test_incoming_push_message_1 ( void **  state)
static

◆ test_incoming_push_message_bad_format()

static void test_incoming_push_message_bad_format ( void **  state)
static

◆ test_incoming_push_message_basic()

static void test_incoming_push_message_basic ( void **  state)
static

◆ test_incoming_push_message_error1()

static void test_incoming_push_message_error1 ( void **  state)
static

◆ test_incoming_push_message_error2()

static void test_incoming_push_message_error2 ( void **  state)
static

◆ test_incoming_push_message_mix()

static void test_incoming_push_message_mix ( void **  state)
static

◆ test_incoming_push_message_mix2()

static void test_incoming_push_message_mix2 ( void **  state)
static

◆ test_incoming_push_message_not_updatable_option()

static void test_incoming_push_message_not_updatable_option ( void **  state)
static

◆ test_send_push_msg0()

static void test_send_push_msg0 ( void **  state)
static

◆ test_send_push_msg1()

static void test_send_push_msg1 ( void **  state)
static

◆ test_send_push_msg10()

static void test_send_push_msg10 ( void **  state)
static

Definition at line 553 of file test_push_update_msg.c.

References msg10, PUSH_BUNDLE_SIZE_TEST, send_push_update(), and UPT_BY_CID.

Referenced by main().

◆ test_send_push_msg11()

static void test_send_push_msg11 ( void **  state)
static

◆ test_send_push_msg12()

static void test_send_push_msg12 ( void **  state)
static

◆ test_send_push_msg13()

static void test_send_push_msg13 ( void **  state)
static

◆ test_send_push_msg14()

static void test_send_push_msg14 ( void **  state)
static

◆ test_send_push_msg2()

static void test_send_push_msg2 ( void **  state)
static

Definition at line 482 of file test_push_update_msg.c.

References msg2, PUSH_BUNDLE_SIZE_TEST, send_push_update(), and UPT_BY_CID.

Referenced by main().

◆ test_send_push_msg3()

static void test_send_push_msg3 ( void **  state)
static

◆ test_send_push_msg4()

static void test_send_push_msg4 ( void **  state)
static

◆ test_send_push_msg5()

static void test_send_push_msg5 ( void **  state)
static

◆ test_send_push_msg6()

static void test_send_push_msg6 ( void **  state)
static

◆ test_send_push_msg7()

static void test_send_push_msg7 ( void **  state)
static

◆ test_send_push_msg8()

static void test_send_push_msg8 ( void **  state)
static

◆ test_send_push_msg9()

static void test_send_push_msg9 ( void **  state)
static

◆ tls_common_name()

const char * tls_common_name ( const struct tls_multi multi,
const bool  null 
)

Returns the common name field for the given tunnel.

Parameters
multiThe tunnel to return the common name for
nullWhether null may be returned. If not, "UNDEF" will be returned.

Definition at line 116 of file test_push_update_msg.c.

References buffer::len.

Variable Documentation

◆ msg0

const char* msg0 = "redirect-gateway local,route 192.168.1.0 255.255.255.0"

Definition at line 415 of file test_push_update_msg.c.

Referenced by test_send_push_msg0().

◆ msg1

const char* msg1
Initial value:
= "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
" akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway local,route 192.168.1.0 255.255.255.0"

Definition at line 416 of file test_push_update_msg.c.

Referenced by test_send_push_msg1(), and ValidateOptions().

◆ msg10

const char* msg10
Initial value:
= "abandon ability able about above absent absorb abstract absurd abuse access accident account accuse achieve"
"acid acoustic acquire across act action actor actress actual adapt add addict address adjust"
"baby bachelor bacon badge bag balance balcony ball bamboo banana banner bar barely bargain barrel base basic"
"basket battle beach bean beauty because become beef before begin behave behind"
"cabbage cabin cable cactus cage cake call calm camera camp can canal cancel candy cannon canoe canvas canyon"
"capable capital captain car carbon card cargo carpet carry cart case"
"daisy damage damp dance danger daring dash daughter dawn day deal debate debris decade december decide decline"
"decorate decrease deer defense define defy degree delay deliver demand demise denial"

Definition at line 431 of file test_push_update_msg.c.

Referenced by test_send_push_msg10().

◆ msg11

const char* msg11
Initial value:
= "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
"a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
"a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
"a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,"
"a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a"

Definition at line 440 of file test_push_update_msg.c.

Referenced by test_send_push_msg11().

◆ msg12

const char* msg12 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,abc"

Definition at line 446 of file test_push_update_msg.c.

Referenced by test_send_push_msg12().

◆ msg13

const char* msg13 = "a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,"

Definition at line 448 of file test_push_update_msg.c.

Referenced by test_send_push_msg13().

◆ msg14

const char* msg14 = "a,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,a"

Definition at line 450 of file test_push_update_msg.c.

Referenced by test_send_push_msg14().

◆ msg2

const char* msg2 = ""

Definition at line 418 of file test_push_update_msg.c.

Referenced by test_send_push_msg2(), and ValidateOptions().

◆ msg3

const char* msg3 = ",,"

Definition at line 419 of file test_push_update_msg.c.

Referenced by test_send_push_msg3().

◆ msg4

const char* msg4
Initial value:
= "-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
" akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0,"

Definition at line 420 of file test_push_update_msg.c.

Referenced by test_send_push_msg4().

◆ msg5

const char* msg5
Initial value:
= ",-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,"
" akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local, route 192.168.1.0 255.255.255.0"

Definition at line 422 of file test_push_update_msg.c.

Referenced by test_send_push_msg5().

◆ msg6

const char* msg6
Initial value:
= "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"
" dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,, route 192.168.1.0 255.255.255.0,"

Definition at line 424 of file test_push_update_msg.c.

Referenced by test_send_push_msg6().

◆ msg7

const char* msg7 = ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"

Definition at line 426 of file test_push_update_msg.c.

Referenced by test_send_push_msg7().

◆ msg8

const char* msg8
Initial value:
= "-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf, akakakakakakakakakakakaf,"
" dhcp-option DNS 8.8.8.8,redirect-gateway\n local,route 192.168.1.0 255.255.255.0\n\n\n"

Definition at line 427 of file test_push_update_msg.c.

Referenced by test_send_push_msg8().

◆ msg9

const char* msg9 = ","

Definition at line 429 of file test_push_update_msg.c.

Referenced by test_send_push_msg9().

◆ r0

char* r0[]
Initial value:
= {
"PUSH_UPDATE,redirect-gateway local,route 192.168.1.0 255.255.255.0",
NULL
}

Definition at line 344 of file test_push_update_msg.c.

Referenced by test_send_push_msg0().

◆ r1

char* r1[]
Initial value:
= {
"PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
"PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway local,push-continuation 2",
"PUSH_UPDATE,route 192.168.1.0 255.255.255.0,push-continuation 1",
NULL
}

Definition at line 348 of file test_push_update_msg.c.

Referenced by add_block_local_item(), and test_send_push_msg1().

◆ r11

char* r11[]
Initial value:
= {
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 2",
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,push-continuation 1",
NULL
}

Definition at line 391 of file test_push_update_msg.c.

Referenced by test_send_push_msg11().

◆ r12

char* r12[]
Initial value:
= {
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,push-continuation 2",
"PUSH_UPDATE,abc,push-continuation 1",
NULL
}

Definition at line 399 of file test_push_update_msg.c.

Referenced by test_send_push_msg12().

◆ r13

char* r13[]
Initial value:
= {
"PUSH_UPDATE,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,,,,,,a,",
NULL
}

Definition at line 404 of file test_push_update_msg.c.

Referenced by test_send_push_msg13().

◆ r14

char* r14[]
Initial value:
= {
"PUSH_UPDATE,a,push-continuation 2",
"PUSH_UPDATE,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,push-continuation 2",
"PUSH_UPDATE,a,push-continuation 1",
NULL
}

Definition at line 408 of file test_push_update_msg.c.

Referenced by test_send_push_msg14().

◆ r3

char* r3[]
Initial value:
= {
"PUSH_UPDATE,,,",
NULL
}

Definition at line 354 of file test_push_update_msg.c.

Referenced by test_send_push_msg3().

◆ r4

char* r4[]
Initial value:
= {
"PUSH_UPDATE,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
"PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
"PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1",
NULL
}

Definition at line 358 of file test_push_update_msg.c.

Referenced by test_send_push_msg4().

◆ r5

char* r5[]
Initial value:
= {
"PUSH_UPDATE,,-dhcp-option, blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
"PUSH_UPDATE, akakakakakakakakakakakaf,dhcp-option DNS 8.8.8.8, redirect-gateway local,push-continuation 2",
"PUSH_UPDATE, route 192.168.1.0 255.255.255.0,push-continuation 1",
NULL
}

Definition at line 364 of file test_push_update_msg.c.

Referenced by test_send_push_msg5().

◆ r6

char* r6[]
Initial value:
= {
"PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
"PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8, redirect-gateway 10.10.10.10,,push-continuation 2",
"PUSH_UPDATE, route 192.168.1.0 255.255.255.0,,push-continuation 1",
NULL
}

Definition at line 370 of file test_push_update_msg.c.

Referenced by add_route_connected_v6_net(), add_route_ipv6(), delete_route_connected_v6_net(), delete_route_ipv6(), delete_routes_v6(), init_route_ipv6(), init_route_ipv6_list(), route_ipv6_clear_host_bits(), setenv_route_ipv6(), setenv_routes_ipv6(), and test_send_push_msg6().

◆ r7

char* r7[]
Initial value:
= {
"PUSH_UPDATE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,push-continuation 2",
"PUSH_UPDATE,,,,,,,,,,,,,,,,,,,push-continuation 1",
NULL
}

Definition at line 376 of file test_push_update_msg.c.

Referenced by test_send_push_msg7().

◆ r8

char* r8[]
Initial value:
= {
"PUSH_UPDATE,-dhcp-option,blablalalalalalalalalalalalalf, lalalalalalalalalalalalalalaf,push-continuation 2",
"PUSH_UPDATE, akakakakakakakakakakakaf, dhcp-option DNS 8.8.8.8,redirect-gateway\n local,push-continuation 2",
"PUSH_UPDATE,route 192.168.1.0 255.255.255.0\n\n\n,push-continuation 1",
NULL
}

Definition at line 381 of file test_push_update_msg.c.

Referenced by test_send_push_msg8().

◆ r9

char* r9[]
Initial value:
= {
"PUSH_UPDATE,,",
NULL
}

Definition at line 387 of file test_push_update_msg.c.

Referenced by test_send_push_msg9().

◆ route_add_count

int route_add_count = 0
static

◆ route_reset_count

int route_reset_count = 0
static