Exemplo n.º 1
0
    def test_whitelist_ip(self):
        ''' Test the whitelisting of a single IP '''

        lock = threading.Lock()
        ban_fetcher = BanFetcher(BINDSTRING, INTERFACE, BAN_BACKEND,
                                 ["10.0.220.1", "10.0.222.1/24"], lock)
        # An address that shouldn't be banned
        self.assertFalse(
            ban_fetcher.subscription(("swabber_bans", "10.0.220.1")),
            msg="IP that should have been whitelisted was banned!")
Exemplo n.º 2
0
    def test_whitelist_network(self): 
        ''' Test the whitelisting of a whole network '''

        lock = threading.Lock()
        ban_fetcher = BanFetcher(BINDSTRING, INTERFACE,
                                 BAN_BACKEND, ["10.0.220.1", "10.0.222.1/24"],
                                 lock)
        # An address in a network that shouldn't be banned
        self.assertFalse(
            ban_fetcher.subscription(("swabber_bans", "10.0.222.3")), 
            msg="IP in a network that should have been whitelisted was banned!")
Exemplo n.º 3
0
    def test_whitelist_notwhitelisted(self):
        ''' Test the unwhitelisting of an IP to ensure it isn't whitelisted '''

        lock = threading.Lock()
        ban_fetcher = BanFetcher(BINDSTRING, INTERFACE, BAN_BACKEND,
                                 ["10.0.220.1", "10.0.222.1/24"], lock)

        # An address that should be banned
        self.assertTrue(ban_fetcher.subscription(
            ("swabber_bans", "10.0.220.2")),
                        msg="Unwhitelisted IP was whitelisted")

        # clean up after ourselves
        ban = IPTablesCommandBanEntry("10.0.220.2")
        ban.unban(interface=INTERFACE)
Exemplo n.º 4
0
    def test_whitelist_notwhitelisted(self): 
        ''' Test the unwhitelisting of an IP to ensure it isn't whitelisted '''

        lock = threading.Lock()
        ban_fetcher = BanFetcher(BINDSTRING, INTERFACE,
                                 BAN_BACKEND, ["10.0.220.1", "10.0.222.1/24"],
                                 lock)

        # An address that should be banned
        self.assertTrue(
            ban_fetcher.subscription(("swabber_bans", "10.0.220.2")), 
            msg="Unwhitelisted IP was whitelisted")

        # clean up after ourselves
        ban = IPTablesCommandBanEntry("10.0.220.2")
        ban.unban(interface=INTERFACE)