Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bind address separate to advertised address #448

Merged
merged 22 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.quorum.tessera.config.cli;

import com.quorum.tessera.config.Config;
import com.quorum.tessera.config.KeyConfiguration;
import com.quorum.tessera.config.Peer;
import com.quorum.tessera.config.PrivateKeyType;
import com.quorum.tessera.config.SslAuthenticationMode;
import com.quorum.tessera.config.SslTrustMode;
import com.quorum.tessera.config.*;
import com.quorum.tessera.config.util.JaxbUtil;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.annotation.XmlElement;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
Expand All @@ -16,13 +17,8 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.xml.bind.annotation.XmlElement;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OverrideUtilTest {

Expand All @@ -31,12 +27,13 @@ public class OverrideUtilTest {
@Test
public void buildOptions() {

List<String> expected = Arrays.asList(
final List<String> expected = Arrays.asList(
"jdbc.username",
"jdbc.password",
"jdbc.url",
"server.hostName",
"server.port",
"server.bindingAddress",
"server.sslConfig.tls",
"server.sslConfig.generateKeyStoreIfNotExisted",
"server.sslConfig.serverKeyStore",
Expand Down Expand Up @@ -83,19 +80,19 @@ public void buildOptions() {
"server.sslConfig.serverTrustCertificates"
);

Map<String, Class> results = OverrideUtil.buildConfigOptions();
final Map<String, Class> results = OverrideUtil.buildConfigOptions();

assertThat(results.keySet())
.filteredOn(s -> !s.contains("$jacocoData"))
.containsExactlyInAnyOrderElementsOf(expected);
.filteredOn(s -> !s.contains("$jacocoData"))
.containsExactlyInAnyOrderElementsOf(expected);

assertThat(results.get("server.sslConfig.knownClientsFile")).isEqualTo(Path.class);
assertThat(results.get("keys.passwords")).isEqualTo(String[].class);

}

@Test
public void initialiseConfigFromNoValues() throws Exception {
public void initialiseConfigFromNoValues() {

Config config = OverrideUtil.createInstance(Config.class);

Expand All @@ -109,14 +106,15 @@ public void initialiseConfigFromNoValues() throws Exception {
OverrideUtil.setValue(config, "jdbc.url", "someurl");
OverrideUtil.setValue(config, "server.hostName", "somehost");
OverrideUtil.setValue(config, "server.port", "999");
OverrideUtil.setValue(config, "server.bindingAddress", "http://binding:9999");
OverrideUtil.setValue(config, "keys.passwords", "pw_one", "pw_two");

OverrideUtil.setValue(config, "server.sslConfig.clientKeyStorePassword", "SomeClientKeyStorePassword");

OverrideUtil.setValue(config, "server.sslConfig.clientTrustStore", "ClientTrustStore");

OverrideUtil.setValue(config, "server.sslConfig.clientTrustCertificates",
"ClientTrustCertificates_1", "ClientTrustCertificates_2");
"ClientTrustCertificates_1", "ClientTrustCertificates_2");

OverrideUtil.setValue(config, "server.sslConfig.clientTrustMode", "CA_OR_TOFU");

Expand All @@ -134,37 +132,32 @@ public void initialiseConfigFromNoValues() throws Exception {
assertThat(config.isUseWhiteList()).isTrue();

assertThat(config.getPeers()).hasSize(2);
assertThat(config.getKeys().getPasswords())
.containsExactlyInAnyOrder("pw_one", "pw_two");

assertThat(config.getServerConfig()).isNotNull();
assertThat(config.getServerConfig().getHostName()).isEqualTo("somehost");
assertThat(config.getServerConfig().getPort()).isEqualTo(999);

assertThat(config.getServerConfig().getSslConfig().getClientKeyStorePassword())
.isEqualTo("SomeClientKeyStorePassword");

assertThat(config.getServerConfig().getSslConfig().getClientTrustStore())
.isEqualTo(Paths.get("ClientTrustStore"));
assertThat(config.getKeys()).isNotNull();
assertThat(config.getKeys().getPasswords()).containsExactlyInAnyOrder("pw_one", "pw_two");
assertThat(config.getKeys().getKeyData()).isEmpty();

assertThat(config.getServerConfig().getSslConfig().getClientTrustMode())
.isEqualTo(SslTrustMode.CA_OR_TOFU);
final ServerConfig serverConfig = config.getServerConfig();
assertThat(serverConfig).isNotNull();
assertThat(serverConfig.getHostName()).isEqualTo("somehost");
assertThat(serverConfig.getPort()).isEqualTo(999);
assertThat(serverConfig.getBindingAddress()).isEqualTo("http://binding:9999");

assertThat(config.getServerConfig().getSslConfig().getClientTrustCertificates())
.containsExactly(Paths.get("ClientTrustCertificates_1"), Paths.get("ClientTrustCertificates_2"));
assertThat(serverConfig.getSslConfig().getClientKeyStorePassword()).isEqualTo("SomeClientKeyStorePassword");

assertThat(config.getServerConfig().getInfluxConfig().getPushIntervalInSecs()).isEqualTo(987L);
assertThat(serverConfig.getSslConfig().getClientTrustStore()).isEqualTo(Paths.get("ClientTrustStore"));

assertThat(config.getKeys()).isNotNull();
assertThat(serverConfig.getSslConfig().getClientTrustMode()).isEqualTo(SslTrustMode.CA_OR_TOFU);

KeyConfiguration keyConfig = config.getKeys();
assertThat(serverConfig.getSslConfig().getClientTrustCertificates())
.containsExactly(Paths.get("ClientTrustCertificates_1"), Paths.get("ClientTrustCertificates_2"));

assertThat(keyConfig.getKeyData()).isEmpty();
assertThat(serverConfig.getInfluxConfig().getPushIntervalInSecs()).isEqualTo(987L);

}

@Test
public void overrideExistingValueKeyDataWithPublicKey() throws Exception {
public void overrideExistingValueKeyDataWithPublicKey() {

Config config = OverrideUtil.createInstance(Config.class);

Expand All @@ -182,7 +175,7 @@ public void overrideExistingValueKeyDataWithPublicKey() throws Exception {
}

@Test
public void overrideExistingValueKeyDataWithPrivateKeyType() throws Exception {
public void overrideExistingValueKeyDataWithPrivateKeyType() {

Config config = OverrideUtil.createInstance(Config.class);

Expand All @@ -197,10 +190,10 @@ public void overrideExistingValueKeyDataWithPrivateKeyType() throws Exception {
assertThat(keyConfig.getKeyData()).hasSize(2);

assertThat(keyConfig.getKeyData().get(0)
.getConfig().getType()).isEqualTo(priavteKeyType);
.getConfig().getType()).isEqualTo(priavteKeyType);

assertThat(keyConfig.getKeyData().get(1)
.getConfig().getType()).isEqualTo(priavteKeyType);
.getConfig().getType()).isEqualTo(priavteKeyType);

}

Expand Down Expand Up @@ -256,9 +249,9 @@ public void isSimple() {
@Test
public void toArrayType() {
assertThat(OverrideUtil.toArrayType(String.class))
.isEqualTo(String[].class);
.isEqualTo(String[].class);
assertThat(OverrideUtil.toArrayType(Path.class))
.isEqualTo(Path[].class);
.isEqualTo(Path[].class);
}

@Test
Expand All @@ -277,23 +270,18 @@ public void classForName() {
@Test
public void convertTo() {

assertThat(OverrideUtil.convertTo(Path.class, "SOMEFILE"))
.isEqualTo(Paths.get("SOMEFILE"));
assertThat(OverrideUtil.convertTo(Path.class, "SOMEFILE")).isEqualTo(Paths.get("SOMEFILE"));

assertThat(OverrideUtil.convertTo(String.class, "SOMESTR"))
.isEqualTo("SOMESTR");
assertThat(OverrideUtil.convertTo(String.class, "SOMESTR")).isEqualTo("SOMESTR");

assertThat(OverrideUtil.convertTo(Integer.class, "999"))
.isEqualTo(999);
assertThat(OverrideUtil.convertTo(Integer.class, "999")).isEqualTo(999);

assertThat(OverrideUtil.convertTo(Long.class, "999"))
.isEqualTo(999L);
assertThat(OverrideUtil.convertTo(Long.class, "999")).isEqualTo(999L);

assertThat(OverrideUtil.convertTo(Boolean.class, "true"))
.isTrue();
assertThat(OverrideUtil.convertTo(Boolean.class, "true")).isTrue();

assertThat(OverrideUtil.convertTo(SslAuthenticationMode.class, "STRICT"))
.isEqualTo(SslAuthenticationMode.STRICT);
.isEqualTo(SslAuthenticationMode.STRICT);

assertThat(OverrideUtil.convertTo(String.class, null)).isNull();

Expand Down Expand Up @@ -332,7 +320,7 @@ public void createConfigInstance() {
}

@Test
public void overrideExistingValueKeyDataWithPrivateKeyData() throws Exception {
public void overrideExistingValueKeyDataWithPrivateKeyData() {

Config config = OverrideUtil.createInstance(Config.class);

Expand All @@ -347,9 +335,9 @@ public void overrideExistingValueKeyDataWithPrivateKeyData() throws Exception {
assertThat(keyConfig.getKeyData()).hasSize(1);

assertThat(keyConfig.getKeyData().get(0)
.getConfig()
.getPrivateKeyData()
.getSnonce()).isEqualTo(value);
.getConfig()
.getPrivateKeyData()
.getSnonce()).isEqualTo(value);

}

Expand Down Expand Up @@ -436,8 +424,8 @@ public void defineAlwaysSendToWithOverridesOnly() throws Exception {

@Test
public void convertToByteArray() {
byte[] ressult = OverrideUtil.convertTo(byte[].class, "HELLOW");
assertThat(ressult).isEqualTo("HELLOW".getBytes());
final byte[] result = OverrideUtil.convertTo(byte[].class, "HELLOW");
assertThat(result).isEqualTo("HELLOW".getBytes());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public Config build() {
toPath(workDir, sslClientTlsCertificatePath)
);

final ServerConfig serverConfig = new ServerConfig(serverHostname, serverPort, sslConfig, null);
final ServerConfig serverConfig = new ServerConfig(serverHostname, serverPort, sslConfig, null, null);

final List<Peer> peerList;
if(peers != null) {
Expand All @@ -279,7 +279,7 @@ public Config build() {
}

forwardingKeys = keyList.stream()
.collect(Collectors.toList());
.collect(Collectors.toList());
} else {
forwardingKeys = Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.io.PrintStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -17,8 +16,6 @@ public class ConfigBuilderTest {

private final ConfigBuilder builderWithValidValues = FixtureUtil.builderWithValidValues();

private final ConfigBuilder builderWithNullValues = FixtureUtil.builderWithNullValues();

@Test
public void nullIsNullAndNotAStringWithTheValueOfNull() {
assertThat(ConfigBuilder.toPath(null, null)).isNull();
Expand All @@ -27,43 +24,40 @@ public void nullIsNullAndNotAStringWithTheValueOfNull() {

@Test
public void buildValid() {
Config result = builderWithValidValues.build();
final Config result = this.builderWithValidValues.build();

assertThat(result).isNotNull();
builderWithValidValues.sslClientTrustCertificates(Arrays.asList("sslServerTrustCertificates"));

assertThat(result.getUnixSocketFile()).isEqualTo(Paths.get("somepath.ipc"));

assertThat(result.getKeys().getKeyData()).hasSize(1);

KeyData keyData = result.getKeys().getKeyData().get(0);

final KeyData keyData = result.getKeys().getKeyData().get(0);
assertThat(keyData).isNotNull();
assertThat(keyData.getConfig().getType()).isEqualTo(PrivateKeyType.LOCKED);

ServerConfig serverConfig = result.getServerConfig();
final ServerConfig serverConfig = result.getServerConfig();
assertThat(serverConfig).isNotNull();
assertThat(serverConfig.getPort()).isEqualTo(892);
assertThat(serverConfig.getHostName()).isEqualTo("http://bogus.com");
assertThat(serverConfig.getBindingAddress()).isEqualTo("http://bogus.com:892");

SslConfig sslConfig = serverConfig.getSslConfig();
final SslConfig sslConfig = serverConfig.getSslConfig();
assertThat(sslConfig).isNotNull();

assertThat(sslConfig.getClientKeyStorePassword()).isEqualTo("sslClientKeyStorePassword");
assertThat(sslConfig.getClientKeyStore()).isEqualTo(Paths.get("sslClientKeyStorePath"));
assertThat(sslConfig.getClientTlsKeyPath()).isEqualTo(Paths.get("sslClientTlsKeyPath"));

assertThat(sslConfig.getServerTrustCertificates())
.containsExactly(Paths.get("sslServerTrustCertificates"));
assertThat(sslConfig.getServerTrustCertificates()).containsExactly(Paths.get("sslServerTrustCertificates"));

assertThat(result.getJdbcConfig().getUsername()).isEqualTo("jdbcUsername");
assertThat(result.getJdbcConfig().getPassword()).isEqualTo("jdbcPassword");
assertThat(result.getJdbcConfig().getUrl()).isEqualTo("jdbc:bogus");

assertThat(result.getServerConfig().getPort()).isEqualTo(892);

}

@Test
public void influxHostNameEmptyThenInfluxConfigIsNull() {
Config result = builderWithValidValues.build();
final Config result = builderWithValidValues.build();

assertThat(result.getServerConfig().getInfluxConfig()).isNull();
}
Expand All @@ -83,8 +77,9 @@ public void alwaysSendToFileNotFoundPrintsErrorMessageToTerminal() {
final ConfigBuilder builder = builderWithValidValues.alwaysSendTo(alwaysSendTo);
builder.build();

assertThat(errContent.toString()).isEqualTo("Error reading alwayssendto file: doesntexist.txt\n" +
"Error reading alwayssendto file: alsodoesntexist.txt\n");
assertThat(errContent.toString()).isEqualTo(
"Error reading alwayssendto file: doesntexist.txt\nError reading alwayssendto file: alsodoesntexist.txt\n"
);

System.setErr(originalErr);

Expand All @@ -93,8 +88,7 @@ public void alwaysSendToFileNotFoundPrintsErrorMessageToTerminal() {
@Test
public void buildWithNoValuesSetDoesNotThrowException() {
final ConfigBuilder builder = ConfigBuilder.create();

Config config = builder.build();
final Config config = builder.build();

assertThat(config).isNotNull();
}
Expand Down
Loading