commit 61a1fe90797814b871c94929b533cf98e7715e30 Author: Damian Johnson atagar@torproject.org Date: Mon May 7 07:40:42 2018 -0700
Separate stem.directory integ tests
Moving the authority and fallback integ tests into their own modules. --- test/integ/descriptor/remote.py | 72 --------------------------------------- test/integ/directory/__init__.py | 8 +++++ test/integ/directory/authority.py | 38 +++++++++++++++++++++ test/integ/directory/fallback.py | 54 +++++++++++++++++++++++++++++ test/settings.cfg | 2 ++ 5 files changed, 102 insertions(+), 72 deletions(-)
diff --git a/test/integ/descriptor/remote.py b/test/integ/descriptor/remote.py index b3553598..0305d069 100644 --- a/test/integ/descriptor/remote.py +++ b/test/integ/descriptor/remote.py @@ -245,75 +245,3 @@ class TestDescriptorDownloader(unittest.TestCase): self.assertTrue(isinstance(single_query_results[0], stem.descriptor.networkstatus.KeyCertificate))
self.assertEqual(2, len(list(multiple_query))) - - @test.require.online - def test_authority_cache_is_up_to_date(self): - """ - Check if the cached authorities bundled with Stem are up to date or not. - """ - - cached_authorities = stem.descriptor.remote.get_authorities() - latest_authorities = stem.descriptor.remote.DirectoryAuthority.from_remote() - - for nickname in cached_authorities: - if nickname not in latest_authorities: - self.fail('%s is no longer a directory authority in tor' % nickname) - - for nickname in latest_authorities: - if nickname not in cached_authorities: - self.fail('%s is now a directory authority in tor' % nickname) - - # tor doesn't note if an autority is a bwauth or not, so we need to exclude - # that from our comparison - - for attr in ('address', 'or_port', 'dir_port', 'fingerprint', 'nickname', 'v3ident'): - for auth in cached_authorities.values(): - cached_value = getattr(auth, attr) - latest_value = getattr(latest_authorities[auth.nickname], attr) - - if cached_value != latest_value: - self.fail('The %s of the %s authority is %s in tor but %s in stem' % (attr, auth.nickname, latest_value, cached_value)) - - @test.require.online - def test_fallback_cache_is_up_to_date(self): - """ - Check if the cached fallback directories bundled with Stem are up to date - or not. - """ - - cached_fallback_directories = stem.descriptor.remote.FallbackDirectory.from_cache() - latest_fallback_directories = stem.descriptor.remote.FallbackDirectory.from_remote() - - if cached_fallback_directories != latest_fallback_directories: - self.fail("Stem's cached fallback directories are out of date. Please run 'cache_fallback_directories.py'...\n\n%s" % stem.descriptor.remote._fallback_directory_differences(cached_fallback_directories, latest_fallback_directories)) - - @test.require.online - def test_fallback_directory_reachability(self): - """ - Fetch information from each fallback directory to confirm that it's - available. - """ - - # Don't run this test by default. Once upon a time it was fine, but tor has - # added so many fallbacks now that this takes a looong time. :( - - self.skipTest('(skipped by default)') - return - - unsuccessful = {} - downloader = stem.descriptor.remote.DescriptorDownloader() - moria1_v3ident = stem.descriptor.remote.get_authorities()['moria1'].v3ident - - for fallback_directory in stem.descriptor.remote.FallbackDirectory.from_cache().values(): - try: - downloader.get_key_certificates(authority_v3idents = moria1_v3ident, endpoints = [(fallback_directory.address, fallback_directory.dir_port)]).run() - except Exception as exc: - unsuccessful[fallback_directory] = exc - - if unsuccessful: - lines = ['We were unable to contact the following fallback directories...\n'] - - for fallback_directory, exc in unsuccessful.items(): - lines.append('* %s:%s (%s): %s' % (fallback_directory.address, fallback_directory.dir_port, fallback_directory.fingerprint, exc)) - - self.fail('\n'.join(lines)) diff --git a/test/integ/directory/__init__.py b/test/integ/directory/__init__.py new file mode 100644 index 00000000..f4e52c12 --- /dev/null +++ b/test/integ/directory/__init__.py @@ -0,0 +1,8 @@ +""" +Integration tests for stem.directory. +""" + +__all__ = [ + 'authority', + 'fallback', +] diff --git a/test/integ/directory/authority.py b/test/integ/directory/authority.py new file mode 100644 index 00000000..fc5eb13e --- /dev/null +++ b/test/integ/directory/authority.py @@ -0,0 +1,38 @@ +""" +Integration tests for stem.directory.Authority. +""" + +import unittest + +import stem.directory +import test.require + + +class TestAuthority(unittest.TestCase): + @test.require.online + def test_cache_is_up_to_date(self): + """ + Check if the cached authorities we bundle are up to date. + """ + + cached_authorities = stem.directory.Authority.from_cache() + latest_authorities = stem.directory.Authority.from_remote() + + for nickname in cached_authorities: + if nickname not in latest_authorities: + self.fail('%s is no longer a directory authority in tor' % nickname) + + for nickname in latest_authorities: + if nickname not in cached_authorities: + self.fail('%s is now a directory authority in tor' % nickname) + + # tor doesn't note if an autority is a bwauth or not, so we need to exclude + # that from our comparison + + for attr in ('address', 'or_port', 'dir_port', 'fingerprint', 'nickname', 'v3ident'): + for auth in cached_authorities.values(): + cached_value = getattr(auth, attr) + latest_value = getattr(latest_authorities[auth.nickname], attr) + + if cached_value != latest_value: + self.fail('The %s of the %s authority is %s in tor but %s in stem' % (attr, auth.nickname, latest_value, cached_value)) diff --git a/test/integ/directory/fallback.py b/test/integ/directory/fallback.py new file mode 100644 index 00000000..e12b2659 --- /dev/null +++ b/test/integ/directory/fallback.py @@ -0,0 +1,54 @@ +""" +Integration tests for stem.directory.Fallback. +""" + +import unittest + +import stem.descriptor.remote +import stem.directory +import test.require + + +class TestFallback(unittest.TestCase): + @test.require.online + def test_cache_is_up_to_date(self): + """ + Check if the cached fallbacks we bundle are up to date. + """ + + cached_fallback_directories = stem.directory.Fallback.from_cache() + latest_fallback_directories = stem.directory.Fallback.from_remote() + + if cached_fallback_directories != latest_fallback_directories: + self.fail("Stem's cached fallback directories are out of date. Please run 'cache_fallback_directories.py'...\n\n%s" % stem.directory._fallback_directory_differences(cached_fallback_directories, latest_fallback_directories)) + + @test.require.online + def test_fallback_directory_reachability(self): + """ + Fetch information from each fallback directory to confirm that it's + available. + """ + + # Don't run this test by default. Once upon a time it was fine, but tor has + # added so many fallbacks now that this takes a looong time. :( + + self.skipTest('(skipped by default)') + return + + unsuccessful = {} + downloader = stem.descriptor.remote.DescriptorDownloader() + moria1_v3ident = stem.directory.Authority.from_cache()['moria1'].v3ident + + for fallback_directory in stem.directory.Fallback.from_cache().values(): + try: + downloader.get_key_certificates(authority_v3idents = moria1_v3ident, endpoints = [(fallback_directory.address, fallback_directory.dir_port)]).run() + except Exception as exc: + unsuccessful[fallback_directory] = exc + + if unsuccessful: + lines = ['We were unable to contact the following fallback directories...\n'] + + for fallback_directory, exc in unsuccessful.items(): + lines.append('* %s:%s (%s): %s' % (fallback_directory.address, fallback_directory.dir_port, fallback_directory.fingerprint, exc)) + + self.fail('\n'.join(lines)) diff --git a/test/settings.cfg b/test/settings.cfg index 312e3ce9..bd99a9d2 100644 --- a/test/settings.cfg +++ b/test/settings.cfg @@ -256,6 +256,8 @@ test.integ_tests |test.integ.interpreter.TestInterpreter |test.integ.version.TestVersion |test.integ.manual.TestManual +|test.integ.directory.authority.TestAuthority +|test.integ.directory.fallback.TestFallback |test.integ.client.connection.TestConnection |test.integ.response.protocolinfo.TestProtocolInfo |test.integ.socket.control_socket.TestControlSocket
tor-commits@lists.torproject.org