summaryrefslogtreecommitdiff
path: root/src/libstrongswan/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/tests')
-rw-r--r--src/libstrongswan/tests/Makefile.in11
-rw-r--r--src/libstrongswan/tests/suites/test_identification.c6
-rw-r--r--src/libstrongswan/tests/suites/test_linked_list_enumerator.c68
-rw-r--r--src/libstrongswan/tests/suites/test_printf.c2
-rw-r--r--src/libstrongswan/tests/suites/test_proposal.c34
-rw-r--r--src/libstrongswan/tests/suites/test_rsa.c2
-rw-r--r--src/libstrongswan/tests/suites/test_settings.c423
-rw-r--r--src/libstrongswan/tests/suites/test_utils.c94
8 files changed, 568 insertions, 72 deletions
diff --git a/src/libstrongswan/tests/Makefile.in b/src/libstrongswan/tests/Makefile.in
index 20cb27cf3..82bb640a8 100644
--- a/src/libstrongswan/tests/Makefile.in
+++ b/src/libstrongswan/tests/Makefile.in
@@ -354,7 +354,6 @@ PYTHON_VERSION = @PYTHON_VERSION@
PY_TEST = @PY_TEST@
RANLIB = @RANLIB@
RTLIB = @RTLIB@
-RUBY = @RUBY@
RUBYGEMDIR = @RUBYGEMDIR@
SED = @SED@
SET_MAKE = @SET_MAKE@
@@ -380,6 +379,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@
@@ -400,8 +401,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@
@@ -456,8 +455,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@
@@ -486,8 +483,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@
diff --git a/src/libstrongswan/tests/suites/test_identification.c b/src/libstrongswan/tests/suites/test_identification.c
index c0a21fe34..4b2202431 100644
--- a/src/libstrongswan/tests/suites/test_identification.c
+++ b/src/libstrongswan/tests/suites/test_identification.c
@@ -234,6 +234,12 @@ static struct {
.data.c = chunk_from_chars(0xc0,0xa8,0x01,0x01) }},
{ "email:tester", ID_RFC822_ADDR, { .type = ENC_STRING,
.data.s = "tester" }},
+ {"xmppaddr:bob@strongswan.org", ID_DER_ASN1_GN, { .type = ENC_CHUNK,
+ .data.c = chunk_from_chars(0xa0,0x20,0x06,0x08,0x2b,0x06,0x01,0x05,
+ 0x05,0x07,0x08,0x05,0xa0,0x14,0x0c,0x12,
+ 0x62,0x6f,0x62,0x40,0x73,0x74,0x72,0x6f,
+ 0x6e,0x67,0x73,0x77,0x61,0x6e,0x2e,0x6f,
+ 0x72,0x67) }},
{ "{1}:#c0a80101", ID_IPV4_ADDR, { .type = ENC_CHUNK,
.data.c = chunk_from_chars(0xc0,0xa8,0x01,0x01) }},
{ "{0x02}:tester", ID_FQDN, { .type = ENC_STRING,
diff --git a/src/libstrongswan/tests/suites/test_linked_list_enumerator.c b/src/libstrongswan/tests/suites/test_linked_list_enumerator.c
index 19f381ef3..30b7b5c11 100644
--- a/src/libstrongswan/tests/suites/test_linked_list_enumerator.c
+++ b/src/libstrongswan/tests/suites/test_linked_list_enumerator.c
@@ -144,11 +144,12 @@ START_TEST(test_insert_before_ends)
int round;
enumerator = list->create_enumerator(list);
+ /* this does not change the enumerator position, which points to 1 */
list->insert_before(list, enumerator, (void*)0);
ck_assert_int_eq(list->get_count(list), 6);
ck_assert(list->get_first(list, (void*)&x) == SUCCESS);
ck_assert_int_eq(x, 0);
- round = 0;
+ round = 1;
while (enumerator->enumerate(enumerator, &x))
{
ck_assert_int_eq(round, x);
@@ -177,8 +178,13 @@ START_TEST(test_insert_before_empty)
ck_assert_int_eq(x, 1);
ck_assert(list->get_last(list, (void*)&x) == SUCCESS);
ck_assert_int_eq(x, 1);
- ck_assert(enumerator->enumerate(enumerator, &x));
+ ck_assert(!enumerator->enumerate(enumerator, &x));
+ list->insert_before(list, enumerator, (void*)2);
+ ck_assert_int_eq(list->get_count(list), 2);
+ ck_assert(list->get_first(list, (void*)&x) == SUCCESS);
ck_assert_int_eq(x, 1);
+ ck_assert(list->get_last(list, (void*)&x) == SUCCESS);
+ ck_assert_int_eq(x, 2);
ck_assert(!enumerator->enumerate(enumerator, NULL));
enumerator->destroy(enumerator);
}
@@ -221,6 +227,43 @@ START_TEST(test_remove_at)
}
END_TEST
+START_TEST(test_remove_at_multi)
+{
+ enumerator_t *enumerator;
+ intptr_t x;
+ int round;
+
+ round = 1;
+ enumerator = list->create_enumerator(list);
+ while (enumerator->enumerate(enumerator, &x))
+ {
+ ck_assert_int_eq(round, x);
+ if (round == 2 || round == 5)
+ {
+ list->remove_at(list, enumerator);
+ }
+ round++;
+ }
+ ck_assert_int_eq(list->get_count(list), 3);
+ list->reset_enumerator(list, enumerator);
+ round = 1;
+ while (enumerator->enumerate(enumerator, &x))
+ {
+ if (round == 2)
+ { /* skip removed item */
+ round++;
+ }
+ ck_assert_int_eq(round, x);
+ list->remove_at(list, enumerator);
+ round++;
+ }
+ ck_assert_int_eq(list->get_count(list), 0);
+ list->reset_enumerator(list, enumerator);
+ ck_assert(!enumerator->enumerate(enumerator, &x));
+ enumerator->destroy(enumerator);
+}
+END_TEST
+
START_TEST(test_remove_at_ends)
{
enumerator_t *enumerator;
@@ -228,14 +271,14 @@ START_TEST(test_remove_at_ends)
enumerator = list->create_enumerator(list);
list->remove_at(list, enumerator);
- ck_assert_int_eq(list->get_count(list), 5);
+ ck_assert_int_eq(list->get_count(list), 4);
ck_assert(list->get_first(list, (void*)&x) == SUCCESS);
- ck_assert_int_eq(x, 1);
+ ck_assert_int_eq(x, 2);
while (enumerator->enumerate(enumerator, &x))
{
}
list->remove_at(list, enumerator);
- ck_assert_int_eq(list->get_count(list), 5);
+ ck_assert_int_eq(list->get_count(list), 4);
ck_assert(list->get_last(list, (void*)&x) == SUCCESS);
ck_assert_int_eq(x, 5);
enumerator->destroy(enumerator);
@@ -254,14 +297,12 @@ START_TEST(test_insert_before_remove_at)
{
ck_assert_int_eq(round, x);
if (round == 2)
- { /* this replaces the current item, as insert_before does not change
- * the enumerator position */
+ { /* this replaces the current item */
list->insert_before(list, enumerator, (void*)42);
list->remove_at(list, enumerator);
}
else if (round == 4)
- { /* this does not replace the item, as remove_at moves the enumerator
- * position to the previous item */
+ { /* same here, the order of calls does not matter */
list->remove_at(list, enumerator);
list->insert_before(list, enumerator, (void*)21);
}
@@ -276,13 +317,9 @@ START_TEST(test_insert_before_remove_at)
{ /* check replaced item */
ck_assert_int_eq(42, x);
}
- else if (round == 3)
- { /* check misplaced item */
- ck_assert_int_eq(21, x);
- }
else if (round == 4)
- { /* check misplaced item */
- ck_assert_int_eq(3, x);
+ { /* check replace item */
+ ck_assert_int_eq(21, x);
}
else
{
@@ -348,6 +385,7 @@ Suite *linked_list_enumerator_suite_create()
tc = tcase_create("modify");
tcase_add_checked_fixture(tc, setup_list, teardown_list);
tcase_add_test(tc, test_remove_at);
+ tcase_add_test(tc, test_remove_at_multi);
tcase_add_test(tc, test_remove_at_ends);
tcase_add_test(tc, test_insert_before_remove_at);
suite_add_tcase(s, tc);
diff --git a/src/libstrongswan/tests/suites/test_printf.c b/src/libstrongswan/tests/suites/test_printf.c
index 377f2a767..ac2b858bb 100644
--- a/src/libstrongswan/tests/suites/test_printf.c
+++ b/src/libstrongswan/tests/suites/test_printf.c
@@ -204,7 +204,7 @@ Suite *printf_suite_create()
tcase_add_test(tc, test_printf_err);
suite_add_tcase(s, tc);
- tc = tcase_create("unsiged");
+ tc = tcase_create("unsigned");
tcase_add_test(tc, test_printf_unsigned);
suite_add_tcase(s, tc);
diff --git a/src/libstrongswan/tests/suites/test_proposal.c b/src/libstrongswan/tests/suites/test_proposal.c
index 938fa38aa..099cd19c7 100644
--- a/src/libstrongswan/tests/suites/test_proposal.c
+++ b/src/libstrongswan/tests/suites/test_proposal.c
@@ -102,7 +102,12 @@ static struct {
{ PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256", "aes128-sha256" },
{ PROTO_ESP, "aes128-sha256", "aes128-sha256-modp3072-modpnone", "aes128-sha256" },
{ PROTO_ESP, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072" },
- { PROTO_ESP, "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modpnone" },
+ { PROTO_ESP, "aes128-sha256-modpnone-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256" },
+ { PROTO_ESP, "aes128-sha256-esn", "aes128-sha256-esn", "aes128-sha256-esn" },
+ { PROTO_ESP, "aes128-sha256-noesn", "aes128-sha256-esn", NULL },
+ { PROTO_ESP, "aes128-sha256-noesn-esn", "aes128-sha256-esn", "aes128-sha256-esn" },
+ { PROTO_ESP, "aes128-sha256-noesn-esn", "aes128-sha256", "aes128-sha256" },
+ { PROTO_ESP, "aes128-sha256-esn-noesn", "aes128-sha256-noesn-esn", "aes128-sha256-esn" },
{ PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072", "aes128-sha256-modp3072" },
{ PROTO_IKE, "aes128-sha256-modp3072", "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072" },
{ PROTO_IKE, "aes128-sha256-modp3072-modpnone", "aes128-sha256-modp3072", "aes128-sha256-modp3072" },
@@ -159,6 +164,29 @@ START_TEST(test_select_spi)
}
END_TEST
+START_TEST(test_matches)
+{
+ proposal_t *self, *other;
+
+ self = proposal_create_from_string(select_data[_i].proto,
+ select_data[_i].self);
+ other = proposal_create_from_string(select_data[_i].proto,
+ select_data[_i].other);
+ if (select_data[_i].expected)
+ {
+ ck_assert(self->matches(self, other, FALSE));
+ ck_assert(other->matches(other, self, FALSE));
+ }
+ else
+ {
+ ck_assert(!self->matches(self, other, FALSE));
+ ck_assert(!other->matches(other, self, FALSE));
+ }
+ other->destroy(other);
+ self->destroy(self);
+}
+END_TEST
+
START_TEST(test_promote_dh_group)
{
proposal_t *proposal;
@@ -312,6 +340,10 @@ Suite *proposal_suite_create()
tcase_add_test(tc, test_select_spi);
suite_add_tcase(s, tc);
+ tc = tcase_create("matches");
+ tcase_add_loop_test(tc, test_matches, 0, countof(select_data));
+ suite_add_tcase(s, tc);
+
tc = tcase_create("promote_dh_group");
tcase_add_test(tc, test_promote_dh_group);
tcase_add_test(tc, test_promote_dh_group_already_front);
diff --git a/src/libstrongswan/tests/suites/test_rsa.c b/src/libstrongswan/tests/suites/test_rsa.c
index 3f6353404..e6dc7744a 100644
--- a/src/libstrongswan/tests/suites/test_rsa.c
+++ b/src/libstrongswan/tests/suites/test_rsa.c
@@ -146,7 +146,7 @@ static void test_bad_sigs(public_key_t *pubkey)
* RSA key sizes to test
*/
static int key_sizes[] = {
- 768, 1024, 1536, 2048, 3072, 4096,
+ 1024, 1536, 2048, 3072, 4096,
};
START_TEST(test_gen)
diff --git a/src/libstrongswan/tests/suites/test_settings.c b/src/libstrongswan/tests/suites/test_settings.c
index 0759f7013..e0609605c 100644
--- a/src/libstrongswan/tests/suites/test_settings.c
+++ b/src/libstrongswan/tests/suites/test_settings.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 Tobias Brunner
+ * Copyright (C) 2014-2018 Tobias Brunner
* HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -452,9 +452,10 @@ static void verify_sections(linked_list_t *verifier, char *parent)
enumerator = settings->create_section_enumerator(settings, parent);
ver = verifier->create_enumerator(verifier);
- while (enumerator->enumerate(enumerator, &section) &&
- ver->enumerate(ver, &current))
+ while (enumerator->enumerate(enumerator, &section))
{
+ ck_assert_msg(ver->enumerate(ver, &current),
+ "no more sections expected, found %s", section);
ck_assert_str_eq(section, current);
verifier->remove_at(verifier, ver);
}
@@ -498,10 +499,11 @@ static void verify_key_values(linked_list_t *keys, linked_list_t *values,
enumerator = settings->create_key_value_enumerator(settings, parent);
enum_keys = keys->create_enumerator(keys);
enum_values = values->create_enumerator(values);
- while (enumerator->enumerate(enumerator, &key, &value) &&
- enum_keys->enumerate(enum_keys, &current_key) &&
- enum_values->enumerate(enum_values, &current_value))
+ while (enumerator->enumerate(enumerator, &key, &value))
{
+ ck_assert_msg(enum_keys->enumerate(enum_keys, &current_key),
+ "no more key/value expected, found %s = %s", key, value);
+ ck_assert(enum_values->enumerate(enum_values, &current_value));
ck_assert_str_eq(current_key, key);
ck_assert_str_eq(current_value, value);
keys->remove_at(keys, enum_keys);
@@ -519,8 +521,8 @@ START_TEST(test_key_value_enumerator)
{
linked_list_t *keys, *values;
- keys = linked_list_create_with_items("key1", "key2", "empty", "key3", NULL);
- values = linked_list_create_with_items("val1", "with space", "", "string with\nnewline", NULL);
+ keys = linked_list_create_with_items("key1", "key2", "empty", "key3", "key4", "key5", NULL);
+ values = linked_list_create_with_items("val1", "with space", "", "string with\nnewline", "multi line\nstring", "escaped newline", NULL);
verify_key_values(keys, values, "main");
keys = linked_list_create_with_items("key", "key2", "subsub", NULL);
@@ -894,7 +896,6 @@ START_TEST(test_load_string)
}
END_TEST
-
START_TEST(test_load_string_section)
{
char *content =
@@ -914,13 +915,6 @@ START_TEST(test_load_string_section)
ck_assert(settings->load_string_section(settings, include_content2, TRUE, "main.sub1"));
verify_include();
- /* invalid strings are a failure */
- ck_assert(!settings->load_string_section(settings, "conf {", TRUE, ""));
- /* NULL or empty strings are OK though */
- ck_assert(settings->load_string_section(settings, "", TRUE, ""));
- ck_assert(settings->load_string_section(settings, NULL, TRUE, ""));
- verify_include();
-
ck_assert(settings->load_string_section(settings, include_content2, FALSE, "main"));
verify_null("main.key1");
verify_string("v2", "main.key2");
@@ -934,6 +928,56 @@ START_TEST(test_load_string_section)
}
END_TEST
+START_TEST(test_load_string_section_null)
+{
+ linked_list_t *keys, *values;
+
+ char *content =
+ "main {\n"
+ " key1 = val1\n"
+ " key2 = val2\n"
+ " none = x\n"
+ " sub1 {\n"
+ " include = value\n"
+ " key2 = value2\n"
+ " }\n"
+ "}";
+
+ settings = settings_create_string(content);
+
+ ck_assert(settings->load_string_section(settings, include_content1, TRUE, ""));
+ ck_assert(settings->load_string_section(settings, include_content2, TRUE, "main.sub1"));
+ verify_include();
+
+ /* invalid strings are a failure */
+ ck_assert(!settings->load_string_section(settings, "conf {", TRUE, ""));
+ /* NULL or empty strings are OK though when merging */
+ ck_assert(settings->load_string_section(settings, "", TRUE, ""));
+ ck_assert(settings->load_string_section(settings, NULL, TRUE, ""));
+ verify_include();
+
+ /* they do purge the settings if merge is not TRUE */
+ ck_assert(settings->load_string_section(settings, "", FALSE, "main"));
+ verify_null("main.key1");
+ verify_null("main.sub1.key2");
+
+ keys = linked_list_create_with_items(NULL);
+ verify_sections(keys, "main");
+
+ keys = linked_list_create_with_items(NULL);
+ values = linked_list_create_with_items(NULL);
+ verify_key_values(keys, values, "main");
+
+ keys = linked_list_create_with_items("main", NULL);
+ verify_sections(keys, "");
+
+ ck_assert(settings->load_string_section(settings, NULL, FALSE, ""));
+
+ keys = linked_list_create_with_items(NULL);
+ verify_sections(keys, "");
+}
+END_TEST
+
START_SETUP(setup_fallback_config)
{
create_settings(chunk_from_str(
@@ -1037,6 +1081,50 @@ START_TEST(test_add_fallback)
}
END_TEST
+START_TEST(test_fallback_resolution)
+{
+ linked_list_t *keys, *values;
+
+ settings->destroy(settings);
+ create_settings(chunk_from_str(
+ "base {\n"
+ " sub {\n"
+ " key1 = val1\n"
+ " key2 = val2\n"
+ " key5 = val5\n"
+ " subsub {\n"
+ " subkey1 = subval1\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ "other {\n"
+ " sub {\n"
+ " key3 = val3\n"
+ " key4 = val4\n"
+ " }\n"
+ "}\n"
+ "main {\n"
+ " sub {\n"
+ " key4=\n"
+ " key5 = \n"
+ " }\n"
+ "}"));
+
+ settings->add_fallback(settings, "other", "base");
+ settings->add_fallback(settings, "main.sub", "other.sub");
+
+ verify_string("val1", "main.sub.key1");
+ verify_string("val3", "main.sub.key3");
+ verify_null("main.sub.key4");
+ verify_null("main.sub.key5");
+ verify_string("subval1", "main.sub.subsub.subkey1");
+
+ keys = linked_list_create_with_items("key3", "key1", "key2", NULL);
+ values = linked_list_create_with_items("val3", "val1", "val2", NULL);
+ verify_key_values(keys, values, "main.sub");
+}
+END_TEST
+
START_TEST(test_add_fallback_printf)
{
settings->add_fallback(settings, "%s.sub1", "sub", "main");
@@ -1051,6 +1139,264 @@ START_TEST(test_add_fallback_printf)
}
END_TEST
+START_TEST(test_references)
+{
+ linked_list_t *keys, *values;
+
+ create_settings(chunk_from_str(
+ "main {\n"
+ " sub1 {\n"
+ " key1 = sub1val1\n"
+ " key2 = sub1val2\n"
+ " key4 = sub1val4\n"
+ " subsub {\n"
+ " subkey1 = sub1subsubval1\n"
+ " subkey2 = sub1subsubval2\n"
+ " }\n"
+ " subsub1 {\n"
+ " subkey1 = sub1subsub1val1\n"
+ " }\n"
+ " }\n"
+ " sub2 : main.sub1 {\n"
+ " key2 = sub2val2\n"
+ " key3 = sub2val3\n"
+ " key4 =\n"
+ " subsub {\n"
+ " subkey1 = sub2subsubval1\n"
+ " subkey3 = sub2subsubval3\n"
+ " }\n"
+ " }\n"
+ "}"));
+
+ verify_string("sub1val1", "main.sub2.key1");
+ verify_string("sub2val2", "main.sub2.key2");
+ verify_string("sub2val3", "main.sub2.key3");
+ verify_null("main.sub2.key4");
+ verify_string("sub2subsubval1", "main.sub2.subsub.subkey1");
+ verify_string("sub1subsubval2", "main.sub2.subsub.subkey2");
+ verify_string("sub2subsubval3", "main.sub2.subsub.subkey3");
+ verify_string("sub1subsub1val1", "main.sub2.subsub1.subkey1");
+
+ keys = linked_list_create_with_items("subsub", "subsub1", NULL);
+ verify_sections(keys, "main.sub2");
+
+ keys = linked_list_create_with_items("key2", "key3", "key1", NULL);
+ values = linked_list_create_with_items("sub2val2", "sub2val3", "sub1val1", NULL);
+ verify_key_values(keys, values, "main.sub2");
+
+ keys = linked_list_create_with_items("subkey1", "subkey3", "subkey2", NULL);
+ values = linked_list_create_with_items("sub2subsubval1", "sub2subsubval3", "sub1subsubval2", NULL);
+ verify_key_values(keys, values, "main.sub2.subsub");
+}
+END_TEST
+
+START_TEST(test_references_templates)
+{
+ create_settings(chunk_from_str(
+ "sub-def {\n"
+ " key1 = sub1val1\n"
+ " key2 = sub1val2\n"
+ " subsub {\n"
+ " subkey1 = sub1subsubval1\n"
+ " }\n"
+ "}\n"
+ "subsub-def {\n"
+ " subkey1 = sub1subval1\n"
+ " subkey2 = sub1subval1\n"
+ "}\n"
+ "main {\n"
+ " sub1 : sub-def {\n"
+ " key1 = mainsub1val1\n"
+ " subsub : subsub-def {\n"
+ " subkey1 = mainsub1subval1\n"
+ " }\n"
+ " subsub1 {\n"
+ " subkey1 = mainsub1sub1val1\n"
+ " }\n"
+ " }\n"
+ " sub2 : sub-def {\n"
+ " key2 = mainsub2val2\n"
+ " key3 = mainsub2val3\n"
+ " subsub {\n"
+ " subkey3 = mainsub2subsubval3\n"
+ " }\n"
+ " }\n"
+ "}"));
+
+ verify_string("mainsub1val1", "main.sub1.key1");
+ verify_string("sub1val2", "main.sub1.key2");
+ verify_string("mainsub1subval1", "main.sub1.subsub.subkey1");
+ verify_string("sub1subval1", "main.sub1.subsub.subkey2");
+ verify_string("mainsub1sub1val1", "main.sub1.subsub1.subkey1");
+ verify_string("sub1val1", "main.sub2.key1");
+ verify_string("mainsub2val2", "main.sub2.key2");
+ verify_string("mainsub2val3", "main.sub2.key3");
+ verify_string("sub1subsubval1", "main.sub2.subsub.subkey1");
+ verify_null("main.sub2.subsub.subkey2");
+ verify_string("mainsub2subsubval3", "main.sub2.subsub.subkey3");
+}
+END_TEST
+
+START_TEST(test_references_order)
+{
+ linked_list_t *keys, *values;
+
+ create_settings(chunk_from_str(
+ "main {\n"
+ " sub1 {\n"
+ " key1 = sub1val1\n"
+ " key2 = sub1val2\n"
+ " subsub1 {\n"
+ " }\n"
+ " }\n"
+ " sub2 {\n"
+ " key2 = sub2val2\n"
+ " key3 = sub2val3\n"
+ " subsub2 {\n"
+ " }\n"
+ " }\n"
+ " sub3 : main.sub1, main.sub2 {\n"
+ " key3 = sub3val3\n"
+ " }\n"
+ " sub4 : main.sub2, main.sub1 {\n"
+ " key3 = sub4val3\n"
+ " }\n"
+ "}"));
+
+ verify_string("sub1val2", "main.sub3.key2");
+ verify_string("sub3val3", "main.sub3.key3");
+ verify_string("sub2val2", "main.sub4.key2");
+ verify_string("sub4val3", "main.sub4.key3");
+
+ /* the order of referenced keys/subsections depends on the reference
+ * statement's order */
+ keys = linked_list_create_with_items("subsub1", "subsub2", NULL);
+ verify_sections(keys, "main.sub3");
+
+ keys = linked_list_create_with_items("subsub2", "subsub1", NULL);
+ verify_sections(keys, "main.sub4");
+
+ /* local keys are always enumerated first */
+ keys = linked_list_create_with_items("key3", "key1", "key2", NULL);
+ values = linked_list_create_with_items("sub3val3", "sub1val1", "sub1val2", NULL);
+ verify_key_values(keys, values, "main.sub3");
+
+ keys = linked_list_create_with_items("key3", "key2", "key1", NULL);
+ values = linked_list_create_with_items("sub4val3", "sub2val2", "sub1val1", NULL);
+ verify_key_values(keys, values, "main.sub4");
+}
+END_TEST
+
+START_TEST(test_references_resolution)
+{
+ linked_list_t *keys, *values;
+
+ create_settings(chunk_from_str(
+ "sec-a {\n"
+ " sub1 {\n"
+ " a1 = val-a1\n"
+ " key = sec-a-val1\n"
+ " sub-a {\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ "sec-b : sec-a {\n"
+ " sub1 {\n"
+ " b1 = val-b1\n"
+ " key = sec-b-val1\n"
+ " sub-b1 {\n"
+ " }\n"
+ " }\n"
+ " sub2 {\n"
+ " b2 = val-b2\n"
+ " key = sec-b-val2\n"
+ " sub-b2 {\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ "sec-c : sec-b {\n"
+ " sub2 : sec-b.sub1 {\n"
+ " c2 = val-c2\n"
+ " key = sec-c-val2\n"
+ " sub-c2 {\n"
+ " }\n"
+ " }\n"
+ "}"));
+
+ verify_string("sec-c-val2", "sec-c.sub2.key");
+ settings_remove_value(settings, "sec-c.sub2.key");
+ verify_string("sec-b-val1", "sec-c.sub2.key");
+ settings_remove_value(settings, "sec-b.sub1.key");
+ verify_string("sec-a-val1", "sec-c.sub2.key");
+ settings_remove_value(settings, "sec-a.sub1.key");
+ verify_string("sec-b-val2", "sec-c.sub2.key");
+ settings_remove_value(settings, "sec-b.sub2.key");
+ verify_null("sec-c.sub2.key");
+
+ keys = linked_list_create_with_items("sub-c2", "sub-b1", "sub-a", "sub-b2", NULL);
+ verify_sections(keys, "sec-c.sub2");
+
+ keys = linked_list_create_with_items("c2", "b1", "a1", "b2", NULL);
+ values = linked_list_create_with_items("val-c2", "val-b1", "val-a1", "val-b2", NULL);
+ verify_key_values(keys, values, "sec-c.sub2");
+}
+END_TEST
+
+START_TEST(test_references_fallback)
+{
+ linked_list_t *keys, *values;
+
+#define test_references_fallback_base_settings \
+ "lib {\n" \
+ " key1 = libval1\n" \
+ " keylib = libval\n" \
+ " sub {\n" \
+ " key1 = libsubval1\n" \
+ " }\n" \
+ " libsub {\n" \
+ " }\n" \
+ "}\n" \
+ "other {\n" \
+ " key1 = otherval1\n" \
+ " keyother = otherval\n" \
+ " sub {\n" \
+ " key1 = othersubval1\n" \
+ " }\n" \
+ " othersub {\n" \
+ " }\n" \
+ "}\n"
+
+ create_settings(chunk_from_str(
+ test_references_fallback_base_settings "app : other {}"));
+
+ /* references have precedence over fallbacks */
+ settings->add_fallback(settings, "app", "lib");
+ verify_string("otherval1", "app.key1");
+ verify_string("libval", "app.keylib");
+ verify_string("othersubval1", "app.sub.key1");
+
+ keys = linked_list_create_with_items("sub", "othersub", "libsub", NULL);
+ verify_sections(keys, "app");
+
+ keys = linked_list_create_with_items("key1", "keyother", "keylib", NULL);
+ values = linked_list_create_with_items("otherval1", "otherval", "libval", NULL);
+ verify_key_values(keys, values, "app");
+
+ /* fallbacks are unaffected when reloading configs with references */
+ ck_assert(settings->load_string_section(settings,
+ test_references_fallback_base_settings "app {}", FALSE, ""));
+ verify_string("libval1", "app.key1");
+ verify_string("libval", "app.keylib");
+ verify_string("libsubval1", "app.sub.key1");
+
+ ck_assert(settings->load_string_section(settings,
+ test_references_fallback_base_settings "app : other {}", FALSE, ""));
+ verify_string("otherval1", "app.key1");
+ verify_string("libval", "app.keylib");
+ verify_string("othersubval1", "app.sub.key1");
+}
+END_TEST
+
START_SETUP(setup_string_config)
{
create_settings(chunk_from_str(
@@ -1115,6 +1461,25 @@ START_TEST(test_valid)
ck_assert(chunk_write(contents, path, 0022, TRUE));
ck_assert(settings->load_files(settings, path, FALSE));
verify_string("a setting with = and { character", "equals");
+
+ contents = chunk_from_str(
+ "ref { key = value }\nvalid:ref {}");
+ ck_assert(chunk_write(contents, path, 0022, TRUE));
+ ck_assert(settings->load_files(settings, path, FALSE));
+ verify_string("value", "valid.key");
+
+ contents = chunk_from_str(
+ "ref { key = value }\nvalid\n:\nref {}");
+ ck_assert(chunk_write(contents, path, 0022, TRUE));
+ ck_assert(settings->load_files(settings, path, FALSE));
+ verify_string("value", "valid.key");
+
+ contents = chunk_from_str(
+ "ref { key = value }\nother { key1 = value1 }\nvalid\n:\nref\n\t,\nother {}");
+ ck_assert(chunk_write(contents, path, 0022, TRUE));
+ ck_assert(settings->load_files(settings, path, FALSE));
+ verify_string("value", "valid.key");
+ verify_string("value1", "valid.key1");
}
END_TEST
@@ -1157,6 +1522,21 @@ START_TEST(test_invalid)
"\"unexpected\" = string");
ck_assert(chunk_write(contents, path, 0022, TRUE));
ck_assert(!settings->load_files(settings, path, FALSE));
+
+ contents = chunk_from_str(
+ "incorrect :: ref {}");
+ ck_assert(chunk_write(contents, path, 0022, TRUE));
+ ck_assert(!settings->load_files(settings, path, FALSE));
+
+ contents = chunk_from_str(
+ "/var/log/daemon.log { dmn = 1 }");
+ ck_assert(chunk_write(contents, path, 0022, TRUE));
+ ck_assert(!settings->load_files(settings, path, FALSE));
+
+ contents = chunk_from_str(
+ "filelog { /var/log/daemon.log = 1 }");
+ ck_assert(chunk_write(contents, path, 0022, TRUE));
+ ck_assert(!settings->load_files(settings, path, FALSE));
}
END_TEST
@@ -1326,14 +1706,25 @@ Suite *settings_suite_create()
tcase_add_checked_fixture(tc, setup_include_config, teardown_config);
tcase_add_test(tc, test_load_string);
tcase_add_test(tc, test_load_string_section);
+ tcase_add_test(tc, test_load_string_section_null);
suite_add_tcase(s, tc);
tc = tcase_create("fallback");
tcase_add_checked_fixture(tc, setup_fallback_config, teardown_config);
tcase_add_test(tc, test_add_fallback);
+ tcase_add_test(tc, test_fallback_resolution);
tcase_add_test(tc, test_add_fallback_printf);
suite_add_tcase(s, tc);
+ tc = tcase_create("references");
+ tcase_add_checked_fixture(tc, NULL, teardown_config);
+ tcase_add_test(tc, test_references);
+ tcase_add_test(tc, test_references_templates);
+ tcase_add_test(tc, test_references_order);
+ tcase_add_test(tc, test_references_resolution);
+ tcase_add_test(tc, test_references_fallback);
+ suite_add_tcase(s, tc);
+
tc = tcase_create("strings");
tcase_add_checked_fixture(tc, setup_string_config, teardown_config);
tcase_add_test(tc, test_strings);
diff --git a/src/libstrongswan/tests/suites/test_utils.c b/src/libstrongswan/tests/suites/test_utils.c
index 00f000a6a..f1d46ee6b 100644
--- a/src/libstrongswan/tests/suites/test_utils.c
+++ b/src/libstrongswan/tests/suites/test_utils.c
@@ -860,47 +860,75 @@ END_TEST
static struct {
char *s;
bool ok;
+ mark_op_t ops;
mark_t m;
} mark_data[] = {
- {NULL, FALSE, { 0 }},
- {"", TRUE, { 0, 0xffffffff }},
- {"/", TRUE, { 0, 0 }},
- {"42", TRUE, { 42, 0xffffffff }},
- {"0x42", TRUE, { 0x42, 0xffffffff }},
- {"x", FALSE, { 0 }},
- {"42/", TRUE, { 0, 0 }},
- {"42/0", TRUE, { 0, 0 }},
- {"42/x", FALSE, { 0 }},
- {"42/42", TRUE, { 42, 42 }},
- {"42/0xff", TRUE, { 42, 0xff }},
- {"0x42/0xff", TRUE, { 0x42, 0xff }},
- {"/0xff", TRUE, { 0, 0xff }},
- {"/x", FALSE, { 0 }},
- {"x/x", FALSE, { 0 }},
- {"0xfffffff0/0x0000ffff", TRUE, { 0x0000fff0, 0x0000ffff }},
- {"%unique", TRUE, { MARK_UNIQUE, 0xffffffff }},
- {"%unique/", TRUE, { MARK_UNIQUE, 0 }},
- {"%unique/0x0000ffff", TRUE, { MARK_UNIQUE, 0x0000ffff }},
- {"%unique/0xffffffff", TRUE, { MARK_UNIQUE, 0xffffffff }},
- {"%unique0xffffffffff", FALSE, { 0, 0 }},
- {"0xffffffff/0x0000ffff", TRUE, { MARK_UNIQUE, 0x0000ffff }},
- {"0xffffffff/0xffffffff", TRUE, { MARK_UNIQUE, 0xffffffff }},
- {"%unique-dir", TRUE, { MARK_UNIQUE_DIR, 0xffffffff }},
- {"%unique-dir/", TRUE, { MARK_UNIQUE_DIR, 0 }},
- {"%unique-dir/0x0000ffff", TRUE, { MARK_UNIQUE_DIR, 0x0000ffff }},
- {"%unique-dir/0xffffffff", TRUE, { MARK_UNIQUE_DIR, 0xffffffff }},
- {"%unique-dir0xffffffff", FALSE, { 0, 0 }},
- {"0xfffffffe/0x0000ffff", TRUE, { MARK_UNIQUE_DIR, 0x0000ffff }},
- {"0xfffffffe/0xffffffff", TRUE, { MARK_UNIQUE_DIR, 0xffffffff }},
- {"%unique-/0xffffffff", FALSE, { 0, 0 }},
- {"%unique-foo/0xffffffff", FALSE, { 0, 0 }},
+ {NULL, FALSE, MARK_OP_NONE, { 0 }},
+ {"", TRUE, MARK_OP_NONE, { 0, 0xffffffff }},
+ {"/", TRUE, MARK_OP_NONE, { 0, 0 }},
+ {"42", TRUE, MARK_OP_NONE, { 42, 0xffffffff }},
+ {"0x42", TRUE, MARK_OP_NONE, { 0x42, 0xffffffff }},
+ {"x", FALSE, MARK_OP_NONE, { 0 }},
+ {"42/", TRUE, MARK_OP_NONE, { 0, 0 }},
+ {"42/0", TRUE, MARK_OP_NONE, { 0, 0 }},
+ {"42/x", FALSE, MARK_OP_NONE, { 0 }},
+ {"42/42", TRUE, MARK_OP_NONE, { 42, 42 }},
+ {"42/0xff", TRUE, MARK_OP_NONE, { 42, 0xff }},
+ {"0x42/0xff", TRUE, MARK_OP_NONE, { 0x42, 0xff }},
+ {"/0xff", TRUE, MARK_OP_NONE, { 0, 0xff }},
+ {"/x", FALSE, MARK_OP_NONE, { 0 }},
+ {"x/x", FALSE, MARK_OP_NONE, { 0 }},
+ {"0xfffffff0/0x0000ffff", TRUE, MARK_OP_UNIQUE,
+ { 0x0000fff0, 0x0000ffff }},
+ {"%unique", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE, 0xffffffff }},
+ {"%unique/", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE, 0 }},
+ {"%unique", FALSE, MARK_OP_NONE,
+ { 0, 0 }},
+ {"%unique/0x0000ffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE, 0x0000ffff }},
+ {"%unique/0xffffffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE, 0xffffffff }},
+ {"%unique0xffffffffff", FALSE, MARK_OP_UNIQUE,
+ { 0, 0 }},
+ {"0xffffffff/0x0000ffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE, 0x0000ffff }},
+ {"0xffffffff/0xffffffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE, 0xffffffff }},
+ {"%unique-dir", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE_DIR, 0xffffffff }},
+ {"%unique-dir/", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE_DIR, 0 }},
+ {"%unique-dir", FALSE, MARK_OP_NONE,
+ { 0, 0 }},
+ {"%unique-dir/0x0000ffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE_DIR, 0x0000ffff }},
+ {"%unique-dir/0xffffffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE_DIR, 0xffffffff }},
+ {"%unique-dir0xffffffff", FALSE, MARK_OP_UNIQUE,
+ { 0, 0 }},
+ {"0xfffffffe/0x0000ffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE_DIR, 0x0000ffff }},
+ {"0xfffffffe/0xffffffff", TRUE, MARK_OP_UNIQUE,
+ { MARK_UNIQUE_DIR, 0xffffffff }},
+ {"%unique-/0xffffffff", FALSE, MARK_OP_UNIQUE,
+ { 0, 0 }},
+ {"%unique-foo/0xffffffff", FALSE, MARK_OP_UNIQUE,
+ { 0, 0 }},
+ {"%same", TRUE, MARK_OP_SAME,
+ { MARK_SAME, 0xffffffff }},
+ {"%same/0x0000ffff", TRUE, MARK_OP_SAME,
+ { MARK_SAME, 0x0000ffff }},
+ {"%%same", FALSE, MARK_OP_NONE,
+ { 0, 0 }},
};
START_TEST(test_mark_from_string)
{
mark_t mark;
- if (mark_from_string(mark_data[_i].s, &mark))
+ if (mark_from_string(mark_data[_i].s, mark_data[_i].ops, &mark))
{
ck_assert_int_eq(mark.value, mark_data[_i].m.value);
ck_assert_int_eq(mark.mask, mark_data[_i].m.mask);