aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-01-23 09:36:00 -0500
committerNick Mathewson <nickm@torproject.org>2015-01-23 09:36:00 -0500
commit5d4bb6f61f360ddcbee83476ff2f93a13f3a19c0 (patch)
treeb863aa88f8810c86e56f711fe1e032585f80e579 /src/test
parentbd22ad12bd84019d00bcd92e2e2390cd910908ce (diff)
parentac9b0a3110ea4eea63133c6d2e3572b2cfd22bd6 (diff)
downloadtor-5d4bb6f61f360ddcbee83476ff2f93a13f3a19c0.tar.gz
tor-5d4bb6f61f360ddcbee83476ff2f93a13f3a19c0.zip
Merge remote-tracking branch 'public/ticket9969'
Conflicts: src/or/directory.c src/or/routerlist.c src/or/routerlist.h src/test/include.am src/test/test.c
Diffstat (limited to 'src/test')
-rw-r--r--src/test/include.am21
-rw-r--r--src/test/test.c98
-rw-r--r--src/test/test_dir.c26
-rw-r--r--src/test/test_nodelist.c2
-rw-r--r--src/test/test_routerlist.c103
5 files changed, 191 insertions, 59 deletions
diff --git a/src/test/include.am b/src/test/include.am
index 3c59a8b3c7..f07c78b95c 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -17,44 +17,45 @@ src_test_AM_CPPFLAGS = -DSHARE_DATADIR="\"$(datadir)\"" \
src_test_test_SOURCES = \
src/test/test.c \
+ src/test/test_accounting.c \
src/test/test_addr.c \
src/test/test_buffers.c \
src/test/test_cell_formats.c \
+ src/test/test_cell_queue.c \
src/test/test_channel.c \
src/test/test_channeltls.c \
+ src/test/test_checkdir.c \
src/test/test_circuitlist.c \
src/test/test_circuitmux.c \
+ src/test/test_config.c \
src/test/test_containers.c \
src/test/test_controller_events.c \
src/test/test_crypto.c \
- src/test/test_cell_queue.c \
src/test/test_data.c \
src/test/test_dir.c \
- src/test/test_checkdir.c \
src/test/test_entryconn.c \
src/test/test_entrynodes.c \
src/test/test_extorport.c \
+ src/test/test_hs.c \
src/test/test_introduce.c \
src/test/test_logging.c \
src/test/test_microdesc.c \
+ src/test/test_nodelist.c \
src/test/test_oom.c \
- src/test/test_accounting.c \
src/test/test_options.c \
+ src/test/test_policy.c \
src/test/test_pt.c \
- src/test/test_relaycell.c \
src/test/test_relay.c \
+ src/test/test_relaycell.c \
src/test/test_replay.c \
src/test/test_routerkeys.c \
+ src/test/test_routerlist.c \
+ src/test/test_routerset.c \
src/test/test_scheduler.c \
src/test/test_socks.c \
+ src/test/test_status.c \
src/test/test_threads.c \
src/test/test_util.c \
- src/test/test_config.c \
- src/test/test_hs.c \
- src/test/test_nodelist.c \
- src/test/test_policy.c \
- src/test/test_status.c \
- src/test/test_routerset.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 fc5290f0b9..debee0a059 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -1294,84 +1294,86 @@ static struct testcase_t test_array[] = {
END_OF_TESTCASES
};
+extern struct testcase_t accounting_tests[];
extern struct testcase_t addr_tests[];
extern struct testcase_t buffer_tests[];
-extern struct testcase_t crypto_tests[];
-extern struct testcase_t container_tests[];
-extern struct testcase_t util_tests[];
-extern struct testcase_t dir_tests[];
-extern struct testcase_t checkdir_tests[];
-extern struct testcase_t microdesc_tests[];
-extern struct testcase_t pt_tests[];
-extern struct testcase_t config_tests[];
-extern struct testcase_t introduce_tests[];
-extern struct testcase_t replaycache_tests[];
-extern struct testcase_t relaycell_tests[];
extern struct testcase_t cell_format_tests[];
+extern struct testcase_t cell_queue_tests[];
+extern struct testcase_t channel_tests[];
+extern struct testcase_t channeltls_tests[];
+extern struct testcase_t checkdir_tests[];
extern struct testcase_t circuitlist_tests[];
extern struct testcase_t circuitmux_tests[];
-extern struct testcase_t cell_queue_tests[];
-extern struct testcase_t options_tests[];
-extern struct testcase_t socks_tests[];
+extern struct testcase_t config_tests[];
+extern struct testcase_t container_tests[];
+extern struct testcase_t controller_event_tests[];
+extern struct testcase_t crypto_tests[];
+extern struct testcase_t dir_tests[];
+extern struct testcase_t entryconn_tests[];
extern struct testcase_t entrynodes_tests[];
-extern struct testcase_t thread_tests[];
extern struct testcase_t extorport_tests[];
-extern struct testcase_t controller_event_tests[];
-extern struct testcase_t logging_tests[];
extern struct testcase_t hs_tests[];
+extern struct testcase_t introduce_tests[];
+extern struct testcase_t logging_tests[];
+extern struct testcase_t microdesc_tests[];
extern struct testcase_t nodelist_tests[];
-extern struct testcase_t routerkeys_tests[];
extern struct testcase_t oom_tests[];
-extern struct testcase_t accounting_tests[];
+extern struct testcase_t options_tests[];
extern struct testcase_t policy_tests[];
-extern struct testcase_t status_tests[];
-extern struct testcase_t routerset_tests[];
-extern struct testcase_t router_tests[];
-extern struct testcase_t channel_tests[];
-extern struct testcase_t channeltls_tests[];
+extern struct testcase_t pt_tests[];
extern struct testcase_t relay_tests[];
+extern struct testcase_t relaycell_tests[];
+extern struct testcase_t replaycache_tests[];
+extern struct testcase_t router_tests[];
+extern struct testcase_t routerkeys_tests[];
+extern struct testcase_t routerlist_tests[];
+extern struct testcase_t routerset_tests[];
extern struct testcase_t scheduler_tests[];
-extern struct testcase_t entryconn_tests[];
+extern struct testcase_t socks_tests[];
+extern struct testcase_t status_tests[];
+extern struct testcase_t thread_tests[];
+extern struct testcase_t util_tests[];
static struct testgroup_t testgroups[] = {
{ "", test_array },
- { "buffer/", buffer_tests },
- { "socks/", socks_tests },
+ { "accounting/", accounting_tests },
{ "addr/", addr_tests },
- { "crypto/", crypto_tests },
- { "container/", container_tests },
- { "util/", util_tests },
- { "util/logging/", logging_tests },
- { "util/thread/", thread_tests },
+ { "buffer/", buffer_tests },
{ "cellfmt/", cell_format_tests },
{ "cellqueue/", cell_queue_tests },
- { "dir/", dir_tests },
+ { "channel/", channel_tests },
+ { "channeltls/", channeltls_tests },
{ "checkdir/", checkdir_tests },
- { "dir/md/", microdesc_tests },
- { "pt/", pt_tests },
- { "config/", config_tests },
- { "replaycache/", replaycache_tests },
- { "relaycell/", relaycell_tests },
- { "introduce/", introduce_tests },
{ "circuitlist/", circuitlist_tests },
{ "circuitmux/", circuitmux_tests },
- { "options/", options_tests },
- { "entrynodes/", entrynodes_tests },
+ { "config/", config_tests },
+ { "container/", container_tests },
+ { "control/", controller_event_tests },
+ { "crypto/", crypto_tests },
+ { "dir/", dir_tests },
+ { "dir/md/", microdesc_tests },
{ "entryconn/", entryconn_tests },
+ { "entrynodes/", entrynodes_tests },
{ "extorport/", extorport_tests },
- { "control/", controller_event_tests },
{ "hs/", hs_tests },
+ { "introduce/", introduce_tests },
{ "nodelist/", nodelist_tests },
- { "routerkeys/", routerkeys_tests },
{ "oom/", oom_tests },
- { "accounting/", accounting_tests },
+ { "options/", options_tests },
{ "policy/" , policy_tests },
- { "status/" , status_tests },
- { "routerset/" , routerset_tests },
- { "channel/", channel_tests },
- { "channeltls/", channeltls_tests },
+ { "pt/", pt_tests },
{ "relay/" , relay_tests },
+ { "relaycell/", relaycell_tests },
+ { "replaycache/", replaycache_tests },
+ { "routerkeys/", routerkeys_tests },
+ { "routerlist/", routerlist_tests },
+ { "routerset/" , routerset_tests },
{ "scheduler/", scheduler_tests },
+ { "socks/", socks_tests },
+ { "status/" , status_tests },
+ { "util/", util_tests },
+ { "util/logging/", logging_tests },
+ { "util/thread/", thread_tests },
END_OF_GROUPS
};
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index a8c6c6fad4..991e613cb6 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -2930,6 +2930,30 @@ test_dir_http_handling(void *args)
tor_free(url);
}
+static void
+test_dir_purpose_needs_anonymity(void *arg)
+{
+ (void)arg;
+ tt_int_op(1, ==, purpose_needs_anonymity(0, ROUTER_PURPOSE_BRIDGE));
+ tt_int_op(1, ==, purpose_needs_anonymity(0, ROUTER_PURPOSE_GENERAL));
+ tt_int_op(0, ==, purpose_needs_anonymity(DIR_PURPOSE_FETCH_MICRODESC,
+ ROUTER_PURPOSE_GENERAL));
+ done: ;
+}
+
+static void
+test_dir_fetch_type(void *arg)
+{
+ (void)arg;
+ tt_assert(dir_fetch_type(DIR_PURPOSE_FETCH_MICRODESC, ROUTER_PURPOSE_GENERAL,
+ NULL) == MICRODESC_DIRINFO);
+ tt_assert(dir_fetch_type(DIR_PURPOSE_FETCH_SERVERDESC, ROUTER_PURPOSE_BRIDGE,
+ NULL) == BRIDGE_DIRINFO);
+ tt_assert(dir_fetch_type(DIR_PURPOSE_FETCH_CONSENSUS, ROUTER_PURPOSE_GENERAL,
+ "microdesc") == (V3_DIRINFO | MICRODESC_DIRINFO));
+ done: ;
+}
+
#define DIR_LEGACY(name) \
{ #name, test_dir_ ## name , TT_FORK, NULL, NULL }
@@ -2957,6 +2981,8 @@ struct testcase_t dir_tests[] = {
DIR_LEGACY(clip_unmeasured_bw_kb_alt),
DIR(fmt_control_ns, 0),
DIR(http_handling, 0),
+ DIR(purpose_needs_anonymity, 0),
+ DIR(fetch_type, 0),
END_OF_TESTCASES
};
diff --git a/src/test/test_nodelist.c b/src/test/test_nodelist.c
index 9bd8b4a7ea..a8693ec9b5 100644
--- a/src/test/test_nodelist.c
+++ b/src/test/test_nodelist.c
@@ -10,7 +10,7 @@
#include "nodelist.h"
#include "test.h"
-/** Tese the case when node_get_by_id() returns NULL,
+/** Test the case when node_get_by_id() returns NULL,
* node_get_verbose_nickname_by_id should return the base 16 encoding
* of the id.
*/
diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c
new file mode 100644
index 0000000000..390b69102f
--- /dev/null
+++ b/src/test/test_routerlist.c
@@ -0,0 +1,103 @@
+/* Copyright (c) 2014, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#define ROUTERLIST_PRIVATE
+#include "or.h"
+#include "routerlist.h"
+#include "directory.h"
+#include "test.h"
+
+
+/* 4 digests + 3 sep + pre + post + NULL */
+static char output[4*BASE64_DIGEST256_LEN+3+2+2+1];
+
+static void
+mock_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose,
+ const char *resource, int pds_flags)
+{
+ (void)dir_purpose;
+ (void)router_purpose;
+ (void)pds_flags;
+ tt_assert(resource);
+ strlcpy(output, resource, sizeof(output));
+ done:
+ ;
+}
+
+static void
+test_routerlist_initiate_descriptor_downloads(void *arg)
+{
+ const char *prose = "unhurried and wise, we perceive.";
+ smartlist_t *digests = smartlist_new();
+ (void)arg;
+
+ for (int i = 0; i < 20; i++) {
+ smartlist_add(digests, (char*)prose);
+ }
+
+ MOCK(directory_get_from_dirserver, mock_get_from_dirserver);
+ initiate_descriptor_downloads(NULL, DIR_PURPOSE_FETCH_MICRODESC,
+ digests, 3, 7, 0);
+ UNMOCK(directory_get_from_dirserver);
+
+ tt_str_op(output, OP_EQ, "d/"
+ "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
+ "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
+ "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4-"
+ "dW5odXJyaWVkIGFuZCB3aXNlLCB3ZSBwZXJjZWl2ZS4"
+ ".z");
+
+ done:
+ smartlist_free(digests);
+}
+
+static int count = 0;
+
+static void
+mock_initiate_descriptor_downloads(const routerstatus_t *source,
+ int purpose, smartlist_t *digests,
+ int lo, int hi, int pds_flags)
+{
+ (void)source;
+ (void)purpose;
+ (void)digests;
+ (void)pds_flags;
+ (void)hi;
+ (void)lo;
+ count += 1;
+}
+
+static void
+test_routerlist_launch_descriptor_downloads(void *arg)
+{
+ smartlist_t *downloadable = smartlist_new();
+ time_t now = time(NULL);
+ char *cp;
+ (void)arg;
+
+ for (int i = 0; i < 100; i++) {
+ cp = tor_malloc(DIGEST256_LEN);
+ tt_assert(cp);
+ crypto_rand(cp, DIGEST256_LEN);
+ smartlist_add(downloadable, cp);
+ }
+
+ MOCK(initiate_descriptor_downloads, mock_initiate_descriptor_downloads);
+ launch_descriptor_downloads(DIR_PURPOSE_FETCH_MICRODESC, downloadable,
+ NULL, now);
+ tt_int_op(3, ==, count);
+ UNMOCK(initiate_descriptor_downloads);
+
+ done:
+ SMARTLIST_FOREACH(downloadable, char *, cp1, tor_free(cp1));
+ smartlist_free(downloadable);
+}
+
+#define NODE(name, flags) \
+ { #name, test_routerlist_##name, (flags), NULL, NULL }
+
+struct testcase_t routerlist_tests[] = {
+ NODE(initiate_descriptor_downloads, 0),
+ NODE(launch_descriptor_downloads, 0),
+ END_OF_TESTCASES
+};