use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class DisabledAutoDiscoveryTest method onUpdateNodeSendsNewKey.
@Test
public void onUpdateNodeSendsNewKey() {
String url = knownPeers.iterator().next().asString();
PublicKey key = mock(PublicKey.class);
List<Recipient> recipients = List.of(Recipient.of(key, url));
List<ActiveNode> storedNodes = new ArrayList<>();
doAnswer(invocation -> {
storedNodes.add(invocation.getArgument(0));
return null;
}).when(networkStore).store(any(ActiveNode.class));
NodeInfo nodeInfo = NodeInfo.Builder.create().withUrl(url).withRecipients(recipients).build();
discovery.onUpdate(nodeInfo);
assertThat(storedNodes).hasSize(1);
ActiveNode savedNode = storedNodes.get(0);
assertThat(savedNode.getKeys()).containsExactly(key);
assertThat(savedNode.getUri()).isEqualTo(NodeUri.create(url));
verify(networkStore).store(any(ActiveNode.class));
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class DiscoveryHelperTest method onCreate.
@Test
public void onCreate() {
URI uri = URI.create("http://somedomain.com/");
when(runtimeContext.getPeers()).thenReturn(List.of(uri));
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
PublicKey publicKey = mock(PublicKey.class);
when(enclave.getPublicKeys()).thenReturn(Set.of(publicKey));
discoveryHelper.onCreate();
verify(networkStore).store(any(ActiveNode.class));
verify(runtimeContext).getP2pServerUri();
verify(enclave).getPublicKeys();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildCurrent.
@Test
public void buildCurrent() {
final URI uri = URI.create("http://somedomain.com");
when(runtimeContext.getP2pServerUri()).thenReturn(uri);
final List<PublicKey> keys = IntStream.range(0, 5).mapToObj(i -> mock(PublicKey.class)).collect(Collectors.toList());
final ActiveNode activeNode = ActiveNode.Builder.create().withUri(NodeUri.create(uri)).withKeys(keys).build();
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
NodeInfo result = discoveryHelper.buildCurrent();
assertThat(result).isNotNull();
assertThat(result.getUrl()).isEqualTo("http://somedomain.com/");
assertThat(result.getRecipients()).hasSize(5);
List<Recipient> recipients = List.copyOf(result.getRecipients());
assertThat(recipients.stream().map(Recipient::getKey).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(keys);
verify(networkStore).getActiveNodes();
verify(runtimeContext).getP2pServerUri();
mockedRuntimeContext.verify(RuntimeContext::getInstance);
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class DiscoveryHelperTest method buildRemoteNodeInfo.
@Test
public void buildRemoteNodeInfo() {
String url = "http://nodeurl.com/";
final PublicKey key = PublicKey.from("key".getBytes());
final PublicKey anotherKey = PublicKey.from("anotherKey".getBytes());
final Recipient recipient = Recipient.of(key, url);
final Recipient sameNodeDifferentKey = Recipient.of(anotherKey, url);
ActiveNode activeNode = mock(ActiveNode.class);
when(activeNode.getUri()).thenReturn(NodeUri.create(url));
when(activeNode.getKeys()).thenReturn(Set.of(key, anotherKey));
when(activeNode.getSupportedVersions()).thenReturn(Set.of("v1", "v2"));
when(networkStore.getActiveNodes()).thenReturn(Stream.of(activeNode));
final NodeInfo result = discoveryHelper.buildRemoteNodeInfo(key);
assertThat(result).isNotNull();
assertThat(result.getUrl()).isEqualTo(url);
assertThat(result.getRecipients()).containsExactlyInAnyOrder(recipient, sameNodeDifferentKey);
assertThat(result.supportedApiVersions()).containsExactlyInAnyOrder("v1", "v2");
verify(networkStore).getActiveNodes();
}
use of com.quorum.tessera.encryption.PublicKey in project tessera by ConsenSys.
the class KeyResource method getPublicKeys.
@GET
@Operation(summary = "/keys", description = "get all public keys managed by the server's enclave")
@ApiResponse(responseCode = "200", description = "server's public keys", content = @Content(schema = @Schema(implementation = GetPublicKeysResponse.class)))
public Response getPublicKeys() {
RuntimeContext runtimeContext = RuntimeContext.getInstance();
Set<PublicKey> publicKeys = runtimeContext.getPublicKeys();
final JsonArrayBuilder keyBuilder = Json.createArrayBuilder();
publicKeys.stream().map(key -> Json.createObjectBuilder().add("key", key.encodeToBase64()).build()).forEach(keyBuilder::add);
final String output = Json.createObjectBuilder().add("keys", keyBuilder.build()).build().toString();
return Response.status(Response.Status.OK).entity(output).build();
}
Aggregations