def test_get_record_type_value(self, mock_get_dns_records): mock_get_dns_records.return_value = [ TXT("IN", "TXT", ["v=spf1 mx -all"]), TXT("IN", "TXT", ["v=DKIM1 p=XXXXX", "YYYYY"]), TXT("IN", "TXT", ["v=DMARC1 p=reject"]), ] self.assertEqual(lib.get_spf_record("example.com"), "v=spf1 mx -all") self.assertEqual(lib.get_dkim_record("example.com", "mail"), "v=DKIM1 p=XXXXXYYYYY") self.assertEqual(lib.get_dmarc_record("example.com"), "v=DMARC1 p=reject")
def mock_resolver(_, record_type): if record_type == 'SRV': return [ SRV(0, 0, 0, 0, 27017, Name(labels=hostname)) for hostname in [ b'mongo1.example.com'.split( b'.'), b'mongo2.example.com'.split(b'.'), b'mongo3.example.com'.split(b'.') ] ] elif record_type == 'TXT': return [TXT(0, 0, [b'replicaSet=rs0'])]
def mock_resolver(_, rdtype, rdclass=None, lifetime=None, **kwargs): if rdtype == 'SRV': return [ SRV(0, 0, 0, 0, 27017, Name(labels=hostname)) for hostname in [ b'mongo1.example.com'.split( b'.'), b'mongo2.example.com'.split(b'.'), b'mongo3.example.com'.split(b'.') ] ] elif rdtype == 'TXT': return [TXT(0, 0, [b'replicaSet=rs0'])]
def _dns_query(self, qname, rdtype, *args, **kwargs): try: return [TXT(1, 16, [self.dmarc_txt_records[qname]])] except KeyError: raise dns_resolver.NXDOMAIN
class RRset(object): def __init__(self): self.address = "192.0.2.1" class RRsetInvalid(object): def __init__(self): self.address = "000.0.0.0" _A_RECORD = A("IN", "A", "1.2.3.4") _MX_RECORD_1 = MX("IN", "MX", 10, Name("mx.example.com".split("."))) _MX_RECORD_2 = MX("IN", "MX", 10, Name("mx2.example.com".split("."))) _MX_RECORD_3 = MX("IN", "MX", 10, Name("mx3.example.com".split("."))) _SPF_RECORD = TXT("IN", "TXT", ["v=spf1 mx -all"]) _DMARC_RECORD = TXT("IN", "TXT", ["v=DMARC1 p=reject"]) _DKIM_RECORD = TXT("IN", "TXT", ["v=DKIM1 p=XXXXX"]) _BAD_MX_RECORD = MX("IN", "MX", 10, Name("bad-response.example.com".split("."))) _DNE_MX_RECORD = MX("IN", "MX", 10, Name("does-not-exist.example.com".split("."))) _MX_RECORDS = [_MX_RECORD_1] _IP_SET_RECORDS = [RRset()] _IPV4_RECORD_1 = (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("192.0.2.1", 25)) _IPV4_RECORD_2 = (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("192.0.2.2", 25)) _IPV6_RECORD = (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("2001:db8::1", 25)) _BAD_IP_RECORD = (socket.AF_INET, socket.SOCK_STREAM, 6, "", ("BAD", 25)) _IP_RECORDS = [_IPV4_RECORD_1, _IPV6_RECORD]
def dns_ip_query_response(): answer = [] answer.append(TXT(1, 16, [b'240.0.0.0'])) return answer