aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-09-23 14:08:24 -0400
committerGeorge Kadianakis <desnacked@riseup.net>2020-10-07 20:46:37 +0300
commitc4812698c3df0bd8aa51c615b0274bbb53b9eb6c (patch)
tree170186e239336d808bd770876845321781e7f69a /src/test
parent2ceea131406b3f88e4a6a9c6bfc9f47f4940ca47 (diff)
downloadtor-c4812698c3df0bd8aa51c615b0274bbb53b9eb6c.tar.gz
tor-c4812698c3df0bd8aa51c615b0274bbb53b9eb6c.zip
Remove long-obsolete members from the state file.
Tor has a feature to preserve unrecognized state file entries in order to maintain forward compatibility. But this feature, along with some unused code that we never actually removed, led to us keeping items that were of no use to the user, other than at worst to preserve ancient information about them. This commit adds a feature to remove obsolete entries when we load the file. Closes ticket 40137.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/include.am1
-rw-r--r--src/test/test.c1
-rw-r--r--src/test/test.h1
-rw-r--r--src/test/test_statefile.c56
4 files changed, 59 insertions, 0 deletions
diff --git a/src/test/include.am b/src/test/include.am
index 215e423834..173f007fbf 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -235,6 +235,7 @@ src_test_test_SOURCES += \
src/test/test_sendme.c \
src/test/test_shared_random.c \
src/test/test_socks.c \
+ src/test/test_statefile.c \
src/test/test_stats.c \
src/test/test_status.c \
src/test/test_storagedir.c \
diff --git a/src/test/test.c b/src/test/test.c
index 38c8206eea..77aa6db975 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -770,6 +770,7 @@ struct testgroup_t testgroups[] = {
{ "sendme/", sendme_tests },
{ "shared-random/", sr_tests },
{ "socks/", socks_tests },
+ { "statefile/", statefile_tests },
{ "stats/", stats_tests },
{ "status/" , status_tests },
{ "storagedir/", storagedir_tests },
diff --git a/src/test/test.h b/src/test/test.h
index 71066db48e..bd3a4102f5 100644
--- a/src/test/test.h
+++ b/src/test/test.h
@@ -187,6 +187,7 @@ extern struct testcase_t scheduler_tests[];
extern struct testcase_t sendme_tests[];
extern struct testcase_t socks_tests[];
extern struct testcase_t sr_tests[];
+extern struct testcase_t statefile_tests[];
extern struct testcase_t stats_tests[];
extern struct testcase_t status_tests[];
extern struct testcase_t storagedir_tests[];
diff --git a/src/test/test_statefile.c b/src/test/test_statefile.c
new file mode 100644
index 0000000000..dc9ecfee3e
--- /dev/null
+++ b/src/test/test_statefile.c
@@ -0,0 +1,56 @@
+/* Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2020, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+
+#define STATEFILE_PRIVATE
+
+#include "core/or/or.h"
+#include "lib/encoding/confline.h"
+#include "app/config/statefile.h"
+
+#include "test/test.h"
+
+static void
+test_statefile_remove_obsolete(void *arg)
+{
+ (void)arg;
+ config_line_t *inp = NULL;
+ /* try empty config */
+ or_state_remove_obsolete_lines(&inp);
+ tt_assert(!inp);
+
+ /* try removing every line */
+ config_line_append(&inp, "EntryGuard", "doesn't matter");
+ config_line_append(&inp, "HidServRevCounter", "ignore");
+ config_line_append(&inp, "hidservrevcounter", "foobar"); // note case
+ or_state_remove_obsolete_lines(&inp);
+ tt_assert(!inp);
+
+ /* Now try removing a subset of lines. */
+ config_line_append(&inp, "EntryGuard", "doesn't matter");
+ config_line_append(&inp, "Guard", "in use");
+ config_line_append(&inp, "HidServRevCounter", "ignore");
+ config_line_append(&inp, "TorVersion", "this test doesn't care");
+ or_state_remove_obsolete_lines(&inp);
+ tt_assert(inp);
+ tt_str_op(inp->key, OP_EQ, "Guard");
+ tt_str_op(inp->value, OP_EQ, "in use");
+ tt_assert(inp->next);
+ tt_str_op(inp->next->key, OP_EQ, "TorVersion");
+ tt_str_op(inp->next->value, OP_EQ, "this test doesn't care");
+ tt_assert(! inp->next->next);
+
+ done:
+ config_free_lines(inp);
+}
+
+#define T(name) \
+ { #name, test_statefile_##name, 0, NULL, NULL }
+
+struct testcase_t statefile_tests[] = {
+ T(remove_obsolete),
+ END_OF_TESTCASES
+};