diff options
| author | Brian Wellington <bwelling@xbill.org> | 2020-07-08 15:11:19 -0700 |
|---|---|---|
| committer | Brian Wellington <bwelling@xbill.org> | 2020-07-08 15:15:31 -0700 |
| commit | 7a5e59707b395454db2cb650371bbc2e800e7be4 (patch) | |
| tree | bc49dbae99179d3afee50e6e25f9ecb80800adc7 /tests/test_query.py | |
| parent | cce293110167a2e8e20fdf6cdf2d15b0b9ca6679 (diff) | |
| download | dnspython-7a5e59707b395454db2cb650371bbc2e800e7be4.tar.gz | |
Add support for receiving UDP queries.
The existing receive_udp() methods are only usable for receiving
responses, as they require an expected destination and check that the
message is from that destination.
This change makes the expected destination (and hence the check)
optional, and returns the address that the message was received from (in
the sync case, this is only done if no destination is provided, for
backwards compatibility).
New tests are added, which required adding generic getsockname() support
to the async backends.
Diffstat (limited to 'tests/test_query.py')
| -rw-r--r-- | tests/test_query.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/test_query.py b/tests/test_query.py index f1ec55c..498128d 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -191,6 +191,18 @@ class QueryTests(unittest.TestCase): (_, tcp) = dns.query.udp_with_fallback(q, address) self.assertFalse(tcp) + def testUDPReceiveQuery(self): + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as listener: + listener.bind(('127.0.0.1', 0)) + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sender: + sender.bind(('127.0.0.1', 0)) + q = dns.message.make_query('dns.google', dns.rdatatype.A) + dns.query.send_udp(sender, q, listener.getsockname()) + expiration = time.time() + 2 + (q, _, addr) = dns.query.receive_udp(listener, + expiration=expiration) + self.assertEqual(addr, sender.getsockname()) + # for brevity _d_and_s = dns.query._destination_and_source |
