[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Avoiding use of sign_descriptor_content()
commit 98cb69522254ddfd7bdd3c8df3b0dc7020c8e0a3
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Wed Mar 20 17:34:07 2013 -0700
Avoiding use of sign_descriptor_content()
The test.mocking.sign_descriptor_content() function is slow. When the user has
pycrypto the runtime of our unit tests jump from 17 to 83 seconds.
This is a no-go since it discourages the use of our tests (our unit tests were
already taking too long imho before this jump). By dropping
sign_descriptor_content() the digest validation checks fail, so mocking those
out.
---
stem/descriptor/server_descriptor.py | 8 +++++---
test/mocking.py | 7 +++++--
test/unit/descriptor/export.py | 14 +++++++++++++-
test/unit/descriptor/server_descriptor.py | 16 +++++++++++-----
test/unit/tutorial.py | 2 ++
5 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 362437f..103ba8b 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -688,9 +688,11 @@ class RelayDescriptor(ServerDescriptor):
log.warn("Signing key hash: %s != fingerprint: %s" % (key_der_as_hash, self.fingerprint.lower()))
raise ValueError("Fingerprint does not match hash")
- self._verify_descriptor(key_as_bytes)
+ self._verify_digest(key_as_bytes)
+
+ def _verify_digest(self, key_as_der):
+ # check that our digest matches what was signed
- def _verify_descriptor(self, key_as_der):
if not stem.prereq.is_crypto_available():
return
@@ -738,7 +740,7 @@ class RelayDescriptor(ServerDescriptor):
if decrypted_bytes.index('\x00\x01') != 0:
raise ValueError("Verification failed, identifier missing")
except ValueError:
- raise ValueError("Verification failed, Malformed data")
+ raise ValueError("Verification failed, malformed data")
try:
identifier_offset = 2
diff --git a/test/mocking.py b/test/mocking.py
index 2a19b83..beaa354 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -643,7 +643,7 @@ def _get_descriptor_content(attr = None, exclude = (), header_template = (), foo
return "\n".join(header_content + remainder + footer_content)
-def get_relay_server_descriptor(attr = None, exclude = (), content = False):
+def get_relay_server_descriptor(attr = None, exclude = (), content = False, sign_content = False):
"""
Provides the descriptor content for...
stem.descriptor.server_descriptor.RelayDescriptor
@@ -651,6 +651,7 @@ def get_relay_server_descriptor(attr = None, exclude = (), content = False):
:param dict attr: keyword/value mappings to be included in the descriptor
:param list exclude: mandatory keywords to exclude from the descriptor
:param bool content: provides the str content of the descriptor rather than the class if True
+ :param bool sign_content: sets a proper digest value if True
:returns: RelayDescriptor for the requested descriptor content
"""
@@ -660,7 +661,9 @@ def get_relay_server_descriptor(attr = None, exclude = (), content = False):
if content:
return desc_content
else:
- desc_content = sign_descriptor_content(desc_content)
+ if sign_content:
+ desc_content = sign_descriptor_content(desc_content)
+
return stem.descriptor.server_descriptor.RelayDescriptor(desc_content, validate = True)
diff --git a/test/unit/descriptor/export.py b/test/unit/descriptor/export.py
index ce98f06..14eb156 100644
--- a/test/unit/descriptor/export.py
+++ b/test/unit/descriptor/export.py
@@ -9,10 +9,22 @@ import stem.prereq
import test.runner
from stem.descriptor.export import export_csv, export_csv_file
-from test.mocking import get_relay_server_descriptor, get_bridge_server_descriptor
+from stem.descriptor.server_descriptor import RelayDescriptor
+
+from test.mocking import no_op, \
+ mock_method, \
+ revert_mocking, \
+ get_relay_server_descriptor, \
+ get_bridge_server_descriptor
class TestExport(unittest.TestCase):
+ def setUp(self):
+ mock_method(RelayDescriptor, '_verify_digest', no_op())
+
+ def tearDown(self):
+ revert_mocking()
+
def test_minimal_descriptor(self):
"""
Exports a single minimal tor server descriptor.
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index ad62444..e62e614 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -13,13 +13,21 @@ import stem.util.str_tools
from stem.descriptor.server_descriptor import RelayDescriptor, BridgeDescriptor
-from test.mocking import get_relay_server_descriptor, \
+from test.mocking import no_op, \
+ mock_method, \
+ revert_mocking, \
+ get_relay_server_descriptor, \
get_bridge_server_descriptor, \
- CRYPTO_BLOB, \
- sign_descriptor_content
+ CRYPTO_BLOB
class TestServerDescriptor(unittest.TestCase):
+ def setUp(self):
+ mock_method(RelayDescriptor, '_verify_digest', no_op())
+
+ def tearDown(self):
+ revert_mocking()
+
def test_minimal_relay_descriptor(self):
"""
Basic sanity check that we can parse a relay server descriptor with minimal
@@ -153,7 +161,6 @@ class TestServerDescriptor(unittest.TestCase):
self._expect_invalid_attr(desc_text, "published")
desc_text = get_relay_server_descriptor({"published": "2012-02-29 04:03:19"}, content = True)
- desc_text = sign_descriptor_content(desc_text)
expected_published = datetime.datetime(2012, 2, 29, 4, 3, 19)
self.assertEquals(expected_published, RelayDescriptor(desc_text).published)
@@ -206,7 +213,6 @@ class TestServerDescriptor(unittest.TestCase):
desc_text = "@pepperjack very tasty\n@mushrooms not so much\n"
desc_text += get_relay_server_descriptor(content = True)
- desc_text = sign_descriptor_content(desc_text)
desc_text += "\ntrailing text that should be ignored, ho hum"
# running _parse_file should provide an iterator with a single descriptor
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py
index d557fa0..c421cd7 100644
--- a/test/unit/tutorial.py
+++ b/test/unit/tutorial.py
@@ -28,6 +28,8 @@ class TestTutorial(unittest.TestCase):
self.stdout, self.stdout_real = StringIO.StringIO(), sys.stdout
sys.stdout = self.stdout
+ mocking.mock_method(RelayDescriptor, '_verify_digest', mocking.no_op())
+
def tearDown(self):
mocking.revert_mocking()
sys.stdout = self.stdout_real
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits