diff options
author | Isis Lovecruft <isis@torproject.org> | 2017-10-23 19:44:06 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-10-24 19:26:24 -0400 |
commit | 02cde0d9398c43de3a67133b7982d9df6962fe32 (patch) | |
tree | e84e8252f9e8357b530c171a69c3eff01e1eb873 /src/test/test_config.c | |
parent | b0e10f23ba2b03f275ef4acf2183a02042e6cded (diff) | |
download | tor-02cde0d9398c43de3a67133b7982d9df6962fe32.tar.gz tor-02cde0d9398c43de3a67133b7982d9df6962fe32.zip |
test: Add unittest for descriptors with BridgeDistribution option.
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r-- | src/test/test_config.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c index 89f9b3e2aa..396f06adff 100644 --- a/src/test/test_config.c +++ b/src/test/test_config.c @@ -4890,6 +4890,65 @@ test_config_parse_port_config__ports__server_options(void *data) config_free_lines(config_port_valid); config_port_valid = NULL; } +/* If we're not configured to be a bridge, but we set + * BridgeDistribution, then options_validate () should return -1. */ +static void +test_config_check_bridge_distribution_setting_not_a_bridge(void *arg) { + or_options_t* options = get_options_mutable(); + or_options_t* old_options = options; + or_options_t* default_options = options; + char* message = (char*)(""); + int ret; + + (void)arg; + + options->BridgeRelay = 0; + options->BridgeDistribution = (char*)("https"); + + ret = options_validate(old_options, options, default_options, 0, &message); + + tt_int_op(ret, OP_EQ, -1); + done: + return; +} + +/* If the BridgeDistribution setting was valid, 0 should be returned. */ +static void +test_config_check_bridge_distribution_setting_valid(void *arg) { + int ret = check_bridge_distribution_setting("https"); + + (void)arg; + + tt_int_op(ret, OP_EQ, 0); + done: + return; +} + +/* If the BridgeDistribution setting was invalid, -1 should be returned. */ +static void +test_config_check_bridge_distribution_setting_invalid(void *arg) { + int ret = check_bridge_distribution_setting("hyphens-are-not-allowed"); + + (void)arg; + + tt_int_op(ret, OP_EQ, -1); + done: + return; +} + +/* If the BridgeDistribution setting was unrecognised, a warning should be + * logged and 0 should be returned. */ +static void +test_config_check_bridge_distribution_setting_unrecognised(void *arg) { + int ret = check_bridge_distribution_setting("unicorn"); + + (void)arg; + + tt_int_op(ret, OP_EQ, 0); + done: + return; +} + #define CONFIG_TEST(name, flags) \ { #name, test_config_ ## name, flags, NULL, NULL } @@ -4916,6 +4975,10 @@ struct testcase_t config_tests[] = { CONFIG_TEST(parse_port_config__ports__no_ports_given, 0), CONFIG_TEST(parse_port_config__ports__server_options, 0), CONFIG_TEST(parse_port_config__ports__ports_given, 0), + CONFIG_TEST(check_bridge_distribution_setting_not_a_bridge, TT_FORK), + CONFIG_TEST(check_bridge_distribution_setting_valid, 0), + CONFIG_TEST(check_bridge_distribution_setting_invalid, 0), + CONFIG_TEST(check_bridge_distribution_setting_unrecognised, 0), END_OF_TESTCASES }; |