示例#1
0
文件: policy.py 项目: gsathya/stem
    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())
示例#2
0
    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())
示例#3
0
文件: policy.py 项目: patrickod/stem
  def test_is_exiting_allowed(self):
    test_inputs = {
      (): True,
      ('accept *:*', ): True,
      ('reject *:*', ): False,
      ('accept *:80', 'reject *:*'): True,
      ('reject *:80', 'accept *:80', 'reject *:*'): False,
      ('reject *:50-90', 'accept *:80', 'reject *:*'): False,
      ('reject *:2-65535', 'accept *:80-65535', 'reject *:*'): False,
      ('reject *:2-65535', 'accept 127.0.0.0:1', 'reject *:*'): True,
      ('reject 127.0.0.1:*', 'accept *:80', 'reject *:*'): True,
    }

    for rules, expected_result in test_inputs.items():
      policy = ExitPolicy(*rules)
      self.assertEqual(expected_result, policy.is_exiting_allowed())
示例#4
0
    def test_is_exiting_allowed(self):
        test_inputs = {
            (): True,
            ('accept *:*', ): True,
            ('reject *:*', ): False,
            ('accept *:80', 'reject *:*'): True,
            ('reject *:80', 'accept *:80', 'reject *:*'): False,
            ('reject *:50-90', 'accept *:80', 'reject *:*'): False,
            ('reject *:2-65535', 'accept *:80-65535', 'reject *:*'): False,
            ('reject *:2-65535', 'accept 127.0.0.0:1', 'reject *:*'): True,
            ('reject 127.0.0.1:*', 'accept *:80', 'reject *:*'): True,
        }

        for rules, expected_result in test_inputs.items():
            policy = ExitPolicy(*rules)
            self.assertEqual(expected_result, policy.is_exiting_allowed())
示例#5
0
文件: policy.py 项目: gsathya/stem
    def test_is_exiting_allowed(self):
        test_inputs = {
            (): True,
            ("accept *:*",): True,
            ("reject *:*",): False,
            ("accept *:80", "reject *:*"): True,
            ("reject *:80", "accept *:80", "reject *:*"): False,
            ("reject *:50-90", "accept *:80", "reject *:*"): False,
            ("reject *:2-65535", "accept *:80-65535", "reject *:*"): False,
            ("reject *:2-65535", "accept 127.0.0.0:1", "reject *:*"): True,
            ("reject 127.0.0.1:*", "accept *:80", "reject *:*"): True,
        }

        for rules, expected_result in test_inputs.items():
            policy = ExitPolicy(*rules)
            self.assertEquals(expected_result, policy.is_exiting_allowed())