Go to the documentation of this file.
47 const char *input =
"V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
51 assert_string_equal(output,
"V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo");
54 input =
"V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
58 assert_string_equal(input, output);
61 input =
"V4,dev-type tun";
64 assert_string_equal(input, output);
67 input =
"V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
71 assert_string_equal(output,
"V4,dev-type tun,link-mtu 1000,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo");
81 const char *teststr =
"TEMP:There are no flags here [really not]";
84 assert_string_equal(
msg,
"There are no flags here [really not]");
92 const char *teststr =
"[backoff 42,advance no]";
95 assert_string_equal(
msg,
"");
105 const char *teststr =
"[advance remote,backoff 77]:go round and round";
108 assert_string_equal(
msg,
"go round and round");
124 const char *str = (
const char *)
key;
125 const int len = strlen(str);
126 return hash_func((
const uint8_t *)str, len, iv);
132 return strcmp((
const char *)
key1, (
const char *)
key2) == 0;
176 char wordfile[PATH_MAX] = { 0 };
179 FILE *words = fopen(wordfile,
"r");
180 assert_non_null(words);
190 if (!fgets(buf,
sizeof(buf), words))
201 if (isalnum(c) || c ==
'_')
203 assert_true(wbi < (
int)
sizeof(wordbuf));
212 ASSERT(wbi < (
int)
sizeof(wordbuf));
213 wordbuf[wbi++] =
'\0';
222 assert_string_equal(w->
word, wordbuf);
242 assert_int_equal(wordcount, 2978);
268 if (!strcmp(w->
word,
"is"))
270 assert_int_equal(w->
n, 49);
272 else if (!strcmp(w->
word,
"redistribute"))
274 assert_int_equal(w->
n, 5);
276 else if (!strcmp(w->
word,
"circumstances"))
278 assert_int_equal(w->
n, 1);
280 else if (!strcmp(w->
word,
"so"))
282 assert_int_equal(w->
n, 8);
284 else if (!strcmp(w->
word,
"BECAUSE"))
286 assert_int_equal(w->
n, 1);
327 return cmocka_run_group_tests(
misc_tests, NULL, NULL);
static int hash_n_elements(const struct hash *hash)
struct hash * hash_init(const int n_buckets, const uint32_t iv, uint32_t(*hash_function)(const void *key, uint32_t iv), bool(*compare_function)(const void *key1, const void *key2))
static struct gc_arena gc_new(void)
static void test_auth_fail_temp_flags(void **state)
static void test_list(void **state)
static const char *const key1
bool hash_add(struct hash *hash, const void *key, void *value, bool replace)
static bool hash_remove(struct hash *hash, const void *key)
static void * hash_lookup(struct hash *hash, const void *key)
const char * parse_auth_failed_temp(struct options *o, const char *reason)
Container for unidirectional cipher and HMAC key material.
void hash_remove_by_value(struct hash *hash, void *value)
void hash_iterator_free(struct hash_iterator *hi)
const struct CMUnitTest misc_tests[]
static void test_auth_fail_temp_flags_msg(void **state)
char * string_alloc(const char *str, struct gc_arena *gc)
static uint32_t word_hash_function(const void *key, uint32_t iv)
struct hash_element * hash_iterator_next(struct hash_iterator *hi)
static unsigned long get_random(void)
static struct hash_element * hash_lookup_by_value(struct hash *hash, void *value)
static bool word_compare_function(const void *key1, const void *key2)
void hash_iterator_init(struct hash *hash, struct hash_iterator *hi)
Garbage collection arena used to keep track of dynamically allocated memory.
static void openvpn_unit_test_setup(void)
Sets up the environment for unit tests like making both stderr and stdout non-buffered to avoid messa...
static void test_compat_lzo_string(void **state)
void hash_free(struct hash *hash)
static void test_auth_fail_temp_no_flags(void **state)
static void gc_free(struct gc_arena *a)
const char * options_string_compat_lzo(const char *options, struct gc_arena *gc)
Takes a locally produced OCC string for TLS server mode and modifies as if the option comp-lzo was en...
Container for bidirectional cipher and HMAC key material.
static int hash_n_buckets(const struct hash *hash)
uint32_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval)
void openvpn_test_get_srcdir_dir(char *buf, size_t bufsize, const char *filename)
Helper function to get a file path from the unit test directory to open it or pass its path to anothe...
void hash_iterator_init_range(struct hash *hash, struct hash_iterator *hi, int start_bucket, int end_bucket)
#define ALLOC_OBJ_GC(dptr, type, gc)