Esempio n. 1
0
    def test_transfer(self):
        """
        An attempt is made to transfer the zone for the domain the
        L{SecondaryAuthority} was constructed with from the server address it
        was constructed with when L{SecondaryAuthority.transfer} is called.
        """
        secondary = SecondaryAuthority.fromServerAddressAndDomain(
            ('192.168.1.2', 1234), 'example.com')
        secondary._reactor = reactor = MemoryReactorClock()

        secondary.transfer()

        # Verify a connection attempt to the server address above
        host, port, factory, timeout, bindAddress = reactor.tcpClients.pop(0)
        self.assertEqual(host, '192.168.1.2')
        self.assertEqual(port, 1234)

        # See if a zone transfer query is issued.
        proto = factory.buildProtocol((host, port))
        transport = StringTransport()
        proto.makeConnection(transport)

        msg = Message()
        # DNSProtocol.writeMessage length encodes the message by prepending a
        # 2 byte message length to the buffered value.
        msg.decode(StringIO(transport.value()[2:]))

        self.assertEqual(
            [dns.Query('example.com', dns.AXFR, dns.IN)], msg.queries)
Esempio n. 2
0
    def test_transfer(self):
        """
        An attempt is made to transfer the zone for the domain the
        L{SecondaryAuthority} was constructed with from the server address it
        was constructed with when L{SecondaryAuthority.transfer} is called.
        """
        secondary = SecondaryAuthority.fromServerAddressAndDomain(
            ('192.168.1.2', 1234), 'example.com')
        secondary._reactor = reactor = MemoryReactorClock()

        secondary.transfer()

        # Verify a connection attempt to the server address above
        host, port, factory, timeout, bindAddress = reactor.tcpClients.pop(0)
        self.assertEqual(host, '192.168.1.2')
        self.assertEqual(port, 1234)

        # See if a zone transfer query is issued.
        proto = factory.buildProtocol((host, port))
        transport = StringTransport()
        proto.makeConnection(transport)

        msg = Message()
        # DNSProtocol.writeMessage length encodes the message by prepending a
        # 2 byte message length to the buffered value.
        msg.decode(StringIO(transport.value()[2:]))

        self.assertEqual([dns.Query('example.com', dns.AXFR, dns.IN)],
                         msg.queries)
Esempio n. 3
0
 def test_defaultPort(self):
     """
     When constructed using L{SecondaryAuthority.__init__}, the default port
     of 53 is used.
     """
     secondary = SecondaryAuthority('192.168.1.1', 'inside.com')
     self.assertEqual(secondary.primary, '192.168.1.1')
     self.assertEqual(secondary._port, 53)
     self.assertEqual(secondary.domain, 'inside.com')
Esempio n. 4
0
 def test_explicitPort(self):
     """
     When constructed using L{SecondaryAuthority.fromServerAddressAndDomain},
     the specified port is used.
     """
     secondary = SecondaryAuthority.fromServerAddressAndDomain(
         ('192.168.1.1', 5353), 'inside.com')
     self.assertEqual(secondary.primary, '192.168.1.1')
     self.assertEqual(secondary._port, 5353)
     self.assertEqual(secondary.domain, 'inside.com')
Esempio n. 5
0
 def test_explicitPort(self):
     """
     When constructed using L{SecondaryAuthority.fromServerAddressAndDomain},
     the specified port is used.
     """
     secondary = SecondaryAuthority.fromServerAddressAndDomain(
         ('192.168.1.1', 5353), 'inside.com')
     self.assertEqual(secondary.primary, '192.168.1.1')
     self.assertEqual(secondary._port, 5353)
     self.assertEqual(secondary.domain, 'inside.com')
    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)
Esempio n. 7
0
    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(
            (b'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(StringIO(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)