Skip to content

Commit

Permalink
rename more "whitelist" occurrences to "allowlist" (#1133)
Browse files Browse the repository at this point in the history
* rename more whitelist occurrences; change allowlisted to allowed and reword where we ended up with allowlisting

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
  • Loading branch information
macfarla authored Jun 24, 2020
1 parent 785b26b commit 9e224ed
Show file tree
Hide file tree
Showing 30 changed files with 305 additions and 285 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setUp() {
}

@Test
public void testNodeCannotConnectWhnAllowlistedOnChainButNotLocal() {
public void testNodeCannotConnectWhenAllowedOnChainButNotLocally() {

// add permissioned node after cluster start because we need enode URI for local config
permissionedNode = permissionedNode("permissioned-node", bootnode, allowedNode);
Expand All @@ -60,7 +60,7 @@ public void testNodeCannotConnectWhnAllowlistedOnChainButNotLocal() {
}

@Test
public void testNodeCannotConnectWhenAllowlistedLocalButNotOnChain() {
public void testNodeCannotConnectWhenAllowedLocallyButNotOnChain() {
// onchain allowlist: A, B
// local allowlist: A, B, C

Expand All @@ -82,7 +82,7 @@ public void testNodeCannotConnectWhenAllowlistedLocalButNotOnChain() {
}

@Test
public void testNodesCanConnectWhenAllowlistedBothOnChainAndLocal() {
public void testNodesCanConnectWhenAllowedBothOnChainAndLocally() {
// add permissioned node after cluster start because we need enode URI for local config
permissionedNode = permissionedNode("permissioned-node", bootnode, allowedNode, forbiddenNode);
permissionedCluster.addNode(permissionedNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ private Cluster permissionedCluster() {
return new Cluster(clusterConfiguration, net);
}

protected Node permissionedNode(final String name, final Node... localConfigAllowListedNodes) {
return permissionedNode(name, GENESIS_FILE, localConfigAllowListedNodes);
protected Node permissionedNode(final String name, final Node... localConfigAllowedNodes) {
return permissionedNode(name, GENESIS_FILE, localConfigAllowedNodes);
}

protected Node permissionedNode(
final String name, final String genesisFile, final Node... localConfigAllowListedNodes) {
final String name, final String genesisFile, final Node... localConfigAllowedNodes) {
PermissionedNodeBuilder permissionedNodeBuilder =
this.permissionedNodeBuilder
.name(name)
.genesisFile(genesisFile)
.nodesContractEnabled(CONTRACT_ADDRESS);
if (localConfigAllowListedNodes != null && localConfigAllowListedNodes.length > 0) {
permissionedNodeBuilder.nodesPermittedInConfig(localConfigAllowListedNodes);
if (localConfigAllowedNodes != null && localConfigAllowedNodes.length > 0) {
permissionedNodeBuilder.nodesPermittedInConfig(localConfigAllowedNodes);
}
return permissionedNodeBuilder.build();
}
Expand Down
8 changes: 4 additions & 4 deletions besu/src/main/java/org/hyperledger/besu/RunnerBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,8 @@ private Map<String, JsonRpcMethod> jsonRpcMethods(
final Set<Capability> supportedCapabilities,
final Collection<RpcApi> jsonRpcApis,
final FilterManager filterManager,
final Optional<AccountLocalConfigPermissioningController> accountWhitelistController,
final Optional<NodeLocalConfigPermissioningController> nodeWhitelistController,
final Optional<AccountLocalConfigPermissioningController> accountAllowlistController,
final Optional<NodeLocalConfigPermissioningController> nodeAllowlistController,
final PrivacyParameters privacyParameters,
final JsonRpcConfiguration jsonRpcConfiguration,
final WebSocketConfiguration webSocketConfiguration,
Expand All @@ -692,8 +692,8 @@ private Map<String, JsonRpcMethod> jsonRpcMethods(
miningCoordinator,
metricsSystem,
supportedCapabilities,
accountWhitelistController,
nodeWhitelistController,
accountAllowlistController,
nodeAllowlistController,
jsonRpcApis,
privacyParameters,
jsonRpcConfiguration,
Expand Down
69 changes: 52 additions & 17 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public void defaultPermissionsTomlFileWithNoPermissionsEnabledMustNotError() {

@Test
public void nodePermissioningTomlPathMustUseOption() throws IOException {
final List<URI> allowlistedNodes =
final List<URI> allowedNodes =
Lists.newArrayList(
URI.create(
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.9:4567"),
Expand All @@ -600,18 +600,18 @@ public void nodePermissioningTomlPathMustUseOption() throws IOException {
final URL configFile = this.getClass().getResource(PERMISSIONING_CONFIG_TOML);
final Path permToml = createTempFile("toml", Resources.toByteArray(configFile));

final String allowlistedNodesString =
allowlistedNodes.stream().map(Object::toString).collect(Collectors.joining(","));
final String allowedNodesString =
allowedNodes.stream().map(Object::toString).collect(Collectors.joining(","));
parseCommand(
"--permissions-nodes-config-file-enabled",
"--permissions-nodes-config-file",
permToml.toString(),
"--bootnodes",
allowlistedNodesString);
allowedNodesString);
final LocalPermissioningConfiguration localPermissioningConfiguration =
LocalPermissioningConfiguration.createDefault();
localPermissioningConfiguration.setNodePermissioningConfigFilePath(permToml.toString());
localPermissioningConfiguration.setNodeAllowlist(allowlistedNodes);
localPermissioningConfiguration.setNodeAllowlist(allowedNodes);

verify(mockRunnerBuilder)
.permissioningConfiguration(permissioningConfigurationArgumentCaptor.capture());
Expand Down Expand Up @@ -2026,8 +2026,10 @@ public void rpcHttpCorsOriginsEmptyValueFails() {
.contains("Domain cannot be empty string or null string.");
}

/** test deprecated CLI option * */
@Deprecated
@Test
public void rpcHttpHostAllowlistAcceptsSingleArgument() {
public void rpcHttpHostWhitelistAcceptsSingleArgument() {
parseCommand("--host-whitelist", "a");

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
Expand All @@ -2042,9 +2044,25 @@ public void rpcHttpHostAllowlistAcceptsSingleArgument() {
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void rpcHttpHostAllowlistAcceptsSingleArgument() {
parseCommand("--host-allowlist", "a");

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();

assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist().size()).isEqualTo(1);
assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist()).contains("a");
assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist())
.doesNotContain("localhost");

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Test
public void rpcHttpHostAllowlistAcceptsMultipleArguments() {
parseCommand("--host-whitelist", "a,b");
parseCommand("--host-allowlist", "a,b");

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();
Expand All @@ -2060,7 +2078,24 @@ public void rpcHttpHostAllowlistAcceptsMultipleArguments() {

@Test
public void rpcHttpHostAllowlistAcceptsDoubleComma() {
parseCommand("--host-whitelist", "a,,b");
parseCommand("--host-allowlist", "a,,b");

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();

assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist().size()).isEqualTo(2);
assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist()).contains("a", "b");
assertThat(jsonRpcConfigArgumentCaptor.getValue().getHostsAllowlist())
.doesNotContain("*", "localhost");

assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString()).isEmpty();
}

@Deprecated
@Test
public void rpcHttpHostWhitelistAllowlistAcceptsMultipleFlags() {
parseCommand("--host-whitelist=a", "--host-allowlist=b");

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();
Expand All @@ -2076,7 +2111,7 @@ public void rpcHttpHostAllowlistAcceptsDoubleComma() {

@Test
public void rpcHttpHostAllowlistAcceptsMultipleFlags() {
parseCommand("--host-whitelist=a", "--host-whitelist=b");
parseCommand("--host-allowlist=a", "--host-allowlist=b");

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();
Expand All @@ -2093,7 +2128,7 @@ public void rpcHttpHostAllowlistAcceptsMultipleFlags() {
@Test
public void rpcHttpHostAllowlistStarWithAnotherHostnameMustFail() {
final String[] origins = {"friend", "*"};
parseCommand("--host-whitelist", String.join(",", origins));
parseCommand("--host-allowlist", String.join(",", origins));

Mockito.verifyZeroInteractions(mockRunnerBuilder);

Expand All @@ -2105,7 +2140,7 @@ public void rpcHttpHostAllowlistStarWithAnotherHostnameMustFail() {
@Test
public void rpcHttpHostAllowlistStarWithAnotherHostnameMustFailStarFirst() {
final String[] origins = {"*", "friend"};
parseCommand("--host-whitelist", String.join(",", origins));
parseCommand("--host-allowlist", String.join(",", origins));

Mockito.verifyZeroInteractions(mockRunnerBuilder);

Expand All @@ -2117,7 +2152,7 @@ public void rpcHttpHostAllowlistStarWithAnotherHostnameMustFailStarFirst() {
@Test
public void rpcHttpHostAllowlistAllWithAnotherHostnameMustFail() {
final String[] origins = {"friend", "all"};
parseCommand("--host-whitelist", String.join(",", origins));
parseCommand("--host-allowlist", String.join(",", origins));

Mockito.verifyZeroInteractions(mockRunnerBuilder);

Expand All @@ -2129,7 +2164,7 @@ public void rpcHttpHostAllowlistAllWithAnotherHostnameMustFail() {
@Test
public void rpcHttpHostAllowlistWithNoneMustBuildEmptyList() {
final String[] origins = {"none"};
parseCommand("--host-whitelist", String.join(",", origins));
parseCommand("--host-allowlist", String.join(",", origins));

verify(mockRunnerBuilder).jsonRpcConfiguration(jsonRpcConfigArgumentCaptor.capture());
verify(mockRunnerBuilder).build();
Expand All @@ -2143,7 +2178,7 @@ public void rpcHttpHostAllowlistWithNoneMustBuildEmptyList() {
@Test
public void rpcHttpHostAllowlistNoneWithAnotherDomainMustFail() {
final String[] origins = {"http://domain1.com", "none"};
parseCommand("--host-whitelist", String.join(",", origins));
parseCommand("--host-allowlist", String.join(",", origins));

Mockito.verifyZeroInteractions(mockRunnerBuilder);

Expand All @@ -2155,7 +2190,7 @@ public void rpcHttpHostAllowlistNoneWithAnotherDomainMustFail() {
@Test
public void rpcHttpHostAllowlistNoneWithAnotherDomainMustFailNoneFirst() {
final String[] origins = {"none", "http://domain1.com"};
parseCommand("--host-whitelist", String.join(",", origins));
parseCommand("--host-allowlist", String.join(",", origins));

Mockito.verifyZeroInteractions(mockRunnerBuilder);

Expand All @@ -2166,7 +2201,7 @@ public void rpcHttpHostAllowlistNoneWithAnotherDomainMustFailNoneFirst() {

@Test
public void rpcHttpHostAllowlistEmptyValueFails() {
parseCommand("--host-whitelist=");
parseCommand("--host-allowlist=");

Mockito.verifyZeroInteractions(mockRunnerBuilder);

Expand Down Expand Up @@ -3065,7 +3100,7 @@ public void privacyWithPruningMustError() {
@Rule public TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void errorIsRaisedIfStaticNodesAreNotAllowlisted() throws IOException {
public void errorIsRaisedIfStaticNodesAreNotAllowed() throws IOException {
final File staticNodesFile = testFolder.newFile("static-nodes.json");
staticNodesFile.deleteOnExit();
final File permissioningConfig = testFolder.newFile("permissioning");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class GraphQLConfiguration {
private int port;
private String host;
private List<String> corsAllowedDomains = Collections.emptyList();
private List<String> hostsWhitelist = Arrays.asList("localhost", "127.0.0.1");
private List<String> hostsAllowlist = Arrays.asList("localhost", "127.0.0.1");
private long httpTimeoutSec = TimeoutOptions.defaultOptions().getTimeoutSeconds();

public static GraphQLConfiguration createDefault() {
Expand Down Expand Up @@ -81,13 +81,13 @@ public void setCorsAllowedDomains(final List<String> corsAllowedDomains) {
this.corsAllowedDomains = corsAllowedDomains;
}

Collection<String> getHostsWhitelist() {
return Collections.unmodifiableCollection(this.hostsWhitelist);
Collection<String> getHostsAllowlist() {
return Collections.unmodifiableCollection(this.hostsAllowlist);
}

public void setHostsAllowlist(final List<String> hostsWhitelist) {
checkNotNull(hostsWhitelist);
this.hostsWhitelist = hostsWhitelist;
public void setHostsAllowlist(final List<String> hostsAllowlist) {
checkNotNull(hostsAllowlist);
this.hostsAllowlist = hostsAllowlist;
}

public Long getHttpTimeoutSec() {
Expand All @@ -105,7 +105,7 @@ public String toString() {
.add("port", port)
.add("host", host)
.add("corsAllowedDomains", corsAllowedDomains)
.add("hostsWhitelist", hostsWhitelist)
.add("hostsAllowlist", hostsAllowlist)
.add("httpTimeoutSec", httpTimeoutSec)
.toString();
}
Expand All @@ -123,11 +123,11 @@ public boolean equals(final Object o) {
&& port == that.port
&& Objects.equals(host, that.host)
&& Objects.equals(corsAllowedDomains, that.corsAllowedDomains)
&& Objects.equals(hostsWhitelist, that.hostsWhitelist);
&& Objects.equals(hostsAllowlist, that.hostsAllowlist);
}

@Override
public int hashCode() {
return Objects.hash(enabled, port, host, corsAllowedDomains, hostsWhitelist);
return Objects.hash(enabled, port, host, corsAllowedDomains, hostsAllowlist);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public CompletableFuture<?> start() {
private Handler<RoutingContext> checkWhitelistHostHeader() {
return event -> {
final Optional<String> hostHeader = getAndValidateHostHeader(event);
if (config.getHostsWhitelist().contains("*")
|| (hostHeader.isPresent() && hostIsInWhitelist(hostHeader.get()))) {
if (config.getHostsAllowlist().contains("*")
|| (hostHeader.isPresent() && hostIsInAllowlist(hostHeader.get()))) {
event.next();
} else {
final HttpServerResponse response = event.response();
Expand All @@ -219,13 +219,13 @@ private Optional<String> getAndValidateHostHeader(final RoutingContext event) {
return Optional.ofNullable(Iterables.get(splitHostHeader, 0));
}

private boolean hostIsInWhitelist(final String hostHeader) {
if (config.getHostsWhitelist().stream()
private boolean hostIsInAllowlist(final String hostHeader) {
if (config.getHostsAllowlist().stream()
.anyMatch(
whitelistEntry -> whitelistEntry.toLowerCase().equals(hostHeader.toLowerCase()))) {
allowlistEntry -> allowlistEntry.toLowerCase().equals(hostHeader.toLowerCase()))) {
return true;
} else {
LOG.trace("Host not in whitelist: '{}'", hostHeader);
LOG.trace("Host not in allowlist: '{}'", hostHeader);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class JsonRpcConfiguration {
private String host;
private List<String> corsAllowedDomains = Collections.emptyList();
private List<RpcApi> rpcApis;
private List<String> hostsWhitelist = Arrays.asList("localhost", "127.0.0.1");
private List<String> hostsAllowlist = Arrays.asList("localhost", "127.0.0.1");
private boolean authenticationEnabled = false;
private String authenticationCredentialsFile;
private File authenticationPublicKeyFile;
Expand Down Expand Up @@ -104,11 +104,11 @@ public void addRpcApi(final RpcApi rpcApi) {
}

public Collection<String> getHostsAllowlist() {
return Collections.unmodifiableCollection(this.hostsWhitelist);
return Collections.unmodifiableCollection(this.hostsAllowlist);
}

public void setHostsAllowlist(final List<String> hostsWhitelist) {
this.hostsWhitelist = hostsWhitelist;
this.hostsAllowlist = hostsWhitelist;
}

public boolean isAuthenticationEnabled() {
Expand Down Expand Up @@ -158,7 +158,7 @@ public String toString() {
.add("port", port)
.add("host", host)
.add("corsAllowedDomains", corsAllowedDomains)
.add("hostsWhitelist", hostsWhitelist)
.add("hostsAllowlist", hostsAllowlist)
.add("rpcApis", rpcApis)
.add("authenticationEnabled", authenticationEnabled)
.add("authenticationCredentialsFile", authenticationCredentialsFile)
Expand All @@ -183,7 +183,7 @@ public boolean equals(final Object o) {
&& Objects.equals(host, that.host)
&& Objects.equals(corsAllowedDomains, that.corsAllowedDomains)
&& Objects.equals(rpcApis, that.rpcApis)
&& Objects.equals(hostsWhitelist, that.hostsWhitelist)
&& Objects.equals(hostsAllowlist, that.hostsAllowlist)
&& Objects.equals(authenticationCredentialsFile, that.authenticationCredentialsFile)
&& Objects.equals(authenticationPublicKeyFile, that.authenticationPublicKeyFile);
}
Expand All @@ -196,7 +196,7 @@ public int hashCode() {
host,
corsAllowedDomains,
rpcApis,
hostsWhitelist,
hostsAllowlist,
authenticationEnabled,
authenticationCredentialsFile,
authenticationPublicKeyFile);
Expand Down
Loading

0 comments on commit 9e224ed

Please sign in to comment.