[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Passing unit tests



commit 419a2938c1d313491401b48de2697a5a8ca5c5a4
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Sep 5 12:42:39 2019 -0700

    Passing unit tests
    
    Fix remaining test failures so unit tests once again pass. Stylistic checks
    still report issues so that's next.
---
 stem/descriptor/hidden_service.py         | 12 ++++++------
 test/unit/descriptor/__init__.py          |  8 +++++++-
 test/unit/descriptor/hidden_service_v3.py |  7 ++++++-
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/hidden_service.py b/stem/descriptor/hidden_service.py
index 1c51b7b2..9e6de0d9 100644
--- a/stem/descriptor/hidden_service.py
+++ b/stem/descriptor/hidden_service.py
@@ -554,12 +554,6 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
     else:
       self._entries = entries
 
-    # ATAGAR XXX need to do this cert extraction in the parsing handler
-    assert(self.signing_cert)
-    cert_lines = self.signing_cert.split('\n')
-    assert(cert_lines[0] == '-----BEGIN ED25519 CERT-----' and cert_lines[-1] == '-----END ED25519 CERT-----')
-    desc_signing_cert = stem.descriptor.certificate.Ed25519Certificate.parse(''.join(cert_lines[1:-1]))
-
     # crypto validation (check skip_crypto_validation)
     # ASN XXX need to verify descriptor signing certificate (for now we trust Tor to do it)
     # ASN XXX need to verify descriptor signature (for now we trust Tor to do it)
@@ -568,6 +562,12 @@ class HiddenServiceDescriptorV3(BaseHiddenServiceDescriptor):
       if self.onion_address is None:
         raise ValueError("Onion address is required to decrypt v3 hidden service descriptors")
 
+      # ATAGAR XXX need to do this cert extraction in the parsing handler
+      assert(self.signing_cert)
+      cert_lines = self.signing_cert.split('\n')
+      assert(cert_lines[0] == '-----BEGIN ED25519 CERT-----' and cert_lines[-1] == '-----END ED25519 CERT-----')
+
+      desc_signing_cert = stem.descriptor.certificate.Ed25519Certificate.parse(''.join(cert_lines[1:-1]))
       plaintext = self.decrypt_descriptor(desc_signing_cert)
 
   def decrypt_descriptor(self, desc_signing_cert):
diff --git a/test/unit/descriptor/__init__.py b/test/unit/descriptor/__init__.py
index 867ed0a4..268e61e4 100644
--- a/test/unit/descriptor/__init__.py
+++ b/test/unit/descriptor/__init__.py
@@ -4,6 +4,8 @@ Unit tests for stem.descriptor.
 
 import os
 
+import stem.descriptor.hidden_service
+
 __all__ = [
   'bandwidth_file',
   'collector',
@@ -49,7 +51,11 @@ def base_expect_invalid_attr_for_text(cls, default_attr, default_prefix, test, d
   """
 
   test.assertRaises(ValueError, cls, desc_text, True)
-  desc = cls(desc_text, validate = False)
+
+  if cls == stem.descriptor.hidden_service.HiddenServiceDescriptorV3:
+    desc = cls(desc_text, validate = False, skip_crypto_validation = True)
+  else:
+    desc = cls(desc_text, validate = False)
 
   if attr:
     # check that the invalid attribute matches the expected value when
diff --git a/test/unit/descriptor/hidden_service_v3.py b/test/unit/descriptor/hidden_service_v3.py
index 97763a39..f4c42008 100644
--- a/test/unit/descriptor/hidden_service_v3.py
+++ b/test/unit/descriptor/hidden_service_v3.py
@@ -6,6 +6,7 @@ import functools
 import unittest
 
 import stem.descriptor
+import stem.prereq
 
 from stem.descriptor.hidden_service import (
   REQUIRED_V3_FIELDS,
@@ -38,6 +39,10 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
       sltib6sxkuxh2scmtuvd5w2g7pahnzkovefxpo4e4ptnkzl5kkq5h2ad.onion
     """
 
+    if not stem.prereq.is_crypto_available(ed25519 = True):
+      self.skipTest('(requires cryptography ed25519 support)')  # TODO: note version here
+      return
+
     with open(get_resource('hidden_service_v3_test'), 'rb') as descriptor_file:
       desc = next(stem.descriptor.parse_file(descriptor_file, 'hidden-service-descriptor-3 1.0', validate = True,
                   onion_address="sltib6sxkuxh2scmtuvd5w2g7pahnzkovefxpo4e4ptnkzl5kkq5h2ad.onion"))
@@ -54,7 +59,7 @@ class TestHiddenServiceDescriptorV3(unittest.TestCase):
     """
 
     with open(get_resource('hidden_service_v3'), 'rb') as descriptor_file:
-      desc = next(stem.descriptor.parse_file(descriptor_file, 'hidden-service-descriptor-3 1.0', validate = True))
+      desc = next(stem.descriptor.parse_file(descriptor_file, 'hidden-service-descriptor-3 1.0', validate = True, skip_crypto_validation = True))
 
     self.assertEqual(3, desc.version)
     self.assertEqual(180, desc.lifetime)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits