summaryrefslogtreecommitdiff
path: root/libnm-util/tests
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-util/tests')
-rw-r--r--libnm-util/tests/Makefile.am28
-rw-r--r--libnm-util/tests/Makefile.in233
-rw-r--r--libnm-util/tests/certs/Makefile.am3
-rw-r--r--libnm-util/tests/certs/Makefile.in24
-rw-r--r--libnm-util/tests/certs/test-aes-key.pem30
-rw-r--r--libnm-util/tests/test-crypto.c40
-rw-r--r--libnm-util/tests/test-general.c1159
-rw-r--r--libnm-util/tests/test-secrets.c108
-rw-r--r--libnm-util/tests/test-setting-8021x.c5
-rw-r--r--libnm-util/tests/test-setting-dcb.c328
-rw-r--r--libnm-util/tests/test-settings-defaults.c8
11 files changed, 1813 insertions, 153 deletions
diff --git a/libnm-util/tests/Makefile.am b/libnm-util/tests/Makefile.am
index d49ef8c8a..6d3d225ef 100644
--- a/libnm-util/tests/Makefile.am
+++ b/libnm-util/tests/Makefile.am
@@ -7,15 +7,18 @@ AM_CPPFLAGS = \
-I$(top_builddir)/include \
-I$(top_srcdir)/libnm-util \
-I$(top_builddir)/libnm-util \
+ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
$(GLIB_CFLAGS) \
- $(DBUS_CFLAGS)
+ $(DBUS_CFLAGS) \
+ -DTEST_CERT_DIR=\"$(top_srcdir)/libnm-util/tests/certs/\"
noinst_PROGRAMS = \
test-settings-defaults \
test-crypto \
test-secrets \
test-general \
- test-setting-8021x
+ test-setting-8021x \
+ test-setting-dcb
test_settings_defaults_SOURCES = \
test-settings-defaults.c
@@ -36,10 +39,6 @@ test_crypto_LDADD = \
test_secrets_SOURCES = \
test-secrets.c
-test_secrets_CPPFLAGS = \
- -DTEST_CERT_DIR=\"$(top_srcdir)/libnm-util/tests/certs/\" \
- $(AM_CPPFLAGS)
-
test_secrets_LDADD = \
$(top_builddir)/libnm-util/libnm-util.la \
$(GLIB_LIBS) \
@@ -61,11 +60,15 @@ test_setting_8021x_LDADD = \
$(GLIB_LIBS) \
$(DBUS_LIBS)
-check-local: test-settings-defaults test-crypto test-secrets
- $(abs_builddir)/test-settings-defaults
- $(abs_builddir)/test-secrets
- $(abs_builddir)/test-general
+test_setting_dcb_SOURCES = \
+ test-setting-dcb.c
+test_setting_dcb_LDADD = \
+ $(top_builddir)/libnm-util/libnm-util.la \
+ $(GLIB_LIBS) \
+ $(DBUS_LIBS)
+
+check-local: test-crypto test-setting-8021x
# Private key and CA certificate in the same file (PEM)
$(abs_builddir)/test-setting-8021x $(srcdir)/certs/test_key_and_cert.pem "test"
@@ -122,4 +125,9 @@ check-local: test-settings-defaults test-crypto test-secrets
$(srcdir)/certs/pkcs8-enc-key.pem \
"1234567890"
+# Private key with AES cipher
+ $(abs_builddir)/test-crypto --key $(srcdir)/certs/test-aes-key.pem "test-aes-password"
+
+TESTS = test-settings-defaults test-secrets test-general test-setting-dcb
+
endif
diff --git a/libnm-util/tests/Makefile.in b/libnm-util/tests/Makefile.in
index 662c31611..de57f25a5 100644
--- a/libnm-util/tests/Makefile.in
+++ b/libnm-util/tests/Makefile.in
@@ -81,12 +81,17 @@ host_triplet = @host@
@ENABLE_TESTS_TRUE@noinst_PROGRAMS = test-settings-defaults$(EXEEXT) \
@ENABLE_TESTS_TRUE@ test-crypto$(EXEEXT) test-secrets$(EXEEXT) \
@ENABLE_TESTS_TRUE@ test-general$(EXEEXT) \
-@ENABLE_TESTS_TRUE@ test-setting-8021x$(EXEEXT)
+@ENABLE_TESTS_TRUE@ test-setting-8021x$(EXEEXT) \
+@ENABLE_TESTS_TRUE@ test-setting-dcb$(EXEEXT)
+@ENABLE_TESTS_TRUE@TESTS = test-settings-defaults$(EXEEXT) \
+@ENABLE_TESTS_TRUE@ test-secrets$(EXEEXT) test-general$(EXEEXT) \
+@ENABLE_TESTS_TRUE@ test-setting-dcb$(EXEEXT)
subdir = libnm-util/tests
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(top_srcdir)/build-aux/depcomp
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \
+ $(top_srcdir)/m4/compiler_warnings.m4 \
$(top_srcdir)/m4/gettext.m4 \
$(top_srcdir)/m4/gnome-code-coverage.m4 \
$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \
@@ -123,8 +128,7 @@ test_general_OBJECTS = $(am_test_general_OBJECTS)
@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \
@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am__test_secrets_SOURCES_DIST = test-secrets.c
-@ENABLE_TESTS_TRUE@am_test_secrets_OBJECTS = \
-@ENABLE_TESTS_TRUE@ test_secrets-test-secrets.$(OBJEXT)
+@ENABLE_TESTS_TRUE@am_test_secrets_OBJECTS = test-secrets.$(OBJEXT)
test_secrets_OBJECTS = $(am_test_secrets_OBJECTS)
@ENABLE_TESTS_TRUE@test_secrets_DEPENDENCIES = \
@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \
@@ -136,6 +140,13 @@ test_setting_8021x_OBJECTS = $(am_test_setting_8021x_OBJECTS)
@ENABLE_TESTS_TRUE@test_setting_8021x_DEPENDENCIES = \
@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \
@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
+am__test_setting_dcb_SOURCES_DIST = test-setting-dcb.c
+@ENABLE_TESTS_TRUE@am_test_setting_dcb_OBJECTS = \
+@ENABLE_TESTS_TRUE@ test-setting-dcb.$(OBJEXT)
+test_setting_dcb_OBJECTS = $(am_test_setting_dcb_OBJECTS)
+@ENABLE_TESTS_TRUE@test_setting_dcb_DEPENDENCIES = \
+@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \
+@ENABLE_TESTS_TRUE@ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
am__test_settings_defaults_SOURCES_DIST = test-settings-defaults.c
@ENABLE_TESTS_TRUE@am_test_settings_defaults_OBJECTS = \
@ENABLE_TESTS_TRUE@ test-settings-defaults.$(OBJEXT)
@@ -179,11 +190,12 @@ am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(test_crypto_SOURCES) $(test_general_SOURCES) \
$(test_secrets_SOURCES) $(test_setting_8021x_SOURCES) \
- $(test_settings_defaults_SOURCES)
+ $(test_setting_dcb_SOURCES) $(test_settings_defaults_SOURCES)
DIST_SOURCES = $(am__test_crypto_SOURCES_DIST) \
$(am__test_general_SOURCES_DIST) \
$(am__test_secrets_SOURCES_DIST) \
$(am__test_setting_8021x_SOURCES_DIST) \
+ $(am__test_setting_dcb_SOURCES_DIST) \
$(am__test_settings_defaults_SOURCES_DIST)
RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
ctags-recursive dvi-recursive html-recursive info-recursive \
@@ -225,6 +237,28 @@ am__define_uniq_tagged_files = \
done | $(am__uniquify_input)`
ETAGS = etags
CTAGS = ctags
+am__tty_colors_dummy = \
+ mgn= red= grn= lgn= blu= brg= std=; \
+ am__color_tests=no
+am__tty_colors = { \
+ $(am__tty_colors_dummy); \
+ if test "X$(AM_COLOR_TESTS)" = Xno; then \
+ am__color_tests=no; \
+ elif test "X$(AM_COLOR_TESTS)" = Xalways; then \
+ am__color_tests=yes; \
+ elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \
+ am__color_tests=yes; \
+ fi; \
+ if test $$am__color_tests = yes; then \
+ red=''; \
+ grn=''; \
+ lgn=''; \
+ blu=''; \
+ mgn=''; \
+ brg=''; \
+ std=''; \
+ fi; \
+}
DIST_SUBDIRS = certs
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
am__relativize = \
@@ -277,12 +311,15 @@ CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DATADIRNAME = @DATADIRNAME@
DBUS_CFLAGS = @DBUS_CFLAGS@
+DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@
+DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@
DBUS_LIBS = @DBUS_LIBS@
DBUS_SYS_DIR = @DBUS_SYS_DIR@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DHCLIENT_PATH = @DHCLIENT_PATH@
DHCPCD_PATH = @DHCPCD_PATH@
+DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@
DLLTOOL = @DLLTOOL@
DNSMASQ_PATH = @DNSMASQ_PATH@
DSYMUTIL = @DSYMUTIL@
@@ -307,7 +344,6 @@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@
GNUTLS_LIBS = @GNUTLS_LIBS@
GREP = @GREP@
GTKDOC_CHECK = @GTKDOC_CHECK@
-GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@
GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
GTKDOC_MKPDF = @GTKDOC_MKPDF@
@@ -352,12 +388,16 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBM = @LIBM@
+LIBNDP_CFLAGS = @LIBNDP_CFLAGS@
+LIBNDP_LIBS = @LIBNDP_LIBS@
LIBNL_CFLAGS = @LIBNL_CFLAGS@
LIBNL_LIBS = @LIBNL_LIBS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@
LIBSOUP_LIBS = @LIBSOUP_LIBS@
+LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@
+LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
@@ -374,6 +414,8 @@ MOC = @MOC@
MSGFMT = @MSGFMT@
MSGFMT_015 = @MSGFMT_015@
MSGMERGE = @MSGMERGE@
+NEWT_CFLAGS = @NEWT_CFLAGS@
+NEWT_LIBS = @NEWT_LIBS@
NM = @NM@
NMEDIT = @NMEDIT@
NM_MAJOR_VERSION = @NM_MAJOR_VERSION@
@@ -401,11 +443,16 @@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
POLKIT_CFLAGS = @POLKIT_CFLAGS@
POLKIT_LIBS = @POLKIT_LIBS@
POSUB = @POSUB@
+PPPD_PATH = @PPPD_PATH@
PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@
+PPPOE_PATH = @PPPOE_PATH@
QT_CFLAGS = @QT_CFLAGS@
QT_LIBS = @QT_LIBS@
RANLIB = @RANLIB@
+READLINE_LIBS = @READLINE_LIBS@
SED = @SED@
+SELINUX_CFLAGS = @SELINUX_CFLAGS@
+SELINUX_LIBS = @SELINUX_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
@@ -420,6 +467,7 @@ UDEV_BASE_DIR = @UDEV_BASE_DIR@
USE_NLS = @USE_NLS@
UUID_CFLAGS = @UUID_CFLAGS@
UUID_LIBS = @UUID_LIBS@
+VALGRIND_RULES = @VALGRIND_RULES@
VAPIGEN = @VAPIGEN@
VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@
VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@
@@ -482,6 +530,7 @@ psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
+subdirs = @subdirs@
sysconfdir = @sysconfdir@
systemdsystemunitdir = @systemdsystemunitdir@
target_alias = @target_alias@
@@ -492,14 +541,17 @@ with_dhclient = @with_dhclient@
with_dhcpcd = @with_dhcpcd@
with_netconfig = @with_netconfig@
with_resolvconf = @with_resolvconf@
+with_valgrind = @with_valgrind@
@ENABLE_TESTS_TRUE@SUBDIRS = certs
@ENABLE_TESTS_TRUE@AM_CPPFLAGS = \
@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/include \
@ENABLE_TESTS_TRUE@ -I$(top_builddir)/include \
@ENABLE_TESTS_TRUE@ -I$(top_srcdir)/libnm-util \
@ENABLE_TESTS_TRUE@ -I$(top_builddir)/libnm-util \
+@ENABLE_TESTS_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
@ENABLE_TESTS_TRUE@ $(GLIB_CFLAGS) \
-@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS)
+@ENABLE_TESTS_TRUE@ $(DBUS_CFLAGS) \
+@ENABLE_TESTS_TRUE@ -DTEST_CERT_DIR=\"$(top_srcdir)/libnm-util/tests/certs/\"
@ENABLE_TESTS_TRUE@test_settings_defaults_SOURCES = \
@ENABLE_TESTS_TRUE@ test-settings-defaults.c
@@ -520,10 +572,6 @@ with_resolvconf = @with_resolvconf@
@ENABLE_TESTS_TRUE@test_secrets_SOURCES = \
@ENABLE_TESTS_TRUE@ test-secrets.c
-@ENABLE_TESTS_TRUE@test_secrets_CPPFLAGS = \
-@ENABLE_TESTS_TRUE@ -DTEST_CERT_DIR=\"$(top_srcdir)/libnm-util/tests/certs/\" \
-@ENABLE_TESTS_TRUE@ $(AM_CPPFLAGS)
-
@ENABLE_TESTS_TRUE@test_secrets_LDADD = \
@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \
@ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \
@@ -545,6 +593,14 @@ with_resolvconf = @with_resolvconf@
@ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \
@ENABLE_TESTS_TRUE@ $(DBUS_LIBS)
+@ENABLE_TESTS_TRUE@test_setting_dcb_SOURCES = \
+@ENABLE_TESTS_TRUE@ test-setting-dcb.c
+
+@ENABLE_TESTS_TRUE@test_setting_dcb_LDADD = \
+@ENABLE_TESTS_TRUE@ $(top_builddir)/libnm-util/libnm-util.la \
+@ENABLE_TESTS_TRUE@ $(GLIB_LIBS) \
+@ENABLE_TESTS_TRUE@ $(DBUS_LIBS)
+
all: all-recursive
.SUFFIXES:
@@ -605,6 +661,10 @@ test-setting-8021x$(EXEEXT): $(test_setting_8021x_OBJECTS) $(test_setting_8021x_
@rm -f test-setting-8021x$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_setting_8021x_OBJECTS) $(test_setting_8021x_LDADD) $(LIBS)
+test-setting-dcb$(EXEEXT): $(test_setting_dcb_OBJECTS) $(test_setting_dcb_DEPENDENCIES) $(EXTRA_test_setting_dcb_DEPENDENCIES)
+ @rm -f test-setting-dcb$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(test_setting_dcb_OBJECTS) $(test_setting_dcb_LDADD) $(LIBS)
+
test-settings-defaults$(EXEEXT): $(test_settings_defaults_OBJECTS) $(test_settings_defaults_DEPENDENCIES) $(EXTRA_test_settings_defaults_DEPENDENCIES)
@rm -f test-settings-defaults$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_settings_defaults_OBJECTS) $(test_settings_defaults_LDADD) $(LIBS)
@@ -617,9 +677,10 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-crypto.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-general.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-secrets.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-setting-8021x.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-setting-dcb.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-settings-defaults.Po@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_secrets-test-secrets.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -642,20 +703,6 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
-test_secrets-test-secrets.o: test-secrets.c
-@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_secrets_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_secrets-test-secrets.o -MD -MP -MF $(DEPDIR)/test_secrets-test-secrets.Tpo -c -o test_secrets-test-secrets.o `test -f 'test-secrets.c' || echo '$(srcdir)/'`test-secrets.c
-@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_secrets-test-secrets.Tpo $(DEPDIR)/test_secrets-test-secrets.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test-secrets.c' object='test_secrets-test-secrets.o' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_secrets_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_secrets-test-secrets.o `test -f 'test-secrets.c' || echo '$(srcdir)/'`test-secrets.c
-
-test_secrets-test-secrets.obj: test-secrets.c
-@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_secrets_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT test_secrets-test-secrets.obj -MD -MP -MF $(DEPDIR)/test_secrets-test-secrets.Tpo -c -o test_secrets-test-secrets.obj `if test -f 'test-secrets.c'; then $(CYGPATH_W) 'test-secrets.c'; else $(CYGPATH_W) '$(srcdir)/test-secrets.c'; fi`
-@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/test_secrets-test-secrets.Tpo $(DEPDIR)/test_secrets-test-secrets.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test-secrets.c' object='test_secrets-test-secrets.obj' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(test_secrets_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o test_secrets-test-secrets.obj `if test -f 'test-secrets.c'; then $(CYGPATH_W) 'test-secrets.c'; else $(CYGPATH_W) '$(srcdir)/test-secrets.c'; fi`
-
mostlyclean-libtool:
-rm -f *.lo
@@ -761,6 +808,99 @@ cscopelist-am: $(am__tagged_files)
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+check-TESTS: $(TESTS)
+ @failed=0; all=0; xfail=0; xpass=0; skip=0; \
+ srcdir=$(srcdir); export srcdir; \
+ list=' $(TESTS) '; \
+ $(am__tty_colors); \
+ if test -n "$$list"; then \
+ for tst in $$list; do \
+ if test -f ./$$tst; then dir=./; \
+ elif test -f $$tst; then dir=; \
+ else dir="$(srcdir)/"; fi; \
+ if $(TESTS_ENVIRONMENT) $${dir}$$tst $(AM_TESTS_FD_REDIRECT); then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xpass=`expr $$xpass + 1`; \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=XPASS; \
+ ;; \
+ *) \
+ col=$$grn; res=PASS; \
+ ;; \
+ esac; \
+ elif test $$? -ne 77; then \
+ all=`expr $$all + 1`; \
+ case " $(XFAIL_TESTS) " in \
+ *[\ \ ]$$tst[\ \ ]*) \
+ xfail=`expr $$xfail + 1`; \
+ col=$$lgn; res=XFAIL; \
+ ;; \
+ *) \
+ failed=`expr $$failed + 1`; \
+ col=$$red; res=FAIL; \
+ ;; \
+ esac; \
+ else \
+ skip=`expr $$skip + 1`; \
+ col=$$blu; res=SKIP; \
+ fi; \
+ echo "$${col}$$res$${std}: $$tst"; \
+ done; \
+ if test "$$all" -eq 1; then \
+ tests="test"; \
+ All=""; \
+ else \
+ tests="tests"; \
+ All="All "; \
+ fi; \
+ if test "$$failed" -eq 0; then \
+ if test "$$xfail" -eq 0; then \
+ banner="$$All$$all $$tests passed"; \
+ else \
+ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \
+ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \
+ fi; \
+ else \
+ if test "$$xpass" -eq 0; then \
+ banner="$$failed of $$all $$tests failed"; \
+ else \
+ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \
+ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \
+ fi; \
+ fi; \
+ dashes="$$banner"; \
+ skipped=""; \
+ if test "$$skip" -ne 0; then \
+ if test "$$skip" -eq 1; then \
+ skipped="($$skip test was not run)"; \
+ else \
+ skipped="($$skip tests were not run)"; \
+ fi; \
+ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$skipped"; \
+ fi; \
+ report=""; \
+ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \
+ report="Please report to $(PACKAGE_BUGREPORT)"; \
+ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \
+ dashes="$$report"; \
+ fi; \
+ dashes=`echo "$$dashes" | sed s/./=/g`; \
+ if test "$$failed" -eq 0; then \
+ col="$$grn"; \
+ else \
+ col="$$red"; \
+ fi; \
+ echo "$${col}$$dashes$${std}"; \
+ echo "$${col}$$banner$${std}"; \
+ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \
+ test -z "$$report" || echo "$${col}$$report$${std}"; \
+ echo "$${col}$$dashes$${std}"; \
+ test "$$failed" -eq 0; \
+ else :; fi
+
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
@@ -818,7 +958,7 @@ distdir: $(DISTFILES)
done
@ENABLE_TESTS_FALSE@check-local:
check-am: all-am
- $(MAKE) $(AM_MAKEFLAGS) check-local
+ $(MAKE) $(AM_MAKEFLAGS) check-TESTS check-local
check: check-recursive
all-am: Makefile $(PROGRAMS)
installdirs: installdirs-recursive
@@ -927,26 +1067,22 @@ uninstall-am:
.MAKE: $(am__recursive_targets) check-am install-am install-strip
.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \
- check-am check-local clean clean-generic clean-libtool \
- clean-noinstPROGRAMS cscopelist-am ctags ctags-am distclean \
- distclean-compile distclean-generic distclean-libtool \
- distclean-tags distdir dvi dvi-am html html-am info info-am \
- install install-am install-data install-data-am install-dvi \
- install-dvi-am install-exec install-exec-am install-html \
- install-html-am install-info install-info-am install-man \
- install-pdf install-pdf-am install-ps install-ps-am \
- install-strip installcheck installcheck-am installdirs \
- installdirs-am maintainer-clean maintainer-clean-generic \
- mostlyclean mostlyclean-compile mostlyclean-generic \
- mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \
- uninstall-am
-
-
-@ENABLE_TESTS_TRUE@check-local: test-settings-defaults test-crypto test-secrets
-@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-settings-defaults
-@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-secrets
-@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-general
-
+ check-TESTS check-am check-local clean clean-generic \
+ clean-libtool clean-noinstPROGRAMS cscopelist-am ctags \
+ ctags-am distclean distclean-compile distclean-generic \
+ distclean-libtool distclean-tags distdir dvi dvi-am html \
+ html-am info info-am install install-am install-data \
+ install-data-am install-dvi install-dvi-am install-exec \
+ install-exec-am install-html install-html-am install-info \
+ install-info-am install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs installdirs-am maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags tags-am uninstall uninstall-am
+
+
+@ENABLE_TESTS_TRUE@check-local: test-crypto test-setting-8021x
# Private key and CA certificate in the same file (PEM)
@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-setting-8021x $(srcdir)/certs/test_key_and_cert.pem "test"
@@ -1003,6 +1139,9 @@ uninstall-am:
@ENABLE_TESTS_TRUE@ $(srcdir)/certs/pkcs8-enc-key.pem \
@ENABLE_TESTS_TRUE@ "1234567890"
+# Private key with AES cipher
+@ENABLE_TESTS_TRUE@ $(abs_builddir)/test-crypto --key $(srcdir)/certs/test-aes-key.pem "test-aes-password"
+
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
diff --git a/libnm-util/tests/certs/Makefile.am b/libnm-util/tests/certs/Makefile.am
index e0f00a479..309925174 100644
--- a/libnm-util/tests/certs/Makefile.am
+++ b/libnm-util/tests/certs/Makefile.am
@@ -20,5 +20,6 @@ EXTRA_DIST = \
test-key-only-decrypted.der \
pkcs8-enc-key.pem \
pkcs8-noenc-key.pem \
- pkcs8-decrypted.der
+ pkcs8-decrypted.der \
+ test-aes-key.pem
diff --git a/libnm-util/tests/certs/Makefile.in b/libnm-util/tests/certs/Makefile.in
index e570aafd0..218cb48d2 100644
--- a/libnm-util/tests/certs/Makefile.in
+++ b/libnm-util/tests/certs/Makefile.in
@@ -89,7 +89,8 @@ host_triplet = @host@
subdir = libnm-util/tests/certs
DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/m4/compiler_warnings.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/m4/ax_lib_readline.m4 \
+ $(top_srcdir)/m4/compiler_warnings.m4 \
$(top_srcdir)/m4/gettext.m4 \
$(top_srcdir)/m4/gnome-code-coverage.m4 \
$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \
@@ -153,12 +154,15 @@ CXXFLAGS = @CXXFLAGS@
CYGPATH_W = @CYGPATH_W@
DATADIRNAME = @DATADIRNAME@
DBUS_CFLAGS = @DBUS_CFLAGS@
+DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@
+DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@
DBUS_LIBS = @DBUS_LIBS@
DBUS_SYS_DIR = @DBUS_SYS_DIR@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DHCLIENT_PATH = @DHCLIENT_PATH@
DHCPCD_PATH = @DHCPCD_PATH@
+DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@
DLLTOOL = @DLLTOOL@
DNSMASQ_PATH = @DNSMASQ_PATH@
DSYMUTIL = @DSYMUTIL@
@@ -183,7 +187,6 @@ GNUTLS_CFLAGS = @GNUTLS_CFLAGS@
GNUTLS_LIBS = @GNUTLS_LIBS@
GREP = @GREP@
GTKDOC_CHECK = @GTKDOC_CHECK@
-GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@
GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
GTKDOC_MKPDF = @GTKDOC_MKPDF@
@@ -228,12 +231,16 @@ LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@
LIBICONV = @LIBICONV@
LIBINTL = @LIBINTL@
LIBM = @LIBM@
+LIBNDP_CFLAGS = @LIBNDP_CFLAGS@
+LIBNDP_LIBS = @LIBNDP_LIBS@
LIBNL_CFLAGS = @LIBNL_CFLAGS@
LIBNL_LIBS = @LIBNL_LIBS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LIBSOUP_CFLAGS = @LIBSOUP_CFLAGS@
LIBSOUP_LIBS = @LIBSOUP_LIBS@
+LIBTEAMDCTL_CFLAGS = @LIBTEAMDCTL_CFLAGS@
+LIBTEAMDCTL_LIBS = @LIBTEAMDCTL_LIBS@
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
@@ -250,6 +257,8 @@ MOC = @MOC@
MSGFMT = @MSGFMT@
MSGFMT_015 = @MSGFMT_015@
MSGMERGE = @MSGMERGE@
+NEWT_CFLAGS = @NEWT_CFLAGS@
+NEWT_LIBS = @NEWT_LIBS@
NM = @NM@
NMEDIT = @NMEDIT@
NM_MAJOR_VERSION = @NM_MAJOR_VERSION@
@@ -277,11 +286,16 @@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
POLKIT_CFLAGS = @POLKIT_CFLAGS@
POLKIT_LIBS = @POLKIT_LIBS@
POSUB = @POSUB@
+PPPD_PATH = @PPPD_PATH@
PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@
+PPPOE_PATH = @PPPOE_PATH@
QT_CFLAGS = @QT_CFLAGS@
QT_LIBS = @QT_LIBS@
RANLIB = @RANLIB@
+READLINE_LIBS = @READLINE_LIBS@
SED = @SED@
+SELINUX_CFLAGS = @SELINUX_CFLAGS@
+SELINUX_LIBS = @SELINUX_LIBS@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
@@ -296,6 +310,7 @@ UDEV_BASE_DIR = @UDEV_BASE_DIR@
USE_NLS = @USE_NLS@
UUID_CFLAGS = @UUID_CFLAGS@
UUID_LIBS = @UUID_LIBS@
+VALGRIND_RULES = @VALGRIND_RULES@
VAPIGEN = @VAPIGEN@
VAPIGEN_MAKEFILE = @VAPIGEN_MAKEFILE@
VAPIGEN_VAPIDIR = @VAPIGEN_VAPIDIR@
@@ -358,6 +373,7 @@ psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
+subdirs = @subdirs@
sysconfdir = @sysconfdir@
systemdsystemunitdir = @systemdsystemunitdir@
target_alias = @target_alias@
@@ -368,6 +384,7 @@ with_dhclient = @with_dhclient@
with_dhcpcd = @with_dhcpcd@
with_netconfig = @with_netconfig@
with_resolvconf = @with_resolvconf@
+with_valgrind = @with_valgrind@
EXTRA_DIST = \
test_ca_cert.pem \
test_ca_cert.der \
@@ -381,7 +398,8 @@ EXTRA_DIST = \
test-key-only-decrypted.der \
pkcs8-enc-key.pem \
pkcs8-noenc-key.pem \
- pkcs8-decrypted.der
+ pkcs8-decrypted.der \
+ test-aes-key.pem
all: all-am
diff --git a/libnm-util/tests/certs/test-aes-key.pem b/libnm-util/tests/certs/test-aes-key.pem
new file mode 100644
index 000000000..aab8f463c
--- /dev/null
+++ b/libnm-util/tests/certs/test-aes-key.pem
@@ -0,0 +1,30 @@
+-----BEGIN RSA PRIVATE KEY-----
+Proc-Type: 4,ENCRYPTED
+DEK-Info: AES-128-CBC,800391B7DD72364B4C2562E0B6AEA000
+
+E9dgNCIATOr4CN5c8o6B+8wdqq/I1BLmPmW2qT7YZepoF7E+RUb8ZLjo1VO2XsJw
+Ir4EzuH7837zBD9dP5CjlY8cWfR63gZpEWRY5Jub8kzvqiL4UZ0Qr8IHOZxAkKEz
+EL1Pn7e+tYt4kA372LPZHWO3vRCgmL1iSJj2/k3avPWAx7NUie4bzGI+00WNv699
+ClKzsJbWB1eiQvYgOr4aVV26oWfa896JkBoGhgZQ6ckqFpsdAos8m46iOSVZrwgq
+Y2/d1CvfQod+87c8LRatwAjf+d6YAJJaeMyxjCGuAY6/JyDsorUkM2OlvbTt6WOA
+gSPWO8I+Ov6THb4IuPhpIJ30Sl88tc6MlIByW49EWu2G1jPw3L8iqRzZ50Z85dyz
+N9yFP91wEwi5F0Zed4iEpg3NVfklEe/VYqCldc5f9fZ84G5V98ZlAdNSqwd/UNBU
+iPTflGqVpp1u+J2isOk+Agpj1MCxh2q0RNuvY9KHzOYBScirfbG4DKNbQgS/5Zw7
+3g9YL5Wbo7BczHLiXf/2adu6T8wI1LKRjkeLV9dK1Vw3ZaGy3mB9oFhCgjh9BNHw
+wC78CVcUErjtOXdQagiCQn5k5EGeAB97QFROoAFjAmGvq3xCi4EHd9Sk6fcMm7Oi
+1fuVR5EXUubF4Llq06lFzQp01s2F73noH49bs3qwdf0n8nrL2XhKB0XCOV/I3K5c
+Y3W+YSl361QGjZ/NUcFLIIy+Uro90MmUBNk6af+wGHRJeflpVnK0ATX1PtpNHziz
+jiMiIZicjgfVLxl1a5zTl6KUmGWKlZb533adQ0s6q9Qmi5Vk5L5W/GdMjcFtZbM6
+GU7EOkwihMLb3DVsNbm7vb8tUXqe/e5RmXtij8Yb+2a6/M9yaOHa0VjHzdiKHecr
+eEYaKQDj7NCWLslNnRRh9GmgXcu2pqBhqRM3HAt3cEaHKKWHTcoWcz11pFwMHNtn
+bU9GjGRVc3lCGhVNRiloO0zrKHmcBpDVLw2+ycXXpj/RaBW2fy0xRLKolyla+jEr
+zdLzVI61O50ZMycOtPmE7DVZpkokn32hGer1eCOFnsN1lywi4cWLvU0jbQC+CJyw
+T9vS8zB3WgOl8rC1AHsfQ4KYajlKleQm89deurQymnt/Qx49SiQA+TpwG9Xvx2TP
+3Vc1NwZfM9ZZ1+6xit/rTuS3LhnmhEnGnV5ZyvAdmkCcV2iHjOnLnQWWQn24MHU3
+8Y9D4AdpI5V7Igwr3vH2NZMiw1W2Yc5EJuPAT8nIs5sgOYhXB/QLPJvulvOQhuNC
+NPwJ6A505JrVNfHuEaoGUyA+mPeWuLwQo8y8cM6ZdFMG3RrwFNzuYTrc1Z/9GsmA
+C0UfHf5dL0r7oWZ1SbpSvsmHYqc8sIypq0ohuLEbpegS/hWP8b2/XDRTjfTiJOrM
+4LsUH9PMOJSxDlwS+7e3FdcGfgXfsMgB3aOjQvNpKEolOuv4A5LVFeMrrwtw4Xo1
+EuhstZwyarUTJenDUXzkakhA+8Yw/g2a7RsnANVTkeBuv2PbqFL4zdlsWvcpkz41
+ESxx1siSeU1E9beOII0zSi8vUD0IAevRHaWSlfU2po600IzX1FN97pa4DJV2ycgn
+-----END RSA PRIVATE KEY-----
diff --git a/libnm-util/tests/test-crypto.c b/libnm-util/tests/test-crypto.c
index 57e39fcaa..c11b6392f 100644
--- a/libnm-util/tests/test-crypto.c
+++ b/libnm-util/tests/test-crypto.c
@@ -28,10 +28,11 @@
#include <stdio.h>
#include <string.h>
-#include "nm-test-helpers.h"
#include "crypto.h"
#include "nm-utils.h"
+#include "nm-test-utils.h"
+
#if 0
static const char *pem_rsa_key_begin = "-----BEGIN RSA PRIVATE KEY-----";
static const char *pem_rsa_key_end = "-----END RSA PRIVATE KEY-----";
@@ -69,10 +70,6 @@ dump_key_to_pem (const char *key, gsize key_len, int key_type)
}
str = g_string_new (NULL);
- if (!str) {
- g_warning ("Couldn't allocate buffer to write out key.");
- goto out;
- }
g_string_append (str, start_tag);
g_string_append_c (str, '\n');
@@ -122,10 +119,8 @@ file_to_byte_array (const char *filename)
if (g_file_get_contents (filename, &contents, &length, NULL)) {
array = g_byte_array_sized_new (length);
- if (array) {
- g_byte_array_append (array, (guint8 *) contents, length);
- g_assert (array->len == length);
- }
+ g_byte_array_append (array, (guint8 *) contents, length);
+ g_assert (array->len == length);
g_free (contents);
}
return array;
@@ -261,6 +256,28 @@ test_load_pkcs8 (const char *path,
}
}
+static gboolean
+is_cipher_aes (const char *path)
+{
+ char *contents;
+ gsize length = 0;
+ const char *cipher;
+ gboolean is_aes = FALSE;
+
+ if (!g_file_get_contents (path, &contents, &length, NULL))
+ return FALSE;
+
+ cipher = strstr (contents, "DEK-Info: ");
+ if (cipher) {
+ cipher += strlen ("DEK-Info: ");
+ if (g_str_has_prefix (cipher, "AES-128-CBC"))
+ is_aes = TRUE;
+ }
+
+ g_free (contents);
+ return is_aes;
+}
+
static void
test_encrypt_private_key (const char *path,
const char *password,
@@ -280,7 +297,10 @@ test_encrypt_private_key (const char *path,
path, NM_CRYPTO_KEY_TYPE_RSA, key_type);
/* Now re-encrypt the private key */
- encrypted = nm_utils_rsa_key_encrypt (array, password, NULL, &error);
+ if (is_cipher_aes (path))
+ encrypted = nm_utils_rsa_key_encrypt_aes (array, password, NULL, &error);
+ else
+ encrypted = nm_utils_rsa_key_encrypt (array, password, NULL, &error);
ASSERT (encrypted != NULL, desc,
"couldn't re-encrypt private key file '%s': %d %s",
path, error->code, error->message);
diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c
index 20a99472b..97625605c 100644
--- a/libnm-util/tests/test-general.c
+++ b/libnm-util/tests/test-general.c
@@ -25,9 +25,9 @@
#include <netinet/ether.h>
#include <linux/if_infiniband.h>
-#include "nm-test-helpers.h"
#include <nm-utils.h>
+#include "nm-setting-private.h"
#include "nm-setting-connection.h"
#include "nm-setting-vpn.h"
#include "nm-setting-gsm.h"
@@ -38,8 +38,14 @@
#include "nm-setting-ip4-config.h"
#include "nm-setting-pppoe.h"
#include "nm-setting-serial.h"
+#include "nm-setting-vlan.h"
+#include "nm-setting-bond.h"
+#include "nm-utils.h"
+#include "nm-utils-private.h"
#include "nm-dbus-glib-types.h"
+#include "nm-test-utils.h"
+
static void
vpn_check_func (const char *key, const char *value, gpointer user_data)
{
@@ -116,22 +122,56 @@ test_setting_vpn_items (void)
nm_setting_vpn_remove_secret (s_vpn, "foobar4");
/* Try to add some blank values and make sure they are rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*key != NULL*");
nm_setting_vpn_add_data_item (s_vpn, NULL, NULL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strlen (key) > 0*");
nm_setting_vpn_add_data_item (s_vpn, "", "");
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*item != NULL*");
nm_setting_vpn_add_data_item (s_vpn, "foobar1", NULL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strlen (item) > 0*");
nm_setting_vpn_add_data_item (s_vpn, "foobar1", "");
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*key != NULL*");
nm_setting_vpn_add_data_item (s_vpn, NULL, "blahblah1");
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strlen (key) > 0*");
nm_setting_vpn_add_data_item (s_vpn, "", "blahblah1");
+ g_test_assert_expected_messages ();
nm_setting_vpn_foreach_data_item (s_vpn, vpn_check_empty_func, "vpn-data-empty");
/* Try to add some blank secrets and make sure they are rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*key != NULL*");
nm_setting_vpn_add_secret (s_vpn, NULL, NULL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strlen (key) > 0*");
nm_setting_vpn_add_secret (s_vpn, "", "");
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*secret != NULL*");
nm_setting_vpn_add_secret (s_vpn, "foobar1", NULL);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strlen (secret) > 0*");
nm_setting_vpn_add_secret (s_vpn, "foobar1", "");
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*key != NULL*");
nm_setting_vpn_add_secret (s_vpn, NULL, "blahblah1");
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strlen (key) > 0*");
nm_setting_vpn_add_secret (s_vpn, "", "blahblah1");
+ g_test_assert_expected_messages ();
nm_setting_vpn_foreach_secret (s_vpn, vpn_check_empty_func, "vpn-secrets-empty");
@@ -144,7 +184,7 @@ test_setting_vpn_update_secrets (void)
NMConnection *connection;
NMSettingVPN *s_vpn;
GHashTable *settings, *vpn, *secrets;
- GValue val = { 0 };
+ GValue val = G_VALUE_INIT;
gboolean success;
GError *error = NULL;
const char *tmp;
@@ -194,6 +234,7 @@ test_setting_vpn_update_secrets (void)
ASSERT (strcmp (tmp, val2) == 0,
"vpn-update-secrets", "unexpected key #2 value");
+ g_hash_table_destroy (settings);
g_object_unref (connection);
}
@@ -266,6 +307,156 @@ test_setting_vpn_modify_during_foreach (void)
g_object_unref (s_vpn);
}
+static void
+test_setting_ip4_config_labels (void)
+{
+ NMSettingIP4Config *s_ip4;
+ NMIP4Address *addr;
+ const char *label;
+ GPtrArray *addrs;
+ GSList *labels;
+ GError *error = NULL;
+
+ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ g_object_set (G_OBJECT (s_ip4),
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
+ NULL);
+
+ /* addr 1 */
+ addr = nm_ip4_address_new ();
+ nm_ip4_address_set_address (addr, 0x01010101);
+ nm_ip4_address_set_prefix (addr, 24);
+
+ nm_setting_ip4_config_add_address (s_ip4, addr);
+ nm_ip4_address_unref (addr);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+ g_assert_cmpstr (label, ==, NULL);
+
+ /* addr 2 */
+ addr = nm_ip4_address_new ();
+ nm_ip4_address_set_address (addr, 0x02020202);
+ nm_ip4_address_set_prefix (addr, 24);
+
+ NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, "eth0:1"));
+ nm_ip4_address_unref (addr);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+ g_assert_cmpstr (label, ==, "eth0:1");
+
+ /* addr 3 */
+ addr = nm_ip4_address_new ();
+ nm_ip4_address_set_address (addr, 0x03030303);
+ nm_ip4_address_set_prefix (addr, 24);
+
+ NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_add_address_with_label (s_ip4, addr, NULL));
+ nm_ip4_address_unref (addr);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 2));
+ g_assert_cmpstr (label, ==, NULL);
+
+ /* Remove addr 1 and re-verify remaining addresses */
+ nm_setting_ip4_config_remove_address (s_ip4, 0);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+
+ addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+ g_assert_cmpstr (label, ==, "eth0:1");
+
+ addr = nm_setting_ip4_config_get_address (s_ip4, 1);
+ g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+ g_assert_cmpstr (label, ==, NULL);
+
+
+ /* Test explicit property assignment */
+ g_object_get (G_OBJECT (s_ip4),
+ NM_SETTING_IP4_CONFIG_ADDRESSES, &addrs,
+ "address-labels", &labels,
+ NULL);
+
+ nm_setting_ip4_config_clear_addresses (s_ip4);
+ g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 0);
+
+ /* Setting addrs but not labels will result in empty labels */
+ g_object_set (G_OBJECT (s_ip4),
+ NM_SETTING_IP4_CONFIG_ADDRESSES, addrs,
+ NULL);
+ g_boxed_free (DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UINT, addrs);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
+
+ addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+ g_assert_cmpstr (label, ==, NULL);
+
+ addr = nm_setting_ip4_config_get_address (s_ip4, 1);
+ g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+ g_assert_cmpstr (label, ==, NULL);
+
+ /* Setting labels now will leave addresses untouched */
+ g_object_set (G_OBJECT (s_ip4),
+ "address-labels", labels,
+ NULL);
+ g_boxed_free (DBUS_TYPE_G_LIST_OF_STRING, labels);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (nm_setting_ip4_config_get_num_addresses (s_ip4), ==, 2);
+
+ addr = nm_setting_ip4_config_get_address (s_ip4, 0);
+ g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x02020202);
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 0));
+ g_assert_cmpstr (label, ==, "eth0:1");
+
+ addr = nm_setting_ip4_config_get_address (s_ip4, 1);
+ g_assert_cmpint (nm_ip4_address_get_address (addr), ==, 0x03030303);
+ label = NM_UTILS_PRIVATE_CALL (nm_setting_ip4_config_get_address_label (s_ip4, 1));
+ g_assert_cmpstr (label, ==, NULL);
+
+ /* Setting labels to a value that's too short or too long will result in
+ * the setting not verifying.
+ */
+ labels = g_slist_append (NULL, "eth0:2");
+ g_object_set (G_OBJECT (s_ip4),
+ "address-labels", labels,
+ NULL);
+
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_error (error, NM_SETTING_IP4_CONFIG_ERROR, NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY);
+ g_assert (g_str_has_prefix (error->message, "ipv4.address-labels:"));
+ g_clear_error (&error);
+
+ labels = g_slist_append (labels, "eth0:3");
+ g_object_set (G_OBJECT (s_ip4),
+ "address-labels", labels,
+ NULL);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_no_error (error);
+
+ labels = g_slist_append (labels, "eth0:4");
+ g_object_set (G_OBJECT (s_ip4),
+ "address-labels", labels,
+ NULL);
+ nm_setting_verify (NM_SETTING (s_ip4), NULL, &error);
+ g_assert_error (error, NM_SETTING_IP4_CONFIG_ERROR, NM_SETTING_IP4_CONFIG_ERROR_INVALID_PROPERTY);
+ g_assert (g_str_has_prefix (error->message, "ipv4.address-labels:"));
+ g_clear_error (&error);
+
+
+ g_object_unref (s_ip4);
+}
+
#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS))
@@ -279,7 +470,7 @@ test_setting_ip6_config_old_address_array (void)
NMSettingIP6Config *s_ip6;
GPtrArray *addresses, *read_addresses;
GValueArray *array, *read_array;
- GValue element = {0, }, written_value = {0, }, read_value = {0, };
+ GValue element = G_VALUE_INIT, written_value = G_VALUE_INIT, read_value = G_VALUE_INIT;
GByteArray *ba;
const guint8 addr[16] = { 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
0x11, 0x22, 0x33, 0x44, 0x66, 0x77, 0x88, 0x99 };
@@ -462,6 +653,7 @@ test_setting_gsm_without_number (void)
g_object_set (s_gsm, NM_SETTING_GSM_NUMBER, "", NULL);
success = nm_setting_verify (NM_SETTING (s_gsm), NULL, &error);
g_assert_error (error, NM_SETTING_GSM_ERROR, NM_SETTING_GSM_ERROR_INVALID_PROPERTY);
+ g_error_free (error);
}
static NMSettingWirelessSecurity *
@@ -582,6 +774,262 @@ test_connection_to_hash_setting_name (void)
}
static void
+test_setting_new_from_hash (void)
+{
+ NMSettingWirelessSecurity *s_wsec;
+ GHashTable *hash;
+
+ s_wsec = make_test_wsec_setting ("setting-to-hash-all");
+ hash = nm_setting_to_hash (NM_SETTING (s_wsec), NM_SETTING_HASH_FLAG_ALL);
+ g_object_unref (s_wsec);
+
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_new_from_hash (NM_TYPE_SETTING_WIRELESS_SECURITY, hash);
+ g_hash_table_destroy (hash);
+
+ g_assert (s_wsec);
+ g_assert_cmpstr (nm_setting_wireless_security_get_key_mgmt (s_wsec), ==, "wpa-psk");
+ g_assert_cmpstr (nm_setting_wireless_security_get_leap_username (s_wsec), ==, "foobarbaz");
+ g_assert_cmpstr (nm_setting_wireless_security_get_psk (s_wsec), ==, "random psk");
+ g_object_unref (s_wsec);
+}
+
+static NMConnection *
+new_test_connection (void)
+{
+ NMConnection *connection;
+ NMSetting *setting;
+ char *uuid;
+ guint64 timestamp = time (NULL);
+
+ connection = nm_connection_new ();
+
+ setting = nm_setting_connection_new ();
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (G_OBJECT (setting),
+ NM_SETTING_CONNECTION_ID, "foobar",
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
+ NM_SETTING_CONNECTION_TIMESTAMP, timestamp,
+ NULL);
+ g_free (uuid);
+ nm_connection_add_setting (connection, setting);
+
+ setting = nm_setting_wired_new ();
+ g_object_set (G_OBJECT (setting),
+ NM_SETTING_WIRED_MTU, 1592,
+ NULL);
+ nm_connection_add_setting (connection, setting);
+
+ setting = nm_setting_ip4_config_new ();
+ g_object_set (G_OBJECT (setting),
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "eyeofthetiger",
+ NULL);
+ nm_connection_add_setting (connection, setting);
+
+ return connection;
+}
+
+static GValue *
+string_to_gvalue (const char *str)
+{
+ GValue *val;
+
+ val = g_slice_new0 (GValue);
+ g_value_init (val, G_TYPE_STRING);
+ g_value_set_string (val, str);
+ return val;
+}
+
+static void
+destroy_gvalue (gpointer data)
+{
+ g_value_unset ((GValue *) data);
+ g_slice_free (GValue, data);
+}
+
+static GHashTable *
+new_connection_hash (char **out_uuid,
+ const char **out_expected_id,
+ const char **out_expected_ip6_method)
+{
+ GHashTable *hash;
+ GHashTable *setting;
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_hash_table_destroy);
+
+ *out_uuid = nm_utils_uuid_generate ();
+ *out_expected_id = "My happy connection";
+ *out_expected_ip6_method = NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL;
+
+ /* Connection setting */
+ setting = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+ g_hash_table_insert (setting,
+ g_strdup (NM_SETTING_NAME),
+ string_to_gvalue (NM_SETTING_CONNECTION_SETTING_NAME));
+ g_hash_table_insert (setting,
+ g_strdup (NM_SETTING_CONNECTION_ID),
+ string_to_gvalue (*out_expected_id));
+ g_hash_table_insert (setting,
+ g_strdup (NM_SETTING_CONNECTION_UUID),
+ string_to_gvalue (*out_uuid));
+ g_hash_table_insert (setting,
+ g_strdup (NM_SETTING_CONNECTION_TYPE),
+ string_to_gvalue (NM_SETTING_WIRED_SETTING_NAME));
+ g_hash_table_insert (hash, g_strdup (NM_SETTING_CONNECTION_SETTING_NAME), setting);
+
+ /* Wired setting */
+ setting = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+ g_hash_table_insert (hash, g_strdup (NM_SETTING_WIRED_SETTING_NAME), setting);
+
+ /* IP6 */
+ setting = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
+ g_hash_table_insert (setting,
+ g_strdup (NM_SETTING_IP6_CONFIG_METHOD),
+ string_to_gvalue (*out_expected_ip6_method));
+ g_hash_table_insert (hash, g_strdup (NM_SETTING_IP6_CONFIG_SETTING_NAME), setting);
+
+ return hash;
+}
+
+static void
+test_connection_replace_settings ()
+{
+ NMConnection *connection;
+ GHashTable *new_settings;
+ GError *error = NULL;
+ gboolean success;
+ NMSettingConnection *s_con;
+ NMSettingIP6Config *s_ip6;
+ char *uuid = NULL;
+ const char *expected_id = NULL, *expected_method = NULL;
+
+ connection = new_test_connection ();
+
+ new_settings = new_connection_hash (&uuid, &expected_id, &expected_method);
+ g_assert (new_settings);
+
+ /* Replace settings and test */
+ success = nm_connection_replace_settings (connection, new_settings, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, expected_id);
+ g_assert_cmpstr (nm_setting_connection_get_uuid (s_con), ==, uuid);
+
+ g_assert (nm_connection_get_setting_wired (connection));
+ g_assert (!nm_connection_get_setting_ip4_config (connection));
+
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ g_assert (s_ip6);
+ g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, expected_method);
+
+ g_free (uuid);
+ g_hash_table_destroy (new_settings);
+ g_object_unref (connection);
+}
+
+static void
+test_connection_replace_settings_from_connection ()
+{
+ NMConnection *connection, *replacement;
+ GError *error = NULL;
+ gboolean success;
+ NMSettingConnection *s_con;
+ NMSetting *setting;
+ GByteArray *ssid;
+ char *uuid = NULL;
+ const char *expected_id = "Awesome connection";
+
+ connection = new_test_connection ();
+ g_assert (connection);
+
+ replacement = nm_connection_new ();
+ g_assert (replacement);
+
+ /* New connection setting */
+ setting = nm_setting_connection_new ();
+ g_assert (setting);
+
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (setting,
+ NM_SETTING_CONNECTION_ID, expected_id,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
+ NULL);
+ nm_connection_add_setting (replacement, setting);
+
+ /* New wifi setting */
+ setting = nm_setting_wireless_new ();
+ g_assert (setting);
+
+ ssid = g_byte_array_new ();
+ g_byte_array_append (ssid, (const guint8 *) "1234567", 7);
+ g_object_set (setting,
+ NM_SETTING_WIRELESS_SSID, ssid,
+ NM_SETTING_WIRELESS_MODE, "infrastructure",
+ NULL);
+ g_byte_array_free (ssid, TRUE);
+ nm_connection_add_setting (replacement, setting);
+
+ /* Replace settings and test */
+ success = nm_connection_replace_settings_from_connection (connection, replacement, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, expected_id);
+ g_assert_cmpstr (nm_setting_connection_get_uuid (s_con), ==, uuid);
+
+ g_assert (!nm_connection_get_setting_wired (connection));
+ g_assert (!nm_connection_get_setting_ip6_config (connection));
+ g_assert (nm_connection_get_setting_wireless (connection));
+
+ g_free (uuid);
+ g_object_unref (replacement);
+ g_object_unref (connection);
+}
+
+static void
+test_connection_new_from_hash ()
+{
+ NMConnection *connection;
+ GHashTable *new_settings;
+ GError *error = NULL;
+ NMSettingConnection *s_con;
+ NMSettingIP6Config *s_ip6;
+ char *uuid = NULL;
+ const char *expected_id = NULL, *expected_method = NULL;
+
+ new_settings = new_connection_hash (&uuid, &expected_id, &expected_method);
+ g_assert (new_settings);
+
+ /* Replace settings and test */
+ connection = nm_connection_new_from_hash (new_settings, &error);
+ g_assert_no_error (error);
+ g_assert (connection);
+
+ s_con = nm_connection_get_setting_connection (connection);
+ g_assert (s_con);
+ g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, expected_id);
+ g_assert_cmpstr (nm_setting_connection_get_uuid (s_con), ==, uuid);
+
+ g_assert (nm_connection_get_setting_wired (connection));
+ g_assert (!nm_connection_get_setting_ip4_config (connection));
+
+ s_ip6 = nm_connection_get_setting_ip6_config (connection);
+ g_assert (s_ip6);
+ g_assert_cmpstr (nm_setting_ip6_config_get_method (s_ip6), ==, expected_method);
+
+ g_free (uuid);
+ g_hash_table_destroy (new_settings);
+ g_object_unref (connection);
+}
+
+static void
check_permission (NMSettingConnection *s_con,
guint32 idx,
const char *expected_uname,
@@ -618,37 +1066,55 @@ test_setting_connection_permissions_helpers (void)
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
/* Ensure a bad [type] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strcmp (ptype, \"user\") == 0*");
success = nm_setting_connection_add_permission (s_con, "foobar", "blah", NULL);
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission type #1");
/* Ensure a bad [type] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*ptype*");
success = nm_setting_connection_add_permission (s_con, NULL, "blah", NULL);
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission type #2");
/* Ensure a bad [item] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*uname*");
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*p != NULL*");
success = nm_setting_connection_add_permission (s_con, "user", NULL, NULL);
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #1");
/* Ensure a bad [item] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*uname[0] != '\\0'*");
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*p != NULL*");
success = nm_setting_connection_add_permission (s_con, "user", "", NULL);
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #2");
/* Ensure an [item] with ':' is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strchr (uname, ':')*");
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*p != NULL*");
success = nm_setting_connection_add_permission (s_con, "user", "ad:asdf", NULL);
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #3");
/* Ensure a non-UTF-8 [item] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*g_utf8_validate (uname, -1, NULL)*");
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*p != NULL*");
success = nm_setting_connection_add_permission (s_con, "user", buf, NULL);
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad permission item #4");
/* Ensure a non-NULL [detail] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*detail == NULL*");
success = nm_setting_connection_add_permission (s_con, "user", "dafasdf", "asdf");
+ g_test_assert_expected_messages ();
ASSERT (success == FALSE,
"setting-connection-permissions-helpers", "unexpected success adding bad detail");
@@ -670,6 +1136,7 @@ test_setting_connection_permissions_helpers (void)
"setting-connection-permissions-helpers", "unexpected failure getting number of permissions in list");
ASSERT (strcmp (list->data, expected_perm) == 0,
"setting-connection-permissions-helpers", "unexpected permission property data");
+ g_slist_free_full (list, g_free);
/* Now remove that permission and ensure we have 0 permissions */
nm_setting_connection_remove_permission (s_con, 0);
@@ -723,42 +1190,58 @@ test_setting_connection_permissions_property (void)
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
/* Ensure a bad [type] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strncmp (str, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0*");
add_permission_property (s_con, "foobar", "blah", -1, NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission type #1");
/* Ensure a bad [type] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*strncmp (str, PERM_USER_PREFIX, strlen (PERM_USER_PREFIX)) == 0*");
add_permission_property (s_con, NULL, "blah", -1, NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission type #2");
/* Ensure a bad [item] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*last_colon > str*");
add_permission_property (s_con, "user", NULL, -1, NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #1");
/* Ensure a bad [item] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*last_colon > str*");
add_permission_property (s_con, "user", "", -1, NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #2");
/* Ensure an [item] with ':' in the middle is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*str[i] != ':'*");
add_permission_property (s_con, "user", "ad:asdf", -1, NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #3");
/* Ensure an [item] with ':' at the end is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*str[i] != ':'*");
add_permission_property (s_con, "user", "adasdfaf:", -1, NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #4");
/* Ensure a non-UTF-8 [item] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*g_utf8_validate (str, -1, NULL)*");
add_permission_property (s_con, "user", buf, (int) sizeof (buf), NULL);
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad permission item #5");
/* Ensure a non-NULL [detail] is rejected */
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*(last_colon + 1) == '\\0'*");
add_permission_property (s_con, "user", "dafasdf", -1, "asdf");
+ g_test_assert_expected_messages ();
ASSERT (nm_setting_connection_get_num_permissions (s_con) == 0,
"setting-connection-permissions-property", "unexpected success adding bad detail");
@@ -777,41 +1260,76 @@ test_setting_connection_permissions_property (void)
g_object_unref (s_con);
}
-static NMConnection *
-new_test_connection (void)
+static void
+test_connection_compare_same (void)
{
- NMConnection *connection;
- NMSetting *setting;
- char *uuid;
- guint64 timestamp = time (NULL);
+ NMConnection *a, *b;
- connection = nm_connection_new ();
+ a = new_test_connection ();
+ b = nm_connection_duplicate (a);
+ g_assert (nm_connection_compare (a, b, NM_SETTING_COMPARE_FLAG_EXACT));
+ g_object_unref (a);
+ g_object_unref (b);
+}
- setting = nm_setting_connection_new ();
- uuid = nm_utils_uuid_generate ();
- g_object_set (G_OBJECT (setting),
- NM_SETTING_CONNECTION_ID, "foobar",
- NM_SETTING_CONNECTION_UUID, uuid,
- NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
- NM_SETTING_CONNECTION_TIMESTAMP, timestamp,
- NULL);
- g_free (uuid);
- nm_connection_add_setting (connection, setting);
+static void
+test_connection_compare_key_only_in_a (void)
+{
+ NMConnection *a, *b;
+ NMSettingConnection *s_con;
- setting = nm_setting_wired_new ();
- g_object_set (G_OBJECT (setting),
- NM_SETTING_WIRED_MTU, 1592,
- NULL);
- nm_connection_add_setting (connection, setting);
+ a = new_test_connection ();
+ b = nm_connection_duplicate (a);
+ s_con = (NMSettingConnection *) nm_connection_get_setting (b, NM_TYPE_SETTING_CONNECTION);
+ g_assert (s_con);
+ g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, (guint64) 0, NULL);
- setting = nm_setting_ip4_config_new ();
- g_object_set (G_OBJECT (setting),
- NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
- NM_SETTING_IP4_CONFIG_DHCP_HOSTNAME, "eyeofthetiger",
- NULL);
- nm_connection_add_setting (connection, setting);
+ g_assert (!nm_connection_compare (a, b, NM_SETTING_COMPARE_FLAG_EXACT));
+ g_object_unref (a);
+ g_object_unref (b);
+}
- return connection;
+static void
+test_connection_compare_setting_only_in_a (void)
+{
+ NMConnection *a, *b;
+
+ a = new_test_connection ();
+ b = nm_connection_duplicate (a);
+ nm_connection_remove_setting (b, NM_TYPE_SETTING_IP4_CONFIG);
+ g_assert (!nm_connection_compare (a, b, NM_SETTING_COMPARE_FLAG_EXACT));
+ g_object_unref (a);
+ g_object_unref (b);
+}
+
+static void
+test_connection_compare_key_only_in_b (void)
+{
+ NMConnection *a, *b;
+ NMSettingConnection *s_con;
+
+ a = new_test_connection ();
+ b = nm_connection_duplicate (a);
+ s_con = (NMSettingConnection *) nm_connection_get_setting (b, NM_TYPE_SETTING_CONNECTION);
+ g_assert (s_con);
+ g_object_set (s_con, NM_SETTING_CONNECTION_TIMESTAMP, (guint64) 0, NULL);
+
+ g_assert (!nm_connection_compare (a, b, NM_SETTING_COMPARE_FLAG_EXACT));
+ g_object_unref (a);
+ g_object_unref (b);
+}
+
+static void
+test_connection_compare_setting_only_in_b (void)
+{
+ NMConnection *a, *b;
+
+ a = new_test_connection ();
+ b = nm_connection_duplicate (a);
+ nm_connection_remove_setting (a, NM_TYPE_SETTING_IP4_CONFIG);
+ g_assert (!nm_connection_compare (a, b, NM_SETTING_COMPARE_FLAG_EXACT));
+ g_object_unref (a);
+ g_object_unref (b);
}
typedef struct {
@@ -864,17 +1382,19 @@ test_connection_diff_a_only (void)
gboolean same;
const DiffSetting settings[] = {
{ NM_SETTING_CONNECTION_SETTING_NAME, {
- { NM_SETTING_CONNECTION_ID, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_UUID, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_TYPE, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_TIMESTAMP, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_AUTOCONNECT, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_READ_ONLY, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_PERMISSIONS, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_ZONE, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_MASTER, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_DIFF_RESULT_IN_A },
- { NM_SETTING_CONNECTION_SECONDARIES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_ID, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_UUID, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_INTERFACE_NAME, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_TYPE, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_TIMESTAMP, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_AUTOCONNECT, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_READ_ONLY, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_PERMISSIONS, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_ZONE, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_MASTER, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_SECONDARIES, NM_SETTING_DIFF_RESULT_IN_A },
+ { NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT, NM_SETTING_DIFF_RESULT_IN_A },
{ NULL, NM_SETTING_DIFF_RESULT_UNKNOWN }
} },
{ NM_SETTING_WIRED_SETTING_NAME, {
@@ -896,6 +1416,7 @@ test_connection_diff_a_only (void)
{ NM_SETTING_IP4_CONFIG_DNS, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_DNS_SEARCH, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_ADDRESSES, NM_SETTING_DIFF_RESULT_IN_A },
+ { "address-labels", NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_ROUTES, NM_SETTING_DIFF_RESULT_IN_A },
{ NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, NM_SETTING_DIFF_RESULT_IN_A },
@@ -917,6 +1438,7 @@ test_connection_diff_a_only (void)
ensure_diffs (out_diffs, settings, ARRAY_LEN (settings));
+ g_hash_table_destroy (out_diffs);
g_object_unref (connection);
}
@@ -966,6 +1488,7 @@ test_connection_diff_different (void)
ensure_diffs (out_diffs, settings, ARRAY_LEN (settings));
+ g_hash_table_destroy (out_diffs);
g_object_unref (a);
g_object_unref (b);
}
@@ -1013,6 +1536,66 @@ test_connection_diff_no_secrets (void)
ensure_diffs (out_diffs, settings, ARRAY_LEN (settings));
+ g_hash_table_destroy (out_diffs);
+ g_object_unref (a);
+ g_object_unref (b);
+}
+
+static void
+test_connection_diff_inferrable (void)
+{
+ NMConnection *a, *b;
+ GHashTable *out_diffs = NULL;
+ gboolean same;
+ NMSettingConnection *s_con;
+ NMSettingWired *s_wired;
+ NMSettingIP4Config *s_ip4;
+ char *uuid;
+ const DiffSetting settings[] = {
+ { NM_SETTING_CONNECTION_SETTING_NAME, {
+ { NM_SETTING_CONNECTION_INTERFACE_NAME, NM_SETTING_DIFF_RESULT_IN_A },
+ { NULL, NM_SETTING_DIFF_RESULT_UNKNOWN },
+ } },
+ };
+
+ a = new_test_connection ();
+ b = nm_connection_duplicate (a);
+
+ /* Change the UUID, wired MTU, and set ignore-auto-dns */
+ s_con = nm_connection_get_setting_connection (a);
+ g_assert (s_con);
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (G_OBJECT (s_con),
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_ID, "really neat connection",
+ NULL);
+ g_free (uuid);
+
+ s_wired = nm_connection_get_setting_wired (a);
+ g_assert (s_wired);
+ g_object_set (G_OBJECT (s_wired), NM_SETTING_WIRED_MTU, 300, NULL);
+
+ s_ip4 = nm_connection_get_setting_ip4_config (a);
+ g_assert (s_ip4);
+ g_object_set (G_OBJECT (s_ip4), NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS, TRUE, NULL);
+
+ /* Make sure the diff returns no results as secrets are ignored */
+ same = nm_connection_diff (a, b, NM_SETTING_COMPARE_FLAG_INFERRABLE, &out_diffs);
+ g_assert (same == TRUE);
+ g_assert (out_diffs == NULL);
+
+ /* And change a INFERRABLE property to ensure that it shows up in the diff results */
+ g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, "usb0", NULL);
+
+ /* Make sure the diff returns no results as secrets are ignored */
+ same = nm_connection_diff (a, b, NM_SETTING_COMPARE_FLAG_INFERRABLE, &out_diffs);
+ g_assert (same == FALSE);
+ g_assert (out_diffs != NULL);
+ g_assert (g_hash_table_size (out_diffs) > 0);
+
+ ensure_diffs (out_diffs, settings, ARRAY_LEN (settings));
+
+ g_hash_table_destroy (out_diffs);
g_object_unref (a);
g_object_unref (b);
}
@@ -1363,6 +1946,12 @@ test_hwaddr_aton_malformed (void)
}
static void
+test_connection_changed_cb (NMConnection *connection, gboolean *data)
+{
+ *data = TRUE;
+}
+
+static void
test_ip4_prefix_to_netmask (void)
{
int i;
@@ -1422,6 +2011,456 @@ test_ip4_netmask_to_prefix (void)
g_rand_free (rand);
}
+#define ASSERT_CHANGED(statement) \
+{ \
+ changed = FALSE; \
+ statement; \
+ g_assert (changed); \
+}
+
+#define ASSERT_UNCHANGED(statement) \
+{ \
+ changed = FALSE; \
+ statement; \
+ g_assert (!changed); \
+}
+
+static void
+test_connection_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+
+ connection = new_test_connection ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ /* Add new setting */
+ ASSERT_CHANGED (nm_connection_add_setting (connection, nm_setting_vlan_new ()));
+
+ /* Remove existing setting */
+ ASSERT_CHANGED (nm_connection_remove_setting (connection, NM_TYPE_SETTING_VLAN));
+
+ /* Remove non-existing setting */
+ ASSERT_UNCHANGED (nm_connection_remove_setting (connection, NM_TYPE_SETTING_VLAN));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_connection_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingConnection *s_con;
+ char *uuid;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_con = (NMSettingConnection *) nm_setting_connection_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ ASSERT_CHANGED (g_object_set (s_con, NM_SETTING_CONNECTION_ID, "adfadfasdfaf", NULL));
+
+ ASSERT_CHANGED (nm_setting_connection_add_permission (s_con, "user", "billsmith", NULL));
+ ASSERT_CHANGED (nm_setting_connection_remove_permission (s_con, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*iter != NULL*");
+ ASSERT_UNCHANGED (nm_setting_connection_remove_permission (s_con, 1));
+ g_test_assert_expected_messages ();
+
+ uuid = nm_utils_uuid_generate ();
+ ASSERT_CHANGED (nm_setting_connection_add_secondary (s_con, uuid));
+ ASSERT_CHANGED (nm_setting_connection_remove_secondary (s_con, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_connection_remove_secondary (s_con, 1));
+ g_test_assert_expected_messages ();
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_bond_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingBond *s_bond;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_bond = (NMSettingBond *) nm_setting_bond_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_bond));
+
+ ASSERT_CHANGED (nm_setting_bond_add_option (s_bond, NM_SETTING_BOND_OPTION_DOWNDELAY, "10"));
+ ASSERT_CHANGED (nm_setting_bond_remove_option (s_bond, NM_SETTING_BOND_OPTION_DOWNDELAY));
+ ASSERT_UNCHANGED (nm_setting_bond_remove_option (s_bond, NM_SETTING_BOND_OPTION_UPDELAY));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_ip4_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingIP4Config *s_ip4;
+ NMIP4Address *addr;
+ NMIP4Route *route;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_ip4));
+
+ ASSERT_CHANGED (nm_setting_ip4_config_add_dns (s_ip4, 0x1122));
+ ASSERT_CHANGED (nm_setting_ip4_config_remove_dns (s_ip4, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*i <= priv->dns->len*");
+ ASSERT_UNCHANGED (nm_setting_ip4_config_remove_dns (s_ip4, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip4_config_add_dns (s_ip4, 0x3344);
+ ASSERT_CHANGED (nm_setting_ip4_config_clear_dns (s_ip4));
+
+ ASSERT_CHANGED (nm_setting_ip4_config_add_dns_search (s_ip4, "foobar.com"));
+ ASSERT_CHANGED (nm_setting_ip4_config_remove_dns_search (s_ip4, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip4_config_remove_dns_search (s_ip4, 1));
+ g_test_assert_expected_messages ();
+
+ ASSERT_CHANGED (nm_setting_ip4_config_add_dns_search (s_ip4, "foobar.com"));
+ ASSERT_CHANGED (nm_setting_ip4_config_clear_dns_searches (s_ip4));
+
+ addr = nm_ip4_address_new ();
+ nm_ip4_address_set_address (addr, 0x2233);
+ nm_ip4_address_set_prefix (addr, 24);
+ ASSERT_CHANGED (nm_setting_ip4_config_add_address (s_ip4, addr));
+ ASSERT_CHANGED (nm_setting_ip4_config_remove_address (s_ip4, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*addr != NULL && label != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip4_config_remove_address (s_ip4, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip4_config_add_address (s_ip4, addr);
+ ASSERT_CHANGED (nm_setting_ip4_config_clear_addresses (s_ip4));
+
+ route = nm_ip4_route_new ();
+ nm_ip4_route_set_dest (route, 0x2233);
+ nm_ip4_route_set_prefix (route, 24);
+
+ ASSERT_CHANGED (nm_setting_ip4_config_add_route (s_ip4, route));
+ ASSERT_CHANGED (nm_setting_ip4_config_remove_route (s_ip4, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip4_config_remove_route (s_ip4, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip4_config_add_route (s_ip4, route);
+ ASSERT_CHANGED (nm_setting_ip4_config_clear_routes (s_ip4));
+
+ nm_ip4_address_unref (addr);
+ nm_ip4_route_unref (route);
+ g_object_unref (connection);
+}
+
+static void
+test_setting_ip6_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingIP6Config *s_ip6;
+ NMIP6Address *addr;
+ NMIP6Route *route;
+ const struct in6_addr t = { { { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 } } };
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_ip6));
+
+ ASSERT_CHANGED (nm_setting_ip6_config_add_dns (s_ip6, &t));
+ ASSERT_CHANGED (nm_setting_ip6_config_remove_dns (s_ip6, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip6_config_remove_dns (s_ip6, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip6_config_add_dns (s_ip6, &t);
+ ASSERT_CHANGED (nm_setting_ip6_config_clear_dns (s_ip6));
+
+ ASSERT_CHANGED (nm_setting_ip6_config_add_dns_search (s_ip6, "foobar.com"));
+ ASSERT_CHANGED (nm_setting_ip6_config_remove_dns_search (s_ip6, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip6_config_remove_dns_search (s_ip6, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip6_config_add_dns_search (s_ip6, "foobar.com");
+ ASSERT_CHANGED (nm_setting_ip6_config_clear_dns_searches (s_ip6));
+
+ addr = nm_ip6_address_new ();
+ nm_ip6_address_set_address (addr, &t);
+ nm_ip6_address_set_prefix (addr, 64);
+
+ ASSERT_CHANGED (nm_setting_ip6_config_add_address (s_ip6, addr));
+ ASSERT_CHANGED (nm_setting_ip6_config_remove_address (s_ip6, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip6_config_remove_address (s_ip6, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip6_config_add_address (s_ip6, addr);
+ ASSERT_CHANGED (nm_setting_ip6_config_clear_addresses (s_ip6));
+
+ route = nm_ip6_route_new ();
+ nm_ip6_route_set_dest (route, &t);
+ nm_ip6_route_set_prefix (route, 128);
+
+ ASSERT_CHANGED (nm_setting_ip6_config_add_route (s_ip6, route));
+ ASSERT_CHANGED (nm_setting_ip6_config_remove_route (s_ip6, 0));
+
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_ip6_config_remove_route (s_ip6, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_ip6_config_add_route (s_ip6, route);
+ ASSERT_CHANGED (nm_setting_ip6_config_clear_routes (s_ip6));
+
+ nm_ip6_address_unref (addr);
+ nm_ip6_route_unref (route);
+ g_object_unref (connection);
+}
+
+static void
+test_setting_vlan_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingVlan *s_vlan;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_vlan = (NMSettingVlan *) nm_setting_vlan_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_vlan));
+
+ ASSERT_CHANGED (nm_setting_vlan_add_priority (s_vlan, NM_VLAN_INGRESS_MAP, 1, 3));
+ ASSERT_CHANGED (nm_setting_vlan_remove_priority (s_vlan, NM_VLAN_INGRESS_MAP, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*idx < g_slist_length (list)*");
+ ASSERT_UNCHANGED (nm_setting_vlan_remove_priority (s_vlan, NM_VLAN_INGRESS_MAP, 1));
+ g_test_assert_expected_messages ();
+ ASSERT_CHANGED (nm_setting_vlan_add_priority_str (s_vlan, NM_VLAN_INGRESS_MAP, "1:3"));
+ ASSERT_CHANGED (nm_setting_vlan_clear_priorities (s_vlan, NM_VLAN_INGRESS_MAP));
+
+ ASSERT_CHANGED (nm_setting_vlan_add_priority (s_vlan, NM_VLAN_EGRESS_MAP, 1, 3));
+ ASSERT_CHANGED (nm_setting_vlan_remove_priority (s_vlan, NM_VLAN_EGRESS_MAP, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*idx < g_slist_length (list)*");
+ ASSERT_UNCHANGED (nm_setting_vlan_remove_priority (s_vlan, NM_VLAN_EGRESS_MAP, 1));
+ g_test_assert_expected_messages ();
+ ASSERT_CHANGED (nm_setting_vlan_add_priority_str (s_vlan, NM_VLAN_EGRESS_MAP, "1:3"));
+ ASSERT_CHANGED (nm_setting_vlan_clear_priorities (s_vlan, NM_VLAN_EGRESS_MAP));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_vpn_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingVPN *s_vpn;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_vpn = (NMSettingVPN *) nm_setting_vpn_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_vpn));
+
+ ASSERT_CHANGED (nm_setting_vpn_add_data_item (s_vpn, "foobar", "baz"));
+ ASSERT_CHANGED (nm_setting_vpn_remove_data_item (s_vpn, "foobar"));
+ ASSERT_UNCHANGED (nm_setting_vpn_remove_data_item (s_vpn, "not added"));
+
+ ASSERT_CHANGED (nm_setting_vpn_add_secret (s_vpn, "foobar", "baz"));
+ ASSERT_CHANGED (nm_setting_vpn_remove_secret (s_vpn, "foobar"));
+ ASSERT_UNCHANGED (nm_setting_vpn_remove_secret (s_vpn, "not added"));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_wired_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingWired *s_wired;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_wired = (NMSettingWired *) nm_setting_wired_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wired));
+
+ ASSERT_CHANGED (nm_setting_wired_add_s390_option (s_wired, "portno", "1"));
+ ASSERT_CHANGED (nm_setting_wired_remove_s390_option (s_wired, "portno"));
+ ASSERT_UNCHANGED (nm_setting_wired_remove_s390_option (s_wired, "layer2"));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_wireless_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingWireless *s_wifi;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wifi));
+
+ ASSERT_CHANGED (nm_setting_wireless_add_seen_bssid (s_wifi, "00:11:22:33:44:55"));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_wireless_security_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSettingWirelessSecurity *s_wsec;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+
+ /* Protos */
+ ASSERT_CHANGED (nm_setting_wireless_security_add_proto (s_wsec, "wpa"));
+ ASSERT_CHANGED (nm_setting_wireless_security_remove_proto (s_wsec, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_wireless_security_remove_proto (s_wsec, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_wireless_security_add_proto (s_wsec, "wep");
+ ASSERT_CHANGED (nm_setting_wireless_security_clear_protos (s_wsec));
+
+ /* Pairwise ciphers */
+ ASSERT_CHANGED (nm_setting_wireless_security_add_pairwise (s_wsec, "tkip"));
+ ASSERT_CHANGED (nm_setting_wireless_security_remove_pairwise (s_wsec, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_wireless_security_remove_pairwise (s_wsec, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_wireless_security_add_pairwise (s_wsec, "tkip");
+ ASSERT_CHANGED (nm_setting_wireless_security_clear_pairwise (s_wsec));
+
+ /* Group ciphers */
+ ASSERT_CHANGED (nm_setting_wireless_security_add_group (s_wsec, "ccmp"));
+ ASSERT_CHANGED (nm_setting_wireless_security_remove_group (s_wsec, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_wireless_security_remove_group (s_wsec, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_wireless_security_add_group (s_wsec, "tkip");
+ ASSERT_CHANGED (nm_setting_wireless_security_clear_groups (s_wsec));
+
+ /* WEP key secret flags */
+ ASSERT_CHANGED (g_assert (nm_setting_set_secret_flags (NM_SETTING (s_wsec), "wep-key0", NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL)));
+ ASSERT_CHANGED (g_assert (nm_setting_set_secret_flags (NM_SETTING (s_wsec), "wep-key1", NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL)));
+ ASSERT_CHANGED (g_assert (nm_setting_set_secret_flags (NM_SETTING (s_wsec), "wep-key2", NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL)));
+ ASSERT_CHANGED (g_assert (nm_setting_set_secret_flags (NM_SETTING (s_wsec), "wep-key3", NM_SETTING_SECRET_FLAG_AGENT_OWNED, NULL)));
+
+ g_object_unref (connection);
+}
+
+static void
+test_setting_802_1x_changed_signal (void)
+{
+ NMConnection *connection;
+ gboolean changed = FALSE;
+ NMSetting8021x *s_8021x;
+
+ connection = nm_connection_new ();
+ g_signal_connect (connection,
+ NM_CONNECTION_CHANGED,
+ (GCallback) test_connection_changed_cb,
+ &changed);
+
+ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_8021x));
+
+ /* EAP methods */
+ ASSERT_CHANGED (nm_setting_802_1x_add_eap_method (s_8021x, "tls"));
+ ASSERT_CHANGED (nm_setting_802_1x_remove_eap_method (s_8021x, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_802_1x_remove_eap_method (s_8021x, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_802_1x_add_eap_method (s_8021x, "ttls");
+ ASSERT_CHANGED (nm_setting_802_1x_clear_eap_methods (s_8021x));
+
+ /* alternate subject matches */
+ ASSERT_CHANGED (nm_setting_802_1x_add_altsubject_match (s_8021x, "EMAIL:server@example.com"));
+ ASSERT_CHANGED (nm_setting_802_1x_remove_altsubject_match (s_8021x, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_802_1x_remove_altsubject_match (s_8021x, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_802_1x_add_altsubject_match (s_8021x, "EMAIL:server@example.com");
+ ASSERT_CHANGED (nm_setting_802_1x_clear_altsubject_matches (s_8021x));
+
+ /* phase2 alternate subject matches */
+ ASSERT_CHANGED (nm_setting_802_1x_add_phase2_altsubject_match (s_8021x, "EMAIL:server@example.com"));
+ ASSERT_CHANGED (nm_setting_802_1x_remove_phase2_altsubject_match (s_8021x, 0));
+ g_test_expect_message ("libnm-util", G_LOG_LEVEL_CRITICAL, "*elt != NULL*");
+ ASSERT_UNCHANGED (nm_setting_802_1x_remove_phase2_altsubject_match (s_8021x, 1));
+ g_test_assert_expected_messages ();
+
+ nm_setting_802_1x_add_phase2_altsubject_match (s_8021x, "EMAIL:server@example.com");
+ ASSERT_CHANGED (nm_setting_802_1x_clear_phase2_altsubject_matches (s_8021x));
+
+ g_object_unref (connection);
+}
+
static void
test_setting_old_uuid (void)
{
@@ -1445,20 +2484,19 @@ test_setting_old_uuid (void)
g_assert (success == TRUE);
}
+NMTST_DEFINE ();
+
int main (int argc, char **argv)
{
- GError *error = NULL;
char *base;
- g_type_init ();
-
- if (!nm_utils_init (&error))
- FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
+ nmtst_init (&argc, &argv, TRUE);
/* The tests */
test_setting_vpn_items ();
test_setting_vpn_update_secrets ();
test_setting_vpn_modify_during_foreach ();
+ test_setting_ip4_config_labels ();
test_setting_ip6_config_old_address_array ();
test_setting_gsm_apn_spaces ();
test_setting_gsm_apn_bad_chars ();
@@ -1479,12 +2517,25 @@ int main (int argc, char **argv)
test_setting_old_uuid ();
test_connection_to_hash_setting_name ();
+ test_setting_new_from_hash ();
+ test_connection_replace_settings ();
+ test_connection_replace_settings_from_connection ();
+ test_connection_new_from_hash ();
+
test_setting_connection_permissions_helpers ();
test_setting_connection_permissions_property ();
+
+ test_connection_compare_same ();
+ test_connection_compare_key_only_in_a ();
+ test_connection_compare_setting_only_in_a ();
+ test_connection_compare_key_only_in_b ();
+ test_connection_compare_setting_only_in_b ();
+
test_connection_diff_a_only ();
test_connection_diff_same ();
test_connection_diff_different ();
test_connection_diff_no_secrets ();
+ test_connection_diff_inferrable ();
test_connection_good_base_types ();
test_connection_bad_base_types ();
@@ -1495,6 +2546,18 @@ int main (int argc, char **argv)
test_ip4_prefix_to_netmask ();
test_ip4_netmask_to_prefix ();
+ test_connection_changed_signal ();
+ test_setting_connection_changed_signal ();
+ test_setting_bond_changed_signal ();
+ test_setting_ip4_changed_signal ();
+ test_setting_ip6_changed_signal ();
+ test_setting_vlan_changed_signal ();
+ test_setting_vpn_changed_signal ();
+ test_setting_wired_changed_signal ();
+ test_setting_wireless_changed_signal ();
+ test_setting_wireless_security_changed_signal ();
+ test_setting_802_1x_changed_signal ();
+
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
g_free (base);
diff --git a/libnm-util/tests/test-secrets.c b/libnm-util/tests/test-secrets.c
index 0e859abcc..73fc9224b 100644
--- a/libnm-util/tests/test-secrets.c
+++ b/libnm-util/tests/test-secrets.c
@@ -22,7 +22,6 @@
#include <glib.h>
#include <string.h>
-#include "nm-test-helpers.h"
#include <nm-utils.h>
#include "nm-setting-connection.h"
@@ -37,6 +36,7 @@
#include "nm-setting-pppoe.h"
#include "nm-setting-vpn.h"
+#include "nm-test-utils.h"
#define TEST_NEED_SECRETS_EAP_TLS_CA_CERT TEST_CERT_DIR "/test_ca_cert.pem"
#define TEST_NEED_SECRETS_EAP_TLS_CLIENT_CERT TEST_CERT_DIR "/test_key_and_cert.pem"
@@ -67,14 +67,9 @@ make_tls_connection (const char *detail, NMSetting8021xCKScheme scheme)
GError *error = NULL;
connection = nm_connection_new ();
- ASSERT (connection != NULL,
- detail, "failed to allocate new connection");
/* Connection setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
- ASSERT (s_con != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_CONNECTION_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
@@ -88,16 +83,10 @@ make_tls_connection (const char *detail, NMSetting8021xCKScheme scheme)
/* Wired setting */
s_wired = (NMSettingWired *) nm_setting_wired_new ();
- ASSERT (s_wired != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_WIRED_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* Wireless security setting */
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
- ASSERT (s_8021x != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_802_1X_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
g_object_set (s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL);
@@ -134,9 +123,6 @@ make_tls_connection (const char *detail, NMSetting8021xCKScheme scheme)
/* IP4 setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
- ASSERT (s_ip4 != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_IP4_CONFIG_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
@@ -247,14 +233,9 @@ make_tls_phase2_connection (const char *detail, NMSetting8021xCKScheme scheme)
GError *error = NULL;
connection = nm_connection_new ();
- ASSERT (connection != NULL,
- detail, "failed to allocate new connection");
/* Connection setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
- ASSERT (s_con != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_CONNECTION_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
@@ -268,16 +249,10 @@ make_tls_phase2_connection (const char *detail, NMSetting8021xCKScheme scheme)
/* Wired setting */
s_wired = (NMSettingWired *) nm_setting_wired_new ();
- ASSERT (s_wired != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_WIRED_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_wired));
/* Wireless security setting */
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
- ASSERT (s_8021x != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_802_1X_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_8021x));
g_object_set (s_8021x, NM_SETTING_802_1X_ANONYMOUS_IDENTITY, "blahblah", NULL);
@@ -316,9 +291,6 @@ make_tls_phase2_connection (const char *detail, NMSetting8021xCKScheme scheme)
/* IP4 setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
- ASSERT (s_ip4 != NULL,
- detail, "failed to allocate new %s setting",
- NM_SETTING_IP4_CONFIG_SETTING_NAME);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
@@ -454,7 +426,6 @@ wifi_connection_new (void)
g_byte_array_append (ssid, &tmpssid[0], sizeof (tmpssid));
g_object_set (s_wifi,
NM_SETTING_WIRELESS_SSID, ssid,
- NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
NULL);
g_byte_array_free (ssid, TRUE);
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
@@ -512,6 +483,8 @@ test_update_secrets_wifi_single_setting (void)
const char *wepkey = "11111111111111111111111111";
const char *tmp;
+ /* Test update with a hashed setting of 802-11-wireless secrets */
+
connection = wifi_connection_new ();
/* Build up the secrets hash */
@@ -546,6 +519,10 @@ test_update_secrets_wifi_full_hash (void)
const char *wepkey = "11111111111111111111111111";
const char *tmp;
+ /* Test update with a hashed connection containing only 802-11-wireless
+ * setting and secrets.
+ */
+
connection = wifi_connection_new ();
/* Build up the secrets hash */
@@ -580,6 +557,10 @@ test_update_secrets_wifi_bad_setting_name (void)
gboolean success;
const char *wepkey = "11111111111111111111111111";
+ /* Test that passing an invalid setting name to
+ * nm_connection_update_secrets() fails with the correct error.
+ */
+
connection = wifi_connection_new ();
/* Build up the secrets hash */
@@ -607,6 +588,10 @@ test_update_secrets_whole_connection (void)
gboolean success;
const char *wepkey = "11111111111111111111111111";
+ /* Test calling nm_connection_update_secrets() with an entire hashed
+ * connection including non-secrets.
+ */
+
connection = wifi_connection_new ();
/* Build up the secrets hash */
@@ -634,6 +619,8 @@ test_update_secrets_whole_connection_empty_hash (void)
GError *error = NULL;
gboolean success;
+ /* Test that updating secrets with an empty hash returns success */
+
connection = wifi_connection_new ();
secrets = g_hash_table_new (g_str_hash, g_str_equal);
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
@@ -651,6 +638,10 @@ test_update_secrets_whole_connection_bad_setting (void)
gboolean success;
const char *wepkey = "11111111111111111111111111";
+ /* Test that sending a hashed connection containing an invalid setting
+ * name fails with the right error.
+ */
+
connection = wifi_connection_new ();
/* Build up the secrets hash */
@@ -674,12 +665,67 @@ test_update_secrets_whole_connection_bad_setting (void)
g_object_unref (connection);
}
+static void
+test_update_secrets_whole_connection_empty_base_setting (void)
+{
+ NMConnection *connection;
+ GHashTable *secrets;
+ GError *error = NULL;
+ gboolean success;
+
+ /* Test that a hashed connection which does not have any hashed secrets
+ * for the requested setting returns success.
+ */
+
+ connection = wifi_connection_new ();
+ secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ONLY_SECRETS);
+ g_assert_cmpint (g_hash_table_size (secrets), ==, 1);
+ g_assert (g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SETTING_NAME));
+
+ success = nm_connection_update_secrets (connection,
+ NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+ secrets,
+ &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ g_hash_table_destroy (secrets);
+ g_object_unref (connection);
+}
+
+static void
+test_update_secrets_null_setting_name_with_setting_hash (void)
+{
+ NMConnection *connection;
+ GHashTable *secrets;
+ GError *error = NULL;
+ gboolean success;
+ const char *wepkey = "11111111111111111111111111";
+
+ /* Ensure that a NULL setting name and only a hashed setting fails */
+
+ connection = wifi_connection_new ();
+
+ secrets = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
+ g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
+ g_hash_table_insert (secrets, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, uint_to_gvalue (NM_WEP_KEY_TYPE_KEY));
+
+ success = nm_connection_update_secrets (connection, NULL, secrets, &error);
+ g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
+ g_assert (!success);
+
+ g_hash_table_destroy (secrets);
+ g_object_unref (connection);
+}
+
int main (int argc, char **argv)
{
GError *error = NULL;
char *base;
+#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
+#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
@@ -697,6 +743,8 @@ int main (int argc, char **argv)
test_update_secrets_whole_connection ();
test_update_secrets_whole_connection_empty_hash ();
test_update_secrets_whole_connection_bad_setting ();
+ test_update_secrets_whole_connection_empty_base_setting ();
+ test_update_secrets_null_setting_name_with_setting_hash ();
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
diff --git a/libnm-util/tests/test-setting-8021x.c b/libnm-util/tests/test-setting-8021x.c
index bdfc8e036..62889c61f 100644
--- a/libnm-util/tests/test-setting-8021x.c
+++ b/libnm-util/tests/test-setting-8021x.c
@@ -22,12 +22,13 @@
#include <glib.h>
#include <string.h>
-#include "nm-test-helpers.h"
#include <nm-utils.h>
#include "nm-setting-connection.h"
#include "nm-setting-8021x.h"
+#include "nm-test-utils.h"
+
static void
compare_blob_data (const char *test,
const char *key_path,
@@ -411,7 +412,9 @@ int main (int argc, char **argv)
if (argc < 3)
FAIL ("init", "need at least two arguments: <path> <password>");
+#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
+#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
diff --git a/libnm-util/tests/test-setting-dcb.c b/libnm-util/tests/test-setting-dcb.c
new file mode 100644
index 000000000..de07f2c2a
--- /dev/null
+++ b/libnm-util/tests/test-setting-dcb.c
@@ -0,0 +1,328 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ */
+
+#include <glib.h>
+#include <string.h>
+#include <nm-utils.h>
+#include <nm-glib-compat.h>
+#include "nm-setting-dcb.h"
+
+#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
+ NM_SETTING_DCB_FLAG_ADVERTISE | \
+ NM_SETTING_DCB_FLAG_WILLING)
+
+static void
+test_dcb_flags_valid (void)
+{
+ NMSettingDcb *s_dcb;
+ GError *error = NULL;
+ gboolean success;
+ guint i;
+
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ g_assert (s_dcb);
+
+ g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, 0);
+ g_assert_cmpint (nm_setting_dcb_get_app_iscsi_flags (s_dcb), ==, 0);
+ g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, 0);
+ g_assert_cmpint (nm_setting_dcb_get_priority_flow_control_flags (s_dcb), ==, 0);
+ g_assert_cmpint (nm_setting_dcb_get_priority_group_flags (s_dcb), ==, 0);
+
+ g_object_set (G_OBJECT (s_dcb),
+ NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL,
+ NM_SETTING_DCB_APP_ISCSI_FLAGS, DCB_FLAGS_ALL,
+ NM_SETTING_DCB_APP_FIP_FLAGS, DCB_FLAGS_ALL,
+ NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, DCB_FLAGS_ALL,
+ NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, DCB_FLAGS_ALL,
+ NULL);
+ /* Priority Group Bandwidth must total 100% */
+ for (i = 0; i < 7; i++)
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, 12);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16);
+
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ g_assert_cmpint (nm_setting_dcb_get_app_fcoe_flags (s_dcb), ==, DCB_FLAGS_ALL);
+ g_assert_cmpint (nm_setting_dcb_get_app_iscsi_flags (s_dcb), ==, DCB_FLAGS_ALL);
+ g_assert_cmpint (nm_setting_dcb_get_app_fip_flags (s_dcb), ==, DCB_FLAGS_ALL);
+ g_assert_cmpint (nm_setting_dcb_get_priority_flow_control_flags (s_dcb), ==, DCB_FLAGS_ALL);
+ g_assert_cmpint (nm_setting_dcb_get_priority_group_flags (s_dcb), ==, DCB_FLAGS_ALL);
+}
+
+#define TEST_FLAG(p, f, v) \
+{ \
+ /* GObject property min/max should ensure the property does not get set to \
+ * the invalid value, so we ensure the value we just tried to set is 0 and \
+ * that verify is successful since the property never got set. \
+ */ \
+ g_object_set (G_OBJECT (s_dcb), p, v, NULL); \
+ g_assert_cmpint (f (s_dcb), ==, 0); \
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
+ g_assert_no_error (error); \
+ g_assert (success); \
+}
+
+static void
+test_dcb_flags_invalid (void)
+{
+ NMSettingDcb *s_dcb;
+ GError *error = NULL;
+ gboolean success;
+
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ g_assert (s_dcb);
+
+ g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
+ TEST_FLAG (NM_SETTING_DCB_APP_FCOE_FLAGS, nm_setting_dcb_get_app_fcoe_flags, 0x332523);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
+ TEST_FLAG (NM_SETTING_DCB_APP_ISCSI_FLAGS, nm_setting_dcb_get_app_iscsi_flags, 0xFF);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
+ TEST_FLAG (NM_SETTING_DCB_APP_FIP_FLAGS, nm_setting_dcb_get_app_fip_flags, 0x1111);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
+ TEST_FLAG (NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, nm_setting_dcb_get_priority_flow_control_flags, G_MAXUINT32);
+ g_test_assert_expected_messages ();
+
+ g_test_expect_message ("GLib-GObject", G_LOG_LEVEL_WARNING, "*invalid or out of range*");
+ TEST_FLAG (NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, nm_setting_dcb_get_priority_group_flags,
+ (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) + 1);
+ g_test_assert_expected_messages ();
+}
+
+#define TEST_APP_PRIORITY(lcprop, ucprop, v) \
+{ \
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_FLAGS, NM_SETTING_DCB_FLAG_NONE, NULL); \
+ \
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_PRIORITY, v, NULL); \
+ g_assert_cmpint (nm_setting_dcb_get_app_##lcprop##_priority (s_dcb), ==, v); \
+ \
+ /* Assert that the setting is invalid while the app is disabled unless v is default */ \
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
+ if (v >= 0) { \
+ g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY); \
+ g_assert (success == FALSE); \
+ } else { \
+ g_assert_no_error (error); \
+ g_assert (success); \
+ } \
+ g_clear_error (&error); \
+ \
+ /* Set the enable flag and re-verify, this time it should be valid */ \
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL); \
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
+ g_assert_no_error (error); \
+ g_assert (success); \
+ \
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_APP_##ucprop##_PRIORITY, 0, NULL); \
+}
+
+static void
+test_dcb_app_priorities (void)
+{
+ NMSettingDcb *s_dcb;
+ GError *error = NULL;
+ gboolean success;
+
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ g_assert (s_dcb);
+
+ /* Defaults */
+ g_assert_cmpint (nm_setting_dcb_get_app_fcoe_priority (s_dcb), ==, -1);
+ g_assert_cmpint (nm_setting_dcb_get_app_iscsi_priority (s_dcb), ==, -1);
+ g_assert_cmpint (nm_setting_dcb_get_app_fip_priority (s_dcb), ==, -1);
+
+ TEST_APP_PRIORITY (fcoe, FCOE, 6);
+ TEST_APP_PRIORITY (iscsi, ISCSI, 5);
+ TEST_APP_PRIORITY (fip, FIP, 4);
+
+ TEST_APP_PRIORITY (fcoe, FCOE, -1);
+ TEST_APP_PRIORITY (iscsi, ISCSI, -1);
+ TEST_APP_PRIORITY (fip, FIP, -1);
+}
+
+#define TEST_PRIORITY_VALID(fn, id, val, flagsprop, verify) \
+{ \
+ /* Assert that setting the value gets the same value back out */ \
+ nm_setting_dcb_set_priority_##fn (s_dcb, id, val); \
+ g_assert_cmpint (nm_setting_dcb_get_priority_##fn (s_dcb, id), ==, val); \
+ \
+ if (verify) { \
+ if (val != 0) { \
+ /* Assert that verify fails because the flags do not include 'enabled' \
+ * and a value has been set. \
+ */ \
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
+ g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY); \
+ g_assert (success == FALSE); \
+ g_clear_error (&error); \
+ } \
+ \
+ /* Assert that adding the 'enabled' flag verifies the setting */ \
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_##flagsprop##_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL); \
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error); \
+ g_assert_no_error (error); \
+ g_assert (success); \
+ } \
+ \
+ /* Reset everything */ \
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_##flagsprop##_FLAGS, NM_SETTING_DCB_FLAG_NONE, NULL); \
+ nm_setting_dcb_set_priority_##fn (s_dcb, id, 0); \
+}
+
+/* If Priority Groups are enabled, PG bandwidth must equal 100% */
+#define SET_VALID_PRIORITY_GROUP_BANDWIDTH \
+{ \
+ guint x; \
+ for (x = 0; x < 7; x++) \
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, x, 12); \
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16); \
+}
+
+static void
+test_dcb_priorities_valid (void)
+{
+ NMSettingDcb *s_dcb;
+ GError *error = NULL;
+ gboolean success;
+ guint i;
+
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ g_assert (s_dcb);
+
+ for (i = 0; i < 8; i++)
+ TEST_PRIORITY_VALID (flow_control, i, TRUE, FLOW_CONTROL, TRUE);
+
+ SET_VALID_PRIORITY_GROUP_BANDWIDTH
+ for (i = 0; i < 8; i++) {
+ TEST_PRIORITY_VALID (group_id, i, i, GROUP, TRUE);
+ TEST_PRIORITY_VALID (group_id, i, 7 - i, GROUP, TRUE);
+ }
+
+ /* Clear PG bandwidth from earlier tests */
+ for (i = 0; i < 8; i++)
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, i, 0);
+
+ /* Priority Group Bandwidth must add up to 100% if enabled, which requires
+ * some dancing for verifying individual values here.
+ */
+ for (i = 0; i < 8; i++) {
+ guint other = 7 - (i % 8);
+
+ /* Set another priority group to the remaining bandwidth */
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 100 - i);
+ TEST_PRIORITY_VALID (group_bandwidth, i, i, GROUP, TRUE);
+
+ /* Set another priority group to the remaining bandwidth */
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 100 - (7 - i));
+ TEST_PRIORITY_VALID (group_bandwidth, i, 7 - i, GROUP, TRUE);
+
+ /* Clear remaining bandwidth */
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, other, 0);
+ }
+
+ SET_VALID_PRIORITY_GROUP_BANDWIDTH
+ for (i = 0; i < 8; i++) {
+ TEST_PRIORITY_VALID (bandwidth, i, i, GROUP, TRUE);
+ TEST_PRIORITY_VALID (bandwidth, i, 7 - i, GROUP, TRUE);
+ }
+
+ SET_VALID_PRIORITY_GROUP_BANDWIDTH
+ for (i = 0; i < 8; i++)
+ TEST_PRIORITY_VALID (strict_bandwidth, i, TRUE, GROUP, TRUE);
+
+ SET_VALID_PRIORITY_GROUP_BANDWIDTH
+ for (i = 0; i < 8; i++) {
+ TEST_PRIORITY_VALID (traffic_class, i, i, GROUP, TRUE);
+ TEST_PRIORITY_VALID (traffic_class, i, 7 - i, GROUP, TRUE);
+ }
+}
+
+static void
+test_dcb_bandwidth_sums (void)
+{
+ NMSettingDcb *s_dcb;
+ GError *error = NULL;
+ gboolean success;
+
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ g_assert (s_dcb);
+
+ /* Assert that setting the value gets the same value back out */
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 0, 9);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 1, 10);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 2, 11);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 3, 12);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 13);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 5, 14);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 6, 15);
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 7, 16);
+
+ /* Assert verify success when sums total 100% */
+ g_object_set (G_OBJECT (s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, NM_SETTING_DCB_FLAG_ENABLE, NULL);
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+ /* Assert verify fails when sums do not total 100% */
+ nm_setting_dcb_set_priority_group_bandwidth (s_dcb, 4, 20);
+ success = nm_setting_verify (NM_SETTING (s_dcb), NULL, &error);
+ g_assert_error (error, NM_SETTING_DCB_ERROR, NM_SETTING_DCB_ERROR_INVALID_PROPERTY);
+ g_assert (success == FALSE);
+ g_clear_error (&error);
+}
+
+#define TPATH "/libnm-util/settings/dcb/"
+
+int main (int argc, char **argv)
+{
+ GError *error = NULL;
+ gboolean success;
+
+ g_test_init (&argc, &argv, NULL);
+
+#if !GLIB_CHECK_VERSION (2, 35, 0)
+ g_type_init ();
+#endif
+
+ success = nm_utils_init (&error);
+ g_assert_no_error (error);
+ g_assert (success);
+
+#if !GLIB_CHECK_VERSION(2,34,0)
+ g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
+#endif
+
+ g_test_add_func (TPATH "flags-valid", test_dcb_flags_valid);
+ g_test_add_func (TPATH "flags-invalid", test_dcb_flags_invalid);
+ g_test_add_func (TPATH "app-priorities", test_dcb_app_priorities);
+ g_test_add_func (TPATH "priorities", test_dcb_priorities_valid);
+ g_test_add_func (TPATH "bandwidth-sums", test_dcb_bandwidth_sums);
+
+ return g_test_run ();
+}
+
diff --git a/libnm-util/tests/test-settings-defaults.c b/libnm-util/tests/test-settings-defaults.c
index b77ddfef9..15412fed5 100644
--- a/libnm-util/tests/test-settings-defaults.c
+++ b/libnm-util/tests/test-settings-defaults.c
@@ -22,7 +22,6 @@
#include <glib.h>
#include <string.h>
-#include "nm-test-helpers.h"
#include <nm-utils.h>
#include "nm-setting-8021x.h"
@@ -39,6 +38,7 @@
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
+#include "nm-test-utils.h"
static void
test_defaults (GType type, const char *name)
@@ -57,8 +57,8 @@ test_defaults (GType type, const char *name)
for (i = 0; i < n_property_specs; i++) {
GParamSpec *prop_spec = property_specs[i];
- GValue value = { 0, };
- GValue defvalue = { 0, };
+ GValue value = G_VALUE_INIT;
+ GValue defvalue = G_VALUE_INIT;
char *actual, *expected;
gboolean ok = FALSE;
@@ -104,7 +104,9 @@ int main (int argc, char **argv)
GError *error = NULL;
char *base;
+#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
+#endif
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);