-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[PIE-1798] Fail cases for multitenancy ATs #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b9e1065
[PIE-1798] Added some multitenancy fail case tests.
mark-terry c2cc6f9
[PIE-1798] Refactoring.
mark-terry e335ca8
[PIE-1798] PR fixes.
mark-terry bb4b2cb
[PIE-1798] PR fixes.
mark-terry 0c8a1b3
Merge branch 'master' into PIE-1798-newfails
mark-terry ce1317d
[PIE-1798] Rawtypes fix.
mark-terry 928c27e
Merge branch 'PIE-1798-newfails' of github.com:mark-terry/besu into P…
mark-terry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...ain/java/org/hyperledger/besu/tests/acceptance/dsl/condition/priv/ExpectJsonRpcError.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * 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.tests.acceptance.dsl.condition.priv; | ||
|
|
||
| import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; | ||
|
|
||
| import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.condition.Condition; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.node.Node; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.web3j.protocol.exceptions.ClientConnectionException; | ||
|
|
||
| public class ExpectJsonRpcError implements Condition { | ||
|
|
||
| private final Transaction<?> transaction; | ||
| private final JsonRpcError error; | ||
|
|
||
| public ExpectJsonRpcError(final Transaction<?> transaction, final JsonRpcError error) { | ||
| this.transaction = transaction; | ||
| this.error = error; | ||
| } | ||
|
|
||
| @Override | ||
| public void verify(final Node node) { | ||
| try { | ||
| node.execute(transaction); | ||
| failBecauseExceptionWasNotThrown(ClientConnectionException.class); | ||
| } catch (final Exception e) { | ||
| Assertions.assertThat(e) | ||
| .isInstanceOf(ClientConnectionException.class) | ||
| .hasMessageContaining("400") | ||
| .hasMessageContaining(error.getMessage()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
.../besu/tests/acceptance/privacy/multitenancy/MultiTenancyValidationFailAcceptanceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,218 @@ | ||
| /* | ||
| * 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.tests.acceptance.privacy.multitenancy; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.ok; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.post; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
| import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; | ||
| import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.DELETE_PRIVACY_GROUP_ERROR; | ||
| import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.ENCLAVE_ERROR; | ||
| import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.FIND_PRIVACY_GROUP_ERROR; | ||
| import static org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError.GET_PRIVATE_TRANSACTION_NONCE_ERROR; | ||
|
|
||
| import org.hyperledger.besu.crypto.SECP256K1; | ||
| import org.hyperledger.besu.enclave.types.PrivacyGroup; | ||
| import org.hyperledger.besu.ethereum.core.Address; | ||
| import org.hyperledger.besu.ethereum.core.Hash; | ||
| import org.hyperledger.besu.ethereum.core.Wei; | ||
| import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; | ||
| import org.hyperledger.besu.ethereum.privacy.Restriction; | ||
| import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.node.BesuNode; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.Cluster; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfiguration; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; | ||
| import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction; | ||
|
|
||
| import java.math.BigInteger; | ||
| import java.util.List; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
|
|
||
| public class MultiTenancyValidationFailAcceptanceTest extends AcceptanceTestBase { | ||
| private BesuNode node; | ||
| private final ObjectMapper mapper = new ObjectMapper(); | ||
| private Cluster multiTenancyCluster; | ||
|
|
||
| private static final String PRIVACY_GROUP_ID = "Z3JvdXBJZA=="; | ||
| private static final String ENCLAVE_PUBLIC_KEY = "B1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; | ||
| private static final String OTHER_ENCLAVE_PUBLIC_KEY = | ||
| "A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo="; | ||
| private final Address senderAddress = | ||
| Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress())); | ||
|
|
||
| @Rule public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort()); | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| final ClusterConfiguration clusterConfiguration = | ||
| new ClusterConfigurationBuilder().awaitPeerDiscovery(false).build(); | ||
| multiTenancyCluster = new Cluster(clusterConfiguration, net); | ||
| node = | ||
| besu.createNodeWithMultiTenantedPrivacy( | ||
| "node1", | ||
| "http://127.0.0.1:" + wireMockRule.port(), | ||
| "authentication/auth_priv.toml", | ||
| "authentication/auth_priv_key"); | ||
| multiTenancyCluster.start(node); | ||
|
|
||
| final String token = | ||
| node.execute(permissioningTransactions.createSuccessfulLogin("failUser", "pegasys")); | ||
| node.useAuthenticationTokenInHeaderForJsonRpc(token); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() { | ||
| multiTenancyCluster.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void sendRawTransactionShouldFailWhenPrivateFromNotMatchEnclaveKey() | ||
| throws JsonProcessingException { | ||
| final PrivateTransaction validSignedPrivateTransaction = | ||
| getValidSignedPrivateTransaction(senderAddress, OTHER_ENCLAVE_PUBLIC_KEY); | ||
| retrievePrivacyGroupEnclaveStub(); | ||
| final Transaction<Hash> transaction = | ||
| privacyTransactions.sendRawTransaction( | ||
| getRLPOutput(validSignedPrivateTransaction).encoded().toHexString()); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, ENCLAVE_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void sendRawTransactionShouldFailWhenPrivacyGroupDoesNotContainEnclaveKey() | ||
| throws JsonProcessingException { | ||
| final PrivateTransaction validSignedPrivateTransaction = | ||
| getValidSignedPrivateTransaction(senderAddress, ENCLAVE_PUBLIC_KEY); | ||
| retrievePrivacyGroupEnclaveStub(); | ||
| final Transaction<Hash> transaction = | ||
| privacyTransactions.sendRawTransaction( | ||
| getRLPOutput(validSignedPrivateTransaction).encoded().toHexString()); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, ENCLAVE_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void distributeRawTransactionShouldFailWhenPrivateFromNotMatchEnclaveKey() { | ||
| final Address senderAddress = | ||
| Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress())); | ||
|
|
||
| final Transaction<String> transaction = | ||
| privacyTransactions.distributeRawTransaction( | ||
| getRLPOutput(getValidSignedPrivateTransaction(senderAddress, OTHER_ENCLAVE_PUBLIC_KEY)) | ||
| .encoded() | ||
| .toHexString()); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, ENCLAVE_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void distributeRawTransactionShouldFailWhenPrivacyGroupDoesNotContainEnclaveKey() | ||
| throws JsonProcessingException { | ||
| final Address senderAddress = | ||
| Address.wrap(Bytes.fromHexString(accounts.getPrimaryBenefactor().getAddress())); | ||
|
|
||
| retrievePrivacyGroupEnclaveStub(); | ||
|
|
||
| final Transaction<String> transaction = | ||
| privacyTransactions.distributeRawTransaction( | ||
| getRLPOutput(getValidSignedPrivateTransaction(senderAddress, ENCLAVE_PUBLIC_KEY)) | ||
| .encoded() | ||
| .toHexString()); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, ENCLAVE_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void deletePrivacyGroupShouldFailWhenEnclaveKeyNotInPrivacyGroup() | ||
| throws JsonProcessingException { | ||
| retrievePrivacyGroupEnclaveStub(); | ||
| final Transaction<String> transaction = | ||
| privacyTransactions.deletePrivacyGroup(PRIVACY_GROUP_ID); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, DELETE_PRIVACY_GROUP_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void findPrivacyGroupShouldFailWhenEnclaveKeyNotInPrivacyGroup() { | ||
| final Transaction<PrivacyGroup[]> transaction = | ||
| privacyTransactions.findPrivacyGroup(new String[] {OTHER_ENCLAVE_PUBLIC_KEY}); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, FIND_PRIVACY_GROUP_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void determineEeaNonceShouldFailWhenPrivateFromNotMatchEnclaveKey() { | ||
| final String accountAddress = Address.ZERO.toHexString(); | ||
| final String senderAddressBase64 = Bytes.fromHexString(accountAddress).toBase64String(); | ||
| final String[] privateFor = {senderAddressBase64}; | ||
| final Transaction<Integer> transaction = | ||
| privacyTransactions.getEeaTransactionCount( | ||
| accountAddress, OTHER_ENCLAVE_PUBLIC_KEY, privateFor); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, GET_PRIVATE_TRANSACTION_NONCE_ERROR)); | ||
| } | ||
|
|
||
| @Test | ||
| public void determineBesuNonceShouldFailWhenEnclaveKeyNotInPrivacyGroup() | ||
| throws JsonProcessingException { | ||
| retrievePrivacyGroupEnclaveStub(); | ||
| final String accountAddress = Address.ZERO.toHexString(); | ||
| final Transaction<Integer> transaction = | ||
| privacyTransactions.getTransactionCount(accountAddress, PRIVACY_GROUP_ID); | ||
| node.verify(priv.multiTenancyValidationFail(transaction, GET_PRIVATE_TRANSACTION_NONCE_ERROR)); | ||
| } | ||
|
|
||
| private void retrievePrivacyGroupEnclaveStub() throws JsonProcessingException { | ||
| final String retrieveGroupResponse = | ||
| mapper.writeValueAsString( | ||
| testPrivacyGroup(List.of(OTHER_ENCLAVE_PUBLIC_KEY), PrivacyGroup.Type.PANTHEON)); | ||
| stubFor(post("/retrievePrivacyGroup").willReturn(ok(retrieveGroupResponse))); | ||
| } | ||
|
|
||
| private PrivacyGroup testPrivacyGroup( | ||
| final List<String> groupMembers, final PrivacyGroup.Type groupType) { | ||
| return new PrivacyGroup(PRIVACY_GROUP_ID, groupType, "test", "testGroup", groupMembers); | ||
| } | ||
|
|
||
| private BytesValueRLPOutput getRLPOutput(final PrivateTransaction validSignedPrivateTransaction) { | ||
| final BytesValueRLPOutput bvrlpo = new BytesValueRLPOutput(); | ||
| validSignedPrivateTransaction.writeTo(bvrlpo); | ||
| return bvrlpo; | ||
| } | ||
|
|
||
| private static PrivateTransaction getValidSignedPrivateTransaction( | ||
| final Address senderAddress, final String privateFrom) { | ||
| return PrivateTransaction.builder() | ||
| .nonce(0) | ||
| .gasPrice(Wei.ZERO) | ||
| .gasLimit(3000000) | ||
| .to(null) | ||
| .value(Wei.ZERO) | ||
| .payload(Bytes.wrap(new byte[] {})) | ||
| .sender(senderAddress) | ||
| .chainId(BigInteger.valueOf(2018)) | ||
| .privateFrom(Bytes.fromBase64String(privateFrom)) | ||
| .restriction(Restriction.RESTRICTED) | ||
| .privacyGroupId(Bytes.fromBase64String(PRIVACY_GROUP_ID)) | ||
| .signAndBuild( | ||
| SECP256K1.KeyPair.create( | ||
| SECP256K1.PrivateKey.create( | ||
| new BigInteger( | ||
| "853d7f0010fd86d0d7811c1f9d968ea89a24484a8127b4a483ddf5d2cfec766d", 16)))); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.