Search in sources :

Example 11 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.

the class DiscoveryHelperTest method buildAllNodeInfosFilteredOutOwn.

@Test
public void buildAllNodeInfosFilteredOutOwn() {
    when(runtimeContext.getP2pServerUri()).thenReturn(URI.create("http://node1.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(1);
    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(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 12 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.

the class DiscoveryHelperTest method getCurrentWithNoKeys.

@Test
public void getCurrentWithNoKeys() {
    final URI uri = URI.create("http://somedomain.com");
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    final List<PublicKey> keys = List.of();
    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();
    verify(runtimeContext).getP2pServerUri();
    assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
    verify(networkStore).getActiveNodes();
    assertThat(result.getRecipients()).isEmpty();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 13 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.

the class DiscoveryHelperTest method recipientKeyNotFound.

@Test
public void recipientKeyNotFound() {
    String url = "http://nodeurl.com/";
    final PublicKey key = PublicKey.from("key".getBytes());
    final PublicKey anotherKey = PublicKey.from("anotherKey".getBytes());
    ActiveNode activeNode = mock(ActiveNode.class);
    when(activeNode.getUri()).thenReturn(NodeUri.create(url));
    when(activeNode.getKeys()).thenReturn(Set.of(key));
    when(activeNode.getSupportedVersions()).thenReturn(Set.of("v1", "v2"));
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    assertThatExceptionOfType(KeyNotFoundException.class).isThrownBy(() -> discoveryHelper.buildRemoteNodeInfo(anotherKey));
    verify(networkStore).getActiveNodes();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) ActiveNode(com.quorum.tessera.discovery.ActiveNode) KeyNotFoundException(com.quorum.tessera.encryption.KeyNotFoundException) Test(org.junit.Test)

Example 14 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.

the class EnclaveKeySynchroniserTest method syncWithChanges.

@Test
public void syncWithChanges() {
    URI uri = URI.create("http://somedomain.com/");
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    NodeUri nodeUri = NodeUri.create(uri);
    Set<PublicKey> newKeys = Set.of(mock(PublicKey.class));
    ActiveNode activeNode = mock(ActiveNode.class);
    when(activeNode.getUri()).thenReturn(nodeUri);
    when(activeNode.getKeys()).thenReturn(newKeys);
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    when(enclave.getPublicKeys()).thenReturn(Set.of(mock(PublicKey.class)));
    enclaveKeySynchroniser.syncKeys();
    verify(runtimeContext).getP2pServerUri();
    verify(networkStore).getActiveNodes();
    verify(enclave).getPublicKeys();
    verify(networkStore).store(any(ActiveNode.class));
    mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Example 15 with ActiveNode

use of com.quorum.tessera.discovery.ActiveNode in project tessera by ConsenSys.

the class EnclaveKeySynchroniserTest method syncKeysNoChanges.

@Test
public void syncKeysNoChanges() {
    URI uri = URI.create("http://somedomain.com/");
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    NodeUri nodeUri = NodeUri.create(uri);
    Set<PublicKey> keys = Set.of(mock(PublicKey.class));
    ActiveNode activeNode = mock(ActiveNode.class);
    when(activeNode.getKeys()).thenReturn(keys);
    when(activeNode.getUri()).thenReturn(nodeUri);
    when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
    when(enclave.getPublicKeys()).thenReturn(keys);
    enclaveKeySynchroniser.syncKeys();
    verify(runtimeContext).getP2pServerUri();
    verify(networkStore).getActiveNodes();
    verify(enclave).getPublicKeys();
    mockedStaticRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Aggregations

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