Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Cleanup SPSP Headers (#439)
Browse files Browse the repository at this point in the history
* Cleanup SPSP headers for publicly accessibility

Signed-off-by: David Fuelling <[email protected]>

* Cleanup SPSP headers.

Signed-off-by: David Fuelling <[email protected]>

* Update header name

Signed-off-by: David Fuelling <[email protected]>
  • Loading branch information
sappenin authored Mar 27, 2020
1 parent fa812ce commit 77f405c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\","
Expand All @@ -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 + "\","
Expand All @@ -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)
));
Expand All @@ -98,14 +98,19 @@ 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)
));

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);
}
Expand Down

0 comments on commit 77f405c

Please sign in to comment.