diff --git a/docs/source/interface.rst b/docs/source/interface.rst index 74881dc4933192477b16e4a471603b69d27312db..909d05e134e68cb75c0640e28baf395700fd8b13 100644 --- a/docs/source/interface.rst +++ b/docs/source/interface.rst @@ -7,14 +7,14 @@ Client When enabled in a Tahoe-LAFS client node, SecureAccessTokenAuthorizer publishes an HTTP-based interface inside the main Tahoe-LAFS web interface. -``PUT /storage-plugins/privatestorageio-satauthz-v1/payment-reference-number`` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``PUT /storage-plugins/privatestorageio-satauthz-v1/voucher`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This endpoint allows an external agent which has submitted a payment to cause the plugin to redeem the voucher for tokens. The request body for this endpoint must have the ``application/json`` content-type. The request body contains a simple json object containing the voucher:: - {"payment-reference-number": "<voucher>"} + {"voucher": "<voucher>"} The endpoint responds to such a request with an **OK** HTTP response code if the voucher is accepted for processing. If the voucher cannot be accepted at the time of the request then the response code will be anything other than **OK**. @@ -22,8 +22,8 @@ If the voucher cannot be accepted at the time of the request then the response c If the response is **OK** then a repeated request with the same body will have no effect. If the response is not **OK** then a repeated request with the same body will try to accept the number again. -``GET /storage-plugins/privatestorageio-satauthz-v1/payment-reference-number/<voucher>`` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``GET /storage-plugins/privatestorageio-satauthz-v1/voucher/<voucher>`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This endpoint allows an external agent to monitor the status of the redemption of a voucher. This endpoint accepts no request body. @@ -37,14 +37,14 @@ the response is **OK** with an ``application/json`` content-type response body l The ``value`` property merely indicates the voucher which was requested. Further properties will be added to this response in the near future. -``GET /storage-plugins/privatestorageio-satauthz-v1/payment-reference-number`` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``GET /storage-plugins/privatestorageio-satauthz-v1/voucher`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This endpoint allows an external agent to retrieve the status of all vouchers. This endpoint accepts no request body. The response is **OK** with ``application/json`` content-type response body like:: - {"payment-reference-numbers": [<voucher status object>, ...]} + {"vouchers": [<voucher status object>, ...]} The elements of the list are objects like the one returned by issuing a **GET** to a child of this collection resource. diff --git a/src/_secureaccesstokenauthorizer/resource.py b/src/_secureaccesstokenauthorizer/resource.py index 8a9c2154fe6212e3963b8a085010ce7268f1f058..0d4e1bb561e5fa5913dc171fb593ca49563025d5 100644 --- a/src/_secureaccesstokenauthorizer/resource.py +++ b/src/_secureaccesstokenauthorizer/resource.py @@ -68,7 +68,7 @@ def from_configuration(node_config, store=None): controller = PaymentController(store) root = Resource() root.putChild( - b"payment-reference-number", + b"voucher", _PaymentReferenceNumberCollection( store, controller, @@ -98,9 +98,9 @@ class _PaymentReferenceNumberCollection(Resource): payload = loads(request.content.read()) except Exception: return bad_request().render(request) - if payload.keys() != [u"payment-reference-number"]: + if payload.keys() != [u"voucher"]: return bad_request().render(request) - prn = payload[u"payment-reference-number"] + prn = payload[u"voucher"] if not is_syntactic_prn(prn): return bad_request().render(request) @@ -111,7 +111,7 @@ class _PaymentReferenceNumberCollection(Resource): def render_GET(self, request): request.responseHeaders.setRawHeaders(u"content-type", [u"application/json"]) return dumps({ - u"payment-reference-numbers": list( + u"vouchers": list( prn.marshal() for prn in self._store.list() diff --git a/src/_secureaccesstokenauthorizer/tests/strategies.py b/src/_secureaccesstokenauthorizer/tests/strategies.py index ad9b2a47d905d32d682e3300f2268819485b18d3..c56b8cecef8a8ee4f417d30e63b86956b0c52315 100644 --- a/src/_secureaccesstokenauthorizer/tests/strategies.py +++ b/src/_secureaccesstokenauthorizer/tests/strategies.py @@ -161,7 +161,7 @@ def client_configurations(): return just({}) -def payment_reference_numbers(): +def vouchers(): """ Build unicode strings in the format of vouchers. """ diff --git a/src/_secureaccesstokenauthorizer/tests/test_client_resource.py b/src/_secureaccesstokenauthorizer/tests/test_client_resource.py index 6eb2f7227b2bac8bf3654e41533e584788d24127..0b42c1d840567caf21d0a796cd0072939da4dfff 100644 --- a/src/_secureaccesstokenauthorizer/tests/test_client_resource.py +++ b/src/_secureaccesstokenauthorizer/tests/test_client_resource.py @@ -102,7 +102,7 @@ from ..resource import ( from .strategies import ( tahoe_configs, client_configurations, - payment_reference_numbers, + vouchers, requests, ) from .matchers import ( @@ -136,7 +136,7 @@ def is_not_json(bytestring): return True return False -def not_payment_reference_numbers(): +def not_vouchers(): """ Builds unicode strings which are not legal vouchers. """ @@ -146,7 +146,7 @@ def not_payment_reference_numbers(): not is_urlsafe_base64(t) ), ), - payment_reference_numbers().map( + vouchers().map( # Turn a valid voucher into a voucher that is invalid only by # containing a character from the base64 alphabet in place of one # from the urlsafe-base64 alphabet. @@ -169,19 +169,18 @@ def is_urlsafe_base64(text): def invalid_bodies(): """ - Build byte strings that ``PUT /payment-reference-number`` considers - invalid. + Build byte strings that ``PUT /voucher`` considers invalid. """ return one_of( # The wrong key but the right kind of value. fixed_dictionaries({ - u"some-key": payment_reference_numbers(), + u"some-key": vouchers(), }).map(dumps), # The right key but the wrong kind of value. fixed_dictionaries({ - u"payment-reference-number": one_of( + u"voucher": one_of( integers(), - not_payment_reference_numbers(), + not_vouchers(), ), }).map(dumps), # Not even JSON @@ -208,7 +207,7 @@ def root_from_config(config): class PaymentReferenceNumberTests(TestCase): """ - Tests relating to ``/payment-reference-number`` as implemented by the + Tests relating to ``/voucher`` as implemented by the ``_secureaccesstokenauthorizer.resource`` module and its handling of vouchers. """ @@ -217,11 +216,11 @@ class PaymentReferenceNumberTests(TestCase): self.useFixture(CaptureTwistedLogs()) - @given(tahoe_configs_with_client_config, requests(just([u"payment-reference-number"]))) + @given(tahoe_configs_with_client_config, requests(just([u"voucher"]))) def test_reachable(self, get_config, request): """ - A resource is reachable at the ``payment-reference-number`` child of a the - resource returned by ``from_configuration``. + A resource is reachable at the ``voucher`` child of a the resource + returned by ``from_configuration``. """ tempdir = self.useFixture(TempDir()) config = get_config(tempdir.join(b"tahoe"), b"tub.port") @@ -232,7 +231,7 @@ class PaymentReferenceNumberTests(TestCase): ) - @given(tahoe_configs_with_client_config, payment_reference_numbers()) + @given(tahoe_configs_with_client_config, vouchers()) def test_put_prn(self, get_config, prn): """ When a voucher is ``PUT`` to ``PaymentReferenceNumberCollection`` it is @@ -244,12 +243,12 @@ class PaymentReferenceNumberTests(TestCase): root = root_from_config(config) agent = RequestTraversalAgent(root) producer = FileBodyProducer( - BytesIO(dumps({u"payment-reference-number": prn})), + BytesIO(dumps({u"voucher": prn})), cooperator=uncooperator(), ) requesting = agent.request( b"PUT", - b"http://127.0.0.1/payment-reference-number", + b"http://127.0.0.1/voucher", bodyProducer=producer, ) self.addDetail( @@ -267,8 +266,8 @@ class PaymentReferenceNumberTests(TestCase): def test_put_invalid_body(self, get_config, body): """ If the body of a ``PUT`` to ``PaymentReferenceNumberCollection`` does not - consist of an object with a single *payment-reference-number* property - then the response is *BAD REQUEST*. + consist of an object with a single *voucher* property then the + response is *BAD REQUEST*. """ tempdir = self.useFixture(TempDir()) config = get_config(tempdir.join(b"tahoe"), b"tub.port") @@ -280,7 +279,7 @@ class PaymentReferenceNumberTests(TestCase): ) requesting = agent.request( b"PUT", - b"http://127.0.0.1/payment-reference-number", + b"http://127.0.0.1/voucher", bodyProducer=producer, ) self.addDetail( @@ -294,7 +293,7 @@ class PaymentReferenceNumberTests(TestCase): ), ) - @given(tahoe_configs_with_client_config, not_payment_reference_numbers()) + @given(tahoe_configs_with_client_config, not_vouchers()) def test_get_invalid_prn(self, get_config, not_prn): """ When a syntactically invalid voucher is requested with a ``GET`` to a @@ -305,7 +304,7 @@ class PaymentReferenceNumberTests(TestCase): config = get_config(tempdir.join(b"tahoe"), b"tub.port") root = root_from_config(config) agent = RequestTraversalAgent(root) - url = u"http://127.0.0.1/payment-reference-number/{}".format( + url = u"http://127.0.0.1/voucher/{}".format( quote( not_prn.encode("utf-8"), safe=b"", @@ -323,7 +322,7 @@ class PaymentReferenceNumberTests(TestCase): ) - @given(tahoe_configs_with_client_config, payment_reference_numbers()) + @given(tahoe_configs_with_client_config, vouchers()) def test_get_unknown_prn(self, get_config, prn): """ When a voucher is requested with a ``GET`` to a child of @@ -336,7 +335,7 @@ class PaymentReferenceNumberTests(TestCase): agent = RequestTraversalAgent(root) requesting = agent.request( b"GET", - u"http://127.0.0.1/payment-reference-number/{}".format(prn).encode("ascii"), + u"http://127.0.0.1/voucher/{}".format(prn).encode("ascii"), ) self.assertThat( requesting, @@ -346,7 +345,7 @@ class PaymentReferenceNumberTests(TestCase): ) - @given(tahoe_configs_with_client_config, payment_reference_numbers()) + @given(tahoe_configs_with_client_config, vouchers()) def test_get_known_prn(self, get_config, prn): """ When a voucher is first ``PUT`` and then later a ``GET`` is issued for the @@ -359,12 +358,12 @@ class PaymentReferenceNumberTests(TestCase): agent = RequestTraversalAgent(root) producer = FileBodyProducer( - BytesIO(dumps({u"payment-reference-number": prn})), + BytesIO(dumps({u"voucher": prn})), cooperator=uncooperator(), ) putting = agent.request( b"PUT", - b"http://127.0.0.1/payment-reference-number", + b"http://127.0.0.1/voucher", bodyProducer=producer, ) self.assertThat( @@ -376,7 +375,7 @@ class PaymentReferenceNumberTests(TestCase): getting = agent.request( b"GET", - u"http://127.0.0.1/payment-reference-number/{}".format( + u"http://127.0.0.1/voucher/{}".format( quote( prn.encode("utf-8"), safe=b"", @@ -402,7 +401,7 @@ class PaymentReferenceNumberTests(TestCase): ), ) - @given(tahoe_configs_with_client_config, lists(payment_reference_numbers(), unique=True)) + @given(tahoe_configs_with_client_config, lists(vouchers(), unique=True)) def test_list_prns(self, get_config, prns): """ A ``GET`` to the ``PaymentReferenceNumberCollection`` itself returns a @@ -421,12 +420,12 @@ class PaymentReferenceNumberTests(TestCase): for prn in prns: producer = FileBodyProducer( - BytesIO(dumps({u"payment-reference-number": prn})), + BytesIO(dumps({u"voucher": prn})), cooperator=uncooperator(), ) putting = agent.request( b"PUT", - b"http://127.0.0.1/payment-reference-number", + b"http://127.0.0.1/voucher", bodyProducer=producer, ) self.assertThat( @@ -438,7 +437,7 @@ class PaymentReferenceNumberTests(TestCase): getting = agent.request( b"GET", - b"http://127.0.0.1/payment-reference-number", + b"http://127.0.0.1/voucher", ) self.assertThat( @@ -450,7 +449,7 @@ class PaymentReferenceNumberTests(TestCase): json_content, succeeded( Equals({ - u"payment-reference-numbers": list( + u"vouchers": list( {u"version": 1, u"number": prn} for prn in prns diff --git a/src/_secureaccesstokenauthorizer/tests/test_model.py b/src/_secureaccesstokenauthorizer/tests/test_model.py index 052f5e6fd5f0e2341ba6a28d2eefcbe9d3747b44..cd427788cf49008caacf453b41d3fe8c638036d7 100644 --- a/src/_secureaccesstokenauthorizer/tests/test_model.py +++ b/src/_secureaccesstokenauthorizer/tests/test_model.py @@ -63,7 +63,7 @@ from ..model import ( from .strategies import ( tahoe_configs, - payment_reference_numbers, + vouchers, ) @@ -87,7 +87,7 @@ class PaymentReferenceStoreTests(TestCase): ) - @given(tahoe_configs(), payment_reference_numbers()) + @given(tahoe_configs(), vouchers()) def test_get_missing(self, get_config, prn): """ ``PaymentReferenceStore.get`` raises ``KeyError`` when called with a @@ -104,7 +104,7 @@ class PaymentReferenceStoreTests(TestCase): raises(KeyError), ) - @given(tahoe_configs(), payment_reference_numbers()) + @given(tahoe_configs(), vouchers()) def test_add(self, get_config, prn): """ ``PaymentReferenceStore.get`` returns a ``PaymentReference`` representing @@ -126,7 +126,7 @@ class PaymentReferenceStoreTests(TestCase): ), ) - @given(tahoe_configs(), payment_reference_numbers()) + @given(tahoe_configs(), vouchers()) def test_add_idempotent(self, get_config, prn): """ More than one call to ``PaymentReferenceStore.add`` with the same argument @@ -149,7 +149,7 @@ class PaymentReferenceStoreTests(TestCase): ) - @given(tahoe_configs(), lists(payment_reference_numbers())) + @given(tahoe_configs(), lists(vouchers())) def test_list(self, get_config, prns): """ ``PaymentReferenceStore.list`` returns a ``list`` containing a @@ -244,7 +244,7 @@ class PaymentReferenceTests(TestCase): """ Tests for ``PaymentReference``. """ - @given(payment_reference_numbers()) + @given(vouchers()) def test_json_roundtrip(self, prn): """ ``PaymentReference.to_json . PaymentReference.from_json → id``