Search in sources :

Example 26 with NodeInfo

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

the class NodeInfoUtilTest method from.

@Test
public void from() {
    PartyInfo partyInfo = mock(PartyInfo.class);
    VersionInfo versionInfo = mock(VersionInfo.class);
    Recipient recipient = Recipient.of(mock(PublicKey.class), "someurl");
    when(partyInfo.getUrl()).thenReturn("someurl");
    when(versionInfo.supportedApiVersions()).thenReturn(Set.of("v1", "v3"));
    when(partyInfo.getRecipients()).thenReturn(Set.of(recipient));
    NodeInfo nodeInfo = NodeInfoUtil.from(partyInfo, Set.of("v1", "v3"));
    assertThat(nodeInfo).isNotNull();
    assertThat(nodeInfo.getUrl()).isEqualTo("someurl");
    assertThat(nodeInfo.supportedApiVersions()).isEqualTo(Set.of("v3", "v1"));
    assertThat(nodeInfo.getRecipients()).hasSize(1);
    assertThat(nodeInfo.getRecipients().iterator().next().getUrl()).isEqualTo("someurl");
}
Also used : VersionInfo(com.quorum.tessera.partyinfo.node.VersionInfo) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) Test(org.junit.Test)

Example 27 with NodeInfo

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

the class BatchWorkflowFactoryImplTest method createBatchWorkflowFactoryImplAndExecuteWorkflow.

@Test
public void createBatchWorkflowFactoryImplAndExecuteWorkflow() {
    BatchWorkflowFactoryImpl batchWorkflowFactory = new BatchWorkflowFactoryImpl(enclave, discovery, resendBatchPublisher);
    BatchWorkflow batchWorkflow = batchWorkflowFactory.create(1L);
    assertThat(batchWorkflow).isNotNull();
    BatchWorkflowContext batchWorkflowContext = new BatchWorkflowContext();
    PublicKey recipientKey = mock(PublicKey.class);
    batchWorkflowContext.setRecipientKey(recipientKey);
    PublicKey ownedKey = mock(PublicKey.class);
    EncodedPayload encodedPayload = mock(EncodedPayload.class);
    when(encodedPayload.getSenderKey()).thenReturn(ownedKey);
    when(encodedPayload.getRecipientKeys()).thenReturn(List.of(recipientKey));
    EncryptedTransaction encryptedTransaction = mock(EncryptedTransaction.class);
    when(encryptedTransaction.getPayload()).thenReturn(encodedPayload);
    batchWorkflowContext.setEncryptedTransaction(encryptedTransaction);
    batchWorkflowContext.setEncodedPayload(encodedPayload);
    batchWorkflowContext.setBatchSize(100);
    when(mockPayloadBuilder.build()).thenReturn(encodedPayload);
    when(enclave.status()).thenReturn(Service.Status.STARTED);
    when(enclave.getPublicKeys()).thenReturn(Set.of(ownedKey));
    NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(recipientKey, "url")));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    assertThat(batchWorkflow.execute(batchWorkflowContext)).isTrue();
    assertThat(batchWorkflow.getPublishedMessageCount()).isOne();
    verify(enclave).status();
    verify(enclave, times(2)).getPublicKeys();
    mockStaticPayloadBuilder.verify(() -> EncodedPayload.Builder.forRecipient(any(), any()));
    verify(mockPayloadBuilder).build();
    verify(discovery).getCurrent();
    verify(resendBatchPublisher).publishBatch(any(), any());
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) BatchWorkflow(com.quorum.tessera.recovery.workflow.BatchWorkflow) BatchWorkflowContext(com.quorum.tessera.recovery.workflow.BatchWorkflowContext) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 28 with NodeInfo

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

the class LegacyResendWorkflowFactoryTest method successForAllStagesReturnsTrue.

@Test
public void successForAllStagesReturnsTrue() {
    final PublicKey targetResendKey = PublicKey.from("target".getBytes());
    final PublicKey localRecipient = PublicKey.from("local-recipient".getBytes());
    final EncodedPayload payload = EncodedPayload.Builder.create().withSenderKey(targetResendKey).withRecipientBox("testbox".getBytes()).build();
    final NodeInfo nodeInfo = mock(NodeInfo.class);
    when(nodeInfo.getRecipients()).thenReturn(Set.of(Recipient.of(targetResendKey, "url")));
    when(discovery.getCurrent()).thenReturn(nodeInfo);
    final EncryptedTransaction encryptedTx = mock(EncryptedTransaction.class);
    when(enclave.getPublicKeys()).thenReturn(Set.of(localRecipient));
    when(enclave.unencryptTransaction(any(EncodedPayload.class), eq(localRecipient))).thenReturn(new byte[0]);
    final BatchWorkflow batchWorkflow = wfFactory.create();
    final BatchWorkflowContext context = new BatchWorkflowContext();
    context.setEncryptedTransaction(encryptedTx);
    context.setEncodedPayload(payload);
    context.setRecipientKey(targetResendKey);
    context.setBatchSize(1);
    final boolean success = batchWorkflow.execute(context);
    assertThat(success).isTrue();
    verify(discovery).getCurrent();
    verify(payloadPublisher).publishPayload(any(EncodedPayload.class), eq(targetResendKey));
    verify(enclave).status();
    verify(enclave, times(2)).getPublicKeys();
    verify(enclave).unencryptTransaction(any(EncodedPayload.class), eq(localRecipient));
}
Also used : PublicKey(com.quorum.tessera.encryption.PublicKey) NodeInfo(com.quorum.tessera.partyinfo.node.NodeInfo) EncodedPayload(com.quorum.tessera.enclave.EncodedPayload) EncryptedTransaction(com.quorum.tessera.data.EncryptedTransaction) Test(org.junit.Test)

Example 29 with NodeInfo

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

the class AutoDiscoveryTest method onUpdateIgnoresKeysThatAreNotOwnedBySender.

@Test
public void onUpdateIgnoresKeysThatAreNotOwnedBySender() {
    String uri = "http://mynode.com";
    PublicKey key = mock(PublicKey.class);
    Recipient recipient = Recipient.of(key, uri);
    Recipient other = Recipient.of(mock(PublicKey.class), "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 30 with NodeInfo

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

the class DisabledAutoDiscoveryTest method onUpdateFromUnknownPeer.

@Test
public void onUpdateFromUnknownPeer() {
    NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl("http://donalddutchdixon.com").build();
    try {
        discovery.onUpdate(nodeInfo);
        failBecauseExceptionWasNotThrown(AutoDiscoveryDisabledException.class);
    } catch (AutoDiscoveryDisabledException exception) {
        assertThat(exception).isNotNull();
    }
}
Also used : AutoDiscoveryDisabledException(com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException) 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