use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class FindRecipientFromPartyInfoTest method executeKeyNotFound.
@Test
public void executeKeyNotFound() {
BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
PublicKey publicKey = mock(PublicKey.class);
batchWorkflowContext.setRecipientKey(publicKey);
NodeInfo nodeInfo = mock(NodeInfo.class);
Recipient recipient = mock(Recipient.class);
when(recipient.getKey()).thenReturn(mock(PublicKey.class));
when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
when(discovery.getCurrent()).thenReturn(nodeInfo);
try {
findRecipientFromPartyInfo.execute(batchWorkflowContext);
failBecauseExceptionWasNotThrown(KeyNotFoundException.class);
} catch (KeyNotFoundException ex) {
verify(discovery).getCurrent();
assertThat(batchWorkflowContext.getRecipient()).isNull();
assertThat(batchWorkflowContext.getRecipientKey()).isSameAs(publicKey);
}
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class PartyInfoServiceUtilTest method validateEmptyRecipientListsAsValid.
@Test
public void validateEmptyRecipientListsAsValid() {
final String url = "http://somedomain.com";
final Set<Recipient> newRecipients = Set.of();
final NodeInfo existingPartyInfo = NodeInfo.Builder.create().withRecipients(newRecipients).withUrl(url).build();
final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isTrue();
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class FindRecipientFromPartyInfo method execute.
@Override
public boolean execute(BatchWorkflowContext event) {
PublicKey recipientKey = event.getRecipientKey();
final Recipient retrievedRecipientFromStore = discovery.getCurrent().getRecipients().stream().filter(recipient -> recipientKey.equals(recipient.getKey())).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
event.setRecipient(retrievedRecipientFromStore);
return true;
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class RestPayloadPublisherTest method publishEnhancedTransactionsToNodesThatDoNotSupport.
@Test
public void publishEnhancedTransactionsToNodesThatDoNotSupport() {
Map<PrivacyMode, Set<String>> privacyModeAndVersions = new HashMap<>();
privacyModeAndVersions.put(PrivacyMode.PARTY_PROTECTION, Set.of("v1"));
privacyModeAndVersions.put(PrivacyMode.PRIVATE_STATE_VALIDATION, Set.of("v1"));
for (Map.Entry<PrivacyMode, Set<String>> pair : privacyModeAndVersions.entrySet()) {
String targetUrl = "http://someplace.com";
EncodedPayload encodedPayload = mock(EncodedPayload.class);
when(encodedPayload.getPrivacyMode()).thenReturn(pair.getKey());
byte[] payloadData = "Some Data".getBytes();
when(payloadEncoder.encode(encodedPayload)).thenReturn(payloadData);
PublicKey recipientKey = mock(PublicKey.class);
NodeInfo nodeInfo = mock(NodeInfo.class);
when(nodeInfo.supportedApiVersions()).thenReturn(pair.getValue());
Recipient recipient = mock(Recipient.class);
when(recipient.getKey()).thenReturn(recipientKey);
when(recipient.getUrl()).thenReturn(targetUrl);
when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
EnhancedPrivacyNotSupportedException exception = catchThrowableOfType(() -> payloadPublisher.publishPayload(encodedPayload, recipientKey), EnhancedPrivacyNotSupportedException.class);
assertThat(exception).hasMessageContaining("Transactions with enhanced privacy is not currently supported");
verify(discovery).getRemoteNodeInfo(eq(recipientKey));
}
payloadEncoderFactoryFunction.verify(times(2), () -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.
the class DiscoveryHelperImpl method buildCurrent.
@Override
public NodeInfo buildCurrent() {
final URI uri = RuntimeContext.getInstance().getP2pServerUri();
final NodeUri nodeUri = NodeUri.create(uri);
final List<ActiveNode> activeNodes = networkStore.getActiveNodes().collect(Collectors.toList());
Set<Recipient> recipients = activeNodes.stream().filter(a -> !a.getKeys().isEmpty()).flatMap(a -> a.getKeys().stream().map(k -> Recipient.of(k, a.getUri().asString()))).collect(Collectors.toSet());
NodeInfo nodeInfo = NodeInfo.Builder.create().withRecipients(recipients).withUrl(nodeUri.asString()).withSupportedApiVersions(ApiVersion.versions()).build();
LOGGER.debug("Built nodeinfo {}", nodeInfo);
return nodeInfo;
}
Aggregations