diff options
Diffstat (limited to 'src/test')
50 files changed, 457 insertions, 168 deletions
diff --git a/src/test/fuzz/fuzz_consensus.c b/src/test/fuzz/fuzz_consensus.c index b170fd33d8..b56702a650 100644 --- a/src/test/fuzz/fuzz_consensus.c +++ b/src/test/fuzz/fuzz_consensus.c @@ -1,8 +1,10 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE +#define SIGCOMMON_PRIVATE #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/ns_parse.h" +#include "feature/dirparse/sigcommon.h" +#include "feature/dirparse/unparseable.h" #include "feature/nodelist/networkstatus.h" #include "lib/crypt_ops/crypto_ed25519.h" #include "feature/nodelist/networkstatus_st.h" diff --git a/src/test/fuzz/fuzz_descriptor.c b/src/test/fuzz/fuzz_descriptor.c index 5a56f4081a..3420113717 100644 --- a/src/test/fuzz/fuzz_descriptor.c +++ b/src/test/fuzz/fuzz_descriptor.c @@ -1,10 +1,13 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE +#define SIGCOMMON_PRIVATE #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/routerparse.h" +#include "feature/dirparse/sigcommon.h" +#include "feature/dirparse/unparseable.h" #include "feature/nodelist/routerlist.h" -#include "feature/relay/routerkeys.h" +#include "feature/nodelist/torcert.h" +#include "feature/keymgt/loadkey.h" #include "test/fuzz/fuzzing.h" static int @@ -76,4 +79,3 @@ fuzz_main(const uint8_t *data, size_t sz) } return 0; } - diff --git a/src/test/fuzz/fuzz_extrainfo.c b/src/test/fuzz/fuzz_extrainfo.c index 6c88f80122..da0fe80838 100644 --- a/src/test/fuzz/fuzz_extrainfo.c +++ b/src/test/fuzz/fuzz_extrainfo.c @@ -1,8 +1,10 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE +#define SIGCOMMON_PRIVATE #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/routerparse.h" +#include "feature/dirparse/sigcommon.h" +#include "feature/dirparse/unparseable.h" #include "feature/nodelist/routerlist.h" #include "feature/relay/routerkeys.h" #include "test/fuzz/fuzzing.h" diff --git a/src/test/fuzz/fuzz_hsdescv2.c b/src/test/fuzz/fuzz_hsdescv2.c index fd5da41635..667b58b3aa 100644 --- a/src/test/fuzz/fuzz_hsdescv2.c +++ b/src/test/fuzz/fuzz_hsdescv2.c @@ -1,9 +1,9 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/unparseable.h" #include "feature/rend/rendcommon.h" +#include "feature/rend/rendparse.h" #include "lib/crypt_ops/crypto_ed25519.h" #include "test/fuzz/fuzzing.h" diff --git a/src/test/fuzz/fuzz_hsdescv3.c b/src/test/fuzz/fuzz_hsdescv3.c index b332973b39..d5ddcc2e27 100644 --- a/src/test/fuzz/fuzz_hsdescv3.c +++ b/src/test/fuzz/fuzz_hsdescv3.c @@ -1,14 +1,13 @@ /* Copyright (c) 2017-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE #define HS_DESCRIPTOR_PRIVATE #include "core/or/or.h" #include "trunnel/ed25519_cert.h" /* Trunnel interface. */ #include "lib/crypt_ops/crypto_ed25519.h" #include "feature/hs/hs_descriptor.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/unparseable.h" #include "test/fuzz/fuzzing.h" diff --git a/src/test/fuzz/fuzz_http.c b/src/test/fuzz/fuzz_http.c index 2fbb275614..06483282bc 100644 --- a/src/test/fuzz/fuzz_http.c +++ b/src/test/fuzz/fuzz_http.c @@ -4,14 +4,14 @@ #include "orconfig.h" #define BUFFERS_PRIVATE -#define DIRECTORY_PRIVATE +#define DIRCACHE_PRIVATE #include "core/or/or.h" #include "lib/err/backtrace.h" #include "lib/container/buffers.h" #include "app/config/config.h" #include "core/mainloop/connection.h" -#include "feature/dircache/directory.h" +#include "feature/dircache/dircache.h" #include "lib/log/log.h" #include "feature/dircommon/dir_connection_st.h" @@ -132,4 +132,3 @@ fuzz_main(const uint8_t *stdin_buf, size_t data_size) return 0; } - diff --git a/src/test/fuzz/fuzz_iptsv2.c b/src/test/fuzz/fuzz_iptsv2.c index a3082f4d0e..265677eebe 100644 --- a/src/test/fuzz/fuzz_iptsv2.c +++ b/src/test/fuzz/fuzz_iptsv2.c @@ -1,9 +1,10 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE + #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/unparseable.h" #include "feature/rend/rendcommon.h" +#include "feature/rend/rendparse.h" #include "lib/crypt_ops/crypto_ed25519.h" #include "feature/rend/rend_service_descriptor_st.h" diff --git a/src/test/fuzz/fuzz_microdesc.c b/src/test/fuzz/fuzz_microdesc.c index fa9676372d..ab54cf2a34 100644 --- a/src/test/fuzz/fuzz_microdesc.c +++ b/src/test/fuzz/fuzz_microdesc.c @@ -1,8 +1,9 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE + #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/microdesc_parse.h" +#include "feature/dirparse/unparseable.h" #include "feature/nodelist/microdesc.h" #include "lib/crypt_ops/crypto_ed25519.h" diff --git a/src/test/fuzz/fuzz_vrs.c b/src/test/fuzz/fuzz_vrs.c index 8c96851b1f..0b869aa5c0 100644 --- a/src/test/fuzz/fuzz_vrs.c +++ b/src/test/fuzz/fuzz_vrs.c @@ -1,9 +1,10 @@ /* Copyright (c) 2016-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define ROUTERPARSE_PRIVATE +#define NS_PARSE_PRIVATE #define NETWORKSTATUS_PRIVATE #include "core/or/or.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/ns_parse.h" +#include "feature/dirparse/unparseable.h" #include "lib/memarea/memarea.h" #include "feature/nodelist/microdesc.h" #include "feature/nodelist/networkstatus.h" diff --git a/src/test/test.c b/src/test/test.c index dc8e3bede3..70d91e3967 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -11,7 +11,6 @@ #include "orconfig.h" #include "lib/crypt_ops/crypto_dh.h" #include "lib/crypt_ops/crypto_rand.h" - #include "app/config/or_state_st.h" #include <stdio.h> @@ -33,7 +32,7 @@ #define ROUTER_PRIVATE #define CIRCUITSTATS_PRIVATE #define CIRCUITLIST_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #define STATEFILE_PRIVATE #include "core/or/or.h" @@ -46,16 +45,16 @@ #include "core/or/connection_edge.h" #include "feature/rend/rendcommon.h" #include "feature/rend/rendcache.h" +#include "feature/rend/rendparse.h" #include "test/test.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "lib/memarea/memarea.h" -#include "core/crypto/onion.h" +#include "core/or/onion.h" #include "core/crypto/onion_ntor.h" #include "core/crypto/onion_fast.h" #include "core/crypto/onion_tap.h" #include "core/or/policies.h" #include "feature/stats/rephist.h" -#include "feature/nodelist/routerparse.h" #include "app/config/statefile.h" #include "lib/crypt_ops/crypto_curve25519.h" @@ -64,6 +63,7 @@ #include "feature/rend/rend_encoded_v2_service_descriptor_st.h" #include "feature/rend/rend_intro_point_st.h" #include "feature/rend/rend_service_descriptor_st.h" +#include "feature/relay/onion_queue.h" /** Run unit tests for the onion handshake code. */ static void diff --git a/src/test/test_cell_formats.c b/src/test/test_cell_formats.c index 2753c42191..daf0296e2a 100644 --- a/src/test/test_cell_formats.c +++ b/src/test/test_cell_formats.c @@ -13,7 +13,7 @@ #include "core/or/connection_or.h" #include "app/config/config.h" #include "lib/crypt_ops/crypto_rand.h" -#include "core/crypto/onion.h" +#include "core/or/onion.h" #include "core/crypto/onion_tap.h" #include "core/crypto/onion_fast.h" #include "core/crypto/onion_ntor.h" diff --git a/src/test/test_channelpadding.c b/src/test/test_channelpadding.c index de673de543..0fd60d0a92 100644 --- a/src/test/test_channelpadding.c +++ b/src/test/test_channelpadding.c @@ -2,7 +2,7 @@ /* See LICENSE for licensing information */ #define TOR_CHANNEL_INTERNAL_ -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #define NETWORKSTATUS_PRIVATE #define TOR_TIMERS_PRIVATE #include "core/or/or.h" @@ -16,7 +16,7 @@ #include "lib/evloop/compat_libevent.h" #include "app/config/config.h" #include "lib/time/compat_time.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "feature/nodelist/networkstatus.h" #include "test/log_test_helpers.h" #include "lib/tls/tortls.h" diff --git a/src/test/test_circuitmux.c b/src/test/test_circuitmux.c index 1d46f8de0d..1be2ff5281 100644 --- a/src/test/test_circuitmux.c +++ b/src/test/test_circuitmux.c @@ -15,6 +15,8 @@ #include "core/or/destroy_cell_queue_st.h" +#include <math.h> + /* XXXX duplicated function from test_circuitlist.c */ static channel_t * new_fake_channel(void) @@ -105,16 +107,19 @@ test_cmux_compute_ticks(void *arg) monotime_coarse_set_mock_time_nsec(now); tick = cell_ewma_get_current_tick_and_fraction(&rem); tt_uint_op(tick, OP_EQ, tick_zero); - tt_double_op(rem, OP_GT, .149999999); - tt_double_op(rem, OP_LT, .150000001); +#ifdef USING_32BIT_MSEC_HACK + const double tolerance = .0005; +#else + const double tolerance = .00000001; +#endif + tt_double_op(fabs(rem - .15), OP_LT, tolerance); /* 25 second later and we should be in another tick. */ now = START_NS + NS_PER_S * 25; monotime_coarse_set_mock_time_nsec(now); tick = cell_ewma_get_current_tick_and_fraction(&rem); tt_uint_op(tick, OP_EQ, tick_zero + 2); - tt_double_op(rem, OP_GT, .499999999); - tt_double_op(rem, OP_LT, .500000001); + tt_double_op(fabs(rem - .5), OP_LT, tolerance); done: ; diff --git a/src/test/test_config.c b/src/test/test_config.c index bf21a8d512..dae4d83766 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -29,15 +29,17 @@ #include "feature/client/entrynodes.h" #include "feature/client/transports.h" #include "feature/relay/ext_orport.h" -#include "feature/stats/geoip.h" +#include "lib/geoip/geoip.h" #include "feature/hibernate/hibernate.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "feature/nodelist/networkstatus.h" #include "feature/nodelist/nodelist.h" #include "core/or/policies.h" #include "feature/rend/rendclient.h" #include "feature/rend/rendservice.h" #include "feature/relay/router.h" +#include "feature/relay/routermode.h" +#include "feature/nodelist/dirlist.h" #include "feature/nodelist/routerlist.h" #include "feature/nodelist/routerset.h" #include "app/config/statefile.h" diff --git a/src/test/test_connection.c b/src/test/test_connection.c index e716c83fe1..0013f47fbc 100644 --- a/src/test/test_connection.c +++ b/src/test/test_connection.c @@ -4,7 +4,7 @@ #include "orconfig.h" #define CONNECTION_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #define CONNECTION_OR_PRIVATE #include "core/or/or.h" @@ -13,12 +13,12 @@ #include "core/mainloop/connection.h" #include "core/or/connection_edge.h" #include "feature/hs/hs_common.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "feature/nodelist/microdesc.h" #include "feature/nodelist/nodelist.h" #include "feature/nodelist/networkstatus.h" #include "feature/rend/rendcache.h" -#include "feature/dircache/directory.h" +#include "feature/dircommon/directory.h" #include "core/or/connection_or.h" #include "lib/net/resolve.h" diff --git a/src/test/test_consdiffmgr.c b/src/test/test_consdiffmgr.c index 6c0601b504..6c451da685 100644 --- a/src/test/test_consdiffmgr.c +++ b/src/test/test_consdiffmgr.c @@ -11,7 +11,7 @@ #include "core/mainloop/cpuworker.h" #include "lib/crypt_ops/crypto_rand.h" #include "feature/nodelist/networkstatus.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/ns_parse.h" #include "lib/evloop/workqueue.h" #include "lib/compress/compress.h" #include "lib/encoding/confline.h" diff --git a/src/test/test_controller.c b/src/test/test_controller.c index 0428ac6fce..4f5a9f58d5 100644 --- a/src/test/test_controller.c +++ b/src/test/test_controller.c @@ -10,7 +10,7 @@ #include "feature/hs/hs_common.h" #include "feature/nodelist/networkstatus.h" #include "feature/rend/rendservice.h" -#include "feature/nodelist/routerlist.h" +#include "feature/nodelist/authcert.h" #include "feature/nodelist/nodelist.h" #include "test/test.h" #include "test/test_helpers.h" diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 723799ee8a..c18aa99fea 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -6,49 +6,73 @@ #include "orconfig.h" #include <math.h> +#define BWAUTH_PRIVATE #define CONFIG_PRIVATE #define CONTROL_PRIVATE +#define DIRCACHE_PRIVATE +#define DIRCLIENT_PRIVATE #define DIRSERV_PRIVATE #define DIRVOTE_PRIVATE -#define ROUTER_PRIVATE -#define ROUTERLIST_PRIVATE -#define ROUTERPARSE_PRIVATE +#define DLSTATUS_PRIVATE #define HIBERNATE_PRIVATE #define NETWORKSTATUS_PRIVATE +#define NS_PARSE_PRIVATE +#define NODE_SELECT_PRIVATE #define RELAY_PRIVATE +#define ROUTERLIST_PRIVATE +#define ROUTER_PRIVATE +#define UNPARSEABLE_PRIVATE +#define VOTEFLAGS_PRIVATE #include "core/or/or.h" -#include "feature/client/bridges.h" -#include "core/mainloop/connection.h" -#include "app/config/confparse.h" #include "app/config/config.h" +#include "app/config/confparse.h" +#include "core/mainloop/connection.h" +#include "core/or/relay.h" +#include "core/or/versions.h" +#include "feature/client/bridges.h" +#include "feature/client/entrynodes.h" #include "feature/control/control.h" -#include "lib/encoding/confline.h" -#include "lib/crypt_ops/crypto_ed25519.h" -#include "lib/crypt_ops/crypto_format.h" -#include "lib/crypt_ops/crypto_rand.h" -#include "feature/dircache/directory.h" -#include "feature/dircache/dirserv.h" +#include "feature/dirauth/bwauth.h" #include "feature/dirauth/dirvote.h" -#include "feature/client/entrynodes.h" +#include "feature/dirauth/dsigs_parse.h" +#include "feature/dirauth/process_descs.h" +#include "feature/dirauth/recommend_pkg.h" +#include "feature/dirauth/shared_random_state.h" +#include "feature/dirauth/voteflags.h" +#include "feature/dircache/dircache.h" +#include "feature/dircache/dirserv.h" +#include "feature/dirclient/dirclient.h" +#include "feature/dirclient/dlstatus.h" +#include "feature/dircommon/directory.h" #include "feature/dircommon/fp_pair.h" +#include "feature/dircommon/voting_schedule.h" #include "feature/hibernate/hibernate.h" -#include "lib/memarea/memarea.h" -#include "lib/osinfo/uname.h" +#include "feature/nodelist/authcert.h" +#include "feature/nodelist/dirlist.h" #include "feature/nodelist/networkstatus.h" -#include "feature/relay/router.h" -#include "feature/relay/routerkeys.h" +#include "feature/nodelist/nickname.h" +#include "feature/nodelist/node_select.h" #include "feature/nodelist/routerlist.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/authcert_parse.h" +#include "feature/dirparse/ns_parse.h" +#include "feature/dirparse/routerparse.h" +#include "feature/dirparse/unparseable.h" #include "feature/nodelist/routerset.h" -#include "feature/dirauth/shared_random_state.h" -#include "test/test.h" -#include "test/test_dir_common.h" #include "feature/nodelist/torcert.h" -#include "core/or/relay.h" -#include "test/log_test_helpers.h" -#include "feature/dircommon/voting_schedule.h" +#include "feature/relay/router.h" +#include "feature/relay/routerkeys.h" +#include "feature/relay/routermode.h" #include "lib/compress/compress.h" +#include "lib/crypt_ops/crypto_ed25519.h" +#include "lib/crypt_ops/crypto_format.h" +#include "lib/crypt_ops/crypto_rand.h" +#include "lib/encoding/confline.h" +#include "lib/memarea/memarea.h" +#include "lib/osinfo/uname.h" +#include "test/log_test_helpers.h" +#include "test/test.h" +#include "test/test_dir_common.h" #include "core/or/addr_policy_st.h" #include "feature/nodelist/authority_cert_st.h" diff --git a/src/test/test_dir_common.c b/src/test/test_dir_common.c index e65e2b0111..86d2838944 100644 --- a/src/test/test_dir_common.c +++ b/src/test/test_dir_common.c @@ -10,6 +10,8 @@ #include "feature/dirauth/dirvote.h" #include "feature/nodelist/nodelist.h" #include "feature/nodelist/routerlist.h" +#include "feature/dirparse/authcert_parse.h" +#include "feature/dirparse/ns_parse.h" #include "test/test_dir_common.h" #include "feature/dircommon/voting_schedule.h" diff --git a/src/test/test_dir_common.h b/src/test/test_dir_common.h index 1e90228edb..1e958a21ff 100644 --- a/src/test/test_dir_common.h +++ b/src/test/test_dir_common.h @@ -5,7 +5,6 @@ #include "core/or/or.h" #include "feature/nodelist/networkstatus.h" -#include "feature/nodelist/routerparse.h" #define TEST_DIR_ROUTER_ID_1 3 #define TEST_DIR_ROUTER_ID_2 5 diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c index 09799a0e5f..1d4a36d7fc 100644 --- a/src/test/test_dir_handle_get.c +++ b/src/test/test_dir_handle_get.c @@ -8,27 +8,32 @@ #define CONNECTION_PRIVATE #define CONFIG_PRIVATE #define RENDCACHE_PRIVATE +#define DIRCACHE_PRIVATE #include "core/or/or.h" #include "app/config/config.h" #include "core/mainloop/connection.h" #include "feature/dircache/consdiffmgr.h" -#include "feature/dircache/directory.h" +#include "feature/dircommon/directory.h" +#include "feature/dircache/dircache.h" #include "test/test.h" #include "lib/compress/compress.h" #include "feature/rend/rendcommon.h" #include "feature/rend/rendcache.h" #include "feature/relay/router.h" +#include "feature/nodelist/authcert.h" +#include "feature/nodelist/dirlist.h" #include "feature/nodelist/routerlist.h" #include "test/rend_test_helpers.h" #include "feature/nodelist/microdesc.h" #include "test/test_helpers.h" #include "feature/nodelist/nodelist.h" #include "feature/client/entrynodes.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/authcert_parse.h" #include "feature/nodelist/networkstatus.h" #include "core/proto/proto_http.h" -#include "feature/stats/geoip.h" +#include "lib/geoip/geoip.h" +#include "feature/stats/geoip_stats.h" #include "feature/dircache/dirserv.h" #include "feature/dirauth/dirvote.h" #include "test/log_test_helpers.h" diff --git a/src/test/test_dos.c b/src/test/test_dos.c index b411e7b38a..40a4c6ba29 100644 --- a/src/test/test_dos.c +++ b/src/test/test_dos.c @@ -9,7 +9,7 @@ #include "core/or/dos.h" #include "core/or/circuitlist.h" #include "lib/crypt_ops/crypto_rand.h" -#include "feature/stats/geoip.h" +#include "feature/stats/geoip_stats.h" #include "core/or/channel.h" #include "feature/nodelist/microdesc.h" #include "feature/nodelist/networkstatus.h" @@ -500,4 +500,3 @@ struct testcase_t dos_tests[] = { NULL, NULL }, END_OF_TESTCASES }; - diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c index cb694106c4..b67c9fae53 100644 --- a/src/test/test_entrynodes.c +++ b/src/test/test_entrynodes.c @@ -8,7 +8,7 @@ #define STATEFILE_PRIVATE #define ENTRYNODES_PRIVATE #define ROUTERLIST_PRIVATE -#define DIRECTORY_PRIVATE +#define DIRCLIENT_PRIVATE #include "core/or/or.h" #include "test/test.h" @@ -19,13 +19,13 @@ #include "app/config/config.h" #include "app/config/confparse.h" #include "lib/crypt_ops/crypto_rand.h" -#include "feature/dircache/directory.h" +#include "feature/dircommon/directory.h" +#include "feature/dirclient/dirclient.h" #include "feature/client/entrynodes.h" #include "feature/nodelist/nodelist.h" #include "feature/nodelist/networkstatus.h" #include "core/or/policies.h" #include "feature/nodelist/routerlist.h" -#include "feature/nodelist/routerparse.h" #include "feature/nodelist/routerset.h" #include "app/config/statefile.h" diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c index ff987563c6..71be9131c7 100644 --- a/src/test/test_extorport.c +++ b/src/test/test_extorport.c @@ -3,7 +3,7 @@ #define CONNECTION_PRIVATE #define EXT_ORPORT_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #include "core/or/or.h" #include "lib/container/buffers.h" #include "core/mainloop/connection.h" @@ -12,11 +12,12 @@ #include "feature/control/control.h" #include "lib/crypt_ops/crypto_rand.h" #include "feature/relay/ext_orport.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "core/or/or_connection_st.h" #include "test/test.h" +#include "test/test_helpers.h" #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> @@ -89,22 +90,6 @@ connection_write_to_buf_impl_replacement(const char *string, size_t len, buf_add(conn->outbuf, string, len); } -static char * -buf_get_contents(buf_t *buf, size_t *sz_out) -{ - char *out; - *sz_out = buf_datalen(buf); - if (*sz_out >= ULONG_MAX) - return NULL; /* C'mon, really? */ - out = tor_malloc(*sz_out + 1); - if (buf_get_bytes(buf, out, (unsigned long)*sz_out) != 0) { - tor_free(out); - return NULL; - } - out[*sz_out] = '\0'; /* Hopefully gratuitous. */ - return out; -} - static void test_ext_or_write_command(void *arg) { @@ -463,7 +448,7 @@ test_ext_or_handshake(void *arg) memcpy(ext_or_auth_cookie, "Gliding wrapt in a brown mantle," , 32); ext_or_auth_cookie_is_set = 1; - init_connection_lists(); + tor_init_connection_lists(); conn = or_connection_new(CONN_TYPE_EXT_OR, AF_INET); tt_int_op(0, OP_EQ, connection_ext_or_start_auth(conn)); diff --git a/src/test/test_geoip.c b/src/test/test_geoip.c index 9df8ea7988..6f9c39063b 100644 --- a/src/test/test_geoip.c +++ b/src/test/test_geoip.c @@ -10,7 +10,8 @@ #define GEOIP_PRIVATE #include "core/or/or.h" #include "app/config/config.h" -#include "feature/stats/geoip.h" +#include "lib/geoip/geoip.h" +#include "feature/stats/geoip_stats.h" #include "test/test.h" /* Record odd numbered fake-IPs using ipv6, even numbered fake-IPs @@ -403,7 +404,8 @@ test_geoip_load_file(void *arg) /* A nonexistant filename should fail. */ tt_int_op(-1, OP_EQ, - geoip_load_file(AF_INET, "/you/did/not/put/a/file/here/I/hope")); + geoip_load_file(AF_INET, "/you/did/not/put/a/file/here/I/hope", + LOG_INFO)); /* We start out with only "Ningunpartia" in the database. */ tt_int_op(1, OP_EQ, geoip_get_n_countries()); @@ -417,7 +419,7 @@ test_geoip_load_file(void *arg) const char *fname = get_fname("geoip"); tt_int_op(0, OP_EQ, write_str_to_file(fname, GEOIP_CONTENT, 1)); - int rv = geoip_load_file(AF_INET, fname); + int rv = geoip_load_file(AF_INET, fname, LOG_WARN); if (rv != 0) { TT_GRIPE(("Unable to load geoip from %s", escaped(fname))); } @@ -467,7 +469,8 @@ test_geoip6_load_file(void *arg) /* A nonexistant filename should fail. */ tt_int_op(-1, OP_EQ, - geoip_load_file(AF_INET6, "/you/did/not/put/a/file/here/I/hope")); + geoip_load_file(AF_INET6, "/you/did/not/put/a/file/here/I/hope", + LOG_INFO)); /* Any lookup attempt should say "-1" because we have no info */ tor_inet_pton(AF_INET6, "2001:4860:4860::8888", &iaddr6); @@ -493,7 +496,7 @@ test_geoip6_load_file(void *arg) "2001:4878:205::,2001:4878:214:ffff:ffff:ffff:ffff:ffff,US\n"; tt_int_op(0, OP_EQ, write_str_to_file(fname6, CONTENT, 1)); - tt_int_op(0, OP_EQ, geoip_load_file(AF_INET6, fname6)); + tt_int_op(0, OP_EQ, geoip_load_file(AF_INET6, fname6, LOG_WARN)); /* Check that we loaded some countries; this will fail if there are ever * fewer than 5 countries in our test data above. */ @@ -545,11 +548,11 @@ test_geoip_load_2nd_file(void *arg) tt_int_op(0, OP_EQ, write_str_to_file(fname_empty, "\n", 1)); /* Load 1st geoip file */ - tt_int_op(0, OP_EQ, geoip_load_file(AF_INET, fname_geoip)); + tt_int_op(0, OP_EQ, geoip_load_file(AF_INET, fname_geoip, LOG_WARN)); /* Load 2nd geoip (empty) file */ /* It has to be the same IP address family */ - tt_int_op(0, OP_EQ, geoip_load_file(AF_INET, fname_empty)); + tt_int_op(0, OP_EQ, geoip_load_file(AF_INET, fname_empty, LOG_WARN)); /* Check that there is no geoip information for 8.8.8.8, */ /* since loading the empty 2nd file should have delete it. */ diff --git a/src/test/test_guardfraction.c b/src/test/test_guardfraction.c index f45a723295..d6f4cd63f2 100644 --- a/src/test/test_guardfraction.c +++ b/src/test/test_guardfraction.c @@ -1,16 +1,16 @@ /* Copyright (c) 2014-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#define DIRSERV_PRIVATE -#define ROUTERPARSE_PRIVATE +#define GUARDFRACTION_PRIVATE #define NETWORKSTATUS_PRIVATE +#define NS_PARSE_PRIVATE #include "orconfig.h" #include "core/or/or.h" #include "app/config/config.h" -#include "feature/dircache/dirserv.h" +#include "feature/dirauth/guardfraction.h" #include "feature/client/entrynodes.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/ns_parse.h" #include "feature/nodelist/networkstatus.h" #include "feature/nodelist/networkstatus_st.h" @@ -422,4 +422,3 @@ struct testcase_t guardfraction_tests[] = { END_OF_TESTCASES }; - diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c index c9138611d8..6ac73bff5c 100644 --- a/src/test/test_helpers.c +++ b/src/test/test_helpers.c @@ -9,7 +9,7 @@ #define ROUTERLIST_PRIVATE #define CONFIG_PRIVATE #define CONNECTION_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #include "orconfig.h" #include "core/or/or.h" @@ -19,7 +19,7 @@ #include "app/config/confparse.h" #include "core/mainloop/connection.h" #include "lib/crypt_ops/crypto_rand.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "feature/nodelist/nodelist.h" #include "core/or/relay.h" #include "feature/nodelist/routerlist.h" @@ -125,6 +125,25 @@ connection_write_to_buf_mock(const char *string, size_t len, buf_add(conn->outbuf, string, len); } +char * +buf_get_contents(buf_t *buf, size_t *sz_out) +{ + tor_assert(buf); + tor_assert(sz_out); + + char *out; + *sz_out = buf_datalen(buf); + if (*sz_out >= ULONG_MAX) + return NULL; /* C'mon, really? */ + out = tor_malloc(*sz_out + 1); + if (buf_get_bytes(buf, out, (unsigned long)*sz_out) != 0) { + tor_free(out); + return NULL; + } + out[*sz_out] = '\0'; /* Hopefully gratuitous. */ + return out; +} + /* Set up a fake origin circuit with the specified number of cells, * Return a pointer to the newly-created dummy circuit */ circuit_t * @@ -217,7 +236,7 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose) mock_connection_connect_sockaddr); MOCK(tor_close_socket, fake_close_socket); - init_connection_lists(); + tor_init_connection_lists(); conn = connection_new(type, TEST_CONN_FAMILY); tt_assert(conn); diff --git a/src/test/test_helpers.h b/src/test/test_helpers.h index 3196c93e6b..72bf7f2f71 100644 --- a/src/test/test_helpers.h +++ b/src/test/test_helpers.h @@ -4,6 +4,8 @@ #ifndef TOR_TEST_HELPERS_H #define TOR_TEST_HELPERS_H +#define BUFFERS_PRIVATE + #include "core/or/or.h" const char *get_yesterday_date_str(void); @@ -18,6 +20,7 @@ void helper_setup_fake_routerlist(void); #define GET(path) "GET " path " HTTP/1.0\r\n\r\n" void connection_write_to_buf_mock(const char *string, size_t len, connection_t *conn, int compressed); +char *buf_get_contents(buf_t *buf, size_t *sz_out); int mock_tor_addr_lookup__fail_on_bad_addrs(const char *name, uint16_t family, tor_addr_t *out); diff --git a/src/test/test_hs_cache.c b/src/test/test_hs_cache.c index 728bb4a2f5..203a1d7039 100644 --- a/src/test/test_hs_cache.c +++ b/src/test/test_hs_cache.c @@ -7,13 +7,15 @@ */ #define CONNECTION_PRIVATE -#define DIRECTORY_PRIVATE +#define DIRCACHE_PRIVATE +#define DIRCLIENT_PRIVATE #define HS_CACHE_PRIVATE #include "trunnel/ed25519_cert.h" #include "feature/hs/hs_cache.h" #include "feature/rend/rendcache.h" -#include "feature/dircache/directory.h" +#include "feature/dircache/dircache.h" +#include "feature/dirclient/dirclient.h" #include "feature/nodelist/networkstatus.h" #include "core/mainloop/connection.h" #include "core/proto/proto_http.h" diff --git a/src/test/test_hs_client.c b/src/test/test_hs_client.c index c91e82ed4a..25cb991a79 100644 --- a/src/test/test_hs_client.c +++ b/src/test/test_hs_client.c @@ -8,7 +8,7 @@ #define CONFIG_PRIVATE #define CRYPTO_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #define HS_CLIENT_PRIVATE #define TOR_CHANNEL_INTERNAL_ #define CIRCUITBUILD_PRIVATE @@ -25,8 +25,8 @@ #include "lib/crypt_ops/crypto_cipher.h" #include "lib/crypt_ops/crypto_dh.h" #include "core/or/channeltls.h" -#include "feature/dircache/directory.h" -#include "core/mainloop/main.h" +#include "feature/dircommon/directory.h" +#include "core/mainloop/mainloop.h" #include "feature/nodelist/nodelist.h" #include "feature/nodelist/routerset.h" @@ -523,6 +523,9 @@ mock_connection_mark_unattached_ap_(entry_connection_t *conn, int endreason, (void) line; (void) file; conn->edge_.end_reason = endreason; + /* This function ultimately will flag this so make sure we do also in the + * MOCK one so we can assess closed connections vs open ones. */ + conn->edge_.base_.marked_for_close = 1; } static void @@ -771,6 +774,117 @@ test_config_client_authorization(void *arg) UNMOCK(check_private_dir); } +static entry_connection_t * +helper_build_socks_connection(const ed25519_public_key_t *service_pk, + int conn_state) +{ + entry_connection_t *socks = entry_connection_new(CONN_TYPE_AP, AF_INET); + ENTRY_TO_EDGE_CONN(socks)->hs_ident = hs_ident_edge_conn_new(service_pk); + TO_CONN(ENTRY_TO_EDGE_CONN(socks))->state = conn_state; + smartlist_add(get_connection_array(), &socks->edge_.base_); + return socks; +} + +static void +test_desc_has_arrived_cleanup(void *arg) +{ + /* The goal of this test is to make sure we clean up everything in between + * two descriptors from the same .onion. Because intro points can change + * from one descriptor to another, once we received a new descriptor, we + * need to cleanup the remaining circuits so they aren't used or selected + * when establishing a connection with the newly stored descriptor. + * + * This test was created because of #27410. */ + + int ret; + char *desc_str = NULL; + hs_descriptor_t *desc = NULL; + const hs_descriptor_t *cached_desc; + ed25519_keypair_t signing_kp; + entry_connection_t *socks1 = NULL, *socks2 = NULL; + hs_ident_dir_conn_t hs_dir_ident; + + (void) arg; + + hs_init(); + + MOCK(networkstatus_get_live_consensus, + mock_networkstatus_get_live_consensus); + MOCK(connection_mark_unattached_ap_, + mock_connection_mark_unattached_ap_); + MOCK(router_have_minimum_dir_info, + mock_router_have_minimum_dir_info_true); + + /* Set consensus time before our time so the cache lookup can always + * validate that the entry is not expired. */ + parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC", &mock_ns.valid_after); + parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC", &mock_ns.fresh_until); + parse_rfc1123_time("Sat, 26 Oct 1985 16:00:00 UTC", &mock_ns.valid_until); + + /* Build a descriptor for a specific .onion. */ + ret = ed25519_keypair_generate(&signing_kp, 0); + tt_int_op(ret, OP_EQ, 0); + desc = hs_helper_build_hs_desc_with_ip(&signing_kp); + tt_assert(desc); + ret = hs_desc_encode_descriptor(desc, &signing_kp, NULL, &desc_str); + tt_int_op(ret, OP_EQ, 0); + + /* Store in the client cache. */ + ret = hs_cache_store_as_client(desc_str, &signing_kp.pubkey); + tt_int_op(ret, OP_EQ, 0); + cached_desc = hs_cache_lookup_as_client(&signing_kp.pubkey); + tt_assert(cached_desc); + hs_helper_desc_equal(desc, cached_desc); + + /* Create two SOCKS connection for the same .onion both in the waiting for a + * descriptor state. */ + socks1 = helper_build_socks_connection(&signing_kp.pubkey, + AP_CONN_STATE_RENDDESC_WAIT); + tt_assert(socks1); + socks2 = helper_build_socks_connection(&signing_kp.pubkey, + AP_CONN_STATE_RENDDESC_WAIT); + tt_assert(socks2); + + /* Now, we'll make the intro points in the current descriptor unusable so + * the hs_client_desc_has_arrived() will take the right code path that we + * want to test that is the fetched descriptor has bad intro points. */ + SMARTLIST_FOREACH_BEGIN(desc->encrypted_data.intro_points, + hs_desc_intro_point_t *, ip) { + hs_cache_client_intro_state_note(&signing_kp.pubkey, + &ip->auth_key_cert->signed_key, + INTRO_POINT_FAILURE_GENERIC); + } SMARTLIST_FOREACH_END(ip); + + /* Simulate that a new descriptor just arrived. We should have both of our + * SOCKS connection to be ended with a resolved failed. */ + hs_ident_dir_conn_init(&signing_kp.pubkey, + &desc->plaintext_data.blinded_pubkey, &hs_dir_ident); + hs_client_desc_has_arrived(&hs_dir_ident); + tt_int_op(socks1->edge_.end_reason, OP_EQ, END_STREAM_REASON_RESOLVEFAILED); + /* XXX: MUST work with OP_EQ. */ + tt_int_op(socks2->edge_.end_reason, OP_EQ, END_STREAM_REASON_RESOLVEFAILED); + + /* Now let say tor cleans up the intro state cache which resets all intro + * point failure count. */ + hs_cache_client_intro_state_purge(); + + /* Retrying all SOCKS which should basically do nothing since we don't have + * any pending SOCKS connection in AP_CONN_STATE_RENDDESC_WAIT state. */ + /* XXX: BUG() is triggered here, shouldn't if socks2 wasn't alive. */ + retry_all_socks_conn_waiting_for_desc(); + + done: + connection_free_minimal(ENTRY_TO_CONN(socks1)); + connection_free_minimal(ENTRY_TO_CONN(socks2)); + hs_descriptor_free(desc); + tor_free(desc_str); + hs_free_all(); + + UNMOCK(networkstatus_get_live_consensus); + UNMOCK(connection_mark_unattached_ap_); + UNMOCK(router_have_minimum_dir_info); +} + struct testcase_t hs_client_tests[] = { { "e2e_rend_circuit_setup_legacy", test_e2e_rend_circuit_setup_legacy, TT_FORK, NULL, NULL }, @@ -786,5 +900,8 @@ struct testcase_t hs_client_tests[] = { NULL, NULL }, { "config_client_authorization", test_config_client_authorization, TT_FORK, NULL, NULL }, + { "desc_has_arrived_cleanup", test_desc_has_arrived_cleanup, + TT_FORK, NULL, NULL }, + END_OF_TESTCASES }; diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c index c60d6e2640..95f7ed14ba 100644 --- a/src/test/test_hs_common.c +++ b/src/test/test_hs_common.c @@ -24,7 +24,7 @@ #include "feature/hs/hs_service.h" #include "app/config/config.h" #include "feature/nodelist/networkstatus.h" -#include "feature/dircache/directory.h" +#include "feature/dirclient/dirclient.h" #include "feature/dirauth/dirvote.h" #include "feature/nodelist/nodelist.h" #include "feature/nodelist/routerlist.h" diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index d6404bd715..7ef0fb6e07 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -10,17 +10,17 @@ #define CIRCUITLIST_PRIVATE #define CONFIG_PRIVATE #define CONNECTION_PRIVATE +#define CONNECTION_EDGE_PRIVATE #define CRYPTO_PRIVATE #define HS_COMMON_PRIVATE #define HS_SERVICE_PRIVATE #define HS_INTROPOINT_PRIVATE #define HS_CIRCUIT_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #define NETWORKSTATUS_PRIVATE #define STATEFILE_PRIVATE #define TOR_CHANNEL_INTERNAL_ #define HS_CLIENT_PRIVATE -#define ROUTERPARSE_PRIVATE #include "test/test.h" #include "test/test_helpers.h" @@ -30,30 +30,33 @@ #include "core/or/or.h" #include "app/config/config.h" +#include "app/config/statefile.h" +#include "core/crypto/hs_ntor.h" +#include "core/mainloop/connection.h" +#include "core/mainloop/mainloop.h" #include "core/or/circuitbuild.h" #include "core/or/circuitlist.h" #include "core/or/circuituse.h" -#include "lib/crypt_ops/crypto_rand.h" -#include "lib/fs/dir.h" -#include "feature/dirauth/dirvote.h" -#include "feature/nodelist/networkstatus.h" -#include "feature/nodelist/nodelist.h" +#include "core/or/connection_edge.h" +#include "core/or/edge_connection_st.h" #include "core/or/relay.h" -#include "feature/nodelist/routerparse.h" +#include "core/or/versions.h" +#include "feature/dirauth/dirvote.h" +#include "feature/dirauth/shared_random_state.h" +#include "feature/dircommon/voting_schedule.h" +#include "feature/hs/hs_circuit.h" +#include "feature/hs/hs_circuitmap.h" +#include "feature/hs/hs_client.h" #include "feature/hs/hs_common.h" #include "feature/hs/hs_config.h" #include "feature/hs/hs_ident.h" #include "feature/hs/hs_intropoint.h" -#include "core/crypto/hs_ntor.h" -#include "feature/hs/hs_circuit.h" -#include "feature/hs/hs_circuitmap.h" #include "feature/hs/hs_service.h" -#include "feature/hs/hs_client.h" -#include "core/mainloop/main.h" +#include "feature/nodelist/networkstatus.h" +#include "feature/nodelist/nodelist.h" #include "feature/rend/rendservice.h" -#include "app/config/statefile.h" -#include "feature/dirauth/shared_random_state.h" -#include "feature/dircommon/voting_schedule.h" +#include "lib/crypt_ops/crypto_rand.h" +#include "lib/fs/dir.h" #include "core/or/cpath_build_state_st.h" #include "core/or/crypt_path_st.h" @@ -2004,6 +2007,96 @@ test_authorized_client_config_equal(void *arg) tor_free(config2); } +/** Test that client circuit ID gets correctly exported */ +static void +test_export_client_circuit_id(void *arg) +{ + origin_circuit_t *or_circ = NULL; + size_t sz; + char *cp1=NULL, *cp2=NULL; + connection_t *conn = NULL; + + (void) arg; + + MOCK(connection_write_to_buf_impl_, connection_write_to_buf_mock); + + hs_service_init(); + + /* Create service */ + hs_service_t *service = helper_create_service(); + /* Check that export circuit ID detection works */ + service->config.circuit_id_protocol = HS_CIRCUIT_ID_PROTOCOL_NONE; + tt_int_op(0, OP_EQ, + hs_service_exports_circuit_id(&service->keys.identity_pk)); + service->config.circuit_id_protocol = HS_CIRCUIT_ID_PROTOCOL_HAPROXY; + tt_int_op(1, OP_EQ, + hs_service_exports_circuit_id(&service->keys.identity_pk)); + + /* Create client connection */ + conn = test_conn_get_connection(AP_CONN_STATE_CIRCUIT_WAIT, CONN_TYPE_AP, 0); + + /* Create client edge conn hs_ident */ + edge_connection_t *edge_conn = TO_EDGE_CONN(conn); + edge_conn->hs_ident = hs_ident_edge_conn_new(&service->keys.identity_pk); + edge_conn->hs_ident->orig_virtual_port = 42; + + /* Create rend circuit */ + or_circ = origin_circuit_new(); + or_circ->base_.purpose = CIRCUIT_PURPOSE_C_REND_JOINED; + edge_conn->on_circuit = TO_CIRCUIT(or_circ); + or_circ->global_identifier = 666; + + /* Export circuit ID */ + export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol); + + /* Check contents */ + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, + "PROXY TCP6 fc00:dead:beef:4dad::0:29a ::1 666 42\r\n"); + + /* Change circ GID and see that the reported circuit ID also changes */ + or_circ->global_identifier = 22; + + /* check changes */ + export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol); + cp2 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_NE, cp2); + tor_free(cp1); + + /* Check that GID with UINT32_MAX works. */ + or_circ->global_identifier = UINT32_MAX; + + export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol); + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, + "PROXY TCP6 fc00:dead:beef:4dad::ffff:ffff ::1 65535 42\r\n"); + tor_free(cp1); + + /* Check that GID with UINT16_MAX works. */ + or_circ->global_identifier = UINT16_MAX; + + export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol); + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, + "PROXY TCP6 fc00:dead:beef:4dad::0:ffff ::1 65535 42\r\n"); + tor_free(cp1); + + /* Check that GID with UINT16_MAX + 7 works. */ + or_circ->global_identifier = UINT16_MAX + 7; + + export_hs_client_circuit_id(edge_conn, service->config.circuit_id_protocol); + cp1 = buf_get_contents(conn->outbuf, &sz); + tt_str_op(cp1, OP_EQ, "PROXY TCP6 fc00:dead:beef:4dad::1:6 ::1 6 42\r\n"); + + done: + UNMOCK(connection_write_to_buf_impl_); + circuit_free_(TO_CIRCUIT(or_circ)); + connection_free_minimal(conn); + hs_service_free(service); + tor_free(cp1); + tor_free(cp2); +} + struct testcase_t hs_service_tests[] = { { "e2e_rend_circuit_setup", test_e2e_rend_circuit_setup, TT_FORK, NULL, NULL }, @@ -2045,6 +2138,8 @@ struct testcase_t hs_service_tests[] = { NULL, NULL }, { "authorized_client_config_equal", test_authorized_client_config_equal, TT_FORK, NULL, NULL }, + { "export_client_circuit_id", test_export_client_circuit_id, TT_FORK, + NULL, NULL }, END_OF_TESTCASES }; diff --git a/src/test/test_mainloop.c b/src/test/test_mainloop.c index f85c224ae9..92ce2e9918 100644 --- a/src/test/test_mainloop.c +++ b/src/test/test_mainloop.c @@ -10,7 +10,7 @@ #include "test/log_test_helpers.h" #include "core/or/or.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" static const uint64_t BILLION = 1000000000; diff --git a/src/test/test_microdesc.c b/src/test/test_microdesc.c index ec4779ead1..8ede2690ec 100644 --- a/src/test/test_microdesc.c +++ b/src/test/test_microdesc.c @@ -4,13 +4,14 @@ #include "orconfig.h" #include "core/or/or.h" -#include "app/config/config.h" #define DIRVOTE_PRIVATE +#include "app/config/config.h" #include "feature/dirauth/dirvote.h" +#include "feature/dirparse/microdesc_parse.h" +#include "feature/dirparse/routerparse.h" #include "feature/nodelist/microdesc.h" #include "feature/nodelist/networkstatus.h" #include "feature/nodelist/routerlist.h" -#include "feature/nodelist/routerparse.h" #include "feature/nodelist/torcert.h" #include "feature/nodelist/microdesc_st.h" diff --git a/src/test/test_oos.c b/src/test/test_oos.c index 5f9942d8ae..fb0daa7a8d 100644 --- a/src/test/test_oos.c +++ b/src/test/test_oos.c @@ -9,8 +9,8 @@ #include "app/config/config.h" #include "core/mainloop/connection.h" #include "core/or/connection_or.h" -#include "feature/dircache/directory.h" -#include "core/mainloop/main.h" +#include "feature/dircommon/directory.h" +#include "core/mainloop/mainloop.h" #include "test/test.h" #include "feature/dircommon/dir_connection_st.h" diff --git a/src/test/test_options.c b/src/test/test_options.c index 56b7f3cf0f..f14e620eeb 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -8,11 +8,11 @@ #include "app/config/confparse.h" #include "app/config/config.h" #include "test/test.h" -#include "feature/stats/geoip.h" +#include "lib/geoip/geoip.h" #define ROUTERSET_PRIVATE #include "feature/nodelist/routerset.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "test/log_test_helpers.h" #include "lib/sandbox/sandbox.h" diff --git a/src/test/test_periodic_event.c b/src/test/test_periodic_event.c index b447ae8888..86dedd85d8 100644 --- a/src/test/test_periodic_event.c +++ b/src/test/test_periodic_event.c @@ -9,7 +9,7 @@ #define CONFIG_PRIVATE #define HS_SERVICE_PRIVATE -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #include "test/test.h" #include "test/test_helpers.h" @@ -18,7 +18,7 @@ #include "app/config/config.h" #include "feature/hibernate/hibernate.h" #include "feature/hs/hs_service.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "core/mainloop/periodic.h" /** Helper function: This is replaced in some tests for the event callbacks so @@ -87,15 +87,19 @@ test_pe_launch(void *arg) item->fn = dumb_event_fn; } - /* Lets make sure that before intialization, we can't scan the periodic - * events list and launch them. Lets try by being a Client. */ options = get_options_mutable(); options->SocksPort_set = 1; periodic_events_on_new_options(options); +#if 0 + /* Lets make sure that before intialization, we can't scan the periodic + * events list and launch them. Lets try by being a Client. */ + /* XXXX We make sure these events are initialized now way earlier than we + * did before. */ for (int i = 0; periodic_events[i].name; ++i) { periodic_event_item_t *item = &periodic_events[i]; tt_int_op(periodic_event_is_enabled(item), OP_EQ, 0); } +#endif initialize_periodic_events(); diff --git a/src/test/test_policy.c b/src/test/test_policy.c index 6a07e5b1f8..afe608f5f7 100644 --- a/src/test/test_policy.c +++ b/src/test/test_policy.c @@ -1,19 +1,20 @@ /* Copyright (c) 2013-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#include "core/or/or.h" #define CONFIG_PRIVATE -#include "app/config/config.h" -#include "feature/relay/router.h" -#include "feature/nodelist/routerparse.h" #define POLICIES_PRIVATE + +#include "core/or/or.h" +#include "app/config/config.h" #include "core/or/policies.h" +#include "feature/dirparse/policy_parse.h" +#include "feature/relay/router.h" #include "lib/encoding/confline.h" #include "test/test.h" #include "core/or/addr_policy_st.h" -#include "feature/nodelist/node_st.h" #include "core/or/port_cfg_st.h" +#include "feature/nodelist/node_st.h" #include "feature/nodelist/routerinfo_st.h" #include "feature/nodelist/routerstatus_st.h" diff --git a/src/test/test_protover.c b/src/test/test_protover.c index 123faccdab..b835e28ab5 100644 --- a/src/test/test_protover.c +++ b/src/test/test_protover.c @@ -554,6 +554,10 @@ test_protover_vote_roundtrip(void *args) const char *input; const char *expected_output; } examples[] = { + { "Risqu\u00e9=1", NULL }, + { ",,,=1", NULL }, + { "\xc1=1", NULL }, + { "Foo_Bar=1", NULL }, { "Fkrkljdsf", NULL }, { "Zn=4294967295", NULL }, { "Zn=4294967295-1", NULL }, diff --git a/src/test/test_rebind.py b/src/test/test_rebind.py index f02cb79b78..7ba3a5796d 100644 --- a/src/test/test_rebind.py +++ b/src/test/test_rebind.py @@ -1,5 +1,3 @@ -#!/usr/bin/python3 - from __future__ import print_function import sys @@ -37,6 +35,12 @@ def pick_random_port(): return port +if sys.hexversion < 0x02070000: + sys.exit("ERROR: unsupported Python version (should be >= 2.7)") + +if sys.hexversion > 0x03000000 and sys.hexversion < 0x03010000: + sys.exit("ERROR: unsupported Python3 version (should be >= 3.1)") + control_port = pick_random_port() socks_port = pick_random_port() diff --git a/src/test/test_relay.c b/src/test/test_relay.c index 65b9a2f940..4311392be8 100644 --- a/src/test/test_relay.c +++ b/src/test/test_relay.c @@ -1,14 +1,17 @@ /* Copyright (c) 2014-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */ -#include "core/or/or.h" #define CIRCUITBUILD_PRIVATE +#define RELAY_PRIVATE +#define REPHIST_PRIVATE +#include "core/or/or.h" #include "core/or/circuitbuild.h" #include "core/or/circuitlist.h" #include "core/or/channeltls.h" #include "feature/stats/rephist.h" -#define RELAY_PRIVATE #include "core/or/relay.h" +#include "feature/stats/rephist.h" +#include "lib/container/order.h" /* For init/free stuff */ #include "core/or/scheduler.h" @@ -22,9 +25,6 @@ static or_circuit_t * new_fake_orcirc(channel_t *nchan, channel_t *pchan); static void test_relay_append_cell_to_circuit_queue(void *arg); -uint64_t find_largest_max(bw_array_t *b); -void commit_max(bw_array_t *b); -void advance_obs(bw_array_t *b); static or_circuit_t * new_fake_orcirc(channel_t *nchan, channel_t *pchan) @@ -113,7 +113,7 @@ test_relay_close_circuit(void *arg) tt_int_op(new_count, OP_EQ, old_count + 1); /* Ensure our write totals are 0 */ - tt_int_op(find_largest_max(write_array), OP_EQ, 0); + tt_u64_op(find_largest_max(write_array), OP_EQ, 0); /* Mark the circuit for close */ circuit_mark_for_close(TO_CIRCUIT(orcirc), 0); @@ -122,7 +122,7 @@ test_relay_close_circuit(void *arg) advance_obs(write_array); commit_max(write_array); /* Check for two cells plus overhead */ - tt_int_op(find_largest_max(write_array), OP_EQ, + tt_u64_op(find_largest_max(write_array), OP_EQ, 2*(get_cell_network_size(nchan->wide_circ_ids) +TLS_PER_CELL_OVERHEAD)); diff --git a/src/test/test_relaycell.c b/src/test/test_relaycell.c index e2d666d52e..3d3addfb9e 100644 --- a/src/test/test_relaycell.c +++ b/src/test/test_relaycell.c @@ -9,7 +9,7 @@ #define CONNECTION_PRIVATE #include "core/or/or.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "app/config/config.h" #include "core/mainloop/connection.h" #include "lib/crypt_ops/crypto_cipher.h" diff --git a/src/test/test_router.c b/src/test/test_router.c index 533135669f..921ec42904 100644 --- a/src/test/test_router.c +++ b/src/test/test_router.c @@ -9,7 +9,7 @@ #include "core/or/or.h" #include "app/config/config.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "feature/hibernate/hibernate.h" #include "feature/nodelist/routerinfo_st.h" #include "feature/nodelist/routerlist.h" diff --git a/src/test/test_routerkeys.c b/src/test/test_routerkeys.c index b62aea113e..f05401ba0d 100644 --- a/src/test/test_routerkeys.c +++ b/src/test/test_routerkeys.c @@ -11,6 +11,7 @@ #include "feature/relay/routerkeys.h" #include "lib/crypt_ops/crypto_cipher.h" #include "lib/crypt_ops/crypto_format.h" +#include "feature/keymgt/loadkey.h" #include "feature/nodelist/torcert.h" #include "test/test.h" diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c index 89d1f4f90f..67af2fd484 100644 --- a/src/test/test_routerlist.c +++ b/src/test/test_routerlist.c @@ -6,19 +6,21 @@ #include <time.h> #define CONNECTION_PRIVATE -#define DIRECTORY_PRIVATE +#define DIRCLIENT_PRIVATE #define DIRVOTE_PRIVATE #define ENTRYNODES_PRIVATE #define HIBERNATE_PRIVATE #define NETWORKSTATUS_PRIVATE #define ROUTERLIST_PRIVATE +#define NODE_SELECT_PRIVATE #define TOR_UNIT_TESTING #include "core/or/or.h" #include "app/config/config.h" #include "core/mainloop/connection.h" #include "feature/control/control.h" #include "lib/crypt_ops/crypto_rand.h" -#include "feature/dircache/directory.h" +#include "feature/dircommon/directory.h" +#include "feature/dirclient/dirclient.h" #include "feature/dirauth/dirvote.h" #include "feature/client/entrynodes.h" #include "feature/hibernate/hibernate.h" @@ -27,9 +29,12 @@ #include "feature/nodelist/nodelist.h" #include "core/or/policies.h" #include "feature/relay/router.h" +#include "feature/nodelist/authcert.h" +#include "feature/nodelist/node_select.h" #include "feature/nodelist/routerlist.h" #include "feature/nodelist/routerset.h" -#include "feature/nodelist/routerparse.h" +#include "feature/dirparse/authcert_parse.h" +#include "feature/dirparse/ns_parse.h" #include "feature/dirauth/shared_random.h" #include "app/config/statefile.h" diff --git a/src/test/test_routerset.c b/src/test/test_routerset.c index db7a6a54ea..86f9c0fa82 100644 --- a/src/test/test_routerset.c +++ b/src/test/test_routerset.c @@ -4,11 +4,11 @@ #define ROUTERSET_PRIVATE #include "core/or/or.h" -#include "feature/stats/geoip.h" -#include "feature/nodelist/routerset.h" -#include "feature/nodelist/routerparse.h" #include "core/or/policies.h" +#include "feature/dirparse/policy_parse.h" #include "feature/nodelist/nodelist.h" +#include "feature/nodelist/routerset.h" +#include "lib/geoip/geoip.h" #include "core/or/addr_policy_st.h" #include "core/or/extend_info_st.h" diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c index 70adf580ab..8a7fb95cc1 100644 --- a/src/test/test_shared_random.c +++ b/src/test/test_shared_random.c @@ -17,8 +17,9 @@ #include "feature/nodelist/networkstatus.h" #include "feature/relay/router.h" #include "feature/relay/routerkeys.h" -#include "feature/nodelist/routerlist.h" -#include "feature/nodelist/routerparse.h" +#include "feature/nodelist/authcert.h" +#include "feature/nodelist/dirlist.h" +#include "feature/dirparse/authcert_parse.h" #include "feature/hs_common/shared_random_client.h" #include "feature/dircommon/voting_schedule.h" diff --git a/src/test/test_status.c b/src/test/test_status.c index 15c406d2ff..3ceba77a84 100644 --- a/src/test/test_status.c +++ b/src/test/test_status.c @@ -21,7 +21,8 @@ #include "feature/stats/rephist.h" #include "core/or/relay.h" #include "feature/relay/router.h" -#include "core/mainloop/main.h" +#include "feature/relay/routermode.h" +#include "core/mainloop/mainloop.h" #include "feature/nodelist/nodelist.h" #include "app/config/statefile.h" #include "lib/tls/tortls.h" diff --git a/src/test/test_workqueue.c b/src/test/test_workqueue.c index 9d48d92773..28fbd6fb9f 100644 --- a/src/test/test_workqueue.c +++ b/src/test/test_workqueue.c @@ -5,7 +5,7 @@ #include "core/or/or.h" #include "lib/thread/threads.h" -#include "core/crypto/onion.h" +#include "core/or/onion.h" #include "lib/evloop/workqueue.h" #include "lib/crypt_ops/crypto_curve25519.h" #include "lib/crypt_ops/crypto_rand.h" diff --git a/src/test/testing_common.c b/src/test/testing_common.c index 5d4c2f15af..c52683afca 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -8,7 +8,7 @@ * \brief Common pieces to implement unit tests. **/ -#define MAIN_PRIVATE +#define MAINLOOP_PRIVATE #include "orconfig.h" #include "core/or/or.h" #include "feature/control/control.h" @@ -16,11 +16,12 @@ #include "lib/crypt_ops/crypto_dh.h" #include "lib/crypt_ops/crypto_ed25519.h" #include "lib/crypt_ops/crypto_rand.h" +#include "feature/stats/predict_ports.h" #include "feature/stats/rephist.h" #include "lib/err/backtrace.h" #include "test/test.h" #include "core/or/channelpadding.h" -#include "core/mainloop/main.h" +#include "core/mainloop/mainloop.h" #include "lib/compress/compress.h" #include "lib/evloop/compat_libevent.h" #include "lib/crypt_ops/crypto_init.h" |