Search in sources :

Example 46 with EncodedPayload

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

the class RecoveryResourceTest method pushNotAllowedForEnhancedPrivacy.

@Test
public void pushNotAllowedForEnhancedPrivacy() {
    final byte[] someData = "SomeData".getBytes();
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getPrivacyMode()).thenReturn(PrivacyMode.PRIVATE_STATE_VALIDATION);
    when(payloadEncoder.decode(someData)).thenReturn(payload);
    final Response result = recoveryResource.push(someData, null);
    assertThat(result.getStatus()).isEqualTo(403);
    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 47 with EncodedPayload

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

the class BatchWorkflowFactoryImplTest method createBatchWorkflowFactoryImplAndExecuteWorkflow.

@Test
public void createBatchWorkflowFactoryImplAndExecuteWorkflow() {
    BatchWorkflowFactoryImpl batchWorkflowFactory = new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
    BatchWorkflow batchWorkflow = batchWorkflowFactory.create(1L);
    assertThat(batchWorkflow).isNotNull();
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    PublicKey recipientKey = mock(PublicKey.class);
    batchWorkflowContext.setRecipientKey(recipientKey);
    PublicKey ownedKey = mock(PublicKey.class);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getSenderKey()).thenReturn(ownedKey);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey));
    EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
    when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
    batchWorkflowContext.setEncryptedTransaction(encryptedTransaction);
    batchWorkflowContext.setEncodedPayload(encodedPayload);
    batchWorkflowContext.setBatchSize(100);
    when(mockPayloadBuilder.build()).thenReturn(encodedPayload);
    when(enclave.status()).thenReturn(Service.Status.STARTED);
    when(enclave.getPublicKeys()).thenReturn(Set.of(ownedKey));
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(recipientKey, "url")));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    assertThat(batchWorkflow.execute(batchWorkflowContext)).isTrue();
    assertThat(batchWorkflow.getPublishedMessageCount()).isOne();
    verify(enclave).status();
    verify(enclave, times(2)).getPublicKeys();
    mockStaticPayloadBuilder.verify(() -> EncodedPayload.Builder.forRecipient(any(), any()));
    verify(mockPayloadBuilder).build();
    verify(discovery).getCurrent();
    verify(resendBatchPublisher).publishBatch(any(), any());
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 48 with EncodedPayload

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

the class LegacyResendManagerImplTest method individualNonStandardPrivateTxFails.

@Test
public void individualNonStandardPrivateTxFails() {
    final EncodedPayload nonSPPayload = EncodedPayload.Builder.create().withPrivacyMode(PrivacyMode.PARTY_PROTECTION).build();
    final EncryptedTransaction databaseTx = new EncryptedTransaction();
    databaseTx.setPayload(nonSPPayload);
    when(dao.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(databaseTx));
    final MessageHash txHash = new MessageHash("sample-hash".getBytes());
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final ResendRequest request = ResendRequest.Builder.create().withType(ResendRequest.ResendRequestType.INDIVIDUAL).withHash(txHash).withRecipient(targetResendKey).build();
    final Throwable throwable = catchThrowable(() -> resendManager.resend(request));
    assertThat(throwable).isInstanceOf(EnhancedPrivacyNotSupportedException.class).hasMessage("Cannot resend enhanced privacy transaction in legacy resend");
    verify(dao).retrieveByHash(txHash);
}
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) ResendRequest(com.quorum.tessera.recovery.resend.ResendRequest) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Test(org.junit.Test)

Example 49 with EncodedPayload

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

the class LegacyResendManagerImplTest method targetKeyIsNotSenderOfTransaction.

@Test
public void targetKeyIsNotSenderOfTransaction() {
    final MessageHash txHash = new MessageHash("sample-hash".getBytes());
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final EncodedPayload nonSPPayload = EncodedPayload.Builder.create().withPrivacyMode(PrivacyMode.STANDARD_PRIVATE).build();
    final EncryptedTransaction databaseTx = new EncryptedTransaction();
    databaseTx.setPayload(nonSPPayload);
    final ResendRequest request = ResendRequest.Builder.create().withType(ResendRequest.ResendRequestType.INDIVIDUAL).withHash(txHash).withRecipient(targetResendKey).build();
    when(dao.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.of(databaseTx));
    final ResendResponse response;
    try (var mockStatic = mockStatic(EncodedPayload.Builder.class)) {
        EncodedPayload.Builder builder = mock(EncodedPayload.Builder.class);
        mockStatic.when(() -> EncodedPayload.Builder.forRecipient(nonSPPayload, targetResendKey)).thenReturn(builder);
        when(builder.build()).thenReturn(nonSPPayload);
        response = resendManager.resend(request);
        mockStatic.verify(() -> EncodedPayload.Builder.forRecipient(nonSPPayload, targetResendKey));
    }
    assertThat(response).isNotNull();
    assertThat(response.getPayload()).isEqualTo(nonSPPayload);
    verify(dao).retrieveByHash(txHash);
}
Also used : ResendResponse(com.quorum.tessera.recovery.resend.ResendResponse) PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) ResendRequest(com.quorum.tessera.recovery.resend.ResendRequest) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 50 with EncodedPayload

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

the class LegacyResendWorkflowFactoryTest method successForAllStagesReturnsTrue.

@Test
public void successForAllStagesReturnsTrue() {
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final PublicKey localRecipient = PublicKey.from("local-recipient".getBytes());
    final EncodedPayload payload = EncodedPayload.Builder.create().withSenderKey(targetResendKey).withRecipientBox("testbox".getBytes()).build();
    final NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(targetResendKey, "url")));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    final EncryptedTransaction encryptedTx = mock(EncryptedTransaction.class);
    when(enclave.getPublicKeys()).thenReturn(Set.of(localRecipient));
    when(enclave.unencryptTransaction(any(EncodedPayload.class), eq(localRecipient))).thenReturn(new byte[0]);
    final BatchWorkflow batchWorkflow = wfFactory.create();
    final BatchWorkflowContext context = new BatchWorkflowContext();
    context.setEncryptedTransaction(encryptedTx);
    context.setEncodedPayload(payload);
    context.setRecipientKey(targetResendKey);
    context.setBatchSize(1);
    final boolean success = batchWorkflow.execute(context);
    assertThat(success).isTrue();
    verify(discovery).getCurrent();
    verify(payloadPublisher).publishPayload(any(EncodedPayload.class), eq(targetResendKey));
    verify(enclave).status();
    verify(enclave, times(2)).getPublicKeys();
    verify(enclave).unencryptTransaction(any(EncodedPayload.class), eq(localRecipient));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) 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