From: Arne Schwabe <[email protected]> This allows these mocks to be reused by other unit tests that need to include push_util.c/h functions.
Change-Id: Ic1ed693f73029f5b5609f717333fdaaabe42acbd Signed-off-by: Arne Schwabe <[email protected]> Acked-by: Frank Lichtenheld <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1853 --- 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/+/1853 This mail reflects revision 6 of this Change. Acked-by according to Gerrit (reflected above): Frank Lichtenheld <[email protected]> diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c3324d..6eb5954 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -930,6 +930,7 @@ target_sources(test_push_update_msg PRIVATE tests/unit_tests/openvpn/mock_msg.c tests/unit_tests/openvpn/mock_get_random.c + tests/unit_tests/openvpn/mock_push_dependencies.c src/openvpn/options_util.c src/openvpn/otime.c src/openvpn/list.c diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvpn/Makefile.am index 6db611e..5954902 100644 --- a/tests/unit_tests/openvpn/Makefile.am +++ b/tests/unit_tests/openvpn/Makefile.am @@ -400,6 +400,7 @@ push_update_msg_testdriver_SOURCES = test_push_update_msg.c \ mock_msg.c \ mock_get_random.c \ + mock_push_dependencies.c \ $(top_srcdir)/src/openvpn/buffer.c \ $(top_srcdir)/src/openvpn/platform.c \ $(top_srcdir)/src/openvpn/options_util.c \ diff --git a/tests/unit_tests/openvpn/mock_push_dependencies.c b/tests/unit_tests/openvpn/mock_push_dependencies.c new file mode 100644 index 0000000..112bcfd --- /dev/null +++ b/tests/unit_tests/openvpn/mock_push_dependencies.c @@ -0,0 +1,69 @@ +/* + * 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) 2002-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/>. + */ + +/* Set of mocked function/globals to get unit tests to + * compile that use the push_util.c file */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "error.h" +#include "options.h" + +void +throw_signal_soft(const int signum, const char *signal_text) +{ + msg(M_WARN, "Offending option received from server"); +} + +uint64_t +pull_permission_mask(const struct context *c) +{ + uint64_t flags = OPT_P_UP | OPT_P_ROUTE_EXTRAS | OPT_P_SOCKBUF | OPT_P_SOCKFLAGS + | OPT_P_SETENV | OPT_P_SHAPER | OPT_P_TIMER | OPT_P_COMP | OPT_P_PERSIST + | OPT_P_MESSAGES | OPT_P_EXPLICIT_NOTIFY | OPT_P_ECHO | OPT_P_PULL_MODE + | OPT_P_PEER_ID | OPT_P_NCP | OPT_P_PUSH_MTU | OPT_P_ROUTE | OPT_P_DHCPDNS; + return flags; +} + +void +unlearn_ifconfig(struct multi_context *m, struct multi_instance *mi) +{ +} + +void +unlearn_ifconfig_ipv6(struct multi_context *m, struct multi_instance *mi) +{ +} + +void +update_vhash(struct multi_context *m, struct multi_instance *mi, const char *new_ip, const char *new_ipv6) +{ +} + +bool +options_postprocess_pull(struct options *options, struct env_set *es) +{ + return true; +} diff --git a/tests/unit_tests/openvpn/test_push_update_msg.c b/tests/unit_tests/openvpn/test_push_update_msg.c index 2653749..a93f916 100644 --- a/tests/unit_tests/openvpn/test_push_update_msg.c +++ b/tests/unit_tests/openvpn/test_push_update_msg.c @@ -12,48 +12,6 @@ #include "push_util.c" -/* mocks */ - -void -throw_signal_soft(const int signum, const char *signal_text) -{ - msg(M_WARN, "Offending option received from server"); -} - -uint64_t -pull_permission_mask(const struct context *c) -{ - uint64_t flags = OPT_P_UP | OPT_P_ROUTE_EXTRAS | OPT_P_SOCKBUF | OPT_P_SOCKFLAGS - | OPT_P_SETENV | OPT_P_SHAPER | OPT_P_TIMER | OPT_P_COMP | OPT_P_PERSIST - | OPT_P_MESSAGES | OPT_P_EXPLICIT_NOTIFY | OPT_P_ECHO | OPT_P_PULL_MODE - | OPT_P_PEER_ID | OPT_P_NCP | OPT_P_PUSH_MTU | OPT_P_ROUTE | OPT_P_DHCPDNS; - return flags; -} - -void -unlearn_ifconfig(struct multi_context *m, struct multi_instance *mi) -{ - return; -} - -void -unlearn_ifconfig_ipv6(struct multi_context *m, struct multi_instance *mi) -{ - return; -} - -void -update_vhash(struct multi_context *m, struct multi_instance *mi, const char *new_ip, const char *new_ipv6) -{ - return; -} - -bool -options_postprocess_pull(struct options *options, struct env_set *es) -{ - return true; -} - /* * Counters to track route accumulation across continuation messages. * Used to verify the bug where update_options_found resets per message. _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
