Search in sources :

Example 1 with AutoDiscoveryDisabledException

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

Example 2 with AutoDiscoveryDisabledException

use of com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException in project tessera by ConsenSys.

the class AutoDiscoveryDisabledExceptionMapperTest method handleAutoDiscoveryDisabledException.

@Test
public void handleAutoDiscoveryDisabledException() {
    final String message = ".. all outta gum";
    final AutoDiscoveryDisabledException exception = new AutoDiscoveryDisabledException(message);
    final Response result = mapper.toResponse(exception);
    assertThat(result.getStatus()).isEqualTo(403);
    assertThat(result.getEntity()).isEqualTo(message);
}
Also used : Response(jakarta.ws.rs.core.Response) AutoDiscoveryDisabledException(com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException) Test(org.junit.Test)

Example 3 with AutoDiscoveryDisabledException

use of com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException in project tessera by ConsenSys.

the class DisabledAutoDiscovery method onUpdate.

@Override
public void onUpdate(NodeInfo nodeInfo) {
    if (!knownPeers.contains(NodeUri.create(nodeInfo.getUrl()))) {
        throw new AutoDiscoveryDisabledException(String.format("%s is not a known peer", nodeInfo.getUrl()));
    }
    final NodeUri callerNodeUri = NodeUri.create(nodeInfo.getUrl());
    final Set<PublicKey> keys = nodeInfo.getRecipients().stream().filter(r -> NodeUri.create(r.getUrl()).equals(callerNodeUri)).map(Recipient::getKey).collect(Collectors.toSet());
    final ActiveNode activeNode = ActiveNode.Builder.create().withUri(callerNodeUri).withSupportedVersions(nodeInfo.supportedApiVersions()).withKeys(keys).build();
    networkStore.store(activeNode);
}
Also used : AutoDiscoveryDisabledException(com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException) PublicKey(com.quorum.tessera.encryption.PublicKey) NodeUri(com.quorum.tessera.discovery.NodeUri) ActiveNode(com.quorum.tessera.discovery.ActiveNode)

Aggregations

AutoDiscoveryDisabledException (com.quorum.tessera.partyinfo.AutoDiscoveryDisabledException)3 Test (org.junit.Test)2 ActiveNode (com.quorum.tessera.discovery.ActiveNode)1 NodeUri (com.quorum.tessera.discovery.NodeUri)1 PublicKey (com.quorum.tessera.encryption.PublicKey)1 NodeInfo (com.quorum.tessera.partyinfo.node.NodeInfo)1 Response (jakarta.ws.rs.core.Response)1