mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Make all unit tests independent of log message order and count
This commit is contained in:
parent
dbb5819e96
commit
f7b2ae91e9
@ -35,48 +35,6 @@ mock_clean_saved_logs(void)
|
|||||||
saved_logs = NULL;
|
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 *
|
const smartlist_t *
|
||||||
mock_saved_logs(void)
|
mock_saved_logs(void)
|
||||||
{
|
{
|
||||||
@ -100,6 +58,33 @@ mock_saved_log_has_message(const char *msg)
|
|||||||
return has_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
|
void
|
||||||
mock_saving_logv(int severity, log_domain_mask_t domain,
|
mock_saving_logv(int severity, log_domain_mask_t domain,
|
||||||
const char *funcname, const char *suffix,
|
const char *funcname, const char *suffix,
|
||||||
|
@ -23,10 +23,33 @@ void mock_clean_saved_logs(void);
|
|||||||
const smartlist_t *mock_saved_logs(void);
|
const smartlist_t *mock_saved_logs(void);
|
||||||
int setup_capture_of_logs(int new_level);
|
int setup_capture_of_logs(int new_level);
|
||||||
void teardown_capture_of_logs(int prev);
|
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_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
|
#endif
|
||||||
|
|
||||||
|
@ -30,38 +30,28 @@ test_compat_libevent_logging_callback(void *ignored)
|
|||||||
int previous_log = setup_capture_of_logs(LOG_DEBUG);
|
int previous_log = setup_capture_of_logs(LOG_DEBUG);
|
||||||
|
|
||||||
libevent_logging_callback(_EVENT_LOG_DEBUG, "hello world");
|
libevent_logging_callback(_EVENT_LOG_DEBUG, "hello world");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Message from libevent: hello world\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_severity(LOG_DEBUG);
|
||||||
"Message from libevent: hello world\n");
|
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_DEBUG);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(_EVENT_LOG_MSG, "hello world another time");
|
libevent_logging_callback(_EVENT_LOG_MSG, "hello world another time");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Message from libevent: hello world another time\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_severity(LOG_INFO);
|
||||||
"Message from libevent: hello world another time\n");
|
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(_EVENT_LOG_WARN, "hello world a third time");
|
libevent_logging_callback(_EVENT_LOG_WARN, "hello world a third time");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Warning from libevent: hello world a third time\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_severity(LOG_WARN);
|
||||||
"Warning from libevent: hello world a third time\n");
|
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(_EVENT_LOG_ERR, "hello world a fourth time");
|
libevent_logging_callback(_EVENT_LOG_ERR, "hello world a fourth time");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Error from libevent: hello world a fourth time\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_severity(LOG_ERR);
|
||||||
"Error from libevent: hello world a fourth time\n");
|
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_ERR);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(42, "hello world a fifth time");
|
libevent_logging_callback(42, "hello world a fifth time");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Message [42] from libevent: hello world a fifth time\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_severity(LOG_WARN);
|
||||||
"Message [42] from libevent: hello world a fifth time\n");
|
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(_EVENT_LOG_DEBUG,
|
libevent_logging_callback(_EVENT_LOG_DEBUG,
|
||||||
@ -78,8 +68,7 @@ test_compat_libevent_logging_callback(void *ignored)
|
|||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
);
|
);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Message from libevent: "
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "Message from libevent: "
|
|
||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
@ -92,25 +81,22 @@ test_compat_libevent_logging_callback(void *ignored)
|
|||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
"012345678901234567890123456789"
|
"012345678901234567890123456789"
|
||||||
"012345678901234567890123456789\n");
|
"012345678901234567890123456789\n");
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_DEBUG);
|
expect_log_severity(LOG_DEBUG);
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(42, "xxx\n");
|
libevent_logging_callback(42, "xxx\n");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Message [42] from libevent: xxx\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "Message [42] from libevent: xxx\n");
|
expect_log_severity(LOG_WARN);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN);
|
|
||||||
|
|
||||||
suppress_libevent_log_msg("something");
|
suppress_libevent_log_msg("something");
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(_EVENT_LOG_MSG, "hello there");
|
libevent_logging_callback(_EVENT_LOG_MSG, "hello there");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Message from libevent: hello there\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_severity(LOG_INFO);
|
||||||
"Message from libevent: hello there\n");
|
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
libevent_logging_callback(_EVENT_LOG_MSG, "hello there something else");
|
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 =/
|
// No way of verifying the result of this, it seems =/
|
||||||
configure_libevent_logging();
|
configure_libevent_logging();
|
||||||
|
@ -392,14 +392,6 @@ free_options_test_data(options_test_data_t *td)
|
|||||||
tor_free(td);
|
tor_free(td);
|
||||||
}
|
}
|
||||||
|
|
||||||
#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);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_options_validate__uname_for_server(void *ignored)
|
test_options_validate__uname_for_server(void *ignored)
|
||||||
{
|
{
|
||||||
@ -436,7 +428,7 @@ test_options_validate__uname_for_server(void *ignored)
|
|||||||
fixed_get_uname_result = "Windows 2000";
|
fixed_get_uname_result = "Windows 2000";
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
|
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);
|
tor_free(msg);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -992,9 +984,9 @@ test_options_validate__relay_with_hidden_services(void *ignored)
|
|||||||
/* options_test_data_t *tdata = get_options_test_data(""); */
|
/* options_test_data_t *tdata = get_options_test_data(""); */
|
||||||
/* ret = options_validate(tdata->old_opt, tdata->opt, */
|
/* ret = options_validate(tdata->old_opt, tdata->opt, */
|
||||||
/* tdata->def_opt, 0, &msg); */
|
/* tdata->def_opt, 0, &msg); */
|
||||||
/* tt_str_op(mock_saved_log_at(0), OP_EQ, */
|
/* expect_log_msg("SocksPort, TransPort, NATDPort, DNSPort, and ORPort " */
|
||||||
/* "SocksPort, TransPort, NATDPort, DNSPort, and ORPort are all " */
|
/* "are all undefined, and there aren't any hidden services " */
|
||||||
/* "undefined, and there aren't any hidden services configured. " */
|
/* "configured. " */
|
||||||
/* " Tor will still run, but probably won't do anything.\n"); */
|
/* " Tor will still run, but probably won't do anything.\n"); */
|
||||||
/* done: */
|
/* done: */
|
||||||
/* teardown_capture_of_logs(previous_log); */
|
/* teardown_capture_of_logs(previous_log); */
|
||||||
@ -1230,8 +1222,7 @@ test_options_validate__scheduler(void *ignored)
|
|||||||
/* ret = options_validate(tdata->old_opt, tdata->opt, */
|
/* ret = options_validate(tdata->old_opt, tdata->opt, */
|
||||||
/* tdata->def_opt, 0, &msg); */
|
/* tdata->def_opt, 0, &msg); */
|
||||||
/* tt_int_op(ret, OP_EQ, -1); */
|
/* tt_int_op(ret, OP_EQ, -1); */
|
||||||
/* tt_str_op(mock_saved_log_at(1), OP_EQ, */
|
/* expect_log_msg("Bad SchedulerLowWaterMark__ option\n"); */
|
||||||
/* "Bad SchedulerLowWaterMark__ option\n"); */
|
|
||||||
|
|
||||||
free_options_test_data(tdata);
|
free_options_test_data(tdata);
|
||||||
tdata = get_options_test_data("SchedulerLowWaterMark__ 42\n"
|
tdata = get_options_test_data("SchedulerLowWaterMark__ 42\n"
|
||||||
@ -1513,7 +1504,7 @@ test_options_validate__paths_needed(void *ignored)
|
|||||||
tt_int_op(ret, OP_EQ, -1);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.90 &&
|
tt_assert(tdata->opt->PathsNeededToBuildCircuits > 0.90 &&
|
||||||
tdata->opt->PathsNeededToBuildCircuits < 0.92);
|
tdata->opt->PathsNeededToBuildCircuits < 0.92);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 0);
|
expect_no_log_entry();
|
||||||
tor_free(msg);
|
tor_free(msg);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -1684,7 +1675,7 @@ test_options_validate__reachable_addresses(void *ignored)
|
|||||||
tdata->opt->FirewallPorts = smartlist_new();
|
tdata->opt->FirewallPorts = smartlist_new();
|
||||||
ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
|
ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
|
||||||
tt_int_op(ret, OP_EQ, -1);
|
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->ReachableDirAddresses->value, OP_EQ, "*:81");
|
||||||
tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:444");
|
tt_str_op(tdata->opt->ReachableORAddresses->value, OP_EQ, "*:444");
|
||||||
tor_free(msg);
|
tor_free(msg);
|
||||||
@ -1719,7 +1710,7 @@ test_options_validate__reachable_addresses(void *ignored)
|
|||||||
|
|
||||||
ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
|
ret = options_validate(tdata->old_opt, tdata->opt, tdata->def_opt, 0, &msg);
|
||||||
tt_int_op(ret, OP_EQ, -1);
|
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");
|
tt_str_op(tdata->opt->ReachableAddresses->value, OP_EQ, "*:82");
|
||||||
tor_free(msg);
|
tor_free(msg);
|
||||||
|
|
||||||
|
@ -344,79 +344,67 @@ test_tortls_log_one_error(void *ignored)
|
|||||||
int previous_log = setup_capture_of_logs(LOG_INFO);
|
int previous_log = setup_capture_of_logs(LOG_INFO);
|
||||||
|
|
||||||
tor_tls_log_one_error(NULL, 0, LOG_WARN, 0, "something");
|
tor_tls_log_one_error(NULL, 0, LOG_WARN, 0, "something");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error while something: "
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while something: "
|
|
||||||
"(null) (in (null):(null):---)\n");
|
"(null) (in (null):(null):---)\n");
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL);
|
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error: (null) "
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error: (null) "
|
|
||||||
"(in (null):(null):---)\n");
|
"(in (null):(null):---)\n");
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tls->address = tor_strdup("127.hello");
|
tls->address = tor_strdup("127.hello");
|
||||||
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL);
|
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error with 127.hello: "
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error with 127.hello: (null) "
|
"(null) (in (null):(null):---)\n");
|
||||||
"(in (null):(null):---)\n");
|
|
||||||
tor_free(tls->address);
|
tor_free(tls->address);
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tls->address = tor_strdup("127.hello");
|
tls->address = tor_strdup("127.hello");
|
||||||
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, "blarg");
|
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, "blarg");
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error while blarg with "
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while blarg with "
|
|
||||||
"127.hello: (null) (in (null):(null):---)\n");
|
"127.hello: (null) (in (null):(null):---)\n");
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, 3), LOG_WARN, 0, NULL);
|
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);
|
expect_log_msg("TLS error with 127.hello: "
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error with 127.hello: "
|
|
||||||
"BN lib (in unknown library:(null):---)\n");
|
"BN lib (in unknown library:(null):---)\n");
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_HTTP_REQUEST),
|
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_HTTP_REQUEST),
|
||||||
LOG_WARN, 0, NULL);
|
LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_HTTPS_PROXY_REQUEST),
|
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_HTTPS_PROXY_REQUEST),
|
||||||
LOG_WARN, 0, NULL);
|
LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_RECORD_LENGTH_MISMATCH),
|
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_RECORD_LENGTH_MISMATCH),
|
||||||
LOG_WARN, 0, NULL);
|
LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_RECORD_TOO_LARGE),
|
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_RECORD_TOO_LARGE),
|
||||||
LOG_WARN, 0, NULL);
|
LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_UNKNOWN_PROTOCOL),
|
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_UNKNOWN_PROTOCOL),
|
||||||
LOG_WARN, 0, NULL);
|
LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_UNSUPPORTED_PROTOCOL),
|
tor_tls_log_one_error(tls, ERR_PACK(1, 2, SSL_R_UNSUPPORTED_PROTOCOL),
|
||||||
LOG_WARN, 0, NULL);
|
LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
tls->ssl = SSL_new(ctx);
|
tls->ssl = SSL_new(ctx);
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL);
|
tor_tls_log_one_error(tls, 0, LOG_WARN, 0, NULL);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error with 127.hello: (null)"
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error with 127.hello: (null)"
|
|
||||||
" (in (null):(null):" SSL_STATE_STR ")\n");
|
" (in (null):(null):" SSL_STATE_STR ")\n");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -450,27 +438,25 @@ test_tortls_get_error(void *ignored)
|
|||||||
|
|
||||||
ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0);
|
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(ret, OP_EQ, TOR_TLS_ERROR_IO);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error: unexpected close while"
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error: unexpected close while"
|
|
||||||
" something (before/accept initialization)\n");
|
" something (before/accept initialization)\n");
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
ret = tor_tls_get_error(tls, 2, 0, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, 2, 0, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, 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();
|
mock_clean_saved_logs();
|
||||||
ret = tor_tls_get_error(tls, 0, 1, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, 0, 1, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, -11);
|
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();
|
mock_clean_saved_logs();
|
||||||
ERR_clear_error();
|
ERR_clear_error();
|
||||||
ERR_put_error(ERR_LIB_BN, 2, -1, "somewhere.c", 99);
|
ERR_put_error(ERR_LIB_BN, 2, -1, "somewhere.c", 99);
|
||||||
ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0);
|
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(ret, OP_EQ, TOR_TLS_ERROR_MISC);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("TLS error while something: (null)"
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, "TLS error while something: (null)"
|
|
||||||
" (in bignum routines:(null):before/accept initialization)\n");
|
" (in bignum routines:(null):before/accept initialization)\n");
|
||||||
|
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
@ -479,7 +465,7 @@ test_tortls_get_error(void *ignored)
|
|||||||
SSL_get_rbio(tls->ssl)->flags = BIO_FLAGS_READ;
|
SSL_get_rbio(tls->ssl)->flags = BIO_FLAGS_READ;
|
||||||
ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, TOR_TLS_WANTREAD);
|
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();
|
mock_clean_saved_logs();
|
||||||
ERR_clear_error();
|
ERR_clear_error();
|
||||||
@ -487,7 +473,7 @@ test_tortls_get_error(void *ignored)
|
|||||||
SSL_get_rbio(tls->ssl)->flags = BIO_FLAGS_WRITE;
|
SSL_get_rbio(tls->ssl)->flags = BIO_FLAGS_WRITE;
|
||||||
ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, TOR_TLS_WANTWRITE);
|
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();
|
mock_clean_saved_logs();
|
||||||
ERR_clear_error();
|
ERR_clear_error();
|
||||||
@ -496,20 +482,18 @@ test_tortls_get_error(void *ignored)
|
|||||||
tls->ssl->s3->warn_alert =SSL_AD_CLOSE_NOTIFY;
|
tls->ssl->s3->warn_alert =SSL_AD_CLOSE_NOTIFY;
|
||||||
ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, 0, 0, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, TOR_TLS_CLOSE);
|
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();
|
mock_clean_saved_logs();
|
||||||
ret = tor_tls_get_error(tls, 0, 2, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, 0, 2, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, -10);
|
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();
|
mock_clean_saved_logs();
|
||||||
ERR_put_error(ERR_LIB_SYS, 2, -1, "somewhere.c", 99);
|
ERR_put_error(ERR_LIB_SYS, 2, -1, "somewhere.c", 99);
|
||||||
ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0);
|
ret = tor_tls_get_error(tls, -1, 0, "something", LOG_WARN, 0);
|
||||||
tt_int_op(ret, OP_EQ, -9);
|
tt_int_op(ret, OP_EQ, -9);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 2);
|
expect_log_msg("TLS error while something: (null) (in system library:"
|
||||||
tt_str_op(mock_saved_log_at(1), OP_EQ,
|
|
||||||
"TLS error while something: (null) (in system library:"
|
|
||||||
"connect:before/accept initialization)\n");
|
"connect:before/accept initialization)\n");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -1823,12 +1807,11 @@ test_tortls_debug_state_callback(void *ignored)
|
|||||||
ssl = tor_malloc_zero(sizeof(SSL));
|
ssl = tor_malloc_zero(sizeof(SSL));
|
||||||
|
|
||||||
tor_tls_debug_state_callback(ssl, 32, 45);
|
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 = snprintf(buf, 1000, "SSL %p is now in state unknown"
|
||||||
" state [type=32,val=45].\n", ssl);
|
" state [type=32,val=45].\n", ssl);
|
||||||
buf[n]='\0';
|
buf[n]='\0';
|
||||||
if (strcasecmp(mock_saved_log_at(0), buf))
|
expect_log_msg(buf);
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ, buf);
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
teardown_capture_of_logs(previous_log);
|
teardown_capture_of_logs(previous_log);
|
||||||
@ -1864,21 +1847,17 @@ test_tortls_server_info_callback(void *ignored)
|
|||||||
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_A);
|
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_A);
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
|
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Couldn't look up the tls for an SSL*. How odd!\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
|
||||||
"Couldn't look up the tls for an SSL*. How odd!\n");
|
|
||||||
|
|
||||||
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B);
|
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B);
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
|
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 1);
|
expect_log_msg("Couldn't look up the tls for an SSL*. How odd!\n");
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
|
||||||
"Couldn't look up the tls for an SSL*. How odd!\n");
|
|
||||||
|
|
||||||
SSL_set_state(ssl, 99);
|
SSL_set_state(ssl, 99);
|
||||||
mock_clean_saved_logs();
|
mock_clean_saved_logs();
|
||||||
tor_tls_server_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 0);
|
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_ex_data(tls->ssl, tor_tls_object_ex_data_index, tls);
|
||||||
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B);
|
SSL_set_state(ssl, SSL3_ST_SW_SRVR_HELLO_B);
|
||||||
@ -2255,18 +2234,15 @@ test_tortls_handshake(void *ignored)
|
|||||||
tls->state = TOR_TLS_ST_HANDSHAKE;
|
tls->state = TOR_TLS_ST_HANDSHAKE;
|
||||||
ret = tor_tls_handshake(tls);
|
ret = tor_tls_handshake(tls);
|
||||||
tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_MISC);
|
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! */
|
/* This fails on jessie. Investigate why! */
|
||||||
#if 0
|
#if 0
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_msg("TLS error while handshaking: (null) (in bignum routines:"
|
||||||
"TLS error while handshaking: (null) (in bignum routines:"
|
|
||||||
"(null):SSLv3 write client hello B)\n");
|
"(null):SSLv3 write client hello B)\n");
|
||||||
tt_str_op(mock_saved_log_at(1), OP_EQ,
|
expect_log_msg("TLS error while handshaking: (null) (in system library:"
|
||||||
"TLS error while handshaking: (null) (in system library:"
|
|
||||||
"connect:SSLv3 write client hello B)\n");
|
"connect:SSLv3 write client hello B)\n");
|
||||||
#endif
|
#endif
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_INFO);
|
expect_log_severity(LOG_INFO);
|
||||||
tt_int_op(mock_saved_severity_at(1), OP_EQ, LOG_INFO);
|
|
||||||
|
|
||||||
tls->isServer = 0;
|
tls->isServer = 0;
|
||||||
method->ssl_connect = setting_error_ssl_connect;
|
method->ssl_connect = setting_error_ssl_connect;
|
||||||
@ -2276,16 +2252,15 @@ test_tortls_handshake(void *ignored)
|
|||||||
tls->state = TOR_TLS_ST_HANDSHAKE;
|
tls->state = TOR_TLS_ST_HANDSHAKE;
|
||||||
ret = tor_tls_handshake(tls);
|
ret = tor_tls_handshake(tls);
|
||||||
tt_int_op(ret, OP_EQ, TOR_TLS_ERROR_MISC);
|
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
|
#if 0
|
||||||
/* See above */
|
/* 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");
|
"(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");
|
"(null) (in system library:connect:SSLv3 write client hello B)\n");
|
||||||
#endif
|
#endif
|
||||||
tt_int_op(mock_saved_severity_at(0), OP_EQ, LOG_WARN);
|
expect_log_severity(LOG_WARN);
|
||||||
tt_int_op(mock_saved_severity_at(1), OP_EQ, LOG_WARN);
|
|
||||||
|
|
||||||
done:
|
done:
|
||||||
teardown_capture_of_logs(previous_log);
|
teardown_capture_of_logs(previous_log);
|
||||||
|
@ -34,8 +34,7 @@ test_util_process_set_waitpid_callback(void *ignored)
|
|||||||
|
|
||||||
res2 = set_waitpid_callback(pid, temp_callback, NULL);
|
res2 = set_waitpid_callback(pid, temp_callback, NULL);
|
||||||
tt_assert(res2);
|
tt_assert(res2);
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_msg("Replaced a waitpid monitor on pid 42. That should be "
|
||||||
"Replaced a waitpid monitor on pid 42. That should be "
|
|
||||||
"impossible.\n");
|
"impossible.\n");
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -56,13 +55,12 @@ test_util_process_clear_waitpid_callback(void *ignored)
|
|||||||
|
|
||||||
res = set_waitpid_callback(pid, temp_callback, NULL);
|
res = set_waitpid_callback(pid, temp_callback, NULL);
|
||||||
clear_waitpid_callback(res);
|
clear_waitpid_callback(res);
|
||||||
tt_int_op(mock_saved_log_number(), OP_EQ, 0);
|
expect_no_log_entry();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* No. This is use-after-free. We don't _do_ that. XXXX */
|
/* No. This is use-after-free. We don't _do_ that. XXXX */
|
||||||
clear_waitpid_callback(res);
|
clear_waitpid_callback(res);
|
||||||
tt_str_op(mock_saved_log_at(0), OP_EQ,
|
expect_log_msg("Couldn't remove waitpid monitor for pid 43.\n");
|
||||||
"Couldn't remove waitpid monitor for pid 43.\n");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
Loading…
Reference in New Issue
Block a user