Search in sources :

Example 86 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class PartyInfoResourceTest method validateReturns400IfMessageIsNotUUID.

@Test
public void validateReturns400IfMessageIsNotUUID() {
    String message = "I love sparrows";
    byte[] payload = message.getBytes();
    PublicKey myKey = PublicKey.from("myKey".getBytes());
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getRecipientKeys()).thenReturn(Collections.singletonList(myKey));
    when(payloadEncoder.decode(payload)).thenReturn(encodedPayload);
    when(enclave.unencryptTransaction(encodedPayload, myKey)).thenReturn(message.getBytes());
    Response result = partyInfoResource.validate(payload);
    assertThat(result.getStatus()).isEqualTo(400);
    assertThat(result.getEntity()).isNull();
    verify(payloadEncoder).decode(payload);
    verify(enclave).unencryptTransaction(encodedPayload, myKey);
}
Also used : Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 87 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class RecoveryResourceTest method pushAllowedForStandardPrivate.

@Test
public void pushAllowedForStandardPrivate() {
    final byte[] someData = "SomeData".getBytes();
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(payloadEncoder.decode(someData)).thenReturn(payload);
    final Response result = recoveryResource.push(someData, null);
    assertThat(result.getStatus()).isEqualTo(201);
    assertThat(result.hasEntity()).isTrue();
    verify(transactionManager).storePayload(payload);
    verify(payloadEncoder).decode(someData);
    payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
Also used : Response(jakarta.ws.rs.core.Response) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 88 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class TransactionResourceTest method push.

@Test
public void push() {
    final byte[] someData = "SomeData".getBytes();
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payloadEncoder.decode(someData)).thenReturn(payload);
    final Response result = transactionResource.push(someData, List.of("4.0,5.0"));
    assertThat(result.getStatus()).isEqualTo(201);
    assertThat(result.hasEntity()).isTrue();
    verify(transactionManager).storePayload(payload);
    verify(payloadEncoder).decode(someData);
    payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
Also used : Response(jakarta.ws.rs.core.Response) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 89 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload in project tessera by ConsenSys.

the class TransactionResourceTest method resend.

@Test
public void resend() {
    ResendRequest resendRequest = new ResendRequest();
    resendRequest.setType("ALL");
    resendRequest.setPublicKey(Base64.getEncoder().encodeToString("JUNIT".getBytes()));
    EncodedPayload payload = mock(EncodedPayload.class);
    com.quorum.tessera.recovery.resend.ResendResponse resendResponse = mock(com.quorum.tessera.recovery.resend.ResendResponse.class);
    when(resendResponse.getPayload()).thenReturn(payload);
    when(legacyResendManager.resend(any(com.quorum.tessera.recovery.resend.ResendRequest.class))).thenReturn(resendResponse);
    when(payloadEncoder.encode(payload)).thenReturn("SUCCESS".getBytes());
    Response result = transactionResource.resend(resendRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    assertThat(result.getEntity()).isEqualTo("SUCCESS".getBytes());
    verify(payloadEncoder).encode(payload);
    verify(legacyResendManager).resend(any(com.quorum.tessera.recovery.resend.ResendRequest.class));
    payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
Also used : Response(jakarta.ws.rs.core.Response) ResendBatchResponse(com.quorum.tessera.recovery.resend.ResendBatchResponse) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) ResendRequest(com.quorum.tessera.p2p.resend.ResendRequest) Test(org.junit.Test)

Example 90 with EncodedPayload

use of com.quorum.tessera.enclave.EncodedPayload 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)

Aggregations

EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)91 Test (org.junit.Test)60 PublicKey (com.quorum.tessera.encryption.PublicKey)50 PayloadEncoder (com.quorum.tessera.enclave.PayloadEncoder)23 Response (jakarta.ws.rs.core.Response)20 MessageHash (com.quorum.tessera.data.MessageHash)13 Collectors (java.util.stream.Collectors)12 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)11 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)11 EncodedPayloadCodec (com.quorum.tessera.enclave.EncodedPayloadCodec)9 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)8 Recipient (com.quorum.tessera.partyinfo.node.Recipient)8 java.util (java.util)8 Invocation (jakarta.ws.rs.client.Invocation)6 WebTarget (jakarta.ws.rs.client.WebTarget)6 StagingTransaction (com.quorum.tessera.data.staging.StagingTransaction)5 PrivacyMetadata (com.quorum.tessera.enclave.PrivacyMetadata)5 RecipientBox (com.quorum.tessera.enclave.RecipientBox)5 TxHash (com.quorum.tessera.enclave.TxHash)5 ResendRequest (com.quorum.tessera.p2p.resend.ResendRequest)5