From 948f7d54fe0fe10dfded60b5b8d9336f72c9ba24 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 30 Jul 2024 15:01:22 +1000 Subject: [PATCH 1/3] removed whitelist permissioning methods Signed-off-by: Sally MacFarlane --- .../jsonrpc/methods/PermJsonRpcMethods.java | 12 -- .../PermAddAccountsToAllowlistTest.java | 16 +- .../PermAddAccountsToWhitelistTest.java | 137 ------------ .../PermAddNodesToWhitelistTest.java | 203 ------------------ .../PermGetAccountsWhitelistTest.java | 77 ------- .../PermGetNodesWhitelistTest.java | 124 ----------- .../PermRemoveAccountsFromWhitelistTest.java | 138 ------------ .../PermRemoveNodesFromWhitelistTest.java | 200 ----------------- .../methods/PermJsonRpcMethodsTest.java | 34 --- 9 files changed, 8 insertions(+), 933 deletions(-) delete mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java delete mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelistTest.java delete mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelistTest.java delete mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelistTest.java delete mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java delete mode 100644 ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelistTest.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java index 3a3b6cfb003..96fce83eab6 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethods.java @@ -17,18 +17,12 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddAccountsToAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddAccountsToWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddNodesToAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddNodesToWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetAccountsAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetAccountsWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetNodesAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetNodesWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermReloadPermissionsFromFile; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromWhitelist; import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; @@ -55,17 +49,11 @@ protected String getApiGroup() { @Override protected Map create() { return mapOf( - new PermAddNodesToWhitelist(nodeAllowlistController), new PermAddNodesToAllowlist(nodeAllowlistController), - new PermRemoveNodesFromWhitelist(nodeAllowlistController), new PermRemoveNodesFromAllowlist(nodeAllowlistController), - new PermGetNodesWhitelist(nodeAllowlistController), new PermGetNodesAllowlist(nodeAllowlistController), - new PermGetAccountsWhitelist(accountsAllowlistController), new PermGetAccountsAllowlist(accountsAllowlistController), - new PermAddAccountsToWhitelist(accountsAllowlistController), new PermAddAccountsToAllowlist(accountsAllowlistController), - new PermRemoveAccountsFromWhitelist(accountsAllowlistController), new PermRemoveAccountsFromAllowlist(accountsAllowlistController), new PermReloadPermissionsFromFile(accountsAllowlistController, nodeAllowlistController)); } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java index 0892cc5c647..66259f00078 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToAllowlistTest.java @@ -43,12 +43,12 @@ @ExtendWith(MockitoExtension.class) public class PermAddAccountsToAllowlistTest { - @Mock private AccountLocalConfigPermissioningController accountWhitelist; + @Mock private AccountLocalConfigPermissioningController accountAllowlist; private PermAddAccountsToAllowlist method; @BeforeEach public void before() { - method = new PermAddAccountsToAllowlist(java.util.Optional.of(accountWhitelist)); + method = new PermAddAccountsToAllowlist(java.util.Optional.of(accountAllowlist)); } @Test @@ -57,10 +57,10 @@ public void getNameShouldReturnExpectedName() { } @Test - public void whenAccountsAreAddedToWhitelistShouldReturnSuccess() { + public void whenAccountsAreAddedToAllowlistShouldReturnSuccess() { List accounts = Arrays.asList("0x0", "0x1"); JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null); - when(accountWhitelist.addAccounts(eq(accounts))).thenReturn(AllowlistOperationResult.SUCCESS); + when(accountAllowlist.addAccounts(eq(accounts))).thenReturn(AllowlistOperationResult.SUCCESS); JsonRpcResponse actualResponse = method.response(request(accounts)); @@ -71,7 +71,7 @@ public void whenAccountsAreAddedToWhitelistShouldReturnSuccess() { public void whenAccountIsInvalidShouldReturnInvalidAccountErrorResponse() { JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_INVALID_ENTRY); - when(accountWhitelist.addAccounts(any())) + when(accountAllowlist.addAccounts(any())) .thenReturn(AllowlistOperationResult.ERROR_INVALID_ENTRY); JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); @@ -83,7 +83,7 @@ public void whenAccountIsInvalidShouldReturnInvalidAccountErrorResponse() { public void whenAccountExistsShouldReturnExistingEntryErrorResponse() { JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_EXISTING_ENTRY); - when(accountWhitelist.addAccounts(any())) + when(accountAllowlist.addAccounts(any())) .thenReturn(AllowlistOperationResult.ERROR_EXISTING_ENTRY); JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); @@ -95,7 +95,7 @@ public void whenAccountExistsShouldReturnExistingEntryErrorResponse() { public void whenInputHasDuplicatedAccountsShouldReturnDuplicatedEntryErrorResponse() { JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_DUPLICATED_ENTRY); - when(accountWhitelist.addAccounts(any())) + when(accountAllowlist.addAccounts(any())) .thenReturn(AllowlistOperationResult.ERROR_DUPLICATED_ENTRY); JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); @@ -108,7 +108,7 @@ public void whenEmptyListOnRequestShouldReturnEmptyEntryErrorResponse() { JsonRpcResponse expectedResponse = new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_EMPTY_ENTRY); - when(accountWhitelist.addAccounts(eq(new ArrayList<>()))) + when(accountAllowlist.addAccounts(eq(new ArrayList<>()))) .thenReturn(AllowlistOperationResult.ERROR_EMPTY_ENTRY); JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java deleted file mode 100644 index 0dd4fb73d46..00000000000 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelistTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; -import org.hyperledger.besu.ethereum.permissioning.AllowlistOperationResult; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@Deprecated -@ExtendWith(MockitoExtension.class) -public class PermAddAccountsToWhitelistTest { - - @Mock private AccountLocalConfigPermissioningController accountWhitelist; - private PermAddAccountsToWhitelist method; - - @BeforeEach - public void before() { - method = new PermAddAccountsToWhitelist(java.util.Optional.of(accountWhitelist)); - } - - @Test - public void getNameShouldReturnExpectedName() { - assertThat(method.getName()).isEqualTo("perm_addAccountsToWhitelist"); - } - - @Test - public void whenAccountsAreAddedToWhitelistShouldReturnSuccess() { - List accounts = Arrays.asList("0x0", "0x1"); - JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null); - when(accountWhitelist.addAccounts(eq(accounts))).thenReturn(AllowlistOperationResult.SUCCESS); - - JsonRpcResponse actualResponse = method.response(request(accounts)); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenAccountIsInvalidShouldReturnInvalidAccountErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_INVALID_ENTRY); - when(accountWhitelist.addAccounts(any())) - .thenReturn(AllowlistOperationResult.ERROR_INVALID_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenAccountExistsShouldReturnExistingEntryErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_EXISTING_ENTRY); - when(accountWhitelist.addAccounts(any())) - .thenReturn(AllowlistOperationResult.ERROR_EXISTING_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenInputHasDuplicatedAccountsShouldReturnDuplicatedEntryErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_DUPLICATED_ENTRY); - when(accountWhitelist.addAccounts(any())) - .thenReturn(AllowlistOperationResult.ERROR_DUPLICATED_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenEmptyListOnRequestShouldReturnEmptyEntryErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_EMPTY_ENTRY); - - when(accountWhitelist.addAccounts(eq(new ArrayList<>()))) - .thenReturn(AllowlistOperationResult.ERROR_EMPTY_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenEmptyParamOnRequestShouldThrowInvalidJsonRpcException() { - JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "perm_addAccountsToWhitelist", new Object[] {})); - - final Throwable thrown = catchThrowable(() -> method.response(request)); - assertThat(thrown) - .hasNoCause() - .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); - } - - private JsonRpcRequestContext request(final List accounts) { - return new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "perm_addAccountsToWhitelist", new Object[] {accounts})); - } -} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelistTest.java deleted file mode 100644 index 237094b90c8..00000000000 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelistTest.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController.NodesAllowlistResult; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.permissioning.AllowlistOperationResult; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import org.assertj.core.api.Assertions; -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@Deprecated -@ExtendWith(MockitoExtension.class) -public class PermAddNodesToWhitelistTest { - - private PermAddNodesToWhitelist method; - private static final String METHOD_NAME = "perm_addNodesToWhitelist"; - - private final String enode1 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String enode2 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String enode3 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String badEnode = "enod://dog@cat:fish"; - - @Mock private NodeLocalConfigPermissioningController nodeLocalConfigPermissioningController; - - @BeforeEach - public void setUp() { - method = new PermAddNodesToWhitelist(Optional.of(nodeLocalConfigPermissioningController)); - } - - @Test - public void shouldReturnCorrectMethodName() { - assertThat(method.getName()).isEqualTo(METHOD_NAME); - } - - @Test - public void shouldThrowInvalidJsonRpcParametersExceptionWhenOnlyBadEnode() { - final ArrayList enodeList = Lists.newArrayList(badEnode); - final JsonRpcRequestContext request = buildRequest(enodeList); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_INVALID_ENTRY); - - when(nodeLocalConfigPermissioningController.addNodes(eq(enodeList))) - .thenThrow(IllegalArgumentException.class); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void shouldThrowInvalidJsonRpcParametersExceptionWhenBadEnodeInList() { - final ArrayList enodeList = Lists.newArrayList(enode2, badEnode, enode1); - final JsonRpcRequestContext request = buildRequest(enodeList); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_INVALID_ENTRY); - - when(nodeLocalConfigPermissioningController.addNodes(eq(enodeList))) - .thenThrow(IllegalArgumentException.class); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void shouldThrowInvalidJsonRpcParametersExceptionWhenEmptyEnode() { - final JsonRpcRequestContext request = buildRequest(Collections.emptyList()); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_EMPTY_ENTRY); - - when(nodeLocalConfigPermissioningController.addNodes(Collections.emptyList())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.ERROR_EMPTY_ENTRY)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void whenRequestContainsDuplicatedNodesShouldReturnDuplicatedEntryError() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1, enode1)); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_DUPLICATED_ENTRY); - - when(nodeLocalConfigPermissioningController.addNodes(any())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.ERROR_DUPLICATED_ENTRY)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void whenRequestContainsEmptyListOfNodesShouldReturnEmptyEntryError() { - final JsonRpcRequestContext request = buildRequest(new ArrayList<>()); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_EMPTY_ENTRY); - - when(nodeLocalConfigPermissioningController.addNodes(eq(new ArrayList<>()))) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.ERROR_EMPTY_ENTRY)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void shouldAddSingleValidNode() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1)); - final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId()); - - when(nodeLocalConfigPermissioningController.addNodes(any())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.SUCCESS)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - - verify(nodeLocalConfigPermissioningController, times(1)).addNodes(any()); - verifyNoMoreInteractions(nodeLocalConfigPermissioningController); - } - - @Test - public void shouldAddMultipleValidNodes() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1, enode2, enode3)); - final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId()); - - when(nodeLocalConfigPermissioningController.addNodes(any())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.SUCCESS)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - - verify(nodeLocalConfigPermissioningController, times(1)).addNodes(any()); - verifyNoMoreInteractions(nodeLocalConfigPermissioningController); - } - - @Test - public void shouldFailWhenP2pDisabled() { - method = new PermAddNodesToWhitelist(Optional.empty()); - - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1, enode2, enode3)); - ; - final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_NOT_ENABLED); - - Assertions.assertThat(method.response(request)) - .usingRecursiveComparison() - .isEqualTo(expectedResponse); - } - - private JsonRpcRequestContext buildRequest(final List enodeList) { - return new JsonRpcRequestContext( - new JsonRpcRequest("2.0", METHOD_NAME, new Object[] {enodeList})); - } -} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelistTest.java deleted file mode 100644 index 024349d8b23..00000000000 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelistTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@Deprecated -@ExtendWith(MockitoExtension.class) -public class PermGetAccountsWhitelistTest { - - private static final JsonRpcRequestContext request = - new JsonRpcRequestContext(new JsonRpcRequest("2.0", "perm_getAccountsWhitelist", null)); - - @Mock private AccountLocalConfigPermissioningController accountWhitelist; - private PermGetAccountsWhitelist method; - - @BeforeEach - public void before() { - method = new PermGetAccountsWhitelist(java.util.Optional.of(accountWhitelist)); - } - - @Test - public void getNameShouldReturnExpectedName() { - assertThat(method.getName()).isEqualTo("perm_getAccountsWhitelist"); - } - - @Test - public void shouldReturnExpectedListOfAccountsWhenWhitelistHasBeenSet() { - List accountsList = Arrays.asList("0x0", "0x1"); - when(accountWhitelist.getAccountAllowlist()).thenReturn(accountsList); - JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, accountsList); - - JsonRpcResponse actualResponse = method.response(request); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void shouldReturnEmptyListOfAccountsWhenWhitelistHasBeenSetAndIsEmpty() { - List emptyAccountsList = new ArrayList<>(); - when(accountWhitelist.getAccountAllowlist()).thenReturn(emptyAccountsList); - JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null, emptyAccountsList); - - JsonRpcResponse actualResponse = method.response(request); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } -} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelistTest.java deleted file mode 100644 index 9981cb27e74..00000000000 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelistTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import org.assertj.core.api.Assertions; -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@Deprecated -@ExtendWith(MockitoExtension.class) -public class PermGetNodesWhitelistTest { - - private PermGetNodesWhitelist method; - private static final String METHOD_NAME = "perm_getNodesWhitelist"; - - private final String enode1 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String enode2 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.11:4567"; - private final String enode3 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.12:4567"; - - @Mock private NodeLocalConfigPermissioningController nodeLocalConfigPermissioningController; - - @BeforeEach - public void setUp() { - method = new PermGetNodesWhitelist(Optional.of(nodeLocalConfigPermissioningController)); - } - - @Test - public void shouldReturnCorrectMethodName() { - assertThat(method.getName()).isEqualTo(METHOD_NAME); - } - - @Test - public void shouldReturnSuccessResponseWhenListPopulated() { - final JsonRpcRequestContext request = buildRequest(); - final JsonRpcResponse expected = - new JsonRpcSuccessResponse( - request.getRequest().getId(), Lists.newArrayList(enode1, enode2, enode3)); - - when(nodeLocalConfigPermissioningController.getNodesAllowlist()) - .thenReturn(buildNodesList(enode1, enode2, enode3)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - - verify(nodeLocalConfigPermissioningController, times(1)).getNodesAllowlist(); - verifyNoMoreInteractions(nodeLocalConfigPermissioningController); - } - - @Test - public void shouldReturnSuccessResponseWhenListSetAndEmpty() { - final JsonRpcRequestContext request = buildRequest(); - final JsonRpcResponse expected = - new JsonRpcSuccessResponse(request.getRequest().getId(), Collections.emptyList()); - - when(nodeLocalConfigPermissioningController.getNodesAllowlist()).thenReturn(buildNodesList()); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - - verify(nodeLocalConfigPermissioningController, times(1)).getNodesAllowlist(); - verifyNoMoreInteractions(nodeLocalConfigPermissioningController); - } - - @Test - public void shouldFailWhenP2pDisabled() { - method = new PermGetNodesWhitelist(Optional.empty()); - - final JsonRpcRequestContext request = buildRequest(); - final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_NOT_ENABLED); - - Assertions.assertThat(method.response(request)) - .usingRecursiveComparison() - .isEqualTo(expectedResponse); - } - - private JsonRpcRequestContext buildRequest() { - return new JsonRpcRequestContext(new JsonRpcRequest("2.0", METHOD_NAME, new Object[] {})); - } - - private List buildNodesList(final String... enodes) { - return Lists.newArrayList(enodes); - } -} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java deleted file mode 100644 index 934329052dc..00000000000 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelistTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.catchThrowable; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.exception.InvalidJsonRpcParameters; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; -import org.hyperledger.besu.ethereum.permissioning.AllowlistOperationResult; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@Deprecated -@ExtendWith(MockitoExtension.class) -public class PermRemoveAccountsFromWhitelistTest { - - @Mock private AccountLocalConfigPermissioningController accountWhitelist; - private PermRemoveAccountsFromWhitelist method; - - @BeforeEach - public void before() { - method = new PermRemoveAccountsFromWhitelist(java.util.Optional.of(accountWhitelist)); - } - - @Test - public void getNameShouldReturnExpectedName() { - assertThat(method.getName()).isEqualTo("perm_removeAccountsFromWhitelist"); - } - - @Test - public void whenAccountsAreRemovedFromWhitelistShouldReturnSuccess() { - List accounts = Arrays.asList("0x0", "0x1"); - JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(null); - when(accountWhitelist.removeAccounts(eq(accounts))) - .thenReturn(AllowlistOperationResult.SUCCESS); - - JsonRpcResponse actualResponse = method.response(request(accounts)); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenAccountIsInvalidShouldReturnInvalidAccountErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_INVALID_ENTRY); - when(accountWhitelist.removeAccounts(any())) - .thenReturn(AllowlistOperationResult.ERROR_INVALID_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenAccountIsAbsentShouldReturnAbsentAccountErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_ABSENT_ENTRY); - when(accountWhitelist.removeAccounts(any())) - .thenReturn(AllowlistOperationResult.ERROR_ABSENT_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenInputHasDuplicatedAccountsShouldReturnDuplicatedEntryErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_DUPLICATED_ENTRY); - when(accountWhitelist.removeAccounts(any())) - .thenReturn(AllowlistOperationResult.ERROR_DUPLICATED_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenEmptyListOnRequestShouldReturnEmptyEntryErrorResponse() { - JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse(null, RpcErrorType.ACCOUNT_ALLOWLIST_EMPTY_ENTRY); - - when(accountWhitelist.removeAccounts(eq(new ArrayList<>()))) - .thenReturn(AllowlistOperationResult.ERROR_EMPTY_ENTRY); - - JsonRpcResponse actualResponse = method.response(request(new ArrayList<>())); - - assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse); - } - - @Test - public void whenEmptyParamOnRequestShouldThrowInvalidJsonRpcException() { - JsonRpcRequestContext request = - new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "perm_removeAccountsFromWhitelist", new Object[] {})); - - final Throwable thrown = catchThrowable(() -> method.response(request)); - assertThat(thrown) - .hasNoCause() - .isInstanceOf(InvalidJsonRpcParameters.class) - .hasMessage("Missing required json rpc parameter at index 0"); - } - - private JsonRpcRequestContext request(final List accounts) { - return new JsonRpcRequestContext( - new JsonRpcRequest("2.0", "perm_removeAccountsFromWhitelist", new Object[] {accounts})); - } -} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelistTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelistTest.java deleted file mode 100644 index 45630a25ad1..00000000000 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelistTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController.NodesAllowlistResult; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType; -import org.hyperledger.besu.ethereum.permissioning.AllowlistOperationResult; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import org.assertj.core.api.Assertions; -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@Deprecated -@ExtendWith(MockitoExtension.class) -public class PermRemoveNodesFromWhitelistTest { - - private PermRemoveNodesFromWhitelist method; - private static final String METHOD_NAME = "perm_removeNodesFromWhitelist"; - - private final String enode1 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String enode2 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String enode3 = - "enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; - private final String badEnode = "enod://dog@cat:fish"; - - @Mock private NodeLocalConfigPermissioningController nodeLocalConfigPermissioningController; - - @BeforeEach - public void setUp() { - method = new PermRemoveNodesFromWhitelist(Optional.of(nodeLocalConfigPermissioningController)); - } - - @Test - public void shouldReturnCorrectMethodName() { - assertThat(method.getName()).isEqualTo(METHOD_NAME); - } - - @Test - public void shouldThrowInvalidJsonRpcParametersExceptionWhenBadEnode() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(badEnode)); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_INVALID_ENTRY); - - when(nodeLocalConfigPermissioningController.removeNodes(eq(Lists.newArrayList(badEnode)))) - .thenThrow(IllegalArgumentException.class); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void shouldThrowInvalidJsonRpcParametersExceptionWhenEmptyList() { - final JsonRpcRequestContext request = buildRequest(Collections.emptyList()); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_EMPTY_ENTRY); - - when(nodeLocalConfigPermissioningController.removeNodes(Collections.emptyList())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.ERROR_EMPTY_ENTRY)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void shouldRemoveSingleValidNode() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1)); - final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId()); - - when(nodeLocalConfigPermissioningController.removeNodes(any())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.SUCCESS)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - - verify(nodeLocalConfigPermissioningController, times(1)).removeNodes(any()); - verifyNoMoreInteractions(nodeLocalConfigPermissioningController); - } - - @Test - public void shouldRemoveMultipleValidNodes() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1, enode2, enode3)); - final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId()); - - when(nodeLocalConfigPermissioningController.removeNodes(any())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.SUCCESS)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - - verify(nodeLocalConfigPermissioningController, times(1)).removeNodes(any()); - verifyNoMoreInteractions(nodeLocalConfigPermissioningController); - } - - @Test - public void shouldFailWhenP2pDisabled() { - method = new PermRemoveNodesFromWhitelist(Optional.empty()); - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1, enode2, enode3)); - final JsonRpcResponse expectedResponse = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_NOT_ENABLED); - - Assertions.assertThat(method.response(request)) - .usingRecursiveComparison() - .isEqualTo(expectedResponse); - } - - @Test - public void whenRequestContainsDuplicatedNodesShouldReturnDuplicatedEntryError() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1, enode1)); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_DUPLICATED_ENTRY); - - when(nodeLocalConfigPermissioningController.removeNodes(any())) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.ERROR_DUPLICATED_ENTRY)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void whenRequestContainsEmptyListOfNodesShouldReturnEmptyEntryError() { - final JsonRpcRequestContext request = buildRequest(new ArrayList<>()); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_EMPTY_ENTRY); - - when(nodeLocalConfigPermissioningController.removeNodes(eq(new ArrayList<>()))) - .thenReturn(new NodesAllowlistResult(AllowlistOperationResult.ERROR_EMPTY_ENTRY)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - @Test - public void shouldReturnCantRemoveBootnodeWhenRemovingBootnode() { - final JsonRpcRequestContext request = buildRequest(Lists.newArrayList(enode1)); - final JsonRpcResponse expected = - new JsonRpcErrorResponse( - request.getRequest().getId(), RpcErrorType.NODE_ALLOWLIST_FIXED_NODE_CANNOT_BE_REMOVED); - - when(nodeLocalConfigPermissioningController.removeNodes(any())) - .thenReturn( - new NodesAllowlistResult(AllowlistOperationResult.ERROR_FIXED_NODE_CANNOT_BE_REMOVED)); - - final JsonRpcResponse actual = method.response(request); - - assertThat(actual).usingRecursiveComparison().isEqualTo(expected); - } - - private JsonRpcRequestContext buildRequest(final List enodeList) { - return new JsonRpcRequestContext( - new JsonRpcRequest("2.0", METHOD_NAME, new Object[] {enodeList})); - } -} diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethodsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethodsTest.java index a8f06f52650..7484730a308 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethodsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PermJsonRpcMethodsTest.java @@ -16,30 +16,19 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_ADD_ACCOUNTS_TO_ALLOWLIST; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_ADD_ACCOUNTS_TO_WHITELIST; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_ADD_NODES_TO_ALLOWLIST; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_ADD_NODES_TO_WHITELIST; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_GET_ACCOUNTS_ALLOWLIST; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_GET_ACCOUNTS_WHITELIST; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_GET_NODES_ALLOWLIST; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_GET_NODES_WHITELIST; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_REMOVE_ACCOUNTS_FROM_ALLOWLIST; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_REMOVE_ACCOUNTS_FROM_WHITELIST; import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_REMOVE_NODES_FROM_ALLOWLIST; -import static org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod.PERM_REMOVE_NODES_FROM_WHITELIST; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.JsonRpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddAccountsToAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddAccountsToWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermAddNodesToAllowlist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetAccountsAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetAccountsWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetNodesAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermGetNodesWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveAccountsFromWhitelist; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromAllowlist; -import org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning.PermRemoveNodesFromWhitelist; import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; @@ -88,27 +77,4 @@ public void allowlistMethodsPresent() { assertThat(rpcMethods.get(PERM_REMOVE_NODES_FROM_ALLOWLIST.getMethodName())) .isInstanceOf(PermRemoveNodesFromAllowlist.class); } - - @Deprecated - @Test - public void whitelistMethodsPresent() { - final Map rpcMethods = permJsonRpcMethods.create(); - assertThat(rpcMethods.size()).isEqualTo(13); - - // Account methods x 3 - assertThat(rpcMethods.get(PERM_GET_ACCOUNTS_WHITELIST.getMethodName())) - .isInstanceOf(PermGetAccountsWhitelist.class); - assertThat(rpcMethods.get(PERM_ADD_ACCOUNTS_TO_WHITELIST.getMethodName())) - .isInstanceOf(PermAddAccountsToWhitelist.class); - assertThat(rpcMethods.get(PERM_REMOVE_ACCOUNTS_FROM_WHITELIST.getMethodName())) - .isInstanceOf(PermRemoveAccountsFromWhitelist.class); - - // Node methods x 3 - assertThat(rpcMethods.get(PERM_GET_NODES_WHITELIST.getMethodName())) - .isInstanceOf(PermGetNodesWhitelist.class); - assertThat(rpcMethods.get(PERM_ADD_NODES_TO_WHITELIST.getMethodName())) - .isInstanceOf(PermAddNodesToAllowlist.class); - assertThat(rpcMethods.get(PERM_REMOVE_NODES_FROM_WHITELIST.getMethodName())) - .isInstanceOf(PermRemoveNodesFromWhitelist.class); - } } From ffea74ea0b5acda28eb01abd1b5dbc8f73b0a648 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 30 Jul 2024 15:06:47 +1000 Subject: [PATCH 2/3] changelog Signed-off-by: Sally MacFarlane --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 072a84c2ba4..498b3c1edd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Allow configuration of Withdrawal Request Contract Address via genesis configuration [#7356](https://github.com/hyperledger/besu/pull/7356) ### Breaking Changes +- Remove long-deprecated `perm*whitelist*` methods [#7401](https://github.com/hyperledger/besu/pull/7401) ### Additions and Improvements From da071fe2aa0ce83c542e1b77470812f4c09cdc96 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Tue, 30 Jul 2024 15:31:12 +1000 Subject: [PATCH 3/3] removed actual RPC methods Signed-off-by: Sally MacFarlane --- .../PermAddAccountsToWhitelist.java | 34 ------------------- .../PermAddNodesToWhitelist.java | 34 ------------------- .../PermGetAccountsWhitelist.java | 34 ------------------- .../permissioning/PermGetNodesWhitelist.java | 34 ------------------- .../PermRemoveAccountsFromWhitelist.java | 34 ------------------- .../PermRemoveNodesFromWhitelist.java | 34 ------------------- 6 files changed, 204 deletions(-) delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelist.java delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelist.java delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelist.java delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelist.java delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelist.java delete mode 100644 ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelist.java diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelist.java deleted file mode 100644 index 37d530634a8..00000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddAccountsToWhitelist.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; - -import java.util.Optional; - -@Deprecated -public class PermAddAccountsToWhitelist extends PermAddAccountsToAllowlist { - - public PermAddAccountsToWhitelist( - final Optional allowlistController) { - super(allowlistController); - } - - @Override - public String getName() { - return RpcMethod.PERM_ADD_ACCOUNTS_TO_WHITELIST.getMethodName(); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelist.java deleted file mode 100644 index c75a86e28ca..00000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermAddNodesToWhitelist.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; - -import java.util.Optional; - -@Deprecated -public class PermAddNodesToWhitelist extends PermAddNodesToAllowlist { - - public PermAddNodesToWhitelist( - final Optional nodeAllowlistPermissioningController) { - super(nodeAllowlistPermissioningController); - } - - @Override - public String getName() { - return RpcMethod.PERM_ADD_NODES_TO_WHITELIST.getMethodName(); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelist.java deleted file mode 100644 index 97281ae707a..00000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetAccountsWhitelist.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; - -import java.util.Optional; - -@Deprecated -public class PermGetAccountsWhitelist extends PermGetAccountsAllowlist { - - public PermGetAccountsWhitelist( - final Optional allowlistController) { - super(allowlistController); - } - - @Override - public String getName() { - return RpcMethod.PERM_GET_ACCOUNTS_WHITELIST.getMethodName(); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelist.java deleted file mode 100644 index 850872d3fd3..00000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermGetNodesWhitelist.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; - -import java.util.Optional; - -@Deprecated -public class PermGetNodesWhitelist extends PermGetNodesAllowlist { - - public PermGetNodesWhitelist( - final Optional nodeAllowlistPermissioningController) { - super(nodeAllowlistPermissioningController); - } - - @Override - public String getName() { - return RpcMethod.PERM_GET_NODES_WHITELIST.getMethodName(); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelist.java deleted file mode 100644 index f72984f03b5..00000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveAccountsFromWhitelist.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.permissioning.AccountLocalConfigPermissioningController; - -import java.util.Optional; - -@Deprecated -public class PermRemoveAccountsFromWhitelist extends PermRemoveAccountsFromAllowlist { - - public PermRemoveAccountsFromWhitelist( - final Optional allowlistController) { - super(allowlistController); - } - - @Override - public String getName() { - return RpcMethod.PERM_REMOVE_ACCOUNTS_FROM_WHITELIST.getMethodName(); - } -} diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelist.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelist.java deleted file mode 100644 index a0b4de534cf..00000000000 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/permissioning/PermRemoveNodesFromWhitelist.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 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. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.permissioning; - -import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; -import org.hyperledger.besu.ethereum.permissioning.NodeLocalConfigPermissioningController; - -import java.util.Optional; - -@Deprecated -public class PermRemoveNodesFromWhitelist extends PermRemoveNodesFromAllowlist { - - public PermRemoveNodesFromWhitelist( - final Optional nodeAllowlistPermissioningController) { - super(nodeAllowlistPermissioningController); - } - - @Override - public String getName() { - return RpcMethod.PERM_REMOVE_NODES_FROM_WHITELIST.getMethodName(); - } -}