Browse code

t_client.sh: Allow to skip tests

Individual tests can define a script to run to test
whether they should be skipped.

Included in this commit is an example check which
checks whether we can do NTLM checks. This fails
e.g. on recent versions of Fedora with mbedTLS
(tested with Fedora 39) or when NTLM support is not
compiled in.

v2:
- ntlm_support:
- support OpenSSL 3
- allow to build without cmocka
v3:
- add example to t_client.rc-sample
- t_client.sh code style
- use syshead.h in error.h
v5:
- rename SKIP_x to CHECK_SKIP_x

Change-Id: I13ea6752c8d102eabcc579e391828c05d5322899
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20240308102818.9249-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/search?l=mid&q=20240308102818.9249-1-gert@greenie.muc.de
Signed-off-by: Gert Doering <gert@greenie.muc.de>

Frank Lichtenheld authored on 2024/03/08 19:28:18
Showing 6 changed files
... ...
@@ -25,16 +25,10 @@
25 25
 #define ERROR_H
26 26
 
27 27
 #include "basic.h"
28
-
29
-#include <errno.h>
30
-#include <stdbool.h>
28
+#include "syshead.h"
31 29
 
32 30
 #include <assert.h>
33 31
 
34
-#if _WIN32
35
-#include <windows.h>
36
-#endif
37
-
38 32
 /* #define ABORT_ON_ERROR */
39 33
 
40 34
 #if defined(ENABLE_PKCS11) || defined(ENABLE_MANAGEMENT)
... ...
@@ -18,6 +18,8 @@ AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING) System Tests'
18 18
 
19 19
 if !WIN32
20 20
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
21
+
22
+check_PROGRAMS = ntlm_support
21 23
 if HAVE_SITNL
22 24
 test_scripts += t_net.sh
23 25
 endif
... ...
@@ -35,3 +37,15 @@ dist_noinst_SCRIPTS = \
35 35
 
36 36
 dist_noinst_DATA = \
37 37
 	t_client.rc-sample
38
+
39
+ntlm_support_CFLAGS  = -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat -I$(top_srcdir)/tests/unit_tests/openvpn -DNO_CMOCKA @TEST_CFLAGS@
40
+ntlm_support_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn $(OPTIONAL_CRYPTO_LIBS)
41
+ntlm_support_SOURCES = ntlm_support.c \
42
+	unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \
43
+	$(top_srcdir)/src/openvpn/buffer.c \
44
+	$(top_srcdir)/src/openvpn/crypto.c \
45
+	$(top_srcdir)/src/openvpn/crypto_openssl.c \
46
+	$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
47
+	$(top_srcdir)/src/openvpn/otime.c \
48
+	$(top_srcdir)/src/openvpn/packet_id.c \
49
+	$(top_srcdir)/src/openvpn/platform.c
38 50
new file mode 100644
... ...
@@ -0,0 +1,52 @@
0
+/*
1
+ *  OpenVPN -- An application to securely tunnel IP networks
2
+ *             over a single UDP port, with support for SSL/TLS-based
3
+ *             session authentication and key exchange,
4
+ *             packet encryption, packet authentication, and
5
+ *             packet compression.
6
+ *
7
+ * Copyright (C) 2023 OpenVPN Inc <sales@openvpn.net>
8
+ *
9
+ *  This program is free software; you can redistribute it and/or modify
10
+ *  it under the terms of the GNU General Public License version 2
11
+ *  as published by the Free Software Foundation.
12
+ *
13
+ *  This program is distributed in the hope that it will be useful,
14
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ *  GNU General Public License for more details.
17
+ *
18
+ *  You should have received a copy of the GNU General Public License along
19
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
20
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
+ */
22
+
23
+#ifdef HAVE_CONFIG_H
24
+#include "config.h"
25
+#endif
26
+
27
+#include "syshead.h"
28
+
29
+#include "crypto.h"
30
+#include "error.h"
31
+
32
+int
33
+main(void)
34
+{
35
+#if defined(ENABLE_CRYPTO_OPENSSL)
36
+    crypto_load_provider("legacy");
37
+    crypto_load_provider("default");
38
+#endif
39
+#ifdef NTLM
40
+    if (!md_valid("MD4"))
41
+    {
42
+        msg(M_FATAL, "MD4 not supported");
43
+    }
44
+    if (!md_valid("MD5"))
45
+    {
46
+        msg(M_FATAL, "MD5 not supported");
47
+    }
48
+#else  /* ifdef NTLM */
49
+    msg(M_FATAL, "NTLM support not compiled in");
50
+#endif
51
+}
... ...
@@ -27,7 +27,7 @@ REMOTE=mytestserver
27 27
 #
28 28
 # tests to run (list suffixes for config stanzas below)
29 29
 #
30
-TEST_RUN_LIST="1 2"
30
+TEST_RUN_LIST="1 2 2n"
31 31
 
32 32
 #
33 33
 # use "sudo" (etc) to give openvpn the necessary privileges
... ...
@@ -53,14 +53,24 @@ OPENVPN_BASE_P2P="..."
53 53
 #
54 54
 # if something is not defined here, the corresponding test is not run
55 55
 #
56
-# possible test options:
56
+# common test options:
57 57
 #
58
-# RUN_TITLE_x="what is being tested on here" (purely informational)
59
-# OPENVPN_CONF_x = "how to call ./openvpn" [mandatory]
58
+# RUN_TITLE_x        = "what is being tested on here" (purely informational)
59
+# OPENVPN_CONF_x     = "how to call ./openvpn" [mandatory]
60 60
 # EXPECT_IFCONFIG4_x = "this IPv4 address needs to show up in ifconfig"
61 61
 # EXPECT_IFCONFIG6_x = "this IPv6 address needs to show up in ifconfig"
62
-# PING4_HOSTS_x = "these hosts musts ping when openvpn is up (IPv4 fping)"
63
-# PING6_HOSTS_x = "these hosts musts ping when openvpn is up (IPv6 fping6)"
62
+# PING4_HOSTS_x      = "these hosts musts ping when openvpn is up (IPv4 fping)"
63
+# PING6_HOSTS_x      = "these hosts musts ping when openvpn is up (IPv6 fping6)"
64
+#
65
+# hook test options:
66
+#
67
+# CHECK_SKIP_x      = "commands to execute before openvpn, skip test on failure"
68
+# PREPARE_x         = "commands to execute before openvpn"
69
+# POSTINIT_CMD_x    = "commands to execute after openvpn but before ping"
70
+# CLEANUP_x         = "commands to execute after the test"
71
+#
72
+# Note: all hooks are "eval"ed, so run in the original shell of the t_client.sh
73
+# script, not a child process.
64 74
 #
65 75
 # Test 1: UDP / p2mp tun
66 76
 #   specify IPv4+IPv6 addresses expected from server and ping targets
... ...
@@ -76,10 +86,18 @@ RUN_TITLE_2="testing tun/tcp/ipv4+ipv6"
76 76
 OPENVPN_CONF_2="$OPENVPN_BASE_P2MP --dev tun --proto tcp --remote $REMOTE --port 51194"
77 77
 PING4_HOSTS_2="10.100.51.1 10.100.0.1"
78 78
 PING6_HOSTS_2="2001:db8::1 2001:db8:a051::1"
79
-#
80 79
 # run command after openvpn initialization is done - here: delay 5 seconds
81 80
 POSTINIT_CMD_2="sleep 5"
82 81
 
82
+# Test 2n: TCP / p2mp tun / via NTLM proxy
83
+RUN_TITLE_2n="testing tun/tcp/ntlm-proxy"
84
+OPENVPN_CONF_2n="$OPENVPN_BASE_P2MP --dev tun --proto tcp --remote $REMOTE --port 51194
85
+ --http-proxy 192.168.1.2 8080 $KEYBASE/t_client_auth.txt ntlm --http-proxy-option VERSION 1.1"
86
+PING4_HOSTS_2n="10.100.51.1 10.100.0.1"
87
+PING6_HOSTS_2n="2001:db8::1 2001:db8:a051::1"
88
+# skip test if NTLM support is not available
89
+CHECK_SKIP_2n="${top_builddir}/tests/ntlm_support"
90
+
83 91
 # Test 3: UDP / p2p tun
84 92
 # ...
85 93
 
... ...
@@ -291,12 +291,14 @@ run_ping_tests()
291 291
 # main test loop
292 292
 # ----------------------------------------------------------
293 293
 SUMMARY_OK=
294
+SUMMARY_SKIP=
294 295
 SUMMARY_FAIL=
295 296
 
296 297
 for SUF in $TEST_RUN_LIST
297 298
 do
298 299
     # get config variables
299 300
     eval test_prep=\"\$PREPARE_$SUF\"
301
+    eval test_check_skip=\"\$CHECK_SKIP_$SUF\"
300 302
     eval test_postinit=\"\$POSTINIT_CMD_$SUF\"
301 303
     eval test_cleanup=\"\$CLEANUP_$SUF\"
302 304
     eval test_run_title=\"\$RUN_TITLE_$SUF\"
... ...
@@ -318,6 +320,16 @@ do
318 318
     output_start "### test run $SUF: '$test_run_title' ###"
319 319
     fail_count=0
320 320
 
321
+    if [ -n "$test_check_skip" ]; then
322
+        output "check whether we need to skip: '$test_check_skip'"
323
+        if eval $test_check_skip; then :
324
+        else
325
+            output "skip check failed, SKIP test $SUF."
326
+	    SUMMARY_SKIP="$SUMMARY_SKIP $SUF"
327
+	    echo -e "$outbuf" ; continue
328
+        fi
329
+    fi
330
+
321 331
     if [ -n "$test_prep" ]; then
322 332
         output "running preparation: '$test_prep'"
323 333
         eval $test_prep
... ...
@@ -455,8 +467,10 @@ do
455 455
 done
456 456
 
457 457
 if [ -z "$SUMMARY_OK" ] ; then SUMMARY_OK=" none"; fi
458
+if [ -z "$SUMMARY_SKIP" ] ; then SUMMARY_SKIP=" none"; fi
458 459
 if [ -z "$SUMMARY_FAIL" ] ; then SUMMARY_FAIL=" none"; fi
459 460
 echo "Test sets succeeded:$SUMMARY_OK."
461
+echo "Test sets skipped:$SUMMARY_SKIP."
460 462
 echo "Test sets failed:$SUMMARY_FAIL."
461 463
 
462 464
 # remove trap handler
... ...
@@ -31,8 +31,9 @@
31 31
 #include <stdlib.h>
32 32
 #include <setjmp.h>
33 33
 #include <stdint.h>
34
+#ifndef NO_CMOCKA
34 35
 #include <cmocka.h>
35
-
36
+#endif
36 37
 
37 38
 #include "errlevel.h"
38 39
 #include "error.h"
... ...
@@ -74,6 +75,8 @@ x_msg(const unsigned int flags, const char *format, ...)
74 74
     va_end(arglist);
75 75
 }
76 76
 
77
+/* Allow to use mock_msg.c outside of UT */
78
+#ifndef NO_CMOCKA
77 79
 void
78 80
 assert_failed(const char *filename, int line, const char *condition)
79 81
 {
... ...
@@ -81,6 +84,15 @@ assert_failed(const char *filename, int line, const char *condition)
81 81
     /* Keep compiler happy.  Should not happen, mock_assert() does not return */
82 82
     exit(1);
83 83
 }
84
+#else  /* ifndef NO_CMOCKA */
85
+void
86
+assert_failed(const char *filename, int line, const char *condition)
87
+{
88
+    msg(M_FATAL, "Assertion failed at %s:%d (%s)", filename, line, condition ? condition : "");
89
+    _exit(1);
90
+}
91
+#endif
92
+
84 93
 
85 94
 /*
86 95
  * Fail memory allocation.  Don't use msg() because it tries