@Test public void ifWorkDirCliOverrideIsProvidedThenItIsAppliedToBothTomlAndCliSetParameters() throws Exception { final Path workdir = Paths.get("override"); if (Files.exists(workdir)) { Files.walk(workdir).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); } Files.createDirectory(workdir); Files.createFile(workdir.resolve("new.pub")); Files.createFile(workdir.resolve("new.key")); Path alwaysSendToFile = Files.createFile(workdir.resolve("alwayssendto")); Files.write( alwaysSendToFile, "/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=\njWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk=" .getBytes()); Path sampleFile = Paths.get(getClass().getResource("/sample-toml-no-nulls-tls-off.conf").toURI()); Map<String, Object> params = new HashMap<>(); params.put("alwaysSendToPath1", "alwayssendto"); params.put("alwaysSendToPath2", "alwayssendto"); String data = ElUtil.process(new String(Files.readAllBytes(sampleFile)), params); Path configFile = Files.createTempFile("workdiroverride", ".txt"); Files.write(configFile, data.getBytes()); String[] args = { "--tomlfile", configFile.toString(), "--workdir", "override", "--publickeys", "new.pub", "--privatekeys", "new.key" }; commandLine.execute(args); final CliResult result = commandLine.getExecutionResult(); assertThat(result).isNotNull(); assertThat(result.getConfig()).isPresent(); final Config config = result.getConfig().get(); final ServerConfig p2pServer = config.getP2PServerConfig(); final SslConfig sslConfig = p2pServer.getSslConfig(); assertThat(p2pServer.getServerAddress()).isEqualTo("http: assertThat(p2pServer.getBindingAddress()).isEqualTo("http: assertThat(this.getUnixSocketServerAddress(config)) .isEqualTo("unix:" + Paths.get("override/constellation.ipc").toAbsolutePath()); assertThat(config.getPeers()) .hasSize(2) .extracting("url") .containsExactly("http: assertThat(config.getKeys().getKeyData()).hasSize(1); assertThat(config.getKeys().getKeyData().get(0)) .extracting("publicKeyPath", "privateKeyPath") .containsExactlyInAnyOrder(Paths.get("override/new.pub"), Paths.get("override/new.key")); assertThat(config.getAlwaysSendTo()) .hasSize(4) .containsExactlyInAnyOrder( "/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=", "jWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk=", "/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=", "jWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk="); assertThat(config.getKeys().getPasswordFile().toString()).isEqualTo("override/passwords"); assertThat(config.getJdbcConfig().getUrl()).isEqualTo("jdbc:h2:mem:tessera"); assertThat(config.isUseWhiteList()).isTrue(); assertThat(sslConfig.getTls()).isEqualTo(SslAuthenticationMode.OFF); assertThat(sslConfig.getServerTlsCertificatePath().toString()).isEqualTo("override/tls-server-cert.pem"); assertThat(sslConfig.getServerTrustCertificates()) .hasSize(2) .containsExactlyInAnyOrder(Paths.get("override/chain1"), Paths.get("override/chain2")); assertThat(sslConfig.getServerTlsKeyPath().toString()).isEqualTo("override/tls-server-key.pem"); assertThat(sslConfig.getServerTrustMode()).isEqualTo(SslTrustMode.TOFU); assertThat(sslConfig.getKnownClientsFile().toString()).isEqualTo("override/tls-known-clients"); assertThat(sslConfig.getClientTlsCertificatePath().toString()).isEqualTo("override/tls-client-cert.pem"); assertThat(sslConfig.getClientTrustCertificates()) .hasSize(2) .containsExactlyInAnyOrder(Paths.get("override/clientchain1"), Paths.get("override/clientchain2")); assertThat(sslConfig.getClientTlsKeyPath().toString()).isEqualTo("override/tls-client-key.pem"); assertThat(sslConfig.getClientTrustMode()).isEqualTo(SslTrustMode.CA_OR_TOFU); assertThat(sslConfig.getKnownServersFile().toString()).isEqualTo("override/tls-known-servers"); }
@Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); @Override CliType getType(); @Override CliResult call(); @Override CliResult execute(String... args); void setOverrides(final LegacyOverridesMixin overrides); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); @Override CliType getType(); @Override CliResult call(); @Override CliResult execute(String... args); void setOverrides(final LegacyOverridesMixin overrides);  }