diff options
Diffstat (limited to 'src/settings/plugins/ifupdown/tests')
4 files changed, 407 insertions, 2 deletions
diff --git a/src/settings/plugins/ifupdown/tests/Makefile.am b/src/settings/plugins/ifupdown/tests/Makefile.am index aed86197..ff219d5d 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.am +++ b/src/settings/plugins/ifupdown/tests/Makefile.am @@ -29,4 +29,4 @@ endif EXTRA_DIST = \ test1 test2 test3 test4 test5 test6 test7 test8 test9 test11 test12 \ - test13 test14 test15 test16 + test13 test14 test15 test16 test17-wired-static-verify-ip4 diff --git a/src/settings/plugins/ifupdown/tests/Makefile.in b/src/settings/plugins/ifupdown/tests/Makefile.in index aca48837..a03be1bd 100644 --- a/src/settings/plugins/ifupdown/tests/Makefile.in +++ b/src/settings/plugins/ifupdown/tests/Makefile.in @@ -141,6 +141,8 @@ GIO_LIBS = @GIO_LIBS@ GLIB_CFLAGS = @GLIB_CFLAGS@ GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ GLIB_LIBS = @GLIB_LIBS@ +GLIB_MAKEFILE = @GLIB_MAKEFILE@ +GLIB_MKENUMS = @GLIB_MKENUMS@ GMODULE_CFLAGS = @GMODULE_CFLAGS@ GMODULE_LIBS = @GMODULE_LIBS@ GMSGFMT = @GMSGFMT@ @@ -195,11 +197,15 @@ LIBNL2_LIBS = @LIBNL2_LIBS@ LIBNL3_CFLAGS = @LIBNL3_CFLAGS@ LIBNL3_LIBS = @LIBNL3_LIBS@ LIBNL_CFLAGS = @LIBNL_CFLAGS@ +LIBNL_GENL3_CFLAGS = @LIBNL_GENL3_CFLAGS@ +LIBNL_GENL3_LIBS = @LIBNL_GENL3_LIBS@ LIBNL_LIBS = @LIBNL_LIBS@ LIBNL_ROUTE3_CFLAGS = @LIBNL_ROUTE3_CFLAGS@ LIBNL_ROUTE3_LIBS = @LIBNL_ROUTE3_LIBS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ +LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@ +LIBSOUP_LIBS = @LIBSOUP_LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ @@ -210,6 +216,7 @@ MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MOC = @MOC@ MSGFMT = @MSGFMT@ MSGFMT_015 = @MSGFMT_015@ MSGMERGE = @MSGMERGE@ @@ -249,6 +256,8 @@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ +SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ +SYSTEMD_LIBS = @SYSTEMD_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ UDEV_BASE_DIR = @UDEV_BASE_DIR@ USE_NLS = @USE_NLS@ @@ -334,7 +343,7 @@ test_ifupdown_LDADD = \ EXTRA_DIST = \ test1 test2 test3 test4 test5 test6 test7 test8 test9 test11 test12 \ - test13 test14 test15 test16 + test13 test14 test15 test16 test17-wired-static-verify-ip4 all: all-am diff --git a/src/settings/plugins/ifupdown/tests/test-ifupdown.c b/src/settings/plugins/ifupdown/tests/test-ifupdown.c index 16465364..01020bdf 100644 --- a/src/settings/plugins/ifupdown/tests/test-ifupdown.c +++ b/src/settings/plugins/ifupdown/tests/test-ifupdown.c @@ -21,6 +21,9 @@ #include <glib.h> #include <string.h> +#include <nm-utils.h> + +#include "nm-test-helpers.h" #include "interface_parser.h" #include "parser.h" @@ -455,6 +458,386 @@ test16_missing_newline (const char *path) ifparser_destroy (); expected_free (e); } +static void +test17_read_static_ipv4 (const char *path) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIP4Config *s_ip4; + NMSettingWired *s_wired; + char *unmanaged = NULL; + GError *error = NULL; + const char* tmp; + const char *expected_address = "10.0.0.3"; + const char *expected_id = "Ifupdown (eth0)"; + const char *expected_dns1 = "10.0.0.1"; + const char *expected_dns2 = "10.0.0.2"; + const char *expected_search1 = "example.com"; + const char *expected_search2 = "foo.example.com"; + guint32 expected_prefix = 8; + NMIP4Address *ip4_addr; + struct in_addr addr; +#define TEST17_NAME "wired-static-verify-ip4" + if_block *block = NULL; + + const char* file = "test17-" TEST17_NAME; + + init_ifparser_with_file (path, file); + block = ifparser_getfirst (); + connection = nm_connection_new(); + ifupdown_update_connection_from_if_block(connection, block, &error); + + ASSERT (connection != NULL, + TEST17_NAME, "failed to read %s: %s", file, error->message); + + ASSERT (nm_connection_verify (connection, &error), + TEST17_NAME, "failed to verify %s: %s", file, error->message); + + ASSERT (unmanaged == NULL, + TEST17_NAME, "failed to verify %s: unexpected unmanaged value", file); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection (connection); + ASSERT (s_con != NULL, + TEST17_NAME, "failed to verify %s: missing %s setting", + file, + NM_SETTING_CONNECTION_SETTING_NAME); + + /* ID */ + tmp = nm_setting_connection_get_id (s_con); + ASSERT (tmp != NULL, + TEST17_NAME, "failed to verify %s: missing %s / %s key", + file, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_ID); + ASSERT (strcmp (tmp, expected_id) == 0, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value: %s", + file, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_ID, tmp); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired (connection); + ASSERT (s_wired != NULL, + TEST17_NAME, "failed to verify %s: missing %s setting", + file, + NM_SETTING_WIRED_SETTING_NAME); + + /* ===== IPv4 SETTING ===== */ + + ASSERT (inet_pton (AF_INET, expected_address, &addr) > 0, + TEST17_NAME, "failed to verify %s: couldn't convert IP address #1", + file); + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + ASSERT (s_ip4 != NULL, + TEST17_NAME, "failed to verify %s: missing %s setting", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME); + + /* Method */ + tmp = nm_setting_ip4_config_get_method (s_ip4); + ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_METHOD); + + /* IP addresses */ + ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_ADDRESSES); + + ip4_addr = nm_setting_ip4_config_get_address (s_ip4, 0); + ASSERT (ip4_addr, + TEST17_NAME, "failed to verify %s: missing IP4 address #1", + file); + + ASSERT (nm_ip4_address_get_prefix (ip4_addr) == expected_prefix, + TEST17_NAME, "failed to verify %s: unexpected IP4 address prefix", + file); + + ASSERT (nm_ip4_address_get_address (ip4_addr) == addr.s_addr, + TEST17_NAME, "failed to verify %s: unexpected IP4 address: %s", + file, addr.s_addr); + + /* DNS Addresses */ + ASSERT (nm_setting_ip4_config_get_num_dns (s_ip4) == 2, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + ASSERT (inet_pton (AF_INET, expected_dns1, &addr) > 0, + TEST17_NAME, "failed to verify %s: couldn't convert DNS IP address #1", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 0) == addr.s_addr, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #1", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + ASSERT (inet_pton (AF_INET, expected_dns2, &addr) > 0, + TEST17_NAME, "failed to verify %s: couldn't convert DNS IP address #2", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + ASSERT (nm_setting_ip4_config_get_dns (s_ip4, 1) == addr.s_addr, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value #2", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + ASSERT (nm_setting_ip4_config_get_num_addresses (s_ip4) == 1, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + /* DNS search domains */ + ASSERT (nm_setting_ip4_config_get_num_dns_searches (s_ip4) == 2, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS); + + tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 0); + ASSERT (tmp != NULL, + TEST17_NAME, "failed to verify %s: missing %s / %s key", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS_SEARCH); + ASSERT (strcmp (tmp, expected_search1) == 0, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS_SEARCH); + + tmp = nm_setting_ip4_config_get_dns_search (s_ip4, 1); + ASSERT (tmp != NULL, + TEST17_NAME, "failed to verify %s: missing %s / %s key", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS_SEARCH); + + ASSERT (strcmp (tmp, expected_search2) == 0, + TEST17_NAME, "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP4_CONFIG_SETTING_NAME, + NM_SETTING_IP4_CONFIG_DNS_SEARCH); + + g_object_unref (connection); +} + +static void +test18_read_static_ipv6 (const char *path) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingIP6Config *s_ip6; + NMSettingWired *s_wired; + char *unmanaged = NULL; + GError *error = NULL; + const char* tmp; + const char *expected_address = "fc00::1"; + const char *expected_id = "Ifupdown (myip6tunnel)"; + const char *expected_dns1 = "fc00::2"; + const char *expected_dns2 = "fc00::3"; + const char *expected_search1 = "example.com"; + const char *expected_search2 = "foo.example.com"; + guint32 expected_prefix = 64; + NMIP6Address *ip6_addr; + struct in6_addr addr; + if_block *block = NULL; +#define TEST18_NAME "wired-static-verify-ip6" + const char* file = "test18-" TEST18_NAME; + + init_ifparser_with_file (path, file); + block = ifparser_getfirst (); + connection = nm_connection_new(); + ifupdown_update_connection_from_if_block(connection, block, &error); + + ASSERT (connection != NULL, + TEST18_NAME + "failed to read %s: %s", file, error->message); + + ASSERT (nm_connection_verify (connection, &error), + TEST18_NAME, + "failed to verify %s: %s", file, error->message); + + ASSERT (unmanaged == NULL, + TEST18_NAME, + "failed to verify %s: unexpected unmanaged value", file); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection (connection); + ASSERT (s_con != NULL, + TEST18_NAME, "failed to verify %s: missing %s setting", + file, + NM_SETTING_CONNECTION_SETTING_NAME); + + /* ID */ + tmp = nm_setting_connection_get_id (s_con); + ASSERT (tmp != NULL, + TEST18_NAME, + "failed to verify %s: missing %s / %s key", + file, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_ID); + + ASSERT (strcmp (tmp, expected_id) == 0, + TEST18_NAME, + "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_CONNECTION_SETTING_NAME, + NM_SETTING_CONNECTION_ID); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired (connection); + ASSERT (s_wired != NULL, + TEST18_NAME, "failed to verify %s: missing %s setting", + file, + NM_SETTING_WIRED_SETTING_NAME); + + /* ===== IPv6 SETTING ===== */ + + ASSERT (inet_pton (AF_INET6, expected_address, &addr) > 0, + TEST18_NAME, + "failed to verify %s: couldn't convert IP address #1", + file); + + s_ip6 = nm_connection_get_setting_ip6_config (connection); + ASSERT (s_ip6 != NULL, + TEST18_NAME, + "failed to verify %s: missing %s setting", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME); + + /* Method */ + tmp = nm_setting_ip6_config_get_method (s_ip6); + ASSERT (strcmp (tmp, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0, + TEST18_NAME, + "failed to verify %s: unexpected %s / %s key value", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_METHOD); + + /* IP addresses */ + ASSERT (nm_setting_ip6_config_get_num_addresses (s_ip6) == 1, + TEST18_NAME, + "failed to verify %s: unexpected number of %s / %s", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_ADDRESSES); + + ip6_addr = nm_setting_ip6_config_get_address (s_ip6, 0); + ASSERT (ip6_addr, + TEST18_NAME, + "failed to verify %s: missing %s / %s #1", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_ADDRESSES); + + ASSERT (nm_ip6_address_get_prefix (ip6_addr) == expected_prefix, + TEST18_NAME + "failed to verify %s: unexpected %s / %s prefix", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_ADDRESSES); + + ASSERT (IN6_ARE_ADDR_EQUAL (nm_ip6_address_get_address (ip6_addr), + &addr), + TEST18_NAME, + "failed to verify %s: unexpected %s / %s", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_ADDRESSES); + + /* DNS Addresses */ + ASSERT (nm_setting_ip6_config_get_num_dns (s_ip6) == 2, + TEST18_NAME, + "failed to verify %s: unexpected number of %s / %s values", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS); + + ASSERT (inet_pton (AF_INET6, expected_dns1, &addr) > 0, + TEST18_NAME, + "failed to verify %s: couldn't convert DNS IP address #1", + file); + + ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 0), + &addr), + TEST18_NAME, + "failed to verify %s: unexpected %s / %s #1", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS); + + ASSERT (inet_pton (AF_INET6, expected_dns2, &addr) > 0, + TEST18_NAME, + "failed to verify %s: couldn't convert DNS IP address #2", + file); + + ASSERT (IN6_ARE_ADDR_EQUAL (nm_setting_ip6_config_get_dns (s_ip6, 1), + &addr), + TEST18_NAME, "failed to verify %s: unexpected %s / %s #2", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS); + + /* DNS search domains */ + ASSERT (nm_setting_ip6_config_get_num_dns_searches (s_ip6) == 2, + TEST18_NAME, + "failed to verify %s: unexpected number of %s / %s values", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS_SEARCH); + + tmp = nm_setting_ip6_config_get_dns_search (s_ip6, 0); + ASSERT (tmp != NULL, + "wired-ipv6-manual-verify-ip6", + "failed to verify %s: missing %s / %s #1", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS_SEARCH); + + ASSERT (strcmp (tmp, expected_search1) == 0, + "wired-ipv6-manual-verify-ip6", + "failed to verify %s: unexpected %s / %s #1", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS_SEARCH); + + tmp = nm_setting_ip6_config_get_dns_search (s_ip6, 1); + ASSERT (tmp != NULL, + TEST18_NAME, + "failed to verify %s: missing %s / %s #2", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS_SEARCH); + + ASSERT (strcmp (tmp, expected_search2) == 0, + TEST18_NAME, + "failed to verify %s: unexpected %s / %s #2", + file, + NM_SETTING_IP6_CONFIG_SETTING_NAME, + NM_SETTING_IP6_CONFIG_DNS_SEARCH); + + g_free (unmanaged); + g_object_unref (connection); +} + #if GLIB_CHECK_VERSION(2,25,12) typedef GTestFixtureFunc TCFunc; @@ -467,6 +850,12 @@ typedef void (*TCFunc)(void); int main (int argc, char **argv) { GTestSuite *suite; + GError *error = NULL; + + g_type_init (); + + if (!nm_utils_init (&error)) + FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message); g_test_init (&argc, &argv, NULL); @@ -490,6 +879,8 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test14_mixed_whitespace_block_start, TEST_ENI_DIR)); g_test_suite_add (suite, TESTCASE (test15_trailing_space, TEST_ENI_DIR)); g_test_suite_add (suite, TESTCASE (test16_missing_newline, TEST_ENI_DIR)); + g_test_suite_add (suite, TESTCASE (test17_read_static_ipv4, TEST_ENI_DIR)); + g_test_suite_add (suite, TESTCASE (test18_read_static_ipv6, TEST_ENI_DIR)); return g_test_run (); } diff --git a/src/settings/plugins/ifupdown/tests/test17-wired-static-verify-ip4 b/src/settings/plugins/ifupdown/tests/test17-wired-static-verify-ip4 new file mode 100644 index 00000000..9e5243a7 --- /dev/null +++ b/src/settings/plugins/ifupdown/tests/test17-wired-static-verify-ip4 @@ -0,0 +1,5 @@ +iface eth0 inet static + address 10.0.0.3 + netmask 255.0.0.0 + dns-search example.com foo.example.com + dns-nameservers 10.0.0.1 10.0.0.2 |