Search in sources :

Example 26 with EncodedPayload

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

the class SearchRecipientKeyForPayloadTest method executeHandleEnclaveExceptions.

@Test
public void executeHandleEnclaveExceptions() {
    final List<Class<? extends Exception>> handledExceptionTypes = List.of(EnclaveNotAvailableException.class, IndexOutOfBoundsException.class, EncryptorException.class);
    handledExceptionTypes.forEach(t -> {
        final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
        final EncryptedTransaction encryptedTransaction = new EncryptedTransaction();
        encryptedTransaction.setHash(new MessageHash("sampleHash".getBytes()));
        workflowEvent.setEncryptedTransaction(encryptedTransaction);
        final EncodedPayload encodedPayload = EncodedPayload.Builder.create().build();
        workflowEvent.setPayloadsToPublish(Set.of(encodedPayload));
        final PublicKey publicKey = PublicKey.from("sample-public-key".getBytes());
        when(enclave.getPublicKeys()).thenReturn(Set.of(publicKey));
        when(enclave.unencryptTransaction(encodedPayload, publicKey)).thenThrow(t);
        final Throwable throwable = catchThrowable(() -> searchRecipientKeyForPayload.execute(workflowEvent));
        assertThat(throwable).isInstanceOf(RecipientKeyNotFoundException.class).hasMessage("No key found as recipient of message c2FtcGxlSGFzaA==");
        verify(enclave).unencryptTransaction(encodedPayload, publicKey);
        verify(enclave).getPublicKeys();
        verifyNoMoreInteractions(enclave);
        reset(enclave);
    });
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) RecipientKeyNotFoundException(com.quorum.tessera.transaction.exception.RecipientKeyNotFoundException) RecipientKeyNotFoundException(com.quorum.tessera.transaction.exception.RecipientKeyNotFoundException) EnclaveNotAvailableException(com.quorum.tessera.enclave.EnclaveNotAvailableException) EncryptorException(com.quorum.tessera.encryption.EncryptorException) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 27 with EncodedPayload

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

the class SearchRecipientKeyForPayloadTest method payloadsAlreadyFormatted.

@Test
public void payloadsAlreadyFormatted() {
    final EncodedPayload payloadForRecipient1 = EncodedPayload.Builder.create().withRecipientKey(PublicKey.from("recipient1".getBytes())).build();
    final EncodedPayload payloadForRecipient2 = EncodedPayload.Builder.create().withRecipientKey(PublicKey.from("recipient2".getBytes())).build();
    final Set<EncodedPayload> preformattedPayloads = Set.of(payloadForRecipient1, payloadForRecipient2);
    final BatchWorkflowContext workflowContext = new BatchWorkflowContext();
    workflowContext.setPayloadsToPublish(preformattedPayloads);
    searchRecipientKeyForPayload.execute(workflowContext);
    assertThat(workflowContext.getPayloadsToPublish()).isEqualTo(preformattedPayloads);
}
Also used : EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 28 with EncodedPayload

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

the class SingleEncodedPayloadPublisherTest method successfulPublishReturnsTrue.

@Test
public void successfulPublishReturnsTrue() {
    final PublicKey sampleKey = PublicKey.from("testkey".getBytes());
    final EncodedPayload samplePayload1 = EncodedPayload.Builder.create().withSenderKey(sampleKey).build();
    final EncodedPayload samplePayload2 = EncodedPayload.Builder.create().build();
    final BatchWorkflowContext context = new BatchWorkflowContext();
    context.setRecipientKey(sampleKey);
    context.setPayloadsToPublish(Set.of(samplePayload1, samplePayload2));
    final boolean success = workflowPublisher.execute(context);
    assertThat(success).isTrue();
    verify(payloadPublisher).publishPayload(samplePayload1, sampleKey);
    verify(payloadPublisher).publishPayload(samplePayload2, sampleKey);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 29 with EncodedPayload

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

the class StandardPrivateOnlyFilterTest method nonStandardPrivateDoesntPass.

@Test
public void nonStandardPrivateDoesntPass() {
    Arrays.stream(PrivacyMode.values()).filter(p -> !PrivacyMode.STANDARD_PRIVATE.equals(p)).forEach(p -> {
        final EncodedPayload.Builder builder = EncodedPayload.Builder.create().withPrivacyMode(p);
        if (p == PrivacyMode.MANDATORY_RECIPIENTS) {
            builder.withMandatoryRecipients(Set.of(mock(PublicKey.class)));
        }
        if (p == PrivacyMode.PRIVATE_STATE_VALIDATION) {
            builder.withExecHash("execHash".getBytes());
        }
        final EncodedPayload psvPayload = builder.build();
        final BatchWorkflowContext contextPsv = new BatchWorkflowContext();
        contextPsv.setEncodedPayload(psvPayload);
        assertThat(filter.filter(contextPsv)).isFalse();
    });
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Arrays(java.util.Arrays) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) Mockito.mock(org.mockito.Mockito.mock) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Test(org.junit.Test)

Example 30 with EncodedPayload

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

the class StandardPrivateOnlyFilterTest method standardPrivatePasses.

@Test
public void standardPrivatePasses() {
    final EncodedPayload payload = EncodedPayload.Builder.create().withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).build();
    final BatchWorkflowContext context = new BatchWorkflowContext();
    context.setEncodedPayload(payload);
    final boolean success = filter.filter(context);
    assertThat(success).isTrue();
}
Also used : EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) 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