Пример #1
0
 def test_in_whitelist(self):
     # Connection should be accepted and nothing logged.
     factory = WhitelistingFactory(TestFactory(), [ip_network('0.0.0.0/0')])
     self.assertIsInstance(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)),
         Protocol)
     self.assertEqual(len(self.observer.messages), 0)
Пример #2
0
 def test_empty_whitelist(self):
     # All connections should be denied
     factory = WhitelistingFactory(TestFactory(), [])
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)),
         None
     )
Пример #3
0
 def test_empty_whitelist(self):
     # All connections should be denied and a default message logged.
     factory = WhitelistingFactory(TestFactory(), [])
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)), None)
     self.assertEqual(len(self.observer.messages), 1)
     self.assertTrue("connection" in self.observer.messages[0][0])
Пример #4
0
 def test_not_in_whitelist(self):
     # Connection should be accepted and nothing logged.
     factory = WhitelistingFactory(TestFactory(), [ip_network('127.0.0.1/32')])
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.2', 0)),
         None
     )
Пример #5
0
 def test_in_whitelist(self):
     # Connection should be accepted and nothing logged.
     factory = WhitelistingFactory(TestFactory(), [ip_network('0.0.0.0/0')])
     self.assertIsInstance(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)),
         Protocol
     )
     self.assertEqual(len(self.observer.messages), 0)
Пример #6
0
 def test_empty_whitelist(self):
     # All connections should be denied and a default message logged.
     factory = WhitelistingFactory(TestFactory(), [])
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)),
         None
     )
     self.assertEqual(len(self.observer.messages), 1)
     self.assertTrue("connection" in self.observer.messages[0][0])
Пример #7
0
 def test_log_message(self):
     # Should be possible to customize the message which is logged.
     TEST_STRING = "test-1234"
     factory = WhitelistingFactory(TestFactory(),
                                   [ip_network('127.0.0.1/32')],
                                   TEST_STRING)
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.2', 0)), None)
     self.assertFalse("connection" in self.observer.messages[0][0])
     self.assertTrue(TEST_STRING in self.observer.messages[0][0])
Пример #8
0
    def test_unix_domain_socket(self):
        """Test that the whitelist is skipped for Unix domain sockets.
        """
        factory = WhitelistingFactory(TestFactory(), [])

        # Should be blocking IP addresses
        self.assertEqual(
            factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)),
            None
        )

        # But Unix domain sockets are allowed
        self.assertIsInstance(
            factory.buildProtocol(UNIXAddress('/test/address')),
            Protocol
        )

        # With a warning logged
        self.assertTrue("Bypassing" in self.observer.messages[1][0])
Пример #9
0
 def test_log_message(self):
     # Should be possible to customize the message which is logged.
     TEST_STRING = "test-1234"
     factory = WhitelistingFactory(
         TestFactory(), [ip_network('127.0.0.1/32')], TEST_STRING
     )
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.2', 0)),
         None
     )
     self.assertFalse("connection" in self.observer.messages[0][0])
     self.assertTrue(TEST_STRING in self.observer.messages[0][0])
Пример #10
0
 def test_not_in_whitelist(self):
     factory = WhitelistingFactory(TestFactory(), [ip_network('127.0.0.1/32')])
     self.assertEqual(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.2', 0)),
         None
     )
Пример #11
0
 def test_in_whitelist(self):
     factory = WhitelistingFactory(TestFactory(), [ip_network('0.0.0.0/0')])
     self.assertIsInstance(
         factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 0)),
         Protocol
     )