Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_query_timeout(self):
self.resolver = aiodns.DNSResolver(timeout=0.1, loop=self.loop)
self.resolver.nameservers = ['1.2.3.4']
f = self.resolver.query('google.com', 'A')
try:
self.loop.run_until_complete(f)
except aiodns.error.DNSError as e:
self.assertEqual(e.args[0], aiodns.error.ARES_ETIMEOUT)
async def resolve(self, domain, last_known_id=None):
if domain.startswith('.'):
return STSFetchResult.NONE, None
# Cleanup domain name
domain = domain.rstrip('.')
# Construct name of corresponding MTA-STS DNS record for domain
sts_txt_domain = '_mta-sts.' + domain
# Try to fetch it
try:
txt_records = await asyncio.wait_for(
self._resolver.query(sts_txt_domain, 'TXT'),
timeout=self._timeout)
except aiodns.error.DNSError as error:
if error.args[0] == aiodns.error.ARES_ETIMEOUT: # pragma: no cover pylint: disable=no-else-return,no-member
# This branch is not covered because of aiodns bug:
# https://github.com/saghul/aiodns/pull/64
# It's hard to decide what to do in case of timeout
# Probably it's better to threat this as fetch error
# so caller probably shall report such cases.
return STSFetchResult.FETCH_ERROR, None
elif error.args[0] == aiodns.error.ARES_ENOTFOUND: # pylint: disable=no-else-return,no-member
return STSFetchResult.NONE, None
elif error.args[0] == aiodns.error.ARES_ENODATA: # pylint: disable=no-else-return,no-member
return STSFetchResult.NONE, None
else: # pragma: no cover
return STSFetchResult.NONE, None
except asyncio.TimeoutError:
return STSFetchResult.FETCH_ERROR, None
# workaround for floating return type of pycares