diff options
author | Taylor Yu <catalyst@torproject.org> | 2017-03-28 17:35:25 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-04-03 11:58:11 -0400 |
commit | f0a57df55ca3abbbd729e46823424a9a75ea2f82 (patch) | |
tree | 5cd8d8413e234d86a569d46fe384dd4cbb31c970 /src/test/test_circuitbuild.c | |
parent | ceedcfe9f249746e92d5a4fe9f0589b6691b4d84 (diff) | |
download | tor-f0a57df55ca3abbbd729e46823424a9a75ea2f82.tar.gz tor-f0a57df55ca3abbbd729e46823424a9a75ea2f82.zip |
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.
Diffstat (limited to 'src/test/test_circuitbuild.c')
-rw-r--r-- | src/test/test_circuitbuild.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test_circuitbuild.c b/src/test/test_circuitbuild.c index c271d8b842..338bc1a667 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 }; |