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