use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.
the class AdminNodeInfoTest method handlesLocalEnodeWithListeningDisabled.
@Test
public void handlesLocalEnodeWithListeningDisabled() {
final EnodeURL localEnode = EnodeURLImpl.builder().nodeId(nodeId).ipAddress("1.2.3.4").discoveryAndListeningPorts(0).discoveryPort(7890).build();
when(p2pNetwork.isP2pEnabled()).thenReturn(true);
when(p2pNetwork.getLocalEnode()).thenReturn(Optional.of(localEnode));
final JsonRpcRequestContext request = adminNodeInfo();
final Map<String, Object> expected = new HashMap<>();
expected.put("enode", "enode://0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807@1.2.3.4:0?discport=7890");
expected.put("id", "0f1b319e32017c3fcb221841f0f978701b4e9513fe6a567a2db43d43381a9c7e3dfe7cae13cbc2f56943400bacaf9082576ab087cd51983b17d729ae796f6807");
expected.put("ip", "1.2.3.4");
expected.put("name", "testnet/1.0/this/that");
expected.put("ports", ImmutableMap.of("discovery", 7890));
expected.put("protocols", ImmutableMap.of("eth", ImmutableMap.of("config", genesisConfigOptions.asMap(), "difficulty", BigInteger.ONE, "genesis", Hash.EMPTY.toString(), "head", Hash.EMPTY.toString(), "network", BigInteger.valueOf(2018))));
final JsonRpcResponse response = method.response(request);
assertThat(response).isInstanceOf(JsonRpcSuccessResponse.class);
final JsonRpcSuccessResponse actual = (JsonRpcSuccessResponse) response;
assertThat(actual.getResult()).isEqualTo(expected);
}
use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.
the class BesuCommandTest method errorIsRaisedIfStaticNodesAreNotAllowed.
@Test
public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException {
final File staticNodesFile = testFolder.newFile("static-nodes.json");
staticNodesFile.deleteOnExit();
final File permissioningConfig = testFolder.newFile("permissioning");
permissioningConfig.deleteOnExit();
final EnodeURL staticNodeURI = EnodeURLImpl.builder().nodeId("50203c6bfca6874370e71aecc8958529fd723feb05013dc1abca8fc1fff845c5259faba05852e9dfe5ce172a7d6e7c2a3a5eaa8b541c8af15ea5518bbff5f2fa").ipAddress("127.0.0.1").useDefaultPorts().build();
final EnodeURL allowedNode = EnodeURLImpl.builder().nodeId("50203c6bfca6874370e71aecc8958529fd723feb05013dc1abca8fc1fff845c5259faba05852e9dfe5ce172a7d6e7c2a3a5eaa8b541c8af15ea5518bbff5f2fa").useDefaultPorts().ipAddress("127.0.0.1").listeningPort(30304).build();
Files.write(staticNodesFile.toPath(), ("[\"" + staticNodeURI.toString() + "\"]").getBytes(UTF_8));
Files.write(permissioningConfig.toPath(), ("nodes-allowlist=[\"" + allowedNode.toString() + "\"]").getBytes(UTF_8));
parseCommand("--data-path=" + testFolder.getRoot().getPath(), "--bootnodes", "--permissions-nodes-config-file-enabled=true", "--permissions-nodes-config-file=" + permissioningConfig.getPath());
assertThat(commandErrorOutput.toString(UTF_8)).contains(staticNodeURI.toString(), "not in nodes-allowlist");
}
use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.
the class RunnerBuilderTest method enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled.
@Test
public void enodeUrlShouldHaveAdvertisedHostWhenDiscoveryDisabled() {
final String p2pAdvertisedHost = "172.0.0.1";
final int p2pListenPort = 30302;
final Runner runner = new RunnerBuilder().p2pListenInterface("0.0.0.0").p2pListenPort(p2pListenPort).p2pAdvertisedHost(p2pAdvertisedHost).p2pEnabled(true).discovery(false).besuController(besuController).ethNetworkConfig(mock(EthNetworkConfig.class)).metricsSystem(mock(ObservableMetricsSystem.class)).jsonRpcConfiguration(mock(JsonRpcConfiguration.class)).permissioningService(mock(PermissioningServiceImpl.class)).graphQLConfiguration(mock(GraphQLConfiguration.class)).webSocketConfiguration(mock(WebSocketConfiguration.class)).jsonRpcIpcConfiguration(mock(JsonRpcIpcConfiguration.class)).metricsConfiguration(mock(MetricsConfiguration.class)).vertx(vertx).dataDir(dataDir.getRoot().toPath()).storageProvider(mock(KeyValueStorageProvider.class)).forkIdSupplier(() -> Collections.singletonList(Bytes.EMPTY)).rpcEndpointService(new RpcEndpointServiceImpl()).build();
runner.startEthereumMainLoop();
final EnodeURL expectedEodeURL = EnodeURLImpl.builder().ipAddress(p2pAdvertisedHost).discoveryPort(0).listeningPort(p2pListenPort).nodeId(besuController.getNodeKey().getPublicKey().getEncoded()).build();
assertThat(runner.getLocalEnode().orElseThrow()).isEqualTo(expectedEodeURL);
}
use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.
the class LocalPermissioningConfigurationValidatorTest method nodeAllowlistCheckShouldIgnoreDiscoveryPortParam.
@Test
public void nodeAllowlistCheckShouldIgnoreDiscoveryPortParam() throws Exception {
final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG);
final Path toml = Files.createTempFile("toml", "");
toml.toFile().deleteOnExit();
Files.write(toml, Resources.toByteArray(configFile));
final LocalPermissioningConfiguration permissioningConfiguration = PermissioningConfigurationBuilder.permissioningConfiguration(true, EnodeDnsConfiguration.DEFAULT_CONFIG, toml.toAbsolutePath().toString(), true, toml.toAbsolutePath().toString());
// This node is defined in the PERMISSIONING_CONFIG file without the discovery port
final EnodeURL enodeURL = EnodeURLImpl.fromString("enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.9:4567?discport=30303");
// In an URI comparison the URLs should not match
boolean isInAllowlist = permissioningConfiguration.getNodeAllowlist().contains(enodeURL);
assertThat(isInAllowlist).isFalse();
// error
try {
PermissioningConfigurationValidator.areAllNodesAreInAllowlist(Lists.newArrayList(enodeURL), permissioningConfiguration);
} catch (Exception e) {
fail("Exception not expected. Validation of nodes in allowlist should ignore the optional discovery port param.");
}
}
use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.
the class LocalPermissioningConfigurationValidatorTest method nodesAllowlistOptionWhichDoesNotIncludeBootnodesMustError.
@Test
public void nodesAllowlistOptionWhichDoesNotIncludeBootnodesMustError() throws Exception {
EthNetworkConfig ethNetworkConfig = EthNetworkConfig.getNetworkConfig(NetworkName.ROPSTEN);
final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG);
final Path toml = Files.createTempFile("toml", "");
toml.toFile().deleteOnExit();
Files.write(toml, Resources.toByteArray(configFile));
LocalPermissioningConfiguration permissioningConfiguration = PermissioningConfigurationBuilder.permissioningConfiguration(true, EnodeDnsConfiguration.DEFAULT_CONFIG, toml.toAbsolutePath().toString(), true, toml.toAbsolutePath().toString());
try {
final List<EnodeURL> enodeURIs = ethNetworkConfig.getBootNodes();
PermissioningConfigurationValidator.areAllNodesAreInAllowlist(enodeURIs, permissioningConfiguration);
fail("expected exception because ropsten bootnodes are not in node-allowlist");
} catch (Exception e) {
assertThat(e.getMessage()).startsWith("Specified node(s) not in nodes-allowlist");
assertThat(e.getMessage()).contains("enode://6332792c4a00e3e4ee0926ed89e0d27ef985424d97b6a45bf0f23e51f0dcb5e66b875777506458aea7af6f9e4ffb69f43f3778ee73c81ed9d34c51c4b16b0b0f@52.232.243.152:30303");
assertThat(e.getMessage()).contains("enode://94c15d1b9e2fe7ce56e458b9a3b672ef11894ddedd0c6f247e0f1d3487f52b66208fb4aeb8179fce6e3a749ea93ed147c37976d67af557508d199d9594c35f09@192.81.208.223:30303");
}
}
Aggregations