|
21 | 21 | TYPES,
|
22 | 22 | DnsCnameChainTooLong,
|
23 | 23 | DnsError,
|
| 24 | + DnsNoMatchingAnswers, |
24 | 25 | DnsRecordDoesNotExist,
|
25 | 26 | DnsSocketError,
|
26 | 27 | DnsTimeout,
|
@@ -1772,6 +1773,18 @@ async def test_localhost_aaaa(self):
|
1772 | 1773 | self.assertEqual(str(res[0]), '::1')
|
1773 | 1774 | self.assertEqual(res[0].expires_at, loop.time())
|
1774 | 1775 |
|
| 1776 | + @async_test |
| 1777 | + async def test_root_servers_queries(self): |
| 1778 | + # Upstream DNS server should return NOERROR status with an empty `A` records set. |
| 1779 | + # The default Github's does not do this, so we need to switch to Google's server. |
| 1780 | + self.addCleanup(patch_open(upstream_ip='8.8.8.8')) |
| 1781 | + |
| 1782 | + resolve, _ = Resolver() |
| 1783 | + with self.assertRaises(DnsNoMatchingAnswers): |
| 1784 | + await resolve('', TYPES.A) |
| 1785 | + with self.assertRaises(DnsNoMatchingAnswers): |
| 1786 | + await resolve('root-servers.net', TYPES.A) |
| 1787 | + |
1775 | 1788 |
|
1776 | 1789 | class TestMemoizedMutex(unittest.TestCase):
|
1777 | 1790 | @async_test
|
@@ -1808,11 +1821,11 @@ async def func():
|
1808 | 1821 | self.assertEqual(await task3, 42)
|
1809 | 1822 |
|
1810 | 1823 |
|
1811 |
| -def patch_open(): |
| 1824 | +def patch_open(upstream_ip='127.0.0.1'): |
1812 | 1825 | def mock_open(file_name, _):
|
1813 | 1826 | lines = \
|
1814 |
| - ['127.0.0.1 localhost'] if file_name == '/etc/hosts' else \ |
1815 |
| - ['nameserver 127.0.0.1'] |
| 1827 | + [f'{upstream_ip} localhost'] if file_name == '/etc/hosts' else \ |
| 1828 | + [f'nameserver {upstream_ip}'] |
1816 | 1829 |
|
1817 | 1830 | context_manager = MagicMock()
|
1818 | 1831 | context_manager.__enter__.return_value = lines
|
|
0 commit comments