|
@@ -599,11 +599,111 @@ test_routerlist_router_is_already_dir_fetching(void *arg)
|
|
|
#undef TEST_ADDR_STR
|
|
|
#undef TEST_DIR_PORT
|
|
|
|
|
|
+static long mock_apparent_skew = 0;
|
|
|
+
|
|
|
+/** Store apparent_skew and assert that the other arguments are as
|
|
|
+ * expected. */
|
|
|
+static void
|
|
|
+mock_clock_skew_warning(const connection_t *conn, long apparent_skew,
|
|
|
+ int trusted, log_domain_mask_t domain,
|
|
|
+ const char *received, const char *source)
|
|
|
+{
|
|
|
+ (void)conn;
|
|
|
+ mock_apparent_skew = apparent_skew;
|
|
|
+ tt_int_op(trusted, OP_EQ, 1);
|
|
|
+ tt_int_op(domain, OP_EQ, LD_GENERAL);
|
|
|
+ tt_str_op(received, OP_EQ, "microdesc flavor consensus");
|
|
|
+ tt_str_op(source, OP_EQ, "CONSENSUS");
|
|
|
+ done:
|
|
|
+ ;
|
|
|
+}
|
|
|
+
|
|
|
+/** Do common setup for test_timely_consensus() and
|
|
|
+ * test_early_consensus(). Call networkstatus_set_current_consensus()
|
|
|
+ * on a constructed consensus and with an appropriately-modified
|
|
|
+ * approx_time. Callers expect presence or absence of appropriate log
|
|
|
+ * messages and control events. */
|
|
|
+static int
|
|
|
+test_skew_common(void *arg, time_t now, unsigned long *offset)
|
|
|
+{
|
|
|
+ char *consensus = NULL;
|
|
|
+ int retval = 0;
|
|
|
+
|
|
|
+ *offset = strtoul(arg, NULL, 10);
|
|
|
+
|
|
|
+ /* Initialize the SRV subsystem */
|
|
|
+ MOCK(get_my_v3_authority_cert, get_my_v3_authority_cert_m);
|
|
|
+ mock_cert = authority_cert_parse_from_string(AUTHORITY_CERT_1, NULL);
|
|
|
+ sr_init(0);
|
|
|
+ UNMOCK(get_my_v3_authority_cert);
|
|
|
+
|
|
|
+ construct_consensus(&consensus, now);
|
|
|
+ tt_assert(consensus);
|
|
|
+
|
|
|
+ update_approx_time(now + *offset);
|
|
|
+
|
|
|
+ mock_apparent_skew = 0;
|
|
|
+ /* Caller will call UNMOCK() */
|
|
|
+ MOCK(clock_skew_warning, mock_clock_skew_warning);
|
|
|
+ /* Caller will call teardown_capture_of_logs() */
|
|
|
+ setup_capture_of_logs(LOG_WARN);
|
|
|
+ retval = networkstatus_set_current_consensus(consensus, "microdesc", 0,
|
|
|
+ NULL);
|
|
|
+
|
|
|
+ done:
|
|
|
+ tor_free(consensus);
|
|
|
+ return retval;
|
|
|
+}
|
|
|
+
|
|
|
+/** Test non-early consensus */
|
|
|
+static void
|
|
|
+test_timely_consensus(void *arg)
|
|
|
+{
|
|
|
+ time_t now = time(NULL);
|
|
|
+ unsigned long offset = 0;
|
|
|
+ int retval = 0;
|
|
|
+
|
|
|
+ retval = test_skew_common(arg, now, &offset);
|
|
|
+ (void)offset;
|
|
|
+ expect_no_log_msg_containing("behind the time published in the consensus");
|
|
|
+ tt_int_op(retval, OP_EQ, 0);
|
|
|
+ tt_int_op(mock_apparent_skew, OP_EQ, 0);
|
|
|
+ done:
|
|
|
+ teardown_capture_of_logs();
|
|
|
+ UNMOCK(clock_skew_warning);
|
|
|
+}
|
|
|
+
|
|
|
+/** Test early consensus */
|
|
|
+static void
|
|
|
+test_early_consensus(void *arg)
|
|
|
+{
|
|
|
+ time_t now = time(NULL);
|
|
|
+ unsigned long offset = 0;
|
|
|
+ int retval = 0;
|
|
|
+
|
|
|
+ retval = test_skew_common(arg, now, &offset);
|
|
|
+ /* Can't use expect_single_log_msg() because of unrecognized authorities */
|
|
|
+ expect_log_msg_containing("behind the time published in the consensus");
|
|
|
+ tt_int_op(retval, OP_EQ, 0);
|
|
|
+ /* This depends on construct_consensus() setting valid_after=now+1000 */
|
|
|
+ tt_int_op(mock_apparent_skew, OP_EQ, offset - 1000);
|
|
|
+ done:
|
|
|
+ teardown_capture_of_logs();
|
|
|
+ UNMOCK(clock_skew_warning);
|
|
|
+}
|
|
|
+
|
|
|
#define NODE(name, flags) \
|
|
|
{ #name, test_routerlist_##name, (flags), NULL, NULL }
|
|
|
#define ROUTER(name,flags) \
|
|
|
{ #name, test_router_##name, (flags), NULL, NULL }
|
|
|
|
|
|
+#define TIMELY(name, arg) \
|
|
|
+ { name, test_timely_consensus, TT_FORK, &passthrough_setup, \
|
|
|
+ (char *)(arg) }
|
|
|
+#define EARLY(name, arg) \
|
|
|
+ { name, test_early_consensus, TT_FORK, &passthrough_setup, \
|
|
|
+ (char *)(arg) }
|
|
|
+
|
|
|
struct testcase_t routerlist_tests[] = {
|
|
|
NODE(initiate_descriptor_downloads, 0),
|
|
|
NODE(launch_descriptor_downloads, 0),
|
|
@@ -611,6 +711,11 @@ struct testcase_t routerlist_tests[] = {
|
|
|
ROUTER(pick_directory_server_impl, TT_FORK),
|
|
|
{ "directory_guard_fetch_with_no_dirinfo",
|
|
|
test_directory_guard_fetch_with_no_dirinfo, TT_FORK, NULL, NULL },
|
|
|
+ /* These depend on construct_consensus() setting valid_after=now+1000 */
|
|
|
+ TIMELY("timely_consensus1", "1010"),
|
|
|
+ TIMELY("timely_consensus2", "1000"),
|
|
|
+ TIMELY("timely_consensus3", "940"),
|
|
|
+ EARLY("early_consensus1", "939"),
|
|
|
END_OF_TESTCASES
|
|
|
};
|
|
|
|