[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Test introduction point creation
commit 1c3f49c8cf18e2b76bb8768437b2e9c1cd79d1a3
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Nov 8 15:18:07 2019 -0800
Test introduction point creation
I love that test_encode_decode_descriptor() exercises re-parsing a descriptor
we create. Adding a more targeted test to do this only for introduction points.
We can then add companion tests once the InnerLayer and OuterLayer classes have
creation methods.
---
stem/descriptor/hidden_service.py | 12 ++++++++++++
test/unit/descriptor/hidden_service_v3.py | 16 ++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index 1c4f0bdf..5fb7a189 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -379,6 +379,18 @@ class IntroductionPointV3(collections.namedtuple('IntroductionPointV3', ['link_s
return link_specifiers
+ def __hash__(self):
+ if not hasattr(self, '_hash'):
+ self._hash = hash(self.encode())
+
+ return self._hash
+
+ def __eq__(self, other):
+ return hash(self) == hash(other) if isinstance(other, IntroductionPointV3) else False
+
+ def __ne__(self, other):
+ return not self == other
+
class AuthorizedClient(collections.namedtuple('AuthorizedClient', ['id', 'iv', 'cookie'])):
"""
diff --git a/test/unit/descriptor/hidden_service_v3.py b/test/unit/descriptor/hidden_service_v3.py
index d7b32485..163ea3db 100644
--- a/test/unit/descriptor/hidden_service_v3.py
+++ b/test/unit/descriptor/hidden_service_v3.py
@@ -269,6 +269,22 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
self.assertRaisesWith(ImportError, 'cryptography module unavailable', intro_point.onion_key)
@test.require.ed25519_support
+ def test_intro_point_creation(self):
+ """
+ Create an introduction point, encode it, then re-parse.
+ """
+
+ intro_point = IntroductionPointV3.create('1.1.1.1', 9001)
+
+ self.assertEqual(1, len(intro_point.link_specifiers))
+ self.assertEqual(stem.client.datatype.LinkByIPv4, type(intro_point.link_specifiers[0]))
+ self.assertEqual('1.1.1.1', intro_point.link_specifiers[0].address)
+ self.assertEqual(9001, intro_point.link_specifiers[0].port)
+
+ reparsed = IntroductionPointV3.parse(intro_point.encode())
+ self.assertEqual(intro_point, reparsed)
+
+ @test.require.ed25519_support
def test_encode_decode_descriptor(self):
"""
Encode an HSv3 descriptor and then decode it and make sure you get the intended results.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits