]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Test unhandled purpose in route_len_for_purpose()
authorTaylor Yu <catalyst@torproject.org>
Tue, 28 Mar 2017 21:35:25 +0000 (17:35 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 3 Apr 2017 15:58:11 +0000 (11:58 -0400)
Check that route_len_for_purpose() (helper for new_route_len())
correctly fails a non-fatal bug assertion if it encounters an
unhandled circuit purpose when it is called with exit node info.

src/test/test_circuitbuild.c

index c271d8b84250ab7418919ceebbbc5a21c2bb2ffc..338bc1a66701481c3bd6795d1e28396961bddfdd 100644 (file)
@@ -96,10 +96,33 @@ test_new_route_len_safe_exit(void *arg)
   UNMOCK(count_acceptable_nodes);
 }
 
+/* Make sure a non-fatal assertion fails when new_route_len() gets an
+ * unexpected circuit purpose. */
+static void
+test_new_route_len_unhandled_exit(void *arg)
+{
+  int r;
+
+  (void)arg;
+  MOCK(count_acceptable_nodes, mock_count_acceptable_nodes);
+
+  tor_capture_bugs_(1);
+  r = new_route_len(CIRCUIT_PURPOSE_CONTROLLER, &dummy_ei, &dummy_nodes);
+  tt_int_op(DEFAULT_ROUTE_LEN + 1, OP_EQ, r);
+  tt_int_op(smartlist_len(tor_get_captured_bug_log_()), OP_EQ, 1);
+  tt_str_op(smartlist_get(tor_get_captured_bug_log_(), 0), OP_EQ,
+            "!(exit_ei && !known_purpose)");
+  tor_end_capture_bugs_();
+
+ done:
+  UNMOCK(count_acceptable_nodes);
+}
+
 struct testcase_t circuitbuild_tests[] = {
   { "noexit", test_new_route_len_noexit, 0, NULL, NULL },
   { "safe_exit", test_new_route_len_safe_exit, 0, NULL, NULL },
   { "unsafe_exit", test_new_route_len_unsafe_exit, 0, NULL, NULL },
+  { "unhandled_exit", test_new_route_len_unhandled_exit, 0, NULL, NULL },
   END_OF_TESTCASES
 };