summaryrefslogtreecommitdiff
path: root/src/libcharon/tests
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2018-09-24 15:11:25 +0200
committerYves-Alexis Perez <corsac@debian.org>2018-09-24 15:11:25 +0200
commit7152c3439f3decbb6366d94464d3c089674c8c30 (patch)
tree48bfe66e31226d55914868bc0558f479e2a22a36 /src/libcharon/tests
parentc2ac4e0da62d859085148d8518d558402e1f9a8c (diff)
parente0e280b7669435b991b7e457abd8aa450930b3e8 (diff)
downloadvyos-strongswan-7152c3439f3decbb6366d94464d3c089674c8c30.tar.gz
vyos-strongswan-7152c3439f3decbb6366d94464d3c089674c8c30.zip
Update upstream source from tag 'upstream/5.7.0'
Update to upstream version '5.7.0' with Debian dir b608300a1e1f88db62d14d08a55ca09f3603f054
Diffstat (limited to 'src/libcharon/tests')
-rw-r--r--src/libcharon/tests/Makefile.am2
-rw-r--r--src/libcharon/tests/Makefile.in49
-rw-r--r--src/libcharon/tests/libcharon_tests.h1
-rw-r--r--src/libcharon/tests/suites/test_peer_cfg.c229
-rw-r--r--src/libcharon/tests/utils/exchange_test_helper.c4
-rw-r--r--src/libcharon/tests/utils/mock_net.c115
-rw-r--r--src/libcharon/tests/utils/mock_net.h36
7 files changed, 430 insertions, 6 deletions
diff --git a/src/libcharon/tests/Makefile.am b/src/libcharon/tests/Makefile.am
index 5ebd0456c..101b534f0 100644
--- a/src/libcharon/tests/Makefile.am
+++ b/src/libcharon/tests/Makefile.am
@@ -4,6 +4,7 @@ check_PROGRAMS = $(TESTS)
libcharon_tests_SOURCES = \
suites/test_ike_cfg.c \
+ suites/test_peer_cfg.c \
suites/test_mem_pool.c \
suites/test_message_chapoly.c \
libcharon_tests.h libcharon_tests.c
@@ -35,6 +36,7 @@ exchange_tests_SOURCES = \
utils/job_asserts.h \
utils/mock_dh.h utils/mock_dh.c \
utils/mock_ipsec.h utils/mock_ipsec.c \
+ utils/mock_net.h utils/mock_net.c \
utils/mock_nonce_gen.h utils/mock_nonce_gen.c \
utils/mock_sender.h utils/mock_sender.c \
utils/sa_asserts.h \
diff --git a/src/libcharon/tests/Makefile.in b/src/libcharon/tests/Makefile.in
index 24552d201..c545c6334 100644
--- a/src/libcharon/tests/Makefile.in
+++ b/src/libcharon/tests/Makefile.in
@@ -121,6 +121,7 @@ am_exchange_tests_OBJECTS = \
utils/exchange_tests-exchange_test_helper.$(OBJEXT) \
utils/exchange_tests-mock_dh.$(OBJEXT) \
utils/exchange_tests-mock_ipsec.$(OBJEXT) \
+ utils/exchange_tests-mock_net.$(OBJEXT) \
utils/exchange_tests-mock_nonce_gen.$(OBJEXT) \
utils/exchange_tests-mock_sender.$(OBJEXT) \
exchange_tests-exchange_tests.$(OBJEXT)
@@ -139,6 +140,7 @@ exchange_tests_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(LDFLAGS) -o $@
am_libcharon_tests_OBJECTS = \
suites/libcharon_tests-test_ike_cfg.$(OBJEXT) \
+ suites/libcharon_tests-test_peer_cfg.$(OBJEXT) \
suites/libcharon_tests-test_mem_pool.$(OBJEXT) \
suites/libcharon_tests-test_message_chapoly.$(OBJEXT) \
libcharon_tests-libcharon_tests.$(OBJEXT)
@@ -334,7 +336,6 @@ PYTHON_VERSION = @PYTHON_VERSION@
PY_TEST = @PY_TEST@
RANLIB = @RANLIB@
RTLIB = @RTLIB@
-RUBY = @RUBY@
RUBYGEMDIR = @RUBYGEMDIR@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -360,6 +361,8 @@ am__tar = @am__tar@
am__untar = @am__untar@
attest_plugins = @attest_plugins@
bindir = @bindir@
+botan_CFLAGS = @botan_CFLAGS@
+botan_LIBS = @botan_LIBS@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
@@ -380,8 +383,6 @@ dvidir = @dvidir@
exec_prefix = @exec_prefix@
fips_mode = @fips_mode@
fuzz_plugins = @fuzz_plugins@
-gtk_CFLAGS = @gtk_CFLAGS@
-gtk_LIBS = @gtk_LIBS@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
@@ -436,8 +437,6 @@ random_device = @random_device@
resolv_conf = @resolv_conf@
routing_table = @routing_table@
routing_table_prio = @routing_table_prio@
-ruby_CFLAGS = @ruby_CFLAGS@
-ruby_LIBS = @ruby_LIBS@
runstatedir = @runstatedir@
s_plugins = @s_plugins@
sbindir = @sbindir@
@@ -466,8 +465,12 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
tss2_CFLAGS = @tss2_CFLAGS@
tss2_LIBS = @tss2_LIBS@
+tss2_esys_CFLAGS = @tss2_esys_CFLAGS@
+tss2_esys_LIBS = @tss2_esys_LIBS@
tss2_socket_CFLAGS = @tss2_socket_CFLAGS@
tss2_socket_LIBS = @tss2_socket_LIBS@
+tss2_sys_CFLAGS = @tss2_sys_CFLAGS@
+tss2_sys_LIBS = @tss2_sys_LIBS@
tss2_tabrmd_CFLAGS = @tss2_tabrmd_CFLAGS@
tss2_tabrmd_LIBS = @tss2_tabrmd_LIBS@
urandom_device = @urandom_device@
@@ -475,6 +478,7 @@ xml_CFLAGS = @xml_CFLAGS@
xml_LIBS = @xml_LIBS@
libcharon_tests_SOURCES = \
suites/test_ike_cfg.c \
+ suites/test_peer_cfg.c \
suites/test_mem_pool.c \
suites/test_message_chapoly.c \
libcharon_tests.h libcharon_tests.c
@@ -505,6 +509,7 @@ exchange_tests_SOURCES = \
utils/job_asserts.h \
utils/mock_dh.h utils/mock_dh.c \
utils/mock_ipsec.h utils/mock_ipsec.c \
+ utils/mock_net.h utils/mock_net.c \
utils/mock_nonce_gen.h utils/mock_nonce_gen.c \
utils/mock_sender.h utils/mock_sender.c \
utils/sa_asserts.h \
@@ -598,6 +603,8 @@ utils/exchange_tests-mock_dh.$(OBJEXT): utils/$(am__dirstamp) \
utils/$(DEPDIR)/$(am__dirstamp)
utils/exchange_tests-mock_ipsec.$(OBJEXT): utils/$(am__dirstamp) \
utils/$(DEPDIR)/$(am__dirstamp)
+utils/exchange_tests-mock_net.$(OBJEXT): utils/$(am__dirstamp) \
+ utils/$(DEPDIR)/$(am__dirstamp)
utils/exchange_tests-mock_nonce_gen.$(OBJEXT): utils/$(am__dirstamp) \
utils/$(DEPDIR)/$(am__dirstamp)
utils/exchange_tests-mock_sender.$(OBJEXT): utils/$(am__dirstamp) \
@@ -608,6 +615,8 @@ exchange_tests$(EXEEXT): $(exchange_tests_OBJECTS) $(exchange_tests_DEPENDENCIES
$(AM_V_CCLD)$(exchange_tests_LINK) $(exchange_tests_OBJECTS) $(exchange_tests_LDADD) $(LIBS)
suites/libcharon_tests-test_ike_cfg.$(OBJEXT): suites/$(am__dirstamp) \
suites/$(DEPDIR)/$(am__dirstamp)
+suites/libcharon_tests-test_peer_cfg.$(OBJEXT): \
+ suites/$(am__dirstamp) suites/$(DEPDIR)/$(am__dirstamp)
suites/libcharon_tests-test_mem_pool.$(OBJEXT): \
suites/$(am__dirstamp) suites/$(DEPDIR)/$(am__dirstamp)
suites/libcharon_tests-test_message_chapoly.$(OBJEXT): \
@@ -636,10 +645,12 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@suites/$(DEPDIR)/libcharon_tests-test_ike_cfg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@suites/$(DEPDIR)/libcharon_tests-test_mem_pool.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@suites/$(DEPDIR)/libcharon_tests-test_message_chapoly.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-exchange_test_asserts.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-exchange_test_helper.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-mock_dh.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-mock_ipsec.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-mock_net.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-mock_nonce_gen.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@utils/$(DEPDIR)/exchange_tests-mock_sender.Po@am__quote@
@@ -807,6 +818,20 @@ utils/exchange_tests-mock_ipsec.obj: utils/mock_ipsec.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(exchange_tests_CFLAGS) $(CFLAGS) -c -o utils/exchange_tests-mock_ipsec.obj `if test -f 'utils/mock_ipsec.c'; then $(CYGPATH_W) 'utils/mock_ipsec.c'; else $(CYGPATH_W) '$(srcdir)/utils/mock_ipsec.c'; fi`
+utils/exchange_tests-mock_net.o: utils/mock_net.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(exchange_tests_CFLAGS) $(CFLAGS) -MT utils/exchange_tests-mock_net.o -MD -MP -MF utils/$(DEPDIR)/exchange_tests-mock_net.Tpo -c -o utils/exchange_tests-mock_net.o `test -f 'utils/mock_net.c' || echo '$(srcdir)/'`utils/mock_net.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) utils/$(DEPDIR)/exchange_tests-mock_net.Tpo utils/$(DEPDIR)/exchange_tests-mock_net.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utils/mock_net.c' object='utils/exchange_tests-mock_net.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(exchange_tests_CFLAGS) $(CFLAGS) -c -o utils/exchange_tests-mock_net.o `test -f 'utils/mock_net.c' || echo '$(srcdir)/'`utils/mock_net.c
+
+utils/exchange_tests-mock_net.obj: utils/mock_net.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(exchange_tests_CFLAGS) $(CFLAGS) -MT utils/exchange_tests-mock_net.obj -MD -MP -MF utils/$(DEPDIR)/exchange_tests-mock_net.Tpo -c -o utils/exchange_tests-mock_net.obj `if test -f 'utils/mock_net.c'; then $(CYGPATH_W) 'utils/mock_net.c'; else $(CYGPATH_W) '$(srcdir)/utils/mock_net.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) utils/$(DEPDIR)/exchange_tests-mock_net.Tpo utils/$(DEPDIR)/exchange_tests-mock_net.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='utils/mock_net.c' object='utils/exchange_tests-mock_net.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(exchange_tests_CFLAGS) $(CFLAGS) -c -o utils/exchange_tests-mock_net.obj `if test -f 'utils/mock_net.c'; then $(CYGPATH_W) 'utils/mock_net.c'; else $(CYGPATH_W) '$(srcdir)/utils/mock_net.c'; fi`
+
utils/exchange_tests-mock_nonce_gen.o: utils/mock_nonce_gen.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(exchange_tests_CFLAGS) $(CFLAGS) -MT utils/exchange_tests-mock_nonce_gen.o -MD -MP -MF utils/$(DEPDIR)/exchange_tests-mock_nonce_gen.Tpo -c -o utils/exchange_tests-mock_nonce_gen.o `test -f 'utils/mock_nonce_gen.c' || echo '$(srcdir)/'`utils/mock_nonce_gen.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) utils/$(DEPDIR)/exchange_tests-mock_nonce_gen.Tpo utils/$(DEPDIR)/exchange_tests-mock_nonce_gen.Po
@@ -863,6 +888,20 @@ suites/libcharon_tests-test_ike_cfg.obj: suites/test_ike_cfg.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcharon_tests_CFLAGS) $(CFLAGS) -c -o suites/libcharon_tests-test_ike_cfg.obj `if test -f 'suites/test_ike_cfg.c'; then $(CYGPATH_W) 'suites/test_ike_cfg.c'; else $(CYGPATH_W) '$(srcdir)/suites/test_ike_cfg.c'; fi`
+suites/libcharon_tests-test_peer_cfg.o: suites/test_peer_cfg.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcharon_tests_CFLAGS) $(CFLAGS) -MT suites/libcharon_tests-test_peer_cfg.o -MD -MP -MF suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Tpo -c -o suites/libcharon_tests-test_peer_cfg.o `test -f 'suites/test_peer_cfg.c' || echo '$(srcdir)/'`suites/test_peer_cfg.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Tpo suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='suites/test_peer_cfg.c' object='suites/libcharon_tests-test_peer_cfg.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcharon_tests_CFLAGS) $(CFLAGS) -c -o suites/libcharon_tests-test_peer_cfg.o `test -f 'suites/test_peer_cfg.c' || echo '$(srcdir)/'`suites/test_peer_cfg.c
+
+suites/libcharon_tests-test_peer_cfg.obj: suites/test_peer_cfg.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcharon_tests_CFLAGS) $(CFLAGS) -MT suites/libcharon_tests-test_peer_cfg.obj -MD -MP -MF suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Tpo -c -o suites/libcharon_tests-test_peer_cfg.obj `if test -f 'suites/test_peer_cfg.c'; then $(CYGPATH_W) 'suites/test_peer_cfg.c'; else $(CYGPATH_W) '$(srcdir)/suites/test_peer_cfg.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Tpo suites/$(DEPDIR)/libcharon_tests-test_peer_cfg.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='suites/test_peer_cfg.c' object='suites/libcharon_tests-test_peer_cfg.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcharon_tests_CFLAGS) $(CFLAGS) -c -o suites/libcharon_tests-test_peer_cfg.obj `if test -f 'suites/test_peer_cfg.c'; then $(CYGPATH_W) 'suites/test_peer_cfg.c'; else $(CYGPATH_W) '$(srcdir)/suites/test_peer_cfg.c'; fi`
+
suites/libcharon_tests-test_mem_pool.o: suites/test_mem_pool.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcharon_tests_CFLAGS) $(CFLAGS) -MT suites/libcharon_tests-test_mem_pool.o -MD -MP -MF suites/$(DEPDIR)/libcharon_tests-test_mem_pool.Tpo -c -o suites/libcharon_tests-test_mem_pool.o `test -f 'suites/test_mem_pool.c' || echo '$(srcdir)/'`suites/test_mem_pool.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) suites/$(DEPDIR)/libcharon_tests-test_mem_pool.Tpo suites/$(DEPDIR)/libcharon_tests-test_mem_pool.Po
diff --git a/src/libcharon/tests/libcharon_tests.h b/src/libcharon/tests/libcharon_tests.h
index d17ea041d..bc0521a75 100644
--- a/src/libcharon/tests/libcharon_tests.h
+++ b/src/libcharon/tests/libcharon_tests.h
@@ -25,5 +25,6 @@
*/
TEST_SUITE(ike_cfg_suite_create)
+TEST_SUITE(peer_cfg_suite_create)
TEST_SUITE(mem_pool_suite_create)
TEST_SUITE_DEPEND(message_chapoly_suite_create, AEAD, ENCR_CHACHA20_POLY1305, 32)
diff --git a/src/libcharon/tests/suites/test_peer_cfg.c b/src/libcharon/tests/suites/test_peer_cfg.c
new file mode 100644
index 000000000..02e38a314
--- /dev/null
+++ b/src/libcharon/tests/suites/test_peer_cfg.c
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include "test_suite.h"
+
+#include <config/peer_cfg.h>
+#include <config/child_cfg.h>
+
+/**
+ * Create a simple IKE config
+ */
+static ike_cfg_t *create_ike_cfg()
+{
+ return ike_cfg_create(IKEV2, TRUE, FALSE, "127.0.0.1", 500,
+ "127.0.0.1", 500, FRAGMENTATION_NO, 0);
+}
+
+/**
+ * Create a simple peer config
+ */
+static peer_cfg_t *create_peer_cfg()
+{
+ peer_cfg_create_t peer = {};
+
+ return peer_cfg_create("peer", create_ike_cfg(), &peer);
+}
+
+static peer_cfg_t *peer_a, *peer_b;
+
+START_SETUP(setup_replace)
+{
+ peer_a = create_peer_cfg();
+ peer_b = create_peer_cfg();
+}
+END_SETUP
+
+START_TEARDOWN(teardown_replace)
+{
+ peer_a->destroy(peer_a);
+ peer_b->destroy(peer_b);
+}
+END_TEARDOWN
+
+/**
+ * Check if the changes are correctly reported
+ * All given objects are destroyed
+ */
+static void test_replace(enumerator_t *changes, linked_list_t *rem,
+ linked_list_t *add)
+{
+ child_cfg_t *child;
+ bool added;
+
+ while (changes->enumerate(changes, &child, &added))
+ {
+ if (added)
+ {
+ ck_assert_msg(add->remove(add, child, NULL) == 1, "child config "
+ "was unexpectedly added");
+ }
+ else
+ {
+ ck_assert_msg(rem->remove(rem, child, NULL) == 1, "child config "
+ "was unexpectedly removed");
+ }
+ }
+ changes->destroy(changes);
+ ck_assert_msg(!rem->get_count(rem), "expected child config was not removed");
+ ck_assert_msg(!add->get_count(add), "expected child config was not added");
+ rem->destroy(rem);
+ add->destroy(add);
+}
+
+/**
+ * Check if the given child configs are contained in the peer config
+ * The list is destroyed
+ */
+static void test_child_cfgs(peer_cfg_t *peer, linked_list_t *children)
+{
+ enumerator_t *enumerator;
+ child_cfg_t *child;
+
+ enumerator = peer->create_child_cfg_enumerator(peer);
+ while (enumerator->enumerate(enumerator, &child))
+ {
+ ck_assert_msg(children->remove(children, child, NULL) == 1, "child "
+ "config was unexpectedly contained in peer config");
+ }
+ enumerator->destroy(enumerator);
+ ck_assert_msg(!children->get_count(children), "expected child config was "
+ "not contained in peer config");
+ children->destroy(children);
+}
+
+START_TEST(replace_child_cfgs_empty)
+{
+ child_cfg_create_t cfg = {};
+ child_cfg_t *child;
+
+ child = child_cfg_create("c", &cfg);
+ peer_b->add_child_cfg(peer_b, child->get_ref(child));
+
+ test_replace(peer_a->replace_child_cfgs(peer_a, peer_b),
+ linked_list_create(),
+ linked_list_create_with_items(child, NULL));
+ test_child_cfgs(peer_a,
+ linked_list_create_with_items(child, NULL));
+
+ child->destroy(child);
+}
+END_TEST
+
+START_TEST(replace_child_cfgs_same)
+{
+ child_cfg_create_t cfg = {};
+ child_cfg_t *child;
+
+ child = child_cfg_create("c", &cfg);
+ peer_a->add_child_cfg(peer_a, child->get_ref(child));
+ peer_b->add_child_cfg(peer_b, child->get_ref(child));
+
+ test_replace(peer_a->replace_child_cfgs(peer_a, peer_b),
+ linked_list_create(),
+ linked_list_create());
+ test_child_cfgs(peer_a,
+ linked_list_create_with_items(child, NULL));
+
+ child->destroy(child);
+}
+END_TEST
+
+START_TEST(replace_child_cfgs_same_replace)
+{
+ child_cfg_create_t cfg = {};
+ child_cfg_t *c1, *c2;
+
+ c1 = child_cfg_create("c1", &cfg);
+ peer_a->add_child_cfg(peer_a, c1->get_ref(c1));
+ c2 = child_cfg_create("c2", &cfg);
+ peer_b->add_child_cfg(peer_b, c2->get_ref(c2));
+
+ test_replace(peer_a->replace_child_cfgs(peer_a, peer_b),
+ linked_list_create(),
+ linked_list_create());
+ test_child_cfgs(peer_a,
+ linked_list_create_with_items(c2, NULL));
+
+ c1->destroy(c1);
+ c2->destroy(c2);
+}
+END_TEST
+
+START_TEST(replace_child_cfgs_clear)
+{
+ child_cfg_create_t cfg = {};
+ child_cfg_t *child;
+
+ child = child_cfg_create("c", &cfg);
+ peer_a->add_child_cfg(peer_a, child->get_ref(child));
+
+ test_replace(peer_a->replace_child_cfgs(peer_a, peer_b),
+ linked_list_create_with_items(child, NULL),
+ linked_list_create());
+ test_child_cfgs(peer_a,
+ linked_list_create());
+
+ child->destroy(child);
+}
+END_TEST
+
+START_TEST(replace_child_cfgs_mixed)
+{
+ child_cfg_create_t cfg1 = {}, cfg2 = { .mode = MODE_TUNNEL, };
+ child_cfg_create_t cfg3 = { .mode = MODE_TRANSPORT};
+ child_cfg_t *c1, *c2, *c3, *c4;
+
+ c1 = child_cfg_create("c1", &cfg1);
+ peer_a->add_child_cfg(peer_a, c1->get_ref(c1));
+ c2 = child_cfg_create("c2", &cfg2);
+ peer_a->add_child_cfg(peer_a, c2->get_ref(c2));
+
+ c3 = child_cfg_create("c3", &cfg3);
+ peer_b->add_child_cfg(peer_b, c3->get_ref(c3));
+ c4 = child_cfg_create("c4", &cfg2);
+ peer_b->add_child_cfg(peer_b, c4->get_ref(c4));
+
+ test_replace(peer_a->replace_child_cfgs(peer_a, peer_b),
+ linked_list_create_with_items(c1, NULL),
+ linked_list_create_with_items(c3, NULL));
+ test_child_cfgs(peer_a,
+ linked_list_create_with_items(c3, c4, NULL));
+
+ c1->destroy(c1);
+ c2->destroy(c2);
+ c3->destroy(c3);
+ c4->destroy(c4);
+}
+END_TEST
+
+Suite *peer_cfg_suite_create()
+{
+ Suite *s;
+ TCase *tc;
+
+ s = suite_create("peer_cfg");
+
+ tc = tcase_create("replace_child_cfgs");
+ tcase_add_checked_fixture(tc, setup_replace, teardown_replace);
+ tcase_add_test(tc, replace_child_cfgs_empty);
+ tcase_add_test(tc, replace_child_cfgs_same);
+ tcase_add_test(tc, replace_child_cfgs_same_replace);
+ tcase_add_test(tc, replace_child_cfgs_clear);
+ tcase_add_test(tc, replace_child_cfgs_mixed);
+ suite_add_tcase(s, tc);
+
+ return s;
+}
diff --git a/src/libcharon/tests/utils/exchange_test_helper.c b/src/libcharon/tests/utils/exchange_test_helper.c
index fce0ccedf..bebf33463 100644
--- a/src/libcharon/tests/utils/exchange_test_helper.c
+++ b/src/libcharon/tests/utils/exchange_test_helper.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 Tobias Brunner
+ * Copyright (C) 2016-2018 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -16,6 +16,7 @@
#include "exchange_test_helper.h"
#include "mock_dh.h"
#include "mock_ipsec.h"
+#include "mock_net.h"
#include "mock_nonce_gen.h"
#include <collections/array.h>
@@ -333,6 +334,7 @@ void exchange_test_helper_init(char *plugins)
/* and there is no kernel plugin loaded
* TODO: we'd have more control if we'd implement kernel_interface_t */
charon->kernel->add_ipsec_interface(charon->kernel, mock_ipsec_create);
+ charon->kernel->add_net_interface(charon->kernel, mock_net_create);
/* like SPIs for IPsec SAs, make IKE SPIs predictable */
charon->ike_sa_manager->set_spi_cb(charon->ike_sa_manager, get_ike_spi,
this);
diff --git a/src/libcharon/tests/utils/mock_net.c b/src/libcharon/tests/utils/mock_net.c
new file mode 100644
index 000000000..5b560871e
--- /dev/null
+++ b/src/libcharon/tests/utils/mock_net.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include "mock_net.h"
+
+#include <daemon.h>
+
+#include <assert.h>
+
+typedef struct private_kernel_net_t private_kernel_net_t;
+
+/**
+ * Private data
+ */
+struct private_kernel_net_t {
+
+ /**
+ * Public interface
+ */
+ kernel_net_t public;
+
+ /**
+ * Local IP address
+ */
+ host_t *host;
+};
+
+/**
+ * Global instance
+ */
+static private_kernel_net_t *instance;
+
+METHOD(kernel_net_t, get_source_addr, host_t*,
+ private_kernel_net_t *this, host_t *dest, host_t *src)
+{
+ return this->host->clone(this->host);
+}
+
+METHOD(kernel_net_t, get_nexthop, host_t*,
+ private_kernel_net_t *this, host_t *dest, int prefix, host_t *src,
+ char **iface)
+{
+ if (iface)
+ {
+ *iface = strdup("lo");
+ }
+ return this->host->clone(this->host);
+}
+
+METHOD(kernel_net_t, get_interface, bool,
+ private_kernel_net_t *this, host_t *host, char **name)
+{
+ if (host->ip_equals(host, this->host))
+ {
+ if (name)
+ {
+ *name = strdup("lo");
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+METHOD(kernel_net_t, create_address_enumerator, enumerator_t*,
+ private_kernel_net_t *this, kernel_address_type_t which)
+{
+ return enumerator_create_single(this->host, NULL);
+}
+
+METHOD(kernel_net_t, destroy, void,
+ private_kernel_net_t *this)
+{
+ this->host->destroy(this->host);
+ free(this);
+}
+
+/*
+ * Described in header
+ */
+kernel_net_t *mock_net_create()
+{
+ private_kernel_net_t *this;
+
+ INIT(this,
+ .public = {
+ .get_source_addr = _get_source_addr,
+ .get_nexthop = _get_nexthop,
+ .get_interface = _get_interface,
+ .create_address_enumerator = _create_address_enumerator,
+ .create_local_subnet_enumerator = (void*)enumerator_create_empty,
+ .add_ip = (void*)return_failed,
+ .del_ip = (void*)return_failed,
+ .add_route = (void*)return_failed,
+ .del_route = (void*)return_failed,
+ .destroy = _destroy,
+ },
+ .host = host_create_from_string("127.0.0.1", 500),
+ );
+
+ instance = this;
+
+ return &this->public;
+}
diff --git a/src/libcharon/tests/utils/mock_net.h b/src/libcharon/tests/utils/mock_net.h
new file mode 100644
index 000000000..15ad1ac0c
--- /dev/null
+++ b/src/libcharon/tests/utils/mock_net.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2018 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+/**
+ * kernel_net_t implementation used for exchange unit tests. Simply returns
+ * an IP address so it seems we're connected.
+ *
+ * @defgroup mock_net mock_net
+ * @{ @ingroup test_utils_c
+ */
+
+#ifndef MOCK_NET_H_
+#define MOCK_NET_H_
+
+#include <kernel/kernel_net.h>
+
+/**
+ * Create an instance of kernel_net_t
+ *
+ * @return created object
+ */
+kernel_net_t *mock_net_create();
+
+#endif /** MOCK_NET_H_ @}*/