use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class ResendAllIT method transactionsAreReconstructedFromMultipleParties.
@Test
public void transactionsAreReconstructedFromMultipleParties() throws UnsupportedEncodingException, SQLException {
// setup (sending in a tx)
Response sendRawResponse = partyOne.getRestClient().target(partyOne.getQ2TUri()).path("/sendraw").request().header("c11n-from", partyOne.getPublicKey()).header("c11n-to", partyTwo.getPublicKey() + "," + partyThree.getPublicKey()).post(Entity.entity(transactionData, MediaType.APPLICATION_OCTET_STREAM));
URI location = sendRawResponse.getLocation();
String hash = sendRawResponse.readEntity(String.class);
final String encodedHash = URLEncoder.encode(hash, UTF_8.toString());
// delete it from the sender node
final Response deleteReq = partyOne.getRestClient().target(location).request().delete();
assertThat(deleteReq).isNotNull();
assertThat(deleteReq.getStatus()).isEqualTo(204);
// check it is deleted
final Response deleteCheck = partyOne.getRestClient().target(partyOne.getQ2TUri()).path("transaction").path(encodedHash).request().get();
assertThat(deleteCheck).isNotNull();
assertThat(deleteCheck.getStatus()).isEqualTo(404);
// request resend from recipients
final ResendRequest req = new ResendRequest();
req.setType(RESEND_ALL_VALUE);
req.setPublicKey(partyOne.getPublicKey());
final Response resendRequest = vanillaHttpOnlyClient.target(partyTwo.getP2PUri()).path(RESEND_PATH).request().buildPost(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE)).invoke();
assertThat(resendRequest).isNotNull();
assertThat(resendRequest.getStatus()).isEqualTo(200);
final Response resendRequestNode3 = vanillaHttpOnlyClient.target(partyThree.getP2PUri()).path(RESEND_PATH).request().buildPost(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE)).invoke();
assertThat(resendRequestNode3).isNotNull();
assertThat(resendRequestNode3.getStatus()).isEqualTo(200);
final String fetch = "SELECT ENCODED_PAYLOAD, PAYLOAD_CODEC FROM ENCRYPTED_TRANSACTION WHERE HASH = ?";
final Connection databaseConnection = PartyHelper.create().findByPublicKey(partyOne.getPublicKey()).getDatabaseConnection();
try (PreparedStatement statement = databaseConnection.prepareStatement(fetch)) {
statement.setBytes(1, Base64.getDecoder().decode(hash));
try (ResultSet rs = statement.executeQuery()) {
assertThat(rs.next()).isTrue();
final byte[] output = rs.getBytes(1);
final EncodedPayloadCodec codec = EncodedPayloadCodec.valueOf(rs.getString(2));
final PayloadEncoder encoderToUse = PayloadEncoder.create(codec);
final EncodedPayload payload = encoderToUse.decode(output);
assertThat(payload.getRecipientKeys()).hasSize(3);
assertThat(payload.getSenderKey().encodeToBase64()).isEqualTo(partyOne.getPublicKey());
assertThat(payload.getRecipientBoxes()).hasSize(3);
}
}
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class ResendIndividualIT method resendTransactionsForGivenKey.
@Test
public void resendTransactionsForGivenKey() {
final ResendRequest request = new ResendRequest();
request.setType(RESEND_INDIVIDUAL_VALUE);
request.setKey(this.hash);
request.setPublicKey(recipient.getPublicKey());
final Response response = vanillaHttpOnlyClient.target(sender.getP2PUri()).path(RESEND_PATH).request().post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
final byte[] returnValue = response.readEntity(byte[].class);
final EncodedPayload payload = ENCODER.decode(returnValue);
assertThat(payload).isNotNull();
assertThat(payload.getRecipientKeys()).hasSize(1);
assertThat(payload.getRecipientKeys().get(0).encodeToBase64()).isEqualTo(recipient.getPublicKey());
assertThat(payload.getSenderKey().encodeToBase64()).isEqualTo(sender.getPublicKey());
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class ResendIndividualIT method resendTransactionThatDoesntExist.
@Test
public void resendTransactionThatDoesntExist() {
final String unknownHash = "2xTEBlTtYXSBXZD4jDDp83cVJbnkzP6PbUoUJx076BO/FSR75NXwDDpLDu3AIiDV1TlK8nGK4mlhsg4Xzpd5og==";
final ResendRequest request = new ResendRequest();
request.setType(RESEND_INDIVIDUAL_VALUE);
request.setKey(unknownHash);
request.setPublicKey(partyHelper.getParties().filter(p -> !p.equals(sender)).filter(p -> !p.equals(recipient)).findAny().get().getPublicKey());
final Response response = vanillaHttpOnlyClient.target(recipient.getP2PUri()).path(RESEND_PATH).request().post(Entity.entity(request, MediaType.APPLICATION_JSON_TYPE));
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(404);
assertThat(response.readEntity(String.class)).contains("Message with hash " + unknownHash + " was not found");
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class RestRecoveryClientTest method makeResendRequest.
@Test
public void makeResendRequest() {
try (var entityMockedStatic = mockStatic(Entity.class)) {
Entity<ResendRequest> outboundEntity = mock(Entity.class);
ResendRequest resendRequest = mock(ResendRequest.class);
entityMockedStatic.when(() -> Entity.entity(resendRequest, MediaType.APPLICATION_JSON)).thenReturn(outboundEntity);
String targetUrl = "targetUrl";
Client client = mock(Client.class);
WebTarget webTarget = mock(WebTarget.class);
when(client.target(targetUrl)).thenReturn(webTarget);
when(webTarget.path("/resend")).thenReturn(webTarget);
Invocation.Builder invocationBuilder = mock(Invocation.Builder.class);
when(webTarget.request()).thenReturn(invocationBuilder);
Response response = mock(Response.class);
when(response.getStatus()).thenReturn(expectedResponseStatus.getStatusCode());
when(invocationBuilder.post(outboundEntity)).thenReturn(response);
RestRecoveryClient restRecoveryClient = new RestRecoveryClient(client);
boolean outcome = restRecoveryClient.makeResendRequest(targetUrl, resendRequest);
if (expectedResponseStatus == Response.Status.OK) {
assertThat(outcome).isTrue();
} else {
assertThat(outcome).isFalse();
}
entityMockedStatic.verify(() -> Entity.entity(resendRequest, MediaType.APPLICATION_JSON));
entityMockedStatic.verifyNoMoreInteractions();
verify(client).target(targetUrl);
verify(webTarget).path("/resend");
verify(webTarget).request();
verify(invocationBuilder).post(outboundEntity);
verifyNoMoreInteractions(outboundEntity, resendRequest, client, webTarget, invocationBuilder);
}
}
use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.
the class RestBatchTransactionRequester method createLegacyRequest.
/**
* Creates the legacy entity that should be sent to the legacy target URL
*
* @param key the public key that transactions should be resent for
* @return the request to be sent
*/
private ResendRequest createLegacyRequest(final PublicKey key) {
final ResendRequest request = new ResendRequest();
final String encoded = key.encodeToBase64();
request.setPublicKey(encoded);
request.setType("ALL");
return request;
}
Aggregations