diff --git a/src/_secureaccesstokenauthorizer/_storage_client.py b/src/_secureaccesstokenauthorizer/_storage_client.py index ff86d26d39ace4797923a9ff16b217e3ae4145ed..309eaab8c53023afc01a0110bea42bbad734b9be 100644 --- a/src/_secureaccesstokenauthorizer/_storage_client.py +++ b/src/_secureaccesstokenauthorizer/_storage_client.py @@ -127,6 +127,7 @@ class SecureAccessTokenAuthorizerStorageClient(object): ): return self._rref.callRemote( "slot_testv_and_readv_and_writev", + self._get_tokens(), storage_index, secrets, tw_vectors, diff --git a/src/_secureaccesstokenauthorizer/_storage_server.py b/src/_secureaccesstokenauthorizer/_storage_server.py index 72ccd37f11e26a52df8b67e61de552af92462ebf..e6425120c1f48007ea9d62317e363fefe34e14ab 100644 --- a/src/_secureaccesstokenauthorizer/_storage_server.py +++ b/src/_secureaccesstokenauthorizer/_storage_server.py @@ -63,14 +63,32 @@ def add_tokens(schema): :return foolscap.remoteinterface.RemoteMethodSchema: A schema like ``schema`` but with one additional required argument. """ - return add_arguments(schema, tokens=TokenList) + return add_arguments(schema, [(b"tokens", TokenList)]) +def add_arguments(schema, kwargs): + """ + Create a new schema like ``schema`` but with the arguments given by + ``kwargs`` prepended to the signature. + + :param foolscap.remoteinterface.RemoteMethodSchema schema: The existing + schema. + + :param list[(bytes, foolscap.IConstraint)] kwargs: The arguments to + prepend to the signature of ``schema``. -def add_arguments(schema, **kwargs): - new_kwargs = schema.argConstraints.copy() + :return foolscap.remoteinterface.RemoteMethodSchema: The new schema + object. + """ + new_kwargs = dict(schema.argConstraints) new_kwargs.update(kwargs) modified_schema = RemoteMethodSchema(**new_kwargs) + # Initialized from **new_kwargs, RemoteMethodSchema.argumentNames is in + # some arbitrary, probably-incorrect order. Fix it. + modified_schema.argumentNames = ( + list(argName for (argName, _) in kwargs) + + schema.argumentNames + ) return modified_schema @@ -129,7 +147,8 @@ class SecureAccessTokenAuthorizerStorageServer(Referenceable): def remote_advise_corrupt_share(self, *a, **kw): return self._original.remote_advise_corrupt_share(*a, **kw) - def remote_slot_testv_and_readv_and_writev(self, *a, **kw): + def remote_slot_testv_and_readv_and_writev(self, tokens, *a, **kw): + self._validate_tokens(tokens) return self._original.remote_slot_testv_and_readv_and_writev(*a, **kw) def remote_slot_readv(self, *a, **kw): diff --git a/src/_secureaccesstokenauthorizer/tests/test_storage_protocol.py b/src/_secureaccesstokenauthorizer/tests/test_storage_protocol.py index a2fdbefcc8d406079a06d40f95a385348146a63b..106585b5b61832b365646bb1b494100d4543a52c 100644 --- a/src/_secureaccesstokenauthorizer/tests/test_storage_protocol.py +++ b/src/_secureaccesstokenauthorizer/tests/test_storage_protocol.py @@ -77,6 +77,9 @@ from ..api import ( SecureAccessTokenAuthorizerStorageServer, SecureAccessTokenAuthorizerStorageClient, ) +from .._storage_server import ( + TOKEN_LENGTH, +) class AnonymousStorageServer(Fixture): def _setUp(self): @@ -113,7 +116,7 @@ class ShareTests(TestCase): self.anonymous_storage_server = self.useFixture(AnonymousStorageServer()).storage_server def get_tokens(): - return [u"x"] + return [b"x" * TOKEN_LENGTH] self.server = SecureAccessTokenAuthorizerStorageServer( self.anonymous_storage_server, @@ -299,10 +302,10 @@ class ShareTests(TestCase): extract_result( self.client.advise_corrupt_share( - u"immutable", + b"immutable", storage_index, sharenum, - u"the bits look bad", + b"the bits look bad", ), ) self.assertThat(