From 548cf050505f5ed1af61c7f830780893282d337e Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone <exarkun@twistedmatrix.com> Date: Mon, 17 Jun 2019 13:00:27 -0400 Subject: [PATCH] The first semi-real test --- setup.cfg | 6 +++ src/_secureaccesstokenauthorizer/__init__.py | 12 ++--- src/_secureaccesstokenauthorizer/_plugin.py | 4 +- .../_storage_server.py | 21 +++++++- src/_secureaccesstokenauthorizer/api.py | 26 ++++++++++ .../tests/__init__.py | 17 +++++++ .../tests/test_plugin.py | 48 +++++++++++++++++++ .../plugins/secureaccesstokenauthorizer.py | 2 +- 8 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 src/_secureaccesstokenauthorizer/api.py create mode 100644 src/_secureaccesstokenauthorizer/tests/__init__.py create mode 100644 src/_secureaccesstokenauthorizer/tests/test_plugin.py diff --git a/setup.cfg b/setup.cfg index b26f51c..e2df42d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -27,4 +27,10 @@ package_dir = # the plugins package we want to ship. packages = _secureaccesstokenauthorizer + _secureaccesstokenauthorizer.tests twisted.plugins + +install_requires = + zope.interface + twisted + tahoe-lafs diff --git a/src/_secureaccesstokenauthorizer/__init__.py b/src/_secureaccesstokenauthorizer/__init__.py index 51b6aad..b796f60 100644 --- a/src/_secureaccesstokenauthorizer/__init__.py +++ b/src/_secureaccesstokenauthorizer/__init__.py @@ -12,12 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = "0.0" - -from ._storage_server import ( - SecureAccessTokenAuthorizerStorageServer, -) +__all__ = [ + "__version__", +] -from ._plugin import ( - SecureAccessTokenAuthorizer, -) +__version__ = "0.0" diff --git a/src/_secureaccesstokenauthorizer/_plugin.py b/src/_secureaccesstokenauthorizer/_plugin.py index 57a8286..ccede20 100644 --- a/src/_secureaccesstokenauthorizer/_plugin.py +++ b/src/_secureaccesstokenauthorizer/_plugin.py @@ -25,7 +25,7 @@ from allmydata.interfaces import ( IFoolscapStoragePlugin, ) -from . import ( +from .api import ( SecureAccessTokenAuthorizerStorageServer, ) @@ -40,7 +40,7 @@ class SecureAccessTokenAuthorizer(object): def get_storage_server(self, configuration, get_anonymous_storage_server): return SecureAccessTokenAuthorizerStorageServer( get_anonymous_storage_server(), - **configuration, + **configuration ) def get_storage_client(self, configuration, announcement): diff --git a/src/_secureaccesstokenauthorizer/_storage_server.py b/src/_secureaccesstokenauthorizer/_storage_server.py index aa5032f..075a0fb 100644 --- a/src/_secureaccesstokenauthorizer/_storage_server.py +++ b/src/_secureaccesstokenauthorizer/_storage_server.py @@ -17,6 +17,25 @@ A Tahoe-LAFS RIStorageServer-alike which authorizes writes and lease updates using a per-call token. """ +from zope.interface import ( + implementer, +) + +from twisted.python.components import ( + proxyForInterface, +) + +from foolscap.constraint import ( + ByteStringConstraint, +) +from foolscap.api import ( + ListOf, +) +from foolscap.remoteinterface import ( + RemoteMethodSchema, + RemoteInterface, +) + from allmydata.interfaces import ( RIStorageServer, ) @@ -43,7 +62,7 @@ def add_tokens(schema): def add_arguments(schema, **kwargs): - new_kwargs = dict(**zip(schema.argumentNames, schema.argConstraints)) + new_kwargs = schema.argConstraints.copy() new_kwargs.update(kwargs) modified_schema = RemoteMethodSchema(**new_kwargs) return modified_schema diff --git a/src/_secureaccesstokenauthorizer/api.py b/src/_secureaccesstokenauthorizer/api.py new file mode 100644 index 0000000..6ccb378 --- /dev/null +++ b/src/_secureaccesstokenauthorizer/api.py @@ -0,0 +1,26 @@ +# Copyright 2019 PrivateStorage.io, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +__all__ = [ + "SecureAccessTokenAuthorizerStorageServer", + "SecureAccessTokenAuthorizer", +] + +from ._storage_server import ( + SecureAccessTokenAuthorizerStorageServer, +) + +from ._plugin import ( + SecureAccessTokenAuthorizer, +) diff --git a/src/_secureaccesstokenauthorizer/tests/__init__.py b/src/_secureaccesstokenauthorizer/tests/__init__.py new file mode 100644 index 0000000..ddc6757 --- /dev/null +++ b/src/_secureaccesstokenauthorizer/tests/__init__.py @@ -0,0 +1,17 @@ +# Copyright 2019 PrivateStorage.io, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +The automated unit test suite. +""" diff --git a/src/_secureaccesstokenauthorizer/tests/test_plugin.py b/src/_secureaccesstokenauthorizer/tests/test_plugin.py new file mode 100644 index 0000000..21b5e41 --- /dev/null +++ b/src/_secureaccesstokenauthorizer/tests/test_plugin.py @@ -0,0 +1,48 @@ +# Copyright 2019 PrivateStorage.io, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Tests for the Tahoe-LAFS plugin. +""" + +from testtools import ( + TestCase, +) +from testtools.matchers import ( + Contains, +) + +from allmydata.interfaces import ( + IFoolscapStoragePlugin, +) + +from twisted.plugin import ( + getPlugins, +) +from twisted.plugins.secureaccesstokenauthorizer import ( + storage_server, +) + +class PluginTests(TestCase): + """ + Tests for ``twisted.plugins.secureaccesstokenauthorizer.storage_server``. + """ + def test_discoverable(self): + """ + The plugin can be discovered. + """ + self.assertThat( + getPlugins(IFoolscapStoragePlugin), + Contains(storage_server), + ) diff --git a/src/twisted/plugins/secureaccesstokenauthorizer.py b/src/twisted/plugins/secureaccesstokenauthorizer.py index de01bbe..908d022 100644 --- a/src/twisted/plugins/secureaccesstokenauthorizer.py +++ b/src/twisted/plugins/secureaccesstokenauthorizer.py @@ -16,7 +16,7 @@ A drop-in to supply plugins to the Twisted plugin system. """ -from _secureaccesstokenauthorizer import ( +from _secureaccesstokenauthorizer.api import ( SecureAccessTokenAuthorizer, ) -- GitLab