Search in sources :

Example 16 with NodeInfo

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

Example 17 with NodeInfo

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

the class PartyInfoServiceUtilTest method validateAttemptToChangeUrlAsInvalid.

@Test
public void validateAttemptToChangeUrlAsInvalid() {
    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://two.com"));
    final NodeInfo newPartyInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(newRecipients).build();
    assertThat(PartyInfoServiceUtil.validateKeysToUrls(existingPartyInfo, newPartyInfo)).isFalse();
}
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)

Example 18 with NodeInfo

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

the class RecoveryTestCase method getAllNodeInfos.

protected Set<NodeInfo> getAllNodeInfos() {
    final NodeInfo node1 = NodeInfo.Builder.create().withUrl(NodeUri.create("http://party1").asString()).withRecipients(Set.of(mock(Recipient.class))).withSupportedApiVersions(Set.of(BaseVersion.API_VERSION_1, EnhancedPrivacyVersion.API_VERSION_2)).build();
    final NodeInfo node2 = NodeInfo.Builder.create().withUrl(NodeUri.create("http://party2").asString()).withRecipients(Set.of(mock(Recipient.class))).withSupportedApiVersions(Set.of(BaseVersion.API_VERSION_1)).build();
    final NodeInfo node3 = NodeInfo.Builder.create().withUrl(NodeUri.create("http://party3").asString()).withRecipients(Set.of(mock(Recipient.class))).withSupportedApiVersions(Set.of(BaseVersion.API_VERSION_1, EnhancedPrivacyVersion.API_VERSION_2)).build();
    final NodeInfo node4 = NodeInfo.Builder.create().withUrl(NodeUri.create("http://party4").asString()).withRecipients(Set.of(mock(Recipient.class))).withSupportedApiVersions(Set.of(BaseVersion.API_VERSION_1)).build();
    return Set.of(node1, node2, node3, node4);
}
Also used : NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo)

Example 19 with NodeInfo

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

the class FindRecipientFromPartyInfoTest method executeKeyFound.

@Test
public void executeKeyFound() {
    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(publicKey);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    boolean result = findRecipientFromPartyInfo.execute(batchWorkflowContext);
    assertThat(result).isTrue();
    assertThat(batchWorkflowContext.getRecipient()).isSameAs(recipient);
    verify(discovery).getCurrent();
}
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)

Example 20 with NodeInfo

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

the class PartyInfoResourceTest method validationDisabledPassesAllKeysToStore.

@Test
public void validationDisabledPassesAllKeysToStore() {
    this.partyInfoResource = new PartyInfoResource(discovery, partyInfoParser, restClient, enclave, payloadEncoder, false, partyStore);
    final byte[] payload = "Test message".getBytes();
    final String url = "http://www.bogus.com";
    final String otherurl = "http://www.randomaddress.com";
    final PublicKey recipientKey = PublicKey.from("recipientKey".getBytes());
    final Set<Recipient> recipientList = new HashSet<>(Arrays.asList(Recipient.of(recipientKey, url), Recipient.of(recipientKey, otherurl)));
    final PartyInfo partyInfo = new PartyInfo(url, recipientList, Collections.emptySet());
    final NodeInfo nodeInfo = NodeInfoUtil.from(partyInfo, null);
    final ArgumentCaptor<PartyInfo> captor = ArgumentCaptor.forClass(PartyInfo.class);
    final byte[] serialisedData = "SERIALISED".getBytes();
    when(partyInfoParser.from(payload)).thenReturn(partyInfo);
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    when(partyInfoParser.to(captor.capture())).thenReturn(serialisedData);
    final Response callResponse = partyInfoResource.partyInfo(payload, null);
    final byte[] data = (byte[]) callResponse.getEntity();
    assertThat(captor.getValue().getUrl()).isEqualTo(url);
    assertThat(captor.getValue().getRecipients()).isEmpty();
    assertThat(captor.getValue().getParties()).isEmpty();
    assertThat(new String(data)).isEqualTo("SERIALISED");
    verify(partyInfoParser).from(payload);
    verify(partyInfoParser).to(any(PartyInfo.class));
    final ArgumentCaptor<NodeInfo> modifiedPartyInfoCaptor = ArgumentCaptor.forClass(NodeInfo.class);
    verify(discovery).onUpdate(modifiedPartyInfoCaptor.capture());
    final NodeInfo modified = modifiedPartyInfoCaptor.getValue();
    assertThat(modified.getUrl()).isEqualTo(url);
    Set<com.quorum.tessera.partyinfo.node.Recipient> updatedRecipients = modified.getRecipients();
    assertThat(updatedRecipients).containsExactlyInAnyOrder(com.quorum.tessera.partyinfo.node.Recipient.of(recipientKey, url), com.quorum.tessera.partyinfo.node.Recipient.of(recipientKey, otherurl));
    verify(discovery).getCurrent();
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) Recipient(com.quorum.tessera.partyinfo.model.Recipient) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Response(jakarta.ws.rs.core.Response) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) 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