summaryrefslogtreecommitdiff
path: root/src/test/test_config.c
diff options
context:
space:
mode:
authorRobert Hogan <robert@roberthogan.net>2010-12-13 22:13:01 +0000
committerNick Mathewson <nickm@torproject.org>2011-11-30 14:08:10 -0500
commit909e9769ece9e89ad0c4bbb558a6f8247c6a62bd (patch)
tree233006bc5a08a1d2c80ad6d43b8dda10876f4eae /src/test/test_config.c
parentc6d8c6baaa983aecd6a5121ec6ed8e2d9a2a24be (diff)
downloadtor-909e9769ece9e89ad0c4bbb558a6f8247c6a62bd.tar.gz
tor-909e9769ece9e89ad0c4bbb558a6f8247c6a62bd.zip
Address nickm's comments at https://trac.torproject.org/projects/tor/ticket/933#comment:4
1. Implement the following mapping rules: MapAddress a.b.c d.e.f # This is what we have now MapAddress .a.b.c d.e.f # Replaces any address ending with .a.b.c with d.e.f MapAddress .a.b.c .d.e.f # Replaces the .a.b.c at the end of any addr with .d.e.f (Note that 'a.b.c .d.e.f' is invalid, and will be rejected.) 2. Add tests for the new rules. 3. Allow proper wildcard annotation, i.e. '*.d.e' '.d.e' will still work. 4. Update addressmap_entry_t with an is_wildcard member.
Diffstat (limited to 'src/test/test_config.c')
-rw-r--r--src/test/test_config.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/test/test_config.c b/src/test/test_config.c
index f39a9ef52d..a7b5d03a0c 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -16,6 +16,11 @@ test_config_addressmap(void)
char address[256];
time_t expires = TIME_MAX;
strlcpy(buf, "MapAddress .google.com .torserver.exit\n"
+ "MapAddress *.yahoo.com *.google.com.torserver.exit\n"
+ "MapAddress .cn.com www.cnn.com\n"
+ "MapAddress *.cnn.com www.cnn.com\n"
+ "MapAddress ex.com www.cnn.com\n"
+ "MapAddress ey.com *.cnn.com\n"
"MapAddress www.torproject.org 1.1.1.1\n"
"MapAddress other.torproject.org "
"this.torproject.org.otherserver.exit\n"
@@ -31,10 +36,34 @@ test_config_addressmap(void)
config_register_addressmaps(get_options());
/* Where no mapping for FQDN match on top-level domain */
+ /* MapAddress .google.com .torserver.exit */
strlcpy(address, "reader.google.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+ test_streq(address, "reader.torserver.exit");
+
+ /* MapAddress *.yahoo.com *.google.com.torserver.exit */
+ strlcpy(address, "reader.yahoo.com", sizeof(address));
+ test_assert(addressmap_rewrite(address, sizeof(address), &expires));
test_streq(address, "reader.google.com.torserver.exit");
+ /*MapAddress *.cnn.com www.cnn.com */
+ strlcpy(address, "cnn.com", sizeof(address));
+ test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+ test_streq(address, "www.cnn.com");
+
+ /* MapAddress .cn.com www.cnn.com */
+ strlcpy(address, "www.cn.com", sizeof(address));
+ test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+ test_streq(address, "www.cnn.com");
+
+ /* MapAddress ex.com www.cnn.com - no match */
+ strlcpy(address, "www.ex.com", sizeof(address));
+ test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+
+ /* MapAddress ey.com *.cnn.com - invalid expression */
+ strlcpy(address, "ey.com", sizeof(address));
+ test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+
/* Where mapping for FQDN match on FQDN */
strlcpy(address, "www.google.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires));
@@ -77,11 +106,11 @@ test_config_addressmap(void)
strlcpy(address, "www.abc.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires));
- test_streq(address, "www.abc.com.torserver.exit");
+ test_streq(address, "www.abc.torserver.exit");
strlcpy(address, "www.def.com", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires));
- test_streq(address, "www.def.com.torserver.exit");
+ test_streq(address, "www.def.torserver.exit");
strlcpy(address, "www.torproject.org", sizeof(address));
test_assert(addressmap_rewrite(address, sizeof(address), &expires));