Search in sources :

Example 21 with Recipient

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);
    }
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) Test(org.junit.Test)

Example 22 with Recipient

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();
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 23 with Recipient

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;
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.node.Recipient) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException)

Example 24 with Recipient

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)));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PublicKey(com.quorum.tessera.encryption.PublicKey) PrivacyMode(com.quorum.tessera.enclave.PrivacyMode) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Recipient(com.quorum.tessera.partyinfo.node.Recipient) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) HashMap(java.util.HashMap) Map(java.util.Map) EnhancedPrivacyNotSupportedException(com.quorum.tessera.transaction.exception.EnhancedPrivacyNotSupportedException) Test(org.junit.Test)

Example 25 with Recipient

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;
}
Also used : KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) Logger(org.slf4j.Logger) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) ApiVersion(com.quorum.tessera.version.ApiVersion) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) Optional(java.util.Optional) URI(java.net.URI) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) NodeUri(com.quorum.tessera.discovery.NodeUri) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) URI(java.net.URI)

Aggregations

Recipient (com.quorum.tessera.partyinfo.node.Recipient)25 PublicKey (com.quorum.tessera.encryption.PublicKey)24 Test (org.junit.Test)22 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)19 ActiveNode (com.quorum.tessera.discovery.ActiveNode)10 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)8 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)7 Set (java.util.Set)6 RuntimeContext (com.quorum.tessera.context.RuntimeContext)5 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)5 NodeUri (com.quorum.tessera.discovery.NodeUri)5 Enclave (com.quorum.tessera.enclave.Enclave)5 URI (java.net.URI)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 ArrayList (java.util.ArrayList)4 IntStream (java.util.stream.IntStream)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3