def test_dispatch_opcode_notify_different_serial(self, func): # DNS packet with NOTIFY opcode payload = "c38021000001000000000000076578616d706c6503636f6d0000060001" master = "10.0.0.1" domain = self._get_secondary_domain({"serial": 123}) domain.attributes.append( objects.DomainAttribute(**{ "key": "master", "value": master })) # expected response is an error code NOERROR. The other fields are # id 50048 # opcode NOTIFY # rcode NOERROR # flags QR AA RD # ;QUESTION # example.com. IN A # ;ANSWER # ;AUTHORITY # ;ADDITIONAL expected_response = ("c380a5000001000000000000076578616d706c6503636f6d" "0000060001") # The SOA serial should be different from the one in thedomain and # will trigger a AXFR func.return_value = self._get_soa_answer(123123) request = dns.message.from_wire(binascii.a2b_hex(payload)) request.environ = {'addr': (master, 53), 'context': self.context} with mock.patch.object(self.handler.storage, 'find_domain', return_value=domain): response = self.handler(request).to_wire() self.mock_tg.add_thread.assert_called_with(self.handler.domain_sync, self.context, domain, [master]) self.assertEqual(expected_response, binascii.b2a_hex(response))
def test_dispatch_opcode_notify_invalid_master(self): # DNS packet with NOTIFY opcode payload = "c38021000001000000000000076578616d706c6503636f6d0000060001" # Have a domain with different master then the one where the notify # comes from causing it to be "ignored" as in not transferred and # logged master = "10.0.0.1" domain = self._get_secondary_domain({"serial": 123}) domain.attributes.append( objects.DomainAttribute(**{ "key": "master", "value": master })) # expected response is an error code REFUSED. The other fields are # id 50048 # opcode NOTIFY # rcode REFUSED # flags QR AA RD # ;QUESTION # example.com. IN SOA # ;ANSWER # ;AUTHORITY # ;ADDITIONAL expected_response = ("c380a1050001000000000000076578616d706c6503636f6d" "0000060001") request = dns.message.from_wire(binascii.a2b_hex(payload)) request.environ = {'addr': ("10.0.0.2", 53), 'context': self.context} with mock.patch.object(self.handler.storage, 'find_domain', return_value=domain): response = self.handler(request).to_wire() assert not self.mock_tg.add_thread.called self.assertEqual(expected_response, binascii.b2a_hex(response))