Search in sources :

Example 6 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class DiscoveryHelperTest method buildCurrent.

@Test
public void buildCurrent() {
    final URI uri = URI.create("http://somedomain.com");
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    final List<PublicKey> keys = IntStream.range(0, 5).mapToObj(i -> mock(PublicKey.class)).collect(Collectors.toList());
    final ActiveNode activeNode = ActiveNode.Builder.create().withUri(NodeUri.create(uri)).withKeys(keys).build();
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    NodeInfo result = discoveryHelper.buildCurrent();
    assertThat(result).isNotNull();
    assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
    assertThat(result.getRecipients()).hasSize(5);
    List<Recipient> recipients = List.copyOf(result.getRecipients());
    assertThat(recipients.stream().map(Recipient::getKey).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(keys);
    verify(networkStore).getActiveNodes();
    verify(runtimeContext).getP2pServerUri();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Mockito(org.mockito.Mockito) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) After(org.junit.After) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) Before(org.junit.Before) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 7 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class DiscoveryHelperTest method buildRemoteNodeInfo.

@Test
public void buildRemoteNodeInfo() {
    String url = "http://nodeurl.com/";
    final PublicKey key = PublicKey.from("key".getBytes());
    final PublicKey anotherKey = PublicKey.from("anotherKey".getBytes());
    final Recipient recipient = Recipient.of(key, url);
    final Recipient sameNodeDifferentKey = Recipient.of(anotherKey, url);
    ActiveNode activeNode = mock(ActiveNode.class);
    when(activeNode.getUri()).thenReturn(NodeUri.create(url));
    when(activeNode.getKeys()).thenReturn(Set.of(key, anotherKey));
    when(activeNode.getSupportedVersions()).thenReturn(Set.of("v1", "v2"));
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    final NodeInfo result = discoveryHelper.buildRemoteNodeInfo(key);
    assertThat(result).isNotNull();
    assertThat(result.getUrl()).isEqualTo(url);
    assertThat(result.getRecipients()).containsExactlyInAnyOrder(recipient, sameNodeDifferentKey);
    assertThat(result.supportedApiVersions()).containsExactlyInAnyOrder("v1", "v2");
    verify(networkStore).getActiveNodes();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 8 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class DiscoveryHelperTest method buildAllNodeInfos.

@Test
public void buildAllNodeInfos() {
    when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://own.com"));
    final ActiveNode node1 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node1.com")).withKeys(List.of(PublicKey.from("key1".getBytes()))).withSupportedVersions(List.of("v1")).build();
    final ActiveNode node2 = ActiveNode.Builder.create().withUri(NodeUri.create("http://node2.com")).withKeys(List.of(PublicKey.from("key2".getBytes()))).withSupportedVersions(List.of("v2")).build();
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(node1, node2));
    final Set<NodeInfo> nodeInfos = discoveryHelper.buildRemoteNodeInfos();
    assertThat(nodeInfos).hasSize(2);
    Set<ActiveNode> activeNodes = nodeInfos.stream().map(nodeInfo -> ActiveNode.Builder.create().withUri(NodeUri.create(nodeInfo.getUrl())).withKeys(nodeInfo.getRecipients().stream().map(Recipient::getKey).collect(Collectors.toSet())).withSupportedVersions(nodeInfo.supportedApiVersions()).build()).collect(Collectors.toSet());
    assertThat(activeNodes).containsExactlyInAnyOrder(node1, node2);
    verify(networkStore).getActiveNodes();
    verify(runtimeContext).getP2pServerUri();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) PublicKey(com.quorum.tessera.encryption.PublicKey) DiscoveryHelper(com.quorum.tessera.discovery.DiscoveryHelper) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Set(java.util.Set) Test(org.junit.Test) NodeUri(com.quorum.tessera.discovery.NodeUri) Collectors(java.util.stream.Collectors) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Mockito(org.mockito.Mockito) ActiveNode(com.quorum.tessera.discovery.ActiveNode) NetworkStore(com.quorum.tessera.discovery.NetworkStore) List(java.util.List) MockedStatic(org.mockito.MockedStatic) Stream(java.util.stream.Stream) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) After(org.junit.After) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Enclave(com.quorum.tessera.enclave.Enclave) URI(java.net.URI) Before(org.junit.Before) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) Test(org.junit.Test)

Example 9 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class DiscoveryHelperImpl method buildRemoteNodeInfo.

@Override
public NodeInfo buildRemoteNodeInfo(PublicKey recipientKey) {
    final ActiveNode activeNode = networkStore.getActiveNodes().filter(node -> node.getKeys().contains(recipientKey)).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
    final String nodeUrl = activeNode.getUri().asString();
    final Set<Recipient> recipients = activeNode.getKeys().stream().map(k -> Recipient.of(k, nodeUrl)).collect(Collectors.toSet());
    final NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(nodeUrl).withRecipients(recipients).withSupportedApiVersions(activeNode.getSupportedVersions()).build();
    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) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException)

Example 10 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient in project tessera by ConsenSys.

the class PartyInfoServiceUtilTest method validateSameRecipientListsAsValid.

@Test
public void validateSameRecipientListsAsValid() {
    final String url = "http://somedomain.com";
    final PublicKey key = PublicKey.from("ONE".getBytes());
    final Set<Recipient> existingRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
    final NodeInfo existingPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(existingRecipients).build();
    final Set<Recipient> newRecipients = Collections.singleton(Recipient.of(key, "http://one.com"));
    final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
    assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isTrue();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

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