Search in sources :

Example 21 with ServerConfig

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."));
}
Also used : AppType(com.quorum.tessera.config.AppType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ConstraintValidatorContext(jakarta.validation.ConstraintValidatorContext) HashMap(java.util.HashMap) Test(org.junit.Test) ServerConfig(com.quorum.tessera.config.ServerConfig) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) CommunicationType(com.quorum.tessera.config.CommunicationType) List(java.util.List) Map(java.util.Map) After(org.junit.After) Config(com.quorum.tessera.config.Config) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Before(org.junit.Before) ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 22 with ServerConfig

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."));
}
Also used : ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) Test(org.junit.Test)

Example 23 with ServerConfig

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");
}
Also used : Path(java.nio.file.Path) HttpRequest(java.net.http.HttpRequest) HttpURLConnection(java.net.HttpURLConnection) SSLContext(javax.net.ssl.SSLContext) SSLContextBuilder(com.quorum.tessera.ssl.context.SSLContextBuilder) URL(java.net.URL) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) ServerConfig(com.quorum.tessera.config.ServerConfig) HttpRequest(java.net.http.HttpRequest) JaxbUtil(com.quorum.tessera.config.util.JaxbUtil) Map(java.util.Map) After(org.junit.After) JsonObject(jakarta.json.JsonObject) HttpClient(java.net.http.HttpClient) URI(java.net.URI) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) HttpResponse(java.net.http.HttpResponse) Before(org.junit.Before) ElUtil(com.quorum.tessera.test.util.ElUtil) Logger(org.slf4j.Logger) HttpsParameters(com.sun.net.httpserver.HttpsParameters) Files(java.nio.file.Files) IOException(java.io.IOException) Test(org.junit.Test) PortUtil(config.PortUtil) UUID(java.util.UUID) ExecArgsBuilder(exec.ExecArgsBuilder) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ExecUtils(exec.ExecUtils) Executors(java.util.concurrent.Executors) Json(jakarta.json.Json) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Stream(java.util.stream.Stream) UriBuilder(jakarta.ws.rs.core.UriBuilder) Paths(java.nio.file.Paths) Optional(java.util.Optional) Config(com.quorum.tessera.config.Config) HttpsConfigurator(com.sun.net.httpserver.HttpsConfigurator) HttpsServer(com.sun.net.httpserver.HttpsServer) StreamConsumer(exec.StreamConsumer) StreamConsumer(exec.StreamConsumer) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) JsonObject(jakarta.json.JsonObject) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) ServerConfig(com.quorum.tessera.config.ServerConfig) HttpClient(java.net.http.HttpClient) JsonObject(jakarta.json.JsonObject) ExecArgsBuilder(exec.ExecArgsBuilder) Test(org.junit.Test)

Example 24 with ServerConfig

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);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) ServerConfig(com.quorum.tessera.config.ServerConfig) Config(com.quorum.tessera.config.Config) ServerConfig(com.quorum.tessera.config.ServerConfig) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) PartyHelper(com.quorum.tessera.test.PartyHelper) Client(jakarta.ws.rs.client.Client) Test(org.junit.Test)

Example 25 with ServerConfig

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]));
}
Also used : Response(jakarta.ws.rs.core.Response) PublicKey(com.quorum.tessera.encryption.PublicKey) java.util(java.util) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServerConfig(com.quorum.tessera.config.ServerConfig) Response(jakarta.ws.rs.core.Response) After(org.junit.After) JsonObject(jakarta.json.JsonObject) StreamingOutput(jakarta.ws.rs.core.StreamingOutput) Before(org.junit.Before) PartyInfoParser(com.quorum.tessera.p2p.partyinfo.PartyInfoParser) ConfigKeyPair(com.quorum.tessera.config.keypairs.ConfigKeyPair) Client(jakarta.ws.rs.client.Client) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) KeyEncryptorFactory(com.quorum.tessera.config.keys.KeyEncryptorFactory) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) ClientFactory(com.quorum.tessera.jaxrs.client.ClientFactory) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(jakarta.ws.rs.client.Entity) KeyDataUtil(com.quorum.tessera.config.util.KeyDataUtil) PartyInfo(com.quorum.tessera.partyinfo.model.PartyInfo) Stream(java.util.stream.Stream) MediaType(jakarta.ws.rs.core.MediaType) Recipient(com.quorum.tessera.partyinfo.model.Recipient) Config(com.quorum.tessera.config.Config) NodeAlias(suite.NodeAlias) ServerConfig(com.quorum.tessera.config.ServerConfig) ServerConfig(com.quorum.tessera.config.ServerConfig) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Config(com.quorum.tessera.config.Config) KeyEncryptor(com.quorum.tessera.config.keys.KeyEncryptor) JsonObject(jakarta.json.JsonObject) EncryptorConfig(com.quorum.tessera.config.EncryptorConfig) Client(jakarta.ws.rs.client.Client)

Aggregations

ServerConfig (com.quorum.tessera.config.ServerConfig)27 Config (com.quorum.tessera.config.Config)20 Test (org.junit.Test)19 Before (org.junit.Before)13 Client (jakarta.ws.rs.client.Client)11 Collectors (java.util.stream.Collectors)10 ClientFactory (com.quorum.tessera.jaxrs.client.ClientFactory)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)9 After (org.junit.After)9 JsonObject (jakarta.json.JsonObject)7 Response (jakarta.ws.rs.core.Response)7 Stream (java.util.stream.Stream)7 EncryptorConfig (com.quorum.tessera.config.EncryptorConfig)6 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)6 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)6 KeyEncryptorFactory (com.quorum.tessera.config.keys.KeyEncryptorFactory)6 KeyDataUtil (com.quorum.tessera.config.util.KeyDataUtil)6 PublicKey (com.quorum.tessera.encryption.PublicKey)6 PartyInfoParser (com.quorum.tessera.p2p.partyinfo.PartyInfoParser)6 PartyInfo (com.quorum.tessera.partyinfo.model.PartyInfo)6