diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/log_test_helpers.c | 69 | ||||
-rw-r--r-- | src/test/log_test_helpers.h | 30 | ||||
-rw-r--r-- | src/test/test.c | 4 | ||||
-rw-r--r-- | src/test/test_address.c | 2 | ||||
-rw-r--r-- | src/test/test_circuitmux.c | 4 | ||||
-rw-r--r-- | src/test/test_compat_libevent.c | 48 | ||||
-rw-r--r-- | src/test/test_config.c | 16 | ||||
-rw-r--r-- | src/test/test_crypto.c | 20 | ||||
-rw-r--r-- | src/test/test_dir.c | 4 | ||||
-rw-r--r-- | src/test/test_dns.c | 2 | ||||
-rw-r--r-- | src/test/test_options.c | 26 | ||||
-rw-r--r-- | src/test/test_rendcache.c | 4 | ||||
-rw-r--r-- | src/test/test_routerlist.c | 2 | ||||
-rw-r--r-- | src/test/test_tortls.c | 131 | ||||
-rw-r--r-- | src/test/test_util_process.c | 8 | ||||
-rw-r--r-- | src/test/testing_common.c | 5 |
16 files changed, 190 insertions, 185 deletions
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c index 88d28e1cc0..bcf73a8437 100644 --- a/src/test/log_test_helpers.c +++ b/src/test/log_test_helpers.c @@ -35,48 +35,6 @@ mock_clean_saved_logs(void) saved_logs = NULL; } -static mock_saved_log_entry_t * -mock_get_log_entry(int ix) -{ - int saved_log_count = mock_saved_log_number(); - if (ix < 0) { - ix = saved_log_count + ix; - } - - if (saved_log_count <= ix) - return NULL; - - return smartlist_get(saved_logs, ix); -} - -const char * -mock_saved_log_at(int ix) -{ - mock_saved_log_entry_t *ent = mock_get_log_entry(ix); - if (ent) - return ent->generated_msg; - else - return ""; -} - -int -mock_saved_severity_at(int ix) -{ - mock_saved_log_entry_t *ent = mock_get_log_entry(ix); - if (ent) - return ent->severity; - else - return -1; -} - -int -mock_saved_log_number(void) -{ - if (!saved_logs) - return 0; - return smartlist_len(saved_logs); -} - const smartlist_t * mock_saved_logs(void) { @@ -100,6 +58,33 @@ mock_saved_log_has_message(const char *msg) return has_msg; } +/* Do the saved logs have any messages with severity? */ +int +mock_saved_log_has_severity(int severity) +{ + int has_sev = 0; + if (saved_logs) { + SMARTLIST_FOREACH(saved_logs, mock_saved_log_entry_t *, m, + { + if (m->severity == severity) { + has_sev = 1; + } + }); + } + + return has_sev; +} + +/* Do the saved logs have any messages? */ +int +mock_saved_log_has_entry(void) +{ + if (saved_logs) { + return smartlist_len(saved_logs) > 0; + } + return 0; +} + void mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, diff --git a/src/test/log_test_helpers.h b/src/test/log_test_helpers.h index 3a565c67c5..02f31a5220 100644 --- a/src/test/log_test_helpers.h +++ b/src/test/log_test_helpers.h @@ -23,10 +23,34 @@ void mock_clean_saved_logs(void); const smartlist_t *mock_saved_logs(void); int setup_capture_of_logs(int new_level); void teardown_capture_of_logs(int prev); -const char *mock_saved_log_at(int ix); -int mock_saved_severity_at(int ix); -int mock_saved_log_number(void); + int mock_saved_log_has_message(const char *msg); +int mock_saved_log_has_severity(int severity); +int mock_saved_log_has_entry(void); + +#define expect_log_msg(str) \ + tt_assert_msg(mock_saved_log_has_message(str), \ + "expected log to contain " # str); + +#define expect_no_log_msg(str) \ + tt_assert_msg(!mock_saved_log_has_message(str), \ + "expected log to not contain " # str); + +#define expect_log_severity(severity) \ + tt_assert_msg(mock_saved_log_has_severity(severity), \ + "expected log to contain severity " # severity); + +#define expect_no_log_severity(severity) \ + tt_assert_msg(!mock_saved_log_has_severity(severity), \ + "expected log to not contain severity " # severity); + +#define expect_log_entry() \ + tt_assert_msg(mock_saved_log_has_entry(), \ + "expected log to contain entries"); + +#define expect_no_log_entry() \ + tt_assert_msg(!mock_saved_log_has_entry(), \ + "expected log to not contain entries"); #endif diff --git a/src/test/test.c b/src/test/test.c index f12ae21ff0..d671ac896e 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -319,11 +319,7 @@ test_circuit_timeout(void *arg) int i, runs; double close_ms; (void)arg; - tor_libevent_cfg cfg; - memset(&cfg, 0, sizeof(cfg)); - - tor_libevent_initialize(&cfg); initialize_periodic_events(); circuit_build_times_init(&initial); diff --git a/src/test/test_address.c b/src/test/test_address.c index 3ddf2476e3..3b17b23571 100644 --- a/src/test/test_address.c +++ b/src/test/test_address.c @@ -532,7 +532,7 @@ test_address_get_if_addrs_ioctl(void *arg) } } - done: + done: if (result) { SMARTLIST_FOREACH(result, tor_addr_t *, t, tor_free(t)); smartlist_free(result); diff --git a/src/test/test_circuitmux.c b/src/test/test_circuitmux.c index 6d93731eea..5c72fc656d 100644 --- a/src/test/test_circuitmux.c +++ b/src/test/test_circuitmux.c @@ -36,11 +36,7 @@ test_cmux_destroy_cell_queue(void *arg) circuit_t *circ = NULL; cell_queue_t *cq = NULL; packed_cell_t *pc = NULL; - tor_libevent_cfg cfg; - memset(&cfg, 0, sizeof(cfg)); - - tor_libevent_initialize(&cfg); scheduler_init(); (void) arg; diff --git a/src/test/test_compat_libevent.c b/src/test/test_compat_libevent.c index 96502df308..f3fe113012 100644 --- a/src/test/test_compat_libevent.c +++ b/src/test/test_compat_libevent.c @@ -30,38 +30,28 @@ test_compat_libevent_logging_callback(void *ignored) int previous_log = setup_capture_of_logs(LOG_DEBUG); libevent_logging_callback(_EVENT_LOG_DEBUG, "hello world"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Message from libevent: hello world\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_DEBUG); + expect_log_msg("Message from libevent: hello world\n"); + expect_log_severity(LOG_DEBUG); mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_MSG, "hello world another time"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Message from libevent: hello world another time\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_msg("Message from libevent: hello world another time\n"); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_WARN, "hello world a third time"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Warning from libevent: hello world a third time\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN); + expect_log_msg("Warning from libevent: hello world a third time\n"); + expect_log_severity(LOG_WARN); mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_ERR, "hello world a fourth time"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Error from libevent: hello world a fourth time\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_ERR); + expect_log_msg("Error from libevent: hello world a fourth time\n"); + expect_log_severity(LOG_ERR); mock_clean_saved_logs(); libevent_logging_callback(42, "hello world a fifth time"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Message [42] from libevent: hello world a fifth time\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN); + expect_log_msg("Message [42] from libevent: hello world a fifth time\n"); + expect_log_severity(LOG_WARN); mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_DEBUG, @@ -78,8 +68,7 @@ test_compat_libevent_logging_callback(void *ignored) "012345678901234567890123456789" "012345678901234567890123456789" ); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: " + expect_log_msg("Message from libevent: " "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789" @@ -92,25 +81,22 @@ test_compat_libevent_logging_callback(void *ignored) "012345678901234567890123456789" "012345678901234567890123456789" "012345678901234567890123456789\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_DEBUG); + expect_log_severity(LOG_DEBUG); mock_clean_saved_logs(); libevent_logging_callback(42, "xxx\n"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "Message [42] from libevent: xxx\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN); + expect_log_msg("Message [42] from libevent: xxx\n"); + expect_log_severity(LOG_WARN); suppress_libevent_log_msg("something"); mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_MSG, "hello there"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Message from libevent: hello there\n"); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_msg("Message from libevent: hello there\n"); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); libevent_logging_callback(_EVENT_LOG_MSG, "hello there something else"); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_msg("hello there something else"); // No way of verifying the result of this, it seems =/ configure_libevent_logging(); diff --git a/src/test/test_config.c b/src/test/test_config.c index 58487d75be..85bedd62c9 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -3958,12 +3958,16 @@ test_config_parse_port_config__ports__ports_given(void *data) smartlist_clear(slout); ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, 0); +#ifdef _WIN32 + tt_int_op(ret, OP_EQ, -1); +#else tt_int_op(ret, OP_EQ, 0); tt_int_op(smartlist_len(slout), OP_EQ, 1); port_cfg = (port_cfg_t *)smartlist_get(slout, 0); tt_int_op(port_cfg->port, OP_EQ, 0); tt_int_op(port_cfg->is_unix_addr, OP_EQ, 1); tt_str_op(port_cfg->unix_addr, OP_EQ, "/tmp/foo/bar"); +#endif // Test failure if we have no ipv4 and no ipv6 (for unix domain sockets, // this makes no sense - it should be fixed) @@ -3984,11 +3988,15 @@ test_config_parse_port_config__ports__ports_given(void *data) ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, CL_PORT_TAKES_HOSTNAMES); +#ifdef _WIN32 + tt_int_op(ret, OP_EQ, -1); +#else tt_int_op(ret, OP_EQ, 0); tt_int_op(smartlist_len(slout), OP_EQ, 1); port_cfg = (port_cfg_t *)smartlist_get(slout, 0); tt_int_op(port_cfg->entry_cfg.ipv4_traffic, OP_EQ, 0); tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 1); +#endif // Test success with both ipv4 and ipv6 (for unix domain sockets, // this makes no sense - it should be fixed) @@ -3999,11 +4007,15 @@ test_config_parse_port_config__ports__ports_given(void *data) ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, CL_PORT_TAKES_HOSTNAMES); +#ifdef _WIN32 + tt_int_op(ret, OP_EQ, -1); +#else tt_int_op(ret, OP_EQ, 0); tt_int_op(smartlist_len(slout), OP_EQ, 1); port_cfg = (port_cfg_t *)smartlist_get(slout, 0); tt_int_op(port_cfg->entry_cfg.ipv4_traffic, OP_EQ, 1); tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 1); +#endif // Test failure if we specify world writable for an IP Port tor_free(config_port_invalid); @@ -4415,10 +4427,14 @@ test_config_parse_port_config__ports__ports_given(void *data) ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, "127.0.0.46", 0, CL_PORT_DFLT_GROUP_WRITABLE); +#ifdef _WIN32 + tt_int_op(ret, OP_EQ, -1); +#else tt_int_op(ret, OP_EQ, 0); tt_int_op(smartlist_len(slout), OP_EQ, 1); port_cfg = (port_cfg_t *)smartlist_get(slout, 0); tt_int_op(port_cfg->is_group_writable, OP_EQ, 1); +#endif done: smartlist_free(slout); diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c index fb21f3ad09..671ae7d7b2 100644 --- a/src/test/test_crypto.c +++ b/src/test/test_crypto.c @@ -147,8 +147,14 @@ test_crypto_rng_engine(void *arg) /* We should correct the method if it's a dummy. */ RAND_set_rand_method(&dummy_method); +#ifdef LIBRESSL_VERSION_NUMBER + /* On libressl, you can't override the RNG. */ + tt_assert(RAND_get_rand_method() == RAND_OpenSSL()); + tt_int_op(0, ==, crypto_force_rand_ssleay()); +#else tt_assert(RAND_get_rand_method() == &dummy_method); tt_int_op(1, ==, crypto_force_rand_ssleay()); +#endif tt_assert(RAND_get_rand_method() == RAND_OpenSSL()); /* Make sure we aren't calling dummy_method */ @@ -1108,6 +1114,11 @@ test_crypto_digests(void *arg) crypto_pk_free(k); } +#ifndef OPENSSL_1_1_API +#define EVP_ENCODE_CTX_new() tor_malloc_zero(sizeof(EVP_ENCODE_CTX)) +#define EVP_ENCODE_CTX_free(ctx) tor_free(ctx) +#endif + /** Encode src into dest with OpenSSL's EVP Encode interface, returning the * length of the encoded data in bytes. */ @@ -1115,12 +1126,13 @@ static int base64_encode_evp(char *dest, char *src, size_t srclen) { const unsigned char *s = (unsigned char*)src; - EVP_ENCODE_CTX ctx; + EVP_ENCODE_CTX *ctx = EVP_ENCODE_CTX_new(); int len, ret; - EVP_EncodeInit(&ctx); - EVP_EncodeUpdate(&ctx, (unsigned char *)dest, &len, s, (int)srclen); - EVP_EncodeFinal(&ctx, (unsigned char *)(dest + len), &ret); + EVP_EncodeInit(ctx); + EVP_EncodeUpdate(ctx, (unsigned char *)dest, &len, s, (int)srclen); + EVP_EncodeFinal(ctx, (unsigned char *)(dest + len), &ret); + EVP_ENCODE_CTX_free(ctx); return ret+ len; } diff --git a/src/test/test_dir.c b/src/test/test_dir.c index 05fbe0a4f6..83a8b8ccc6 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -3238,7 +3238,7 @@ test_dir_packages(void *arg) ADD(4, "clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa"); ADD(5, "clownshoes 22alpha4 http://quumble.example.cam/ blake2=fooa"); - /* Five votes for A ... all from the same guy. Three for B. */ + /* Five votes for A ... all from the same authority. Three for B. */ ADD(0, "cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m"); ADD(1, "cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m"); ADD(3, "cbc 99.1.11.1.1 http://example.com/cbc/ cubehash=ahooy sha512=m"); @@ -3312,7 +3312,6 @@ test_dir_download_status_schedule(void *arg) tt_assert(increment == expected_increment); tt_assert(dls_failure.next_attempt_at == TIME_MIN + expected_increment); -#if TIME_T_IS_SIGNED delay1 = INT_MAX; increment = download_status_schedule_get_delay(&dls_failure, schedule, @@ -3320,7 +3319,6 @@ test_dir_download_status_schedule(void *arg) expected_increment = delay1; tt_assert(increment == expected_increment); tt_assert(dls_failure.next_attempt_at == TIME_MAX); -#endif delay1 = 0; increment = download_status_schedule_get_delay(&dls_attempt, diff --git a/src/test/test_dns.c b/src/test/test_dns.c index 6fdbe905e0..5289ca58ff 100644 --- a/src/test/test_dns.c +++ b/src/test/test_dns.c @@ -490,7 +490,7 @@ NS(test_main)(void *arg) (void)arg; - TO_CONN(exitconn)->address = tor_strdup("127.0.0.1.in-addr.arpa"); + TO_CONN(exitconn)->address = tor_strdup("1.0.0.127.in-addr.arpa"); NS_MOCK(router_my_exit_policy_is_reject_star); diff --git a/src/test/test_options.c b/src/test/test_options.c index e15c88112d..10ee1f962b 100644 --- a/src/test/test_options.c +++ b/src/test/test_options.c @@ -371,7 +371,7 @@ get_options_test_data(const char *conf) } tt_assert(rv == 0); -done: + done: config_free_lines(cl); if (rv != 0) { free_options_test_data(result); @@ -437,7 +437,7 @@ test_options_validate__uname_for_server(void *ignored) fixed_get_uname_result = "Windows 2000"; mock_clean_saved_logs(); options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); + expect_log_entry(); tor_free(msg); done: @@ -949,7 +949,7 @@ test_options_validate__authdir(void *ignored) done: teardown_capture_of_logs(previous_log); - sandbox_free_getaddrinfo_cache(); + // sandbox_free_getaddrinfo_cache(); free_options_test_data(tdata); tor_free(msg); } @@ -993,9 +993,9 @@ test_options_validate__relay_with_hidden_services(void *ignored) /* options_test_data_t *tdata = get_options_test_data(""); */ /* ret = options_validate(tdata->old_opt, tdata->opt, */ /* tdata->def_opt, 0, &msg); */ -/* tt_str_op(mock_saved_log_at(0), OP_EQ, */ -/* "SocksPort, TransPort, NATDPort, DNSPort, and ORPort are all " */ -/* "undefined, and there aren't any hidden services configured. " */ +/* expect_log_msg("SocksPort, TransPort, NATDPort, DNSPort, and ORPort " */ +/* "are all undefined, and there aren't any hidden services " */ +/* "configured. " */ /* " Tor will still run, but probably won't do anything.\n"); */ /* done: */ /* teardown_capture_of_logs(previous_log); */ @@ -1231,8 +1231,7 @@ test_options_validate__scheduler(void *ignored) /* ret = options_validate(tdata->old_opt, tdata->opt, */ /* tdata->def_opt, 0, &msg); */ /* tt_int_op(ret, OP_EQ, -1); */ - /* tt_str_op(mock_saved_log_at(1), OP_EQ, */ - /* "Bad SchedulerLowWaterMark__ option\n"); */ + /* expect_log_msg("Bad SchedulerLowWaterMark__ option\n"); */ free_options_test_data(tdata); tdata = get_options_test_data("SchedulerLowWaterMark__ 42\n" @@ -1485,7 +1484,8 @@ test_options_validate__paths_needed(void *ignored) tt_int_op(ret, OP_EQ, -1); tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.24 && tdata->opt->PathsNeededToBuildCircuits < 0.26); - expect_log_msg("PathsNeededToBuildCircuits is too low. Increasing to 0.25\n"); + expect_log_msg("PathsNeededToBuildCircuits is too low. " + "Increasing to 0.25\n"); tor_free(msg); free_options_test_data(tdata); @@ -1514,7 +1514,7 @@ test_options_validate__paths_needed(void *ignored) tt_int_op(ret, OP_EQ, -1); tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.90 && tdata->opt->PathsNeededToBuildCircuits < 0.92); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); tor_free(msg); done: @@ -1685,7 +1685,7 @@ test_options_validate__reachable_addresses(void *ignored) tdata->opt->FirewallPorts = smartlist_new(); ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg); tt_int_op(ret, OP_EQ, -1); - tt_int_op(mock_saved_log_number(), OP_EQ, 4); + expect_log_entry(); tt_str_op(tdata->opt->ReachableDirAddresses->value, OP_EQ, "*:81"); tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:444"); tor_free(msg); @@ -1720,7 +1720,7 @@ test_options_validate__reachable_addresses(void *ignored) ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg); tt_int_op(ret, OP_EQ, -1); - tt_int_op(mock_saved_log_number(), OP_EQ, 4); + expect_log_entry(); tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:82"); tor_free(msg); @@ -3210,7 +3210,7 @@ test_options_validate__proxy(void *ignored) free_options_test_data(tdata); memarea_clear_freelist(); policies_free_all(); - sandbox_free_getaddrinfo_cache(); + // sandbox_free_getaddrinfo_cache(); tor_free(msg); } diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c index 77796994b4..7e04799db2 100644 --- a/src/test/test_rendcache.c +++ b/src/test/test_rendcache.c @@ -128,8 +128,8 @@ test_rend_cache_store_v2_desc_as_client(void *data) // Test bad base32 failure // This causes an assertion failure if we're running with assertions. - // But when doing coverage, we can test it. -#ifdef TOR_COVERAGE + // But when building without asserts, we can test it. +#ifdef DISABLE_ASSERTS_IN_UNIT_TESTS ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str, "!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL); tt_int_op(ret, OP_EQ, RCS_BADDESC); diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c index 193e3fa8c1..fdbd5abf3b 100644 --- a/src/test/test_routerlist.c +++ b/src/test/test_routerlist.c @@ -312,7 +312,7 @@ test_router_pick_directory_server_impl(void *arg) node_router3->rs->last_dir_503_at = 0; /* Set a Fascist firewall */ - flags &= ! PDS_IGNORE_FASCISTFIREWALL; + flags &= ~ PDS_IGNORE_FASCISTFIREWALL; policy_line = tor_malloc_zero(sizeof(config_line_t)); policy_line->key = tor_strdup("ReachableORAddresses"); policy_line->value = tor_strdup("accept *:442, reject *:*"); diff --git a/src/test/test_tortls.c b/src/test/test_tortls.c index add020e9f4..138485c971 100644 --- a/src/test/test_tortls.c +++ b/src/test/test_tortls.c @@ -344,79 +344,67 @@ test_tortls_log_one_error(void *ignored) int previous_log = setup_capture_of_logs(LOG_INFO); tor_tls_log_one_error(NULL, 0, LOG_WARN, 0, "something"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while something: " + expect_log_msg("TLS error while something: " "(null) (in (null):(null):---)\n"); mock_clean_saved_logs(); tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error: (null) " + expect_log_msg("TLS error: (null) " "(in (null):(null):---)\n"); mock_clean_saved_logs(); tls->address = tor_strdup("127.hello"); tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error with 127.hello: (null) " - "(in (null):(null):---)\n"); + expect_log_msg("TLS error with 127.hello: " + "(null) (in (null):(null):---)\n"); tor_free(tls->address); mock_clean_saved_logs(); tls->address = tor_strdup("127.hello"); tor_tls_log_one_error(tls, 0, LOG_WARN, 0, "blarg"); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while blarg with " + expect_log_msg("TLS error while blarg with " "127.hello: (null) (in (null):(null):---)\n"); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, 3), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error with 127.hello: " + expect_log_msg("TLS error with 127.hello: " "BN lib (in unknown library:(null):---)\n"); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_HTTP_REQUEST), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_HTTPS_PROXY_REQUEST), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_RECORD_LENGTH_MISMATCH), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_RECORD_TOO_LARGE), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_UNKNOWN_PROTOCOL), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); mock_clean_saved_logs(); tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_UNSUPPORTED_PROTOCOL), LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); tls->ssl = SSL_new(ctx); mock_clean_saved_logs(); tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error with 127.hello: (null)" + expect_log_msg("TLS error with 127.hello: (null)" " (in (null):(null):" SSL_STATE_STR ")\n"); done: @@ -450,27 +438,25 @@ test_tortls_get_error(void *ignored) ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_IO); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error: unexpected close while" + expect_log_msg("TLS error: unexpected close while" " something (before/accept initialization)\n"); mock_clean_saved_logs(); ret = tor_tls_get_error(tls, 2, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, 0); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); mock_clean_saved_logs(); ret = tor_tls_get_error(tls, 0, 1, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, -11); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); mock_clean_saved_logs(); ERR_clear_error(); ERR_put_error(ERR_LIB_BN, 2, -1, "somewhere.c", 99); ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_MISC); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while something: (null)" + expect_log_msg("TLS error while something: (null)" " (in bignum routines:(null):before/accept initialization)\n"); mock_clean_saved_logs(); @@ -479,7 +465,7 @@ test_tortls_get_error(void *ignored) SSL_get_rbio(tls->ssl)->flags = BIO_FLAGS_READ; ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, TOR_TLS_WANTREAD); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); mock_clean_saved_logs(); ERR_clear_error(); @@ -487,7 +473,7 @@ test_tortls_get_error(void *ignored) SSL_get_rbio(tls->ssl)->flags = BIO_FLAGS_WRITE; ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, TOR_TLS_WANTWRITE); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); mock_clean_saved_logs(); ERR_clear_error(); @@ -496,20 +482,18 @@ test_tortls_get_error(void *ignored) tls->ssl->s3->warn_alert =SSL_AD_CLOSE_NOTIFY; ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, TOR_TLS_CLOSE); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); + expect_log_entry(); mock_clean_saved_logs(); ret = tor_tls_get_error(tls, 0, 2, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, -10); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); mock_clean_saved_logs(); ERR_put_error(ERR_LIB_SYS, 2, -1, "somewhere.c", 99); ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0); tt_int_op(ret, OP_EQ, -9); - tt_int_op(mock_saved_log_number(), OP_EQ, 2); - tt_str_op(mock_saved_log_at(1), OP_EQ, - "TLS error while something: (null) (in system library:" + expect_log_msg("TLS error while something: (null) (in system library:" "connect:before/accept initialization)\n"); done: @@ -1363,11 +1347,10 @@ test_tortls_get_buffer_sizes(void *ignored) tls->ssl->s3->wbuf.offset = 0; tls->ssl->s3->wbuf.left = 43; + ret = tor_tls_get_buffer_sizes(tls, &rbuf_c, &rbuf_b, &wbuf_c, &wbuf_b); #if OPENSSL_VERSION_NUMBER >= OPENSSL_V_SERIES(1,1,0) - ret = tor_tls_get_buffer_sizes(NULL, NULL, NULL, NULL, NULL); tt_int_op(ret, OP_EQ, -1); #else - ret = tor_tls_get_buffer_sizes(tls, &rbuf_c, &rbuf_b, &wbuf_c, &wbuf_b); tt_int_op(ret, OP_EQ, 0); tt_int_op(rbuf_c, OP_EQ, 0); tt_int_op(wbuf_c, OP_EQ, 0); @@ -1617,11 +1600,18 @@ test_tortls_block_renegotiation(void *ignored) tls = tor_malloc_zero(sizeof(tor_tls_t)); tls->ssl = tor_malloc_zero(sizeof(SSL)); tls->ssl->s3 = tor_malloc_zero(sizeof(SSL3_STATE)); - tls->ssl->s3->flags = 0x0010; +#ifndef SUPPORT_UNSAFE_RENEGOTIATION_FLAG +#define SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0 +#endif + + tls->ssl->s3->flags = SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION; tor_tls_block_renegotiation(tls); - tt_assert(!(SSL_get_options(tls->ssl) & 0x0010)); +#ifndef OPENSSL_1_1_API + tt_assert(!(tls->ssl->s3->flags & + SSL3_FLAGS_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)); +#endif done: tor_free(tls->ssl->s3); @@ -1639,7 +1629,9 @@ test_tortls_unblock_renegotiation(void *ignored) tls->ssl = tor_malloc_zero(sizeof(SSL)); tor_tls_unblock_renegotiation(tls); - tt_assert(SSL_get_options(tls->ssl) & 0x00040000L); + tt_uint_op(SSL_get_options(tls->ssl) & + SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION, OP_EQ, + SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION); done: tor_free(tls->ssl); @@ -1823,12 +1815,12 @@ test_tortls_debug_state_callback(void *ignored) ssl = tor_malloc_zero(sizeof(SSL)); tor_tls_debug_state_callback(ssl, 32, 45); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - n = snprintf(buf, 1000, "SSL %p is now in state unknown" + + n = tor_snprintf(buf, 1000, "SSL %p is now in state unknown" " state [type=32,val=45].\n", ssl); - buf[n]='\0'; - if (strcasecmp(mock_saved_log_at(0), buf)) - tt_str_op(mock_saved_log_at(0), OP_EQ, buf); + /* tor's snprintf returns -1 on error */ + tt_int_op(n, OP_NE, -1); + expect_log_msg(buf); done: teardown_capture_of_logs(previous_log); @@ -1864,21 +1856,17 @@ test_tortls_server_info_callback(void *ignored) SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_A); mock_clean_saved_logs(); tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Couldn't look up the tls for an SSL*. How odd!\n"); + expect_log_msg("Couldn't look up the tls for an SSL*. How odd!\n"); SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B); mock_clean_saved_logs(); tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0); - tt_int_op(mock_saved_log_number(), OP_EQ, 1); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Couldn't look up the tls for an SSL*. How odd!\n"); + expect_log_msg("Couldn't look up the tls for an SSL*. How odd!\n"); SSL_set_state(ssl, 99); mock_clean_saved_logs(); tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); SSL_set_ex_data(tls->ssl, tor_tls_object_ex_data_index, tls); SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B); @@ -1927,6 +1915,7 @@ fixed_ssl_shutdown(SSL *s) return fixed_ssl_shutdown_result; } +#ifndef LIBRESSL_VERSION_NUMBER static int fixed_ssl_state_to_set; static tor_tls_t *fixed_tls; @@ -1944,6 +1933,7 @@ setting_version_and_state_ssl_shutdown(SSL *s) s->version = SSL2_VERSION; return fixed_ssl_shutdown_result; } +#endif static int dummy_handshake_func(SSL *s) @@ -1977,6 +1967,7 @@ test_tortls_shutdown(void *ignored) ret = tor_tls_shutdown(tls); tt_int_op(ret, OP_EQ, -9); +#ifndef LIBRESSL_VERSION_NUMBER tls->ssl->handshake_func = dummy_handshake_func; fixed_ssl_read_result_index = 0; @@ -2038,6 +2029,7 @@ test_tortls_shutdown(void *ignored) method->ssl_shutdown = setting_version_and_state_ssl_shutdown; ret = tor_tls_shutdown(tls); tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_MISC); +#endif done: teardown_capture_of_logs(previous_log); @@ -2100,6 +2092,7 @@ test_tortls_read(void *ignored) ret = tor_tls_read(tls, buf, 10); tt_int_op(negotiated_callback_called, OP_EQ, 1); +#ifndef LIBRESSL_VERSION_NUMBER fixed_ssl_read_result_index = 0; fixed_ssl_read_result[0] = 0; tls->ssl->version = SSL2_VERSION; @@ -2107,7 +2100,7 @@ test_tortls_read(void *ignored) ret = tor_tls_read(tls, buf, 10); tt_int_op(ret, OP_EQ, TOR_TLS_CLOSE); tt_int_op(tls->state, OP_EQ, TOR_TLS_ST_CLOSED); - +#endif // TODO: fill up done: @@ -2255,18 +2248,15 @@ test_tortls_handshake(void *ignored) tls->state = TOR_TLS_ST_HANDSHAKE; ret = tor_tls_handshake(tls); tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_MISC); - tt_int_op(mock_saved_log_number(), OP_EQ, 2); + expect_log_entry(); /* This fails on jessie. Investigate why! */ #if 0 - tt_str_op(mock_saved_log_at(0), OP_EQ, - "TLS error while handshaking: (null) (in bignum routines:" + expect_log_msg("TLS error while handshaking: (null) (in bignum routines:" "(null):SSLv3 write client hello B)\n"); - tt_str_op(mock_saved_log_at(1), OP_EQ, - "TLS error while handshaking: (null) (in system library:" + expect_log_msg("TLS error while handshaking: (null) (in system library:" "connect:SSLv3 write client hello B)\n"); #endif - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO); - tt_int_op(mock_saved_severity_at(1), OP_EQ, LOG_INFO); + expect_log_severity(LOG_INFO); tls->isServer = 0; method->ssl_connect = setting_error_ssl_connect; @@ -2276,16 +2266,15 @@ test_tortls_handshake(void *ignored) tls->state = TOR_TLS_ST_HANDSHAKE; ret = tor_tls_handshake(tls); tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_MISC); - tt_int_op(mock_saved_log_number(), OP_EQ, 2); + expect_log_entry(); #if 0 /* See above */ - tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while handshaking: " + expect_log_msg("TLS error while handshaking: " "(null) (in bignum routines:(null):SSLv3 write client hello B)\n"); - tt_str_op(mock_saved_log_at(1), OP_EQ, "TLS error while handshaking: " + expect_log_msg("TLS error while handshaking: " "(null) (in system library:connect:SSLv3 write client hello B)\n"); #endif - tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN); - tt_int_op(mock_saved_severity_at(1), OP_EQ, LOG_WARN); + expect_log_severity(LOG_WARN); done: teardown_capture_of_logs(previous_log); @@ -2618,14 +2607,14 @@ test_tortls_create_certificate(void *ignored) tt_assert(!ret); fixed_crypto_pk_get_evp_pkey_result_index = 0; - fixed_crypto_pk_get_evp_pkey_result[0] = tor_malloc_zero(sizeof(EVP_PKEY)); + fixed_crypto_pk_get_evp_pkey_result[0] = EVP_PKEY_new(); fixed_crypto_pk_get_evp_pkey_result[1] = NULL; ret = tor_tls_create_certificate(pk1, pk2, "hello", "hello2", 1); tt_assert(!ret); fixed_crypto_pk_get_evp_pkey_result_index = 0; - fixed_crypto_pk_get_evp_pkey_result[0] = tor_malloc_zero(sizeof(EVP_PKEY)); - fixed_crypto_pk_get_evp_pkey_result[1] = tor_malloc_zero(sizeof(EVP_PKEY)); + fixed_crypto_pk_get_evp_pkey_result[0] = EVP_PKEY_new(); + fixed_crypto_pk_get_evp_pkey_result[1] = EVP_PKEY_new(); ret = tor_tls_create_certificate(pk1, pk2, "hello", "hello2", 1); tt_assert(!ret); diff --git a/src/test/test_util_process.c b/src/test/test_util_process.c index cb1d5b2ebb..0a4354c043 100644 --- a/src/test/test_util_process.c +++ b/src/test/test_util_process.c @@ -34,8 +34,7 @@ test_util_process_set_waitpid_callback(void *ignored) res2 = set_waitpid_callback(pid, temp_callback, NULL); tt_assert(res2); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Replaced a waitpid monitor on pid 42. That should be " + expect_log_msg("Replaced a waitpid monitor on pid 42. That should be " "impossible.\n"); done: @@ -56,13 +55,12 @@ test_util_process_clear_waitpid_callback(void *ignored) res = set_waitpid_callback(pid, temp_callback, NULL); clear_waitpid_callback(res); - tt_int_op(mock_saved_log_number(), OP_EQ, 0); + expect_no_log_entry(); #if 0 /* No. This is use-after-free. We don't _do_ that. XXXX */ clear_waitpid_callback(res); - tt_str_op(mock_saved_log_at(0), OP_EQ, - "Couldn't remove waitpid monitor for pid 43.\n"); + expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n"); #endif done: diff --git a/src/test/testing_common.c b/src/test/testing_common.c index e20e9e6095..9c7fca05a5 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -238,6 +238,11 @@ main(int c, const char **v) update_approx_time(time(NULL)); options = options_new(); tor_threads_init(); + + struct tor_libevent_cfg cfg; + memset(&cfg, 0, sizeof(cfg)); + tor_libevent_initialize(&cfg); + control_initialize_event_queue(); init_logging(1); configure_backtrace_handler(get_version()); |