Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve AXFR host if DNS name is supplied #22

Merged
merged 1 commit into from
May 14, 2023
Merged

Resolve AXFR host if DNS name is supplied #22

merged 1 commit into from
May 14, 2023

Conversation

yzguy
Copy link
Contributor

@yzguy yzguy commented May 12, 2023

Addresses #18

In our documentation we reference using a DNS name, which actually was not functional and wildly it never came up until recently. dnspython's dns.query.xfr and dns.query.tcp expect an IP address to perform actions against otherwise it will error, it does not handle resolving it on it's own.

This change adds a quick check to see if the host supplied by the user is an IPv4/IPv6 addresses or a DNS name, and if a DNS name is supplied it will resolve it to an IP to be passed off to dns.query.xfr and dns.query.tcp

Probably after #5 and this are merged will cut a new release

@yzguy yzguy requested a review from a team May 12, 2023 18:17
try:
h = dns.resolver.resolve(host)[0].address
except DNSException as err:
raise AxfrSourceZoneTransferFailed(err) from None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Hadn't run across the from None thing before.

Copy link
Contributor Author

@yzguy yzguy May 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the relevant thing I found for it https://stackoverflow.com/questions/52725278/during-handling-of-the-above-exception-another-exception-occurred

In this case the checking of the IP address calls like inet.aton which throws a SyntaxError, which then I think isn’t caught or something, but then the calling method throws a ValueError. You end up doing from None to silence the “inner” exceptions (SyntaxError) for the outer one (ValueError)

Other cool thing I found was autospec https://docs.python.org/3/library/unittest.mock.html#auto-speccing
Didn’t end up using it but played around with it figuring out the tests for this.

@yzguy yzguy merged commit 8e88301 into main May 14, 2023
5 checks passed
@yzguy yzguy deleted the dns_lookup branch May 14, 2023 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants