aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_config.c
diff options
context:
space:
mode:
authorteor <teor@torproject.org>2019-11-06 11:19:46 +1000
committerteor <teor@torproject.org>2019-11-06 11:19:46 +1000
commitde6ceb0bee8c1bf56d8929940a109bdc2a2d7521 (patch)
tree64cefa8b30b050e26229f307bca8a9d65a7310ae /src/test/test_config.c
parent4f9a0033920b21882c4b6eead3c55551826ee8e9 (diff)
parent03e77ef036e41486b8bfe138d11790c928f49f35 (diff)
downloadtor-de6ceb0bee8c1bf56d8929940a109bdc2a2d7521.tar.gz
tor-de6ceb0bee8c1bf56d8929940a109bdc2a2d7521.zip
Merge branch 'maint-0.4.0' into maint-0.4.1
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r--src/test/test_config.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index a415ca4480..85216f4a40 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -5288,6 +5288,73 @@ test_config_include_folder_order(void *data)
}
static void
+test_config_include_blank_file_last(void *data)
+{
+ (void)data;
+
+ config_line_t *result = NULL;
+ char *torrcd = NULL;
+ char *path = NULL;
+ char *dir = tor_strdup(get_fname("test_include_blank_file_last"));
+ tt_ptr_op(dir, OP_NE, NULL);
+
+#ifdef _WIN32
+ tt_int_op(mkdir(dir), OP_EQ, 0);
+#else
+ tt_int_op(mkdir(dir, 0700), OP_EQ, 0);
+#endif
+
+ tor_asprintf(&torrcd, "%s"PATH_SEPARATOR"%s", dir, "torrc.d");
+
+#ifdef _WIN32
+ tt_int_op(mkdir(torrcd), OP_EQ, 0);
+#else
+ tt_int_op(mkdir(torrcd, 0700), OP_EQ, 0);
+#endif
+
+ tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "aa_1st");
+ tt_int_op(write_str_to_file(path, "Test 1\n", 0), OP_EQ, 0);
+ tor_free(path);
+
+ tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "bb_2nd");
+ tt_int_op(write_str_to_file(path, "Test 2\n", 0), OP_EQ, 0);
+ tor_free(path);
+
+ tor_asprintf(&path, "%s"PATH_SEPARATOR"%s", torrcd, "cc_comment");
+ tt_int_op(write_str_to_file(path, "# comment only\n", 0), OP_EQ, 0);
+ tor_free(path);
+
+ char torrc_contents[1000];
+ tor_snprintf(torrc_contents, sizeof(torrc_contents),
+ "%%include %s\n"
+ "Test 3\n",
+ torrcd);
+
+ int include_used;
+ tt_int_op(config_get_lines_include(torrc_contents, &result, 0, &include_used,
+ NULL), OP_EQ, 0);
+ tt_ptr_op(result, OP_NE, NULL);
+ tt_int_op(include_used, OP_EQ, 1);
+
+ int len = 0;
+ config_line_t *next;
+ for (next = result; next != NULL; next = next->next) {
+ char expected[10];
+ tor_snprintf(expected, sizeof(expected), "%d", len + 1);
+ tt_str_op(next->key, OP_EQ, "Test");
+ tt_str_op(next->value, OP_EQ, expected);
+ len++;
+ }
+ tt_int_op(len, OP_EQ, 3);
+
+ done:
+ config_free_lines(result);
+ tor_free(torrcd);
+ tor_free(path);
+ tor_free(dir);
+}
+
+static void
test_config_include_path_syntax(void *data)
{
(void)data;
@@ -5982,6 +6049,7 @@ struct testcase_t config_tests[] = {
CONFIG_TEST(include_recursion_before_after, 0),
CONFIG_TEST(include_recursion_after_only, 0),
CONFIG_TEST(include_folder_order, 0),
+ CONFIG_TEST(include_blank_file_last, 0),
CONFIG_TEST(include_path_syntax, 0),
CONFIG_TEST(include_not_processed, 0),
CONFIG_TEST(include_has_include, 0),