Skip to content

Commit

Permalink
changes as per new plenum (hyperledger#535)
Browse files Browse the repository at this point in the history
* changes as per new plenum

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

* bump plenum version

Signed-off-by: ashcherbakov <[email protected]>
  • Loading branch information
lovesh authored and ashcherbakov committed Jan 29, 2018
1 parent ac1cd2d commit ddee8ba
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 162 deletions.
2 changes: 1 addition & 1 deletion indy_client/test/cli/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def susanMap():
return getDefaultUserMap("Susan")


@pytest.fixture(scope="module")
@pytest.fixture(scope="module") # noqa
def faberMap(agentIpAddress, faberAgentPort):
ha = "{}:{}".format(agentIpAddress, faberAgentPort)
return {'inviter': 'Faber College',
Expand Down
9 changes: 6 additions & 3 deletions indy_client/test/cli/test_send_get_nym_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from indy_node.test.helper import check_str_is_base58_compatible

CURRENT_VERKEY_FOR_NYM = 'Current verkey for NYM {dest} is {verkey}'
CURRENT_VERKEY_FOR_NYM_WITH_ROLE = 'Current verkey for NYM {dest} is {verkey} with role {role}'
CURRENT_VERKEY_FOR_NYM_WITH_ROLE = 'Current verkey for NYM {dest} is ' \
'{verkey} with role {role}'
CURRENT_VERKEY_IS_SAME_AS_IDENTIFIER = \
'Current verkey is same as identifier {dest}'
NYM_NOT_FOUND = 'NYM {dest} not found'
Expand Down Expand Up @@ -48,7 +49,8 @@ def test_get_nym_returns_role(
be, do, poolNodesStarted, trusteeCli):
current_role = Roles.TRUST_ANCHOR
uuidIdentifier, abbrevVerkey = createHalfKeyIdentifierAndAbbrevVerkey()
addNym(be, do, trusteeCli, idr=uuidIdentifier, verkey=abbrevVerkey, role=current_role)
addNym(be, do, trusteeCli, idr=uuidIdentifier, verkey=abbrevVerkey,
role=current_role)

parameters = {
'dest': uuidIdentifier,
Expand All @@ -59,7 +61,8 @@ def test_get_nym_returns_role(
do('send GET_NYM dest={dest}',
mapper=parameters, expect=CURRENT_VERKEY_FOR_NYM_WITH_ROLE, within=2)
new_role = ''
addNym(be, do, trusteeCli, idr=uuidIdentifier, verkey=abbrevVerkey, role=new_role)
addNym(be, do, trusteeCli, idr=uuidIdentifier, verkey=abbrevVerkey,
role=new_role)
do('send GET_NYM dest={dest}',
mapper=parameters, expect=CURRENT_VERKEY_FOR_NYM, within=2)

Expand Down
6 changes: 2 additions & 4 deletions indy_client/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import pytest

from plenum.common.signer_simple import SimpleSigner
from plenum.common.constants import VERKEY, ALIAS, STEWARD, TXN_ID, TRUSTEE, TYPE

from indy_client.client.wallet.wallet import Wallet
Expand All @@ -33,8 +32,7 @@
from indy_client.test.cli.helper import newCLI, addTrusteeTxnsToGenesis, addTxnToGenesisFile
from indy_node.test.helper import makePendingTxnsRequest, buildStewardClient, \
TestNode
from indy_client.test.helper import addRole, \
genTestClient, TestClient, createNym
from indy_client.test.helper import addRole, genTestClient, TestClient, createNym

# noinspection PyUnresolvedReferences
from plenum.test.conftest import tdir, client_tdir, nodeReg, up, ready, \
Expand All @@ -43,7 +41,7 @@
poolTxnNodeNames, allPluginsPath, tdirWithNodeKeepInited, tdirWithPoolTxns, \
poolTxnStewardData, poolTxnStewardNames, getValueFromModule, \
txnPoolNodesLooper, patchPluginManager, tdirWithClientPoolTxns, \
warncheck, warnfilters as plenum_warnfilters, setResourceLimits
warncheck, warnfilters as plenum_warnfilters, setResourceLimits, do_post_node_creation

# noinspection PyUnresolvedReferences
from indy_common.test.conftest import tconf, general_conf_tdir, poolTxnTrusteeNames, \
Expand Down
3 changes: 2 additions & 1 deletion indy_client/test/test_nym_attrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ def testStewardCannotAddUsersAttribute(nodeSet, looper, steward,
checkRejects,
steward,
reqs[0].reqId,
"UnauthorizedClientRequest('Only identity owner/guardian can add attribute for that identity'",
"UnauthorizedClientRequest('Only identity owner/guardian can "
"add attribute for that identity'",
retryWait=1,
timeout=timeout))

Expand Down
24 changes: 12 additions & 12 deletions indy_common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from plenum.common.constants import TARGET_NYM, NONCE, RAW, ENC, HASH, NAME, VERSION, ORIGIN, FORCE
from plenum.common.messages.fields import IterableField, AnyMapField, \
NonEmptyStringField, LedgerIdField as PLedgerIdField, \
LedgerInfoField as PLedgerInfoField
NonEmptyStringField
from plenum.common.messages.node_message_factory import node_message_factory

from plenum.common.messages.message_base import MessageValidator
Expand Down Expand Up @@ -239,21 +238,22 @@ class ClientMessageValidator(PClientMessageValidator):
)


class LedgerIdField(PLedgerIdField):
ledger_ids = PLedgerIdField.ledger_ids + (CONFIG_LEDGER_ID,)


class LedgerInfoField(PLedgerInfoField):
_ledger_id_class = LedgerIdField
# THE CODE BELOW MIGHT BE NEEDED IN THE FUTURE, THEREFORE KEEPING IT
# class LedgerIdField(PLedgerIdField):
# ledger_ids = PLedgerIdField.ledger_ids + (CONFIG_LEDGER_ID,)
#
#
# class LedgerInfoField(PLedgerInfoField):
# _ledger_id_class = LedgerIdField


# TODO: it is a workaround which helps extend some fields from
# downstream projects, should be removed after we find a better way
# to do this
node_message_factory.update_schemas_by_field_type(
PLedgerIdField, LedgerIdField)
node_message_factory.update_schemas_by_field_type(
PLedgerInfoField, LedgerInfoField)
# node_message_factory.update_schemas_by_field_type(
# PLedgerIdField, LedgerIdField)
# node_message_factory.update_schemas_by_field_type(
# PLedgerInfoField, LedgerInfoField)


class SafeRequest(Request, ClientMessageValidator):
Expand Down
3 changes: 2 additions & 1 deletion indy_common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from base58 import b58decode
from common.serializers.serialization import serialize_msg_for_signing
from plenum.common.types import f
from plenum.common.util import isHex, error, cryptonymToHex
from plenum.common.util import isHex, cryptonymToHex
from common.error import error
from stp_core.crypto.nacl_wrappers import Verifier


Expand Down
28 changes: 6 additions & 22 deletions indy_node/server/client_authn.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from copy import deepcopy
from hashlib import sha256

from indy_node.server.config_req_handler import ConfigReqHandler
from plenum.common.types import OPERATION
from plenum.common.constants import TXN_TYPE, RAW, ENC, HASH
from plenum.server.client_authn import NaclAuthNr, CoreAuthNr, CoreAuthMixin

from indy_common.constants import ATTRIB, GET_TXNS
from indy_node.server.pool_req_handler import PoolRequestHandler
from indy_node.server.domain_req_handler import DomainReqHandler

from indy_common.constants import ATTRIB, POOL_UPGRADE, SCHEMA, CLAIM_DEF, \
GET_NYM, GET_ATTR, GET_SCHEMA, GET_CLAIM_DEF, POOL_CONFIG
from indy_node.persistence.idr_cache import IdrCache


Expand All @@ -18,23 +15,10 @@ class LedgerBasedAuthNr(CoreAuthMixin, NaclAuthNr):
Transaction-based client authenticator.
"""

write_types = CoreAuthMixin.write_types.union(
PoolRequestHandler.write_types
).union(
DomainReqHandler.write_types
).union(
ConfigReqHandler.write_types
)

query_types = CoreAuthMixin.query_types.union(
{GET_TXNS, }
).union(
PoolRequestHandler.query_types
).union(
DomainReqHandler.query_types
).union(
ConfigReqHandler.query_types
)
write_types = CoreAuthMixin.write_types.union({ATTRIB, SCHEMA, CLAIM_DEF,
POOL_CONFIG, POOL_UPGRADE})
query_types = CoreAuthMixin.query_types.union({GET_NYM, GET_ATTR, GET_SCHEMA,
GET_CLAIM_DEF})

def __init__(self, cache: IdrCache):
NaclAuthNr.__init__(self)
Expand Down
10 changes: 5 additions & 5 deletions indy_node/server/domain_req_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ def _doStaticValidationNym(self, identifier, reqId, operation):
"{} not a valid role".
format(role))

@staticmethod
def _validate_attrib_keys(operation):
dataKeys = {RAW, ENC, HASH}.intersection(set(operation.keys()))
return len(dataKeys) == 1

def _doStaticValidationAttrib(self, identifier, reqId, operation):
if not self._validate_attrib_keys(operation):
raise InvalidClientRequest(identifier, reqId,
Expand Down Expand Up @@ -125,6 +120,11 @@ def validate(self, req: Request, config=None):
elif typ == CLAIM_DEF:
self._validate_claim_def(req)

@staticmethod
def _validate_attrib_keys(operation):
dataKeys = {RAW, ENC, HASH}.intersection(set(operation.keys()))
return len(dataKeys) == 1

def _validateNym(self, req: Request):
origin = req.identifier
op = req.operation
Expand Down
Loading

0 comments on commit ddee8ba

Please sign in to comment.