Search in sources :

Example 1 with Recipient

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

the class RestPayloadPublisherTest method publishMandatoryRecipientsToNodesThatDoNotSupport.

@Test
public void publishMandatoryRecipientsToNodesThatDoNotSupport() {
    String targetUrl = "http://someplace.com";
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getPrivacyMode()).thenReturn(PrivacyMode.MANDATORY_RECIPIENTS);
    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(Set.of("v2", "2.1", "3.0"));
    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);
    assertThatExceptionOfType(MandatoryRecipientsNotSupportedException.class).isThrownBy(() -> payloadPublisher.publishPayload(encodedPayload, recipientKey)).withMessageContaining("Transactions with mandatory recipients are not currently supported on recipient");
    verify(discovery).getRemoteNodeInfo(eq(recipientKey));
    payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Recipient(com.quorum.tessera.partyinfo.node.Recipient) Test(org.junit.Test)

Example 2 with Recipient

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

the class RestPayloadPublisherTest method handleConnectionError.

@Test
public void handleConnectionError() {
    final String targetUri = "http://jimmywhite.com";
    final PublicKey recipientKey = mock(PublicKey.class);
    Recipient recipient = mock(Recipient.class);
    when(recipient.getKey()).thenReturn(recipientKey);
    when(recipient.getUrl()).thenReturn(targetUri);
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
    when(nodeInfo.getUrl()).thenReturn(targetUri);
    when(discovery.getRemoteNodeInfo(recipientKey)).thenReturn(nodeInfo);
    Client client = mock(Client.class);
    when(client.target(targetUri)).thenThrow(ProcessingException.class);
    final EncodedPayload payload = mock(EncodedPayload.class);
    when(payload.getPrivacyMode()).thenReturn(PrivacyMode.STANDARD_PRIVATE);
    when(payloadEncoder.encode(payload)).thenReturn("SomeData".getBytes());
    RestPayloadPublisher restPayloadPublisher = new RestPayloadPublisher(client, discovery);
    try {
        restPayloadPublisher.publishPayload(payload, recipientKey);
        failBecauseExceptionWasNotThrown(NodeOfflineException.class);
    } catch (NodeOfflineException ex) {
        assertThat(ex).hasMessageContaining(targetUri);
        verify(client).target(targetUri);
        verify(discovery).getRemoteNodeInfo(eq(recipientKey));
        verify(payloadEncoder).encode(payload);
        verify(discovery).getRemoteNodeInfo(eq(recipientKey));
        payloadEncoderFactoryFunction.verify(() -> PayloadEncoder.create(any(EncodedPayloadCodec.class)));
    }
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Recipient(com.quorum.tessera.partyinfo.node.Recipient) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) Client(jakarta.ws.rs.client.Client) NodeOfflineException(com.quorum.tessera.transaction.publish.NodeOfflineException) EncodedPayloadCodec(com.quorum.tessera.enclave.EncodedPayloadCodec) Test(org.junit.Test)

Example 3 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient 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 4 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient 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 5 with Recipient

use of com.quorum.tessera.partyinfo.node.Recipient 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)

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