From 77f405ce8cc5d19c7e09cf29979893ef8bcb5b98 Mon Sep 17 00:00:00 2001 From: David Fuelling Date: Fri, 27 Mar 2020 15:10:06 -0600 Subject: [PATCH] Cleanup SPSP Headers (#439) * Cleanup SPSP headers for publicly accessibility Signed-off-by: David Fuelling * Cleanup SPSP headers. Signed-off-by: David Fuelling * Update header name Signed-off-by: David Fuelling --- .../spsp/client/SimpleSpspClient.java | 2 +- .../interledger/spsp/client/SpspClient.java | 23 +++++++++++++------ .../spsp/client/SimpleSpspClientTest.java | 13 +++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java index e85e4978..b56a2ce1 100644 --- a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java +++ b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SimpleSpspClient.java @@ -51,7 +51,7 @@ public StreamConnectionDetails getStreamConnectionDetails(final HttpUrl spspUrl) return execute(new Request.Builder() .url(spspUrl) - .header("Accept", ACCEPT_SPSP_JSON) + .header("Accept", APPLICATION_SPSP4_JSON_VALUE) .get() .build(), StreamConnectionDetails.class); } diff --git a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java index 6d4e1ed1..fbeaa6ae 100644 --- a/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java +++ b/spsp-parent/spsp-client/src/main/java/org/interledger/spsp/client/SpspClient.java @@ -12,26 +12,35 @@ */ public interface SpspClient { - String ACCEPT_SPSP_JSON = "application/spsp4+json, application/spsp+json"; + /** + * The Java, JS, Rafiki, and Rust SPSP servers all respond properly to this header. + */ + String APPLICATION_SPSP4_JSON_VALUE = "application/spsp4+json"; /** - * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given pointer). - * Typically used for setting up a STREAM connection. - * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint" + * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given pointer). Typically used + * for setting up a STREAM connection. + * * @param paymentPointer payment pointer to query on + * * @return stream connection details + * * @throws InvalidReceiverClientException thrown if the payment pointer does not point to a valid account + * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint" */ StreamConnectionDetails getStreamConnectionDetails(PaymentPointer paymentPointer) throws InvalidReceiverClientException; /** - * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given SPSP url). - * Typically used for setting up a STREAM connection. - * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint" + * Calls SPSP endpoint to obtain address and secret needed to setup a payment (for the given SPSP url). Typically used + * for setting up a STREAM connection. + * * @param spspUrl url for the SPSP account endpoint + * * @return stream connection details + * * @throws InvalidReceiverClientException thrown if the payment pointer does not point to a valid account + * @see "https://github.com/interledger/rfcs/blob/master/0009-simple-payment-setup-protocol/0009-simple-payment-setup-protocol.md#query-get-spsp-endpoint" */ StreamConnectionDetails getStreamConnectionDetails(HttpUrl spspUrl) throws InvalidReceiverClientException; diff --git a/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java b/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java index ec4c0db9..ec7a7ec4 100644 --- a/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java +++ b/spsp-parent/spsp-client/src/test/java/org/interledger/spsp/client/SimpleSpspClientTest.java @@ -39,7 +39,7 @@ public void getStreamConnectionDetailsFromPaymentPointer() { String wiremockIlpAddress = "test.wiremock"; stubFor(get(urlEqualTo("/" + testClient)) - .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON)) + .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE)) .willReturn(aResponse() .withStatus(200) .withBody("{\"destination_account\":\"" + wiremockIlpAddress + "." + testClient + "\"," @@ -63,7 +63,7 @@ public void getStreamConnectionDetailsFromUrl() { String wiremockIlpAddress = "test.wiremock"; stubFor(get(urlEqualTo("/" + testClient)) - .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON)) + .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE)) .willReturn(aResponse() .withStatus(200) .withBody("{\"destination_account\":\"" + wiremockIlpAddress + "." + testClient + "\"," @@ -85,7 +85,7 @@ public void getStreamConnectionDetails404ThrowsInvalidReceiver() { String testClient = "testClient"; stubFor(get(urlEqualTo("/" + testClient)) - .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON)) + .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE)) .willReturn(aResponse() .withStatus(404) )); @@ -98,7 +98,7 @@ public void getStreamConnectionDetails500ThrowsSpspClientException() { String testClient = "testClient"; stubFor(get(urlEqualTo("/" + testClient)) - .withHeader("Accept", equalTo(SpspClient.ACCEPT_SPSP_JSON)) + .withHeader("Accept", equalTo(SpspClient.APPLICATION_SPSP4_JSON_VALUE)) .willReturn(aResponse() .withStatus(503) )); @@ -106,6 +106,11 @@ public void getStreamConnectionDetails500ThrowsSpspClientException() { client.getStreamConnectionDetails(paymentPointer(testClient)); } + @Test + public void testHeaders() { + assertThat(SpspClient.APPLICATION_SPSP4_JSON_VALUE).isEqualTo("application/spsp4+json"); + } + private PaymentPointer paymentPointer(String testClient) { return PaymentPointer.of("$test.wiremock/" + testClient); }