mirror of https://github.com/hyperledger/besu
Nodes whitelist acceptance test (#472)
* Refactoring PantheonNodeFactory and adding PermissioningConfiguration * Created ClusterConfiguration * Acceptance test for nodes whitelist * Fixing constructor Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
5e53036799
commit
0ba0a05c2a
@ -0,0 +1,26 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2018 ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
*/ |
||||||
|
package tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster; |
||||||
|
|
||||||
|
public class ClusterConfiguration { |
||||||
|
|
||||||
|
private final boolean awaitPeerDiscovery; |
||||||
|
|
||||||
|
ClusterConfiguration(final boolean awaitPeerDiscovery) { |
||||||
|
this.awaitPeerDiscovery = awaitPeerDiscovery; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isAwaitPeerDiscovery() { |
||||||
|
return awaitPeerDiscovery; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2018 ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
*/ |
||||||
|
package tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster; |
||||||
|
|
||||||
|
public class ClusterConfigurationBuilder { |
||||||
|
private boolean awaitPeerDiscovery = true; |
||||||
|
|
||||||
|
public ClusterConfigurationBuilder setAwaitPeerDiscovery(final boolean awaitPeerDiscovery) { |
||||||
|
this.awaitPeerDiscovery = awaitPeerDiscovery; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public ClusterConfiguration build() { |
||||||
|
return new ClusterConfiguration(awaitPeerDiscovery); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,75 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2018 ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
*/ |
||||||
|
package tech.pegasys.pantheon.tests.acceptance.dsl.node.factory; |
||||||
|
|
||||||
|
import tech.pegasys.pantheon.ethereum.core.MiningParameters; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; |
||||||
|
import tech.pegasys.pantheon.ethereum.p2p.config.PermissioningConfiguration; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider; |
||||||
|
|
||||||
|
class PantheonFactoryConfiguration { |
||||||
|
|
||||||
|
private final String name; |
||||||
|
private final MiningParameters miningParameters; |
||||||
|
private final JsonRpcConfiguration jsonRpcConfiguration; |
||||||
|
private final WebSocketConfiguration webSocketConfiguration; |
||||||
|
private final PermissioningConfiguration permissioningConfiguration; |
||||||
|
private final boolean devMode; |
||||||
|
private final GenesisConfigProvider genesisConfigProvider; |
||||||
|
|
||||||
|
PantheonFactoryConfiguration( |
||||||
|
final String name, |
||||||
|
final MiningParameters miningParameters, |
||||||
|
final JsonRpcConfiguration jsonRpcConfiguration, |
||||||
|
final WebSocketConfiguration webSocketConfiguration, |
||||||
|
final PermissioningConfiguration permissioningConfiguration, |
||||||
|
final boolean devMode, |
||||||
|
final GenesisConfigProvider genesisConfigProvider) { |
||||||
|
this.name = name; |
||||||
|
this.miningParameters = miningParameters; |
||||||
|
this.jsonRpcConfiguration = jsonRpcConfiguration; |
||||||
|
this.webSocketConfiguration = webSocketConfiguration; |
||||||
|
this.permissioningConfiguration = permissioningConfiguration; |
||||||
|
this.devMode = devMode; |
||||||
|
this.genesisConfigProvider = genesisConfigProvider; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public MiningParameters getMiningParameters() { |
||||||
|
return miningParameters; |
||||||
|
} |
||||||
|
|
||||||
|
public JsonRpcConfiguration getJsonRpcConfiguration() { |
||||||
|
return jsonRpcConfiguration; |
||||||
|
} |
||||||
|
|
||||||
|
public WebSocketConfiguration getWebSocketConfiguration() { |
||||||
|
return webSocketConfiguration; |
||||||
|
} |
||||||
|
|
||||||
|
public PermissioningConfiguration getPermissioningConfiguration() { |
||||||
|
return permissioningConfiguration; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isDevMode() { |
||||||
|
return devMode; |
||||||
|
} |
||||||
|
|
||||||
|
public GenesisConfigProvider getGenesisConfigProvider() { |
||||||
|
return genesisConfigProvider; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,112 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2018 ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
*/ |
||||||
|
package tech.pegasys.pantheon.tests.acceptance.dsl.node.factory; |
||||||
|
|
||||||
|
import static java.util.Collections.singletonList; |
||||||
|
|
||||||
|
import tech.pegasys.pantheon.ethereum.core.MiningParameters; |
||||||
|
import tech.pegasys.pantheon.ethereum.core.MiningParametersTestBuilder; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.JsonRpcConfiguration; |
||||||
|
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.WebSocketConfiguration; |
||||||
|
import tech.pegasys.pantheon.ethereum.p2p.config.PermissioningConfiguration; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.GenesisConfigProvider; |
||||||
|
|
||||||
|
import java.util.Optional; |
||||||
|
|
||||||
|
public class PantheonFactoryConfigurationBuilder { |
||||||
|
|
||||||
|
private String name; |
||||||
|
private MiningParameters miningParameters = |
||||||
|
new MiningParametersTestBuilder().enabled(false).build(); |
||||||
|
private JsonRpcConfiguration jsonRpcConfiguration = JsonRpcConfiguration.createDefault(); |
||||||
|
private WebSocketConfiguration webSocketConfiguration = WebSocketConfiguration.createDefault(); |
||||||
|
private PermissioningConfiguration permissioningConfiguration = |
||||||
|
PermissioningConfiguration.createDefault(); |
||||||
|
private boolean devMode = true; |
||||||
|
private GenesisConfigProvider genesisConfigProvider = ignore -> Optional.empty(); |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setName(final String name) { |
||||||
|
this.name = name; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setMiningParameters( |
||||||
|
final MiningParameters miningParameters) { |
||||||
|
this.miningParameters = miningParameters; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder miningEnabled() { |
||||||
|
this.miningParameters = new MiningParametersTestBuilder().enabled(true).build(); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setJsonRpcConfiguration( |
||||||
|
final JsonRpcConfiguration jsonRpcConfiguration) { |
||||||
|
this.jsonRpcConfiguration = jsonRpcConfiguration; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder jsonRpcEnabled() { |
||||||
|
final JsonRpcConfiguration config = JsonRpcConfiguration.createDefault(); |
||||||
|
config.setEnabled(true); |
||||||
|
config.setPort(0); |
||||||
|
config.setHostsWhitelist(singletonList("*")); |
||||||
|
|
||||||
|
this.jsonRpcConfiguration = config; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setWebSocketConfiguration( |
||||||
|
final WebSocketConfiguration webSocketConfiguration) { |
||||||
|
this.webSocketConfiguration = webSocketConfiguration; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder webSocketEnabled() { |
||||||
|
final WebSocketConfiguration config = WebSocketConfiguration.createDefault(); |
||||||
|
config.setEnabled(true); |
||||||
|
config.setPort(0); |
||||||
|
|
||||||
|
this.webSocketConfiguration = config; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setPermissioningConfiguration( |
||||||
|
final PermissioningConfiguration permissioningConfiguration) { |
||||||
|
this.permissioningConfiguration = permissioningConfiguration; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setDevMode(final boolean devMode) { |
||||||
|
this.devMode = devMode; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfigurationBuilder setGenesisConfigProvider( |
||||||
|
final GenesisConfigProvider genesisConfigProvider) { |
||||||
|
this.genesisConfigProvider = genesisConfigProvider; |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
public PantheonFactoryConfiguration build() { |
||||||
|
return new PantheonFactoryConfiguration( |
||||||
|
name, |
||||||
|
miningParameters, |
||||||
|
jsonRpcConfiguration, |
||||||
|
webSocketConfiguration, |
||||||
|
permissioningConfiguration, |
||||||
|
devMode, |
||||||
|
genesisConfigProvider); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,65 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2018 ConsenSys AG. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||||
|
* the License. You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||||
|
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||||
|
* specific language governing permissions and limitations under the License. |
||||||
|
*/ |
||||||
|
package tech.pegasys.pantheon.tests.acceptance.permissioning; |
||||||
|
|
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.Cluster; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfiguration; |
||||||
|
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; |
||||||
|
|
||||||
|
import java.net.URI; |
||||||
|
import java.util.Collections; |
||||||
|
|
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
|
||||||
|
public class NodesWhitelistAcceptanceTest extends AcceptanceTestBase { |
||||||
|
|
||||||
|
private Cluster permissionedCluster; |
||||||
|
private Node forbiddenNode; |
||||||
|
private Node allowedNode; |
||||||
|
private Node permissionedNode; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() throws Exception { |
||||||
|
final ClusterConfiguration clusterConfiguration = |
||||||
|
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build(); |
||||||
|
|
||||||
|
permissionedCluster = new Cluster(clusterConfiguration, net); |
||||||
|
forbiddenNode = pantheon.createArchiveNode("forbidden-node"); |
||||||
|
allowedNode = pantheon.createArchiveNode("allowed-node"); |
||||||
|
permissionedNode = |
||||||
|
pantheon.createNodeWithNodesWhitelist( |
||||||
|
"permissioned-node", Collections.singletonList(getEnodeURI(allowedNode))); |
||||||
|
permissionedCluster.start(allowedNode, forbiddenNode, permissionedNode); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
public void permissionedNodeShouldDiscoverOnlyAllowedNode() { |
||||||
|
allowedNode.verify(net.awaitPeerCount(2)); |
||||||
|
forbiddenNode.verify(net.awaitPeerCount(1)); |
||||||
|
permissionedNode.verify(net.awaitPeerCount(1)); |
||||||
|
} |
||||||
|
|
||||||
|
private URI getEnodeURI(final Node node) { |
||||||
|
return URI.create(((PantheonNode) node).getConfiguration().enodeUrl()); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void tearDownAcceptanceTestBase() { |
||||||
|
permissionedCluster.stop(); |
||||||
|
super.tearDownAcceptanceTestBase(); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue