[NC-2119] permissioning config path CLI (#729)

* added CLI for permissioning config file path

* added test for --permissions-config-file without param value

* merged changes from NC-1968 and set the config path on the PermissioningConfiguration object when it's created

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Sally MacFarlane 6 years ago committed by GitHub
parent f2438dcf79
commit a5afe34e34
  1. 24
      ethereum/p2p/src/main/java/tech/pegasys/pantheon/ethereum/p2p/peers/Peer.java
  2. 9
      ethereum/permissioning/src/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfiguration.java
  3. 12
      pantheon/src/main/java/tech/pegasys/pantheon/PermissioningConfigurationBuilder.java
  4. 2
      pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java
  5. 24
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  6. 28
      pantheon/src/main/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidator.java
  7. 45
      pantheon/src/test/java/tech/pegasys/pantheon/PermissioningConfigurationBuilderTest.java
  8. 49
      pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java
  9. 10
      pantheon/src/test/java/tech/pegasys/pantheon/util/PermissioningConfigurationValidatorTest.java
  10. 1
      pantheon/src/test/resources/everything_config.toml

@ -16,6 +16,10 @@ import tech.pegasys.pantheon.crypto.SecureRandomProvider;
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
import java.util.OptionalInt;
import org.bouncycastle.util.encoders.Hex;
public interface Peer extends PeerId { public interface Peer extends PeerId {
/** /**
@ -49,4 +53,24 @@ public interface Peer extends PeerId {
out.writeBytesValue(getId()); out.writeBytesValue(getId());
out.endList(); out.endList();
} }
/**
* Returns this peer's enode URI.
*
* @return The enode URI as a String.
*/
default String getEnodeURI() {
String url = Hex.toHexString(this.getId().extractArray());
Endpoint endpoint = this.getEndpoint();
String nodeIp = endpoint.getHost();
OptionalInt tcpPort = endpoint.getTcpPort();
int udpPort = endpoint.getUdpPort();
if (tcpPort.isPresent() && (tcpPort.getAsInt() != udpPort)) {
return String.format(
"enode://%s@%s:%d?discport=%d", url, nodeIp, tcpPort.getAsInt(), udpPort);
} else {
return String.format("enode://%s@%s:%d", url, nodeIp, udpPort);
}
}
} }

@ -22,6 +22,7 @@ public class PermissioningConfiguration {
private List<String> accountWhitelist; private List<String> accountWhitelist;
private boolean nodeWhitelistSet; private boolean nodeWhitelistSet;
private boolean accountWhitelistSet; private boolean accountWhitelistSet;
private String configurationFilePath;
public List<URI> getNodeWhitelist() { public List<URI> getNodeWhitelist() {
return nodeWhitelist; return nodeWhitelist;
@ -59,4 +60,12 @@ public class PermissioningConfiguration {
public boolean isAccountWhitelistSet() { public boolean isAccountWhitelistSet() {
return accountWhitelistSet; return accountWhitelistSet;
} }
public String getConfigurationFilePath() {
return configurationFilePath;
}
public void setConfigurationFilePath(final String configurationFilePath) {
this.configurationFilePath = configurationFilePath;
}
} }

@ -39,23 +39,25 @@ public class PermissioningConfigurationBuilder {
final boolean permissionedNodeEnabled, final boolean permissionedNodeEnabled,
final boolean permissionedAccountEnabled) { final boolean permissionedAccountEnabled) {
String permToml = permissioningConfigTomlAsString(permissioningConfigFile(configFilePath));
return permissioningConfiguration( return permissioningConfiguration(
TomlConfigFileParser.loadConfiguration(permToml), configFilePath, permissionedNodeEnabled, permissionedAccountEnabled);
permissionedNodeEnabled,
permissionedAccountEnabled);
} }
public static PermissioningConfiguration permissioningConfiguration( public static PermissioningConfiguration permissioningConfiguration(
final TomlParseResult permToml, final String configFilePath,
final boolean permissionedNodeEnabled, final boolean permissionedNodeEnabled,
final boolean permissionedAccountEnabled) { final boolean permissionedAccountEnabled) {
TomlParseResult permToml =
TomlConfigFileParser.loadConfiguration(
permissioningConfigTomlAsString(permissioningConfigFile(configFilePath)));
TomlArray accountWhitelistTomlArray = permToml.getArray("accounts-whitelist"); TomlArray accountWhitelistTomlArray = permToml.getArray("accounts-whitelist");
TomlArray nodeWhitelistTomlArray = permToml.getArray("nodes-whitelist"); TomlArray nodeWhitelistTomlArray = permToml.getArray("nodes-whitelist");
final PermissioningConfiguration permissioningConfiguration = final PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault(); PermissioningConfiguration.createDefault();
permissioningConfiguration.setConfigurationFilePath(configFilePath);
if (permissionedAccountEnabled) { if (permissionedAccountEnabled) {
if (accountWhitelistTomlArray != null) { if (accountWhitelistTomlArray != null) {
List<String> accountsWhitelistToml = List<String> accountsWhitelistToml =

@ -42,8 +42,8 @@ interface DefaultCommandValues {
long DEFAULT_MAX_REFRESH_DELAY = 3600000; long DEFAULT_MAX_REFRESH_DELAY = 3600000;
long DEFAULT_MIN_REFRESH_DELAY = 1; long DEFAULT_MIN_REFRESH_DELAY = 1;
String DOCKER_GENESIS_LOCATION = "/etc/pantheon/genesis.json"; String DOCKER_GENESIS_LOCATION = "/etc/pantheon/genesis.json";
String PERMISSIONING_CONFIG_LOCATION = "/etc/pantheon/permissioned_config.toml";
String DOCKER_DATADIR_LOCATION = "/var/lib/pantheon"; String DOCKER_DATADIR_LOCATION = "/var/lib/pantheon";
String PERMISSIONING_CONFIG_LOCATION = "permissions_config.toml";
String MANDATORY_HOST_FORMAT_HELP = "<HOST>"; String MANDATORY_HOST_FORMAT_HELP = "<HOST>";
String MANDATORY_PORT_FORMAT_HELP = "<PORT>"; String MANDATORY_PORT_FORMAT_HELP = "<PORT>";
// Default should be FAST for the next release // Default should be FAST for the next release

@ -462,6 +462,13 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
) )
private final Boolean permissionsAccountsEnabled = false; private final Boolean permissionsAccountsEnabled = false;
@Option(
names = {"--permissions-config-path"},
description =
"Path to permissions config TOML file (default: a file named \"permissions_config.toml\" in the Pantheon data folder)"
)
private String permissionsConfigPath = null;
@Option( @Option(
names = {"--privacy-enabled"}, names = {"--privacy-enabled"},
description = "Set if private transaction should be enabled (default: ${DEFAULT-VALUE})" description = "Set if private transaction should be enabled (default: ${DEFAULT-VALUE})"
@ -630,6 +637,15 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
} }
} }
private String getPermissionsConfigPath() {
return permissionsConfigPath != null
? permissionsConfigPath
: dataDir().toAbsolutePath()
+ System.getProperty("file.separator")
+ DefaultCommandValues.PERMISSIONING_CONFIG_LOCATION;
}
private JsonRpcConfiguration jsonRpcConfiguration() { private JsonRpcConfiguration jsonRpcConfiguration() {
CommandLineUtils.checkOptionDependencies( CommandLineUtils.checkOptionDependencies(
@ -722,10 +738,10 @@ public class PantheonCommand implements DefaultCommandValues, Runnable {
return PermissioningConfiguration.createDefault(); return PermissioningConfiguration.createDefault();
} }
return PermissioningConfigurationBuilder.permissioningConfigurationFromToml( final PermissioningConfiguration permissioningConfiguration =
DefaultCommandValues.PERMISSIONING_CONFIG_LOCATION, PermissioningConfigurationBuilder.permissioningConfigurationFromToml(
permissionsNodesEnabled, getPermissionsConfigPath(), permissionsNodesEnabled, permissionsAccountsEnabled);
permissionsAccountsEnabled); return permissioningConfiguration;
} }
private PrivacyParameters orionConfiguration() { private PrivacyParameters orionConfiguration() {

@ -14,18 +14,15 @@ package tech.pegasys.pantheon.util;
import tech.pegasys.pantheon.cli.EthNetworkConfig; import tech.pegasys.pantheon.cli.EthNetworkConfig;
import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration; import tech.pegasys.pantheon.ethereum.p2p.config.DiscoveryConfiguration;
import tech.pegasys.pantheon.ethereum.p2p.peers.Endpoint;
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; import tech.pegasys.pantheon.ethereum.p2p.peers.Peer;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.OptionalInt;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.bouncycastle.util.encoders.Hex;
public class PermissioningConfigurationValidator { public class PermissioningConfigurationValidator {
public static void areAllBootnodesAreInWhitelist( public static void areAllBootnodesAreInWhitelist(
@ -44,26 +41,19 @@ public class PermissioningConfigurationValidator {
node -> node ->
!permissioningConfiguration !permissioningConfiguration
.getNodeWhitelist() .getNodeWhitelist()
.contains(URI.create(buildEnodeURI(node)))) .contains(URI.create(node.getEnodeURI())))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
if (!bootnodesNotInWhitelist.isEmpty()) { if (!bootnodesNotInWhitelist.isEmpty()) {
throw new Exception("Bootnode(s) not in nodes-whitelist " + bootnodesNotInWhitelist); throw new Exception(
"Bootnode(s) not in nodes-whitelist " + nodeToURI(bootnodesNotInWhitelist));
} }
} }
private static String buildEnodeURI(final Peer s) { private static Collection<String> nodeToURI(final List<Peer> bootnodesNotInWhitelist) {
String url = Hex.toHexString(s.getId().extractArray()); return bootnodesNotInWhitelist
Endpoint endpoint = s.getEndpoint(); .parallelStream()
String nodeIp = endpoint.getHost(); .map(Peer::getEnodeURI)
OptionalInt tcpPort = endpoint.getTcpPort(); .collect(Collectors.toList());
int udpPort = endpoint.getUdpPort();
if (tcpPort.isPresent() && (tcpPort.getAsInt() != udpPort)) {
return String.format(
"enode://%s@%s:%d?discport=%d", url, nodeIp, tcpPort.getAsInt(), udpPort);
} else {
return String.format("enode://%s@%s:%d", url, nodeIp, udpPort);
}
} }
} }

@ -24,8 +24,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import net.consensys.cava.toml.Toml;
import net.consensys.cava.toml.TomlParseResult;
import org.junit.Test; import org.junit.Test;
public class PermissioningConfigurationBuilderTest { public class PermissioningConfigurationBuilderTest {
@ -54,10 +52,10 @@ public class PermissioningConfigurationBuilderTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue(); assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist()) assertThat(permissioningConfiguration.getAccountWhitelist())
@ -75,10 +73,10 @@ public class PermissioningConfigurationBuilderTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_NODE_WHITELIST_ONLY);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, false); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, false);
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isFalse(); assertThat(permissioningConfiguration.isAccountWhitelistSet()).isFalse();
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue(); assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
@ -91,10 +89,10 @@ public class PermissioningConfigurationBuilderTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ACCOUNT_WHITELIST_ONLY); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ACCOUNT_WHITELIST_ONLY);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, false, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), false, true);
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isFalse(); assertThat(permissioningConfiguration.isNodeWhitelistSet()).isFalse();
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue(); assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
@ -108,10 +106,10 @@ public class PermissioningConfigurationBuilderTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_INVALID_ENODE); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_INVALID_ENODE);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
try { try {
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
fail("Expecting IllegalArgumentException: Enode URL contains an invalid node ID"); fail("Expecting IllegalArgumentException: Enode URL contains an invalid node ID");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertThat(e.getMessage()).startsWith("Enode URL contains an invalid node ID"); assertThat(e.getMessage()).startsWith("Enode URL contains an invalid node ID");
@ -124,10 +122,10 @@ public class PermissioningConfigurationBuilderTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_EMPTY_WHITELISTS); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_EMPTY_WHITELISTS);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue(); assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty(); assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty();
@ -141,10 +139,29 @@ public class PermissioningConfigurationBuilderTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ABSENT_WHITELISTS); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ABSENT_WHITELISTS);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty();
assertThat(permissioningConfiguration.isAccountWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.getAccountWhitelist()).isEmpty();
}
@Test
public void permissioningConfigFromFileMustSetFilePath() throws IOException {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ABSENT_WHITELISTS);
final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile));
PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfigurationFromToml(
toml.toString(), true, true);
assertThat(permissioningConfiguration.getConfigurationFilePath()).isEqualTo(toml.toString());
assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue(); assertThat(permissioningConfiguration.isNodeWhitelistSet()).isTrue();
assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty(); assertThat(permissioningConfiguration.getNodeWhitelist()).isEmpty();

@ -38,6 +38,7 @@ import tech.pegasys.pantheon.ethereum.eth.sync.SyncMode;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration; import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.util.bytes.BytesValue; import tech.pegasys.pantheon.util.bytes.BytesValue;
@ -49,6 +50,7 @@ import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
@ -72,6 +74,7 @@ public class PantheonCommandTest extends CommandTestAbstract {
private final String ORION_URI = "http://1.2.3.4:5555"; private final String ORION_URI = "http://1.2.3.4:5555";
private final String VALID_NODE_ID = private final String VALID_NODE_ID =
"6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"; "6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0";
static final String PERMISSIONING_CONFIG_TOML = "permissioning_config.toml";
private static final JsonRpcConfiguration defaultJsonRpcConfiguration; private static final JsonRpcConfiguration defaultJsonRpcConfiguration;
private static final WebSocketConfiguration defaultWebSocketConfiguration; private static final WebSocketConfiguration defaultWebSocketConfiguration;
@ -89,11 +92,6 @@ public class PantheonCommandTest extends CommandTestAbstract {
"enode://" + VALID_NODE_ID + "@192.168.0.3:4567" "enode://" + VALID_NODE_ID + "@192.168.0.3:4567"
}; };
private final String[] ropstenBootnodes = {
"enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303",
"enode://94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09@192.81.208.223:30303"
};
static { static {
final JsonRpcConfiguration rpcConf = JsonRpcConfiguration.createDefault(); final JsonRpcConfiguration rpcConf = JsonRpcConfiguration.createDefault();
defaultJsonRpcConfiguration = rpcConf; defaultJsonRpcConfiguration = rpcConf;
@ -311,10 +309,47 @@ public class PantheonCommandTest extends CommandTestAbstract {
} }
@Test @Test
public void tomlThatConfiguresEverythingExceptPermissioning() throws IOException { public void permissionsTomlPathWithoutOptionMustDisplayUsage() {
parseCommand("--permissions-config-path");
verifyZeroInteractions(mockRunnerBuilder);
assertThat(commandErrorOutput.toString())
.startsWith("Missing required parameter for option '--permissions-config-path'");
assertThat(commandOutput.toString()).isEmpty();
}
@Test
public void permissionsTomlPathMustUseOption() throws IOException {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_TOML);
final Path permToml = Files.createTempFile("toml", "");
Files.write(permToml, Resources.toByteArray(configFile));
parseCommand(
"--permissions-accounts-enabled", "--permissions-config-path", permToml.toString());
PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
permissioningConfiguration.setConfigurationFilePath(permToml.toString());
permissioningConfiguration.setAccountWhitelist(
Arrays.asList("0x0000000000000000000000000000000000000009"));
verify(mockRunnerBuilder)
.permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture());
verify(mockRunnerBuilder).build();
assertThat(permissioningConfigurationArgumentCaptor.getValue())
.isEqualToComparingFieldByField(permissioningConfiguration);
assertThat(commandErrorOutput.toString()).isEmpty();
assertThat(commandOutput.toString()).isEmpty();
}
@Test
public void tomlThatConfiguresEverythingExceptPermissioningToml() throws IOException {
assumeTrue(isFullInstantiation()); assumeTrue(isFullInstantiation());
// Load a TOML that configures literally everything (except permissioning) // Load a TOML that configures literally everything (except permissioning TOML config)
final URL configFile = Resources.getResource("everything_config.toml"); final URL configFile = Resources.getResource("everything_config.toml");
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));

@ -25,8 +25,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import com.google.common.io.Resources; import com.google.common.io.Resources;
import net.consensys.cava.toml.Toml;
import net.consensys.cava.toml.TomlParseResult;
import org.junit.Test; import org.junit.Test;
public class PermissioningConfigurationValidatorTest { public class PermissioningConfigurationValidatorTest {
@ -44,10 +42,10 @@ public class PermissioningConfigurationValidatorTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ROPSTEN_BOOTNODES); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG_ROPSTEN_BOOTNODES);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
PermissioningConfigurationValidator.areAllBootnodesAreInWhitelist( PermissioningConfigurationValidator.areAllBootnodesAreInWhitelist(
ethNetworkConfig, permissioningConfiguration); ethNetworkConfig, permissioningConfiguration);
@ -61,10 +59,10 @@ public class PermissioningConfigurationValidatorTest {
final URL configFile = Resources.getResource(PERMISSIONING_CONFIG); final URL configFile = Resources.getResource(PERMISSIONING_CONFIG);
final Path toml = Files.createTempFile("toml", ""); final Path toml = Files.createTempFile("toml", "");
Files.write(toml, Resources.toByteArray(configFile)); Files.write(toml, Resources.toByteArray(configFile));
final TomlParseResult tomlResult = Toml.parse(toml);
PermissioningConfiguration permissioningConfiguration = PermissioningConfiguration permissioningConfiguration =
PermissioningConfigurationBuilder.permissioningConfiguration(tomlResult, true, true); PermissioningConfigurationBuilder.permissioningConfiguration(
toml.toAbsolutePath().toString(), true, true);
try { try {
PermissioningConfigurationValidator.areAllBootnodesAreInWhitelist( PermissioningConfigurationValidator.areAllBootnodesAreInWhitelist(

@ -68,6 +68,7 @@ min-gas-price="1"
# Permissioning # Permissioning
permissions-nodes-enabled=false permissions-nodes-enabled=false
permissions-accounts-enabled=false permissions-accounts-enabled=false
permissions-config-path="./permissions_config.toml"
# Privacy # Privacy
privacy-url="http://127.0.0.1:8888" privacy-url="http://127.0.0.1:8888"

Loading…
Cancel
Save