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)));
}
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());
}
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);
}
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);
}
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));
}
Aggregations