Skip to content

Commit

Permalink
Fix issue with long names.
Browse files Browse the repository at this point in the history
This patch touches #162.

Indeed, before this patch, we were not handling long labels correctely.

Contributors:
  * @spirillen
  • Loading branch information
funilrys committed Jan 5, 2021
1 parent b85e3b2 commit 04668ec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 35 additions & 11 deletions PyFunceble/query/dns/query_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ def wrapper(self, *args, **kwargs):
if self.subject and self.query_record_type:
self.dns_name = self.get_dns_name_from_subject_and_query_type()

self.query_message = dns.message.make_query(
self.dns_name, self.query_record_type
)
if self.dns_name:
self.query_message = dns.message.make_query(
self.dns_name, self.query_record_type
)
else:
self.query_message = None

return result

Expand Down Expand Up @@ -229,20 +232,37 @@ def wrapper(self, *args, **kwargs): # pragma: no cover ## Just common sense

return wrapper

def ignore_if_query_message_is_missing(func): # pylint: disable=no-self-argument
"""
Ignores the call to the decorated method if the query message is
missing. Otherwise, return an empty list.
"""

@functools.wraps(func)
def wrapper(self, *args, **kwargs): # pragma: no cover ## Just common sense
if self.query_message:
return func(self, *args, **kwargs) # pylint: disable=not-callable
return []

return wrapper

@ensure_subject_is_given
def get_dns_name_from_subject_and_query_type(self):
"""
Provides the dns name based on the current subject and query type.
"""

if self.get_human_query_record_type().lower() == "ptr":
try:
return dns.name.from_text(
ipaddress.ip_address(self.subject).reverse_pointer
)
except ValueError:
return dns.name.from_text(self.subject)
return dns.name.from_text(self.subject)
try:
if self.get_human_query_record_type().lower() == "ptr":
try:
return dns.name.from_text(
ipaddress.ip_address(self.subject).reverse_pointer
)
except ValueError:
return dns.name.from_text(self.subject)
return dns.name.from_text(self.subject)
except dns.name.LabelTooLong:
return None

@property
def subject(self) -> Optional[str]:
Expand Down Expand Up @@ -590,6 +610,7 @@ def _mix_order(
return dataset

@ensure_subject_is_given
@ignore_if_query_message_is_missing
@update_lookup_record_response
def tcp(
self,
Expand Down Expand Up @@ -647,6 +668,7 @@ def tcp(
return ListHelper(result).remove_duplicates().subject

@ensure_subject_is_given
@ignore_if_query_message_is_missing
@update_lookup_record_response
def udp(
self,
Expand Down Expand Up @@ -704,6 +726,7 @@ def udp(
return ListHelper(result).remove_duplicates().subject

@ensure_subject_is_given
@ignore_if_query_message_is_missing
@update_lookup_record_response
def https(
self,
Expand Down Expand Up @@ -755,6 +778,7 @@ def https(
return ListHelper(result).remove_duplicates().subject

@ensure_subject_is_given
@ignore_if_query_message_is_missing
@update_lookup_record_response
def tls(
self,
Expand Down
2 changes: 1 addition & 1 deletion PyFunceble/query/netinfo/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_info(self) -> Optional[List[str]]:
x[-1][0]
for x in socket.getaddrinfo(self.subject, 80, proto=socket.IPPROTO_TCP)
]
except (socket.gaierror, socket.herror):
except (socket.gaierror, socket.herror, UnicodeError):
pass

return []

0 comments on commit 04668ec

Please sign in to comment.