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();
}
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();
}
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);
}
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();
}
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();
}
Aggregations