Search in sources :

Example 56 with MessageHash

use of com.quorum.tessera.data.MessageHash 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 57 with MessageHash

use of com.quorum.tessera.data.MessageHash 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 58 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class SearchRecipientKeyForPayloadTest method execute.

@Test
public void execute() {
    final BatchWorkflowContext workflowEvent = new BatchWorkflowContext();
    final EncryptedTransaction encryptedTransaction = new EncryptedTransaction();
    encryptedTransaction.setHash(new MessageHash("sampleHash".getBytes()));
    workflowEvent.setEncryptedTransaction(encryptedTransaction);
    final EncodedPayload encodedPayloadForRecipient1 = EncodedPayload.Builder.create().withRecipientBox("sample-box-1".getBytes()).build();
    final EncodedPayload encodedPayloadForRecipient2 = EncodedPayload.Builder.create().withRecipientBox("sample-box-2".getBytes()).build();
    workflowEvent.setPayloadsToPublish(Set.of(encodedPayloadForRecipient1, encodedPayloadForRecipient2));
    final PublicKey recipient1 = PublicKey.from("sample-public-key-1".getBytes());
    final PublicKey recipient2 = PublicKey.from("sample-public-key-2".getBytes());
    // Using this LinkedHashSet instead of Set.of(...) to provide a defined iteration order.
    final LinkedHashSet<PublicKey> enclaveKeys = new LinkedHashSet<>();
    enclaveKeys.add(recipient1);
    enclaveKeys.add(recipient2);
    when(enclave.getPublicKeys()).thenReturn(enclaveKeys);
    when(enclave.unencryptTransaction(encodedPayloadForRecipient1, recipient1)).thenReturn(new byte[0]);
    when(enclave.unencryptTransaction(encodedPayloadForRecipient2, recipient2)).thenReturn(new byte[0]);
    when(enclave.unencryptTransaction(encodedPayloadForRecipient2, recipient1)).thenThrow(EncryptorException.class);
    searchRecipientKeyForPayload.execute(workflowEvent);
    final Set<EncodedPayload> updatedPayloads = workflowEvent.getPayloadsToPublish();
    assertThat(updatedPayloads).containsExactlyInAnyOrder(EncodedPayload.Builder.from(encodedPayloadForRecipient1).withRecipientKey(recipient1).build(), EncodedPayload.Builder.from(encodedPayloadForRecipient2).withRecipientKey(recipient2).build());
    verify(enclave).unencryptTransaction(encodedPayloadForRecipient1, recipient1);
    verify(enclave).unencryptTransaction(encodedPayloadForRecipient2, recipient1);
    verify(enclave).unencryptTransaction(encodedPayloadForRecipient2, recipient2);
    verify(enclave, times(2)).getPublicKeys();
    verifyNoMoreInteractions(enclave);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PublicKey(com.quorum.tessera.encryption.PublicKey) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 59 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class RecoveryImplTest method testSyncSuccess.

@Test
public void testSyncSuccess() {
    StagingTransaction version1 = mock(StagingTransaction.class);
    StagingTransaction version2 = mock(StagingTransaction.class);
    when(version1.getHash()).thenReturn("TXN1");
    when(version2.getHash()).thenReturn("TXN1");
    EncodedPayload firstPayload = mock(EncodedPayload.class);
    EncodedPayload secondPayload = mock(EncodedPayload.class);
    when(version1.getEncodedPayload()).thenReturn(firstPayload);
    when(version2.getEncodedPayload()).thenReturn(secondPayload);
    when(stagingEntityDAO.retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt())).thenReturn(List.of(version1, version2));
    when(stagingEntityDAO.countAll()).thenReturn(2L);
    when(transactionManager.storePayload(any())).thenReturn(new MessageHash("hash".getBytes()));
    RecoveryResult result = recovery.sync();
    assertThat(result).isEqualTo(RecoveryResult.SUCCESS);
    verify(stagingEntityDAO).retrieveTransactionBatchOrderByStageAndHash(anyInt(), anyInt());
    verify(stagingEntityDAO, times(2)).countAll();
    verify(transactionManager).storePayload(firstPayload);
    verify(transactionManager).storePayload(secondPayload);
}
Also used : StagingTransaction(com.quorum.tessera.data.staging.StagingTransaction) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) MessageHash(com.quorum.tessera.data.MessageHash) RecoveryResult(com.quorum.tessera.recovery.RecoveryResult) Test(org.junit.Test)

Example 60 with MessageHash

use of com.quorum.tessera.data.MessageHash in project tessera by ConsenSys.

the class RawTransactionResourceTest method storeUsingDefaultKeyVersion21.

@Test
public void storeUsingDefaultKeyVersion21() {
    com.quorum.tessera.transaction.StoreRawResponse response = mock(com.quorum.tessera.transaction.StoreRawResponse.class);
    MessageHash transactionHash = mock(MessageHash.class);
    when(transactionHash.getHashBytes()).thenReturn("TXN".getBytes());
    when(response.getHash()).thenReturn(transactionHash);
    when(transactionManager.store(any())).thenReturn(response);
    when(transactionManager.defaultPublicKey()).thenReturn(PublicKey.from("SENDER".getBytes()));
    final StoreRawRequest storeRawRequest = new StoreRawRequest();
    storeRawRequest.setPayload("PAYLOAD".getBytes());
    final Response result = transactionResource.storeVersion21(storeRawRequest);
    assertThat(result.getStatus()).isEqualTo(200);
    verify(transactionManager).store(any());
    verify(transactionManager).defaultPublicKey();
}
Also used : Response(jakarta.ws.rs.core.Response) StoreRawRequest(com.quorum.tessera.api.StoreRawRequest) MessageHash(com.quorum.tessera.data.MessageHash) Test(org.junit.Test)

Aggregations

MessageHash (com.quorum.tessera.data.MessageHash)81 PublicKey (com.quorum.tessera.encryption.PublicKey)56 Test (org.junit.Test)51 Response (jakarta.ws.rs.core.Response)44 Operation (io.swagger.v3.oas.annotations.Operation)21 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)21 SendResponse (com.quorum.tessera.api.SendResponse)17 ReceiveResponse (com.quorum.tessera.transaction.ReceiveResponse)16 SendRequest (com.quorum.tessera.api.SendRequest)15 PrivacyGroup (com.quorum.tessera.enclave.PrivacyGroup)15 PrivacyMode (com.quorum.tessera.enclave.PrivacyMode)15 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)13 java.util (java.util)13 Collectors (java.util.stream.Collectors)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)12 TransactionManager (com.quorum.tessera.transaction.TransactionManager)12 Tag (io.swagger.v3.oas.annotations.tags.Tag)11 Valid (jakarta.validation.Valid)11