From: "flichtenheld (Code Review)" Date: Wed, 14 Feb 2024 12:07:38 +0000 In-Reply-To: References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <203a96f191f6241d42804a020aa4434b97e1fa90-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="do1i7tndHQI="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: t_client.sh: Allow to skip tests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --do1i7tndHQI= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/521?usp=3Demail to look at the new patch set (#2). Change subject: t_client.sh: Allow to skip tests ...................................................................... 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 Change-Id: I13ea6752c8d102eabcc579e391828c05d5322899 Signed-off-by: Frank Lichtenheld --- M src/openvpn/error.h M tests/Makefile.am A tests/ntlm_support.c M tests/t_client.sh.in M tests/unit_tests/openvpn/mock_msg.c 5 files changed, 94 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/21/521/2 diff --git a/src/openvpn/error.h b/src/openvpn/error.h index 1225b13..0ef3263 100644 --- a/src/openvpn/error.h +++ b/src/openvpn/error.h @@ -33,6 +33,9 @@ #if _WIN32 #include +#else +/* for _exit() */ +#include #endif /* #define ABORT_ON_ERROR */ diff --git a/tests/Makefile.am b/tests/Makefile.am index b3b2d74..13a1013 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -19,6 +19,8 @@ if !WIN32 test_scripts =3D t_client.sh t_lpback.sh t_cltsrv.sh + +check_PROGRAMS =3D ntlm_support if HAVE_SITNL test_scripts +=3D t_net.sh endif @@ -36,3 +38,15 @@ dist_noinst_DATA =3D \ t_client.rc-sample + +ntlm_support_CFLAGS =3D -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/c= ompat -I$(top_srcdir)/tests/unit_tests/openvpn -DNO_CMOCKA @TEST_CFLAGS@ +ntlm_support_LDFLAGS =3D @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn $(OPTI= ONAL_CRYPTO_LIBS) +ntlm_support_SOURCES =3D ntlm_support.c \ + unit_tests/openvpn/mock_msg.c unit_tests/openvpn/mock_msg.h \ + $(top_srcdir)/src/openvpn/buffer.c \ + $(top_srcdir)/src/openvpn/crypto.c \ + $(top_srcdir)/src/openvpn/crypto_openssl.c \ + $(top_srcdir)/src/openvpn/crypto_mbedtls.c \ + $(top_srcdir)/src/openvpn/otime.c \ + $(top_srcdir)/src/openvpn/packet_id.c \ + $(top_srcdir)/src/openvpn/platform.c diff --git a/tests/ntlm_support.c b/tests/ntlm_support.c new file mode 100644 index 0000000..8d81257 --- /dev/null +++ b/tests/ntlm_support.c @@ -0,0 +1,51 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2023 OpenVPN Inc + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "syshead.h" + +#include "crypto.h" + +int +main(void) +{ +#if defined(ENABLE_CRYPTO_OPENSSL) + crypto_load_provider("legacy"); + crypto_load_provider("default"); +#endif +#ifdef NTLM + if (!md_valid("MD4")) + { + msg(M_FATAL, "MD4 not supported"); + } + if (!md_valid("MD5")) + { + msg(M_FATAL, "MD5 not supported"); + } +#else /* ifdef NTLM */ + msg(M_FATAL, "NTLM support not compiled in"); +#endif +} diff --git a/tests/t_client.sh.in b/tests/t_client.sh.in index 99e6f9c..7be1c8e 100755 --- a/tests/t_client.sh.in +++ b/tests/t_client.sh.in @@ -291,12 +291,14 @@ # main test loop # ---------------------------------------------------------- SUMMARY_OK=3D +SUMMARY_SKIP=3D SUMMARY_FAIL=3D for SUF in $TEST_RUN_LIST do # get config variables eval test_prep=3D\"\$PREPARE_$SUF\" + eval test_check_skip=3D\"\$SKIP_$SUF\" eval test_postinit=3D\"\$POSTINIT_CMD_$SUF\" eval test_cleanup=3D\"\$CLEANUP_$SUF\" eval test_run_title=3D\"\$RUN_TITLE_$SUF\" @@ -318,6 +320,15 @@ output_start "### test run $SUF: '$test_run_title' ###" fail_count=3D0 + if [ -n "$test_check_skip" ]; then + output "check whether we need to skip: '$test_check_skip'" + eval $test_check_skip || { + output "skip check failed, SKIP test $SUF." + SUMMARY_SKIP=3D"$SUMMARY_SKIP $SUF" + echo -e "$outbuf" ; continue + } + fi + if [ -n "$test_prep" ]; then output "running preparation: '$test_prep'" eval $test_prep @@ -455,8 +466,10 @@ done if [ -z "$SUMMARY_OK" ] ; then SUMMARY_OK=3D" none"; fi +if [ -z "$SUMMARY_SKIP" ] ; then SUMMARY_SKIP=3D" none"; fi if [ -z "$SUMMARY_FAIL" ] ; then SUMMARY_FAIL=3D" none"; fi echo "Test sets succeeded:$SUMMARY_OK." +echo "Test sets skipped:$SUMMARY_SKIP." echo "Test sets failed:$SUMMARY_FAIL." # remove trap handler diff --git a/tests/unit_tests/openvpn/mock_msg.c b/tests/unit_tests/openvpn= /mock_msg.c index d74efaa..a291f8f 100644 --- a/tests/unit_tests/openvpn/mock_msg.c +++ b/tests/unit_tests/openvpn/mock_msg.c @@ -31,8 +31,9 @@ #include #include #include +#ifndef NO_CMOCKA #include - +#endif #include "errlevel.h" #include "error.h" @@ -74,6 +75,8 @@ va_end(arglist); } +/* Allow to use mock_msg.c outside of UT */ +#ifndef NO_CMOCKA void assert_failed(const char *filename, int line, const char *condition) { @@ -81,6 +84,15 @@ /* Keep compiler happy. Should not happen, mock_assert() does not ret= urn */ exit(1); } +#else /* ifndef NO_CMOCKA */ +void +assert_failed(const char *filename, int line, const char *condition) +{ + msg(M_FATAL, "Assertion failed at %s:%d (%s)", filename, line, conditi= on ? condition : ""); + _exit(1); +} +#endif + /* * Fail memory allocation. Don't use msg() because it tries -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/521?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I13ea6752c8d102eabcc579e391828c05d5322899 Gerrit-Change-Number: 521 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newpatchset --do1i7tndHQI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld uploaded patch set #2 to this change.

<= p>View Ch= ange

t_client.sh: Allow to skip tests

Individual tests can defin= e a script to run to test
whether they should be skipped.

Include= d 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
(t= ested with Fedora 39) or when NTLM support is not
compiled in.

v2= :
- ntlm_support:
- support OpenSSL 3
- allow to build with= out cmocka

Change-Id: I13ea6752c8d102eabcc579e391828c05d5322899
S= igned-off-by: Frank Lichtenheld <frank@...2641...>
---
M src/op= envpn/error.h
M tests/Makefile.am
A tests/ntlm_support.c
M tests/t= _client.sh.in
M tests/unit_tests/openvpn/mock_msg.c
5 files changed, = 94 insertions(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net=
:29418/openvpn refs/changes/21/521/2
diff --git a/src/openvpn/error=
.h b/src/openvpn/error.h
index 1225b13..0ef3263 100644
--- a/src/openvpn/error.h
+++ b/src/openvpn/err= or.h
@@ -33,6 +33,9 @@

#= if _WIN32
#include <windows.h>
+#else
+/* for _exit() */
+#include <unistd.h>
#endif<= br>
/* #define ABORT_ON_ERROR */
di= ff --git a/tests/Makefile.am b/tests/Makefile.am
index b3b2= d74..13a1013 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am

@@ -19,6 +19,8 @@
=
if !WIN32
test_scripts =3D t_client.sh = t_lpback.sh t_cltsrv.sh
+
+check_PROGRAMS = =3D ntlm_support
if HAVE_SITNL
test_scrip= ts +=3D t_net.sh
endif
@@ -36,3 +38,15 @@<= /span>

dist_noinst_DATA =3D \
= t_client.rc-sample
+=
+ntlm_support_CFLAGS= =3D -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat -I$(top_srcdir= )/tests/unit_tests/openvpn -DNO_CMOCKA @TEST_CFLAGS@
+ntlm_support_LDFLAGS =3D @TEST_LDFLAGS@ -= L$(top_srcdir)/src/openvpn $(OPTIONAL_CRYPTO_LIBS)
+ntlm_support_SOURCES =3D ntlm_support.c \
+ unit_tests/openvpn/mo= ck_msg.c unit_tests/openvpn/mock_msg.h \
+ $(top_srcdir)/src/openvpn/buffer.c \
+ $(top_srcdir)/src/openvpn/crypto.c = \
+ $(top_srcdir)/src= /openvpn/crypto_openssl.c \
+ $(top_srcdir)/src/openvpn/crypto_mbedtls.c \
+ $(top_srcdir)/src/openvpn/otime.c \
+ $(top_srcdir)/src/openv= pn/packet_id.c \
+ $(= top_srcdir)/src/openvpn/platform.c
diff --git a/tests/ntlm_= support.c b/tests/ntlm_support.c
new file mode 100644
index 0000000..8d81257
--- /dev/null
<= span>+++ b/tests/ntlm_support.c

@@ -0,0 +1,51 @@
= +/*
+ * OpenVPN -- An application to securely tunne= l IP networks
+ * = over a single UDP port, with support for SSL/TLS-based
<= span style=3D"color: hsl(120, 100%, 40%);">+ * session authenti= cation and key exchange,

+ * packet encryption, packet authentication, and+ * packet compres= sion.
+ *
<= span style=3D"color: hsl(120, 100%, 40%);">+ * Copyright (C) 2023 OpenVPN I= nc <sales@...515...>

+ *
+ * This p= rogram is free software; you can redistribute it and/or modify
+ * it under the terms of the GN= U General Public License version 2

+ * as published by the Free Software Foundation.
= + *
+ * This program is distributed in the hope tha= t it will be useful,
= + * but WITHOUT ANY WARRANTY; without even the implied warranty of<= br>+ * MERCHANTABILITY or FITN= ESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.<= br>+ *
+ * You should have received a copy of the G= NU General Public License along
+ * with this program; if not, write to the Free Software Found= ation, Inc.,
+ * 51 = Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#endif
+=
+#include "sysh= ead.h"
+<= br>+#include "crypto.h&quo= t;
+
+int
+main(void)
+{
+#if = defined(ENABLE_CRYPTO_OPENSSL)
+ crypto_load_provider("legacy");
+ crypto_load_provider("default= ");
+#endif
+#ifdef NTLM
+ if (!md_valid("MD4"= ;))

+ {
= + msg(M_FATAL, "MD4= not supported");
+ if (!md= _valid("MD5"))
+ {
+ m= sg(M_FATAL, "MD5 not supported");
+ }
+#else /* ifdef NTLM */
+ msg(M_FATAL, "NTLM support not compiled in");
+#endif
+}

diff --git a/tes= ts/t_client.sh.in b/tests/t_client.sh.in
index 99e6f9c..7be= 1c8e 100755
--- a/tests/t_client.sh.in
+++ = b/tests/t_client.sh.in
@@ -291,12 +291,14 @@
# main test loop
# ------------------------------------= ----------------------
SUMMARY_OK=3D
+SUMMARY_SKIP=3D
SUMMARY_= FAIL=3D

for SUF in $TEST_RUN_LIST=
do
# get config variables
= eval test_prep=3D\"\$PREPARE_$SUF\"
+ eval test_check_skip=3D\"\$SKIP_$SUF= \"
eval test_postinit=3D\"\$POSTINIT_CMD_$SU= F\"
eval test_cleanup=3D\"\$CLEANUP_$SUF\&qu= ot;
eval test_run_title=3D\"\$RUN_TITLE_$SUF\&quo= t;
@@ -318,6 +320,15 @@
output_start &= quot;### test run $SUF: '$test_run_title' ###"
fail_count=3D0

+ if [ -n "$test_check_skip" ]; then<= br>+ output "check = whether we need to skip: '$test_check_skip'"
+ eval $test_check_skip || {
+ output &qu= ot;skip check failed, SKIP test $SUF."
+ SUMMARY_SKIP=3D"$SUMMARY_SKIP $SUF"<= /span>
+ echo -e "$= outbuf" ; continue
+ }
+ fi=
+
= if [ -n "$test_prep" ]; then
output &= quot;running preparation: '$test_prep'"
= eval $test_prep
@@ -455,8 +466,10 @@
do= ne

if [ -z "$SUMMARY_OK" ] ; t= hen SUMMARY_OK=3D" none"; fi
+if [ -z "$SUMMARY_SKIP" ] ; then SUMMARY_SKIP= =3D" none"; fi
if [ -z "$SUMMARY_FAIL"= ] ; then SUMMARY_FAIL=3D" none"; fi
echo "= Test sets succeeded:$SUMMARY_OK."
+echo "Test sets skipped:$SUMMARY_SKIP."=
echo "Test sets failed:$SUMMARY_FAIL."

# remove trap handler
diff --git a/test= s/unit_tests/openvpn/mock_msg.c b/tests/unit_tests/openvpn/mock_msg.c

index d74efaa..a291f8f 100644
--- a/tests/unit_t= ests/openvpn/mock_msg.c
+++ b/tests/unit_tests/openvpn/mock= _msg.c
@@ -31,8 +31,9 @@
#include <stdl= ib.h>
#include <setjmp.h>
#inclu= de <stdint.h>
+= #ifndef NO_CMOCKA
#include <cmocka.h>
-
+#endif

#include &quo= t;errlevel.h"
#include "error.h"
= @@ -74,6 +75,8 @@
va_end(arglist);
}

+/* Allow to use mock_msg.c outside of UT */
+#ifndef NO_CMOCKA
void<= br> assert_failed(const char *filename, int line, const char *conditi= on)
{
@@ -81,6 +84,15 @@
= /* Keep compiler happy. Should not happen, mock_assert() does not retu= rn */
exit(1);
}
+#else /* ifndef NO_CMOCKA */
= +void
+assert_failed(const char *filename, int line,= const char *condition)
+{
+ msg(M_FATA= L, "Assertion failed at %s:%d (%s)", filename, line, condition ? = condition : "");
+ _exit(1);
= +}
+#endif
= +

<= span> /*
* Fail memory allocation. Don't use msg() b= ecause it tries

To view, visit change 521. = To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I13ea6752c8d102eabcc579e3918= 28c05d5322899
Gerrit-Change-Number: 521
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-MessageType: newpatchset
--do1i7tndHQI=--