relay: Refactor tests, and add extra options tests

Part of 32213.
This commit is contained in:
teor 2019-10-30 22:51:56 +10:00
parent 51ca6dea08
commit 73c0439d48

View File

@ -1002,6 +1002,7 @@ test_options_validate__relay_with_hidden_services(void *ignored)
{ {
(void)ignored; (void)ignored;
char *msg; char *msg;
int ret;
setup_capture_of_logs(LOG_DEBUG); setup_capture_of_logs(LOG_DEBUG);
options_test_data_t *tdata = get_options_test_data( options_test_data_t *tdata = get_options_test_data(
"ORPort 127.0.0.1:5555\n" "ORPort 127.0.0.1:5555\n"
@ -1010,7 +1011,8 @@ test_options_validate__relay_with_hidden_services(void *ignored)
"HiddenServicePort 80 127.0.0.1:8080\n" "HiddenServicePort 80 127.0.0.1:8080\n"
); );
options_validate(NULL, tdata->opt, &msg); ret = options_validate(NULL, tdata->opt, &msg);
tt_int_op(ret, OP_EQ, 0);
expect_log_msg( expect_log_msg(
"Tor is currently configured as a relay and a hidden service. " "Tor is currently configured as a relay and a hidden service. "
"That's not very secure: you should probably run your hidden servi" "That's not very secure: you should probably run your hidden servi"
@ -1023,27 +1025,25 @@ test_options_validate__relay_with_hidden_services(void *ignored)
tor_free(msg); tor_free(msg);
} }
// TODO: it doesn't seem possible to hit the case of having no port lines at static void
// all, since there will be a default created for SocksPort test_options_validate__listen_ports(void *ignored)
/* static void */ {
/* test_options_validate__ports(void *ignored) */ (void)ignored;
/* { */ int ret;
/* (void)ignored; */ char *msg;
/* int ret; */ setup_capture_of_logs(LOG_WARN);
/* char *msg; */ options_test_data_t *tdata = get_options_test_data("SOCKSPort 0");
/* setup_capture_of_logs(LOG_WARN); */ ret = options_validate(NULL, tdata->opt, &msg);
/* options_test_data_t *tdata = get_options_test_data(""); */ tt_int_op(ret, OP_EQ, 0);
/* ret = options_validate(NULL, tdata->opt, */ expect_log_msg("SocksPort, TransPort, NATDPort, DNSPort, and ORPort "
/* tdata->def_opt, 0, &msg); */ "are all undefined, and there aren't any hidden services "
/* expect_log_msg("SocksPort, TransPort, NATDPort, DNSPort, and ORPort " */ "configured. "
/* "are all undefined, and there aren't any hidden services " */ " Tor will still run, but probably won't do anything.\n");
/* "configured. " */ done:
/* " Tor will still run, but probably won't do anything.\n"); */ teardown_capture_of_logs();
/* done: */ free_options_test_data(tdata);
/* teardown_capture_of_logs(); */ tor_free(msg);
/* free_options_test_data(tdata); */ }
/* tor_free(msg); */
/* } */
static void static void
test_options_validate__transproxy(void *ignored) test_options_validate__transproxy(void *ignored)
@ -2561,6 +2561,20 @@ test_options_validate__accounting(void *ignored)
tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_MAX); tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_MAX);
tor_free(msg); tor_free(msg);
free_options_test_data(tdata);
tdata = get_options_test_data("AccountingRule in\n");
ret = options_validate(NULL, tdata->opt, &msg);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_IN);
tor_free(msg);
free_options_test_data(tdata);
tdata = get_options_test_data("AccountingRule out\n");
ret = options_validate(NULL, tdata->opt, &msg);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(tdata->opt->AccountingRule, OP_EQ, ACCT_OUT);
tor_free(msg);
free_options_test_data(tdata); free_options_test_data(tdata);
tdata = get_options_test_data("AccountingStart fail\n"); tdata = get_options_test_data("AccountingStart fail\n");
ret = options_validate(NULL, tdata->opt, &msg); ret = options_validate(NULL, tdata->opt, &msg);
@ -4299,6 +4313,7 @@ struct testcase_t options_tests[] = {
LOCAL_VALIDATE_TEST(logs), LOCAL_VALIDATE_TEST(logs),
LOCAL_VALIDATE_TEST(authdir), LOCAL_VALIDATE_TEST(authdir),
LOCAL_VALIDATE_TEST(relay_with_hidden_services), LOCAL_VALIDATE_TEST(relay_with_hidden_services),
LOCAL_VALIDATE_TEST(listen_ports),
LOCAL_VALIDATE_TEST(transproxy), LOCAL_VALIDATE_TEST(transproxy),
LOCAL_VALIDATE_TEST(exclude_nodes), LOCAL_VALIDATE_TEST(exclude_nodes),
LOCAL_VALIDATE_TEST(node_families), LOCAL_VALIDATE_TEST(node_families),