commit e4f1b57419f1e8ab87c54b65d9da8949e975dd95 Author: Damian Johnson atagar@torproject.org Date: Tue Jun 27 09:23:30 2017 -0700
Raise NotImplementedError if signing not implemented
We're documented as raising a NotImplementedError if signing isn't yet supported but we didn't yet do that. --- stem/descriptor/extrainfo_descriptor.py | 6 ++++++ stem/descriptor/hidden_service_descriptor.py | 3 +++ stem/descriptor/microdescriptor.py | 3 +++ stem/descriptor/networkstatus.py | 12 ++++++++++++ stem/descriptor/router_status_entry.py | 9 +++++++++ stem/descriptor/server_descriptor.py | 3 +++ test/unit/descriptor/extrainfo_descriptor.py | 6 ++++++ test/unit/descriptor/hidden_service_descriptor.py | 4 ++++ test/unit/descriptor/microdescriptor.py | 9 ++++++--- test/unit/descriptor/networkstatus/directory_authority.py | 6 ++++++ test/unit/descriptor/networkstatus/document_v2.py | 6 ++++++ test/unit/descriptor/networkstatus/document_v3.py | 4 ++++ test/unit/descriptor/networkstatus/key_certificate.py | 5 +++++ test/unit/descriptor/router_status_entry.py | 7 +++++++ test/unit/descriptor/server_descriptor.py | 1 + 15 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 847a2c7..c0484ad 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -974,6 +974,9 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, RELAY_EXTRAINFO_HEADER, RELAY_EXTRAINFO_FOOTER)
@lru_cache() @@ -1010,6 +1013,9 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, BRIDGE_EXTRAINFO_HEADER, BRIDGE_EXTRAINFO_FOOTER)
def digest(self): diff --git a/stem/descriptor/hidden_service_descriptor.py b/stem/descriptor/hidden_service_descriptor.py index d752369..f9a5e35 100644 --- a/stem/descriptor/hidden_service_descriptor.py +++ b/stem/descriptor/hidden_service_descriptor.py @@ -252,6 +252,9 @@ class HiddenServiceDescriptor(Descriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, HIDDEN_SERVICE_HEADER, HIDDEN_SERVICE_FOOTER)
@classmethod diff --git a/stem/descriptor/microdescriptor.py b/stem/descriptor/microdescriptor.py index 257067e..3990720 100644 --- a/stem/descriptor/microdescriptor.py +++ b/stem/descriptor/microdescriptor.py @@ -264,6 +264,9 @@ class Microdescriptor(Descriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, MICRODESCRIPTOR)
def __init__(self, raw_contents, validate = False, annotations = None): diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py index 4cea4eb..2fc868a 100644 --- a/stem/descriptor/networkstatus.py +++ b/stem/descriptor/networkstatus.py @@ -512,6 +512,9 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, NETWORK_STATUS_DOCUMENT_HEADER_V2, NETWORK_STATUS_DOCUMENT_FOOTER_V2)
def __init__(self, raw_content, validate = False): @@ -960,6 +963,9 @@ class NetworkStatusDocumentV3(NetworkStatusDocument):
@classmethod def content(cls, attr = None, exclude = (), sign = False, authorities = None, routers = None): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + attr = {} if attr is None else dict(attr)
is_vote = attr.get('vote-status') == 'vote' @@ -1424,6 +1430,9 @@ class DirectoryAuthority(Descriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False, is_vote = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + attr = {} if attr is None else dict(attr)
# include mandatory 'vote-digest' if a consensus @@ -1618,6 +1627,9 @@ class KeyCertificate(Descriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, KEY_CERTIFICATE_HEADER, KEY_CERTIFICATE_FOOTER)
def __init__(self, raw_content, validate = False): diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py index 19d4d3c..c5f21bf 100644 --- a/stem/descriptor/router_status_entry.py +++ b/stem/descriptor/router_status_entry.py @@ -529,6 +529,9 @@ class RouterStatusEntryV2(RouterStatusEntry):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, ROUTER_STATUS_ENTRY_V2_HEADER)
def _name(self, is_plural = False): @@ -626,6 +629,9 @@ class RouterStatusEntryV3(RouterStatusEntry):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, ROUTER_STATUS_ENTRY_V3_HEADER)
def _name(self, is_plural = False): @@ -699,6 +705,9 @@ class RouterStatusEntryMicroV3(RouterStatusEntry):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, ROUTER_STATUS_ENTRY_MICRO_V3_HEADER)
def _name(self, is_plural = False): diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py index 607908d..a66faa8 100644 --- a/stem/descriptor/server_descriptor.py +++ b/stem/descriptor/server_descriptor.py @@ -962,6 +962,9 @@ class BridgeDescriptor(ServerDescriptor):
@classmethod def content(cls, attr = None, exclude = (), sign = False): + if sign: + raise NotImplementedError('Signing of %s not implemented' % cls.__name__) + return _descriptor_content(attr, exclude, sign, BRIDGE_SERVER_HEADER)
def digest(self): diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py index 798320e..d41f68b 100644 --- a/test/unit/descriptor/extrainfo_descriptor.py +++ b/test/unit/descriptor/extrainfo_descriptor.py @@ -8,6 +8,7 @@ import re import unittest
import stem.descriptor +import test.require
from stem.descriptor.extrainfo_descriptor import ( RelayExtraInfoDescriptor, @@ -133,6 +134,11 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw self.assertEqual({}, desc.dir_v2_responses_unknown) self.assertEqual({}, desc.dir_v2_responses_unknown)
+ @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of RelayExtraInfoDescriptor not implemented', RelayExtraInfoDescriptor.create, sign = True) + self.assertRaisesRegexp(NotImplementedError, 'Signing of BridgeExtraInfoDescriptor not implemented', BridgeExtraInfoDescriptor.create, sign = True) + def test_multiple_metrics_bridge_descriptors(self): """ Check that we can read bridge descriptors when there's multiple in a file. diff --git a/test/unit/descriptor/hidden_service_descriptor.py b/test/unit/descriptor/hidden_service_descriptor.py index 2f8427f..09d8de5 100644 --- a/test/unit/descriptor/hidden_service_descriptor.py +++ b/test/unit/descriptor/hidden_service_descriptor.py @@ -274,6 +274,10 @@ class TestHiddenServiceDescriptor(unittest.TestCase): self.assertEqual([2, 3], desc.protocol_versions)
@test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of HiddenServiceDescriptor not implemented', HiddenServiceDescriptor.create, sign = True) + + @test.require.cryptography def test_with_basic_auth(self): """ Parse a descriptor with introduction-points encrypted with basic auth. diff --git a/test/unit/descriptor/microdescriptor.py b/test/unit/descriptor/microdescriptor.py index 35b8de0..0de947f 100644 --- a/test/unit/descriptor/microdescriptor.py +++ b/test/unit/descriptor/microdescriptor.py @@ -4,13 +4,12 @@ Unit tests for stem.descriptor.microdescriptor.
import unittest
-import stem.exit_policy - import stem.descriptor +import stem.exit_policy +import test.require
from stem.util import str_type from stem.descriptor.microdescriptor import Microdescriptor - from test.unit.descriptor import get_resource
FIRST_ONION_KEY = """\ @@ -96,6 +95,10 @@ class TestMicrodescriptor(unittest.TestCase): self.assertEqual({}, desc.protocols) self.assertEqual([], desc.get_unrecognized_lines())
+ @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of Microdescriptor not implemented', Microdescriptor.create, sign = True) + def test_unrecognized_line(self): """ Includes unrecognized content in the descriptor. diff --git a/test/unit/descriptor/networkstatus/directory_authority.py b/test/unit/descriptor/networkstatus/directory_authority.py index a80cb44..f2c270e 100644 --- a/test/unit/descriptor/networkstatus/directory_authority.py +++ b/test/unit/descriptor/networkstatus/directory_authority.py @@ -4,6 +4,8 @@ Unit tests for the DirectoryAuthority of stem.descriptor.networkstatus.
import unittest
+import test.require + from stem.descriptor.networkstatus import ( AUTHORITY_HEADER, DirectoryAuthority, @@ -52,6 +54,10 @@ class TestDirectoryAuthority(unittest.TestCase): self.assertEqual(KeyCertificate.create(), authority.key_certificate) self.assertEqual([], authority.get_unrecognized_lines())
+ @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of DirectoryAuthority not implemented', DirectoryAuthority.create, sign = True) + def test_unrecognized_line(self): """ Includes unrecognized content in the descriptor. diff --git a/test/unit/descriptor/networkstatus/document_v2.py b/test/unit/descriptor/networkstatus/document_v2.py index 7b6fdb1..2ed3177 100644 --- a/test/unit/descriptor/networkstatus/document_v2.py +++ b/test/unit/descriptor/networkstatus/document_v2.py @@ -5,6 +5,8 @@ Unit tests for the NetworkStatusDocumentV2 of stem.descriptor.networkstatus. import datetime import unittest
+import test.require + from stem.descriptor.networkstatus import ( NETWORK_STATUS_DOCUMENT_HEADER_V2, NETWORK_STATUS_DOCUMENT_FOOTER_V2, @@ -111,3 +113,7 @@ TpQQk3nNQF8z6UIvdlvP+DnJV4izWVkQEZgUZgIVM0E= self.assertEqual([], document.options) self.assertEqual('moria2', document.signing_authority) self.assertEqual(NETWORK_STATUS_DOCUMENT_FOOTER_V2[0][1][7:], document.signature) + + @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of NetworkStatusDocumentV2 not implemented', NetworkStatusDocumentV2.create, sign = True) diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py index 68d7270..3de445b 100644 --- a/test/unit/descriptor/networkstatus/document_v3.py +++ b/test/unit/descriptor/networkstatus/document_v3.py @@ -375,6 +375,10 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w= self.assertEqual([DOC_SIG], document.signatures) self.assertEqual([], document.get_unrecognized_lines())
+ @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of NetworkStatusDocumentV3 not implemented', NetworkStatusDocumentV3.create, sign = True) + def test_examples(self): """ Run something similar to the examples in the header pydocs. diff --git a/test/unit/descriptor/networkstatus/key_certificate.py b/test/unit/descriptor/networkstatus/key_certificate.py index 4770517..d7982ae 100644 --- a/test/unit/descriptor/networkstatus/key_certificate.py +++ b/test/unit/descriptor/networkstatus/key_certificate.py @@ -6,6 +6,7 @@ import datetime import unittest
import stem.descriptor +import test.require
from stem.descriptor.networkstatus import ( KEY_CERTIFICATE_HEADER, @@ -148,6 +149,10 @@ GM9hAsAMRX9Ogqhq5UjDNqEsvDKuyVeyh7unSZEOip9Zr6K/+7VsVPNb8vfBRBjo self.assertEqual(expected_key_cert, cert.certification) self.assertEqual([], cert.get_unrecognized_lines())
+ @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of KeyCertificate not implemented', KeyCertificate.create, sign = True) + def test_unrecognized_line(self): """ Includes unrecognized content in the descriptor. diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py index 37d763e..166b419 100644 --- a/test/unit/descriptor/router_status_entry.py +++ b/test/unit/descriptor/router_status_entry.py @@ -7,6 +7,7 @@ import functools import unittest
import stem.descriptor +import test.require
from stem import Flag from stem.exit_policy import MicroExitPolicy @@ -159,6 +160,12 @@ class TestRouterStatusEntry(unittest.TestCase): self.assertEqual('6A252497006BB9AF36A1B1B902C4D7FA2129923400DBE0101F167B1B031F63BD', entry.digest) self.assertEqual([], entry.get_unrecognized_lines())
+ @test.require.cryptography + def test_descriptor_signing(self): + self.assertRaisesRegexp(NotImplementedError, 'Signing of RouterStatusEntryV2 not implemented', RouterStatusEntryV2.create, sign = True) + self.assertRaisesRegexp(NotImplementedError, 'Signing of RouterStatusEntryV3 not implemented', RouterStatusEntryV3.create, sign = True) + self.assertRaisesRegexp(NotImplementedError, 'Signing of RouterStatusEntryMicroV3 not implemented', RouterStatusEntryMicroV3.create, sign = True) + def test_without_ed25519(self): """ Parses a router status entry without a ed25519 value. diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py index 2c47bdf..c881751 100644 --- a/test/unit/descriptor/server_descriptor.py +++ b/test/unit/descriptor/server_descriptor.py @@ -258,6 +258,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4= @test.require.cryptography def test_descriptor_signing(self): RelayDescriptor.create(sign = True) + self.assertRaisesRegexp(NotImplementedError, 'Signing of BridgeDescriptor not implemented', BridgeDescriptor.create, sign = True)
@patch('time.time', Mock(return_value = time.mktime(datetime.date(2010, 1, 1).timetuple()))) def test_with_ed25519(self):