[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Merge branch 'bug933_nm_rebased_v2'



commit 3b88b638264011158d27d5b451fd07d16f60e16b
Merge: 60b41cd e8d598c
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Wed Nov 30 14:10:22 2011 -0500

    Merge branch 'bug933_nm_rebased_v2'
    
    Conflicts:
    	src/test/test.c

 changes/bug933           |    4 +
 doc/tor.1.txt            |   41 ++++++++++-
 src/or/circuituse.c      |    2 +-
 src/or/config.c          |   62 +++++++++++++----
 src/or/connection_edge.c |  105 +++++++++++++++++++++++++---
 src/or/connection_edge.h |    3 +-
 src/or/control.c         |    3 +-
 src/test/Makefile.am     |    1 +
 src/test/test.c          |    2 +
 src/test/test_config.c   |  170 ++++++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 361 insertions(+), 32 deletions(-)

diff --cc src/test/Makefile.am
index ffe1f94,e675431..73de300
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@@ -19,13 -19,10 +19,14 @@@ test_SOURCES = 
  	test_data.c \
  	test_dir.c \
  	test_microdesc.c \
 +	test_pt.c \
  	test_util.c \
+ 	test_config.c \
  	tinytest.c
  
 +bench_SOURCES = \
 +	bench.c
 +
  test_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
          @TOR_LDFLAGS_libevent@
  test_LDADD = ../or/libtor.a ../common/libor.a ../common/libor-crypto.a \
diff --cc src/test/test.c
index 092b2c3,76644a7..5fcc31c
--- a/src/test/test.c
+++ b/src/test/test.c
@@@ -1843,7 -1941,7 +1843,8 @@@ extern struct testcase_t container_test
  extern struct testcase_t util_tests[];
  extern struct testcase_t dir_tests[];
  extern struct testcase_t microdesc_tests[];
 +extern struct testcase_t pt_tests[];
+ extern struct testcase_t config_tests[];
  
  static struct testgroup_t testgroups[] = {
    { "", test_array },
@@@ -1854,7 -1952,7 +1855,8 @@@
    { "util/", util_tests },
    { "dir/", dir_tests },
    { "dir/md/", microdesc_tests },
 +  { "pt/", pt_tests },
+   { "config/", config_tests },
    END_OF_GROUPS
  };
  
diff --cc src/test/test_config.c
index 0000000,99d7215..4ce0fa8
mode 000000,100644..100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@@ -1,0 -1,170 +1,170 @@@
+ /* Copyright (c) 2001-2004, Roger Dingledine.
+  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+  * Copyright (c) 2007-2010, The Tor Project, Inc. */
+ /* See LICENSE for licensing information */
+ 
+ #include "orconfig.h"
+ #include "or.h"
+ #include "config.h"
+ #include "connection_edge.h"
+ #include "test.h"
+ 
+ static void
+ test_config_addressmap(void *arg)
+ {
+   char buf[1024];
+   char address[256];
+   time_t expires = TIME_MAX;
+   (void)arg;
+ 
+   strlcpy(buf, "MapAddress .invalidwildcard.com *.torserver.exit\n" // invalid
+           "MapAddress *invalidasterisk.com *.torserver.exit\n" // invalid
+           "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"
+           "MapAddress test.torproject.org 2.2.2.2\n"
+           "MapAddress www.google.com 3.3.3.3\n"
+           "MapAddress www.example.org 4.4.4.4\n"
+           "MapAddress 4.4.4.4 7.7.7.7\n"
+           "MapAddress 4.4.4.4 5.5.5.5\n"
+           "MapAddress www.infiniteloop.org 6.6.6.6\n"
+           "MapAddress 6.6.6.6 www.infiniteloop.org\n"
+           , sizeof(buf));
+ 
 -  config_get_lines(buf, &(get_options_mutable()->AddressMap));
++  config_get_lines(buf, &(get_options_mutable()->AddressMap), 0);
+   config_register_addressmaps(get_options());
+ 
+   /* MapAddress .invalidwildcard.com .torserver.exit  - no match */
+   strlcpy(address, "www.invalidwildcard.com", sizeof(address));
+   test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+ 
+   /* MapAddress *invalidasterisk.com .torserver.exit  - no match */
+   strlcpy(address, "www.invalidasterisk.com", sizeof(address));
+   test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+ 
+   /* 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));
+   test_streq(address, "3.3.3.3");
+ 
+   strlcpy(address, "www.torproject.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "1.1.1.1");
+ 
+   strlcpy(address, "other.torproject.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "this.torproject.org.otherserver.exit");
+ 
+   strlcpy(address, "test.torproject.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "2.2.2.2");
+ 
+   /* Test a chain of address mappings and the order in which they were added:
+           "MapAddress www.example.org 4.4.4.4"
+           "MapAddress 4.4.4.4 7.7.7.7"
+           "MapAddress 4.4.4.4 5.5.5.5"
+   */
+   strlcpy(address, "www.example.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "5.5.5.5");
+ 
+   /* Test infinite address mapping results in no change */
+   strlcpy(address, "www.infiniteloop.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "www.infiniteloop.org");
+ 
+   /* Test we don't find false positives */
+   strlcpy(address, "www.example.com", sizeof(address));
+   test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+ 
+   /* Test top-level-domain matching a bit harder */
+   addressmap_clear_configured();
+   strlcpy(buf, "MapAddress *.com *.torserver.exit\n"
+           "MapAddress *.torproject.org 1.1.1.1\n"
+           "MapAddress *.net 2.2.2.2\n"
+           , sizeof(buf));
 -  config_get_lines(buf, &(get_options_mutable()->AddressMap));
++  config_get_lines(buf, &(get_options_mutable()->AddressMap), 0);
+   config_register_addressmaps(get_options());
+ 
+   strlcpy(address, "www.abc.com", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   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.torserver.exit");
+ 
+   strlcpy(address, "www.torproject.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "1.1.1.1");
+ 
+   strlcpy(address, "test.torproject.org", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "1.1.1.1");
+ 
+   strlcpy(address, "torproject.net", sizeof(address));
+   test_assert(addressmap_rewrite(address, sizeof(address), &expires));
+   test_streq(address, "2.2.2.2");
+ 
+   /* We don't support '*' as a mapping directive */
+   addressmap_clear_configured();
+   strlcpy(buf, "MapAddress * *.torserver.exit\n", sizeof(buf));
 -  config_get_lines(buf, &(get_options_mutable()->AddressMap));
++  config_get_lines(buf, &(get_options_mutable()->AddressMap), 0);
+   config_register_addressmaps(get_options());
+ 
+   strlcpy(address, "www.abc.com", sizeof(address));
+   test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+ 
+   strlcpy(address, "www.def.net", sizeof(address));
+   test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+ 
+   strlcpy(address, "www.torproject.org", sizeof(address));
+   test_assert(!addressmap_rewrite(address, sizeof(address), &expires));
+ 
+ done:
+   ;
+ }
+ 
+ #define CONFIG_TEST(name, flags)                          \
+   { #name, test_config_ ## name, flags, NULL, NULL }
+ 
+ struct testcase_t config_tests[] = {
+   CONFIG_TEST(addressmap, 0),
+   END_OF_TESTCASES
+ };
+ 

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits