Exemplo n.º 1
0
 def test_hinfo(self):
     """
     The repr of a L{dns.Record_HINFO} instance includes the cpu, os, and
     TTL fields of the record.
     """
     self.assertEqual(repr(dns.Record_HINFO('sparc', 'minix', 12)),
                      "<HINFO cpu='sparc' os='minix' ttl=12>")
Exemplo n.º 2
0
 def testHINFO(self):
     """Test DNS 'HINFO' record queries"""
     return self.namesTest(
         self.resolver.lookupHostInfo('test-domain.com'), [
             dns.Record_HINFO(
                 os='Linux', cpu='A Fast One, Dontcha know', ttl=19283784)
         ])
Exemplo n.º 3
0
 def test_HINFO(self):
     """Test DNS 'HINFO' record queries"""
     return self.namesTest(
         self.resolver.lookupHostInfo("test-domain.com"),
         [
             dns.Record_HINFO(
                 os=b"Linux", cpu=b"A Fast One, Dontcha know", ttl=19283784)
         ],
     )
Exemplo n.º 4
0
 def test_hinfo(self):
     """
     Two L{dns.Record_HINFO} instances compare equal if and only if they
     have the same cpu, os, and ttl.
     """
     # Vary the cpu
     self._equalityTest(dns.Record_HINFO('x86-64', 'plan9', 10),
                        dns.Record_HINFO('x86-64', 'plan9', 10),
                        dns.Record_HINFO('i386', 'plan9', 10))
     # Vary the os
     self._equalityTest(dns.Record_HINFO('x86-64', 'plan9', 10),
                        dns.Record_HINFO('x86-64', 'plan9', 10),
                        dns.Record_HINFO('x86-64', 'plan11', 10))
     # Vary the ttl
     self._equalityTest(dns.Record_HINFO('x86-64', 'plan9', 10),
                        dns.Record_HINFO('x86-64', 'plan9', 10),
                        dns.Record_HINFO('x86-64', 'plan9', 100))
Exemplo n.º 5
0
    expire=999999,
    retry=100,
)

test_domain_com = NoFileAuthority(
    soa=('test-domain.com', soa_record),
    records={
        'test-domain.com': [
            soa_record,
            dns.Record_A('127.0.0.1'),
            dns.Record_NS('39.28.189.39'),
            dns.Record_SPF('v=spf1 mx/30 mx:example.org/30 -all'),
            dns.Record_SPF('v=spf1 +mx a:\0colo',
                           '.example.com/28 -all not valid'),
            dns.Record_MX(10, 'host.test-domain.com'),
            dns.Record_HINFO(os='Linux', cpu='A Fast One, Dontcha know'),
            dns.Record_CNAME('canonical.name.com'),
            dns.Record_MB('mailbox.test-domain.com'),
            dns.Record_MG('mail.group.someplace'),
            dns.Record_TXT('A First piece of Text', 'a SecoNd piece'),
            dns.Record_A6(0, 'ABCD::4321', ''),
            dns.Record_A6(12, '0:0069::0', 'some.network.tld'),
            dns.Record_A6(8, '0:5634:1294:AFCB:56AC:48EF:34C3:01FF',
                          'tra.la.la.net'),
            dns.Record_TXT('Some more text, haha!  Yes.  \0  Still here?'),
            dns.Record_MR('mail.redirect.or.whatever'),
            dns.Record_MINFO(rmailbx='r mail box', emailbx='e mail box'),
            dns.Record_AFSDB(subtype=1, hostname='afsdb.test-domain.com'),
            dns.Record_RP(mbox='whatever.i.dunno', txt='some.more.text'),
            dns.Record_WKS('12.54.78.12', socket.IPPROTO_TCP,
                           '\x12\x01\x16\xfe\xc1\x00\x01'),
Exemplo n.º 6
0
    expire=999999,
    retry=100,
)

test_domain_com = NoFileAuthority(
    soa=(b"test-domain.com", soa_record),
    records={
        b"test-domain.com": [
            soa_record,
            dns.Record_A(b"127.0.0.1"),
            dns.Record_NS(b"39.28.189.39"),
            dns.Record_SPF(b"v=spf1 mx/30 mx:example.org/30 -all"),
            dns.Record_SPF(b"v=spf1 +mx a:\0colo",
                           b".example.com/28 -all not valid"),
            dns.Record_MX(10, "host.test-domain.com"),
            dns.Record_HINFO(os=b"Linux", cpu=b"A Fast One, Dontcha know"),
            dns.Record_CNAME(b"canonical.name.com"),
            dns.Record_MB(b"mailbox.test-domain.com"),
            dns.Record_MG(b"mail.group.someplace"),
            dns.Record_TXT(b"A First piece of Text", b"a SecoNd piece"),
            dns.Record_A6(0, b"ABCD::4321", b""),
            dns.Record_A6(12, b"0:0069::0", b"some.network.tld"),
            dns.Record_A6(8, b"0:5634:1294:AFCB:56AC:48EF:34C3:01FF",
                          b"tra.la.la.net"),
            dns.Record_TXT(b"Some more text, haha!  Yes.  \0  Still here?"),
            dns.Record_MR(b"mail.redirect.or.whatever"),
            dns.Record_MINFO(rmailbx=b"r mail box", emailbx=b"e mail box"),
            dns.Record_AFSDB(subtype=1, hostname=b"afsdb.test-domain.com"),
            dns.Record_RP(mbox=b"whatever.i.dunno", txt=b"some.more.text"),
            dns.Record_WKS(b"12.54.78.12", socket.IPPROTO_TCP,
                           b"\x12\x01\x16\xfe\xc1\x00\x01"),
Exemplo n.º 7
0
    def __build_answer(self,
                       query,
                       db_zone,
                       db_record,
                       is_conditional_response=False):
        record = None
        # Calculate the query type (in case it's a request for A but a CNAME is returned).
        query_type = REV_TYPES[db_record.type]
        if query_type == dns.A:
            record = dns.Record_A(address=db_record.property(
                'address', conditional=is_conditional_response),
                                  ttl=db_record.ttl)
        elif query_type == dns.AAAA:
            record = dns.Record_AAAA(address=db_record.property(
                'address', conditional=is_conditional_response),
                                     ttl=db_record.ttl)
        elif query_type == dns.AFSDB:
            record = dns.Record_AFSDB(subtype=int(
                db_record.property('subtype',
                                   conditional=is_conditional_response)),
                                      hostname=db_record.property(
                                          'hostname',
                                          conditional=is_conditional_response))
        elif query_type == dns.CNAME:
            record = dns.Record_CNAME(name=db_record.property(
                'name', conditional=is_conditional_response),
                                      ttl=db_record.ttl)
        elif query_type == dns.DNAME:
            record = dns.Record_DNAME(name=db_record.property(
                'name', conditional=is_conditional_response),
                                      ttl=db_record.ttl)
        elif query_type == dns.HINFO:
            record = dns.Record_HINFO(
                cpu=db_record.property(
                    'cpu', conditional=is_conditional_response).encode(),
                os=db_record.property(
                    'os', conditional=is_conditional_response).encode())
        elif query_type == dns.MX:
            record = dns.Record_MX(preference=int(
                db_record.property('preference',
                                   conditional=is_conditional_response)),
                                   name=db_record.property(
                                       'name',
                                       conditional=is_conditional_response))
        elif query_type == dns.NAPTR:
            record = dns.Record_NAPTR(
                order=int(
                    db_record.property('order',
                                       conditional=is_conditional_response)),
                preference=int(
                    db_record.property('preference',
                                       conditional=is_conditional_response)),
                flags=db_record.property(
                    'flags', conditional=is_conditional_response).encode(),
                service=db_record.property(
                    'service', conditional=is_conditional_response).encode(),
                regexp=db_record.property(
                    'regexp', conditional=is_conditional_response).encode(),
                replacement=db_record.property(
                    'replacement', conditional=is_conditional_response))
        elif query_type == dns.NS:
            record = dns.Record_NS(name=db_record.property(
                'name', conditional=is_conditional_response),
                                   ttl=db_record.ttl)
        elif query_type == dns.PTR:
            record = dns.Record_PTR(name=db_record.property(
                'name', conditional=is_conditional_response),
                                    ttl=db_record.ttl)
        elif query_type == dns.RP:
            record = dns.Record_RP(
                mbox=db_record.property('mbox',
                                        conditional=is_conditional_response),
                txt=db_record.property('txt',
                                       conditional=is_conditional_response))
        elif query_type == dns.SOA:
            record = dns.Record_SOA(
                mname=db_record.property('mname',
                                         conditional=is_conditional_response),
                rname=db_record.property('rname',
                                         conditional=is_conditional_response),
                serial=int(
                    db_record.property('serial',
                                       conditional=is_conditional_response)),
                refresh=int(
                    db_record.property('refresh',
                                       conditional=is_conditional_response)),
                retry=int(
                    db_record.property('retry',
                                       conditional=is_conditional_response)),
                expire=int(
                    db_record.property('expire',
                                       conditional=is_conditional_response)),
                minimum=int(
                    db_record.property('minimum',
                                       conditional=is_conditional_response)))
        elif query_type == dns.SPF:
            record = dns.Record_SPF(
                db_record.property(
                    'data', conditional=is_conditional_response).encode())
        elif query_type == dns.SRV:
            record = dns.Record_SRV(
                priority=int(
                    db_record.property('priority',
                                       conditional=is_conditional_response)),
                port=int(
                    db_record.property('port',
                                       conditional=is_conditional_response)),
                weight=int(
                    db_record.property('weight',
                                       conditional=is_conditional_response)),
                target=db_record.property('target',
                                          conditional=is_conditional_response))
        elif query_type == dns.SSHFP:
            record = dns.Record_SSHFP(
                algorithm=int(
                    db_record.property('algorithm',
                                       conditional=is_conditional_response)),
                fingerprintType=int(
                    db_record.property('fingerprint_type',
                                       conditional=is_conditional_response)),
                fingerprint=db_record.property(
                    'fingerprint',
                    conditional=is_conditional_response).encode())
        elif query_type == dns.TSIG:
            record = dns.Record_TSIG(
                algorithm=db_record.property(
                    'algorithm', conditional=is_conditional_response).encode(),
                timeSigned=int(
                    db_record.property('timesigned',
                                       conditional=is_conditional_response)),
                fudge=int(
                    db_record.property('fudge',
                                       conditional=is_conditional_response)),
                originalID=int(
                    db_record.property('original_id',
                                       conditional=is_conditional_response)),
                MAC=db_record.property(
                    'mac', conditional=is_conditional_response).encode(),
                otherData=db_record.property(
                    'other_data',
                    conditional=is_conditional_response).encode())
        elif query_type == dns.TXT:
            record = dns.Record_TXT(
                db_record.property(
                    'data', conditional=is_conditional_response).encode())
        else:
            pass

        if not record:
            return None

        answer = dns.RRHeader(name=query.name.name,
                              type=query_type,
                              cls=query.cls,
                              ttl=db_record.ttl,
                              payload=record)
        return answer