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

[tor-commits] [stem/master] Fix exit policy tests



commit 6f7c54782d865eabbbce49223bf2b2619fbf5d47
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Apr 15 12:45:09 2018 -0700

    Fix exit policy tests
    
    Oops, earlier change broke one of our unit test mocks.
---
 test/integ/control/controller.py | 43 +++++-----------------------------------
 test/unit/control/controller.py  | 16 ++-------------
 2 files changed, 7 insertions(+), 52 deletions(-)

diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index b59f5d63..cde8e140 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -270,45 +270,12 @@ class TestController(unittest.TestCase):
   @test.require.controller
   def test_get_exit_policy(self):
     """
-    Sanity test for get_exit_policy(). We have the default policy (no
-    ExitPolicy set) which is a little... long due to the boilerplate.
-    """
-
-    expected = ExitPolicy(
-      'reject 0.0.0.0/8:*',
-      'reject 169.254.0.0/16:*',
-      'reject 127.0.0.0/8:*',
-      'reject 192.168.0.0/16:*',
-      'reject 10.0.0.0/8:*',
-      'reject 172.16.0.0/12:*',
-      # this is where 'reject [public_addr]:*' may or may not be
-      'reject *:25',
-      'reject *:119',
-      'reject *:135-139',
-      'reject *:445',
-      'reject *:563',
-      'reject *:1214',
-      'reject *:4661-4666',
-      'reject *:6346-6429',
-      'reject *:6699',
-      'reject *:6881-6999',
-      'accept *:*',
-    )
-
-    runner = test.runner.get_runner()
-
-    with runner.get_tor_controller() as controller:
-      # We can't simply compare the policies because the tor policy may or may
-      # not have a reject entry for our public address. Hence, stripping it
-      # from the policy's string, then comparing those.
-
-      policy_str = str(controller.get_exit_policy())
-
-      public_addr_start = policy_str.find('reject 172.16.0.0/12:*') + 22
-      public_addr_end = policy_str.find(', reject *:25')
+    Sanity test for get_exit_policy(). Our 'ExitRelay 0' torrc entry causes us
+    to have a simple reject-all policy.
+    """
 
-      policy_str = policy_str[:public_addr_start] + policy_str[public_addr_end:]
-      self.assertEqual(str(expected), policy_str)
+    with test.runner.get_runner().get_tor_controller() as controller:
+      self.assertEqual(ExitPolicy('reject *:*'), controller.get_exit_policy())
 
   @test.require.controller
   def test_authenticate(self):
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index 929adcfc..92abfb67 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -164,23 +164,11 @@ class TestControl(unittest.TestCase):
     }[param]
 
     get_info_mock.side_effect = lambda param, default = None: {
-      'address': '123.45.67.89',
-      'exit-policy/default': 'reject *:25,reject *:119,reject *:135-139,reject *:445,reject *:563,reject *:1214,reject *:4661-4666,reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*',
+      'exit-policy/full': 'reject *:25,reject *:119,reject *:135-139,reject *:445,reject *:563,reject *:1214,reject *:4661-4666,reject *:6346-6429,reject *:6699,reject *:6881-6999,accept *:*',
     }[param]
 
     expected = ExitPolicy(
-      'reject 0.0.0.0/8:*',  # private entries
-      'reject 169.254.0.0/16:*',
-      'reject 127.0.0.0/8:*',
-      'reject 192.168.0.0/16:*',
-      'reject 10.0.0.0/8:*',
-      'reject 172.16.0.0/12:*',
-      'reject 123.45.67.89:*',  # relay's public address
-      'accept *:80',  # finally we get to our ExitPolicy
-      'accept *:443',
-      'accept 43.5.5.5:*',
-      'reject *:22',
-      'reject *:25',  # default policy
+      'reject *:25',
       'reject *:119',
       'reject *:135-139',
       'reject *:445',

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