rename variables to use allowlist (#2832)

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/2854/head
Sally MacFarlane 3 years ago committed by GitHub
parent 4d93bc75e5
commit aaad52e175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/AllowlistPersistorAcceptanceTest.java
  2. 2
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/AllowlistWithDnsPersistorAcceptanceTest.java
  3. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcConfiguration.java
  4. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToAllowlist.java
  5. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesAllowlist.java
  6. 18
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermReloadPermissionsFromFile.java
  7. 10
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromAllowlist.java
  8. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/JsonRpcMethodsFactory.java
  9. 38
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java
  10. 12
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceHostAllowlistTest.java

@ -64,7 +64,7 @@ public class AllowlistPersistorAcceptanceTest extends AcceptanceTestBase {
} }
@Test @Test
public void manipulatedAccountsWhitelistIsPersisted() { public void manipulatedAccountsAllowlistIsPersisted() {
node.verify( node.verify(
perm.expectPermissioningAllowlistFileKeyValue( perm.expectPermissioningAllowlistFileKeyValue(
ALLOWLIST_TYPE.ACCOUNTS, tempFile, senderA.getAddress())); ALLOWLIST_TYPE.ACCOUNTS, tempFile, senderA.getAddress()));
@ -87,7 +87,7 @@ public class AllowlistPersistorAcceptanceTest extends AcceptanceTestBase {
} }
@Test @Test
public void manipulatedNodesWhitelistIsPersisted() { public void manipulatedNodesAllowlistIsPersisted() {
node.verify(perm.addNodesToAllowlist(ENODE_ONE, ENODE_TWO)); node.verify(perm.addNodesToAllowlist(ENODE_ONE, ENODE_TWO));
node.verify( node.verify(
perm.expectPermissioningAllowlistFileKeyValue( perm.expectPermissioningAllowlistFileKeyValue(
@ -104,7 +104,7 @@ public class AllowlistPersistorAcceptanceTest extends AcceptanceTestBase {
} }
@Test @Test
public void manipulatedNodesWhitelistWithHostnameShouldNotWorkWhenDnsDisabled() { public void manipulatedNodesAllowlistWithHostnameShouldNotWorkWhenDnsDisabled() {
Assertions.assertThatThrownBy(() -> node.verify(perm.addNodesToAllowlist(ENODE_FOURTH))) Assertions.assertThatThrownBy(() -> node.verify(perm.addNodesToAllowlist(ENODE_FOURTH)))
.isInstanceOf(RuntimeException.class) .isInstanceOf(RuntimeException.class)
.hasMessageContaining("Request contains an invalid node"); .hasMessageContaining("Request contains an invalid node");

@ -60,7 +60,7 @@ public class AllowlistWithDnsPersistorAcceptanceTest extends AcceptanceTestBase
} }
@Test @Test
public void manipulatedNodesWhitelistWithHostnameShouldWorkWhenDnsEnabled() { public void manipulatedNodesAllowlistWithHostnameShouldWorkWhenDnsEnabled() {
node.verify(perm.addNodesToAllowlist(ENODE_ONE, ENODE_TWO)); node.verify(perm.addNodesToAllowlist(ENODE_ONE, ENODE_TWO));
node.verify( node.verify(

@ -110,8 +110,8 @@ public class JsonRpcConfiguration {
return Collections.unmodifiableCollection(this.hostsAllowlist); return Collections.unmodifiableCollection(this.hostsAllowlist);
} }
public void setHostsAllowlist(final List<String> hostsWhitelist) { public void setHostsAllowlist(final List<String> hostsAllowlist) {
this.hostsAllowlist = hostsWhitelist; this.hostsAllowlist = hostsAllowlist;
} }
public boolean isAuthenticationEnabled() { public boolean isAuthenticationEnabled() {

@ -32,11 +32,11 @@ import java.util.Optional;
public class PermAddNodesToAllowlist implements JsonRpcMethod { public class PermAddNodesToAllowlist implements JsonRpcMethod {
private final Optional<NodeLocalConfigPermissioningController> private final Optional<NodeLocalConfigPermissioningController>
nodeWhitelistPermissioningController; nodeAllowlistPermissioningController;
public PermAddNodesToAllowlist( public PermAddNodesToAllowlist(
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistPermissioningController) { final Optional<NodeLocalConfigPermissioningController> nodeAllowlistPermissioningController) {
this.nodeWhitelistPermissioningController = nodeWhitelistPermissioningController; this.nodeAllowlistPermissioningController = nodeAllowlistPermissioningController;
} }
@Override @Override
@ -50,11 +50,11 @@ public class PermAddNodesToAllowlist implements JsonRpcMethod {
requestContext.getRequiredParameter(0, StringListParameter.class); requestContext.getRequiredParameter(0, StringListParameter.class);
try { try {
if (nodeWhitelistPermissioningController.isPresent()) { if (nodeAllowlistPermissioningController.isPresent()) {
try { try {
final List<String> enodeURLs = enodeListParam.getStringList(); final List<String> enodeURLs = enodeListParam.getStringList();
final NodesAllowlistResult nodesAllowlistResult = final NodesAllowlistResult nodesAllowlistResult =
nodeWhitelistPermissioningController.get().addNodes(enodeURLs); nodeAllowlistPermissioningController.get().addNodes(enodeURLs);
switch (nodesAllowlistResult.result()) { switch (nodesAllowlistResult.result()) {
case SUCCESS: case SUCCESS:

@ -30,11 +30,11 @@ import java.util.Optional;
public class PermGetNodesAllowlist implements JsonRpcMethod { public class PermGetNodesAllowlist implements JsonRpcMethod {
private final Optional<NodeLocalConfigPermissioningController> private final Optional<NodeLocalConfigPermissioningController>
nodeWhitelistPermissioningController; nodeAllowlistPermissioningController;
public PermGetNodesAllowlist( public PermGetNodesAllowlist(
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistPermissioningController) { final Optional<NodeLocalConfigPermissioningController> nodeAllowlistPermissioningController) {
this.nodeWhitelistPermissioningController = nodeWhitelistPermissioningController; this.nodeAllowlistPermissioningController = nodeAllowlistPermissioningController;
} }
@Override @Override
@ -45,9 +45,9 @@ public class PermGetNodesAllowlist implements JsonRpcMethod {
@Override @Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
try { try {
if (nodeWhitelistPermissioningController.isPresent()) { if (nodeAllowlistPermissioningController.isPresent()) {
final List<String> enodeList = final List<String> enodeList =
nodeWhitelistPermissioningController.get().getNodesAllowlist(); nodeAllowlistPermissioningController.get().getNodesAllowlist();
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), enodeList); return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), enodeList);
} else { } else {

@ -28,14 +28,14 @@ import java.util.Optional;
public class PermReloadPermissionsFromFile implements JsonRpcMethod { public class PermReloadPermissionsFromFile implements JsonRpcMethod {
private final Optional<AccountLocalConfigPermissioningController> accountWhitelistController; private final Optional<AccountLocalConfigPermissioningController> accountAllowlistController;
private final Optional<NodeLocalConfigPermissioningController> nodesWhitelistController; private final Optional<NodeLocalConfigPermissioningController> nodesAllowlistController;
public PermReloadPermissionsFromFile( public PermReloadPermissionsFromFile(
final Optional<AccountLocalConfigPermissioningController> accountWhitelistController, final Optional<AccountLocalConfigPermissioningController> accountAllowlistController,
final Optional<NodeLocalConfigPermissioningController> nodesWhitelistController) { final Optional<NodeLocalConfigPermissioningController> nodesAllowlistController) {
this.accountWhitelistController = accountWhitelistController; this.accountAllowlistController = accountAllowlistController;
this.nodesWhitelistController = nodesWhitelistController; this.nodesAllowlistController = nodesAllowlistController;
} }
@Override @Override
@ -45,14 +45,14 @@ public class PermReloadPermissionsFromFile implements JsonRpcMethod {
@Override @Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
if (!accountWhitelistController.isPresent() && !nodesWhitelistController.isPresent()) { if (!accountAllowlistController.isPresent() && !nodesAllowlistController.isPresent()) {
return new JsonRpcErrorResponse( return new JsonRpcErrorResponse(
requestContext.getRequest().getId(), JsonRpcError.PERMISSIONING_NOT_ENABLED); requestContext.getRequest().getId(), JsonRpcError.PERMISSIONING_NOT_ENABLED);
} }
try { try {
accountWhitelistController.ifPresent(AccountLocalConfigPermissioningController::reload); accountAllowlistController.ifPresent(AccountLocalConfigPermissioningController::reload);
nodesWhitelistController.ifPresent(NodeLocalConfigPermissioningController::reload); nodesAllowlistController.ifPresent(NodeLocalConfigPermissioningController::reload);
return new JsonRpcSuccessResponse(requestContext.getRequest().getId()); return new JsonRpcSuccessResponse(requestContext.getRequest().getId());
} catch (Exception e) { } catch (Exception e) {
return new JsonRpcErrorResponse( return new JsonRpcErrorResponse(

@ -32,11 +32,11 @@ import java.util.Optional;
public class PermRemoveNodesFromAllowlist implements JsonRpcMethod { public class PermRemoveNodesFromAllowlist implements JsonRpcMethod {
private final Optional<NodeLocalConfigPermissioningController> private final Optional<NodeLocalConfigPermissioningController>
nodeWhitelistPermissioningController; nodeAllowlistPermissioningController;
public PermRemoveNodesFromAllowlist( public PermRemoveNodesFromAllowlist(
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistPermissioningController) { final Optional<NodeLocalConfigPermissioningController> nodeAllowlistPermissioningController) {
this.nodeWhitelistPermissioningController = nodeWhitelistPermissioningController; this.nodeAllowlistPermissioningController = nodeAllowlistPermissioningController;
} }
@Override @Override
@ -49,11 +49,11 @@ public class PermRemoveNodesFromAllowlist implements JsonRpcMethod {
final StringListParameter enodeListParam = final StringListParameter enodeListParam =
requestContext.getRequiredParameter(0, StringListParameter.class); requestContext.getRequiredParameter(0, StringListParameter.class);
try { try {
if (nodeWhitelistPermissioningController.isPresent()) { if (nodeAllowlistPermissioningController.isPresent()) {
try { try {
final List<String> enodeURLs = enodeListParam.getStringList(); final List<String> enodeURLs = enodeListParam.getStringList();
final NodesAllowlistResult nodesAllowlistResult = final NodesAllowlistResult nodesAllowlistResult =
nodeWhitelistPermissioningController.get().removeNodes(enodeURLs); nodeAllowlistPermissioningController.get().removeNodes(enodeURLs);
switch (nodesAllowlistResult.result()) { switch (nodesAllowlistResult.result()) {
case SUCCESS: case SUCCESS:

@ -61,8 +61,8 @@ public class JsonRpcMethodsFactory {
final MiningCoordinator miningCoordinator, final MiningCoordinator miningCoordinator,
final ObservableMetricsSystem metricsSystem, final ObservableMetricsSystem metricsSystem,
final Set<Capability> supportedCapabilities, final Set<Capability> supportedCapabilities,
final Optional<AccountLocalConfigPermissioningController> accountsWhitelistController, final Optional<AccountLocalConfigPermissioningController> accountsAllowlistController,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController, final Optional<NodeLocalConfigPermissioningController> nodeAllowlistController,
final Collection<RpcApi> rpcApis, final Collection<RpcApi> rpcApis,
final PrivacyParameters privacyParameters, final PrivacyParameters privacyParameters,
final JsonRpcConfiguration jsonRpcConfiguration, final JsonRpcConfiguration jsonRpcConfiguration,
@ -111,7 +111,7 @@ public class JsonRpcMethodsFactory {
webSocketConfiguration, webSocketConfiguration,
metricsConfiguration), metricsConfiguration),
new MinerJsonRpcMethods(miningCoordinator), new MinerJsonRpcMethods(miningCoordinator),
new PermJsonRpcMethods(accountsWhitelistController, nodeWhitelistController), new PermJsonRpcMethods(accountsAllowlistController, nodeAllowlistController),
new PrivJsonRpcMethods( new PrivJsonRpcMethods(
blockchainQueries, blockchainQueries,
protocolSchedule, protocolSchedule,

@ -38,14 +38,14 @@ import java.util.Optional;
public class PermJsonRpcMethods extends ApiGroupJsonRpcMethods { public class PermJsonRpcMethods extends ApiGroupJsonRpcMethods {
private final Optional<AccountLocalConfigPermissioningController> accountsWhitelistController; private final Optional<AccountLocalConfigPermissioningController> accountsAllowlistController;
private final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController; private final Optional<NodeLocalConfigPermissioningController> nodeAllowlistController;
public PermJsonRpcMethods( public PermJsonRpcMethods(
final Optional<AccountLocalConfigPermissioningController> accountsWhitelistController, final Optional<AccountLocalConfigPermissioningController> accountsAllowlistController,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController) { final Optional<NodeLocalConfigPermissioningController> nodeAllowlistController) {
this.accountsWhitelistController = accountsWhitelistController; this.accountsAllowlistController = accountsAllowlistController;
this.nodeWhitelistController = nodeWhitelistController; this.nodeAllowlistController = nodeAllowlistController;
} }
@Override @Override
@ -56,18 +56,18 @@ public class PermJsonRpcMethods extends ApiGroupJsonRpcMethods {
@Override @Override
protected Map<String, JsonRpcMethod> create() { protected Map<String, JsonRpcMethod> create() {
return mapOf( return mapOf(
new PermAddNodesToWhitelist(nodeWhitelistController), new PermAddNodesToWhitelist(nodeAllowlistController),
new PermAddNodesToAllowlist(nodeWhitelistController), new PermAddNodesToAllowlist(nodeAllowlistController),
new PermRemoveNodesFromWhitelist(nodeWhitelistController), new PermRemoveNodesFromWhitelist(nodeAllowlistController),
new PermRemoveNodesFromAllowlist(nodeWhitelistController), new PermRemoveNodesFromAllowlist(nodeAllowlistController),
new PermGetNodesWhitelist(nodeWhitelistController), new PermGetNodesWhitelist(nodeAllowlistController),
new PermGetNodesAllowlist(nodeWhitelistController), new PermGetNodesAllowlist(nodeAllowlistController),
new PermGetAccountsWhitelist(accountsWhitelistController), new PermGetAccountsWhitelist(accountsAllowlistController),
new PermGetAccountsAllowlist(accountsWhitelistController), new PermGetAccountsAllowlist(accountsAllowlistController),
new PermAddAccountsToWhitelist(accountsWhitelistController), new PermAddAccountsToWhitelist(accountsAllowlistController),
new PermAddAccountsToAllowlist(accountsWhitelistController), new PermAddAccountsToAllowlist(accountsAllowlistController),
new PermRemoveAccountsFromWhitelist(accountsWhitelistController), new PermRemoveAccountsFromWhitelist(accountsAllowlistController),
new PermRemoveAccountsFromAllowlist(accountsWhitelistController), new PermRemoveAccountsFromAllowlist(accountsAllowlistController),
new PermReloadPermissionsFromFile(accountsWhitelistController, nodeWhitelistController)); new PermReloadPermissionsFromFile(accountsAllowlistController, nodeAllowlistController));
} }
} }

@ -64,7 +64,7 @@ import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
public class JsonRpcHttpServiceHostWhitelistTest { public class JsonRpcHttpServiceHostAllowlistTest {
@ClassRule public static final TemporaryFolder folder = new TemporaryFolder(); @ClassRule public static final TemporaryFolder folder = new TemporaryFolder();
@ -82,7 +82,7 @@ public class JsonRpcHttpServiceHostWhitelistTest {
private final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig(); private final JsonRpcConfiguration jsonRpcConfig = createJsonRpcConfig();
private final NatService natService = new NatService(Optional.empty()); private final NatService natService = new NatService(Optional.empty());
private final List<String> hostsWhitelist = Arrays.asList("ally", "friend"); private final List<String> hostsAllowlist = Arrays.asList("ally", "friend");
@Before @Before
public void initServerAndClient() throws Exception { public void initServerAndClient() throws Exception {
@ -170,8 +170,8 @@ public class JsonRpcHttpServiceHostWhitelistTest {
} }
@Test @Test
public void requestWithWhitelistedHostIsAccepted() throws IOException { public void requestWithAllowlistedHostIsAccepted() throws IOException {
jsonRpcConfig.setHostsAllowlist(hostsWhitelist); jsonRpcConfig.setHostsAllowlist(hostsAllowlist);
assertThat(doRequest("ally")).isEqualTo(200); assertThat(doRequest("ally")).isEqualTo(200);
assertThat(doRequest("ally:12345")).isEqualTo(200); assertThat(doRequest("ally:12345")).isEqualTo(200);
assertThat(doRequest("friend")).isEqualTo(200); assertThat(doRequest("friend")).isEqualTo(200);
@ -179,7 +179,7 @@ public class JsonRpcHttpServiceHostWhitelistTest {
@Test @Test
public void requestWithUnknownHostIsRejected() throws IOException { public void requestWithUnknownHostIsRejected() throws IOException {
jsonRpcConfig.setHostsAllowlist(hostsWhitelist); jsonRpcConfig.setHostsAllowlist(hostsAllowlist);
assertThat(doRequest("foe")).isEqualTo(403); assertThat(doRequest("foe")).isEqualTo(403);
} }
@ -196,7 +196,7 @@ public class JsonRpcHttpServiceHostWhitelistTest {
@Test @Test
public void requestWithMalformedHostIsRejected() throws IOException { public void requestWithMalformedHostIsRejected() throws IOException {
jsonRpcConfig.setHostsAllowlist(hostsWhitelist); jsonRpcConfig.setHostsAllowlist(hostsAllowlist);
assertThat(doRequest("ally:friend")).isEqualTo(403); assertThat(doRequest("ally:friend")).isEqualTo(403);
assertThat(doRequest("ally:123456")).isEqualTo(403); assertThat(doRequest("ally:123456")).isEqualTo(403);
assertThat(doRequest("ally:friend:1234")).isEqualTo(403); assertThat(doRequest("ally:friend:1234")).isEqualTo(403);
Loading…
Cancel
Save