commit 1936c4d5bdb861c34409a3e366e63035cce3a4a3 Author: Damian Johnson atagar@torproject.org Date: Tue Jul 17 08:29:56 2012 -0700
Test for the set_default_allowed() method --- test/unit/exit_policy/policy.py | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py index a6eb00e..51d650c 100644 --- a/test/unit/exit_policy/policy.py +++ b/test/unit/exit_policy/policy.py @@ -35,6 +35,29 @@ class TestExitPolicy(unittest.TestCase): policy = ExitPolicy(*"accept *:80, accept *:443, reject *:*".split(",")) self.assertEquals(expected_policy, policy)
+ def test_set_default_allowed(self): + policy = ExitPolicy('reject *:80', 'accept *:443') + + # our default for being allowed defaults to True + self.assertFalse(policy.can_exit_to("75.119.206.243", 80)) + self.assertTrue(policy.can_exit_to("75.119.206.243", 443)) + self.assertTrue(policy.can_exit_to("75.119.206.243", 999)) + + policy.set_default_allowed(False) + self.assertFalse(policy.can_exit_to("75.119.206.243", 80)) + self.assertTrue(policy.can_exit_to("75.119.206.243", 443)) + self.assertFalse(policy.can_exit_to("75.119.206.243", 999)) + + # Our is_exiting_allowed() is also influcenced by this flag if we lack any + # 'accept' rules. + + policy = ExitPolicy() + self.assertTrue(policy.is_exiting_allowed()) + + policy.set_default_allowed(False) + self.assertFalse(policy.is_exiting_allowed()) + + def test_parsing(self): """ Tests parsing by the ExitPolicy class constructor.
tor-commits@lists.torproject.org