forked from PegaSysEng/pantheon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NC-1968] Permissioning whitelist persistence. (PegaSysEng#763)
* [NC-1968] Initial commit. * [NC-1968] Acceptance tests. * [NC-1968] PR fixes. * [NC-1968] Merge conflicts.
- Loading branch information
1 parent
b1e8df2
commit d6bfbdb
Showing
27 changed files
with
832 additions
and
86 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...ch/pegasys/pantheon/tests/acceptance/dsl/condition/perm/WhiteListContainsKeyAndValue.java
This file contains 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,50 @@ | ||
/* | ||
* Copyright 2019 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. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.dsl.condition.perm; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
|
||
public class WhiteListContainsKeyAndValue implements Condition { | ||
private final WhitelistPersistor.WHITELIST_TYPE whitelistType; | ||
private final Collection<String> whitelistValues; | ||
private final Path configFilePath; | ||
|
||
public WhiteListContainsKeyAndValue( | ||
final WhitelistPersistor.WHITELIST_TYPE whitelistType, | ||
final Collection<String> whitelistValues, | ||
final Path configFilePath) { | ||
this.whitelistType = whitelistType; | ||
this.whitelistValues = whitelistValues; | ||
this.configFilePath = configFilePath; | ||
} | ||
|
||
@Override | ||
public void verify(final Node node) { | ||
boolean result; | ||
try { | ||
result = | ||
WhitelistPersistor.verifyConfigFileMatchesState( | ||
whitelistType, whitelistValues, configFilePath); | ||
} catch (final Exception e) { | ||
result = false; | ||
} | ||
assertThat(result).isTrue(); | ||
} | ||
} |
This file contains 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 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 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
102 changes: 102 additions & 0 deletions
102
...ech/pegasys/pantheon/tests/acceptance/permissioning/WhitelistPersistorAcceptanceTest.java
This file contains 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,102 @@ | ||
/* | ||
* Copyright 2019 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. | ||
*/ | ||
package tech.pegasys.pantheon.tests.acceptance.permissioning; | ||
|
||
import static tech.pegasys.pantheon.ethereum.permissioning.WhitelistPersistor.WHITELIST_TYPE; | ||
|
||
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; | ||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
import org.assertj.core.util.Lists; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class WhitelistPersistorAcceptanceTest extends AcceptanceTestBase { | ||
|
||
private Node node; | ||
private Account senderA; | ||
private Account senderB; | ||
private Path tempFile; | ||
|
||
private final String enode1 = | ||
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; | ||
private final String enode2 = | ||
"enode://5f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; | ||
private final String enode3 = | ||
"enode://4f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567"; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
senderA = accounts.getPrimaryBenefactor(); | ||
senderB = accounts.getSecondaryBenefactor(); | ||
tempFile = Files.createTempFile("test", "test"); | ||
node = | ||
pantheon.createNodeWithWhitelistsEnabled( | ||
"node", | ||
new ArrayList<>(), | ||
Collections.singletonList(senderA.getAddress()), | ||
tempFile.toAbsolutePath().toString()); | ||
cluster.start(node); | ||
} | ||
|
||
@Test | ||
public void manipulatedAccountsWhitelistIsPersisted() { | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.ACCOUNTS, Collections.singleton(senderA.getAddress()), tempFile)); | ||
|
||
node.execute(transactions.addAccountsToWhitelist(senderB.getAddress())); | ||
node.verify(perm.expectAccountsWhitelist(senderA.getAddress(), senderB.getAddress())); | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.ACCOUNTS, | ||
Lists.list(senderA.getAddress(), senderB.getAddress()), | ||
tempFile)); | ||
|
||
node.execute(transactions.removeAccountsFromWhitelist(senderB.getAddress())); | ||
node.verify(perm.expectAccountsWhitelist(senderA.getAddress())); | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.ACCOUNTS, Collections.singleton(senderA.getAddress()), tempFile)); | ||
|
||
node.execute(transactions.removeAccountsFromWhitelist(senderA.getAddress())); | ||
node.verify(perm.expectAccountsWhitelist()); | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.ACCOUNTS, Collections.emptyList(), tempFile)); | ||
} | ||
|
||
@Test | ||
public void manipulatedNodesWhitelistIsPersisted() { | ||
node.verify(perm.addNodesToWhitelist(Lists.newArrayList(enode1, enode2))); | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.NODES, Lists.newArrayList(enode1, enode2), tempFile)); | ||
|
||
node.verify(perm.removeNodesFromWhitelist(Lists.newArrayList(enode1))); | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.NODES, Collections.singleton(enode2), tempFile)); | ||
|
||
node.verify(perm.addNodesToWhitelist(Lists.newArrayList(enode1, enode3))); | ||
node.verify( | ||
perm.expectPermissioningWhitelistFileKeyValue( | ||
WHITELIST_TYPE.NODES, Lists.newArrayList(enode2, enode1, enode3), tempFile)); | ||
} | ||
} |
This file contains 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 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 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
Oops, something went wrong.