Search in sources :

Example 6 with NodeInfo

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

the class RestPrivacyGroupPublisherTest method remoteNodeDoesNotSupportPrivacyGroup.

@Test
public void remoteNodeDoesNotSupportPrivacyGroup() {
    String targetUrl = "url2.com";
    final List<String> versions = List.of(MultiTenancyVersion.API_VERSION_2_1);
    final NodeInfo oldNode = NodeInfo.Builder.create().withUrl(targetUrl).withRecipients(Collections.emptyList()).withSupportedApiVersions(versions).build();
    PublicKey recipient = PublicKey.from("OLD_KEY".getBytes());
    when(discovery.getRemoteNodeInfo(recipient)).thenReturn(oldNode);
    final byte[] data = new byte[] { 15 };
    try {
        publisher.publishPrivacyGroup(data, recipient);
    } catch (PrivacyGroupNotSupportedException privacyGroupNotSupportedException) {
        assertThat(privacyGroupNotSupportedException).isNotNull().hasMessageContaining(recipient.encodeToBase64());
        verify(discovery).getRemoteNodeInfo(recipient);
    }
}
Also used : PrivacyGroupNotSupportedException(com.quorum.tessera.privacygroup.exception.PrivacyGroupNotSupportedException) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) PublicKey(com.quorum.tessera.encryption.PublicKey) Test(org.junit.Test)

Example 7 with NodeInfo

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

the class AutoDiscoveryTest method onUpdateSendHasTwoKeys.

@Test
public void onUpdateSendHasTwoKeys() {
    String uri = "http://mynode.com";
    PublicKey key = mock(PublicKey.class);
    Recipient recipient = Recipient.of(key, uri);
    PublicKey otherKey = mock(PublicKey.class);
    Recipient other = Recipient.of(otherKey, uri);
    List<Recipient> recipients = List.of(recipient, other);
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).build();
    List<ActiveNode> storedNodes = new ArrayList<>();
    doAnswer(invocation -> {
        storedNodes.add(invocation.getArgument(0));
        return null;
    }).when(networkStore).store(any(ActiveNode.class));
    discovery.onUpdate(nodeInfo);
    assertThat(storedNodes).hasSize(1);
    ActiveNode result = storedNodes.iterator().next();
    assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
    assertThat(result.getKeys()).containsExactlyInAnyOrder(key, otherKey);
    verify(networkStore).store(any(ActiveNode.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 8 with NodeInfo

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

the class DisabledAutoDiscoveryTest method onUpdateIgnoreKeysNotOwnedBySender.

@Test
public void onUpdateIgnoreKeysNotOwnedBySender() {
    String uri = "http://renoraynes.com";
    PublicKey key = mock(PublicKey.class);
    PublicKey key2 = mock(PublicKey.class);
    Recipient recipient = Recipient.of(key, uri);
    Recipient other = Recipient.of(key2, "http://othernode.com");
    List<Recipient> recipients = List.of(recipient, other);
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(uri).withRecipients(recipients).withSupportedApiVersions(List.of("Two", "Fifty")).build();
    List<ActiveNode> storedNodes = new ArrayList<>();
    doAnswer(invocation -> {
        storedNodes.add(invocation.getArgument(0));
        return null;
    }).when(networkStore).store(any(ActiveNode.class));
    discovery.onUpdate(nodeInfo);
    assertThat(storedNodes).hasSize(1);
    ActiveNode result = storedNodes.iterator().next();
    assertThat(result.getUri()).isEqualTo(NodeUri.create(uri));
    assertThat(result.getKeys()).containsExactly(key);
    assertThat(result.getSupportedVersions()).containsExactlyInAnyOrder("Two", "Fifty");
    verify(networkStore).store(any(ActiveNode.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 9 with NodeInfo

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

the class DisabledAutoDiscoveryTest method onUpdateNodeSendsNewKey.

@Test
public void onUpdateNodeSendsNewKey() {
    String url = knownPeers.iterator().next().asString();
    PublicKey key = mock(PublicKey.class);
    List<Recipient> recipients = List.of(Recipient.of(key, url));
    List<ActiveNode> storedNodes = new ArrayList<>();
    doAnswer(invocation -> {
        storedNodes.add(invocation.getArgument(0));
        return null;
    }).when(networkStore).store(any(ActiveNode.class));
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).build();
    discovery.onUpdate(nodeInfo);
    assertThat(storedNodes).hasSize(1);
    ActiveNode savedNode = storedNodes.get(0);
    assertThat(savedNode.getKeys()).containsExactly(key);
    assertThat(savedNode.getUri()).isEqualTo(NodeUri.create(url));
    verify(networkStore).store(any(ActiveNode.class));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) ArrayList(java.util.ArrayList) Recipient(com.quorum.tessera.partyinfo.node.Recipient) ActiveNode(com.quorum.tessera.discovery.ActiveNode) Test(org.junit.Test)

Example 10 with NodeInfo

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

the class DiscoveryHelperTest method getCurrentWithUriOnly.

@Test
public void getCurrentWithUriOnly() {
    final URI uri = URI.create("http://somedomain.com");
    when(runtimeContext.getP2pServerUri()).thenReturn(uri);
    NodeInfo result = discoveryHelper.buildCurrent();
    assertThat(result).isNotNull();
    verify(runtimeContext).getP2pServerUri();
    assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
    assertThat(result.getRecipients()).isEmpty();
    verify(networkStore).getActiveNodes();
    mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) RuntimeContext(com.quorum.tessera.context.RuntimeContext) URI(java.net.URI) Test(org.junit.Test)

Aggregations

NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)49 Test (org.junit.Test)37 PublicKey (com.quorum.tessera.encryption.PublicKey)31 Recipient (com.quorum.tessera.partyinfo.node.Recipient)19 ActiveNode (com.quorum.tessera.discovery.ActiveNode)12 Response (jakarta.ws.rs.core.Response)11 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)10 NodeUri (com.quorum.tessera.discovery.NodeUri)8 URI (java.net.URI)8 Collectors (java.util.stream.Collectors)8 RuntimeContext (com.quorum.tessera.context.RuntimeContext)7 EncodedPayload (com.quorum.tessera.enclave.EncodedPayload)7 Set (java.util.Set)7 KeyNotFoundException (com.quorum.tessera.encryption.KeyNotFoundException)6 Logger (org.slf4j.Logger)6 Discovery (com.quorum.tessera.discovery.Discovery)5 DiscoveryHelper (com.quorum.tessera.discovery.DiscoveryHelper)5 NetworkStore (com.quorum.tessera.discovery.NetworkStore)5 Enclave (com.quorum.tessera.enclave.Enclave)5 Entity (jakarta.ws.rs.client.Entity)5