OpenVPN
test_misc.c
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2021-2022 Arne Schwabe <arne@rfc2549.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #elif defined(_MSC_VER)
27 #include "config-msvc.h"
28 #endif
29 
30 #include "syshead.h"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <stdarg.h>
35 #include <string.h>
36 #include <setjmp.h>
37 #include <cmocka.h>
38 
39 #include "ssl_util.h"
40 
41 static void
43 {
44  struct gc_arena gc = gc_new();
45 
46  const char *input = "V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
47 
48  const char *output = options_string_compat_lzo(input, &gc);
49 
50  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");
51 
52  /* This string is has a much too small link-mtu so we should fail on it" */
53  input = "V4,dev-type tun,link-mtu 2,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
54 
55  output = options_string_compat_lzo(input, &gc);
56 
57  assert_string_equal(input, output);
58 
59  /* not matching at all */
60  input = "V4,dev-type tun";
61  output = options_string_compat_lzo(input, &gc);
62 
63  assert_string_equal(input, output);
64 
65 
66  input = "V4,dev-type tun,link-mtu 999,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
67  output = options_string_compat_lzo(input, &gc);
68 
69  /* 999 -> 1000, 3 to 4 chars */
70  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");
71 
72  gc_free(&gc);
73 }
74 
75 const struct CMUnitTest misc_tests[] = {
76  cmocka_unit_test(test_compat_lzo_string),
77 };
78 
79 int
80 main(void)
81 {
82  return cmocka_run_group_tests(misc_tests, NULL, NULL);
83 }
gc_new
static struct gc_arena gc_new(void)
Definition: buffer.h:998
config-msvc.h
main
int main(void)
Definition: test_misc.c:80
misc_tests
const struct CMUnitTest misc_tests[]
Definition: test_misc.c:75
ssl_util.h
syshead.h
gc_arena
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
test_compat_lzo_string
static void test_compat_lzo_string(void **state)
Definition: test_misc.c:42
gc_free
static void gc_free(struct gc_arena *a)
Definition: buffer.h:1006
options_string_compat_lzo
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...
Definition: ssl_util.c:80
config.h