Search in sources :

Example 11 with ResendRequest

use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.

the class ResendAllIT method transactionFromSenderDoesNotContainDataOfOtherParties.

@Test
public void transactionFromSenderDoesNotContainDataOfOtherParties() 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 a recipient node
    final Response deleteReq = partyTwo.getRestClient().target(partyTwo.getQ2TUri()).path("transaction").path(encodedHash).request().delete();
    assertThat(deleteReq).isNotNull();
    assertThat(deleteReq.getStatus()).isEqualTo(204);
    // check it is deleted
    final Response deleteCheck = partyTwo.getRestClient().target(partyTwo.getQ2TUri()).path("transaction").path(encodedHash).request().get();
    assertThat(deleteCheck).isNotNull();
    assertThat(deleteCheck.getStatus()).isEqualTo(404);
    // request resend from sender
    final ResendRequest req = new ResendRequest();
    req.setType(RESEND_ALL_VALUE);
    req.setPublicKey(partyTwo.getPublicKey());
    final Response resendRequest = vanillaHttpOnlyClient.target(partyOne.getP2PUri()).path(RESEND_PATH).request().buildPost(Entity.entity(req, MediaType.APPLICATION_JSON_TYPE)).invoke();
    assertThat(resendRequest).isNotNull();
    assertThat(resendRequest.getStatus()).isEqualTo(200);
    final String fetch = "SELECT ENCODED_PAYLOAD, PAYLOAD_CODEC FROM ENCRYPTED_TRANSACTION WHERE HASH = ?";
    final Connection databaseConnection = PartyHelper.create().findByPublicKey(partyTwo.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(1);
            assertThat(payload.getRecipientKeys().get(0).encodeToBase64()).isEqualTo(partyTwo.getPublicKey());
            assertThat(payload.getSenderKey().encodeToBase64()).isEqualTo(partyOne.getPublicKey());
            assertThat(payload.getRecipientBoxes()).hasSize(1);
        }
    }
}
Also used : Response(jakarta.ws.rs.core.Response) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) URI(java.net.URI) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) Test(org.junit.Test)

Example 12 with ResendRequest

use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.

the class ResendIndividualIT method resendTransactionForIncorrectKey.

@Test
public void resendTransactionForIncorrectKey() {
    final ResendRequest request = new ResendRequest();
    request.setType(RESEND_INDIVIDUAL_VALUE);
    request.setKey(this.hash);
    Party anyOtherParty = partyHelper.getParties().filter(p -> !p.equals(sender)).filter(p -> !p.equals(recipient)).findAny().get();
    request.setPublicKey(anyOtherParty.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(500);
    assertThat(response.readEntity(String.class)).contains("Recipient " + anyOtherParty.getPublicKey() + " is not a recipient of transaction");
}
Also used : Client(jakarta.ws.rs.client.Client) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PayloadEncoderImpl(com.quorum.tessera.enclave.PayloadEncoderImpl) Test(org.junit.Test) PayloadEncoder(com.quorum.tessera.enclave.PayloadEncoder) PartyHelper(com.quorum.tessera.test.PartyHelper) Entity(jakarta.ws.rs.client.Entity) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType) Party(com.quorum.tessera.test.Party) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) ClientBuilder(jakarta.ws.rs.client.ClientBuilder) Before(org.junit.Before) Response(jakarta.ws.rs.core.Response) Party(com.quorum.tessera.test.Party) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Example 13 with ResendRequest

use of com.quorum.tessera.p2p.resend.ResendRequest in project tessera by ConsenSys.

the class ResendIndividualIT method resendTransactionWhereKeyIsSender.

@Test
public void resendTransactionWhereKeyIsSender() {
    final ResendRequest request = new ResendRequest();
    request.setType(RESEND_INDIVIDUAL_VALUE);
    request.setKey(this.hash);
    request.setPublicKey(sender.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(200);
    final byte[] returnValue = response.readEntity(byte[].class);
    final EncodedPayload payload = ENCODER.decode(returnValue);
    assertThat(payload).isNotNull();
    assertThat(payload.getRecipientKeys().get(0).encodeToBase64()).isEqualTo(recipient.getPublicKey());
    assertThat(payload.getSenderKey().encodeToBase64()).isEqualTo(sender.getPublicKey());
}
Also used : Response(jakarta.ws.rs.core.Response) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Aggregations

ResendRequest (com.quorum.tessera.p2p.resend.ResendRequest)13 Response (jakarta.ws.rs.core.Response)12 Test (org.junit.Test)12 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)7 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)4 Client (jakarta.ws.rs.client.Client)4 URI (java.net.URI)3 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)2 PayloadEncoderImpl (com.quorum.tessera.enclave.PayloadEncoderImpl)2 Party (com.quorum.tessera.test.Party)2 PartyHelper (com.quorum.tessera.test.PartyHelper)2 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 Entity (jakarta.ws.rs.client.Entity)2 Invocation (jakarta.ws.rs.client.Invocation)2 WebTarget (jakarta.ws.rs.client.WebTarget)2 MediaType (jakarta.ws.rs.core.MediaType)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2