use of com.quorum.tessera.config.Config in project tessera by ConsenSys.
the class PayloadDigestTest method create.
@Test
public void create() {
ServiceLoader<PayloadDigest> serviceLoader = mock(ServiceLoader.class);
Stream<ServiceLoader.Provider<PayloadDigest>> providerStream = Stream.of(DefaultPayloadDigest.class, SHA512256PayloadDigest.class).map(type -> new ServiceLoader.Provider<PayloadDigest>() {
@Override
public Class<? extends PayloadDigest> type() {
return type;
}
@Override
public PayloadDigest get() {
return mock(type);
}
});
when(serviceLoader.stream()).thenReturn(providerStream);
Config config = mock(Config.class);
when(config.getClientMode()).thenReturn(clientMode);
ConfigFactory configFactory = mock(ConfigFactory.class);
when(configFactory.getConfig()).thenReturn(config);
PayloadDigest result;
try (var serviceLoaderMockedStatic = mockStatic(ServiceLoader.class);
var configFactoryMockedStatic = mockStatic(ConfigFactory.class)) {
serviceLoaderMockedStatic.when(() -> ServiceLoader.load(PayloadDigest.class)).thenReturn(serviceLoader);
configFactoryMockedStatic.when(ConfigFactory::create).thenReturn(configFactory);
result = PayloadDigest.create();
serviceLoaderMockedStatic.verify(() -> ServiceLoader.load(PayloadDigest.class));
serviceLoaderMockedStatic.verifyNoMoreInteractions();
configFactoryMockedStatic.verify(ConfigFactory::create);
configFactoryMockedStatic.verifyNoMoreInteractions();
}
assertThat(result).isExactlyInstanceOf(digestType).isNotNull();
}
use of com.quorum.tessera.config.Config in project tessera by ConsenSys.
the class EnclaveServerProvider method provider.
public static EnclaveServer provider() {
Config config = ConfigFactory.create().getConfig();
Enclave enclave = EnclaveFactoryImpl.createServer(config);
LOGGER.debug("Creating server with {}", enclave);
return new EnclaveServerImpl(enclave);
}
use of com.quorum.tessera.config.Config 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.Config in project tessera by ConsenSys.
the class AzureStepDefs method startTessera.
private void startTessera(List<String> args, List<String> jvmArgs, Path verifyConfig) throws Exception {
LOGGER.info("Starting: {}", String.join(" ", args));
String jvmArgsStr = String.join(" ", jvmArgs);
LOGGER.info("JVM Args: {}", jvmArgsStr);
ProcessBuilder tesseraProcessBuilder = new ProcessBuilder(args);
Map<String, String> tesseraEnvironment = tesseraProcessBuilder.environment();
tesseraEnvironment.put(AZURE_CLIENT_ID, "my-client-id");
tesseraEnvironment.put(AZURE_CLIENT_SECRET, "my-client-secret");
tesseraEnvironment.put("AZURE_TENANT_ID", "my-tenant-id");
tesseraEnvironment.put("JAVA_OPTS", // JAVA_OPTS is read by start script and is used to provide jvm args
jvmArgsStr);
try {
tesseraProcess.set(tesseraProcessBuilder.redirectErrorStream(true).start());
} catch (NullPointerException ex) {
ex.printStackTrace();
throw new NullPointerException("Check that application.jar property has been set");
}
executorService.submit(() -> {
try (BufferedReader reader = Stream.of(tesseraProcess.get().getInputStream()).map(InputStreamReader::new).map(BufferedReader::new).findAny().get()) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
});
CountDownLatch startUpLatch = new CountDownLatch(1);
if (Objects.nonNull(verifyConfig)) {
final Config config = JaxbUtil.unmarshal(Files.newInputStream(verifyConfig), Config.class);
final URL bindingUrl = UriBuilder.fromUri(config.getP2PServerConfig().getBindingUri()).path("upcheck").build().toURL();
executorService.submit(() -> {
while (true) {
try {
HttpURLConnection conn = (HttpURLConnection) bindingUrl.openConnection();
conn.connect();
System.out.println(bindingUrl + " started." + conn.getResponseCode());
startUpLatch.countDown();
return;
} catch (IOException ex) {
try {
TimeUnit.MILLISECONDS.sleep(200L);
} catch (InterruptedException ex1) {
}
}
}
});
boolean started = startUpLatch.await(30, TimeUnit.SECONDS);
if (!started) {
System.err.println(bindingUrl + " Not started. ");
}
}
executorService.submit(() -> {
try {
int exitCode = tesseraProcess.get().waitFor();
startUpLatch.countDown();
if (0 != exitCode) {
System.err.println("Tessera node exited with code " + exitCode);
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
});
startUpLatch.await(30, TimeUnit.SECONDS);
}
use of com.quorum.tessera.config.Config in project tessera by ConsenSys.
the class HashicorpStepDefs method startTessera.
private void startTessera(List<String> args, List<String> jvmArgs, Path verifyConfig, String authMethod) throws Exception {
String jvmArgsStr = String.join(" ", jvmArgs);
LOGGER.info("Starting: {}", String.join(" ", args));
LOGGER.info("JVM Args: {}", jvmArgsStr);
ProcessBuilder tesseraProcessBuilder = new ProcessBuilder(args);
Map<String, String> tesseraEnvironment = tesseraProcessBuilder.environment();
tesseraEnvironment.put(HASHICORP_CLIENT_KEYSTORE_PWD, "testtest");
tesseraEnvironment.put(HASHICORP_CLIENT_TRUSTSTORE_PWD, "testtest");
tesseraEnvironment.put("JAVA_OPTS", // JAVA_OPTS is read by start script and is used to provide jvm args
jvmArgsStr);
if ("token".equals(authMethod)) {
Objects.requireNonNull(vaultToken);
tesseraEnvironment.put(HASHICORP_TOKEN, vaultToken);
} else {
Objects.requireNonNull(approleRoleId);
Objects.requireNonNull(approleSecretId);
tesseraEnvironment.put(HASHICORP_ROLE_ID, approleRoleId);
tesseraEnvironment.put(HASHICORP_SECRET_ID, approleSecretId);
}
try {
tesseraProcess.set(tesseraProcessBuilder.redirectErrorStream(true).start());
} catch (NullPointerException ex) {
throw new NullPointerException("Check that application.jar property has been set");
}
executorService.submit(() -> {
try (BufferedReader reader = Stream.of(tesseraProcess.get().getInputStream()).map(InputStreamReader::new).map(BufferedReader::new).findAny().get()) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
});
CountDownLatch startUpLatch = new CountDownLatch(1);
if (Objects.nonNull(verifyConfig)) {
final Config config = JaxbUtil.unmarshal(Files.newInputStream(verifyConfig), Config.class);
final URL bindingUrl = UriBuilder.fromUri(config.getP2PServerConfig().getBindingUri()).path("upcheck").build().toURL();
executorService.submit(() -> {
while (true) {
try {
HttpURLConnection conn = (HttpURLConnection) bindingUrl.openConnection();
conn.connect();
System.out.println(bindingUrl + " started." + conn.getResponseCode());
startUpLatch.countDown();
return;
} catch (IOException ex) {
try {
TimeUnit.MILLISECONDS.sleep(200L);
} catch (InterruptedException ex1) {
}
}
}
});
boolean started = startUpLatch.await(30, TimeUnit.SECONDS);
if (!started) {
System.err.println(bindingUrl + " Not started. ");
}
}
executorService.submit(() -> {
try {
int exitCode = tesseraProcess.get().waitFor();
startUpLatch.countDown();
if (0 != exitCode) {
System.err.println("Tessera node exited with code " + exitCode);
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
});
startUpLatch.await(30, TimeUnit.SECONDS);
}
Aggregations