[NetworkManager-openvpn] Accept all valid 'proto' arguments.
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [NetworkManager-openvpn] Accept all valid 'proto' arguments.
- Date: Fri, 23 Oct 2020 13:18:19 +0000 (UTC)
commit 667113138d3e27cb367e87090955e50885913407
Author: Katelyn Schiesser <katelyn schiesser gmail com>
Date: Sat Oct 17 23:30:54 2020 -0700
Accept all valid 'proto' arguments.
OpenVPN allows for a bunch of different args for 'proto', namely 'udp' and 'tcp'
variants that include '4' or '6', and specific to tcp, '-client' suffixes. This
was already defined in shared/util.h; this commit changes the 'proto' check to
also use the 'NMOVPN_PROTCOL_TYPES' array, and adds test for all supported protos.
https://gitlab.gnome.org/GNOME/NetworkManager-openvpn/-/issues/59
https://gitlab.gnome.org/GNOME/NetworkManager-openvpn/-/merge_requests/30
Makefile.am | 10 +-
properties/import-export.c | 13 ++-
properties/tests/conf/proto-tcp-client.ovpn | 5 +
properties/tests/conf/proto-tcp.ovpn | 5 +
properties/tests/conf/proto-tcp4-client.ovpn | 5 +
properties/tests/conf/proto-tcp4.ovpn | 5 +
properties/tests/conf/proto-tcp6-client.ovpn | 5 +
properties/tests/conf/proto-tcp6.ovpn | 5 +
properties/tests/conf/proto-udp.ovpn | 5 +
properties/tests/conf/proto-udp4.ovpn | 5 +
properties/tests/conf/proto-udp6.ovpn | 5 +
properties/tests/test-import-export.c | 136 +++++++++++++++++++++++++++
12 files changed, 196 insertions(+), 8 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 18f8f67..37748b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -320,7 +320,15 @@ EXTRA_DIST += \
properties/tests/conf/tls-inline-cert.pem \
properties/tests/conf/tls-inline-crl-verify-file.pem \
properties/tests/conf/tls-inline-key.pem \
- properties/tests/conf/tls-inline-ta.pem
+ properties/tests/conf/tls-inline-ta.pem \
+ properties/tests/conf/proto-udp.ovpn \
+ properties/tests/conf/proto-udp4.ovpn \
+ properties/tests/conf/proto-udp6.ovpn \
+ properties/tests/conf/proto-tcp.ovpn \
+ properties/tests/conf/proto-tcp4.ovpn \
+ properties/tests/conf/proto-tcp6.ovpn \
+ properties/tests/conf/proto-tcp4-client.ovpn \
+ properties/tests/conf/proto-tcp6-client.ovpn
###############################################################################
diff --git a/properties/import-export.c b/properties/import-export.c
index 8260d83..c1fe6db 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -897,18 +897,17 @@ do_import (const char *path, const char *contents, gsize contents_len, GError **
if (NM_IN_STRSET (params[0], NMV_OVPN_TAG_PROTO)) {
if (!args_params_check_nargs_n (params, 1, &line_error))
goto handle_line_error;
- /* Valid parameters are "udp", "tcp-client" and "tcp-server".
+ /* Valid parameters are defined in shared/utils.h
* 'tcp' isn't technically valid, but it used to be accepted so
* we'll handle it here anyway.
*/
- if (nm_streq (params[1], "udp")) {
- /* ignore; udp is default */
- } else if (NM_IN_STRSET (params[1], "tcp-client", "tcp-server", "tcp"))
- setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
- else {
- line_error = args_params_error_message_invalid_arg (params, 1);
+ if (!NM_IN_STRSET (params[1], NMOVPN_PROTCOL_TYPES)) {
+ line_error = g_strdup_printf (_("proto expects protocol type like “udp” or
“tcp”"));
goto handle_line_error;
}
+ if (!NM_IN_STRSET (params[1], "udp", "udp4", "udp6")) {
+ setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
+ }
continue;
}
diff --git a/properties/tests/conf/proto-tcp-client.ovpn b/properties/tests/conf/proto-tcp-client.ovpn
new file mode 100644
index 0000000..fcce845
--- /dev/null
+++ b/properties/tests/conf/proto-tcp-client.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto tcp-client
diff --git a/properties/tests/conf/proto-tcp.ovpn b/properties/tests/conf/proto-tcp.ovpn
new file mode 100644
index 0000000..e7c6977
--- /dev/null
+++ b/properties/tests/conf/proto-tcp.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto tcp
diff --git a/properties/tests/conf/proto-tcp4-client.ovpn b/properties/tests/conf/proto-tcp4-client.ovpn
new file mode 100644
index 0000000..6f5d833
--- /dev/null
+++ b/properties/tests/conf/proto-tcp4-client.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto tcp4-client
diff --git a/properties/tests/conf/proto-tcp4.ovpn b/properties/tests/conf/proto-tcp4.ovpn
new file mode 100644
index 0000000..6f8a5c0
--- /dev/null
+++ b/properties/tests/conf/proto-tcp4.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto tcp4
diff --git a/properties/tests/conf/proto-tcp6-client.ovpn b/properties/tests/conf/proto-tcp6-client.ovpn
new file mode 100644
index 0000000..aeb16df
--- /dev/null
+++ b/properties/tests/conf/proto-tcp6-client.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto tcp6-client
diff --git a/properties/tests/conf/proto-tcp6.ovpn b/properties/tests/conf/proto-tcp6.ovpn
new file mode 100644
index 0000000..454b8e3
--- /dev/null
+++ b/properties/tests/conf/proto-tcp6.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto tcp6
diff --git a/properties/tests/conf/proto-udp.ovpn b/properties/tests/conf/proto-udp.ovpn
new file mode 100644
index 0000000..c68b4c7
--- /dev/null
+++ b/properties/tests/conf/proto-udp.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto udp
diff --git a/properties/tests/conf/proto-udp4.ovpn b/properties/tests/conf/proto-udp4.ovpn
new file mode 100644
index 0000000..21d309e
--- /dev/null
+++ b/properties/tests/conf/proto-udp4.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto udp4
diff --git a/properties/tests/conf/proto-udp6.ovpn b/properties/tests/conf/proto-udp6.ovpn
new file mode 100644
index 0000000..14b1d69
--- /dev/null
+++ b/properties/tests/conf/proto-udp6.ovpn
@@ -0,0 +1,5 @@
+remote 173.8.149.245 666
+dev tun
+client
+
+proto udp6
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 367130e..260e353 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -1011,6 +1011,118 @@ test_push_peer_info_import (void)
_check_item (s_vpn, NM_OPENVPN_KEY_PUSH_PEER_INFO, "yes");
}
+static void
+test_proto_udp_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-udp.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, NULL);
+}
+
+static void
+test_proto_udp4_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-udp4.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, NULL);
+}
+
+static void
+test_proto_udp6_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-udp6.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, NULL);
+}
+
+static void
+test_proto_tcp_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-tcp.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
+}
+
+static void
+test_proto_tcp4_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-tcp4.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
+}
+
+static void
+test_proto_tcp6_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-tcp6.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
+}
+
+static void
+test_proto_tcp4_client_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-tcp4-client.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
+}
+
+static void
+test_proto_tcp6_client_import (void)
+{
+ _CREATE_PLUGIN (plugin);
+ gs_unref_object NMConnection *connection = NULL;
+ NMSettingVpn *s_vpn;
+
+ connection = get_basic_connection (plugin, SRCDIR, "proto-tcp6-client.ovpn");
+
+ s_vpn = nm_connection_get_setting_vpn (connection);
+
+ _check_item (s_vpn, NM_OPENVPN_KEY_PROTO_TCP, "yes");
+}
+
/*****************************************************************************/
static void
@@ -1199,6 +1311,30 @@ int main (int argc, char **argv)
_add_test_func_simple (test_push_peer_info_import);
_add_test_func ("push-peer-info-export", test_export_compare, "push-peer-info.ovpn",
"push-peer-info.ovpntest");
+ _add_test_func_simple (test_proto_udp_import);
+ _add_test_func ("proto-udp-export", test_export_compare, "proto-udp.ovpn", "proto-udp.ovpntest");
+
+ _add_test_func_simple (test_proto_udp4_import);
+ _add_test_func ("proto-udp4-export", test_export_compare, "proto-udp4.ovpn", "proto-udp4.ovpntest");
+
+ _add_test_func_simple (test_proto_udp6_import);
+ _add_test_func ("proto-udp6-export", test_export_compare, "proto-udp6.ovpn", "proto-udp6.ovpntest");
+
+ _add_test_func_simple (test_proto_tcp_import);
+ _add_test_func ("proto-tcp-export", test_export_compare, "proto-tcp.ovpn", "proto-tcp.ovpntest");
+
+ _add_test_func_simple (test_proto_tcp4_import);
+ _add_test_func ("proto-tcp4-export", test_export_compare, "proto-tcp4.ovpn", "proto-tcp4.ovpntest");
+
+ _add_test_func_simple (test_proto_tcp6_import);
+ _add_test_func ("proto-tcp6-export", test_export_compare, "proto-tcp6.ovpn", "proto-tcp6.ovpntest");
+
+ _add_test_func_simple (test_proto_tcp4_client_import);
+ _add_test_func ("proto-tcp4-client-export", test_export_compare, "proto-tcp4-client.ovpn",
"proto-tcp4-client.ovpntest");
+
+ _add_test_func_simple (test_proto_tcp6_client_import);
+ _add_test_func ("proto-tcp6-client-export", test_export_compare, "proto-tcp6-client.ovpn",
"proto-tcp6-client.ovpntest");
+
_add_test_func_simple (test_args_parse_line);
result = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]