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

[tor-commits] [stem/master] Don't validate descriptors by default



commit 4dfe010b3965435aa283c4f5b1f8d9ccce3d3e8a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Jan 25 14:36:22 2015 -0800

    Don't validate descriptors by default
    
    Not quite keeping with backward compatability, but what most users want.
    
    When parsing descriptors validation is now opt-in rather than opt-out. With our
    recent change to lazy load this is much quicker. This change also helped me
    catch a few lazy-loading bugs.
---
 stem/descriptor/__init__.py                        |    2 +-
 stem/descriptor/extrainfo_descriptor.py            |    4 +-
 stem/descriptor/microdescriptor.py                 |    4 +-
 stem/descriptor/networkstatus.py                   |   20 ++++----
 stem/descriptor/reader.py                          |    2 +-
 stem/descriptor/remote.py                          |    2 +-
 stem/descriptor/router_status_entry.py             |    2 +-
 stem/descriptor/server_descriptor.py               |   10 ++--
 stem/descriptor/tordnsel.py                        |    2 +-
 test/integ/descriptor/extrainfo_descriptor.py      |    2 +-
 test/integ/descriptor/microdescriptor.py           |    2 +-
 test/integ/descriptor/networkstatus.py             |    4 +-
 test/integ/descriptor/remote.py                    |   11 ++--
 test/integ/descriptor/server_descriptor.py         |    2 +-
 test/unit/descriptor/extrainfo_descriptor.py       |    6 +--
 test/unit/descriptor/microdescriptor.py            |    4 +-
 .../networkstatus/directory_authority.py           |   20 ++++----
 test/unit/descriptor/networkstatus/document_v3.py  |   54 ++++++++++----------
 .../descriptor/networkstatus/key_certificate.py    |   18 +++----
 test/unit/descriptor/remote.py                     |    4 ++
 test/unit/descriptor/router_status_entry.py        |    8 +--
 test/unit/descriptor/server_descriptor.py          |   24 ++++-----
 test/unit/descriptor/tordnsel.py                   |    6 +--
 23 files changed, 109 insertions(+), 104 deletions(-)

diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 0d2295d..c368a38 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -82,7 +82,7 @@ DocumentHandler = stem.util.enum.UppercaseEnum(
 )
 
 
-def parse_file(descriptor_file, descriptor_type = None, validate = True, document_handler = DocumentHandler.ENTRIES, **kwargs):
+def parse_file(descriptor_file, descriptor_type = None, validate = False, document_handler = DocumentHandler.ENTRIES, **kwargs):
   """
   Simple function to read the descriptor contents from a file, providing an
   iterator for its :class:`~stem.descriptor.__init__.Descriptor` contents.
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 5b0339c..9b76f19 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -159,7 +159,7 @@ _timestamp_re = re.compile('^(.*) \(([0-9]+) s\)( .*)?$')
 _locale_re = re.compile('^[a-zA-Z0-9\?]{2}$')
 
 
-def _parse_file(descriptor_file, is_bridge = False, validate = True, **kwargs):
+def _parse_file(descriptor_file, is_bridge = False, validate = False, **kwargs):
   """
   Iterates over the extra-info descriptors in a file.
 
@@ -767,7 +767,7 @@ class ExtraInfoDescriptor(Descriptor):
     'bridge-ip-transports': _parse_bridge_ip_transports_line,
   }
 
-  def __init__(self, raw_contents, validate = True):
+  def __init__(self, raw_contents, validate = False):
     """
     Extra-info descriptor constructor. By default this validates the
     descriptor's content as it's parsed. This validation can be disabled to
diff --git a/stem/descriptor/microdescriptor.py b/stem/descriptor/microdescriptor.py
index c9389e4..1c767c7 100644
--- a/stem/descriptor/microdescriptor.py
+++ b/stem/descriptor/microdescriptor.py
@@ -101,7 +101,7 @@ SINGLE_FIELDS = (
 )
 
 
-def _parse_file(descriptor_file, validate = True, **kwargs):
+def _parse_file(descriptor_file, validate = False, **kwargs):
   """
   Iterates over the microdescriptors in a file.
 
@@ -220,7 +220,7 @@ class Microdescriptor(Descriptor):
     'id': _parse_id_line,
   }
 
-  def __init__(self, raw_contents, validate = True, annotations = None):
+  def __init__(self, raw_contents, validate = False, annotations = None):
     super(Microdescriptor, self).__init__(raw_contents, lazy_load = not validate)
     self._annotation_lines = annotations if annotations else []
     entries = _get_descriptor_components(raw_contents, validate)
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index feb8b37..df55ab8 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -191,7 +191,7 @@ PARAM_RANGE = {
 }
 
 
-def _parse_file(document_file, document_type = None, validate = True, is_microdescriptor = False, document_handler = DocumentHandler.ENTRIES, **kwargs):
+def _parse_file(document_file, document_type = None, validate = False, is_microdescriptor = False, document_handler = DocumentHandler.ENTRIES, **kwargs):
   """
   Parses a network status and iterates over the RouterStatusEntry in it. The
   document that these instances reference have an empty 'routers' attribute to
@@ -267,7 +267,7 @@ def _parse_file(document_file, document_type = None, validate = True, is_microde
     raise ValueError('Unrecognized document_handler: %s' % document_handler)
 
 
-def _parse_file_key_certs(certificate_file, validate = True):
+def _parse_file_key_certs(certificate_file, validate = False):
   """
   Parses a file containing one or more authority key certificates.
 
@@ -409,7 +409,7 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
     'directory-signature': _parse_directory_signature_line,
   }
 
-  def __init__(self, raw_content, validate = True):
+  def __init__(self, raw_content, validate = False):
     super(NetworkStatusDocumentV2, self).__init__(raw_content, lazy_load = not validate)
 
     # Splitting the document from the routers. Unlike v3 documents we're not
@@ -593,8 +593,8 @@ def _parse_header_parameters_line(descriptor, entries):
   # Int32 ::= A decimal integer between -2147483648 and 2147483647.
   # Parameters ::= Parameter | Parameters SP Parameter
 
-  if descriptor._lazy_loading and descriptor._default_params:
-    descriptor.params = dict(DEFAULT_PARAMS)
+  if descriptor._lazy_loading:
+    descriptor.params = dict(DEFAULT_PARAMS) if descriptor._default_params else {}
 
   value = _value('params', entries)
 
@@ -738,7 +738,7 @@ class NetworkStatusDocumentV3(NetworkStatusDocument):
     'directory-signature': _parse_footer_directory_signature_line,
   }
 
-  def __init__(self, raw_content, validate = True, default_params = True):
+  def __init__(self, raw_content, validate = False, default_params = True):
     """
     Parse a v3 network status document.
 
@@ -1094,7 +1094,7 @@ class DirectoryAuthority(Descriptor):
     'vote-digest': _parse_vote_digest_line,
   }
 
-  def __init__(self, raw_content, validate = True, is_vote = False):
+  def __init__(self, raw_content, validate = False, is_vote = False):
     """
     Parse a directory authority entry in a v3 network status document.
 
@@ -1256,7 +1256,7 @@ class KeyCertificate(Descriptor):
     'dir-key-certification': _parse_dir_key_certification_line,
   }
 
-  def __init__(self, raw_content, validate = True):
+  def __init__(self, raw_content, validate = False):
     super(KeyCertificate, self).__init__(raw_content, lazy_load = not validate)
     entries = _get_descriptor_components(raw_content, validate)
 
@@ -1310,7 +1310,7 @@ class DocumentSignature(object):
   :raises: **ValueError** if a validity check fails
   """
 
-  def __init__(self, method, identity, key_digest, signature, validate = True):
+  def __init__(self, method, identity, key_digest, signature, validate = False):
     # Checking that these attributes are valid. Technically the key
     # digest isn't a fingerprint, but it has the same characteristics.
 
@@ -1356,7 +1356,7 @@ class BridgeNetworkStatusDocument(NetworkStatusDocument):
   :var datetime published: time when the document was published
   """
 
-  def __init__(self, raw_content, validate = True):
+  def __init__(self, raw_content, validate = False):
     super(BridgeNetworkStatusDocument, self).__init__(raw_content)
 
     self.published = None
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 4865119..c482670 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -263,7 +263,7 @@ class DescriptorReader(object):
   :param dict kwargs: additional arguments for the descriptor constructor
   """
 
-  def __init__(self, target, validate = True, follow_links = False, buffer_size = 100, persistence_path = None, document_handler = stem.descriptor.DocumentHandler.ENTRIES, **kwargs):
+  def __init__(self, target, validate = False, follow_links = False, buffer_size = 100, persistence_path = None, document_handler = stem.descriptor.DocumentHandler.ENTRIES, **kwargs):
     if isinstance(target, (bytes, str_type)):
       self._targets = [target]
     else:
diff --git a/stem/descriptor/remote.py b/stem/descriptor/remote.py
index 058741f..2f9c1e0 100644
--- a/stem/descriptor/remote.py
+++ b/stem/descriptor/remote.py
@@ -216,7 +216,7 @@ class Query(object):
     the same as running **query.run(True)** (default is **False**)
   """
 
-  def __init__(self, resource, descriptor_type = None, endpoints = None, retries = 2, fall_back_to_authority = False, timeout = None, start = True, block = False, validate = True, document_handler = stem.descriptor.DocumentHandler.ENTRIES, **kwargs):
+  def __init__(self, resource, descriptor_type = None, endpoints = None, retries = 2, fall_back_to_authority = False, timeout = None, start = True, block = False, validate = False, document_handler = stem.descriptor.DocumentHandler.ENTRIES, **kwargs):
     if not resource.startswith('/'):
       raise ValueError("Resources should start with a '/': %s" % resource)
 
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index e0421cd..599e71f 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -386,7 +386,7 @@ class RouterStatusEntry(Descriptor):
     'v': _parse_v_line,
   }
 
-  def __init__(self, content, validate = True, document = None):
+  def __init__(self, content, validate = False, document = None):
     """
     Parse a router descriptor in a network status document.
 
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index afcdac2..0967b65 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -101,7 +101,7 @@ DEFAULT_IPV6_EXIT_POLICY = stem.exit_policy.MicroExitPolicy('reject 1-65535')
 REJECT_ALL_POLICY = stem.exit_policy.ExitPolicy('reject *:*')
 
 
-def _parse_file(descriptor_file, is_bridge = False, validate = True, **kwargs):
+def _parse_file(descriptor_file, is_bridge = False, validate = False, **kwargs):
   """
   Iterates over the server descriptors in a file.
 
@@ -375,8 +375,8 @@ _parse_extrainfo_digest_line = _parse_forty_character_hex('extra-info-digest', '
 _parse_read_history_line = functools.partial(_parse_history_line, 'read-history', 'read_history_end', 'read_history_interval', 'read_history_values')
 _parse_write_history_line = functools.partial(_parse_history_line, 'write-history', 'write_history_end', 'write_history_interval', 'write_history_values')
 _parse_ipv6_policy_line = lambda descriptor, entries: setattr(descriptor, 'exit_policy_v6', stem.exit_policy.MicroExitPolicy(_value('ipv6-policy', entries)))
-_parse_allow_single_hop_exits_line = lambda descriptor, entries: setattr(descriptor, 'allow_single_hop_exits', True)
-_parse_caches_extra_info_line = lambda descriptor, entries: setattr(descriptor, 'extra_info_cache', True)
+_parse_allow_single_hop_exits_line = lambda descriptor, entries: setattr(descriptor, 'allow_single_hop_exits', 'allow_single_hop_exits' in entries)
+_parse_caches_extra_info_line = lambda descriptor, entries: setattr(descriptor, 'extra_info_cache', 'extra_info_cache' in entries)
 _parse_family_line = lambda descriptor, entries: setattr(descriptor, 'family', set(_value('family', entries).split(' ')))
 _parse_eventdns_line = lambda descriptor, entries: setattr(descriptor, 'eventdns', _value('eventdns', entries) == '1')
 _parse_onion_key_line = _parse_key_block('onion-key', 'onion_key', 'RSA PUBLIC KEY')
@@ -501,7 +501,7 @@ class ServerDescriptor(Descriptor):
     'eventdns': _parse_eventdns_line,
   }
 
-  def __init__(self, raw_contents, validate = True, annotations = None):
+  def __init__(self, raw_contents, validate = False, annotations = None):
     """
     Server descriptor constructor, created from an individual relay's
     descriptor content (as provided by 'GETINFO desc/*', cached descriptors,
@@ -667,7 +667,7 @@ class RelayDescriptor(ServerDescriptor):
     'router-signature': _parse_router_signature_line,
   })
 
-  def __init__(self, raw_contents, validate = True, annotations = None):
+  def __init__(self, raw_contents, validate = False, annotations = None):
     super(RelayDescriptor, self).__init__(raw_contents, validate, annotations)
 
     # validate the descriptor if required
diff --git a/stem/descriptor/tordnsel.py b/stem/descriptor/tordnsel.py
index 0a68580..b50f31a 100644
--- a/stem/descriptor/tordnsel.py
+++ b/stem/descriptor/tordnsel.py
@@ -21,7 +21,7 @@ from stem.descriptor import (
 )
 
 
-def _parse_file(tordnsel_file, validate = True, **kwargs):
+def _parse_file(tordnsel_file, validate = False, **kwargs):
   """
   Iterates over a tordnsel file.
 
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 7c24c3c..5a81d81 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -29,7 +29,7 @@ class TestExtraInfoDescriptor(unittest.TestCase):
       return
 
     with open(descriptor_path, 'rb') as descriptor_file:
-      for desc in stem.descriptor.parse_file(descriptor_file, 'extra-info 1.0'):
+      for desc in stem.descriptor.parse_file(descriptor_file, 'extra-info 1.0', validate = True):
         unrecognized_lines = desc.get_unrecognized_lines()
 
         if desc.dir_v2_responses_unknown:
diff --git a/test/integ/descriptor/microdescriptor.py b/test/integ/descriptor/microdescriptor.py
index 5eb8edf..9849e26 100644
--- a/test/integ/descriptor/microdescriptor.py
+++ b/test/integ/descriptor/microdescriptor.py
@@ -27,7 +27,7 @@ class TestMicrodescriptor(unittest.TestCase):
       return
 
     with open(descriptor_path, 'rb') as descriptor_file:
-      for desc in stem.descriptor.parse_file(descriptor_file, 'microdescriptor 1.0'):
+      for desc in stem.descriptor.parse_file(descriptor_file, 'microdescriptor 1.0', validate = True):
         unrecognized_lines = desc.get_unrecognized_lines()
 
         if unrecognized_lines:
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index 8172fb4..032f83c 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -37,7 +37,7 @@ class TestNetworkStatus(unittest.TestCase):
 
     count = 0
     with open(consensus_path, 'rb') as descriptor_file:
-      for router in stem.descriptor.parse_file(descriptor_file, 'network-status-consensus-3 1.0'):
+      for router in stem.descriptor.parse_file(descriptor_file, 'network-status-consensus-3 1.0', validate = True):
         count += 1
 
         # check if there's any unknown flags
@@ -78,7 +78,7 @@ class TestNetworkStatus(unittest.TestCase):
 
     count = 0
     with open(consensus_path, 'rb') as descriptor_file:
-      for router in stem.descriptor.parse_file(descriptor_file, 'network-status-microdesc-consensus-3 1.0'):
+      for router in stem.descriptor.parse_file(descriptor_file, 'network-status-microdesc-consensus-3 1.0', validate = True):
         count += 1
 
         # check if there's any unknown flags
diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py
index d1a377c..5ac848a 100644
--- a/test/integ/descriptor/remote.py
+++ b/test/integ/descriptor/remote.py
@@ -37,6 +37,7 @@ class TestDescriptorDownloader(unittest.TestCase):
         'server-descriptor 1.0',
         endpoints = [(authority.address, authority.dir_port)],
         timeout = 30,
+        validate = True,
       ), authority))
 
     for query, authority in queries:
@@ -72,7 +73,7 @@ class TestDescriptorDownloader(unittest.TestCase):
     elif test.runner.only_run_once(self, 'test_get_server_descriptors'):
       return
 
-    downloader = stem.descriptor.remote.DescriptorDownloader()
+    downloader = stem.descriptor.remote.DescriptorDownloader(validate = True)
 
     # Fetch a single descriptor and a batch. I'd love to also exercise
     # retrieving all descriptors, but that adds roughly a minute to the runtime
@@ -108,7 +109,7 @@ class TestDescriptorDownloader(unittest.TestCase):
     elif test.runner.only_run_once(self, 'test_get_extrainfo_descriptors'):
       return
 
-    downloader = stem.descriptor.remote.DescriptorDownloader()
+    downloader = stem.descriptor.remote.DescriptorDownloader(validate = True)
 
     single_query = downloader.get_extrainfo_descriptors('9695DFC35FFEB861329B9F1AB04C46397020CE31')
 
@@ -142,7 +143,7 @@ class TestDescriptorDownloader(unittest.TestCase):
     elif test.runner.only_run_once(self, 'test_get_microdescriptors'):
       return
 
-    downloader = stem.descriptor.remote.DescriptorDownloader()
+    downloader = stem.descriptor.remote.DescriptorDownloader(validate = True)
 
     single_query = downloader.get_microdescriptors('6dCl6ab8CLo0LeMjxi/MZgVJiZgWN8WKTesWPBMtyTo')
 
@@ -171,7 +172,7 @@ class TestDescriptorDownloader(unittest.TestCase):
     elif test.runner.only_run_once(self, 'test_get_consensus'):
       return
 
-    downloader = stem.descriptor.remote.DescriptorDownloader()
+    downloader = stem.descriptor.remote.DescriptorDownloader(validate = True)
 
     consensus_query = downloader.get_consensus()
     consensus_query.run()
@@ -190,7 +191,7 @@ class TestDescriptorDownloader(unittest.TestCase):
     elif test.runner.only_run_once(self, 'test_get_key_certificates'):
       return
 
-    downloader = stem.descriptor.remote.DescriptorDownloader()
+    downloader = stem.descriptor.remote.DescriptorDownloader(validate = True)
 
     single_query = downloader.get_key_certificates('D586D18309DED4CD6D57C18FDB97EFA96D330566')
 
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index d291923..9f018e7 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -30,7 +30,7 @@ class TestServerDescriptor(unittest.TestCase):
       return
 
     with open(descriptor_path, 'rb') as descriptor_file:
-      for desc in stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0'):
+      for desc in stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0', validate = True):
         # the following attributes should be deprecated, and not appear in the wild
         self.assertEqual(None, desc.read_history_end)
         self.assertEqual(None, desc.write_history_end)
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index 525ff06..a30d47a 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -583,7 +583,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
     self.assertEqual({}, desc.ip_versions)
 
     desc_text = get_bridge_extrainfo_descriptor({'bridge-ip-versions': 'v4=24.5'}, content = True)
-    self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text)
+    self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text, True)
 
   def test_bridge_ip_transports_line(self):
     """
@@ -597,7 +597,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
     self.assertEqual({}, desc.ip_transports)
 
     desc_text = get_bridge_extrainfo_descriptor({'bridge-ip-transports': '<OR>=24.5'}, content = True)
-    self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text)
+    self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text, True)
 
   def test_transport_line(self):
     """
@@ -624,7 +624,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
     value when we're constructed without validation.
     """
 
-    self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text)
+    self.assertRaises(ValueError, RelayExtraInfoDescriptor, desc_text, True)
     desc = RelayExtraInfoDescriptor(desc_text, validate = False)
 
     if attr:
diff --git a/test/unit/descriptor/microdescriptor.py b/test/unit/descriptor/microdescriptor.py
index 8fe0937..598f58e 100644
--- a/test/unit/descriptor/microdescriptor.py
+++ b/test/unit/descriptor/microdescriptor.py
@@ -113,7 +113,7 @@ class TestMicrodescriptor(unittest.TestCase):
     """
 
     desc_text = b'family Amunet1\n' + get_microdescriptor(content = True)
-    self.assertRaises(ValueError, Microdescriptor, desc_text)
+    self.assertRaises(ValueError, Microdescriptor, desc_text, True)
 
     desc = Microdescriptor(desc_text, validate = False)
     self.assertEqual(['Amunet1'], desc.family)
@@ -149,7 +149,7 @@ class TestMicrodescriptor(unittest.TestCase):
     desc_text += b'\nfamily Amunet1'
     desc_text += b'\nfamily Amunet2'
 
-    self.assertRaises(ValueError, Microdescriptor, desc_text)
+    self.assertRaises(ValueError, Microdescriptor, desc_text, True)
 
     # family entries will overwrite each other
     desc = Microdescriptor(desc_text, validate = False)
diff --git a/test/unit/descriptor/networkstatus/directory_authority.py b/test/unit/descriptor/networkstatus/directory_authority.py
index a5bc647..0c44a1e 100644
--- a/test/unit/descriptor/networkstatus/directory_authority.py
+++ b/test/unit/descriptor/networkstatus/directory_authority.py
@@ -84,7 +84,7 @@ class TestDirectoryAuthority(unittest.TestCase):
     """
 
     content = b'ho-hum 567\n' + get_directory_authority(content = True)
-    self.assertRaises(ValueError, DirectoryAuthority, content)
+    self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
     authority = DirectoryAuthority(content, False)
     self.assertEqual('turtles', authority.nickname)
@@ -97,7 +97,7 @@ class TestDirectoryAuthority(unittest.TestCase):
 
     for excluded_field in ('dir-source', 'contact'):
       content = get_directory_authority(exclude = (excluded_field,), content = True)
-      self.assertRaises(ValueError, DirectoryAuthority, content)
+      self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
       authority = DirectoryAuthority(content, False)
 
@@ -123,7 +123,7 @@ class TestDirectoryAuthority(unittest.TestCase):
 
     for index, duplicate_line in enumerate(lines):
       content = b'\n'.join(lines[:index] + [duplicate_line] + lines[index:])
-      self.assertRaises(ValueError, DirectoryAuthority, content)
+      self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
       authority = DirectoryAuthority(content, False)
       self.assertEqual('turtles', authority.nickname)
@@ -136,7 +136,7 @@ class TestDirectoryAuthority(unittest.TestCase):
     for missing_value in AUTHORITY_HEADER[0][1].split(' '):
       dir_source = AUTHORITY_HEADER[0][1].replace(missing_value, '').replace('  ', ' ')
       content = get_directory_authority({'dir-source': dir_source}, content = True)
-      self.assertRaises(ValueError, DirectoryAuthority, content)
+      self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
       authority = DirectoryAuthority(content, False)
 
@@ -161,7 +161,7 @@ class TestDirectoryAuthority(unittest.TestCase):
     for value in test_values:
       dir_source = AUTHORITY_HEADER[0][1].replace('27B6B5996C426270A5C95488AA5BCEB6BCC86956', value)
       content = get_directory_authority({'dir-source': dir_source}, content = True)
-      self.assertRaises(ValueError, DirectoryAuthority, content)
+      self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
       authority = DirectoryAuthority(content, False)
       self.assertEqual(None, authority.fingerprint)
@@ -183,7 +183,7 @@ class TestDirectoryAuthority(unittest.TestCase):
     for value in test_values:
       dir_source = AUTHORITY_HEADER[0][1].replace('76.73.17.194', value)
       content = get_directory_authority({'dir-source': dir_source}, content = True)
-      self.assertRaises(ValueError, DirectoryAuthority, content)
+      self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
       authority = DirectoryAuthority(content, False)
       self.assertEqual(None, authority.address)
@@ -215,7 +215,7 @@ class TestDirectoryAuthority(unittest.TestCase):
             dir_source = dir_source.replace('9030', value)
 
           content = get_directory_authority({'dir-source': dir_source}, content = True)
-          self.assertRaises(ValueError, DirectoryAuthority, content)
+          self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
           authority = DirectoryAuthority(content, False)
 
@@ -233,7 +233,7 @@ class TestDirectoryAuthority(unittest.TestCase):
 
     # check that we'll fail if legacy-dir-key appears in a consensus
     content = get_directory_authority({'legacy-dir-key': test_value}, content = True)
-    self.assertRaises(ValueError, DirectoryAuthority, content)
+    self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
     test_values = (
       '',
@@ -243,7 +243,7 @@ class TestDirectoryAuthority(unittest.TestCase):
 
     for value in test_values:
       content = get_directory_authority({'legacy-dir-key': value}, content = True)
-      self.assertRaises(ValueError, DirectoryAuthority, content)
+      self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
       authority = DirectoryAuthority(content, False)
       self.assertEqual(None, authority.legacy_dir_key)
@@ -257,7 +257,7 @@ class TestDirectoryAuthority(unittest.TestCase):
 
     # include a key cert with a consensus
     content = get_directory_authority(content = True) + b'\n' + key_cert
-    self.assertRaises(ValueError, DirectoryAuthority, content)
+    self.assertRaises(ValueError, DirectoryAuthority, content, True)
 
     authority = DirectoryAuthority(content, False)
     self.assertEqual('turtles', authority.nickname)
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index b0bb14a..3ed7fbe 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -452,7 +452,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
         for field, in_votes, in_consensus, is_mandatory in entries:
           if is_mandatory and ((is_consensus and in_consensus) or (is_vote and in_votes)):
             content = get_network_status_document_v3(attr, exclude = (field,), content = True)
-            self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+            self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
             NetworkStatusDocumentV3(content, False)  # constructs without validation
 
   def test_unrecognized_line(self):
@@ -486,7 +486,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
         test_lines[index], test_lines[index + 1] = test_lines[index + 1], test_lines[index]
 
         content = b'\n'.join(test_lines)
-        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+        self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
         NetworkStatusDocumentV3(content, False)  # constructs without validation
 
   def test_duplicate_fields(self):
@@ -516,7 +516,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
         test_lines.insert(index, line)
 
         content = b'\n'.join(test_lines)
-        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+        self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
         NetworkStatusDocumentV3(content, False)  # constructs without validation
 
   def test_version(self):
@@ -536,7 +536,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     self.assertEqual(True, document.is_microdescriptor)
 
     content = get_network_status_document_v3({'network-status-version': '4'}, content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual(4, document.version)
@@ -565,7 +565,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
     for test_value in test_values:
       content = get_network_status_document_v3({'vote-status': test_value}, content = True)
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
       document = NetworkStatusDocumentV3(content, False)
       self.assertEqual(True, document.is_consensus)
@@ -595,7 +595,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
     for test_value in test_values:
       content = get_network_status_document_v3({'vote-status': 'vote', 'consensus-methods': test_value}, content = True)
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
       expected_value = [2, 3, 4] if test_value == '2 3 4' else [1]
 
@@ -626,7 +626,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
     for test_value in test_values:
       content = get_network_status_document_v3({'consensus-method': test_value}, content = True)
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
       document = NetworkStatusDocumentV3(content, False)
       self.assertEqual(1, document.consensus_method)
@@ -666,7 +666,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
       for test_value in test_values:
         content = get_network_status_document_v3({'vote-status': 'vote', field: test_value}, content = True)
-        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+        self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
         document = NetworkStatusDocumentV3(content, False)
         self.assertEqual(None, getattr(document, attr))
@@ -690,7 +690,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
     for test_value in test_values:
       content = get_network_status_document_v3({'voting-delay': test_value}, content = True)
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
       document = NetworkStatusDocumentV3(content, False)
       self.assertEqual(None, document.vote_delay)
@@ -721,7 +721,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
       for test_value in test_values:
         content = get_network_status_document_v3({field: test_value}, content = True)
-        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+        self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
         document = NetworkStatusDocumentV3(content, False)
         self.assertEqual([], getattr(document, attr))
@@ -789,7 +789,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
     for test_value in test_values:
       content = get_network_status_document_v3({'vote-status': 'vote', 'flag-thresholds': test_value}, content = True)
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
       document = NetworkStatusDocumentV3(content, False)
       self.assertEqual({}, document.flag_thresholds)
@@ -827,7 +827,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
 
     for test_value in test_values:
       content = get_network_status_document_v3({"params": test_value}, content = True)
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
       document = NetworkStatusDocumentV3(content, False)
       self.assertEqual(DEFAULT_PARAMS, document.params)
@@ -860,7 +860,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
       if is_ok:
         document = NetworkStatusDocumentV3(content, default_params = False)
       else:
-        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+        self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
         document = NetworkStatusDocumentV3(content, False, default_params = False)
 
       self.assertEqual(expected_value, document.params)
@@ -871,7 +871,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     """
 
     content = get_network_status_document_v3({'params': 'unrecognized=-122 bwauthpid=1'}, content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False, default_params = False)
     self.assertEqual({}, document.params)
@@ -883,7 +883,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     """
 
     content = get_network_status_document_v3({'consensus-method': '8'}, content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual([DOC_SIG], document.signatures)
@@ -918,7 +918,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     """
 
     content = get_network_status_document_v3({'directory-footer': 'blarg'}, content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual([DOC_SIG], document.signatures)
@@ -958,7 +958,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
       weight_entry = base_weight_entry.replace('Wbe=5', test_value)
       content = get_network_status_document_v3({'bandwidth-weights': weight_entry}, content = True)
 
-      self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+      self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
       document = NetworkStatusDocumentV3(content, False)
       self.assertEqual({}, document.bandwidth_weights)
 
@@ -970,7 +970,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     weight_entry = ' '.join(['%s=5' % e for e in reversed(BANDWIDTH_WEIGHT_ENTRIES)])
 
     content = get_network_status_document_v3({'bandwidth-weights': weight_entry}, content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual({}, document.bandwidth_weights)
@@ -984,7 +984,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     expected = dict([(e, 5) for e in BANDWIDTH_WEIGHT_ENTRIES])
 
     content = get_network_status_document_v3({'vote-status': 'vote', 'bandwidth-weights': weight_entry}, content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual(expected, document.bandwidth_weights)
@@ -1029,7 +1029,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
         attrs[test_attr] = test_value
 
         content = get_network_status_document_v3({'directory-signature': '%s %s\n%s' % tuple(attrs)}, content = True)
-        self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+        self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
         NetworkStatusDocumentV3(content, False)  # checks that it's still parsable without validation
 
   def test_with_router_status_entries(self):
@@ -1055,14 +1055,14 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     entry3 = RouterStatusEntryV3(get_router_status_entry_v3({'r': 'ugabuga'}, content = True), False)
     content = get_network_status_document_v3(routers = (entry3,), content = True)
 
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual([entry3], list(document.routers.values()))
 
     # try including with a microdescriptor consensus
 
     content = get_network_status_document_v3({'network-status-version': '3 microdesc'}, routers = (entry1,), content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual([RouterStatusEntryMicroV3(str(entry1), False)], list(document.routers.values()))
@@ -1089,7 +1089,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     entry3 = RouterStatusEntryMicroV3(get_router_status_entry_micro_v3({'r': 'ugabuga'}, content = True), False)
 
     content = get_network_status_document_v3({'network-status-version': '3 microdesc'}, routers = (entry3,), content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual([entry3], list(document.routers.values()))
@@ -1097,7 +1097,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     # try including microdescriptor entry in a normal consensus
 
     content = get_network_status_document_v3(routers = (entry1,), content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, False)
     self.assertEqual([RouterStatusEntryV3(str(entry1), False)], list(document.routers.values()))
@@ -1119,7 +1119,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
           if is_document_vote:
             # votes can only have a single authority
 
-            self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+            self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
             document = NetworkStatusDocumentV3(content, validate = False)
           else:
             document = NetworkStatusDocumentV3(content)
@@ -1127,7 +1127,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
           self.assertEqual((authority1, authority2), document.directory_authorities)
         else:
           # authority votes in a consensus or consensus authorities in a vote
-          self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+          self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
           document = NetworkStatusDocumentV3(content, validate = False)
           self.assertEqual((authority1, authority2), document.directory_authorities)
 
@@ -1159,7 +1159,7 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
     authority = DirectoryAuthority(authority_content, False, True)
 
     content = get_network_status_document_v3({'vote-status': 'vote'}, authorities = (authority,), content = True)
-    self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
+    self.assertRaises(ValueError, NetworkStatusDocumentV3, content, True)
 
     document = NetworkStatusDocumentV3(content, validate = False)
     self.assertEqual((authority,), document.directory_authorities)
diff --git a/test/unit/descriptor/networkstatus/key_certificate.py b/test/unit/descriptor/networkstatus/key_certificate.py
index 12facaa..bbcaaa0 100644
--- a/test/unit/descriptor/networkstatus/key_certificate.py
+++ b/test/unit/descriptor/networkstatus/key_certificate.py
@@ -53,7 +53,7 @@ class TestKeyCertificate(unittest.TestCase):
 
     for cert_text in (b'dir-address 127.0.0.1:80\n' + content,
                       content + b'\ndir-address 127.0.0.1:80'):
-      self.assertRaises(ValueError, KeyCertificate, cert_text)
+      self.assertRaises(ValueError, KeyCertificate, cert_text, True)
 
       certificate = KeyCertificate(cert_text, False)
       self.assertEqual('127.0.0.1', certificate.address)
@@ -68,7 +68,7 @@ class TestKeyCertificate(unittest.TestCase):
 
     for excluded_field in mandatory_fields:
       content = get_key_certificate(exclude = (excluded_field,), content = True)
-      self.assertRaises(ValueError, KeyCertificate, content)
+      self.assertRaises(ValueError, KeyCertificate, content, True)
 
       certificate = KeyCertificate(content, False)
 
@@ -95,11 +95,11 @@ class TestKeyCertificate(unittest.TestCase):
     self.assertEqual(3, certificate.version)
 
     content = get_key_certificate({'dir-key-certificate-version': '4'}, content = True)
-    self.assertRaises(ValueError, KeyCertificate, content)
+    self.assertRaises(ValueError, KeyCertificate, content, True)
     self.assertEqual(4, KeyCertificate(content, False).version)
 
     content = get_key_certificate({'dir-key-certificate-version': 'boo'}, content = True)
-    self.assertRaises(ValueError, KeyCertificate, content)
+    self.assertRaises(ValueError, KeyCertificate, content, True)
     self.assertEqual(None, KeyCertificate(content, False).version)
 
   def test_dir_address(self):
@@ -124,7 +124,7 @@ class TestKeyCertificate(unittest.TestCase):
 
     for test_value in test_values:
       content = get_key_certificate({'dir-address': test_value}, content = True)
-      self.assertRaises(ValueError, KeyCertificate, content)
+      self.assertRaises(ValueError, KeyCertificate, content, True)
 
       certificate = KeyCertificate(content, False)
       self.assertEqual(None, certificate.address)
@@ -144,7 +144,7 @@ class TestKeyCertificate(unittest.TestCase):
 
     for test_value in test_values:
       content = get_key_certificate({'fingerprint': test_value}, content = True)
-      self.assertRaises(ValueError, KeyCertificate, content)
+      self.assertRaises(ValueError, KeyCertificate, content, True)
 
       certificate = KeyCertificate(content, False)
       self.assertEqual(None, certificate.fingerprint)
@@ -166,7 +166,7 @@ class TestKeyCertificate(unittest.TestCase):
     for field, attr in (('dir-key-published', 'published'), ('dir-key-expires', 'expires')):
       for test_value in test_values:
         content = get_key_certificate({field: test_value}, content = True)
-        self.assertRaises(ValueError, KeyCertificate, content)
+        self.assertRaises(ValueError, KeyCertificate, content, True)
 
         certificate = KeyCertificate(content, False)
         self.assertEqual(None, getattr(certificate, attr))
@@ -189,7 +189,7 @@ class TestKeyCertificate(unittest.TestCase):
                         ('dir-key-crosscert', 'crosscert'),
                         ('dir-key-certification', 'certification')):
       content = get_key_certificate({field: test_value}, content = True)
-      self.assertRaises(ValueError, KeyCertificate, content)
+      self.assertRaises(ValueError, KeyCertificate, content, True)
 
       certificate = KeyCertificate(content, False)
       self.assertEqual(None, getattr(certificate, attr))
@@ -200,4 +200,4 @@ class TestKeyCertificate(unittest.TestCase):
     """
 
     content = get_key_certificate({'dir-identity-key': '\n-----BEGIN MD5SUM-----%s-----END MD5SUM-----' % CRYPTO_BLOB}, content = True)
-    self.assertRaises(ValueError, KeyCertificate, content)
+    self.assertRaises(ValueError, KeyCertificate, content, True)
diff --git a/test/unit/descriptor/remote.py b/test/unit/descriptor/remote.py
index 60a5c1a..19907a7 100644
--- a/test/unit/descriptor/remote.py
+++ b/test/unit/descriptor/remote.py
@@ -72,6 +72,7 @@ class TestDescriptorDownloader(unittest.TestCase):
       '/tor/server/fp/9695DFC35FFEB861329B9F1AB04C46397020CE31',
       'server-descriptor 1.0',
       endpoints = [('128.31.0.39', 9131)],
+      validate = True,
     )
 
     expeced_url = 'http://128.31.0.39:9131/tor/server/fp/9695DFC35FFEB861329B9F1AB04C46397020CE31'
@@ -101,6 +102,7 @@ class TestDescriptorDownloader(unittest.TestCase):
       '/tor/server/fp/9695DFC35FFEB861329B9F1AB04C46397020CE31',
       'server-descriptor 1.0',
       endpoints = [('128.31.0.39', 9131)],
+      validate = True,
     )
 
     # checking via the iterator
@@ -126,6 +128,7 @@ class TestDescriptorDownloader(unittest.TestCase):
       endpoints = [('128.31.0.39', 9131)],
       fall_back_to_authority = False,
       timeout = 5,
+      validate = True,
     )
 
     self.assertRaises(socket.timeout, query.run)
@@ -143,6 +146,7 @@ class TestDescriptorDownloader(unittest.TestCase):
       '/tor/server/fp/9695DFC35FFEB861329B9F1AB04C46397020CE31',
       'server-descriptor 1.0',
       endpoints = [('128.31.0.39', 9131)],
+      validate = True,
     )
 
     # check that iterating over the query provides the descriptors each time
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index 1243a55..14df828 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -39,7 +39,7 @@ class TestRouterStatusEntry(unittest.TestCase):
 
     # checks with some malformed inputs
     for arg in ('', '20wYcb', '20wYcb' * 30):
-      self.assertRaises(ValueError, _base64_to_hex, arg)
+      self.assertRaises(ValueError, _base64_to_hex, arg, True)
 
   def test_minimal_v2(self):
     """
@@ -137,7 +137,7 @@ class TestRouterStatusEntry(unittest.TestCase):
     """
 
     content = b'z some stuff\n' + get_router_status_entry_v3(content = True)
-    self.assertRaises(ValueError, RouterStatusEntryV3, content)
+    self.assertRaises(ValueError, RouterStatusEntryV3, content, True)
     self.assertEqual(['z some stuff'], RouterStatusEntryV3(content, False).get_unrecognized_lines())
 
   def test_blank_lines(self):
@@ -158,7 +158,7 @@ class TestRouterStatusEntry(unittest.TestCase):
 
     for index, duplicate_line in enumerate(lines):
       content = b'\n'.join(lines[:index] + [duplicate_line] + lines[index:])
-      self.assertRaises(ValueError, RouterStatusEntryV3, content)
+      self.assertRaises(ValueError, RouterStatusEntryV3, content, True)
 
       entry = RouterStatusEntryV3(content, False)
       self.assertEqual('caerSidi', entry.nickname)
@@ -524,7 +524,7 @@ class TestRouterStatusEntry(unittest.TestCase):
     value when we're constructed without validation.
     """
 
-    self.assertRaises(ValueError, RouterStatusEntryV3, content)
+    self.assertRaises(ValueError, RouterStatusEntryV3, content, True)
     entry = RouterStatusEntryV3(content, False)
 
     if attr:
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index f261798..00d2bb3 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -155,7 +155,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
 
     descriptor_file = open(get_resource('old_descriptor'), 'rb')
 
-    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0'))
+    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0', validate = True))
     self.assertEqual('krypton', desc.nickname)
     self.assertEqual('3E2F63E2356F52318B536A12B6445373808A5D6C', desc.fingerprint)
     self.assertEqual('212.37.39.59', desc.address)
@@ -203,7 +203,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
 
     expected_contact = b'1024D/04D2E818 L\xc3\xa9na\xc3\xafc Huard <lenaic dot huard AT laposte dot net>'
 
-    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0'))
+    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0', validate = True))
     self.assertEqual('Coruscant', desc.nickname)
     self.assertEqual('0B9821545C48E496AEED9ECC0DB506C49FF8158D', desc.fingerprint)
     self.assertEqual('88.182.161.122', desc.address)
@@ -244,7 +244,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     """
 
     descriptor_file = open(get_resource('cr_in_contact_line'), 'rb')
-    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0'))
+    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0', validate = True))
 
     self.assertEqual('pogonip', desc.nickname)
     self.assertEqual('6DABD62BC65D4E6FE620293157FC76968DAB9C9B', desc.fingerprint)
@@ -266,7 +266,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     """
 
     descriptor_file = open(get_resource('negative_uptime'), 'rb')
-    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0'))
+    desc = next(stem.descriptor.parse_file(descriptor_file, 'server-descriptor 1.0', validate = True))
 
     self.assertEqual('TipTor', desc.nickname)
     self.assertEqual('137962D4931DBF08A24E843288B8A155D6D2AEDD', desc.fingerprint)
@@ -275,8 +275,8 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     # modify the relay version so it's after when the negative uptime bug
     # should appear
 
-    descriptor_contents = str(desc).replace('Tor 0.1.1.25', 'Tor 0.1.2.7')
-    self.assertRaises(ValueError, stem.descriptor.server_descriptor.RelayDescriptor, descriptor_contents)
+    descriptor_contents = desc.get_bytes().replace(b'Tor 0.1.1.25', b'Tor 0.1.2.7')
+    self.assertRaises(ValueError, stem.descriptor.server_descriptor.RelayDescriptor, descriptor_contents, True)
 
   def test_bridge_descriptor(self):
     """
@@ -291,7 +291,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
       '$8C8A470D7C23151665A7B84E75E89FCC205A3304',
     ])
 
-    desc = next(stem.descriptor.parse_file(descriptor_file, 'bridge-server-descriptor 1.0'))
+    desc = next(stem.descriptor.parse_file(descriptor_file, 'bridge-server-descriptor 1.0', validate = True))
     self.assertEqual('Unnamed', desc.nickname)
     self.assertEqual('AE54E28ED069CDF45F3009F963EE3B3D6FA26A2E', desc.fingerprint)
     self.assertEqual('10.45.227.253', desc.address)
@@ -519,7 +519,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     desc_text += b'\ntrailing text that should be invalid, ho hum'
 
     # running _parse_file should provide an iterator with a single descriptor
-    desc_iter = stem.descriptor.server_descriptor._parse_file(io.BytesIO(desc_text))
+    desc_iter = stem.descriptor.server_descriptor._parse_file(io.BytesIO(desc_text), validate = True)
     self.assertRaises(ValueError, list, desc_iter)
 
     desc_text = b'@pepperjack very tasty\n@mushrooms not so much\n'
@@ -552,7 +552,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
 
     for attr in stem.descriptor.server_descriptor.REQUIRED_FIELDS:
       desc_text = get_relay_server_descriptor(exclude = [attr], content = True)
-      self.assertRaises(ValueError, RelayDescriptor, desc_text)
+      self.assertRaises(ValueError, RelayDescriptor, desc_text, True)
 
       # check that we can still construct it without validation
       desc = RelayDescriptor(desc_text, validate = False)
@@ -652,7 +652,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     # checks when missing
 
     desc_text = get_bridge_server_descriptor(exclude = ['router-digest'], content = True)
-    self.assertRaises(ValueError, BridgeDescriptor, desc_text)
+    self.assertRaises(ValueError, BridgeDescriptor, desc_text, True)
 
     # check that we can still construct it without validation
     desc = BridgeDescriptor(desc_text, validate = False)
@@ -669,7 +669,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
 
     for value in test_values:
       desc_text = get_bridge_server_descriptor({'router-digest': value}, content = True)
-      self.assertRaises(ValueError, BridgeDescriptor, desc_text)
+      self.assertRaises(ValueError, BridgeDescriptor, desc_text, True)
 
       desc = BridgeDescriptor(desc_text, validate = False)
       self.assertEqual(None, desc.digest())
@@ -714,7 +714,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
     value when we're constructed without validation.
     """
 
-    self.assertRaises(ValueError, RelayDescriptor, desc_text)
+    self.assertRaises(ValueError, RelayDescriptor, desc_text, True)
     desc = RelayDescriptor(desc_text, validate = False)
 
     if attr:
diff --git a/test/unit/descriptor/tordnsel.py b/test/unit/descriptor/tordnsel.py
index 26227cc..f6cf07f 100644
--- a/test/unit/descriptor/tordnsel.py
+++ b/test/unit/descriptor/tordnsel.py
@@ -68,17 +68,17 @@ class TestTorDNSELDescriptor(unittest.TestCase):
     # block content raises value error
 
     extra = b'ExtraContent goes here\n'
-    descriptors = _parse_file(io.BytesIO(TEST_DESC + extra))
+    descriptors = _parse_file(io.BytesIO(TEST_DESC + extra), validate = True)
     self.assertRaises(ValueError, list, descriptors)
 
     # malformed fingerprint raises value errors
 
     extra = b'ExitNode 030B22437D99B2DB2908B747B6'
-    self.assertRaises(ValueError, list, _parse_file(io.BytesIO(TEST_DESC + extra)))
+    self.assertRaises(ValueError, list, _parse_file(io.BytesIO(TEST_DESC + extra), validate = True))
 
     # malformed date raises value errors
 
-    self.assertRaises(ValueError, list, _parse_file(io.BytesIO(TEST_DESC + MALFORMED_ENTRY_1)))
+    self.assertRaises(ValueError, list, _parse_file(io.BytesIO(TEST_DESC + MALFORMED_ENTRY_1), validate = True))
 
     # skip exit address if malformed date and validate is False
 

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