commit f0a57df55ca3abbbd729e46823424a9a75ea2f82 Author: Taylor Yu catalyst@torproject.org Date: Tue Mar 28 17:35:25 2017 -0400
Test unhandled purpose in route_len_for_purpose()
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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
diff --git a/src/test/test_circuitbuild.c b/src/test/test_circuitbuild.c index c271d8b..338bc1a 100644 --- a/src/test/test_circuitbuild.c +++ b/src/test/test_circuitbuild.c @@ -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 };
tor-commits@lists.torproject.org