Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1785?usp=email
to review the following change.
Change subject: tests: add subnet-pool tag lookup unit test
......................................................................
tests: add subnet-pool tag lookup unit test
Cover subnet_pool_by_tag: a client's subnet-pool-tag resolves to the
right pool (carrying its subnet and gateway), and an unknown tag returns
NULL, which is the condition that rejects the client with AUTH_FAILED.
Change-Id: Id414ce0c8f5ed5b01259590e4eaa1b19f2239362
GitHub: closes openvpn/OpenVPN#987
Signed-off-by: Antonio Quartulli <[email protected]>
---
M CMakeLists.txt
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_subnet_pool.c
3 files changed, 92 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/85/1785/1
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8de836a..ac1d05e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -671,6 +671,7 @@
"test_provider"
"test_socket"
"test_ssl"
+ "test_subnet_pool"
"test_user_pass"
"test_push_update_msg"
)
@@ -830,6 +831,11 @@
src/openvpn/list.c
)
+ target_sources(test_subnet_pool PRIVATE
+ tests/unit_tests/openvpn/mock_get_random.c
+ src/openvpn/options_util.c
+ )
+
target_sources(test_ncp PRIVATE
src/openvpn/crypto_epoch.c
src/openvpn/crypto_mbedtls.c
diff --git a/tests/unit_tests/openvpn/Makefile.am
b/tests/unit_tests/openvpn/Makefile.am
index 1128eb4..bfb7284 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -21,6 +21,7 @@
push_update_msg_testdriver \
socket_testdriver \
ssl_testdriver \
+ subnet_pool_testdriver \
user_pass_testdriver
if HAVE_LD_WRAP_SUPPORT
@@ -361,6 +362,19 @@
$(top_srcdir)/src/openvpn/platform.c \
$(top_srcdir)/src/openvpn/mbuf.c
+subnet_pool_testdriver_CFLAGS = \
+ -I$(top_srcdir)/include -I$(top_srcdir)/src/compat
-I$(top_srcdir)/src/openvpn \
+ @TEST_CFLAGS@
+
+subnet_pool_testdriver_LDFLAGS = @TEST_LDFLAGS@
+
+subnet_pool_testdriver_SOURCES = test_subnet_pool.c \
+ mock_msg.c test_common.h \
+ mock_get_random.c \
+ $(top_srcdir)/src/openvpn/buffer.c \
+ $(top_srcdir)/src/openvpn/options_util.c \
+ $(top_srcdir)/src/openvpn/platform.c
+
misc_testdriver_CFLAGS = \
-I$(top_srcdir)/include -I$(top_srcdir)/src/compat
-I$(top_srcdir)/src/openvpn \
-DSOURCEDIR=\"$(top_srcdir)\" @TEST_CFLAGS@
diff --git a/tests/unit_tests/openvpn/test_subnet_pool.c
b/tests/unit_tests/openvpn/test_subnet_pool.c
new file mode 100644
index 0000000..8e73b64
--- /dev/null
+++ b/tests/unit_tests/openvpn/test_subnet_pool.c
@@ -0,0 +1,72 @@
+/*
+ * 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) 2026 OpenVPN Inc <[email protected]>
+ *
+ * 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, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include <stdlib.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "options.h"
+#include "options_util.h"
+#include "test_common.h"
+#include "mock_msg.h"
+
+/* --subnet-pool-tag resolves a client to its --subnet-pool; an unknown tag
+ * returns NULL, which is what makes the server reject that client. */
+static void
+test_subnet_pool_by_tag(void **state)
+{
+ struct subnet_pool_def c = { .next = NULL, .tag = "grpC", .network =
0x0a020300, .netmask = 0xffffff00, .gateway = 0x0a020301 };
+ struct subnet_pool_def b = { .next = &c, .tag = "grpB", .network =
0x0a020200, .netmask = 0xffffff00, .gateway = 0x0a020201 };
+ struct subnet_pool_def a = { .next = &b, .tag = "grpA", .network =
0x0a020100, .netmask = 0xffffff00, .gateway = 0x0a020101 };
+
+ /* every configured tag resolves to its own pool, wherever it sits */
+ assert_ptr_equal(subnet_pool_by_tag(&a, "grpA"), &a);
+ assert_ptr_equal(subnet_pool_by_tag(&a, "grpB"), &b);
+ assert_ptr_equal(subnet_pool_by_tag(&a, "grpC"), &c);
+
+ /* and it carries that pool's subnet/gateway */
+ const struct subnet_pool_def *r = subnet_pool_by_tag(&a, "grpB");
+ assert_int_equal(r->network, 0x0a020200);
+ assert_int_equal(r->netmask, 0xffffff00);
+ assert_int_equal(r->gateway, 0x0a020201);
+
+ /* unknown tag and empty list both miss */
+ assert_null(subnet_pool_by_tag(&a, "nope"));
+ assert_null(subnet_pool_by_tag(NULL, "grpA"));
+}
+
+const struct CMUnitTest subnet_pool_tests[] = {
+ cmocka_unit_test(test_subnet_pool_by_tag),
+};
+
+int
+main(void)
+{
+ openvpn_unit_test_setup();
+ return cmocka_run_group_tests(subnet_pool_tests, NULL, NULL);
+}
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1785?usp=email
To unsubscribe, or for help writing mail filters, visit
http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id414ce0c8f5ed5b01259590e4eaa1b19f2239362
Gerrit-Change-Number: 1785
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel