def create_soa(self): # Maybe allow these to be changed? soa_rec = Record_SOA(mname='localhost', rname='root.localhost', serial=1, refresh="1H", retry="1H", expire="1H", minimum="1") self.soa = [self.domain.lower(), soa_rec]
def test_lookupAddress(self): """ L{SecondaryAuthority.lookupAddress} returns a L{Deferred} that fires with the I{A} records the authority has cached from the primary. """ secondary = SecondaryAuthority.fromServerAddressAndDomain( ("192.168.1.2", 1234), b"example.com") secondary._reactor = reactor = MemoryReactorClock() secondary.transfer() host, port, factory, timeout, bindAddress = reactor.tcpClients.pop(0) proto = factory.buildProtocol((host, port)) transport = StringTransport() proto.makeConnection(transport) query = Message(answer=1, auth=1) query.decode(BytesIO(transport.value()[2:])) # Generate a response with some data we can check. soa = Record_SOA( mname=b"ns1.example.com", rname="admin.example.com", serial=123456, refresh=3600, minimum=4800, expire=7200, retry=9600, ttl=12000, ) a = Record_A(b"192.168.1.2", ttl=0) answer = Message(id=query.id, answer=1, auth=1) answer.answers.extend([ RRHeader(b"example.com", type=SOA, payload=soa), RRHeader(b"example.com", payload=a), RRHeader(b"example.com", type=SOA, payload=soa), ]) data = answer.toStr() proto.dataReceived(pack("!H", len(data)) + data) result = self.successResultOf(secondary.lookupAddress("example.com")) self.assertEqual( ([RRHeader(b"example.com", payload=a, auth=True)], [], []), result)
def make_soa_result(self, serial): return RRHeader(type=SOA, cls=A, ttl=30, payload=Record_SOA(serial=serial))
@ensure_returns_deferred async def lookupAllRecords(self, name, timeout=None): query = Query(name, type=ALL_RECORDS) answers = await self.callback(query) return answers, [], [] SOA_OBJ = RRHeader(name='lo0.wtf', type=SOA, ttl=60, payload=Record_SOA( mname='lo0-ns1.leigh.party', rname='l.leigh.net.au', serial=int(time() / 10), refresh=60, retry=60, expire=60, minimum=60, )) async def get_response(query: Query): name = query.name.name if name.endswith(b'.'): name = name[:-1] if not name.endswith(b'.lo0.wtf'): raise DomainError() results = [] if query.type in (AAAA, ALL_RECORDS): name = name[:-8] vhost, username = name.rsplit(b'.', 1) vhost_hash = CityHash32(vhost)