summary refs log tree commit diff
path: root/callouts/tests
diff options
context:
space:
mode:
Diffstat (limited to 'callouts/tests')
-rw-r--r--callouts/tests/Makefile.am2
-rw-r--r--callouts/tests/Makefile.in16
-rw-r--r--callouts/tests/dispatcher-connectivity-full23
-rw-r--r--callouts/tests/dispatcher-connectivity-unknown22
-rw-r--r--callouts/tests/test-dispatcher-envp.c73
5 files changed, 95 insertions, 41 deletions
diff --git a/callouts/tests/Makefile.am b/callouts/tests/Makefile.am
index 6ac15874..2450f372 100644
--- a/callouts/tests/Makefile.am
+++ b/callouts/tests/Makefile.am
@@ -32,6 +32,8 @@ TESTS = test-dispatcher-envp
 endif
 
 EXTRA_DIST= \
+	dispatcher-connectivity-full \
+	dispatcher-connectivity-unknown \
 	dispatcher-down \
 	dispatcher-external \
 	dispatcher-up \
diff --git a/callouts/tests/Makefile.in b/callouts/tests/Makefile.in
index a4a80afb..9f79b951 100644
--- a/callouts/tests/Makefile.in
+++ b/callouts/tests/Makefile.in
@@ -92,8 +92,9 @@ host_triplet = @host@
 @ENABLE_TESTS_TRUE@TESTS = test-dispatcher-envp$(EXEEXT)
 subdir = callouts/tests
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \
-	$(top_srcdir)/m4/compiler_warnings.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \
+	$(top_srcdir)/m4/ax_lib_readline.m4 \
+	$(top_srcdir)/m4/compiler_options.m4 \
 	$(top_srcdir)/m4/gettext.m4 \
 	$(top_srcdir)/m4/gnome-code-coverage.m4 \
 	$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \
@@ -427,6 +428,7 @@ DHCLIENT_PATH = @DHCLIENT_PATH@
 DHCPCD_PATH = @DHCPCD_PATH@
 DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@
 DLLTOOL = @DLLTOOL@
+DL_LIBS = @DL_LIBS@
 DNSMASQ_PATH = @DNSMASQ_PATH@
 DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@
 DSYMUTIL = @DSYMUTIL@
@@ -483,13 +485,14 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@
 INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@
 INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@
 IPTABLES_PATH = @IPTABLES_PATH@
+JANSSON_CFLAGS = @JANSSON_CFLAGS@
+JANSSON_LIBS = @JANSSON_LIBS@
 KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@
 LCOV = @LCOV@
 LD = @LD@
 LDFLAGS = @LDFLAGS@
 LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@
 LIBAUDIT_LIBS = @LIBAUDIT_LIBS@
-LIBDL = @LIBDL@
 LIBICONV = @LIBICONV@
 LIBINTL = @LIBINTL@
 LIBM = @LIBM@
@@ -501,6 +504,8 @@ LIBOBJS = @LIBOBJS@
 LIBS = @LIBS@
 LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@
 LIBSOUP_LIBS = @LIBSOUP_LIBS@
+LIBSYSTEMD_CFLAGS = @LIBSYSTEMD_CFLAGS@
+LIBSYSTEMD_LIBS = @LIBSYSTEMD_LIBS@
 LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@
 LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@
 LIBTOOL = @LIBTOOL@
@@ -561,6 +566,8 @@ QT_CFLAGS = @QT_CFLAGS@
 QT_LIBS = @QT_LIBS@
 RANLIB = @RANLIB@
 READLINE_LIBS = @READLINE_LIBS@
+SANITIZERS = @SANITIZERS@
+SANITIZER_ENV = @SANITIZER_ENV@
 SED = @SED@
 SELINUX_CFLAGS = @SELINUX_CFLAGS@
 SELINUX_LIBS = @SELINUX_LIBS@
@@ -596,6 +603,7 @@ ac_ct_AR = @ac_ct_AR@
 ac_ct_CC = @ac_ct_CC@
 ac_ct_CXX = @ac_ct_CXX@
 ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+ac_ct_RANLIB = @ac_ct_RANLIB@
 am__include = @am__include@
 am__leading_dot = @am__leading_dot@
 am__quote = @am__quote@
@@ -679,6 +687,8 @@ with_valgrind = @with_valgrind@
 @ENABLE_TESTS_TRUE@	$(GLIB_LIBS)
 
 EXTRA_DIST = \
+	dispatcher-connectivity-full \
+	dispatcher-connectivity-unknown \
 	dispatcher-down \
 	dispatcher-external \
 	dispatcher-up \
diff --git a/callouts/tests/dispatcher-connectivity-full b/callouts/tests/dispatcher-connectivity-full
new file mode 100644
index 00000000..c370bc35
--- /dev/null
+++ b/callouts/tests/dispatcher-connectivity-full
@@ -0,0 +1,23 @@
+[main]
+action=connectiviy-change
+expected-iface=wlan0
+uuid=3fd2a33a-d81b-423f-ae99-e6baba742311
+id=Random Connection
+connectivity-state=FULL
+
+[device]
+state=30
+ip-interface=wlan0
+type=2
+interface=wlan0
+path=/org/freedesktop/NetworkManager/Devices/0
+
+[env]
+PATH=
+CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
+CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
+CONNECTION_ID=Random Connection
+CONNECTION_FILENAME=/callouts/tests/dispatcher-connectivity-full
+DEVICE_IFACE=wlan0
+DEVICE_IP_IFACE=wlan0
+CONNECTIVITY_STATE=FULL
diff --git a/callouts/tests/dispatcher-connectivity-unknown b/callouts/tests/dispatcher-connectivity-unknown
new file mode 100644
index 00000000..9622d017
--- /dev/null
+++ b/callouts/tests/dispatcher-connectivity-unknown
@@ -0,0 +1,22 @@
+[main]
+action=connectiviy-change
+expected-iface=wlan0
+uuid=3fd2a33a-d81b-423f-ae99-e6baba742311
+id=Random Connection
+connectivity-state=UNKNOWN
+
+[device]
+state=30
+ip-interface=wlan0
+type=2
+interface=wlan0
+path=/org/freedesktop/NetworkManager/Devices/0
+
+[env]
+PATH=
+CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
+CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
+CONNECTION_ID=Random Connection
+CONNECTION_FILENAME=/callouts/tests/dispatcher-connectivity-unknown
+DEVICE_IFACE=wlan0
+DEVICE_IP_IFACE=wlan0
diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c
index 9cdaa3b5..8636f097 100644
--- a/callouts/tests/test-dispatcher-envp.c
+++ b/callouts/tests/test-dispatcher-envp.c
@@ -28,7 +28,7 @@
 #include "nm-dispatcher-utils.h"
 #include "nm-dispatcher-api.h"
 
-#include "nm-test-utils.h"
+#include "nm-utils/nm-test-utils.h"
 
 /*******************************************/
 
@@ -39,6 +39,7 @@ parse_main (GKeyFile *kf,
             GVariant **out_con_props,
             char **out_expected_iface,
             char **out_action,
+            char **out_connectivity_state,
             char **out_vpn_ip_iface,
             GError **error)
 {
@@ -51,6 +52,7 @@ parse_main (GKeyFile *kf,
 	if (*out_expected_iface == NULL)
 		return FALSE;
 
+	*out_connectivity_state = g_key_file_get_string (kf, "main", "connectivity-state", NULL);
 	*out_vpn_ip_iface = g_key_file_get_string (kf, "main", "vpn-ip-iface", NULL);
 
 	*out_action = g_key_file_get_string (kf, "main", "action", error);
@@ -359,6 +361,7 @@ get_dispatcher_file (const char *file,
                      GVariant **out_device_ip6_props,
                      GVariant **out_device_dhcp4_props,
                      GVariant **out_device_dhcp6_props,
+                     char **out_connectivity_state,
                      char **out_vpn_ip_iface,
                      GVariant **out_vpn_ip4_props,
                      GVariant **out_vpn_ip6_props,
@@ -379,6 +382,7 @@ get_dispatcher_file (const char *file,
 	g_assert (out_device_ip6_props && !*out_device_ip6_props);
 	g_assert (out_device_dhcp4_props && !*out_device_dhcp4_props);
 	g_assert (out_device_dhcp6_props && !*out_device_dhcp6_props);
+	g_assert (out_connectivity_state && !*out_connectivity_state);
 	g_assert (out_vpn_ip_iface && !*out_vpn_ip_iface);
 	g_assert (out_vpn_ip4_props && !*out_vpn_ip4_props);
 	g_assert (out_vpn_ip6_props && !*out_vpn_ip6_props);
@@ -396,6 +400,7 @@ get_dispatcher_file (const char *file,
 	                 out_con_props,
 	                 out_expected_iface,
 	                 out_action,
+	                 out_connectivity_state,
 	                 out_vpn_ip_iface,
 	                 error))
 		goto out;
@@ -444,25 +449,27 @@ out:
 static void
 test_generic (const char *file, const char *override_vpn_ip_iface)
 {
-	GVariant *con_dict = NULL;
-	GVariant *con_props = NULL;
-	GVariant *device_props = NULL;
-	GVariant *device_ip4_props = NULL;
-	GVariant *device_ip6_props = NULL;
-	GVariant *device_dhcp4_props = NULL;
-	GVariant *device_dhcp6_props = NULL;
-	char *vpn_ip_iface = NULL;
-	GVariant *vpn_ip4_props = NULL;
-	GVariant *vpn_ip6_props = NULL;
-	char *expected_iface = NULL;
-	char *action = NULL;
-	char *out_iface = NULL;
+	gs_unref_variant GVariant *con_dict = NULL;
+	gs_unref_variant GVariant *con_props = NULL;
+	gs_unref_variant GVariant *device_props = NULL;
+	gs_unref_variant GVariant *device_ip4_props = NULL;
+	gs_unref_variant GVariant *device_ip6_props = NULL;
+	gs_unref_variant GVariant *device_dhcp4_props = NULL;
+	gs_unref_variant GVariant *device_dhcp6_props = NULL;
+	gs_free char *connectivity_change = NULL;
+	gs_free char *vpn_ip_iface = NULL;
+	gs_unref_variant GVariant *vpn_ip4_props = NULL;
+	gs_unref_variant GVariant *vpn_ip6_props = NULL;
+	gs_free char *expected_iface = NULL;
+	gs_free char *action = NULL;
+	gs_free char *out_iface = NULL;
 	const char *error_message = NULL;
-	GHashTable *expected_env = NULL;
+	gs_unref_hashtable GHashTable *expected_env = NULL;
 	GError *error = NULL;
 	gboolean success;
 	char *p;
-	char **denv, **iter;
+	gs_strfreev char **denv = NULL;
+	char **iter;
 
 	/* Read in the test file */
 	p = g_build_filename (SRCDIR, file, NULL);
@@ -474,6 +481,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
 	                               &device_ip6_props,
 	                               &device_dhcp4_props,
 	                               &device_dhcp6_props,
+	                               &connectivity_change,
 	                               &vpn_ip_iface,
 	                               &vpn_ip4_props,
 	                               &vpn_ip6_props,
@@ -494,6 +502,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
 	                                           device_ip6_props,
 	                                           device_dhcp4_props,
 	                                           device_dhcp6_props,
+	                                           connectivity_change,
 	                                           override_vpn_ip_iface ? override_vpn_ip_iface : vpn_ip_iface,
 	                                           vpn_ip4_props,
 	                                           vpn_ip6_props,
@@ -545,28 +554,6 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
 	}
 
 	g_assert_cmpstr (expected_iface, ==, out_iface);
-
-	g_strfreev (denv);
-	g_free (out_iface);
-	g_free (vpn_ip_iface);
-	g_free (expected_iface);
-	g_free (action);
-	g_variant_unref (con_dict);
-	g_variant_unref (con_props);
-	g_variant_unref (device_props);
-	if (device_ip4_props)
-		g_variant_unref (device_ip4_props);
-	if (device_ip6_props)
-		g_variant_unref (device_ip6_props);
-	if (device_dhcp4_props)
-		g_variant_unref (device_dhcp4_props);
-	if (device_dhcp6_props)
-		g_variant_unref (device_dhcp6_props);
-	if (vpn_ip4_props)
-		g_variant_unref (vpn_ip4_props);
-	if (vpn_ip6_props)
-		g_variant_unref (vpn_ip6_props);
-	g_hash_table_destroy (expected_env);
 }
 
 /*******************************************/
@@ -602,6 +589,15 @@ test_external (void)
 }
 
 static void
+test_connectivity_changed (void)
+{
+	/* These tests will check that the CONNECTIVITY_STATE environment
+	 * variable is only defined for known states, such as 'full'. */
+	test_generic ("dispatcher-connectivity-unknown", NULL);
+	test_generic ("dispatcher-connectivity-full", NULL);
+}
+
+static void
 test_up_empty_vpn_iface (void)
 {
 	/* Test that an empty VPN iface variable, like is passed through D-Bus
@@ -624,6 +620,7 @@ main (int argc, char **argv)
 	g_test_add_func ("/dispatcher/vpn_up", test_vpn_up);
 	g_test_add_func ("/dispatcher/vpn_down", test_vpn_down);
 	g_test_add_func ("/dispatcher/external", test_external);
+	g_test_add_func ("/dispatcher/connectivity_changed", test_connectivity_changed);
 
 	g_test_add_func ("/dispatcher/up_empty_vpn_iface", test_up_empty_vpn_iface);