tor-commits
Threads by month
- ----- 2025 -----
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
January 2016
- 19 participants
- 1449 discussions

[translation/https_everywhere] Update translations for https_everywhere
by translation@torproject.org 21 Jan '16
by translation@torproject.org 21 Jan '16
21 Jan '16
commit de455ff5c45a25b97795db1019c9023149a48c50
Author: Translation commit bot <translation(a)torproject.org>
Date: Thu Jan 21 19:15:15 2016 +0000
Update translations for https_everywhere
---
tr/https-everywhere.dtd | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tr/https-everywhere.dtd b/tr/https-everywhere.dtd
index 137bfe2..39656d3 100644
--- a/tr/https-everywhere.dtd
+++ b/tr/https-everywhere.dtd
@@ -3,11 +3,11 @@
<!ENTITY https-everywhere.about.ext_description "Web iletişiminizi şifreleyin! Birçok sitede otomatik olarak HTTPS güvenliğini kullanın.">
<!ENTITY https-everywhere.about.version "Sürüm">
<!ENTITY https-everywhere.about.created_by "Oluşturan">
-<!ENTITY https-everywhere.about.and "ve">
+<!ENTITY https-everywhere.about.and ", ve">
<!ENTITY https-everywhere.about.librarians "Kural Kümesi Kitaplıkları">
<!ENTITY https-everywhere.about.thanks "Teşekkürler">
-<!ENTITY https-everywhere.about.many_contributors "Şu kişileri de içeren birçok katkıcı:">
-<!ENTITY https-everywhere.about.noscript "Ayrıca, HTTPS Everywhere'in bazı bölğmleri Giorgio Maone ve diğerleri tarafından yazılmış NoScript kodlarına dayanmaktadır. Mükemmel çalışmaları için onlara minnettarız!">
+<!ENTITY https-everywhere.about.many_contributors "Şu kişilerin yer aldığı birçok katılımcı">
+<!ENTITY https-everywhere.about.noscript "Ek olarak, bazı HTTPS Everywhere bölümleri Giorgio Maone ve diğerleri tarafından yazılmış NoScript kodlarına dayanmaktadır. Harika katkıları için minnettarız!">
<!ENTITY https-everywhere.about.contribute "HTTPS Everywhere'i beğendiyseniz">
<!ENTITY https-everywhere.about.donate_tor "Tor'a">
<!ENTITY https-everywhere.about.tor_lang_code "tr">
1
0

[translation/tor-launcher-network-settings] Update translations for tor-launcher-network-settings
by translation@torproject.org 21 Jan '16
by translation@torproject.org 21 Jan '16
21 Jan '16
commit 995bf06cfab7f60cbde44987374356264b3c1cc8
Author: Translation commit bot <translation(a)torproject.org>
Date: Thu Jan 21 18:45:39 2016 +0000
Update translations for tor-launcher-network-settings
---
tr/network-settings.dtd | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tr/network-settings.dtd b/tr/network-settings.dtd
index eb86388..a190388 100644
--- a/tr/network-settings.dtd
+++ b/tr/network-settings.dtd
@@ -13,7 +13,7 @@
<!ENTITY torSettings.firstQuestion "Aşağıdakilerden hangisi durumunuzu en iyi açıklıyor?">
<!ENTITY torSettings.configurePrompt1 "Bu bilgisayarın İnternet bağlantısı sansürlü ya da vekil sunucu arkasında.">
-<!ENTITY torSettings.configurePrompt2 "I need to configure bridge or local proxy settings before I connect to the Tor network.">
+<!ENTITY torSettings.configurePrompt2 "Tor ağına bağlanmadan önce köprü ya da yerel vekil sunucu ayarlarını yapmalıyım">
<!ENTITY torSettings.configure "Yapılandır">
<!ENTITY torSettings.connectPrompt2 "I would like to make a direct connection to the Tor network.">
<!ENTITY torSettings.connectPrompt3 "Bu çoğu durumda çalışır.">
1
0
commit 017047e7b2215131907e7afb4107b9013651345d
Author: Ola Bini <ola(a)olabini.se>
Date: Mon Oct 5 15:06:34 2015 -0500
Fix all spaces
---
src/or/config.c | 3 +-
src/test/test_config.c | 321 ++++++++++++++++++++++++++++++++----------------
2 files changed, 218 insertions(+), 106 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index 7c57a4b..3456106 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1688,7 +1688,8 @@ options_act(const or_options_t *old_options)
if (revise_trackexithosts)
addressmap_clear_excluded_trackexithosts(options);
- if (!options->AutomapHostsOnResolve && old_options->AutomapHostsOnResolve) {
+ if (!options->AutomapHostsOnResolve &&
+ old_options->AutomapHostsOnResolve) {
revise_automap_entries = 1;
} else {
if (!smartlist_strings_eq(old_options->AutomapHostsSuffixes,
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 742db28..6724f55 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -3257,8 +3257,10 @@ test_config_parse_port_config__listenaddress(void *data)
{
(void)data;
int ret;
- config_line_t *config_listen_address = NULL, *config_listen_address2 = NULL, *config_listen_address3 = NULL;
- config_line_t *config_port1 = NULL, *config_port2 = NULL, *config_port3 = NULL, *config_port4 = NULL, *config_port5 = NULL;
+ config_line_t *config_listen_address = NULL, *config_listen_address2 = NULL,
+ *config_listen_address3 = NULL;
+ config_line_t *config_port1 = NULL, *config_port2 = NULL,
+ *config_port3 = NULL, *config_port4 = NULL, *config_port5 = NULL;
smartlist_t *slout = NULL;
port_cfg_t *port_cfg = NULL;
@@ -3266,11 +3268,11 @@ test_config_parse_port_config__listenaddress(void *data)
ret = parse_port_config(NULL, NULL, NULL, NULL, 0, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
-
// Setup some test data
config_listen_address = mock_config_line("DNSListenAddress", "127.0.0.1");
config_listen_address2 = mock_config_line("DNSListenAddress", "x$$$:::345");
- config_listen_address3 = mock_config_line("DNSListenAddress", "127.0.0.1:1442");
+ config_listen_address3 = mock_config_line("DNSListenAddress",
+ "127.0.0.1:1442");
config_port1 = mock_config_line("DNSPort", "42");
config_port2 = mock_config_line("DNSPort", "43");
config_port1->next = config_port2;
@@ -3278,39 +3280,50 @@ test_config_parse_port_config__listenaddress(void *data)
config_port4 = mock_config_line("DNSPort", "55542");
config_port5 = mock_config_line("DNSPort", "666777");
- // Test failure when we have a ListenAddress line and several Port lines for the same portname
- ret = parse_port_config(NULL, config_port1, config_listen_address, "DNS", 0, NULL, 0, 0);
+ // Test failure when we have a ListenAddress line and several
+ // Port lines for the same portname
+ ret = parse_port_config(NULL, config_port1, config_listen_address, "DNS", 0,
+ NULL, 0, 0);
tt_int_op(ret, OP_EQ, -1);
- // Test case when we have a listen address, no default port and allow spurious listen address lines
- ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL, 0, test_CL_PORT_ALLOW_EXTRA_LISTENADDR);
+ // Test case when we have a listen address, no default port and allow
+ // spurious listen address lines
+ ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL,
+ 0, test_CL_PORT_ALLOW_EXTRA_LISTENADDR);
tt_int_op(ret, OP_EQ, 1);
- // Test case when we have a listen address, no default port but doesn't allow spurious listen address lines
- ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL, 0, 0);
+ // Test case when we have a listen address, no default port but doesn't
+ // allow spurious listen address lines
+ ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL,
+ 0, 0);
tt_int_op(ret, OP_EQ, -1);
- // Test case when we have a listen address, and a port that points to auto, should use the AUTO port
+ // Test case when we have a listen address, and a port that points to auto,
+ // should use the AUTO port
slout = smartlist_new();
- ret = parse_port_config(slout, config_port3, config_listen_address, "DNS", 0, NULL, 0, 0);
+ ret = parse_port_config(slout, config_port3, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
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, CFG_AUTO_PORT);
// Test when we have a listen address and a custom port
- ret = parse_port_config(slout, config_port4, config_listen_address, "DNS", 0, NULL, 0, 0);
+ ret = parse_port_config(slout, config_port4, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 2);
port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
tt_int_op(port_cfg->port, OP_EQ, 55542);
// Test when we have a listen address and an invalid custom port
- ret = parse_port_config(slout, config_port5, config_listen_address, "DNS", 0, NULL, 0, 0);
+ ret = parse_port_config(slout, config_port5, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test we get a server port configuration when asked for it
- ret = parse_port_config(slout, NULL, config_listen_address, "DNS", 0, NULL, 123, test_CL_PORT_SERVER_OPTIONS);
+ ret = parse_port_config(slout, NULL, config_listen_address, "DNS", 0, NULL,
+ 123, test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 4);
port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
@@ -3319,34 +3332,45 @@ test_config_parse_port_config__listenaddress(void *data)
tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 1);
// Test an invalid ListenAddress configuration
- ret = parse_port_config(NULL, NULL, config_listen_address2, "DNS", 0, NULL, 222, 0);
+ ret = parse_port_config(NULL, NULL, config_listen_address2, "DNS", 0, NULL,
+ 222, 0);
tt_int_op(ret, OP_EQ, -1);
// Test default to the port in the listen address if available
- ret = parse_port_config(slout, config_port2, config_listen_address3, "DNS", 0, NULL, 0, 0);
+ ret = parse_port_config(slout, config_port2, config_listen_address3, "DNS",
+ 0, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 5);
port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
tt_int_op(port_cfg->port, OP_EQ, 1442);
- // Test we work correctly without an out, but with a listen address and a port
- ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS", 0, NULL, 0, 0);
+ // Test we work correctly without an out, but with a listen address
+ // and a port
+ ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal control
- ret = parse_port_config(slout, config_port2, config_listen_address, "DNS", CONN_TYPE_CONTROL_LISTENER, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
+ CONN_TYPE_CONTROL_LISTENER, NULL, 0,
+ test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal ext or listener
- ret = parse_port_config(slout, config_port2, config_listen_address, "DNS", CONN_TYPE_EXT_OR_LISTENER, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
+ CONN_TYPE_EXT_OR_LISTENER, NULL, 0,
+ test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal other
- ret = parse_port_config(slout, config_port2, config_listen_address, "DNS", 0, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
+ 0, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal control without an out
- ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS", CONN_TYPE_CONTROL_LISTENER, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS",
+ CONN_TYPE_CONTROL_LISTENER, NULL, 0,
+ test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
done:
@@ -3361,7 +3385,6 @@ test_config_parse_port_config__listenaddress(void *data)
smartlist_free(slout);
}
-
static void
test_config_parse_port_config__ports(void *data)
{
@@ -3415,8 +3438,10 @@ test_config_parse_port_config__ports(void *data)
tt_int_op(port_cfg->port, OP_EQ, 42);
tt_int_op(port_cfg->is_unix_addr, OP_EQ, 0);
- // Test with defaultport, with defaultaddress and out, adds a new port cfg for a unix address
- ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "/foo/bar/unixdomain", 42, test_CL_PORT_IS_UNIXSOCKET);
+ // Test with defaultport, with defaultaddress and out, adds a new port cfg
+ // for a unix address
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "/foo/bar/unixdomain",
+ 42, test_CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 2);
port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
@@ -3430,22 +3455,27 @@ test_config_parse_port_config__ports(void *data)
// Test error when encounters an invalid Port specification
config_port_invalid = mock_config_line("DNSPort", "");
- ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL, 0, 0);
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test error when encounters an empty unix domain specification
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "unix:");
- ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL, 0, 0);
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, 0);
tt_int_op(ret, OP_EQ, -1);
- // Test error when encounters a unix domain specification but the listener doesnt support domain sockets
+ // Test error when encounters a unix domain specification but the listener
+ // doesnt support domain sockets
config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar");
- ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", CONN_TYPE_AP_DNS_LISTENER, NULL, 0, 0);
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_DNS_LISTENER, NULL, 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test valid unix domain
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 3);
port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
@@ -3453,26 +3483,38 @@ test_config_parse_port_config__ports(void *data)
tt_int_op(port_cfg->is_unix_addr, OP_EQ, 1);
tt_str_op(port_cfg->unix_addr, OP_EQ, "/tmp/foo/bar");
- // Test failure if we have no ipv4 and no ipv6 (for unix domain sockets, this makes no sense - it should be fixed)
+ // Test failure if we have no ipv4 and no ipv6 (for unix domain sockets,
+ // this makes no sense - it should be fixed)
tor_free(config_port_invalid);
- config_port_invalid = mock_config_line("DNSPort", "unix:/tmp/foo/bar NoIPv4Traffic");
- ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, test_CL_PORT_TAKES_HOSTNAMES);
+ config_port_invalid = mock_config_line("DNSPort",
+ "unix:/tmp/foo/bar NoIPv4Traffic");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0,
+ test_CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, -1);
- // Test success with no ipv4 but take ipv6 (for unix domain sockets, this makes no sense - it should be fixed)
+ // Test success with no ipv4 but take ipv6 (for unix domain sockets, this
+ // makes no sense - it should be fixed)
tor_free(config_port_valid);
- config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar NoIPv4Traffic IPv6Traffic");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, test_CL_PORT_TAKES_HOSTNAMES);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar "
+ "NoIPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0,
+ test_CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 4);
port_cfg = (port_cfg_t *)smartlist_get(slout, 3);
tt_int_op(port_cfg->entry_cfg.ipv4_traffic, OP_EQ, 0);
tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 1);
- // Test success with both ipv4 and ipv6 (for unix domain sockets, this makes no sense - it should be fixed)
+ // Test success with both ipv4 and ipv6 (for unix domain sockets,
+ // this makes no sense - it should be fixed)
tor_free(config_port_valid);
- config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar IPv4Traffic IPv6Traffic");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, test_CL_PORT_TAKES_HOSTNAMES);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar "
+ "IPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0,
+ test_CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 5);
port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
@@ -3482,85 +3524,102 @@ test_config_parse_port_config__ports(void *data)
// Test failure if we specify world writable for an IP Port
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "42 WorldWritable");
- ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test failure if we specify group writable for an IP Port
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "42 GroupWritable");
- ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test success with only a port (this will fail without a default address)
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42");
- ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
// Test success with only a port and isolate destination port
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 IsolateDestPort");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 6);
port_cfg = (port_cfg_t *)smartlist_get(slout, 5);
- tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_DESTPORT);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_DESTPORT);
// Test success with a negative isolate destination port, and plural
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 NoIsolateDestPorts");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 7);
port_cfg = (port_cfg_t *)smartlist_get(slout, 6);
- tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT & ~ISO_DESTPORT);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ,
+ ISO_DEFAULT & ~ISO_DESTPORT);
// Test success with isolate destination address
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 IsolateDestAddr");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 8);
port_cfg = (port_cfg_t *)smartlist_get(slout, 7);
- tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_DESTADDR);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_DESTADDR);
// Test success with isolate socks AUTH
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 IsolateSOCKSAuth");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 9);
port_cfg = (port_cfg_t *)smartlist_get(slout, 8);
- tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_SOCKSAUTH);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_SOCKSAUTH);
// Test success with isolate client protocol
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 IsolateClientProtocol");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 10);
port_cfg = (port_cfg_t *)smartlist_get(slout, 9);
- tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_CLIENTPROTO);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_CLIENTPROTO);
// Test success with isolate client address
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 IsolateClientAddr");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 11);
port_cfg = (port_cfg_t *)smartlist_get(slout, 10);
- tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_CLIENTADDR);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_CLIENTADDR);
// Test success with ignored unknown options
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 ThisOptionDoesntExist");
- ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
// Test success with no isolate socks AUTH
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 NoIsolateSOCKSAuth");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 12);
port_cfg = (port_cfg_t *)smartlist_get(slout, 11);
@@ -3569,7 +3628,9 @@ test_config_parse_port_config__ports(void *data)
// Test success with prefer ipv6
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 IPv6Traffic PreferIPv6");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, "127.0.0.42", 0, test_CL_PORT_TAKES_HOSTNAMES);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, "127.0.0.42", 0,
+ test_CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 13);
port_cfg = (port_cfg_t *)smartlist_get(slout, 12);
@@ -3578,7 +3639,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with cache ipv4 DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 CacheIPv4DNS");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 14);
port_cfg = (port_cfg_t *)smartlist_get(slout, 13);
@@ -3588,7 +3650,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with cache ipv6 DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 CacheIPv6DNS");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 15);
port_cfg = (port_cfg_t *)smartlist_get(slout, 14);
@@ -3598,7 +3661,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with no cache ipv4 DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 NoCacheIPv4DNS");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 16);
port_cfg = (port_cfg_t *)smartlist_get(slout, 15);
@@ -3608,7 +3672,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with cache DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 CacheDNS");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, test_CL_PORT_TAKES_HOSTNAMES);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, test_CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 17);
port_cfg = (port_cfg_t *)smartlist_get(slout, 16);
@@ -3618,7 +3683,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with use cached ipv4 DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 UseIPv4Cache");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 18);
port_cfg = (port_cfg_t *)smartlist_get(slout, 17);
@@ -3628,7 +3694,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with use cached ipv6 DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 UseIPv6Cache");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 19);
port_cfg = (port_cfg_t *)smartlist_get(slout, 18);
@@ -3638,7 +3705,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with use cached DNS
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 UseDNSCache");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 20);
port_cfg = (port_cfg_t *)smartlist_get(slout, 19);
@@ -3648,7 +3716,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with not preferring ipv6 automap
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 NoPreferIPv6Automap");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 21);
port_cfg = (port_cfg_t *)smartlist_get(slout, 20);
@@ -3657,7 +3726,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with prefer SOCKS no auth
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 PreferSOCKSNoAuth");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 22);
port_cfg = (port_cfg_t *)smartlist_get(slout, 21);
@@ -3669,29 +3739,40 @@ test_config_parse_port_config__ports(void *data)
config_port_invalid = mock_config_line("DNSPort", "0");
config_port_valid = mock_config_line("DNSPort", "42");
config_port_invalid->next = config_port_valid;
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test success with warn non-local control
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_CONTROL_LISTENER, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_CONTROL_LISTENER, "127.0.0.42", 0,
+ test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local listener
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_EXT_OR_LISTENER, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_EXT_OR_LISTENER, "127.0.0.42", 0,
+ test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local other
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local other without out
- ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with both ipv4 and ipv6 but without stream options
tor_free(config_port_valid);
- config_port_valid = mock_config_line("DNSPort", "42 IPv4Traffic IPv6Traffic");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_TAKES_HOSTNAMES | test_CL_PORT_NO_STREAM_OPTIONS);
+ config_port_valid = mock_config_line("DNSPort", "42 IPv4Traffic "
+ "IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.44", 0,
+ test_CL_PORT_TAKES_HOSTNAMES |
+ test_CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 27);
port_cfg = (port_cfg_t *)smartlist_get(slout, 26);
@@ -3701,26 +3782,33 @@ test_config_parse_port_config__ports(void *data)
// Test failure for a SessionGroup argument with invalid value
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=invalid");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
- // TODO: this seems wrong. Shouldn't it be the other way around? Potential bug.
- // Test failure for a SessionGroup argument with valid value but with stream options allowed
+ // TODO: this seems wrong. Shouldn't it be the other way around?
+ // Potential bug.
+ // Test failure for a SessionGroup argument with valid value but with stream
+ // options allowed
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.44", 0, 0);
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.44", 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test failure for more than one SessionGroup argument
tor_free(config_port_invalid);
- config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 SessionGroup=321");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 "
+ "SessionGroup=321");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test success with a sessiongroup options
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 SessionGroup=1111122");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 28);
port_cfg = (port_cfg_t *)smartlist_get(slout, 27);
@@ -3729,14 +3817,16 @@ test_config_parse_port_config__ports(void *data)
// Test success with a zero unix domain socket, and doesnt add it to out
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "0");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 28);
// Test success with a one unix domain socket, and doesnt add it to out
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "something");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 29);
port_cfg = (port_cfg_t *)smartlist_get(slout, 28);
@@ -3746,7 +3836,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with a port of auto - it uses the default address
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "auto");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 30);
port_cfg = (port_cfg_t *)smartlist_get(slout, 29);
@@ -3757,7 +3848,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with parsing both an address and an auto port
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.122:auto");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 31);
port_cfg = (port_cfg_t *)smartlist_get(slout, 30);
@@ -3768,13 +3860,15 @@ test_config_parse_port_config__ports(void *data)
// Test failure when asked to parse an invalid address followed by auto
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "invalidstuff!!:auto");
- ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test success with parsing both an address and a real port
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.123:656");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 32);
port_cfg = (port_cfg_t *)smartlist_get(slout, 31);
@@ -3785,19 +3879,24 @@ test_config_parse_port_config__ports(void *data)
// Test failure if we can't parse anything at all
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "something wrong");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, -1);
// Test failure if we find both an address, a port and an auto
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "127.0.1.0:123:auto");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, -1);
- // Test that default to group writeable default sets group writeable for domain socket
+ // Test that default to group writeable default sets group writeable for
+ // domain socket
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "unix:/tmp/somewhere");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, "127.0.0.46", 0, test_CL_PORT_DFLT_GROUP_WRITABLE);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, "127.0.0.46", 0,
+ test_CL_PORT_DFLT_GROUP_WRITABLE);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 33);
port_cfg = (port_cfg_t *)smartlist_get(slout, 32);
@@ -3809,8 +3908,10 @@ test_config_parse_port_config__ports(void *data)
// Test success with NoAdvertise option
tor_free(config_port_valid);
- config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoAdvertise");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ config_port_valid = mock_config_line("DNSPort",
+ "127.0.0.124:656 NoAdvertise");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 34);
port_cfg = (port_cfg_t *)smartlist_get(slout, 33);
@@ -3820,7 +3921,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with NoListen option
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 35);
port_cfg = (port_cfg_t *)smartlist_get(slout, 34);
@@ -3829,14 +3931,17 @@ test_config_parse_port_config__ports(void *data)
// Test failure with both NoAdvertise and NoListen option
tor_free(config_port_invalid);
- config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen NoAdvertise");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen "
+ "NoAdvertise");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test success with IPv4Only
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 IPv4Only");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 36);
port_cfg = (port_cfg_t *)smartlist_get(slout, 35);
@@ -3846,7 +3951,8 @@ test_config_parse_port_config__ports(void *data)
// Test success with IPv6Only
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "[::1]:656 IPv6Only");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 37);
port_cfg = (port_cfg_t *)smartlist_get(slout, 36);
@@ -3855,27 +3961,33 @@ test_config_parse_port_config__ports(void *data)
// Test failure with both IPv4Only and IPv6Only
tor_free(config_port_invalid);
- config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only IPv4Only");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only "
+ "IPv4Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test success with invalid parameter
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 unknown");
- ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 38);
// Test failure when asked to bind only to ipv6 but gets an ipv4 address
tor_free(config_port_invalid);
- config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ config_port_invalid = mock_config_line("DNSPort",
+ "127.0.0.124:656 IPv6Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test failure when asked to bind only to ipv4 but gets an ipv6 address
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "[::1]:656 IPv4Only");
- ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, test_CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// End group --------------------- SERVER OPTIONS ---------------------
@@ -3886,7 +3998,6 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_valid);
}
-
#define CONFIG_TEST(name, flags) \
{ #name, test_config_ ## name, flags, NULL, NULL }
1
0
commit 49eefc0884a2248aea53d554f5be1214c82b9960
Author: Ola Bini <ola(a)olabini.se>
Date: Mon Oct 5 15:17:11 2015 -0500
Use tor_addr_eq instead of tt_mem_op
---
src/test/test_config.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 2005440..cf48938 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -3834,7 +3834,7 @@ test_config_parse_port_config__ports(void *data)
port_cfg = (port_cfg_t *)smartlist_get(slout, 29);
tt_int_op(port_cfg->port, OP_EQ, CFG_AUTO_PORT);
tor_addr_parse(&addr, "127.0.0.46");
- tt_mem_op(&port_cfg->addr, OP_EQ, &addr, sizeof(tor_addr_t));
+ tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
// Test success with parsing both an address and an auto port
tor_free(config_port_valid);
@@ -3846,7 +3846,7 @@ test_config_parse_port_config__ports(void *data)
port_cfg = (port_cfg_t *)smartlist_get(slout, 30);
tt_int_op(port_cfg->port, OP_EQ, CFG_AUTO_PORT);
tor_addr_parse(&addr, "127.0.0.122");
- tt_mem_op(&port_cfg->addr, OP_EQ, &addr, sizeof(tor_addr_t));
+ tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
// Test failure when asked to parse an invalid address followed by auto
tor_free(config_port_invalid);
@@ -3865,7 +3865,7 @@ test_config_parse_port_config__ports(void *data)
port_cfg = (port_cfg_t *)smartlist_get(slout, 31);
tt_int_op(port_cfg->port, OP_EQ, 656);
tor_addr_parse(&addr, "127.0.0.123");
- tt_mem_op(&port_cfg->addr, OP_EQ, &addr, sizeof(tor_addr_t));
+ tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
// Test failure if we can't parse anything at all
tor_free(config_port_invalid);
1
0

[tor/master] Move CL_PORT definitions so they are accessible to the tests as well
by nickm@torproject.org 21 Jan '16
by nickm@torproject.org 21 Jan '16
21 Jan '16
commit 5cb724201293bf7edf1397c442c39f6585215a4f
Author: Ola Bini <ola(a)olabini.se>
Date: Mon Oct 5 15:10:58 2015 -0500
Move CL_PORT definitions so they are accessible to the tests as well
---
src/or/config.c | 8 ------
src/or/config.h | 10 +++++++
src/test/test_config.c | 75 +++++++++++++++++++++---------------------------
3 files changed, 43 insertions(+), 50 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index 3456106..e542656 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5809,14 +5809,6 @@ warn_nonlocal_controller_ports(smartlist_t *ports, unsigned forbid_nonlocal)
} SMARTLIST_FOREACH_END(port);
}
-#define CL_PORT_NO_STREAM_OPTIONS (1u<<0)
-#define CL_PORT_WARN_NONLOCAL (1u<<1)
-#define CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
-#define CL_PORT_SERVER_OPTIONS (1u<<3)
-#define CL_PORT_FORBID_NONLOCAL (1u<<4)
-#define CL_PORT_TAKES_HOSTNAMES (1u<<5)
-#define CL_PORT_IS_UNIXSOCKET (1u<<6)
-#define CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
#ifdef HAVE_SYS_UN_H
diff --git a/src/or/config.h b/src/or/config.h
index 756b08c..f29c7da 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -136,6 +136,16 @@ smartlist_t *get_options_from_transport_options_line(const char *line,
smartlist_t *get_options_for_server_transport(const char *transport);
#ifdef CONFIG_PRIVATE
+
+#define CL_PORT_NO_STREAM_OPTIONS (1u<<0)
+#define CL_PORT_WARN_NONLOCAL (1u<<1)
+#define CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
+#define CL_PORT_SERVER_OPTIONS (1u<<3)
+#define CL_PORT_FORBID_NONLOCAL (1u<<4)
+#define CL_PORT_TAKES_HOSTNAMES (1u<<5)
+#define CL_PORT_IS_UNIXSOCKET (1u<<6)
+#define CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
+
STATIC int options_act(const or_options_t *old_options);
#ifdef TOR_UNIT_TESTS
extern struct config_format_t options_format;
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 6724f55..2005440 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -3243,15 +3243,6 @@ mock_config_line(const char *key, const char *val)
return config_line;
}
-#define test_CL_PORT_NO_STREAM_OPTIONS (1u<<0)
-#define test_CL_PORT_WARN_NONLOCAL (1u<<1)
-#define test_CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
-#define test_CL_PORT_SERVER_OPTIONS (1u<<3)
-#define test_CL_PORT_FORBID_NONLOCAL (1u<<4)
-#define test_CL_PORT_TAKES_HOSTNAMES (1u<<5)
-#define test_CL_PORT_IS_UNIXSOCKET (1u<<6)
-#define test_CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
-
static void
test_config_parse_port_config__listenaddress(void *data)
{
@@ -3289,7 +3280,7 @@ test_config_parse_port_config__listenaddress(void *data)
// Test case when we have a listen address, no default port and allow
// spurious listen address lines
ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL,
- 0, test_CL_PORT_ALLOW_EXTRA_LISTENADDR);
+ 0, CL_PORT_ALLOW_EXTRA_LISTENADDR);
tt_int_op(ret, OP_EQ, 1);
// Test case when we have a listen address, no default port but doesn't
@@ -3323,7 +3314,7 @@ test_config_parse_port_config__listenaddress(void *data)
// Test we get a server port configuration when asked for it
ret = parse_port_config(slout, NULL, config_listen_address, "DNS", 0, NULL,
- 123, test_CL_PORT_SERVER_OPTIONS);
+ 123, CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 4);
port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
@@ -3353,24 +3344,24 @@ test_config_parse_port_config__listenaddress(void *data)
// Test warning nonlocal control
ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
CONN_TYPE_CONTROL_LISTENER, NULL, 0,
- test_CL_PORT_WARN_NONLOCAL);
+ CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal ext or listener
ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
CONN_TYPE_EXT_OR_LISTENER, NULL, 0,
- test_CL_PORT_WARN_NONLOCAL);
+ CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal other
ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
- 0, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ 0, NULL, 0, CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test warning nonlocal control without an out
ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS",
CONN_TYPE_CONTROL_LISTENER, NULL, 0,
- test_CL_PORT_WARN_NONLOCAL);
+ CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
done:
@@ -3441,7 +3432,7 @@ test_config_parse_port_config__ports(void *data)
// Test with defaultport, with defaultaddress and out, adds a new port cfg
// for a unix address
ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "/foo/bar/unixdomain",
- 42, test_CL_PORT_IS_UNIXSOCKET);
+ 42, CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 2);
port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
@@ -3490,7 +3481,7 @@ test_config_parse_port_config__ports(void *data)
"unix:/tmp/foo/bar NoIPv4Traffic");
ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, NULL, 0,
- test_CL_PORT_TAKES_HOSTNAMES);
+ CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, -1);
// Test success with no ipv4 but take ipv6 (for unix domain sockets, this
@@ -3500,7 +3491,7 @@ test_config_parse_port_config__ports(void *data)
"NoIPv4Traffic IPv6Traffic");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, NULL, 0,
- test_CL_PORT_TAKES_HOSTNAMES);
+ CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 4);
port_cfg = (port_cfg_t *)smartlist_get(slout, 3);
@@ -3514,7 +3505,7 @@ test_config_parse_port_config__ports(void *data)
"IPv4Traffic IPv6Traffic");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, NULL, 0,
- test_CL_PORT_TAKES_HOSTNAMES);
+ CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 5);
port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
@@ -3630,7 +3621,7 @@ test_config_parse_port_config__ports(void *data)
config_port_valid = mock_config_line("DNSPort", "42 IPv6Traffic PreferIPv6");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, "127.0.0.42", 0,
- test_CL_PORT_TAKES_HOSTNAMES);
+ CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 13);
port_cfg = (port_cfg_t *)smartlist_get(slout, 12);
@@ -3673,7 +3664,7 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 CacheDNS");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
- "127.0.0.42", 0, test_CL_PORT_TAKES_HOSTNAMES);
+ "127.0.0.42", 0, CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 17);
port_cfg = (port_cfg_t *)smartlist_get(slout, 16);
@@ -3746,23 +3737,23 @@ test_config_parse_port_config__ports(void *data)
// Test success with warn non-local control
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_CONTROL_LISTENER, "127.0.0.42", 0,
- test_CL_PORT_WARN_NONLOCAL);
+ CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local listener
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_EXT_OR_LISTENER, "127.0.0.42", 0,
- test_CL_PORT_WARN_NONLOCAL);
+ CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local other
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
- "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ "127.0.0.42", 0, CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local other without out
ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
- "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ "127.0.0.42", 0, CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with both ipv4 and ipv6 but without stream options
@@ -3771,8 +3762,8 @@ test_config_parse_port_config__ports(void *data)
"IPv6Traffic");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.44", 0,
- test_CL_PORT_TAKES_HOSTNAMES |
- test_CL_PORT_NO_STREAM_OPTIONS);
+ CL_PORT_TAKES_HOSTNAMES |
+ CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 27);
port_cfg = (port_cfg_t *)smartlist_get(slout, 26);
@@ -3783,7 +3774,7 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=invalid");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
- "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ "127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// TODO: this seems wrong. Shouldn't it be the other way around?
@@ -3801,14 +3792,14 @@ test_config_parse_port_config__ports(void *data)
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 "
"SessionGroup=321");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
- "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ "127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test success with a sessiongroup options
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "42 SessionGroup=1111122");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
- "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ "127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 28);
port_cfg = (port_cfg_t *)smartlist_get(slout, 27);
@@ -3818,7 +3809,7 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "0");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
- "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
+ "127.0.0.45", 0, CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 28);
@@ -3826,7 +3817,7 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "something");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
- "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
+ "127.0.0.45", 0, CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 29);
port_cfg = (port_cfg_t *)smartlist_get(slout, 28);
@@ -3896,7 +3887,7 @@ test_config_parse_port_config__ports(void *data)
config_port_valid = mock_config_line("DNSPort", "unix:/tmp/somewhere");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, "127.0.0.46", 0,
- test_CL_PORT_DFLT_GROUP_WRITABLE);
+ CL_PORT_DFLT_GROUP_WRITABLE);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 33);
port_cfg = (port_cfg_t *)smartlist_get(slout, 32);
@@ -3911,7 +3902,7 @@ test_config_parse_port_config__ports(void *data)
config_port_valid = mock_config_line("DNSPort",
"127.0.0.124:656 NoAdvertise");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
- test_CL_PORT_SERVER_OPTIONS);
+ CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 34);
port_cfg = (port_cfg_t *)smartlist_get(slout, 33);
@@ -3922,7 +3913,7 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
- test_CL_PORT_SERVER_OPTIONS);
+ CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 35);
port_cfg = (port_cfg_t *)smartlist_get(slout, 34);
@@ -3934,14 +3925,14 @@ test_config_parse_port_config__ports(void *data)
config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen "
"NoAdvertise");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
- 0, test_CL_PORT_SERVER_OPTIONS);
+ 0, CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test success with IPv4Only
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 IPv4Only");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
- test_CL_PORT_SERVER_OPTIONS);
+ CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 36);
port_cfg = (port_cfg_t *)smartlist_get(slout, 35);
@@ -3952,7 +3943,7 @@ test_config_parse_port_config__ports(void *data)
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "[::1]:656 IPv6Only");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
- test_CL_PORT_SERVER_OPTIONS);
+ CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 37);
port_cfg = (port_cfg_t *)smartlist_get(slout, 36);
@@ -3964,14 +3955,14 @@ test_config_parse_port_config__ports(void *data)
config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only "
"IPv4Only");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
- 0, test_CL_PORT_SERVER_OPTIONS);
+ 0, CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test success with invalid parameter
tor_free(config_port_valid);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 unknown");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
- test_CL_PORT_SERVER_OPTIONS);
+ CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 38);
@@ -3980,14 +3971,14 @@ test_config_parse_port_config__ports(void *data)
config_port_invalid = mock_config_line("DNSPort",
"127.0.0.124:656 IPv6Only");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
- 0, test_CL_PORT_SERVER_OPTIONS);
+ 0, CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// Test failure when asked to bind only to ipv4 but gets an ipv6 address
tor_free(config_port_invalid);
config_port_invalid = mock_config_line("DNSPort", "[::1]:656 IPv4Only");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
- 0, test_CL_PORT_SERVER_OPTIONS);
+ 0, CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
// End group --------------------- SERVER OPTIONS ---------------------
1
0

[tor/master] Divide the different parse_port_config groups into separate tests
by nickm@torproject.org 21 Jan '16
by nickm@torproject.org 21 Jan '16
21 Jan '16
commit f319231e6ea2eaa87ca937f8ff3c1c1209e9bda3
Author: Ola Bini <ola(a)olabini.se>
Date: Mon Oct 5 15:31:49 2015 -0500
Divide the different parse_port_config groups into separate tests
---
src/or/config.c | 2 +-
src/or/config.h | 1 +
src/test/test_config.c | 226 +++++++++++++++++++++++++++++++-----------------
3 files changed, 151 insertions(+), 78 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index e542656..865cfd9 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5809,7 +5809,6 @@ warn_nonlocal_controller_ports(smartlist_t *ports, unsigned forbid_nonlocal)
} SMARTLIST_FOREACH_END(port);
}
-
#ifdef HAVE_SYS_UN_H
/** Parse the given <b>addrport</b> and set <b>path_out</b> if a Unix socket
@@ -7323,3 +7322,4 @@ init_cookie_authentication(const char *fname, const char *header,
tor_free(cookie_file_str);
return retval;
}
+
diff --git a/src/or/config.h b/src/or/config.h
index f29c7da..33dc5df 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -177,3 +177,4 @@ parse_port_config(smartlist_t *out,
#endif
#endif
+
diff --git a/src/test/test_config.c b/src/test/test_config.c
index cf48938..6fdd7e7 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -3377,19 +3377,16 @@ test_config_parse_port_config__listenaddress(void *data)
}
static void
-test_config_parse_port_config__ports(void *data)
+test_config_parse_port_config__ports__no_ports_given(void *data)
{
(void)data;
int ret;
smartlist_t *slout = NULL;
port_cfg_t *port_cfg = NULL;
config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
- tor_addr_t addr;
slout = smartlist_new();
- // Test group -------------------- NO PORTS GIVEN ---------------------
-
// Test no defaultport, no defaultaddress and no out
ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
@@ -3422,6 +3419,7 @@ test_config_parse_port_config__ports(void *data)
tt_int_op(smartlist_len(slout), OP_EQ, 0);
// Test with defaultport, with defaultaddress and out, adds a new port cfg
+ smartlist_clear(slout);
ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "127.0.0.2", 42, 0);
tt_int_op(ret, OP_EQ, 0);
tt_int_op(smartlist_len(slout), OP_EQ, 1);
@@ -3431,18 +3429,33 @@ test_config_parse_port_config__ports(void *data)
// Test with defaultport, with defaultaddress and out, adds a new port cfg
// for a unix address
+ smartlist_clear(slout);
ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "/foo/bar/unixdomain",
42, CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 2);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
+ 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, "/foo/bar/unixdomain");
- // End group --------------------- NO PORTS GIVEN ---------------------
+ done:
+ smartlist_free(slout);
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+}
- // Test group -------------------- PORTS GIVEN ------------------------
+static void
+test_config_parse_port_config__ports__ports_given(void *data)
+{
+ (void)data;
+ int ret;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+ config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
+ tor_addr_t addr;
+
+ slout = smartlist_new();
// Test error when encounters an invalid Port specification
config_port_invalid = mock_config_line("DNSPort", "");
@@ -3465,11 +3478,12 @@ test_config_parse_port_config__ports(void *data)
tt_int_op(ret, OP_EQ, -1);
// Test valid unix domain
+ smartlist_clear(slout);
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, NULL, 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 3);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
+ 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");
@@ -3487,28 +3501,30 @@ test_config_parse_port_config__ports(void *data)
// Test success with no ipv4 but take ipv6 (for unix domain sockets, this
// makes no sense - it should be fixed)
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar "
"NoIPv4Traffic IPv6Traffic");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, NULL, 0,
CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 4);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 3);
+ 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);
// Test success with both ipv4 and ipv6 (for unix domain sockets,
// this makes no sense - it should be fixed)
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar "
"IPv4Traffic IPv6Traffic");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, NULL, 0,
CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 5);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
+ 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);
@@ -3535,67 +3551,73 @@ test_config_parse_port_config__ports(void *data)
// Test success with only a port and isolate destination port
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IsolateDestPort");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 6);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 5);
+ 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.isolation_flags, OP_EQ,
ISO_DEFAULT | ISO_DESTPORT);
// Test success with a negative isolate destination port, and plural
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 NoIsolateDestPorts");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 7);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 6);
+ 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.isolation_flags, OP_EQ,
ISO_DEFAULT & ~ISO_DESTPORT);
// Test success with isolate destination address
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IsolateDestAddr");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 8);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 7);
+ 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.isolation_flags, OP_EQ,
ISO_DEFAULT | ISO_DESTADDR);
// Test success with isolate socks AUTH
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IsolateSOCKSAuth");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 9);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 8);
+ 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.isolation_flags, OP_EQ,
ISO_DEFAULT | ISO_SOCKSAUTH);
// Test success with isolate client protocol
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IsolateClientProtocol");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 10);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 9);
+ 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.isolation_flags, OP_EQ,
ISO_DEFAULT | ISO_CLIENTPROTO);
// Test success with isolate client address
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IsolateClientAddr");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 11);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 10);
+ 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.isolation_flags, OP_EQ,
ISO_DEFAULT | ISO_CLIENTADDR);
@@ -3608,125 +3630,137 @@ test_config_parse_port_config__ports(void *data)
// Test success with no isolate socks AUTH
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 NoIsolateSOCKSAuth");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.3", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 12);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 11);
+ 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.socks_prefer_no_auth, OP_EQ, 1);
// Test success with prefer ipv6
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IPv6Traffic PreferIPv6");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, "127.0.0.42", 0,
CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 13);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 12);
+ 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.prefer_ipv6, OP_EQ, 1);
// Test success with cache ipv4 DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 CacheIPv4DNS");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 14);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 13);
+ 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.cache_ipv4_answers, OP_EQ, 1);
tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0);
// Test success with cache ipv6 DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 CacheIPv6DNS");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 15);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 14);
+ 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.cache_ipv4_answers, OP_EQ, 1);
tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1);
// Test success with no cache ipv4 DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 NoCacheIPv4DNS");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 16);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 15);
+ 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.cache_ipv4_answers, OP_EQ, 0);
tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0);
// Test success with cache DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 CacheDNS");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, CL_PORT_TAKES_HOSTNAMES);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 17);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 16);
+ 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.cache_ipv4_answers, OP_EQ, 1);
tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1);
// Test success with use cached ipv4 DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 UseIPv4Cache");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 18);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 17);
+ 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.use_cached_ipv4_answers, OP_EQ, 1);
tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 0);
// Test success with use cached ipv6 DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 UseIPv6Cache");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 19);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 18);
+ 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.use_cached_ipv4_answers, OP_EQ, 0);
tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1);
// Test success with use cached DNS
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 UseDNSCache");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 20);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 19);
+ 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.use_cached_ipv4_answers, OP_EQ, 1);
tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1);
// Test success with not preferring ipv6 automap
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 NoPreferIPv6Automap");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 21);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 20);
+ 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.prefer_ipv6_virtaddr, OP_EQ, 0);
// Test success with prefer SOCKS no auth
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 PreferSOCKSNoAuth");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 22);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 21);
+ 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.socks_prefer_no_auth, OP_EQ, 1);
// Test failure with both a zero port and a non-zero port
tor_free(config_port_invalid);
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "0");
config_port_valid = mock_config_line("DNSPort", "42");
config_port_invalid->next = config_port_valid;
@@ -3735,18 +3769,21 @@ test_config_parse_port_config__ports(void *data)
tt_int_op(ret, OP_EQ, -1);
// Test success with warn non-local control
+ smartlist_clear(slout);
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_CONTROL_LISTENER, "127.0.0.42", 0,
CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local listener
+ smartlist_clear(slout);
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_EXT_OR_LISTENER, "127.0.0.42", 0,
CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
// Test success with warn non-local other
+ smartlist_clear(slout);
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.42", 0, CL_PORT_WARN_NONLOCAL);
tt_int_op(ret, OP_EQ, 0);
@@ -3758,6 +3795,7 @@ test_config_parse_port_config__ports(void *data)
// Test success with both ipv4 and ipv6 but without stream options
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 IPv4Traffic "
"IPv6Traffic");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
@@ -3765,13 +3803,14 @@ test_config_parse_port_config__ports(void *data)
CL_PORT_TAKES_HOSTNAMES |
CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 27);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 26);
+ 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, 0);
// Test failure for a SessionGroup argument with invalid value
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=invalid");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
"127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
@@ -3782,6 +3821,7 @@ test_config_parse_port_config__ports(void *data)
// Test failure for a SessionGroup argument with valid value but with stream
// options allowed
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
"127.0.0.44", 0, 0);
@@ -3789,6 +3829,7 @@ test_config_parse_port_config__ports(void *data)
// Test failure for more than one SessionGroup argument
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 "
"SessionGroup=321");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
@@ -3797,53 +3838,58 @@ test_config_parse_port_config__ports(void *data)
// Test success with a sessiongroup options
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "42 SessionGroup=1111122");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 28);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 27);
+ 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.session_group, OP_EQ, 1111122);
// Test success with a zero unix domain socket, and doesnt add it to out
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "0");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.45", 0, CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 28);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
// Test success with a one unix domain socket, and doesnt add it to out
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "something");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.45", 0, CL_PORT_IS_UNIXSOCKET);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 29);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 28);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 0);
tt_int_op(port_cfg->is_unix_addr, OP_EQ, 1);
tt_str_op(port_cfg->unix_addr, OP_EQ, "something");
// Test success with a port of auto - it uses the default address
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "auto");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 30);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 29);
+ 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, CFG_AUTO_PORT);
tor_addr_parse(&addr, "127.0.0.46");
tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
// Test success with parsing both an address and an auto port
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "127.0.0.122:auto");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 31);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 30);
+ 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, CFG_AUTO_PORT);
tor_addr_parse(&addr, "127.0.0.122");
tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
@@ -3857,18 +3903,20 @@ test_config_parse_port_config__ports(void *data)
// Test success with parsing both an address and a real port
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "127.0.0.123:656");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
"127.0.0.46", 0, 0);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 32);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 31);
+ 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, 656);
tor_addr_parse(&addr, "127.0.0.123");
tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
// Test failure if we can't parse anything at all
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "something wrong");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
"127.0.0.46", 0, 0);
@@ -3876,6 +3924,7 @@ test_config_parse_port_config__ports(void *data)
// Test failure if we find both an address, a port and an auto
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "127.0.1.0:123:auto");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
"127.0.0.46", 0, 0);
@@ -3884,18 +3933,32 @@ test_config_parse_port_config__ports(void *data)
// Test that default to group writeable default sets group writeable for
// domain socket
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "unix:/tmp/somewhere");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
CONN_TYPE_AP_LISTENER, "127.0.0.46", 0,
CL_PORT_DFLT_GROUP_WRITABLE);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 33);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 32);
+ 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);
- // End group --------------------- PORTS GIVEN ------------------------
+ done:
+ smartlist_free(slout);
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+}
+
+static void
+test_config_parse_port_config__ports__server_options(void *data)
+{
+ (void)data;
+ int ret;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+ config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
- // Start group ------------------- SERVER OPTIONS ---------------------
+ slout = smartlist_new();
// Test success with NoAdvertise option
tor_free(config_port_valid);
@@ -3904,24 +3967,26 @@ test_config_parse_port_config__ports(void *data)
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 34);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 33);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 0);
tt_int_op(port_cfg->server_cfg.no_advertise, OP_EQ, 1);
tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 0);
// Test success with NoListen option
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 35);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 34);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 0);
tt_int_op(port_cfg->server_cfg.no_advertise, OP_EQ, 0);
tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 1);
// Test failure with both NoAdvertise and NoListen option
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen "
"NoAdvertise");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
@@ -3930,28 +3995,31 @@ test_config_parse_port_config__ports(void *data)
// Test success with IPv4Only
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 IPv4Only");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 36);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 35);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 0);
tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 1);
tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 0);
// Test success with IPv6Only
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "[::1]:656 IPv6Only");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 37);
- port_cfg = (port_cfg_t *)smartlist_get(slout, 36);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 0);
tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 0);
tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 1);
// Test failure with both IPv4Only and IPv6Only
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only "
"IPv4Only");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
@@ -3960,14 +4028,16 @@ test_config_parse_port_config__ports(void *data)
// Test success with invalid parameter
tor_free(config_port_valid);
+ smartlist_clear(slout);
config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 unknown");
ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, 0);
- tt_int_op(smartlist_len(slout), OP_EQ, 38);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
// Test failure when asked to bind only to ipv6 but gets an ipv4 address
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort",
"127.0.0.124:656 IPv6Only");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
@@ -3976,13 +4046,12 @@ test_config_parse_port_config__ports(void *data)
// Test failure when asked to bind only to ipv4 but gets an ipv6 address
tor_free(config_port_invalid);
+ smartlist_clear(slout);
config_port_invalid = mock_config_line("DNSPort", "[::1]:656 IPv4Only");
ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
0, CL_PORT_SERVER_OPTIONS);
tt_int_op(ret, OP_EQ, -1);
- // End group --------------------- SERVER OPTIONS ---------------------
-
done:
smartlist_free(slout);
tor_free(config_port_invalid);
@@ -4003,6 +4072,9 @@ struct testcase_t config_tests[] = {
CONFIG_TEST(write_to_data_subdir, TT_FORK),
CONFIG_TEST(fix_my_family, 0),
CONFIG_TEST(parse_port_config__listenaddress, 0),
- CONFIG_TEST(parse_port_config__ports, 0),
+ 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),
END_OF_TESTCASES
};
+
1
0

[tor/master] Merge remote-tracking branch 'twstrike/parse_port_config_tests'
by nickm@torproject.org 21 Jan '16
by nickm@torproject.org 21 Jan '16
21 Jan '16
commit cbed61d1280d5f85b1670a70c9d8d2331b919e80
Merge: ae3d2a9 f319231
Author: Nick Mathewson <nickm(a)torproject.org>
Date: Thu Jan 21 12:15:39 2016 -0500
Merge remote-tracking branch 'twstrike/parse_port_config_tests'
src/or/config.c | 33 +-
src/or/config.h | 23 +-
src/test/test_config.c | 856 +++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 889 insertions(+), 23 deletions(-)
diff --cc src/or/config.h
index 6e08f9d,33dc5df..920281a
--- a/src/or/config.h
+++ b/src/or/config.h
@@@ -152,14 -161,19 +163,24 @@@ STATIC int parse_transport_line(const o
int server);
STATIC int consider_adding_dir_servers(const or_options_t *options,
const or_options_t *old_options);
+STATIC void add_default_trusted_dir_authorities(dirinfo_type_t type);
MOCK_DECL(STATIC void, add_default_fallback_dir_servers, (void));
-STATIC int
-parse_dir_fallback_line(const char *line,
- int validate_only);
-STATIC int
-parse_port_config(smartlist_t *out,
+STATIC int parse_dir_authority_line(const char *line,
+ dirinfo_type_t required_type,
+ int validate_only);
+STATIC int parse_dir_fallback_line(const char *line, int validate_only);
+STATIC int have_enough_mem_for_dircache(const or_options_t *options,
+ size_t total_mem, char **msg);
++STATIC int parse_dir_fallback_line(const char *line,
++ int validate_only);
++STATIC int parse_port_config(smartlist_t *out,
+ const config_line_t *ports,
+ const config_line_t *listenaddrs,
+ const char *portname,
+ int listener_type,
+ const char *defaultaddr,
+ int defaultport,
+ const unsigned flags);
#endif
#endif
diff --cc src/test/test_config.c
index 097fe15,6fdd7e7..58487d7
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@@ -15,12 -20,28 +20,30 @@@
#include "test.h"
#include "util.h"
#include "address.h"
+ #include "connection_or.h"
+ #include "control.h"
+ #include "cpuworker.h"
++#include "dirserv.h"
+ #include "dirvote.h"
+ #include "dns.h"
#include "entrynodes.h"
#include "transports.h"
- #include "routerlist.h"
+ #include "ext_orport.h"
+ #include "geoip.h"
+ #include "hibernate.h"
+ #include "main.h"
+#include "networkstatus.h"
+ #include "nodelist.h"
+ #include "policies.h"
+ #include "rendclient.h"
+ #include "rendservice.h"
#include "router.h"
- #include "dirserv.h"
+ #include "routerlist.h"
+ #include "routerset.h"
+ #include "statefile.h"
+ #include "test.h"
+ #include "transports.h"
+ #include "util.h"
static void
test_config_addressmap(void *arg)
@@@ -3413,280 -3233,831 +3436,1105 @@@ test_config_adding_dir_servers(void *ar
UNMOCK(add_default_fallback_dir_servers);
}
+static void
+test_config_default_dir_servers(void *arg)
+{
+ or_options_t *opts = NULL;
+ (void)arg;
+ int trusted_count = 0;
+ int fallback_count = 0;
+
+ /* new set of options should stop fallback parsing */
+ opts = tor_malloc_zero(sizeof(or_options_t));
+ opts->UseDefaultFallbackDirs = 0;
+ /* set old_options to NULL to force dir update */
+ consider_adding_dir_servers(opts, NULL);
+ trusted_count = smartlist_len(router_get_trusted_dir_servers());
+ fallback_count = smartlist_len(router_get_fallback_dir_servers());
+ or_options_free(opts);
+ opts = NULL;
+
+ /* assume a release will never go out with less than 7 authorities */
+ tt_assert(trusted_count >= 7);
+ /* if we disable the default fallbacks, there must not be any extra */
+ tt_assert(fallback_count == trusted_count);
+
+ opts = tor_malloc_zero(sizeof(or_options_t));
+ opts->UseDefaultFallbackDirs = 1;
+ consider_adding_dir_servers(opts, opts);
+ trusted_count = smartlist_len(router_get_trusted_dir_servers());
+ fallback_count = smartlist_len(router_get_fallback_dir_servers());
+ or_options_free(opts);
+ opts = NULL;
+
+ /* assume a release will never go out with less than 7 authorities */
+ tt_assert(trusted_count >= 7);
+ /* XX/teor - allow for default fallbacks to be added without breaking
+ * the unit tests. Set a minimum fallback count once the list is stable. */
+ tt_assert(fallback_count >= trusted_count);
+
+ done:
+ or_options_free(opts);
+}
+
+static int mock_router_pick_published_address_result = 0;
+
+static int
+mock_router_pick_published_address(const or_options_t *options, uint32_t *addr)
+{
+ (void)options;
+ (void)addr;
+ return mock_router_pick_published_address_result;
+}
+
+static int mock_router_my_exit_policy_is_reject_star_result = 0;
+
+static int
+mock_router_my_exit_policy_is_reject_star(void)
+{
+ return mock_router_my_exit_policy_is_reject_star_result;
+}
+
+static int mock_advertised_server_mode_result = 0;
+
+static int
+mock_advertised_server_mode(void)
+{
+ return mock_advertised_server_mode_result;
+}
+
+static routerinfo_t *mock_router_get_my_routerinfo_result = NULL;
+
+static const routerinfo_t *
+mock_router_get_my_routerinfo(void)
+{
+ return mock_router_get_my_routerinfo_result;
+}
+
+static void
+test_config_directory_fetch(void *arg)
+{
+ (void)arg;
+
+ /* Test Setup */
+ or_options_t *options = tor_malloc_zero(sizeof(or_options_t));
+ routerinfo_t routerinfo;
+ memset(&routerinfo, 0, sizeof(routerinfo));
+ mock_router_pick_published_address_result = -1;
+ mock_router_my_exit_policy_is_reject_star_result = 1;
+ mock_advertised_server_mode_result = 0;
+ mock_router_get_my_routerinfo_result = NULL;
+ MOCK(router_pick_published_address, mock_router_pick_published_address);
+ MOCK(router_my_exit_policy_is_reject_star,
+ mock_router_my_exit_policy_is_reject_star);
+ MOCK(advertised_server_mode, mock_advertised_server_mode);
+ MOCK(router_get_my_routerinfo, mock_router_get_my_routerinfo);
+
+ /* Clients can use multiple directory mirrors for bootstrap */
+ memset(options, 0, sizeof(or_options_t));
+ options->ClientOnly = 1;
+ tt_assert(server_mode(options) == 0);
+ tt_assert(public_server_mode(options) == 0);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 1);
+
+ /* Bridge Clients can use multiple directory mirrors for bootstrap */
+ memset(options, 0, sizeof(or_options_t));
+ options->UseBridges = 1;
+ tt_assert(server_mode(options) == 0);
+ tt_assert(public_server_mode(options) == 0);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 1);
+
+ /* Bridge Relays (Bridges) must act like clients, and use multiple
+ * directory mirrors for bootstrap */
+ memset(options, 0, sizeof(or_options_t));
+ options->BridgeRelay = 1;
+ options->ORPort_set = 1;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 0);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 1);
+
+ /* Clients set to FetchDirInfoEarly must fetch it from the authorities,
+ * but can use multiple authorities for bootstrap */
+ memset(options, 0, sizeof(or_options_t));
+ options->FetchDirInfoEarly = 1;
+ tt_assert(server_mode(options) == 0);
+ tt_assert(public_server_mode(options) == 0);
+ tt_assert(directory_fetches_from_authorities(options) == 1);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 1);
+
+ /* OR servers only fetch the consensus from the authorities when they don't
+ * know their own address, but never use multiple directories for bootstrap
+ */
+ memset(options, 0, sizeof(or_options_t));
+ options->ORPort_set = 1;
+
+ mock_router_pick_published_address_result = -1;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 1);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ mock_router_pick_published_address_result = 0;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ /* Exit OR servers only fetch the consensus from the authorities when they
+ * refuse unknown exits, but never use multiple directories for bootstrap
+ */
+ memset(options, 0, sizeof(or_options_t));
+ options->ORPort_set = 1;
+ options->ExitRelay = 1;
+ mock_router_pick_published_address_result = 0;
+ mock_router_my_exit_policy_is_reject_star_result = 0;
+ mock_advertised_server_mode_result = 1;
+ mock_router_get_my_routerinfo_result = &routerinfo;
+
+ routerinfo.supports_tunnelled_dir_requests = 1;
+
+ options->RefuseUnknownExits = 1;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 1);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ options->RefuseUnknownExits = 0;
+ mock_router_pick_published_address_result = 0;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ /* Dir servers fetch the consensus from the authorities, unless they are not
+ * advertising themselves (hibernating) or have no routerinfo or are not
+ * advertising their dirport, and never use multiple directories for
+ * bootstrap. This only applies if they are also OR servers.
+ * (We don't care much about the behaviour of non-OR directory servers.) */
+ memset(options, 0, sizeof(or_options_t));
+ options->DirPort_set = 1;
+ options->ORPort_set = 1;
+ options->DirCache = 1;
+ mock_router_pick_published_address_result = 0;
+ mock_router_my_exit_policy_is_reject_star_result = 1;
+
+ mock_advertised_server_mode_result = 1;
+ routerinfo.dir_port = 1;
+ mock_router_get_my_routerinfo_result = &routerinfo;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 1);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ mock_advertised_server_mode_result = 0;
+ routerinfo.dir_port = 1;
+ mock_router_get_my_routerinfo_result = &routerinfo;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ mock_advertised_server_mode_result = 1;
+ mock_router_get_my_routerinfo_result = NULL;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ mock_advertised_server_mode_result = 1;
+ routerinfo.dir_port = 0;
+ routerinfo.supports_tunnelled_dir_requests = 0;
+ mock_router_get_my_routerinfo_result = &routerinfo;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 0);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ mock_advertised_server_mode_result = 1;
+ routerinfo.dir_port = 1;
+ routerinfo.supports_tunnelled_dir_requests = 1;
+ mock_router_get_my_routerinfo_result = &routerinfo;
+ tt_assert(server_mode(options) == 1);
+ tt_assert(public_server_mode(options) == 1);
+ tt_assert(directory_fetches_from_authorities(options) == 1);
+ tt_assert(networkstatus_consensus_can_use_multiple_directories(options)
+ == 0);
+
+ done:
+ tor_free(options);
+ UNMOCK(router_pick_published_address);
+ UNMOCK(router_get_my_routerinfo);
+ UNMOCK(advertised_server_mode);
+ UNMOCK(router_my_exit_policy_is_reject_star);
+}
+
+static void
+test_config_default_fallback_dirs(void *arg)
+{
+ const char *fallback[] = {
+#include "../or/fallback_dirs.inc"
+ NULL
+ };
+
+ int n_included_fallback_dirs = 0;
+ int n_added_fallback_dirs = 0;
+
+ (void)arg;
+ clear_dir_servers();
+
+ while (fallback[n_included_fallback_dirs])
+ n_included_fallback_dirs++;
+
+ add_default_fallback_dir_servers();
+
+ n_added_fallback_dirs = smartlist_len(router_get_fallback_dir_servers());
+
+ tt_assert(n_included_fallback_dirs == n_added_fallback_dirs);
+
+ done:
+ clear_dir_servers();
+}
+
+ static config_line_t *
+ mock_config_line(const char *key, const char *val)
+ {
+ config_line_t *config_line = tor_malloc(sizeof(config_line_t));
+ memset(config_line, 0, sizeof(config_line_t));
+ config_line->key = tor_strdup(key);
+ config_line->value = tor_strdup(val);
+ return config_line;
+ }
+
+ static void
+ test_config_parse_port_config__listenaddress(void *data)
+ {
+ (void)data;
+ int ret;
+ config_line_t *config_listen_address = NULL, *config_listen_address2 = NULL,
+ *config_listen_address3 = NULL;
+ config_line_t *config_port1 = NULL, *config_port2 = NULL,
+ *config_port3 = NULL, *config_port4 = NULL, *config_port5 = NULL;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+
+ // Test basic invocation with no arguments
+ ret = parse_port_config(NULL, NULL, NULL, NULL, 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Setup some test data
+ config_listen_address = mock_config_line("DNSListenAddress", "127.0.0.1");
+ config_listen_address2 = mock_config_line("DNSListenAddress", "x$$$:::345");
+ config_listen_address3 = mock_config_line("DNSListenAddress",
+ "127.0.0.1:1442");
+ config_port1 = mock_config_line("DNSPort", "42");
+ config_port2 = mock_config_line("DNSPort", "43");
+ config_port1->next = config_port2;
+ config_port3 = mock_config_line("DNSPort", "auto");
+ config_port4 = mock_config_line("DNSPort", "55542");
+ config_port5 = mock_config_line("DNSPort", "666777");
+
+ // Test failure when we have a ListenAddress line and several
+ // Port lines for the same portname
+ ret = parse_port_config(NULL, config_port1, config_listen_address, "DNS", 0,
+ NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test case when we have a listen address, no default port and allow
+ // spurious listen address lines
+ ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL,
+ 0, CL_PORT_ALLOW_EXTRA_LISTENADDR);
+ tt_int_op(ret, OP_EQ, 1);
+
+ // Test case when we have a listen address, no default port but doesn't
+ // allow spurious listen address lines
+ ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL,
+ 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test case when we have a listen address, and a port that points to auto,
+ // should use the AUTO port
+ slout = smartlist_new();
+ ret = parse_port_config(slout, config_port3, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
+ 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, CFG_AUTO_PORT);
+
+ // Test when we have a listen address and a custom port
+ ret = parse_port_config(slout, config_port4, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 2);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
+ tt_int_op(port_cfg->port, OP_EQ, 55542);
+
+ // Test when we have a listen address and an invalid custom port
+ ret = parse_port_config(slout, config_port5, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test we get a server port configuration when asked for it
+ ret = parse_port_config(slout, NULL, config_listen_address, "DNS", 0, NULL,
+ 123, CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 4);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
+ tt_int_op(port_cfg->port, OP_EQ, 123);
+ tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 1);
+ tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 1);
+
+ // Test an invalid ListenAddress configuration
+ ret = parse_port_config(NULL, NULL, config_listen_address2, "DNS", 0, NULL,
+ 222, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test default to the port in the listen address if available
+ ret = parse_port_config(slout, config_port2, config_listen_address3, "DNS",
+ 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 5);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
+ tt_int_op(port_cfg->port, OP_EQ, 1442);
+
+ // Test we work correctly without an out, but with a listen address
+ // and a port
+ ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS",
+ 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal control
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
+ CONN_TYPE_CONTROL_LISTENER, NULL, 0,
+ CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal ext or listener
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
+ CONN_TYPE_EXT_OR_LISTENER, NULL, 0,
+ CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal other
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS",
+ 0, NULL, 0, CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal control without an out
+ ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS",
+ CONN_TYPE_CONTROL_LISTENER, NULL, 0,
+ CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ done:
+ tor_free(config_listen_address);
+ tor_free(config_listen_address2);
+ tor_free(config_listen_address3);
+ tor_free(config_port1);
+ tor_free(config_port2);
+ tor_free(config_port3);
+ tor_free(config_port4);
+ tor_free(config_port5);
+ smartlist_free(slout);
+ }
+
+ static void
+ test_config_parse_port_config__ports__no_ports_given(void *data)
+ {
+ (void)data;
+ int ret;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+ config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
+
+ slout = smartlist_new();
+
+ // Test no defaultport, no defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test with defaultport, no defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, NULL, 42, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test no defaultport, with defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, "127.0.0.2", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test with defaultport, with defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, "127.0.0.2", 42, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test no defaultport, no defaultaddress and with out
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test with defaultport, no defaultaddress and with out
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, NULL, 42, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test no defaultport, with defaultaddress and with out
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "127.0.0.2", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test with defaultport, with defaultaddress and out, adds a new port cfg
+ smartlist_clear(slout);
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "127.0.0.2", 42, 0);
+ 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, 42);
+ tt_int_op(port_cfg->is_unix_addr, OP_EQ, 0);
+
+ // Test with defaultport, with defaultaddress and out, adds a new port cfg
+ // for a unix address
+ smartlist_clear(slout);
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "/foo/bar/unixdomain",
+ 42, CL_PORT_IS_UNIXSOCKET);
+ 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, "/foo/bar/unixdomain");
+
+ done:
+ smartlist_free(slout);
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+ }
+
+ static void
+ test_config_parse_port_config__ports__ports_given(void *data)
+ {
+ (void)data;
+ int ret;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+ config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
+ tor_addr_t addr;
+
+ slout = smartlist_new();
+
+ // Test error when encounters an invalid Port specification
+ config_port_invalid = mock_config_line("DNSPort", "");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test error when encounters an empty unix domain specification
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "unix:");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test error when encounters a unix domain specification but the listener
+ // doesnt support domain sockets
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar");
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_DNS_LISTENER, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test valid unix domain
+ smartlist_clear(slout);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0, 0);
+ 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");
+
+ // Test failure if we have no ipv4 and no ipv6 (for unix domain sockets,
+ // this makes no sense - it should be fixed)
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort",
+ "unix:/tmp/foo/bar NoIPv4Traffic");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0,
+ CL_PORT_TAKES_HOSTNAMES);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with no ipv4 but take ipv6 (for unix domain sockets, this
+ // makes no sense - it should be fixed)
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar "
+ "NoIPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0,
+ CL_PORT_TAKES_HOSTNAMES);
+ 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);
+
+ // Test success with both ipv4 and ipv6 (for unix domain sockets,
+ // this makes no sense - it should be fixed)
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar "
+ "IPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, NULL, 0,
+ CL_PORT_TAKES_HOSTNAMES);
+ 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);
+
+ // Test failure if we specify world writable for an IP Port
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 WorldWritable");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure if we specify group writable for an IP Port
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 GroupWritable");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with only a port (this will fail without a default address)
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42");
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with only a port and isolate destination port
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateDestPort");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_DESTPORT);
+
+ // Test success with a negative isolate destination port, and plural
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 NoIsolateDestPorts");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.isolation_flags, OP_EQ,
+ ISO_DEFAULT & ~ISO_DESTPORT);
+
+ // Test success with isolate destination address
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateDestAddr");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_DESTADDR);
+
+ // Test success with isolate socks AUTH
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateSOCKSAuth");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_SOCKSAUTH);
+
+ // Test success with isolate client protocol
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateClientProtocol");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_CLIENTPROTO);
+
+ // Test success with isolate client address
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateClientAddr");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.isolation_flags, OP_EQ,
+ ISO_DEFAULT | ISO_CLIENTADDR);
+
+ // Test success with ignored unknown options
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 ThisOptionDoesntExist");
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with no isolate socks AUTH
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 NoIsolateSOCKSAuth");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.3", 0, 0);
+ 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.socks_prefer_no_auth, OP_EQ, 1);
+
+ // Test success with prefer ipv6
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IPv6Traffic PreferIPv6");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, "127.0.0.42", 0,
+ CL_PORT_TAKES_HOSTNAMES);
+ 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.prefer_ipv6, OP_EQ, 1);
+
+ // Test success with cache ipv4 DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 CacheIPv4DNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.cache_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0);
+
+ // Test success with cache ipv6 DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 CacheIPv6DNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.cache_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1);
+
+ // Test success with no cache ipv4 DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 NoCacheIPv4DNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.cache_ipv4_answers, OP_EQ, 0);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0);
+
+ // Test success with cache DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 CacheDNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, CL_PORT_TAKES_HOSTNAMES);
+ 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.cache_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1);
+
+ // Test success with use cached ipv4 DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 UseIPv4Cache");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.use_cached_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 0);
+
+ // Test success with use cached ipv6 DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 UseIPv6Cache");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.use_cached_ipv4_answers, OP_EQ, 0);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1);
+
+ // Test success with use cached DNS
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 UseDNSCache");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.use_cached_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1);
+
+ // Test success with not preferring ipv6 automap
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 NoPreferIPv6Automap");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.prefer_ipv6_virtaddr, OP_EQ, 0);
+
+ // Test success with prefer SOCKS no auth
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 PreferSOCKSNoAuth");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ 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.socks_prefer_no_auth, OP_EQ, 1);
+
+ // Test failure with both a zero port and a non-zero port
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "0");
+ config_port_valid = mock_config_line("DNSPort", "42");
+ config_port_invalid->next = config_port_valid;
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with warn non-local control
+ smartlist_clear(slout);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_CONTROL_LISTENER, "127.0.0.42", 0,
+ CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with warn non-local listener
+ smartlist_clear(slout);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_EXT_OR_LISTENER, "127.0.0.42", 0,
+ CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with warn non-local other
+ smartlist_clear(slout);
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with warn non-local other without out
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.42", 0, CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with both ipv4 and ipv6 but without stream options
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 IPv4Traffic "
+ "IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.44", 0,
+ CL_PORT_TAKES_HOSTNAMES |
+ CL_PORT_NO_STREAM_OPTIONS);
+ 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, 0);
+
+ // Test failure for a SessionGroup argument with invalid value
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=invalid");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // TODO: this seems wrong. Shouldn't it be the other way around?
+ // Potential bug.
+ // Test failure for a SessionGroup argument with valid value but with stream
+ // options allowed
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.44", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure for more than one SessionGroup argument
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 "
+ "SessionGroup=321");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with a sessiongroup options
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "42 SessionGroup=1111122");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.44", 0, CL_PORT_NO_STREAM_OPTIONS);
+ 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.session_group, OP_EQ, 1111122);
+
+ // Test success with a zero unix domain socket, and doesnt add it to out
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "0");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.45", 0, CL_PORT_IS_UNIXSOCKET);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test success with a one unix domain socket, and doesnt add it to out
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "something");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.45", 0, CL_PORT_IS_UNIXSOCKET);
+ 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_unix_addr, OP_EQ, 1);
+ tt_str_op(port_cfg->unix_addr, OP_EQ, "something");
+
+ // Test success with a port of auto - it uses the default address
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "auto");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
+ 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, CFG_AUTO_PORT);
+ tor_addr_parse(&addr, "127.0.0.46");
+ tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
+
+ // Test success with parsing both an address and an auto port
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.122:auto");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
+ 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, CFG_AUTO_PORT);
+ tor_addr_parse(&addr, "127.0.0.122");
+ tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
+
+ // Test failure when asked to parse an invalid address followed by auto
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "invalidstuff!!:auto");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with parsing both an address and a real port
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.123:656");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
+ 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, 656);
+ tor_addr_parse(&addr, "127.0.0.123");
+ tt_assert(tor_addr_eq(&port_cfg->addr, &addr))
+
+ // Test failure if we can't parse anything at all
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "something wrong");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure if we find both an address, a port and an auto
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.1.0:123:auto");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0,
+ "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test that default to group writeable default sets group writeable for
+ // domain socket
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/somewhere");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS",
+ CONN_TYPE_AP_LISTENER, "127.0.0.46", 0,
+ CL_PORT_DFLT_GROUP_WRITABLE);
+ 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);
+
+ done:
+ smartlist_free(slout);
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+ }
+
+ static void
+ test_config_parse_port_config__ports__server_options(void *data)
+ {
+ (void)data;
+ int ret;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+ config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
+
+ slout = smartlist_new();
+
+ // Test success with NoAdvertise option
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort",
+ "127.0.0.124:656 NoAdvertise");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ CL_PORT_SERVER_OPTIONS);
+ 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->server_cfg.no_advertise, OP_EQ, 1);
+ tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 0);
+
+ // Test success with NoListen option
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ CL_PORT_SERVER_OPTIONS);
+ 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->server_cfg.no_advertise, OP_EQ, 0);
+ tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 1);
+
+ // Test failure with both NoAdvertise and NoListen option
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen "
+ "NoAdvertise");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with IPv4Only
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 IPv4Only");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ CL_PORT_SERVER_OPTIONS);
+ 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->server_cfg.bind_ipv4_only, OP_EQ, 1);
+ tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 0);
+
+ // Test success with IPv6Only
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "[::1]:656 IPv6Only");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ CL_PORT_SERVER_OPTIONS);
+ 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->server_cfg.bind_ipv4_only, OP_EQ, 0);
+ tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 1);
+
+ // Test failure with both IPv4Only and IPv6Only
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only "
+ "IPv4Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with invalid parameter
+ tor_free(config_port_valid);
+ smartlist_clear(slout);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 unknown");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0,
+ CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 1);
+
+ // Test failure when asked to bind only to ipv6 but gets an ipv4 address
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort",
+ "127.0.0.124:656 IPv6Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure when asked to bind only to ipv4 but gets an ipv6 address
+ tor_free(config_port_invalid);
+ smartlist_clear(slout);
+ config_port_invalid = mock_config_line("DNSPort", "[::1]:656 IPv4Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL,
+ 0, CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ done:
+ smartlist_free(slout);
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+ }
+
#define CONFIG_TEST(name, flags) \
{ #name, test_config_ ## name, flags, NULL, NULL }
@@@ -3707,7 -4071,10 +4555,11 @@@ struct testcase_t config_tests[] =
CONFIG_TEST(check_or_create_data_subdir, TT_FORK),
CONFIG_TEST(write_to_data_subdir, TT_FORK),
CONFIG_TEST(fix_my_family, 0),
+ CONFIG_TEST(directory_fetch, 0),
+ CONFIG_TEST(parse_port_config__listenaddress, 0),
+ 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),
END_OF_TESTCASES
};
1
0
commit 3b535869a4a85358df1fa774bc6a36625e453f22
Author: Ola Bini <ola(a)olabini.se>
Date: Tue Sep 15 18:12:14 2015 +0200
Add tests for parse_port_config
---
src/or/config.c | 29 ++-
src/or/config.h | 17 +-
src/test/test_config.c | 681 +++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 708 insertions(+), 19 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index 98d9d83..3130db1 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -545,7 +545,7 @@ static const config_var_t testing_tor_network_defaults[] = {
static char *get_windows_conf_root(void);
#endif
static int options_act_reversible(const or_options_t *old_options, char **msg);
-static int options_act(const or_options_t *old_options);
+STATIC int options_act(const or_options_t *old_options);
static int options_transition_allowed(const or_options_t *old,
const or_options_t *new,
char **msg);
@@ -623,15 +623,15 @@ static char *global_dirfrontpagecontents = NULL;
static smartlist_t *configured_ports = NULL;
/** Return the contents of our frontpage string, or NULL if not configured. */
-const char *
-get_dirportfrontpage(void)
+MOCK_IMPL(const char*,
+get_dirportfrontpage, (void))
{
return global_dirfrontpagecontents;
}
-/** Return the currently configured options. */
-or_options_t *
-get_options_mutable(void)
+/** Returns the currently configured options. */
+MOCK_IMPL(or_options_t *,
+get_options_mutable, (void))
{
tor_assert(global_options);
return global_options;
@@ -790,7 +790,6 @@ config_free_all(void)
tor_free(torrc_fname);
tor_free(torrc_defaults_fname);
- tor_free(the_tor_version);
tor_free(global_dirfrontpagecontents);
tor_free(the_short_tor_version);
@@ -1365,7 +1364,7 @@ options_transition_requires_fresh_tls_context(const or_options_t *old_options,
* Note: We haven't moved all the "act on new configuration" logic
* here yet. Some is still in do_hup() and other places.
*/
-static int
+STATIC int
options_act(const or_options_t *old_options)
{
config_line_t *cl;
@@ -1387,10 +1386,12 @@ options_act(const or_options_t *old_options)
if (options->DisableDebuggerAttachment && !disabled_debugger_attach &&
running_tor) {
int ok = tor_disable_debugger_attach();
+ /* LCOV_EXCL_START the warned_debugger_attach is 0 can't reach inside. */
if (warned_debugger_attach && ok == 1) {
log_notice(LD_CONFIG, "Disabled attaching debuggers for unprivileged "
"users.");
}
+ /* LCOV_EXCL_STOP */
disabled_debugger_attach = (ok == 1);
} else if (!options->DisableDebuggerAttachment &&
!warned_debugger_attach) {
@@ -1417,12 +1418,14 @@ options_act(const or_options_t *old_options)
#endif
#ifdef ENABLE_TOR2WEB_MODE
+/* LCOV_EXCL_START */
if (!options->Tor2webMode) {
log_err(LD_CONFIG, "This copy of Tor was compiled to run in "
"'tor2web mode'. It can only be run with the Tor2webMode torrc "
"option enabled.");
return -1;
}
+/* LCOV_EXCL_STOP */
#else
if (options->Tor2webMode) {
log_err(LD_CONFIG, "This copy of Tor was not compiled to run in "
@@ -1686,8 +1689,7 @@ options_act(const or_options_t *old_options)
if (revise_trackexithosts)
addressmap_clear_excluded_trackexithosts(options);
- if (!options->AutomapHostsOnResolve) {
- if (old_options->AutomapHostsOnResolve)
+ if (!options->AutomapHostsOnResolve && old_options->AutomapHostsOnResolve) {
revise_automap_entries = 1;
} else {
if (!smartlist_strings_eq(old_options->AutomapHostsSuffixes,
@@ -1826,8 +1828,8 @@ options_act(const or_options_t *old_options)
print_notice = 1;
}
if (print_notice)
- log_notice(LD_CONFIG, "Configured to measure statistics. Look for "
- "the *-stats files that will first be written to the "
+ log_notice(LD_CONFIG, "Configured to measure statistics. Look for "
+ "the *-stats files that will first be written to the "
"data directory in 24 hours from now.");
}
@@ -5903,7 +5905,7 @@ config_parse_unix_port(const char *addrport, char **path_out)
* <b>out</b> for every port that the client should listen on. Return 0
* on success, -1 on failure.
*/
-static int
+STATIC int
parse_port_config(smartlist_t *out,
const config_line_t *ports,
const config_line_t *listenaddrs,
@@ -7329,4 +7331,3 @@ init_cookie_authentication(const char *fname, const char *header,
tor_free(cookie_file_str);
return retval;
}
-
diff --git a/src/or/config.h b/src/or/config.h
index 0ee1e1a..28d0cb4 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -14,9 +14,9 @@
#include "testsupport.h"
-const char *get_dirportfrontpage(void);
-MOCK_DECL(const or_options_t *,get_options,(void));
-or_options_t *get_options_mutable(void);
+MOCK_DECL(const char*, get_dirportfrontpage, (void));
+MOCK_DECL(const or_options_t *, get_options, (void));
+MOCK_DECL(or_options_t *, get_options_mutable, (void));
int set_options(or_options_t *new_val, char **msg);
void config_free_all(void);
const char *safe_str_client(const char *address);
@@ -138,6 +138,7 @@ smartlist_t *get_options_for_server_transport(const char *transport);
#ifdef CONFIG_PRIVATE
#ifdef TOR_UNIT_TESTS
extern struct config_format_t options_format;
+STATIC int options_act(const or_options_t *old_options);
#endif
STATIC void or_options_free(or_options_t *options);
@@ -154,7 +155,15 @@ MOCK_DECL(STATIC void, add_default_fallback_dir_servers, (void));
STATIC int
parse_dir_fallback_line(const char *line,
int validate_only);
+STATIC int
+parse_port_config(smartlist_t *out,
+ const config_line_t *ports,
+ const config_line_t *listenaddrs,
+ const char *portname,
+ int listener_type,
+ const char *defaultaddr,
+ int defaultport,
+ const unsigned flags);
#endif
#endif
-
diff --git a/src/test/test_config.c b/src/test/test_config.c
index 28e9fa0..742db28 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -7,17 +7,41 @@
#define CONFIG_PRIVATE
#define PT_PRIVATE
+#define ROUTERSET_PRIVATE
#include "or.h"
+#include "address.h"
#include "addressmap.h"
+#include "circuitmux_ewma.h"
+#include "circuitbuild.h"
#include "config.h"
#include "confparse.h"
+#include "connection.h"
#include "connection_edge.h"
#include "test.h"
#include "util.h"
#include "address.h"
+#include "connection_or.h"
+#include "control.h"
+#include "cpuworker.h"
+#include "dirvote.h"
+#include "dns.h"
#include "entrynodes.h"
#include "transports.h"
+#include "ext_orport.h"
+#include "geoip.h"
+#include "hibernate.h"
+#include "main.h"
+#include "nodelist.h"
+#include "policies.h"
+#include "rendclient.h"
+#include "rendservice.h"
+#include "router.h"
#include "routerlist.h"
+#include "routerset.h"
+#include "statefile.h"
+#include "test.h"
+#include "transports.h"
+#include "util.h"
static void
test_config_addressmap(void *arg)
@@ -3209,6 +3233,660 @@ test_config_adding_dir_servers(void *arg)
UNMOCK(add_default_fallback_dir_servers);
}
+static config_line_t *
+mock_config_line(const char *key, const char *val)
+{
+ config_line_t *config_line = tor_malloc(sizeof(config_line_t));
+ memset(config_line, 0, sizeof(config_line_t));
+ config_line->key = tor_strdup(key);
+ config_line->value = tor_strdup(val);
+ return config_line;
+}
+
+#define test_CL_PORT_NO_STREAM_OPTIONS (1u<<0)
+#define test_CL_PORT_WARN_NONLOCAL (1u<<1)
+#define test_CL_PORT_ALLOW_EXTRA_LISTENADDR (1u<<2)
+#define test_CL_PORT_SERVER_OPTIONS (1u<<3)
+#define test_CL_PORT_FORBID_NONLOCAL (1u<<4)
+#define test_CL_PORT_TAKES_HOSTNAMES (1u<<5)
+#define test_CL_PORT_IS_UNIXSOCKET (1u<<6)
+#define test_CL_PORT_DFLT_GROUP_WRITABLE (1u<<7)
+
+static void
+test_config_parse_port_config__listenaddress(void *data)
+{
+ (void)data;
+ int ret;
+ config_line_t *config_listen_address = NULL, *config_listen_address2 = NULL, *config_listen_address3 = NULL;
+ config_line_t *config_port1 = NULL, *config_port2 = NULL, *config_port3 = NULL, *config_port4 = NULL, *config_port5 = NULL;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+
+ // Test basic invocation with no arguments
+ ret = parse_port_config(NULL, NULL, NULL, NULL, 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+
+ // Setup some test data
+ config_listen_address = mock_config_line("DNSListenAddress", "127.0.0.1");
+ config_listen_address2 = mock_config_line("DNSListenAddress", "x$$$:::345");
+ config_listen_address3 = mock_config_line("DNSListenAddress", "127.0.0.1:1442");
+ config_port1 = mock_config_line("DNSPort", "42");
+ config_port2 = mock_config_line("DNSPort", "43");
+ config_port1->next = config_port2;
+ config_port3 = mock_config_line("DNSPort", "auto");
+ config_port4 = mock_config_line("DNSPort", "55542");
+ config_port5 = mock_config_line("DNSPort", "666777");
+
+ // Test failure when we have a ListenAddress line and several Port lines for the same portname
+ ret = parse_port_config(NULL, config_port1, config_listen_address, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test case when we have a listen address, no default port and allow spurious listen address lines
+ ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL, 0, test_CL_PORT_ALLOW_EXTRA_LISTENADDR);
+ tt_int_op(ret, OP_EQ, 1);
+
+ // Test case when we have a listen address, no default port but doesn't allow spurious listen address lines
+ ret = parse_port_config(NULL, NULL, config_listen_address, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test case when we have a listen address, and a port that points to auto, should use the AUTO port
+ slout = smartlist_new();
+ ret = parse_port_config(slout, config_port3, config_listen_address, "DNS", 0, NULL, 0, 0);
+ 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, CFG_AUTO_PORT);
+
+ // Test when we have a listen address and a custom port
+ ret = parse_port_config(slout, config_port4, config_listen_address, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 2);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
+ tt_int_op(port_cfg->port, OP_EQ, 55542);
+
+ // Test when we have a listen address and an invalid custom port
+ ret = parse_port_config(slout, config_port5, config_listen_address, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test we get a server port configuration when asked for it
+ ret = parse_port_config(slout, NULL, config_listen_address, "DNS", 0, NULL, 123, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 4);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
+ tt_int_op(port_cfg->port, OP_EQ, 123);
+ tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 1);
+ tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 1);
+
+ // Test an invalid ListenAddress configuration
+ ret = parse_port_config(NULL, NULL, config_listen_address2, "DNS", 0, NULL, 222, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test default to the port in the listen address if available
+ ret = parse_port_config(slout, config_port2, config_listen_address3, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 5);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
+ tt_int_op(port_cfg->port, OP_EQ, 1442);
+
+ // Test we work correctly without an out, but with a listen address and a port
+ ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal control
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS", CONN_TYPE_CONTROL_LISTENER, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal ext or listener
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS", CONN_TYPE_EXT_OR_LISTENER, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal other
+ ret = parse_port_config(slout, config_port2, config_listen_address, "DNS", 0, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test warning nonlocal control without an out
+ ret = parse_port_config(NULL, config_port2, config_listen_address, "DNS", CONN_TYPE_CONTROL_LISTENER, NULL, 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ done:
+ tor_free(config_listen_address);
+ tor_free(config_listen_address2);
+ tor_free(config_listen_address3);
+ tor_free(config_port1);
+ tor_free(config_port2);
+ tor_free(config_port3);
+ tor_free(config_port4);
+ tor_free(config_port5);
+ smartlist_free(slout);
+}
+
+
+static void
+test_config_parse_port_config__ports(void *data)
+{
+ (void)data;
+ int ret;
+ smartlist_t *slout = NULL;
+ port_cfg_t *port_cfg = NULL;
+ config_line_t *config_port_invalid = NULL, *config_port_valid = NULL;
+ tor_addr_t addr;
+
+ slout = smartlist_new();
+
+ // Test group -------------------- NO PORTS GIVEN ---------------------
+
+ // Test no defaultport, no defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test with defaultport, no defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, NULL, 42, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test no defaultport, with defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, "127.0.0.2", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test with defaultport, with defaultaddress and no out
+ ret = parse_port_config(NULL, NULL, NULL, "DNS", 0, "127.0.0.2", 42, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test no defaultport, no defaultaddress and with out
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test with defaultport, no defaultaddress and with out
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, NULL, 42, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test no defaultport, with defaultaddress and with out
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "127.0.0.2", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 0);
+
+ // Test with defaultport, with defaultaddress and out, adds a new port cfg
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "127.0.0.2", 42, 0);
+ 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, 42);
+ tt_int_op(port_cfg->is_unix_addr, OP_EQ, 0);
+
+ // Test with defaultport, with defaultaddress and out, adds a new port cfg for a unix address
+ ret = parse_port_config(slout, NULL, NULL, "DNS", 0, "/foo/bar/unixdomain", 42, test_CL_PORT_IS_UNIXSOCKET);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 2);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 1);
+ 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, "/foo/bar/unixdomain");
+
+ // End group --------------------- NO PORTS GIVEN ---------------------
+
+ // Test group -------------------- PORTS GIVEN ------------------------
+
+ // Test error when encounters an invalid Port specification
+ config_port_invalid = mock_config_line("DNSPort", "");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test error when encounters an empty unix domain specification
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "unix:");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test error when encounters a unix domain specification but the listener doesnt support domain sockets
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar");
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", CONN_TYPE_AP_DNS_LISTENER, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test valid unix domain
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 3);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 2);
+ 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");
+
+ // Test failure if we have no ipv4 and no ipv6 (for unix domain sockets, this makes no sense - it should be fixed)
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "unix:/tmp/foo/bar NoIPv4Traffic");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, test_CL_PORT_TAKES_HOSTNAMES);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with no ipv4 but take ipv6 (for unix domain sockets, this makes no sense - it should be fixed)
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar NoIPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, test_CL_PORT_TAKES_HOSTNAMES);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 4);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 3);
+ tt_int_op(port_cfg->entry_cfg.ipv4_traffic, OP_EQ, 0);
+ tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 1);
+
+ // Test success with both ipv4 and ipv6 (for unix domain sockets, this makes no sense - it should be fixed)
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/foo/bar IPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, NULL, 0, test_CL_PORT_TAKES_HOSTNAMES);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 5);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 4);
+ tt_int_op(port_cfg->entry_cfg.ipv4_traffic, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 1);
+
+ // Test failure if we specify world writable for an IP Port
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 WorldWritable");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure if we specify group writable for an IP Port
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 GroupWritable");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with only a port (this will fail without a default address)
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42");
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with only a port and isolate destination port
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateDestPort");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 6);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 5);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_DESTPORT);
+
+ // Test success with a negative isolate destination port, and plural
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 NoIsolateDestPorts");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 7);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 6);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT & ~ISO_DESTPORT);
+
+ // Test success with isolate destination address
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateDestAddr");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 8);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 7);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_DESTADDR);
+
+ // Test success with isolate socks AUTH
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateSOCKSAuth");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 9);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 8);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_SOCKSAUTH);
+
+ // Test success with isolate client protocol
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateClientProtocol");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 10);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 9);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_CLIENTPROTO);
+
+ // Test success with isolate client address
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IsolateClientAddr");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 11);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 10);
+ tt_int_op(port_cfg->entry_cfg.isolation_flags, OP_EQ, ISO_DEFAULT | ISO_CLIENTADDR);
+
+ // Test success with ignored unknown options
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 ThisOptionDoesntExist");
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with no isolate socks AUTH
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 NoIsolateSOCKSAuth");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.3", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 12);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 11);
+ tt_int_op(port_cfg->entry_cfg.socks_prefer_no_auth, OP_EQ, 1);
+
+ // Test success with prefer ipv6
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IPv6Traffic PreferIPv6");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, "127.0.0.42", 0, test_CL_PORT_TAKES_HOSTNAMES);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 13);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 12);
+ tt_int_op(port_cfg->entry_cfg.prefer_ipv6, OP_EQ, 1);
+
+ // Test success with cache ipv4 DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 CacheIPv4DNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 14);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 13);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0);
+
+ // Test success with cache ipv6 DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 CacheIPv6DNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 15);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 14);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1);
+
+ // Test success with no cache ipv4 DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 NoCacheIPv4DNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 16);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 15);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv4_answers, OP_EQ, 0);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 0);
+
+ // Test success with cache DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 CacheDNS");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, test_CL_PORT_TAKES_HOSTNAMES);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 17);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 16);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.cache_ipv6_answers, OP_EQ, 1);
+
+ // Test success with use cached ipv4 DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 UseIPv4Cache");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 18);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 17);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 0);
+
+ // Test success with use cached ipv6 DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 UseIPv6Cache");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 19);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 18);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv4_answers, OP_EQ, 0);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1);
+
+ // Test success with use cached DNS
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 UseDNSCache");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 20);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 19);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv4_answers, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.use_cached_ipv6_answers, OP_EQ, 1);
+
+ // Test success with not preferring ipv6 automap
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 NoPreferIPv6Automap");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 21);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 20);
+ tt_int_op(port_cfg->entry_cfg.prefer_ipv6_virtaddr, OP_EQ, 0);
+
+ // Test success with prefer SOCKS no auth
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 PreferSOCKSNoAuth");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 22);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 21);
+ tt_int_op(port_cfg->entry_cfg.socks_prefer_no_auth, OP_EQ, 1);
+
+ // Test failure with both a zero port and a non-zero port
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+ config_port_invalid = mock_config_line("DNSPort", "0");
+ config_port_valid = mock_config_line("DNSPort", "42");
+ config_port_invalid->next = config_port_valid;
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.42", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with warn non-local control
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_CONTROL_LISTENER, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with warn non-local listener
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_EXT_OR_LISTENER, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with warn non-local other
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with warn non-local other without out
+ ret = parse_port_config(NULL, config_port_valid, NULL, "DNS", 0, "127.0.0.42", 0, test_CL_PORT_WARN_NONLOCAL);
+ tt_int_op(ret, OP_EQ, 0);
+
+ // Test success with both ipv4 and ipv6 but without stream options
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 IPv4Traffic IPv6Traffic");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_TAKES_HOSTNAMES | test_CL_PORT_NO_STREAM_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 27);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 26);
+ tt_int_op(port_cfg->entry_cfg.ipv4_traffic, OP_EQ, 1);
+ tt_int_op(port_cfg->entry_cfg.ipv6_traffic, OP_EQ, 0);
+
+ // Test failure for a SessionGroup argument with invalid value
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=invalid");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // TODO: this seems wrong. Shouldn't it be the other way around? Potential bug.
+ // Test failure for a SessionGroup argument with valid value but with stream options allowed
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.44", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure for more than one SessionGroup argument
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "42 SessionGroup=123 SessionGroup=321");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with a sessiongroup options
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "42 SessionGroup=1111122");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.44", 0, test_CL_PORT_NO_STREAM_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 28);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 27);
+ tt_int_op(port_cfg->entry_cfg.session_group, OP_EQ, 1111122);
+
+ // Test success with a zero unix domain socket, and doesnt add it to out
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "0");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 28);
+
+ // Test success with a one unix domain socket, and doesnt add it to out
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "something");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.45", 0, test_CL_PORT_IS_UNIXSOCKET);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 29);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 28);
+ tt_int_op(port_cfg->is_unix_addr, OP_EQ, 1);
+ tt_str_op(port_cfg->unix_addr, OP_EQ, "something");
+
+ // Test success with a port of auto - it uses the default address
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "auto");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 30);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 29);
+ tt_int_op(port_cfg->port, OP_EQ, CFG_AUTO_PORT);
+ tor_addr_parse(&addr, "127.0.0.46");
+ tt_mem_op(&port_cfg->addr, OP_EQ, &addr, sizeof(tor_addr_t));
+
+ // Test success with parsing both an address and an auto port
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.122:auto");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 31);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 30);
+ tt_int_op(port_cfg->port, OP_EQ, CFG_AUTO_PORT);
+ tor_addr_parse(&addr, "127.0.0.122");
+ tt_mem_op(&port_cfg->addr, OP_EQ, &addr, sizeof(tor_addr_t));
+
+ // Test failure when asked to parse an invalid address followed by auto
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "invalidstuff!!:auto");
+ ret = parse_port_config(NULL, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with parsing both an address and a real port
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.123:656");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 32);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 31);
+ tt_int_op(port_cfg->port, OP_EQ, 656);
+ tor_addr_parse(&addr, "127.0.0.123");
+ tt_mem_op(&port_cfg->addr, OP_EQ, &addr, sizeof(tor_addr_t));
+
+ // Test failure if we can't parse anything at all
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "something wrong");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure if we find both an address, a port and an auto
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.1.0:123:auto");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, "127.0.0.46", 0, 0);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test that default to group writeable default sets group writeable for domain socket
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "unix:/tmp/somewhere");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", CONN_TYPE_AP_LISTENER, "127.0.0.46", 0, test_CL_PORT_DFLT_GROUP_WRITABLE);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 33);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 32);
+ tt_int_op(port_cfg->is_group_writable, OP_EQ, 1);
+
+ // End group --------------------- PORTS GIVEN ------------------------
+
+ // Start group ------------------- SERVER OPTIONS ---------------------
+
+ // Test success with NoAdvertise option
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoAdvertise");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 34);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 33);
+ tt_int_op(port_cfg->server_cfg.no_advertise, OP_EQ, 1);
+ tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 0);
+
+ // Test success with NoListen option
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 35);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 34);
+ tt_int_op(port_cfg->server_cfg.no_advertise, OP_EQ, 0);
+ tt_int_op(port_cfg->server_cfg.no_listen, OP_EQ, 1);
+
+ // Test failure with both NoAdvertise and NoListen option
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 NoListen NoAdvertise");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with IPv4Only
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 IPv4Only");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 36);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 35);
+ tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 1);
+ tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 0);
+
+ // Test success with IPv6Only
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "[::1]:656 IPv6Only");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 37);
+ port_cfg = (port_cfg_t *)smartlist_get(slout, 36);
+ tt_int_op(port_cfg->server_cfg.bind_ipv4_only, OP_EQ, 0);
+ tt_int_op(port_cfg->server_cfg.bind_ipv6_only, OP_EQ, 1);
+
+ // Test failure with both IPv4Only and IPv6Only
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only IPv4Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test success with invalid parameter
+ tor_free(config_port_valid);
+ config_port_valid = mock_config_line("DNSPort", "127.0.0.124:656 unknown");
+ ret = parse_port_config(slout, config_port_valid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, 0);
+ tt_int_op(smartlist_len(slout), OP_EQ, 38);
+
+ // Test failure when asked to bind only to ipv6 but gets an ipv4 address
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "127.0.0.124:656 IPv6Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // Test failure when asked to bind only to ipv4 but gets an ipv6 address
+ tor_free(config_port_invalid);
+ config_port_invalid = mock_config_line("DNSPort", "[::1]:656 IPv4Only");
+ ret = parse_port_config(slout, config_port_invalid, NULL, "DNS", 0, NULL, 0, test_CL_PORT_SERVER_OPTIONS);
+ tt_int_op(ret, OP_EQ, -1);
+
+ // End group --------------------- SERVER OPTIONS ---------------------
+
+ done:
+ smartlist_free(slout);
+ tor_free(config_port_invalid);
+ tor_free(config_port_valid);
+}
+
+
#define CONFIG_TEST(name, flags) \
{ #name, test_config_ ## name, flags, NULL, NULL }
@@ -3222,6 +3900,7 @@ struct testcase_t config_tests[] = {
CONFIG_TEST(check_or_create_data_subdir, TT_FORK),
CONFIG_TEST(write_to_data_subdir, TT_FORK),
CONFIG_TEST(fix_my_family, 0),
+ CONFIG_TEST(parse_port_config__listenaddress, 0),
+ CONFIG_TEST(parse_port_config__ports, 0),
END_OF_TESTCASES
};
-
1
0
commit 598cd4690cba5cd26326c2e37dfcde099904f5df
Author: Ola Bini <ola(a)olabini.se>
Date: Mon Oct 5 14:56:57 2015 -0500
Make compilation work under gcc-warnings
---
src/or/config.c | 1 -
src/or/config.h | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/or/config.c b/src/or/config.c
index 3130db1..7c57a4b 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -545,7 +545,6 @@ static const config_var_t testing_tor_network_defaults[] = {
static char *get_windows_conf_root(void);
#endif
static int options_act_reversible(const or_options_t *old_options, char **msg);
-STATIC int options_act(const or_options_t *old_options);
static int options_transition_allowed(const or_options_t *old,
const or_options_t *new,
char **msg);
diff --git a/src/or/config.h b/src/or/config.h
index 28d0cb4..756b08c 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -136,9 +136,9 @@ smartlist_t *get_options_from_transport_options_line(const char *line,
smartlist_t *get_options_for_server_transport(const char *transport);
#ifdef CONFIG_PRIVATE
+STATIC int options_act(const or_options_t *old_options);
#ifdef TOR_UNIT_TESTS
extern struct config_format_t options_format;
-STATIC int options_act(const or_options_t *old_options);
#endif
STATIC void or_options_free(or_options_t *options);
1
0

[translation/tails-perl5lib_completed] Update translations for tails-perl5lib_completed
by translation@torproject.org 21 Jan '16
by translation@torproject.org 21 Jan '16
21 Jan '16
commit bded1e2213d9757805cb9e311f2de645b63145b9
Author: Translation commit bot <translation(a)torproject.org>
Date: Thu Jan 21 16:49:47 2016 +0000
Update translations for tails-perl5lib_completed
---
de.po | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/de.po b/de.po
index 65e7e9b..25b990b 100644
--- a/de.po
+++ b/de.po
@@ -3,24 +3,35 @@
# This file is distributed under the same license as the PACKAGE package.
#
# Translators:
+# max weber, 2016
# Tobias Bannert <tobannert(a)gmail.com>, 2013
# rike, 2014-2015
msgid ""
msgstr ""
"Project-Id-Version: The Tor Project\n"
"Report-Msgid-Bugs-To: Tails developers <tails(a)boum.org>\n"
-"POT-Creation-Date: 2014-06-24 11:37+0200\n"
-"PO-Revision-Date: 2015-01-28 06:06+0000\n"
-"Last-Translator: rike\n"
-"Language-Team: German (http://www.transifex.com/projects/p/torproject/language/de/)\n"
+"POT-Creation-Date: 2016-01-11 15:40+0100\n"
+"PO-Revision-Date: 2016-01-21 16:21+0000\n"
+"Last-Translator: max weber\n"
+"Language-Team: German (http://www.transifex.com/otf/torproject/language/de/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: de\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: ../lib/Tails/RunningSystem.pm:153
+#: ../lib/Tails/RunningSystem.pm:159
+msgid "Error"
+msgstr "Fehler"
+
+#: ../lib/Tails/RunningSystem.pm:161
msgid ""
"The device Tails is running from cannot be found. Maybe you used the `toram'"
" option?"
msgstr "Das Gerät, von dem Tails ausgeführt wird, konnte nicht gefunden werden. Haben Sie vielleicht die »toram«-Option benutzt?"
+
+#: ../lib/Tails/RunningSystem.pm:192
+msgid ""
+"The drive Tails is running from cannot be found. Maybe you used the `toram' "
+"option?"
+msgstr "Das Speichermedium von dem Tails ausgeführt wird konnte nicht gefunden werden. Haben Sie vielleicht die `toram' Option benutzt?"
1
0