From patchwork Mon Jan 19 21:50:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4724 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:9186:b0:80a:3855:ce6a with SMTP id j6csp3454110maf; Mon, 19 Jan 2026 13:51:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWneI226QKO4OvERAomoBtanHK52XU+OxLbvvjyTxP4mRKM2/2DJOEHkA1wD1Yh8bkN7g4/C6v0WzE=@openvpn.net X-Received: by 2002:a05:6808:14c6:b0:450:3ff9:f4ef with SMTP id 5614622812f47-45c9c16eb14mr7375769b6e.56.1768859476257; Mon, 19 Jan 2026 13:51:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768859476; cv=none; d=google.com; s=arc-20240605; b=CmeJeebfWGyUs+JFfGEsimdVgwwKMGS9e0eWF29AJMHxaqNCLzOc6gVKw9X+Nmteav JwB36NWGNM7Ak0YVnW+QXT963SiS/m27iQMwEhWjbdGV9WveNzqKwnVOPoZWvtvemBdX ZqM21bYwICDRq76Yg9Ef6RloMl84LdTVhF4SwhEbO4gPprIiaV84ekuHoK+qMpe6Ba5g 9nbDVwj+PnoMXPQV1rdo2d0zzL4alD6rGMPXMx+fvrO6EmPaYWJWZAXLDV7KapdCf8nE ACWB6FgaqXtNMIv5rG6bCiocRJVz/ThcetiWyXGLzi/cZU9sxN1CUZjpTpHgFHPpcUHa uicg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=jkjgcu4EXKgCspBx1n5eB04UPOtWxMrcTbdmBbRaNzY=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=W9qihwWN+IhrJRMuIQEa1iWEqQ3iJyo4L2uHfV7yprlu9VSGZUcjoJY6VbyNX9Wcuw lcJEKS+bs7UKTW1Ts3WQNENd7OlueVtNMqXJSzlxGoCx0Y4gEGDiFuBnPF/i/NefywiU Ez/wAPX6PEDEoxomVJSZAAx5w7oR/gMmKWFcX6VT9ANA0hOl3ij/hg+uHqwuFzsov0ra dyIT6jP7c/K+v6MORKqt4vblO8pQE3MEZqIrRkRGotDzf+L35rilwS99oGSPGxZSVchw Ct8uKIWAQc4McvEnkfhBnBGnn9E8HmBIY5gI6tTDJf8rl9agonHvbmAzPTKz4uFkGrFh SlRg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=XtbhIDr0; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=HXFIM5el; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=herdTxU4; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 5614622812f47-45c9e36f5edsi6667018b6e.79.2026.01.19.13.51.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jan 2026 13:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=XtbhIDr0; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=HXFIM5el; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=herdTxU4; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jkjgcu4EXKgCspBx1n5eB04UPOtWxMrcTbdmBbRaNzY=; b=XtbhIDr080iopcALwUSQnwKMqi YSu7Ou9vh317Bn0l5DESMWHjosJy1IdRHCyYNGR3kobAI7A8okDRZ5NAgyd6T04VQqzsVtEETJG2s oxVf+V+i6s4eEjUW9XkjFc/VRYkW0IMzSPKqdkxGKIo/KWkfFXdZNYAADYpYN1HV9cAE=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vhx9U-0005Dz-MC; Mon, 19 Jan 2026 21:51:12 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vhx9T-0005Dt-OJ for openvpn-devel@lists.sourceforge.net; Mon, 19 Jan 2026 21:51:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=aCdaweEKeUU2AWst1AKAxJ4d/vOdnFZgehGejeHrt6Y=; b=HXFIM5elQZSWZy22PMZoPduxAp ubGckk6u/2EDA3TJwFLck4mCERv8HL4qfoiMwoqJKiiHrYTkDWCWbrewiBD6V+KOgy1DKX9GzpsMx PfMg++5s5nCdcIs7l3h+vrBJ+YJm71O1mziteHxDo7pOnN3N71Hpj+kYJkx/f/bnY698=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=aCdaweEKeUU2AWst1AKAxJ4d/vOdnFZgehGejeHrt6Y=; b=herdTxU4ADs8gG3Fs1GsbGdqWP sdc5XY/boo1kuI2KCBQFFNAWlKccVXvKJjjpEfkHqW6wZwiuopEE18fTi3zYoby+6gpusOAGfbuKc 4doNJgHOGCVIkExdqNmEAvODJYWzVxSFJg1YOdztsbp4HXDTdpioWBcFet1Wb4xQXBK8=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1vhx9S-00069Y-KT for openvpn-devel@lists.sourceforge.net; Mon, 19 Jan 2026 21:51:11 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 60JLoxw5027903 for ; Mon, 19 Jan 2026 22:50:59 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 60JLox7K027902 for openvpn-devel@lists.sourceforge.net; Mon, 19 Jan 2026 22:50:59 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Mon, 19 Jan 2026 22:50:53 +0100 Message-ID: <20260119215058.27888-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld This adds the required build infrastructure and adds tests for two functions related to GetItfDnsDomains(). Change-Id: I33583e51e1143c53fbe0aef16546fa3f602b17c0 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/open [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1vhx9S-00069Y-KT Subject: [Openvpn-devel] [PATCH v6] openvpnserv: Add a first unit test X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1854783593919470387?= X-GMAIL-MSGID: =?utf-8?q?1854783593919470387?= From: Frank Lichtenheld This adds the required build infrastructure and adds tests for two functions related to GetItfDnsDomains(). Change-Id: I33583e51e1143c53fbe0aef16546fa3f602b17c0 Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1459 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1459 This mail reflects revision 6 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/configure.ac b/configure.ac index 8ba5673..d3d548b 100644 --- a/configure.ac +++ b/configure.ac @@ -1460,6 +1460,7 @@ tests/unit_tests/Makefile tests/unit_tests/example_test/Makefile tests/unit_tests/openvpn/Makefile + tests/unit_tests/openvpnserv/Makefile tests/unit_tests/plugins/Makefile tests/unit_tests/plugins/auth-pam/Makefile sample/Makefile diff --git a/src/openvpnserv/CMakeLists.txt b/src/openvpnserv/CMakeLists.txt index 2c8f310..fc15382 100644 --- a/src/openvpnserv/CMakeLists.txt +++ b/src/openvpnserv/CMakeLists.txt @@ -10,13 +10,29 @@ set(MC_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/mc) -target_include_directories(openvpnserv PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/../../ - ../../include/ - ../openvpn/ - ../compat/ - ${MC_GEN_DIR} +function(add_common_options target) + target_include_directories(${target} PRIVATE + ${CMAKE_CURRENT_BINARY_DIR}/../../ + ../../include/ + ../openvpn/ + ../compat/ + ${MC_GEN_DIR} ) + target_compile_options(${target} PRIVATE + -D_UNICODE + -UNTDDI_VERSION + -D_WIN32_WINNT=_WIN32_WINNT_VISTA + ) + target_link_libraries(${target} PRIVATE + advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib + shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib ole32.lib pathcch.lib) + if (MINGW) + target_compile_options(${target} PRIVATE -municode) + target_link_options(${target} PRIVATE -municode) + endif () +endfunction() + +add_common_options(openvpnserv) target_sources(openvpnserv PRIVATE common.c interactive.c @@ -26,18 +42,6 @@ ../openvpn/wfp_block.c ../openvpn/wfp_block.h openvpnserv_resources.rc ) -target_compile_options(openvpnserv PRIVATE - -D_UNICODE - -UNTDDI_VERSION - -D_WIN32_WINNT=_WIN32_WINNT_VISTA - ) -target_link_libraries(openvpnserv - advapi32.lib userenv.lib iphlpapi.lib fwpuclnt.lib rpcrt4.lib - shlwapi.lib netapi32.lib ws2_32.lib ntdll.lib ole32.lib pathcch.lib) -if (MINGW) - target_compile_options(openvpnserv PRIVATE -municode) - target_link_options(openvpnserv PRIVATE -municode) -endif () # below we generate a DLL which contains an event source for event log messages from eventmsg.mc template file(MAKE_DIRECTORY ${MC_GEN_DIR}) @@ -74,3 +78,30 @@ endif() add_dependencies(openvpnserv msg_mc_gen) + +if (BUILD_TESTING) + set(unit_tests + "test_openvpnserv" + ) + + foreach (test_name ${unit_tests}) + add_test(${test_name} ${test_name}) + add_executable(${test_name} + ../../tests/unit_tests/openvpnserv/${test_name}.c + ${MC_GEN_DIR}/eventmsg.h + ) + + add_common_options(${test_name}) + target_link_libraries(${test_name} PUBLIC ${CMOCKA_LIBRARIES}) + target_include_directories(${test_name} PRIVATE + . + ../../tests/unit_tests/openvpn + ) + endforeach() + + target_sources(test_openvpnserv PRIVATE + common.c + validate.c + ../openvpn/wfp_block.c ../openvpn/wfp_block.h + ) +endif () diff --git a/tests/unit_tests/Makefile.am b/tests/unit_tests/Makefile.am index 33fefaa..ce6278e 100644 --- a/tests/unit_tests/Makefile.am +++ b/tests/unit_tests/Makefile.am @@ -1,5 +1,5 @@ AUTOMAKE_OPTIONS = foreign if ENABLE_UNITTESTS -SUBDIRS = example_test openvpn plugins +SUBDIRS = example_test openvpn openvpnserv plugins endif diff --git a/tests/unit_tests/openvpn/test_common.h b/tests/unit_tests/openvpn/test_common.h index f898e89..156e5a9 100644 --- a/tests/unit_tests/openvpn/test_common.h +++ b/tests/unit_tests/openvpn/test_common.h @@ -20,8 +20,9 @@ * with this program; if not, see . */ -#include #include +#include +#include #include /* Do we use cmocka < 2.0.0? */ diff --git a/tests/unit_tests/openvpnserv/Makefile.am b/tests/unit_tests/openvpnserv/Makefile.am new file mode 100644 index 0000000..6064978 --- /dev/null +++ b/tests/unit_tests/openvpnserv/Makefile.am @@ -0,0 +1,16 @@ +AUTOMAKE_OPTIONS = foreign + +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING) service Unit-Tests' + +if WIN32 +test_binaries = openvpnserv_testdriver +endif + +openvpnserv_testdriver_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/openvpn -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpnserv @TEST_CFLAGS@ +openvpnserv_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(top_srcdir)/src/openvpn +openvpnserv_testdriver_SOURCES = test_openvpnserv.c \ + $(top_srcdir)/src/openvpnserv/common.c \ + $(top_srcdir)/src/openvpnserv/validate.c \ + $(top_srcdir)/src//openvpn/wfp_block.c \ + $(top_srcdir)/src//openvpn/wfp_block.h + diff --git a/tests/unit_tests/openvpnserv/test_openvpnserv.c b/tests/unit_tests/openvpnserv/test_openvpnserv.c new file mode 100644 index 0000000..348de4f --- /dev/null +++ b/tests/unit_tests/openvpnserv/test_openvpnserv.c @@ -0,0 +1,113 @@ +/* + * 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) 2025 Frank Lichtenheld + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 2 of the License, + * or (at your option) any later version. + * + * 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, see . + */ + +#include +#include +#include "test_common.h" + +#include +#include + +#include "interactive.c" + +BOOL +ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status) +{ + return TRUE; +} + +static void +test_list_contains_domain(void **state) +{ + PCWSTR domain = L"openvpn.net"; + size_t domain_len = wcslen(domain); + assert_true(ListContainsDomain(domain, domain, domain_len)); + assert_true(ListContainsDomain(L"openvpn.com,openvpn.net", domain, domain_len)); + assert_true(ListContainsDomain(L"openvpn.net,openvpn.com", domain, domain_len)); + + assert_false(ListContainsDomain(L"openvpn.com", domain, domain_len)); + assert_false(ListContainsDomain(L"internal.openvpn.net", domain, domain_len)); +} + +#define BUF_SIZE 64 +static void +test_convert_itf_dns_domains(void **state) +{ + DWORD size, orig_size, len, res_len; + LSTATUS err; + const DWORD glyph_size = sizeof(wchar_t); + + wchar_t domains_1[BUF_SIZE] = L"openvpn.com"; + len = (DWORD)wcslen(domains_1) + 1; + size = orig_size = len * glyph_size; + wchar_t domains_1_res[BUF_SIZE] = L".openvpn.com"; + res_len = len + 2; /* adds . and \0 */ + err = ConvertItfDnsDomains(L"openvpn.net", domains_1, &size, BUF_SIZE); + assert_memory_equal(domains_1, domains_1_res, size); + assert_int_equal(size, res_len * glyph_size); + assert_int_equal(err, NO_ERROR); + + wchar_t domains_2[BUF_SIZE] = L"openvpn.com,openvpn.net"; + len = (DWORD)wcslen(domains_2) + 1; + size = orig_size = len * glyph_size; + wchar_t domains_2_res[BUF_SIZE] = L".openvpn.com"; + res_len = (DWORD)wcslen(domains_2_res) + 2; + err = ConvertItfDnsDomains(L"openvpn.net", domains_2, &size, BUF_SIZE); + assert_memory_equal(domains_2, domains_2_res, size); + assert_int_equal(size, res_len * glyph_size); + assert_int_equal(err, NO_ERROR); + + wchar_t domains_3[BUF_SIZE] = L"openvpn.com,openvpn.net"; + len = (DWORD)wcslen(domains_3) + 1; + size = orig_size = len * glyph_size; + wchar_t domains_3_res[BUF_SIZE] = L".openvpn.net"; + res_len = (DWORD)wcslen(domains_3_res) + 2; + err = ConvertItfDnsDomains(L"openvpn.com", domains_3, &size, BUF_SIZE); + assert_memory_equal(domains_3, domains_3_res, size); + assert_int_equal(size, res_len * glyph_size); + assert_int_equal(err, NO_ERROR); + + wchar_t domains_4[BUF_SIZE] = L"openvpn.com,openvpn.net"; + len = (DWORD)wcslen(domains_4) + 1; + size = orig_size = len * glyph_size; + wchar_t domains_4_res[BUF_SIZE] = L".openvpn.com\0.openvpn.net"; + res_len = len + 3; /* adds two . and one \0 */ + err = ConvertItfDnsDomains(NULL, domains_4, &size, BUF_SIZE); + assert_memory_equal(domains_4, domains_4_res, size); + assert_int_equal(size, res_len * glyph_size); + assert_int_equal(err, NO_ERROR); +} + +int +wmain(void) +{ + openvpn_unit_test_setup(); + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_list_contains_domain), + cmocka_unit_test(test_convert_itf_dns_domains), + }; + + int ret = cmocka_run_group_tests_name("openvpnserv tests", tests, NULL, NULL); + + return ret; +}