aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-04-08 13:55:02 -0400
committerNick Mathewson <nickm@torproject.org>2014-04-08 13:55:02 -0400
commit245f273aaf6a6189a57d837d5fd76b76cc9b6f8e (patch)
tree2806ce750222a7e80e6151656360aeeb0a6d93eb /src/test
parent3ac426afe8f169cb2c16de9d37b8630b7c3216f5 (diff)
parent51e13cd1ad5f7c130521e2a964ea462f35d1880e (diff)
downloadtor-245f273aaf6a6189a57d837d5fd76b76cc9b6f8e.tar
tor-245f273aaf6a6189a57d837d5fd76b76cc9b6f8e.tar.gz
Merge branch 'bug7952_final'
Conflicts: src/test/include.am src/test/test.c
Diffstat (limited to 'src/test')
-rw-r--r--src/test/include.am1
-rw-r--r--src/test/test.c2
-rw-r--r--src/test/test_policy.c93
3 files changed, 96 insertions, 0 deletions
diff --git a/src/test/include.am b/src/test/include.am
index c59ebb2ad..34bbe6b5e 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -43,6 +43,7 @@ src_test_test_SOURCES = \
src/test/test_config.c \
src/test/test_hs.c \
src/test/test_nodelist.c \
+ src/test/test_policy.c \
src/ext/tinytest.c
src_test_test_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
diff --git a/src/test/test.c b/src/test/test.c
index 0e0fc6a4f..a53b5b0c8 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1638,6 +1638,7 @@ extern struct testcase_t hs_tests[];
extern struct testcase_t nodelist_tests[];
extern struct testcase_t routerkeys_tests[];
extern struct testcase_t oom_tests[];
+extern struct testcase_t exit_policy_tests[];
static struct testgroup_t testgroups[] = {
{ "", test_array },
@@ -1666,6 +1667,7 @@ static struct testgroup_t testgroups[] = {
{ "nodelist/", nodelist_tests },
{ "routerkeys/", routerkeys_tests },
{ "oom/", oom_tests },
+ { "policy/" , exit_policy_tests },
END_OF_GROUPS
};
diff --git a/src/test/test_policy.c b/src/test/test_policy.c
new file mode 100644
index 000000000..8f7fa255a
--- /dev/null
+++ b/src/test/test_policy.c
@@ -0,0 +1,93 @@
+/* Copyright (c) 2013, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "or.h"
+#include "router.h"
+#include "routerparse.h"
+#include "policies.h"
+#include "test.h"
+
+static void
+test_dump_exit_policy_to_string(void *arg)
+{
+ char *ep;
+ addr_policy_t *policy_entry;
+
+ routerinfo_t *ri = tor_malloc_zero(sizeof(routerinfo_t));
+
+ (void)arg;
+
+ ri->policy_is_reject_star = 1;
+ ri->exit_policy = NULL; // expecting "reject *:*"
+ ep = router_dump_exit_policy_to_string(ri,1,1);
+
+ test_streq("reject *:*",ep);
+
+ tor_free(ep);
+
+ ri->exit_policy = smartlist_new();
+ ri->policy_is_reject_star = 0;
+
+ policy_entry = router_parse_addr_policy_item_from_string("accept *:*",-1);
+
+ smartlist_add(ri->exit_policy,policy_entry);
+
+ ep = router_dump_exit_policy_to_string(ri,1,1);
+
+ test_streq("accept *:*",ep);
+
+ tor_free(ep);
+
+ policy_entry = router_parse_addr_policy_item_from_string("reject *:25",-1);
+
+ smartlist_add(ri->exit_policy,policy_entry);
+
+ ep = router_dump_exit_policy_to_string(ri,1,1);
+
+ test_streq("accept *:*\nreject *:25",ep);
+
+ tor_free(ep);
+
+ policy_entry =
+ router_parse_addr_policy_item_from_string("reject 8.8.8.8:*",-1);
+
+ smartlist_add(ri->exit_policy,policy_entry);
+
+ ep = router_dump_exit_policy_to_string(ri,1,1);
+
+ test_streq("accept *:*\nreject *:25\nreject 8.8.8.8:*",ep);
+
+ policy_entry =
+ router_parse_addr_policy_item_from_string("reject6 [FC00::]/7:*",-1);
+
+ smartlist_add(ri->exit_policy,policy_entry);
+
+ ep = router_dump_exit_policy_to_string(ri,1,1);
+
+ test_streq("accept *:*\nreject *:25\nreject 8.8.8.8:*\n"
+ "reject6 [fc00::]/7:*",ep);
+
+ policy_entry =
+ router_parse_addr_policy_item_from_string("accept6 [c000::]/3:*",-1);
+
+ smartlist_add(ri->exit_policy,policy_entry);
+
+ ep = router_dump_exit_policy_to_string(ri,1,1);
+
+ test_streq("accept *:*\nreject *:25\nreject 8.8.8.8:*\n"
+ "reject6 [fc00::]/7:*\naccept6 [c000::]/3:*",ep);
+
+ done:
+
+ SMARTLIST_FOREACH(ri->exit_policy, addr_policy_t *,
+ entry, addr_policy_free(entry));
+ tor_free(ri);
+ tor_free(ep);
+}
+
+struct testcase_t exit_policy_tests[] = {
+ { "router_dump_exit_policy_to_string", test_dump_exit_policy_to_string, 0,
+ NULL, NULL },
+ END_OF_TESTCASES
+};
+