From a7dda9c341506e295b6781860adf9b5dc5fc2102 Mon Sep 17 00:00:00 2001 From: Graham Hayes Date: Wed, 1 Feb 2017 00:19:43 +0000 Subject: [PATCH] Do not send DNS queries against hostnames the `dns.query` API takes an IP address. This ensures the `host` is always an IP Change-Id: Id9601173e68bab3b6b245215f82b02a6492670cd Closes-Bug: #1623949 --- designate/mdns/notify.py | 7 ++++++- designate/tests/unit/test_mdns/test_notify.py | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/designate/mdns/notify.py b/designate/mdns/notify.py index b7c3632ea..ed842e6d8 100644 --- a/designate/mdns/notify.py +++ b/designate/mdns/notify.py @@ -309,4 +309,9 @@ class NotifyEndpoint(base.BaseEndpoint): :return: response """ send = dns_query.tcp if CONF['service:mdns'].all_tcp else dns_query.udp - return send(dns_message, host, port=port, timeout=timeout) + return send( + dns_message, + socket.gethostbyname(host), + port=port, + timeout=timeout + ) diff --git a/designate/tests/unit/test_mdns/test_notify.py b/designate/tests/unit/test_mdns/test_notify.py index e61dc4725..e9c81a558 100644 --- a/designate/tests/unit/test_mdns/test_notify.py +++ b/designate/tests/unit/test_mdns/test_notify.py @@ -266,9 +266,9 @@ class MdnsNotifyTest(base.BaseTestCase): @mock.patch.object(notify.dns_query, 'tcp') @mock.patch.object(notify.dns_query, 'udp') def test_send_dns_message(self, *mocks): - out = self.notify._send_dns_message('msg', 'host', 123, 1) + out = self.notify._send_dns_message('msg', '192.0.2.1', 1234, 1) assert not notify.dns_query.tcp.called - notify.dns_query.udp.assert_called_with('msg', 'host', port=123, + notify.dns_query.udp.assert_called_with('msg', '192.0.2.1', port=1234, timeout=1) assert isinstance(out, Mock)