Skip to content

Commit

Permalink
[INDY-1148] It's possible to create several nodes with the same alias (
Browse files Browse the repository at this point in the history
…hyperledger#554)

add dynamic validation of alias and test

Signed-off-by: toktar <[email protected]>

put alias validation into PoolRequestHandler.isNodeDataConflicting

Signed-off-by: toktar <[email protected]>

change validation in pool_req_handler.

Signed-off-by: toktar <[email protected]>
  • Loading branch information
Toktar authored and Andrew Nikitin committed Apr 9, 2018
1 parent 5b19ea5 commit a3a2080
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
13 changes: 8 additions & 5 deletions plenum/server/pool_req_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def authErrorWhileAddingNode(self, request):
origin)
if self.stewardHasNode(origin):
return "{} already has a node".format(origin)
if self.isNodeDataConflicting(operation.get(DATA, {})):
if self.isNodeDataConflicting(data):
return "existing data has conflicts with " \
"request data {}".format(operation.get(DATA))

Expand Down Expand Up @@ -156,14 +156,14 @@ def isNodeDataSame(self, nodeNym, newData, isCommitted=True):
nodeInfo.pop(f.IDENTIFIER.nm, None)
return nodeInfo == newData

def isNodeDataConflicting(self, data, nodeNym=None):
def isNodeDataConflicting(self, data, updatingNym=None):
# Check if node's ALIAS or IPs or ports conflicts with other nodes,
# also, the node is not allowed to change its alias.

# Check ALIAS change
nodeData = {}
if nodeNym:
nodeData = self.getNodeData(nodeNym, isCommitted=False)
if updatingNym:
nodeData = self.getNodeData(updatingNym, isCommitted=False)
if nodeData.get(ALIAS) != data.get(ALIAS):
return True
else:
Expand All @@ -177,7 +177,7 @@ def isNodeDataConflicting(self, data, nodeNym=None):
otherNodeData = self.stateSerializer.deserialize(otherNodeData)
otherNodeData.pop(f.IDENTIFIER.nm, None)
otherNodeData.pop(SERVICES, None)
if not nodeNym or otherNode != nodeNym:
if not updatingNym or otherNode != updatingNym:
# The node's ip, port and alias shuuld be unique
bag = set()
for d in (nodeData, otherNodeData):
Expand All @@ -191,6 +191,9 @@ def isNodeDataConflicting(self, data, nodeNym=None):
if (not nodeData and len(bag) != 3) or (
nodeData and len(bag) != 6):
return True
if data.get(ALIAS) == otherNodeData.get(
ALIAS) and not updatingNym:
return True

def dataErrorWhileValidatingUpdate(self, data, nodeNym):
error = self.dataErrorWhileValidating(data, skipKeys=True)
Expand Down
26 changes: 26 additions & 0 deletions plenum/test/pool_transactions/test_node_adding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from plenum.common.constants import STEWARD, DATA
from plenum.common.request import Request
from plenum.test.pool_transactions.helper import sendAddNewNode, addNewClient
from plenum.test.helper import waitRejectWithReason


def test_add_node_with_not_unique_alias(looper,
tdir,
tconf,
txnPoolNodeSet,
steward1,
stewardWallet):
newNodeName = "Alpha"
newSteward = addNewClient(STEWARD, looper, steward1, stewardWallet,
"testStewardMy")
newNode = sendAddNewNode(tdir, tconf, newNodeName, steward1, newSteward)
data = {}
for item in newNode:
if isinstance(item, Request):
data = item.operation.get(DATA)

for node in txnPoolNodeSet:
waitRejectWithReason(looper, steward1,
"existing data has conflicts with " +
"request data {}".format(data),
node.clientstack.name)

0 comments on commit a3a2080

Please sign in to comment.