|
|
|
@ -16,8 +16,10 @@ import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
import static tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController.NodesWhitelistResult; |
|
|
|
|
|
|
|
|
|
import tech.pegasys.pantheon.ethereum.p2p.peers.DefaultPeer; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; |
|
|
|
|
import tech.pegasys.pantheon.ethereum.permissioning.WhitelistOperationResult; |
|
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
@ -125,4 +127,107 @@ public class NodeWhitelistControllerTest { |
|
|
|
|
|
|
|
|
|
assertThat(actualResult).isEqualToComparingOnlyGivenFields(expected, "result"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void whenNodeIdsAreDifferentItShouldNotBePermitted() { |
|
|
|
|
Peer peer1 = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0xaaaa80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303); |
|
|
|
|
Peer peer2 = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0xbbba80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303); |
|
|
|
|
|
|
|
|
|
controller.addNode(peer1); |
|
|
|
|
|
|
|
|
|
assertThat(controller.isPermitted(peer2)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void whenNodesHostsAreDifferentItShouldNotBePermitted() { |
|
|
|
|
Peer peer1 = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0xaaaa80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303); |
|
|
|
|
Peer peer2 = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0xaaaa80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.2", |
|
|
|
|
30303); |
|
|
|
|
|
|
|
|
|
controller.addNode(peer1); |
|
|
|
|
|
|
|
|
|
assertThat(controller.isPermitted(peer2)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void whenNodesUdpPortsAreDifferentItShouldNotBePermitted() { |
|
|
|
|
Peer peer1 = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0xaaaa80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30301); |
|
|
|
|
Peer peer2 = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0xaaaa80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30302); |
|
|
|
|
|
|
|
|
|
controller.addNode(peer1); |
|
|
|
|
|
|
|
|
|
assertThat(controller.isPermitted(peer2)).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void whenCheckingIfNodeIsPermittedTcpPortShouldNotBeConsideredIfAbsent() { |
|
|
|
|
Peer peerWithTcpPortSet = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0x6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303, |
|
|
|
|
10001); |
|
|
|
|
Peer peerWithoutTcpPortSet = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0x6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303); |
|
|
|
|
|
|
|
|
|
controller.addNode(peerWithoutTcpPortSet); |
|
|
|
|
|
|
|
|
|
assertThat(controller.isPermitted(peerWithTcpPortSet)).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void whenCheckingIfNodeIsPermittedTcpPortShouldBeConsideredIfPresent() { |
|
|
|
|
Peer peerWithTcpPortSet = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0x6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303, |
|
|
|
|
10001); |
|
|
|
|
Peer peerWithDifferentTcpPortSet = |
|
|
|
|
new DefaultPeer( |
|
|
|
|
BytesValue.fromHexString( |
|
|
|
|
"0x6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0"), |
|
|
|
|
"127.0.0.1", |
|
|
|
|
30303, |
|
|
|
|
10002); |
|
|
|
|
|
|
|
|
|
controller.addNode(peerWithDifferentTcpPortSet); |
|
|
|
|
|
|
|
|
|
assertThat(controller.isPermitted(peerWithTcpPortSet)).isFalse(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|