use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class ServerConfigsValidatorTest method isNotValidWhenNoP2PServersAreDefined.
@Test
public void isNotValidWhenNoP2PServersAreDefined() {
List<ServerConfig> serverConfigList = serverConfigList().stream().filter(s -> s.getApp() != AppType.P2P).collect(Collectors.toList());
Config config = new Config();
config.setServerConfigs(serverConfigList);
assertThat(validator.isValid(config, cvc)).isFalse();
verify(cvc).disableDefaultConstraintViolation();
verify(cvc).buildConstraintViolationWithTemplate(eq("Exactly one P2P server must be configured."));
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class ServerConfigsValidatorTest method isNotValidWhenTwoOrMoreP2PServersAreDefinedAndEnabled.
@Test
public void isNotValidWhenTwoOrMoreP2PServersAreDefinedAndEnabled() {
List<ServerConfig> serverConfigList = serverConfigList();
serverConfigList.add(serverConfigsMap.get(AppType.P2P));
Config config = new Config();
config.setServerConfigs(serverConfigList);
assertThat(validator.isValid(config, cvc)).isFalse();
verify(cvc).disableDefaultConstraintViolation();
verify(cvc).buildConstraintViolationWithTemplate(eq("Exactly one P2P server must be configured."));
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class AwsKeyVaultIT method tesseraStartupRequestsKeysWhosIdsAreConfigured.
@Test
public void tesseraStartupRequestsKeysWhosIdsAreConfigured() throws Exception {
Map<String, Object> params = Map.of("awsSecretsManagerEndpoint", keyVaultUrl);
Path tempTesseraConfig = ElUtil.createTempFileFromTemplate(getClass().getResource("/vault/tessera-aws-config.json"), params);
List<String> args = new ExecArgsBuilder().withStartScript(startScript).withClassPathItem(distDirectory).withArg("-configfile", tempTesseraConfig.toString()).withArg("-pidfile", pid.toAbsolutePath().toString()).withArg("-jdbc.autoCreateTables", "true").build();
ProcessBuilder processBuilder = new ProcessBuilder(args);
processBuilder.environment().putAll(env());
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
executorService.submit(new StreamConsumer(process.getInputStream(), LOGGER::info));
executorService.submit(() -> {
int exitCode = process.waitFor();
assertThat(exitCode).describedAs("Tessera node exited with code %d", exitCode).isEqualTo(0);
return null;
});
final Config config = JaxbUtil.unmarshal(Files.newInputStream(tempTesseraConfig), Config.class);
final URI bindingUrl = Optional.of(config).map(Config::getP2PServerConfig).map(ServerConfig::getBindingUri).map(UriBuilder::fromUri).map(u -> u.path("upcheck")).map(UriBuilder::build).get();
HttpClient httpClient = HttpClient.newHttpClient();
final HttpRequest request = HttpRequest.newBuilder().uri(bindingUrl).GET().build();
CountDownLatch startUpLatch = new CountDownLatch(1);
executorService.submit(() -> {
while (true) {
try {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
startUpLatch.countDown();
}
} catch (InterruptedException | IOException e) {
}
}
});
assertThat(startUpLatch.await(2, TimeUnit.MINUTES)).isTrue();
assertThat(httpHandler.getCounter()).isEqualTo(2);
List<JsonObject> requests = httpHandler.getRequests().get("secretsmanager.GetSecretValue");
assertThat(requests).hasSize(2);
List<String> secretIds = requests.stream().map(j -> j.getString("SecretId")).collect(Collectors.toList());
assertThat(secretIds).containsExactlyInAnyOrder("secretIdPub", "secretIdKey");
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class MetricsIT method metrics.
@Test
public void metrics() {
final PartyHelper partyHelper = PartyHelper.create();
Set<ServerConfig> serverConfigs = partyHelper.getParties().map(Party::getConfig).map(Config::getServerConfigs).flatMap(List::stream).collect(Collectors.toUnmodifiableSet());
ClientFactory clientFactory = new ClientFactory();
for (ServerConfig serverConfig : serverConfigs) {
Client c = clientFactory.buildFrom(serverConfig);
Response response = c.target(serverConfig.getServerUri()).path("metrics").request().get();
assertThat(response).isNotNull();
assertThat(response.getStatus()).isEqualTo(200);
}
}
use of com.quorum.tessera.config.ServerConfig in project tessera by ConsenSys.
the class PeerToPeerIT method validatePartyInfoContentsOnNodeA.
/*
Assume that not of the tests should have managed to change the initial party info
*/
private void validatePartyInfoContentsOnNodeA() {
Party someParty = partyHelper.getParties().filter(p -> !p.getAlias().equals("A")).findAny().get();
ServerConfig serverContext = someParty.getConfig().getP2PServerConfig();
Client client = clientFactory.buildFrom(serverContext);
Response response = client.target(partyA.getP2PUri()).path("partyinfo").request().get();
assertThat(response.getStatus()).isEqualTo(200);
JsonObject result = response.readEntity(JsonObject.class);
Map<String, String> actual = result.getJsonArray("keys").stream().map(o -> o.asJsonObject()).collect(Collectors.toMap(o -> o.getString("key"), o -> removeTrailingSlash(o.getString("url"))));
EncryptorConfig encryptorConfig = partyHelper.getParties().findFirst().map(Party::getConfig).map(Config::getEncryptor).get();
KeyEncryptor keyEncryptor = KeyEncryptorFactory.newFactory().create(encryptorConfig);
List<String> keyz = partyHelper.getParties().map(Party::getConfig).map(Config::getKeys).flatMap(k -> k.getKeyData().stream()).map(kd -> KeyDataUtil.unmarshal(kd, keyEncryptor)).map(ConfigKeyPair::getPublicKey).collect(Collectors.toList());
List<String> urls = partyHelper.getParties().map(Party::getConfig).map(Config::getP2PServerConfig).map(ServerConfig::getServerAddress).map(s -> removeTrailingSlash(s)).collect(Collectors.toList());
assertThat(actual).containsKeys(keyz.toArray(new String[0]));
assertThat(actual).containsValues(urls.toArray(new String[0]));
}
Aggregations