Search in sources :

Example 1 with LocalPermissioningConfiguration

use of org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration in project besu by hyperledger.

the class AccountPermissioningControllerFactoryTest method createLocalConfigOnlyControllerShouldReturnExpectedController.

@Test
public void createLocalConfigOnlyControllerShouldReturnExpectedController() {
    LocalPermissioningConfiguration localConfig = localConfig();
    assertThat(localConfig.isAccountAllowlistEnabled()).isTrue();
    PermissioningConfiguration permissioningConfiguration = new PermissioningConfiguration(Optional.of(localConfig), Optional.empty(), Optional.empty());
    Optional<AccountPermissioningController> controller = AccountPermissioningControllerFactory.create(permissioningConfiguration, transactionSimulator, metricsSystem, blockchain);
    Assertions.assertThat(controller).isNotEmpty();
    assertThat(controller.get().getAccountLocalConfigPermissioningController()).isNotEmpty();
    assertThat(controller.get().getTransactionSmartContractPermissioningController()).isEmpty();
}
Also used : LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) PermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration) SmartContractPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration) LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) Test(org.junit.Test)

Example 2 with LocalPermissioningConfiguration

use of org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration in project besu by hyperledger.

the class AccountPermissioningControllerFactoryTest method createLocalConfigWithAccountPermissioningDisabledShouldReturnEmpty.

@Test
public void createLocalConfigWithAccountPermissioningDisabledShouldReturnEmpty() {
    LocalPermissioningConfiguration localConfig = LocalPermissioningConfiguration.createDefault();
    assertThat(localConfig.isAccountAllowlistEnabled()).isFalse();
    PermissioningConfiguration permissioningConfiguration = new PermissioningConfiguration(Optional.of(localConfig), Optional.empty(), Optional.empty());
    Optional<AccountPermissioningController> controller = AccountPermissioningControllerFactory.create(permissioningConfiguration, transactionSimulator, metricsSystem, blockchain);
    Assertions.assertThat(controller).isEmpty();
}
Also used : LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) PermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration) SmartContractPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration) LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) Test(org.junit.Test)

Example 3 with LocalPermissioningConfiguration

use of org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration in project besu by hyperledger.

the class AccountPermissioningControllerFactoryTest method createLocalAndOnchainControllerShouldReturnExpectedControllers.

@Test
public void createLocalAndOnchainControllerShouldReturnExpectedControllers() {
    LocalPermissioningConfiguration localConfig = localConfig();
    assertThat(localConfig.isAccountAllowlistEnabled()).isTrue();
    SmartContractPermissioningConfiguration onchainConfig = onchainConfig();
    assertThat(onchainConfig.isSmartContractAccountAllowlistEnabled()).isTrue();
    PermissioningConfiguration permissioningConfiguration = new PermissioningConfiguration(Optional.of(localConfig), Optional.of(onchainConfig), Optional.empty());
    Optional<AccountPermissioningController> controller = AccountPermissioningControllerFactory.create(permissioningConfiguration, transactionSimulator, metricsSystem, blockchain);
    Assertions.assertThat(controller).isNotEmpty();
    assertThat(controller.get().getAccountLocalConfigPermissioningController()).isNotEmpty();
    assertThat(controller.get().getTransactionSmartContractPermissioningController()).isNotEmpty();
}
Also used : LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) PermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration) SmartContractPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration) LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) SmartContractPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration) Test(org.junit.Test)

Example 4 with LocalPermissioningConfiguration

use of org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration 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.");
    }
}
Also used : Path(java.nio.file.Path) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) URL(java.net.URL) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Test(org.junit.Test)

Example 5 with LocalPermissioningConfiguration

use of org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration 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");
    }
}
Also used : Path(java.nio.file.Path) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) EthNetworkConfig(org.hyperledger.besu.cli.config.EthNetworkConfig) URL(java.net.URL) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Test(org.junit.Test)

Aggregations

LocalPermissioningConfiguration (org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration)14 Test (org.junit.Test)9 PermissioningConfiguration (org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration)8 SmartContractPermissioningConfiguration (org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration)7 EnodeURL (org.hyperledger.besu.plugin.data.EnodeURL)7 URL (java.net.URL)6 Path (java.nio.file.Path)6 IOException (java.io.IOException)2 EthNetworkConfig (org.hyperledger.besu.cli.config.EthNetworkConfig)2 GOERLI_DISCOVERY_URL (org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.GOERLI_DISCOVERY_URL)2 MAINNET_DISCOVERY_URL (org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.MAINNET_DISCOVERY_URL)2 RINKEBY_DISCOVERY_URL (org.hyperledger.besu.ethereum.p2p.config.DefaultDiscoveryConfiguration.RINKEBY_DISCOVERY_URL)2 Vertx (io.vertx.core.Vertx)1 File (java.io.File)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1