Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

[PAN-2345] node permissioning controller #1075

Merged
merged 31 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
65ea2a5
draft classes from #1039
macfarla Mar 5, 2019
dd94978
draft classes from #1039
macfarla Mar 5, 2019
4a7411b
refactor NodeWhitelistController -> NodeLocalConfigPermissioningContr…
macfarla Mar 5, 2019
c4e0442
add local file provider
macfarla Mar 5, 2019
78f4b28
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 5, 2019
a0d9934
merged master
macfarla Mar 6, 2019
21350d8
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 7, 2019
269ddab
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 7, 2019
a059497
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 7, 2019
d1f74a6
added test
macfarla Mar 8, 2019
4226d57
added tests
macfarla Mar 8, 2019
d5b5736
added tests
macfarla Mar 8, 2019
a67baa5
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 11, 2019
02fc4f8
removed LocalConfigNodePermissioningProvider for simplicity
macfarla Mar 11, 2019
18768fa
refactor to remove dupe
macfarla Mar 12, 2019
7dae36a
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 12, 2019
d7c6841
draft factory
macfarla Mar 12, 2019
cd1116a
added smart contract config
macfarla Mar 12, 2019
d44d03a
added smart contract permissioning config
macfarla Mar 13, 2019
84d826f
merged master
macfarla Mar 13, 2019
c406dbb
refactored PermissioningConfiguration classes
macfarla Mar 13, 2019
acbaff2
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 13, 2019
09fb5ca
javadoc
macfarla Mar 13, 2019
e8e931a
added checks to test
macfarla Mar 14, 2019
323babf
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 14, 2019
9c0a547
only use SyncStatusProvider if Smart Contract Permissioning enabled
macfarla Mar 14, 2019
4b2bdaf
Merge branch 'master' of github.com:PegaSysEng/pantheon into pan-2345…
macfarla Mar 14, 2019
53551c9
check we are not adding self enode
macfarla Mar 14, 2019
34a7b99
local permissioning controller isPermitted() should return true if ei…
macfarla Mar 14, 2019
0c01c9f
simplified assertions
macfarla Mar 14, 2019
11067c2
formatting
macfarla Mar 14, 2019
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
Expand Up @@ -23,7 +23,7 @@
import tech.pegasys.pantheon.ethereum.core.Util;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition;
import tech.pegasys.pantheon.tests.acceptance.dsl.httptransaction.HttpRequestFactory;
Expand Down Expand Up @@ -83,7 +83,7 @@ public class PantheonNode implements NodeConfiguration, RunnableNode, AutoClosea
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final Optional<LocalPermissioningConfiguration> permissioningConfiguration;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean devMode;
private final boolean discoveryEnabled;
Expand All @@ -103,7 +103,7 @@ public PantheonNode(
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Optional<LocalPermissioningConfiguration> permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final boolean p2pEnabled,
Expand Down Expand Up @@ -472,7 +472,7 @@ public boolean isDiscoveryEnabled() {
return discoveryEnabled;
}

Optional<PermissioningConfiguration> getPermissioningConfiguration() {
Optional<LocalPermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import tech.pegasys.pantheon.ethereum.core.PrivacyParameters;
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;

Expand All @@ -30,7 +30,7 @@ class PantheonFactoryConfiguration {
private final JsonRpcConfiguration jsonRpcConfiguration;
private final WebSocketConfiguration webSocketConfiguration;
private final MetricsConfiguration metricsConfiguration;
private final Optional<PermissioningConfiguration> permissioningConfiguration;
private final Optional<LocalPermissioningConfiguration> permissioningConfiguration;
private final boolean devMode;
private final GenesisConfigProvider genesisConfigProvider;
private final boolean p2pEnabled;
Expand All @@ -44,7 +44,7 @@ class PantheonFactoryConfiguration {
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
final MetricsConfiguration metricsConfiguration,
final Optional<PermissioningConfiguration> permissioningConfiguration,
final Optional<LocalPermissioningConfiguration> permissioningConfiguration,
final boolean devMode,
final GenesisConfigProvider genesisConfigProvider,
final boolean p2pEnabled,
Expand Down Expand Up @@ -88,7 +88,7 @@ public MetricsConfiguration getMetricsConfiguration() {
return metricsConfiguration;
}

public Optional<PermissioningConfiguration> getPermissioningConfiguration() {
public Optional<LocalPermissioningConfiguration> getPermissioningConfiguration() {
return permissioningConfiguration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.metrics.prometheus.MetricsConfiguration;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;

Expand All @@ -38,7 +38,7 @@ public class PantheonFactoryConfigurationBuilder {
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault();
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault();
private MetricsConfiguration metricsConfiguration = MetricsConfiguration.createDefault();
private Optional<PermissioningConfiguration> permissioningConfiguration = Optional.empty();
private Optional<LocalPermissioningConfiguration> permissioningConfiguration = Optional.empty();
private boolean devMode = true;
private GenesisConfigProvider genesisConfigProvider = ignore -> Optional.empty();
private Boolean p2pEnabled = true;
Expand Down Expand Up @@ -137,7 +137,7 @@ public PantheonFactoryConfigurationBuilder webSocketAuthenticationEnabled()
}

public PantheonFactoryConfigurationBuilder setPermissioningConfiguration(
final PermissioningConfiguration permissioningConfiguration) {
final LocalPermissioningConfiguration permissioningConfiguration) {
this.permissioningConfiguration = Optional.of(permissioningConfiguration);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApi;
import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.LocalPermissioningConfiguration;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor.WHITELIST_TYPE;
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider;
Expand Down Expand Up @@ -183,8 +183,8 @@ public PantheonNode createNodeWithWhitelistsEnabled(
final List<String> accountsWhitelist,
final String tempFilePath)
throws IOException {
final PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
final LocalPermissioningConfiguration permissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
permissioningConfiguration.setNodeWhitelist(nodesWhitelist);
permissioningConfiguration.setAccountWhitelist(accountsWhitelist);
permissioningConfiguration.setConfigurationFilePath(tempFilePath);
Expand All @@ -204,8 +204,8 @@ public PantheonNode createNodeWithNodesWhitelist(

public PantheonNode createNodeWithNodesWhitelist(
final String name, final List<URI> nodesWhitelist) throws IOException {
final PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
final LocalPermissioningConfiguration permissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
permissioningConfiguration.setNodeWhitelist(nodesWhitelist);

final List<String> whitelistAsStrings =
Expand Down Expand Up @@ -241,8 +241,8 @@ private void initPermissioningConfigurationFile(

public PantheonNode createNodeWithAccountsWhitelist(
final String name, final List<String> accountsWhitelist) throws IOException {
final PermissioningConfiguration permissioningConfiguration =
PermissioningConfiguration.createDefault();
final LocalPermissioningConfiguration permissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
permissioningConfiguration.setAccountWhitelist(accountsWhitelist);
permissioningConfiguration.setConfigurationFilePath(
createTempPermissioningConfigurationFile().getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.p2p.P2pDisabledException;
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork;
import tech.pegasys.pantheon.ethereum.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;

import java.util.List;

Expand Down Expand Up @@ -50,7 +50,7 @@ public JsonRpcResponse response(final JsonRpcRequest req) {
if (p2pNetwork.getNodeWhitelistController().isPresent()) {
try {
final List<String> enodeURLs = enodeListParam.getStringList();
final NodeWhitelistController.NodesWhitelistResult nodesWhitelistResult =
final NodeLocalConfigPermissioningController.NodesWhitelistResult nodesWhitelistResult =
p2pNetwork.getNodeWhitelistController().get().addNodes(enodeURLs);

switch (nodesWhitelistResult.result()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.permissioning.AccountWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;

import java.util.Optional;

public class PermReloadPermissionsFromFile implements JsonRpcMethod {

private final Optional<AccountWhitelistController> accountWhitelistController;
private final Optional<NodeWhitelistController> nodesWhitelistController;
private final Optional<NodeLocalConfigPermissioningController> nodesWhitelistController;

public PermReloadPermissionsFromFile(
final Optional<AccountWhitelistController> accountWhitelistController,
final Optional<NodeWhitelistController> nodesWhitelistController) {
final Optional<NodeLocalConfigPermissioningController> nodesWhitelistController) {
this.accountWhitelistController = accountWhitelistController;
this.nodesWhitelistController = nodesWhitelistController;
}
Expand All @@ -48,7 +48,7 @@ public JsonRpcResponse response(final JsonRpcRequest request) {

try {
accountWhitelistController.ifPresent(AccountWhitelistController::reload);
nodesWhitelistController.ifPresent(NodeWhitelistController::reload);
nodesWhitelistController.ifPresent(NodeLocalConfigPermissioningController::reload);
return new JsonRpcSuccessResponse(request.getId());
} catch (Exception e) {
return new JsonRpcErrorResponse(request.getId(), JsonRpcError.WHITELIST_RELOAD_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.p2p.P2pDisabledException;
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork;
import tech.pegasys.pantheon.ethereum.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;

import java.util.List;

Expand Down Expand Up @@ -50,7 +50,7 @@ public JsonRpcResponse response(final JsonRpcRequest req) {
if (p2pNetwork.getNodeWhitelistController().isPresent()) {
try {
final List<String> enodeURLs = enodeListParam.getStringList();
final NodeWhitelistController.NodesWhitelistResult nodesWhitelistResult =
final NodeLocalConfigPermissioningController.NodesWhitelistResult nodesWhitelistResult =
p2pNetwork.getNodeWhitelistController().get().removeNodes(enodeURLs);

switch (nodesWhitelistResult.result()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static tech.pegasys.pantheon.ethereum.permissioning.NodeWhitelistController.NodesWhitelistResult;
import static tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController.NodesWhitelistResult;

import tech.pegasys.pantheon.ethereum.jsonrpc.internal.JsonRpcRequest;
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter;
Expand All @@ -29,7 +29,7 @@
import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse;
import tech.pegasys.pantheon.ethereum.p2p.P2pDisabledException;
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork;
import tech.pegasys.pantheon.ethereum.permissioning.NodeWhitelistController;
import tech.pegasys.pantheon.ethereum.permissioning.NodeLocalConfigPermissioningController;
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult;

import java.util.ArrayList;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class PermAddNodesToWhitelistTest {
private final String badEnode = "enod://dog@cat:fish";

@Mock private P2PNetwork p2pNetwork;
@Mock private NodeWhitelistController nodeWhitelistController;
@Mock private NodeLocalConfigPermissioningController nodeLocalConfigPermissioningController;

private JsonRpcParameter params = new JsonRpcParameter();

Expand All @@ -79,8 +79,10 @@ public void shouldThrowInvalidJsonRpcParametersExceptionWhenOnlyBadEnode() {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(eq(enodeList))).thenThrow(IllegalArgumentException.class);
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(eq(enodeList)))
.thenThrow(IllegalArgumentException.class);

final JsonRpcResponse actual = method.response(request);

Expand All @@ -94,8 +96,10 @@ public void shouldThrowInvalidJsonRpcParametersExceptionWhenBadEnodeInList() {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_INVALID_ENTRY);

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(eq(enodeList))).thenThrow(IllegalArgumentException.class);
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(eq(enodeList)))
.thenThrow(IllegalArgumentException.class);

final JsonRpcResponse actual = method.response(request);

Expand All @@ -108,8 +112,9 @@ public void shouldThrowInvalidJsonRpcParametersExceptionWhenEmptyEnode() {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(eq(Lists.emptyList())))
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(eq(Lists.emptyList())))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_EMPTY_ENTRY));

final JsonRpcResponse actual = method.response(request);
Expand All @@ -123,8 +128,9 @@ public void whenRequestContainsDuplicatedNodesShouldReturnDuplicatedEntryError()
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_DUPLICATED_ENTRY);

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(any()))
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_DUPLICATED_ENTRY));

final JsonRpcResponse actual = method.response(request);
Expand All @@ -138,8 +144,9 @@ public void whenRequestContainsEmptyListOfNodesShouldReturnEmptyEntryError() {
final JsonRpcResponse expected =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.NODE_WHITELIST_EMPTY_ENTRY);

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(eq(new ArrayList<>())))
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(eq(new ArrayList<>())))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.ERROR_EMPTY_ENTRY));

final JsonRpcResponse actual = method.response(request);
Expand All @@ -152,33 +159,35 @@ public void shouldAddSingleValidNode() {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode1));
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId());

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(any()))
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.SUCCESS));

final JsonRpcResponse actual = method.response(request);

assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);

verify(nodeWhitelistController, times(1)).addNodes(any());
verifyNoMoreInteractions(nodeWhitelistController);
verify(nodeLocalConfigPermissioningController, times(1)).addNodes(any());
verifyNoMoreInteractions(nodeLocalConfigPermissioningController);
}

@Test
public void shouldAddMultipleValidNodes() {
final JsonRpcRequest request = buildRequest(Lists.newArrayList(enode1, enode2, enode3));
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getId());

when(p2pNetwork.getNodeWhitelistController()).thenReturn(Optional.of(nodeWhitelistController));
when(nodeWhitelistController.addNodes(any()))
when(p2pNetwork.getNodeWhitelistController())
.thenReturn(Optional.of(nodeLocalConfigPermissioningController));
when(nodeLocalConfigPermissioningController.addNodes(any()))
.thenReturn(new NodesWhitelistResult(WhitelistOperationResult.SUCCESS));

final JsonRpcResponse actual = method.response(request);

assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);

verify(nodeWhitelistController, times(1)).addNodes(any());
verifyNoMoreInteractions(nodeWhitelistController);
verify(nodeLocalConfigPermissioningController, times(1)).addNodes(any());
verifyNoMoreInteractions(nodeLocalConfigPermissioningController);
}

@Test
Expand Down
Loading