Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ def test_dns_record_hashablity_does_not_consider_ttl():
assert len(record_set) == 1


def test_dns_record_hashablity_does_not_consider_unique():
"""Test DNSRecord are hashable and unique is ignored."""

# Verify the unique value is not considered in the hash
record1 = r.DNSAddress(
'irrelevant', const._TYPE_A, const._CLASS_IN | const._CLASS_UNIQUE, const._DNS_OTHER_TTL, b'same'
)
record2 = r.DNSAddress('irrelevant', const._TYPE_A, const._CLASS_IN, const._DNS_OTHER_TTL, b'same')

assert record1.class_ == record2.class_
assert record1.__hash__() == record2.__hash__()
record_set = {record1, record2}
assert len(record_set) == 1


def test_dns_address_record_hashablity():
"""Test DNSAddress are hashable."""
address1 = r.DNSAddress('irrelevant', const._TYPE_A, const._CLASS_IN, 1, b'a')
Expand Down
14 changes: 7 additions & 7 deletions zeroconf/_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DNSQuestion(DNSEntry):

def __init__(self, name: str, type_: int, class_: int) -> None:
super().__init__(name, type_, class_)
self._hash = hash((self.key, type_, class_))
self._hash = hash((self.key, type_, self.class_))

def answered_by(self, rec: 'DNSRecord') -> bool:
"""Returns true if the question is answered by the record"""
Expand Down Expand Up @@ -247,7 +247,7 @@ def __init__(
super().__init__(name, type_, class_, ttl, created)
self.address = address
self.scope_id = scope_id
self._hash = hash((self.key, type_, class_, address, scope_id))
self._hash = hash((self.key, type_, self.class_, address, scope_id))

def write(self, out: 'DNSOutgoing') -> None:
"""Used in constructing an outgoing packet"""
Expand Down Expand Up @@ -290,7 +290,7 @@ def __init__(
super().__init__(name, type_, class_, ttl, created)
self.cpu = cpu
self.os = os
self._hash = hash((self.key, type_, class_, cpu, os))
self._hash = hash((self.key, type_, self.class_, cpu, os))

def write(self, out: 'DNSOutgoing') -> None:
"""Used in constructing an outgoing packet"""
Expand Down Expand Up @@ -326,7 +326,7 @@ def __init__(
) -> None:
super().__init__(name, type_, class_, ttl, created)
self.alias = alias
self._hash = hash((self.key, type_, class_, alias))
self._hash = hash((self.key, type_, self.class_, alias))

@property
def max_size_compressed(self) -> int:
Expand Down Expand Up @@ -367,7 +367,7 @@ def __init__(
assert isinstance(text, (bytes, type(None)))
super().__init__(name, type_, class_, ttl, created)
self.text = text
self._hash = hash((self.key, type_, class_, text))
self._hash = hash((self.key, type_, self.class_, text))

def write(self, out: 'DNSOutgoing') -> None:
"""Used in constructing an outgoing packet"""
Expand Down Expand Up @@ -411,7 +411,7 @@ def __init__(
self.weight = weight
self.port = port
self.server = server
self._hash = hash((self.key, type_, class_, priority, weight, port, server))
self._hash = hash((self.key, type_, self.class_, priority, weight, port, server))

def write(self, out: 'DNSOutgoing') -> None:
"""Used in constructing an outgoing packet"""
Expand Down Expand Up @@ -459,7 +459,7 @@ def __init__(
super().__init__(name, type_, class_, ttl, created)
self.next_name = next_name
self.rdtypes = rdtypes
self._hash = hash((self.key, type_, class_, next_name, *self.rdtypes))
self._hash = hash((self.key, type_, self.class_, next_name, *self.rdtypes))

def __eq__(self, other: Any) -> bool:
"""Tests equality on cpu and os"""
Expand Down