Search in sources :

Example 1 with ResendRequest

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

the class LegacyResendManagerImplTest method targetIsSenderOfTransaction.

@Test
public void targetIsSenderOfTransaction() {
    final MessageHash txHash = new MessageHash("sample-hash".getBytes());
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final PublicKey localRecipientKey = PublicKey.from("local-recipient".getBytes());
    final EncodedPayload nonSPPayload = EncodedPayload.Builder.create().withSenderKey(targetResendKey).withRecipientBox("testBox".getBytes()).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));
    when(enclave.getPublicKeys()).thenReturn(Set.of(localRecipientKey));
    when(enclave.unencryptTransaction(any(), eq(localRecipientKey))).thenReturn(new byte[0]);
    final ResendResponse response = resendManager.resend(request);
    final EncodedPayload expected = EncodedPayload.Builder.from(nonSPPayload).withRecipientKey(localRecipientKey).build();
    assertThat(response).isNotNull();
    assertThat(response.getPayload()).isEqualToComparingFieldByFieldRecursively(expected);
    verify(dao).retrieveByHash(txHash);
    verify(enclave).getPublicKeys();
    verify(enclave).unencryptTransaction(any(), eq(localRecipientKey));
}
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 2 with ResendRequest

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

the class LegacyResendManagerImplTest method individualMissingTxFails.

@Test
public void individualMissingTxFails() {
    when(dao.retrieveByHash(any(MessageHash.class))).thenReturn(Optional.empty());
    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(TransactionNotFoundException.class).hasMessage("Message with hash c2FtcGxlLWhhc2g= was not found");
    verify(dao).retrieveByHash(txHash);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) TransactionNotFoundException(com.quorum.tessera.transaction.exception.TransactionNotFoundException) MessageHash(com.quorum.tessera.data.MessageHash) ResendRequest(com.quorum.tessera.recovery.resend.ResendRequest) Test(org.junit.Test)

Example 3 with ResendRequest

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

the class LegacyResendManagerImplTest method performResendAll.

@Test
public void performResendAll() {
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final ResendRequest request = ResendRequest.Builder.create().withType(ResendRequest.ResendRequestType.ALL).withRecipient(targetResendKey).build();
    // Not bothered about going through the process, just make sure they are all loaded from the
    // database
    // We are not testing the workflow itself, only that the workflow gets the right amount of
    // transactions
    when(dao.transactionCount()).thenReturn(2L);
    when(dao.retrieveTransactions(0, 1)).thenReturn(List.of(new EncryptedTransaction()));
    when(dao.retrieveTransactions(1, 1)).thenReturn(List.of(new EncryptedTransaction()));
    final ResendResponse response = resendManager.resend(request);
    assertThat(response).isNotNull();
    assertThat(response.getPayload()).isNull();
    verify(enclave, times(2)).status();
    verify(dao).transactionCount();
    verify(dao).retrieveTransactions(0, 1);
    verify(dao).retrieveTransactions(1, 1);
}
Also used : ResendResponse(com.quorum.tessera.recovery.resend.ResendResponse) PublicKey(com.quorum.tessera.encryption.PublicKey) ResendRequest(com.quorum.tessera.recovery.resend.ResendRequest) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 4 with ResendRequest

use of com.quorum.tessera.recovery.resend.ResendRequest 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 5 with ResendRequest

use of com.quorum.tessera.recovery.resend.ResendRequest 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)

Aggregations

PublicKey (com.quorum.tessera.encryption.PublicKey)5 ResendRequest (com.quorum.tessera.recovery.resend.ResendRequest)5 Test (org.junit.Test)5 EncryptedTransaction (com.quorum.tessera.data.EncryptedTransaction)4 MessageHash (com.quorum.tessera.data.MessageHash)4 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)3 ResendResponse (com.quorum.tessera.recovery.resend.ResendResponse)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 EnhancedPrivacyNotSupportedException (com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException)1 TransactionNotFoundException (com.quorum.tessera.transaction.exception.TransactionNotFoundException)1