use of com.quorum.tessera.encryption.KeyNotFoundException in project tessera by ConsenSys.
the class KeyNotFoundExceptionMapperTest method toResponse.
@Test
public void toResponse() {
final KeyNotFoundException keyNotFoundException = new KeyNotFoundException("OUCH");
final Response result = instance.toResponse(keyNotFoundException);
assertThat(result).isNotNull();
final String message = (String) result.getEntity();
assertThat(message).isEqualTo("OUCH");
assertThat(result.getStatus()).isEqualTo(404);
}
use of com.quorum.tessera.encryption.KeyNotFoundException in project tessera by ConsenSys.
the class DiscoveryHelperImpl method buildRemoteNodeInfo.
@Override
public NodeInfo buildRemoteNodeInfo(PublicKey recipientKey) {
final ActiveNode activeNode = networkStore.getActiveNodes().filter(node -> node.getKeys().contains(recipientKey)).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
final String nodeUrl = activeNode.getUri().asString();
final Set<Recipient> recipients = activeNode.getKeys().stream().map(k -> Recipient.of(k, nodeUrl)).collect(Collectors.toSet());
final NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(nodeUrl).withRecipients(recipients).withSupportedApiVersions(activeNode.getSupportedVersions()).build();
return nodeInfo;
}
use of com.quorum.tessera.encryption.KeyNotFoundException in project tessera by ConsenSys.
the class FindRecipientFromPartyInfoTest method executeKeyNotFound.
@Test
public void executeKeyNotFound() {
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(mock(PublicKey.class));
when(nodeInfo.getRecipients()).thenReturn(Set.of(recipient));
when(discovery.getCurrent()).thenReturn(nodeInfo);
try {
findRecipientFromPartyInfo.execute(batchWorkflowContext);
failBecauseExceptionWasNotThrown(KeyNotFoundException.class);
} catch (KeyNotFoundException ex) {
verify(discovery).getCurrent();
assertThat(batchWorkflowContext.getRecipient()).isNull();
assertThat(batchWorkflowContext.getRecipientKey()).isSameAs(publicKey);
}
}
use of com.quorum.tessera.encryption.KeyNotFoundException in project tessera by ConsenSys.
the class FindRecipientFromPartyInfo method execute.
@Override
public boolean execute(BatchWorkflowContext event) {
PublicKey recipientKey = event.getRecipientKey();
final Recipient retrievedRecipientFromStore = discovery.getCurrent().getRecipients().stream().filter(recipient -> recipientKey.equals(recipient.getKey())).findAny().orElseThrow(() -> new KeyNotFoundException("Recipient not found for key: " + recipientKey.encodeToBase64()));
event.setRecipient(retrievedRecipientFromStore);
return true;
}
Aggregations