From 527e43b68293d05ee9f9ae8b791b9799a033520f Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Mon, 15 Jul 2019 12:11:28 -0400 Subject: [PATCH] Minimal test for get_storage_client --- src/_secureaccesstokenauthorizer/_plugin.py | 8 +++-- .../tests/strategies.py | 7 ++++ .../tests/test_plugin.py | 36 +++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/_secureaccesstokenauthorizer/_plugin.py b/src/_secureaccesstokenauthorizer/_plugin.py index 0350fa7..ba09200 100644 --- a/src/_secureaccesstokenauthorizer/_plugin.py +++ b/src/_secureaccesstokenauthorizer/_plugin.py @@ -72,7 +72,9 @@ class SecureAccessTokenAuthorizer(object): def get_storage_client(self, configuration, announcement, get_rref): - return SecureAccessTokenAuthorizerStorageClient( - get_rref, - lambda: [b"x" * TOKEN_LENGTH], + return succeed( + SecureAccessTokenAuthorizerStorageClient( + get_rref, + lambda: [b"x" * TOKEN_LENGTH], + ) ) diff --git a/src/_secureaccesstokenauthorizer/tests/strategies.py b/src/_secureaccesstokenauthorizer/tests/strategies.py index e3f5e5f..7ecf774 100644 --- a/src/_secureaccesstokenauthorizer/tests/strategies.py +++ b/src/_secureaccesstokenauthorizer/tests/strategies.py @@ -206,3 +206,10 @@ def test_and_write_vectors_for_shares(): # Just for practical purposes... max_size=8, ) + + +def announcements(): + """ + Build announcements for the SecureAccessTokenAuthorizer plugin. + """ + return just({}) diff --git a/src/_secureaccesstokenauthorizer/tests/test_plugin.py b/src/_secureaccesstokenauthorizer/tests/test_plugin.py index 3d83cad..4c62ca7 100644 --- a/src/_secureaccesstokenauthorizer/tests/test_plugin.py +++ b/src/_secureaccesstokenauthorizer/tests/test_plugin.py @@ -47,6 +47,7 @@ from foolscap.ipb import ( from allmydata.interfaces import ( IFoolscapStoragePlugin, IAnnounceableStorageServer, + IStorageServer, ) from twisted.plugin import ( @@ -61,6 +62,7 @@ from twisted.plugins.secureaccesstokenauthorizer import ( from .strategies import ( configurations, + announcements, ) from .matchers import ( Provides, @@ -70,6 +72,10 @@ def get_anonymous_storage_server(): return None +def get_rref(): + return None + + class PluginTests(TestCase): """ Tests for ``twisted.plugins.secureaccesstokenauthorizer.storage_server``. @@ -91,6 +97,12 @@ class PluginTests(TestCase): verifyObject(IFoolscapStoragePlugin, storage_server) + +class ServerPluginTests(TestCase): + """ + Tests for the plugin's implementation of + ``IFoolscapStoragePlugin.get_storage_server``. + """ @given(configurations()) def test_returns_announceable(self, configuration): """ @@ -176,3 +188,27 @@ class PluginTests(TestCase): ), ), ) + + + +class ClientPluginTests(TestCase): + """ + Tests for the plugin's implementation of + ``IFoolscapStoragePlugin.get_storage_client``. + """ + @given(configurations(), announcements()) + def test_interface(self, configuration, announcement): + """ + ``get_storage_client`` returns a ``Deferred`` that fires with an object + which provides ``IStorageServer``. + """ + storage_client_deferred = storage_server.get_storage_client( + configuration, + announcement, + get_rref, + ) + + self.assertThat( + storage_client_deferred, + succeeded(Provides([IStorageServer])), + ) -- GitLab