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

[or-cvs] r8764: Add some more unit tests for policies. (in tor/trunk: . src/or)



Author: nickm
Date: 2006-10-19 19:05:25 -0400 (Thu, 19 Oct 2006)
New Revision: 8764

Modified:
   tor/trunk/
   tor/trunk/src/or/test.c
Log:
 r9276@Kushana:  nickm | 2006-10-19 17:08:15 -0400
 Add some more unit tests for policies.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r9276] on c95137ef-5f19-0410-b913-86e773d04f59

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2006-10-19 23:05:19 UTC (rev 8763)
+++ tor/trunk/src/or/test.c	2006-10-19 23:05:25 UTC (rev 8764)
@@ -36,6 +36,8 @@
 size_t read_escaped_data(const char *data, size_t len, int translate_newlines,
                          char **out);
 or_options_t *options_new(void);
+int parse_addr_policy(config_line_t *cfg, addr_policy_t **dest,
+                      int assume_action);
 
 static char temp_dir[256];
 
@@ -1617,9 +1619,10 @@
 }
 
 static void
-test_exit_policies(void)
+test_policies(void)
 {
-  addr_policy_t *policy;
+  addr_policy_t *policy, *policy2;
+  config_line_t line;
 
   policy = router_parse_addr_policy_from_string("reject 192.168.0.0/16:*",-1);
   test_eq(NULL, policy->next);
@@ -1630,7 +1633,6 @@
   test_eq(65535, policy->prt_max);
   test_streq("reject 192.168.0.0/16:*", policy->string);
 
-//  test_assert(exit_policy_implicitly_allows_local_networks(policy, 0));
   test_assert(ADDR_POLICY_ACCEPTED ==
           compare_addr_to_addr_policy(0x01020304u, 2, policy));
   test_assert(ADDR_POLICY_PROBABLY_ACCEPTED ==
@@ -1638,18 +1640,34 @@
   test_assert(ADDR_POLICY_REJECTED ==
           compare_addr_to_addr_policy(0xc0a80102, 2, policy));
 
+  policy2 = NULL;
+  test_assert(0 == policies_parse_exit_policy(NULL, &policy2, 1));
+  test_assert(policy2);
+
+  test_assert(!exit_policy_is_general_exit(policy));
+  test_assert(exit_policy_is_general_exit(policy2));
+
+  test_assert(cmp_addr_policies(policy, policy2));
+  test_assert(!cmp_addr_policies(policy2, policy2));
+
+  test_assert(!policy_is_reject_star(policy2));
+  test_assert(policy_is_reject_star(policy));
+
   addr_policy_free(policy);
+  addr_policy_free(policy2);
 
-#if 0
-  /* Copied from router.c */
+  /* make sure compacting logic works. */
   policy = NULL;
-  options_append_default_exit_policy(&policy);
+  line.key = (char*)"foo";
+  line.value = (char*)"accept *:80,reject private:*,reject *:*";
+  line.next = NULL;
+  test_assert(0 == policies_parse_exit_policy(&line, &policy, 0));
   test_assert(policy);
-  test_assert(!exit_policy_implicitly_allows_local_networks(policy, 1));
+  test_streq(policy->string, "accept *:80");
+  test_streq(policy->next->string, "reject *:*");
+  test_eq_ptr(policy->next->next, NULL);
 
   addr_policy_free(policy);
-#endif
-
 }
 
 static void
@@ -1838,8 +1856,8 @@
   test_onion_handshake();
   puts("\n========================= Directory Formats ===============");
   test_dir_format();
-  puts("\n========================= Exit policies ===================");
-  test_exit_policies();
+  puts("\n========================= Policies ===================");
+  test_policies();
   puts("\n========================= Rendezvous functionality ========");
   test_rend_fns();
   puts("");