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>
(cherry picked from commit 0c7cf0694ee6f878168330e9a084c255c51a9e8b)

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)
... ...
@@ -16,6 +16,8 @@ SUBDIRS = unit_tests
16 16
 
17 17
 if !WIN32
18 18
 test_scripts = t_client.sh t_lpback.sh t_cltsrv.sh
19
+
20
+check_PROGRAMS = ntlm_support
19 21
 if HAVE_SITNL
20 22
 test_scripts += t_net.sh
21 23
 endif
... ...
@@ -33,3 +35,15 @@ dist_noinst_SCRIPTS = \
33 33
 
34 34
 dist_noinst_DATA = \
35 35
 	t_client.rc-sample
36
+
37
+ntlm_support_CFLAGS  = -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat -I$(top_srcdir)/tests/unit_tests/openvpn -DNO_CMOCKA @TEST_CFLAGS@
38
+ntlm_support_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn $(OPTIONAL_CRYPTO_LIBS)
39
+ntlm_support_SOURCES = ntlm_support.c \
40
+	unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \
41
+	$(top_srcdir)/src/openvpn/buffer.c \
42
+	$(top_srcdir)/src/openvpn/crypto.c \
43
+	$(top_srcdir)/src/openvpn/crypto_openssl.c \
44
+	$(top_srcdir)/src/openvpn/crypto_mbedtls.c \
45
+	$(top_srcdir)/src/openvpn/otime.c \
46
+	$(top_srcdir)/src/openvpn/packet_id.c \
47
+	$(top_srcdir)/src/openvpn/platform.c
36 48
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
 
... ...
@@ -290,12 +290,14 @@ run_ping_tests()
290 290
 # main test loop
291 291
 # ----------------------------------------------------------
292 292
 SUMMARY_OK=
293
+SUMMARY_SKIP=
293 294
 SUMMARY_FAIL=
294 295
 
295 296
 for SUF in $TEST_RUN_LIST
296 297
 do
297 298
     # get config variables
298 299
     eval test_prep=\"\$PREPARE_$SUF\"
300
+    eval test_check_skip=\"\$CHECK_SKIP_$SUF\"
299 301
     eval test_postinit=\"\$POSTINIT_CMD_$SUF\"
300 302
     eval test_cleanup=\"\$CLEANUP_$SUF\"
301 303
     eval test_run_title=\"\$RUN_TITLE_$SUF\"
... ...
@@ -317,6 +319,16 @@ do
317 317
     output_start "### test run $SUF: '$test_run_title' ###"
318 318
     fail_count=0
319 319
 
320
+    if [ -n "$test_check_skip" ]; then
321
+        output "check whether we need to skip: '$test_check_skip'"
322
+        if eval $test_check_skip; then :
323
+        else
324
+            output "skip check failed, SKIP test $SUF."
325
+	    SUMMARY_SKIP="$SUMMARY_SKIP $SUF"
326
+	    echo -e "$outbuf" ; continue
327
+        fi
328
+    fi
329
+
320 330
     if [ -n "$test_prep" ]; then
321 331
         output "running preparation: '$test_prep'"
322 332
         eval $test_prep
... ...
@@ -454,8 +466,10 @@ do
454 454
 done
455 455
 
456 456
 if [ -z "$SUMMARY_OK" ] ; then SUMMARY_OK=" none"; fi
457
+if [ -z "$SUMMARY_SKIP" ] ; then SUMMARY_SKIP=" none"; fi
457 458
 if [ -z "$SUMMARY_FAIL" ] ; then SUMMARY_FAIL=" none"; fi
458 459
 echo "Test sets succeeded:$SUMMARY_OK."
460
+echo "Test sets skipped:$SUMMARY_SKIP."
459 461
 echo "Test sets failed:$SUMMARY_FAIL."
460 462
 
461 463
 # 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"
... ...
@@ -68,6 +69,8 @@ x_msg(const unsigned int flags, const char *format, ...)
68 68
     va_end(arglist);
69 69
 }
70 70
 
71
+/* Allow to use mock_msg.c outside of UT */
72
+#ifndef NO_CMOCKA
71 73
 void
72 74
 assert_failed(const char *filename, int line, const char *condition)
73 75
 {
... ...
@@ -75,6 +78,15 @@ assert_failed(const char *filename, int line, const char *condition)
75 75
     /* Keep compiler happy.  Should not happen, mock_assert() does not return */
76 76
     exit(1);
77 77
 }
78
+#else  /* ifndef NO_CMOCKA */
79
+void
80
+assert_failed(const char *filename, int line, const char *condition)
81
+{
82
+    msg(M_FATAL, "Assertion failed at %s:%d (%s)", filename, line, condition ? condition : "");
83
+    _exit(1);
84
+}
85
+#endif
86
+
78 87
 
79 88
 /*
80 89
  * Fail memory allocation.  Don't use msg() because it tries