def test_dnsblocklistgroup_get(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     DNSResolver.query('4.3.2.1.test1.example.com',
                       'A').InAnyOrder('one').AndReturn(FakeAsyncResult())
     DNSResolver.query('4.3.2.1.test2.example.com',
                       'A').InAnyOrder('one').AndRaise(
                           DNSError(ARES_ENOTFOUND))
     DNSResolver.query('4.3.2.1.test3.example.com',
                       'A').InAnyOrder('one').AndReturn(FakeAsyncResult())
     DNSResolver.query('8.7.6.5.test1.example.com',
                       'A').InAnyOrder('two').AndRaise(
                           DNSError(ARES_ENOTFOUND))
     DNSResolver.query('8.7.6.5.test2.example.com',
                       'A').InAnyOrder('two').AndRaise(
                           DNSError(ARES_ENOTFOUND))
     DNSResolver.query('8.7.6.5.test3.example.com',
                       'A').InAnyOrder('two').AndRaise(
                           DNSError(ARES_ENOTFOUND))
     self.mox.ReplayAll()
     self.assertEqual(set(['test1.example.com', 'test3.example.com']),
                      group.get('1.2.3.4'))
     self.assertNotIn('5.6.7.8', group)
 def test_dnsblocklistgroup_get_reasons(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     DNSResolver.query('4.3.2.1.test1.example.com', 'TXT').InAnyOrder().AndReturn(FakeAsyncResult(['reason one']))
     DNSResolver.query('4.3.2.1.test3.example.com', 'TXT').InAnyOrder().AndReturn(FakeAsyncResult())
     self.mox.ReplayAll()
     self.assertEqual({'test1.example.com': 'reason one', 'test3.example.com': None},
                      group.get_reasons(set(['test1.example.com', 'test3.example.com']), '1.2.3.4'))
Пример #3
0
 def get_banner_decorator(self):
     if self.dnsbl:
         if isinstance(self.dnsbl, list):
             blgroup = DnsBlocklistGroup()
             for bl in self.dnsbl:
                 blgroup.add_dnsbl(bl)
             return check_dnsbl(blgroup, match_code='520')
         else:
             return check_dnsbl(self.dnsbl, match_code='520')
     return self._noop_decorator
Пример #4
0
 def test_dnsblocklistgroup_get_reasons(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     dns.resolver.query('4.3.2.1.test1.example.com', 'TXT').InAnyOrder().AndReturn(['reason one'])
     dns.resolver.query('4.3.2.1.test3.example.com', 'TXT').InAnyOrder()
     self.mox.ReplayAll()
     self.assertEqual({'test1.example.com': 'reason one', 'test3.example.com': None},
                      group.get_reasons(set(['test1.example.com', 'test3.example.com']), '1.2.3.4'))
Пример #5
0
 def test_dnsblocklistgroup_get_reasons(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl("test1.example.com")
     group.add_dnsbl("test2.example.com")
     group.add_dnsbl("test3.example.com")
     dns_resolver.query("4.3.2.1.test1.example.com", "TXT").InAnyOrder().AndReturn(["reason one"])
     dns_resolver.query("4.3.2.1.test3.example.com", "TXT").InAnyOrder()
     self.mox.ReplayAll()
     self.assertEqual(
         {"test1.example.com": "reason one", "test3.example.com": None},
         group.get_reasons(set(["test1.example.com", "test3.example.com"]), "1.2.3.4"),
     )
 def test_dnsblocklistgroup_get(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     DNSResolver.query('4.3.2.1.test1.example.com', 'A').InAnyOrder('one').AndReturn(FakeAsyncResult())
     DNSResolver.query('4.3.2.1.test2.example.com', 'A').InAnyOrder('one').AndRaise(DNSError(ARES_ENOTFOUND))
     DNSResolver.query('4.3.2.1.test3.example.com', 'A').InAnyOrder('one').AndReturn(FakeAsyncResult())
     DNSResolver.query('8.7.6.5.test1.example.com', 'A').InAnyOrder('two').AndRaise(DNSError(ARES_ENOTFOUND))
     DNSResolver.query('8.7.6.5.test2.example.com', 'A').InAnyOrder('two').AndRaise(DNSError(ARES_ENOTFOUND))
     DNSResolver.query('8.7.6.5.test3.example.com', 'A').InAnyOrder('two').AndRaise(DNSError(ARES_ENOTFOUND))
     self.mox.ReplayAll()
     self.assertEqual(set(['test1.example.com', 'test3.example.com']), group.get('1.2.3.4'))
     self.assertNotIn('5.6.7.8', group)
Пример #7
0
 def test_dnsblocklistgroup_get(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl('test1.example.com')
     group.add_dnsbl('test2.example.com')
     group.add_dnsbl('test3.example.com')
     dns.resolver.query('4.3.2.1.test1.example.com', 'A').InAnyOrder('one')
     dns.resolver.query('4.3.2.1.test2.example.com', 'A').InAnyOrder('one').AndRaise(dns.resolver.NXDOMAIN)
     dns.resolver.query('4.3.2.1.test3.example.com', 'A').InAnyOrder('one')
     dns.resolver.query('8.7.6.5.test1.example.com', 'A').InAnyOrder('two').AndRaise(dns.resolver.NXDOMAIN)
     dns.resolver.query('8.7.6.5.test2.example.com', 'A').InAnyOrder('two').AndRaise(dns.resolver.NXDOMAIN)
     dns.resolver.query('8.7.6.5.test3.example.com', 'A').InAnyOrder('two').AndRaise(dns.resolver.NXDOMAIN)
     self.mox.ReplayAll()
     self.assertEqual(set(['test1.example.com', 'test3.example.com']), group.get('1.2.3.4'))
     self.assertNotIn('5.6.7.8', group)
Пример #8
0
 def test_dnsblocklistgroup_get(self):
     group = DnsBlocklistGroup()
     group.add_dnsbl("test1.example.com")
     group.add_dnsbl("test2.example.com")
     group.add_dnsbl("test3.example.com")
     dns_resolver.query("4.3.2.1.test1.example.com", "A").InAnyOrder("one")
     dns_resolver.query("4.3.2.1.test2.example.com", "A").InAnyOrder("one").AndRaise(NXDOMAIN)
     dns_resolver.query("4.3.2.1.test3.example.com", "A").InAnyOrder("one")
     dns_resolver.query("8.7.6.5.test1.example.com", "A").InAnyOrder("two").AndRaise(NXDOMAIN)
     dns_resolver.query("8.7.6.5.test2.example.com", "A").InAnyOrder("two").AndRaise(NXDOMAIN)
     dns_resolver.query("8.7.6.5.test3.example.com", "A").InAnyOrder("two").AndRaise(NXDOMAIN)
     self.mox.ReplayAll()
     self.assertEqual(set(["test1.example.com", "test3.example.com"]), group.get("1.2.3.4"))
     self.assertNotIn("5.6.7.8", group)