summaryrefslogtreecommitdiff
path: root/src/test/test_dir.c
diff options
context:
space:
mode:
authorteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-04-20 17:30:55 +1000
committerteor (Tim Wilson-Brown) <teor2345@gmail.com>2016-04-28 12:26:38 +1000
commit692828bea558295b2480eab473f9131e85d1eb9e (patch)
treeba737cfb0ae7f7743b2cef0aa90f56c2b1e1c6c2 /src/test/test_dir.c
parent7babf33239eb1e349826753a9d0405cb59150cce (diff)
downloadtor-692828bea558295b2480eab473f9131e85d1eb9e.tar.gz
tor-692828bea558295b2480eab473f9131e85d1eb9e.zip
Decide to advertise begindir support like we decide to advertise DirPort
Decide to advertise begindir support in a similar way to how we decide to advertise DirPort. Fix up the associated descriptor-building unit tests. Resolves #18616, bugfix on 0c8e042c30946faa in #12538 in 0.2.8.1-alpha.
Diffstat (limited to 'src/test/test_dir.c')
-rw-r--r--src/test/test_dir.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index ea179fb02c..401c7b299c 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -85,6 +85,15 @@ test_dir_nicknames(void *arg)
;
}
+static smartlist_t *mocked_configured_ports = NULL;
+
+/** Returns mocked_configured_ports */
+static const smartlist_t *
+mock_get_configured_ports(void)
+{
+ return mocked_configured_ports;
+}
+
/** Run unit tests for router descriptor generation logic. */
static void
test_dir_formats(void *arg)
@@ -104,6 +113,7 @@ test_dir_formats(void *arg)
or_options_t *options = get_options_mutable();
const addr_policy_t *p;
time_t now = time(NULL);
+ port_cfg_t orport, dirport;
(void)arg;
pk1 = pk_generate(0);
@@ -185,9 +195,31 @@ test_dir_formats(void *arg)
/* XXXX025 router_dump_to_string should really take this from ri.*/
options->ContactInfo = tor_strdup("Magri White "
"<magri@elsewhere.example.com>");
+ /* Skip reachability checks for DirPort and tunnelled-dir-server */
+ options->AssumeReachable = 1;
+
+ /* Fake just enough of an ORPort and DirPort to get by */
+ MOCK(get_configured_ports, mock_get_configured_ports);
+ mocked_configured_ports = smartlist_new();
+
+ memset(&orport, 0, sizeof(orport));
+ orport.type = CONN_TYPE_OR_LISTENER;
+ orport.addr.family = AF_INET;
+ orport.port = 9000;
+ smartlist_add(mocked_configured_ports, &orport);
+
+ memset(&dirport, 0, sizeof(dirport));
+ dirport.type = CONN_TYPE_DIR_LISTENER;
+ dirport.addr.family = AF_INET;
+ dirport.port = 9003;
+ smartlist_add(mocked_configured_ports, &dirport);
buf = router_dump_router_to_string(r1, pk2, NULL, NULL, NULL);
+ UNMOCK(get_configured_ports);
+ smartlist_free(mocked_configured_ports);
+ mocked_configured_ports = NULL;
+
tor_free(options->ContactInfo);
tt_assert(buf);
@@ -308,6 +340,16 @@ test_dir_formats(void *arg)
strlcat(buf2, "tunnelled-dir-server\n", sizeof(buf2));
strlcat(buf2, "router-sig-ed25519 ", sizeof(buf2));
+ /* Fake just enough of an ORPort to get by */
+ MOCK(get_configured_ports, mock_get_configured_ports);
+ mocked_configured_ports = smartlist_new();
+
+ memset(&orport, 0, sizeof(orport));
+ orport.type = CONN_TYPE_OR_LISTENER;
+ orport.addr.family = AF_INET;
+ orport.port = 9005;
+ smartlist_add(mocked_configured_ports, &orport);
+
buf = router_dump_router_to_string(r2, pk1, pk2, &r2_onion_keypair, &kp2);
tt_assert(buf);
buf[strlen(buf2)] = '\0'; /* Don't compare the sig; it's never the same
@@ -318,6 +360,10 @@ test_dir_formats(void *arg)
buf = router_dump_router_to_string(r2, pk1, NULL, NULL, NULL);
+ UNMOCK(get_configured_ports);
+ smartlist_free(mocked_configured_ports);
+ mocked_configured_ports = NULL;
+
/* Reset for later */
cp = buf;
rp2 = router_parse_entry_from_string((const char*)cp,NULL,1,0,NULL,NULL);