Skip to content

Commit

Permalink
INDY-2142: add a validation for ISSUANCE_TYPE in revoc_reg_def
Browse files Browse the repository at this point in the history
Signed-off-by: toktar <renata.toktar@dsr-corporation.com>
  • Loading branch information
Toktar committed Jun 14, 2019
1 parent 89e0691 commit 1fd4550
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
5 changes: 3 additions & 2 deletions indy_common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
SCHEMA_ATTR_NAMES, CLAIM_DEF_SIGNATURE_TYPE, CLAIM_DEF_PUBLIC_KEYS, CLAIM_DEF_TAG, CLAIM_DEF_SCHEMA_REF, \
CLAIM_DEF_PRIMARY, CLAIM_DEF_REVOCATION, CLAIM_DEF_FROM, PACKAGE, AUTH_RULE, AUTH_RULES, CONSTRAINT, AUTH_ACTION, \
AUTH_TYPE, \
FIELD, OLD_VALUE, NEW_VALUE, GET_AUTH_RULE, RULES
FIELD, OLD_VALUE, NEW_VALUE, GET_AUTH_RULE, RULES, ISSUANCE_BY_DEFAULT, ISSUANCE_ON_DEMAND
from indy_common.version import SchemaVersion


Expand Down Expand Up @@ -102,7 +102,8 @@ class ClaimDefField(MessageValidator):

class RevocDefValueField(MessageValidator):
schema = (
(ISSUANCE_TYPE, NonEmptyStringField()),
(ISSUANCE_TYPE, ChooseField(values=(ISSUANCE_BY_DEFAULT,
ISSUANCE_ON_DEMAND))),
(MAX_CRED_NUM, IntegerField()),
(PUBLIC_KEYS, AnyMapField()),
(TAILS_HASH, NonEmptyStringField()),
Expand Down
45 changes: 45 additions & 0 deletions indy_node/test/anon_creds/test_incorrect_revoc_reg_def.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import json

import pytest

from indy_common.constants import CRED_DEF_ID, CLAIM_DEF_SCHEMA_REF, CLAIM_DEF_SIGNATURE_TYPE, \
CLAIM_DEF_TAG, VALUE, ISSUANCE_TYPE, REVOKED, PREV_ACCUM, ISSUANCE_BY_DEFAULT
from indy_common.state.domain import make_state_path_for_claim_def
from indy_node.test.anon_creds.conftest import build_revoc_reg_entry_for_given_revoc_reg_def
from plenum.common.exceptions import RequestNackedException
from plenum.test.helper import sdk_sign_request_from_dict, sdk_send_and_check


def test_incorrect_revoc_reg_def(looper,
txnPoolNodeSet,
sdk_wallet_steward,
sdk_pool_handle,
send_claim_def,
build_revoc_def_by_default):
_, author_did = sdk_wallet_steward
claim_def_req = send_claim_def[0]
revoc_reg = build_revoc_def_by_default
revoc_reg['operation'][CRED_DEF_ID] = \
make_state_path_for_claim_def(author_did,
str(claim_def_req['operation'][CLAIM_DEF_SCHEMA_REF]),
claim_def_req['operation'][CLAIM_DEF_SIGNATURE_TYPE],
claim_def_req['operation'][CLAIM_DEF_TAG]
).decode()

# test incorrect ISSUANCE_TYPE
revoc_reg['operation'][VALUE][ISSUANCE_TYPE] = "incorrect_type"
revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, revoc_reg['operation'])
with pytest.raises(RequestNackedException, match='unknown value'):
sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet, sdk_pool_handle)

# test correct ISSUANCE_TYPE
revoc_reg['operation'][VALUE][ISSUANCE_TYPE] = ISSUANCE_BY_DEFAULT
revoc_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, revoc_reg['operation'])
sdk_send_and_check([json.dumps(revoc_req)], looper, txnPoolNodeSet, sdk_pool_handle)

# send revoc_reg_entry to check that revoc_reg_def ordered correctly
rev_reg_entry = build_revoc_reg_entry_for_given_revoc_reg_def(revoc_req)
rev_reg_entry[VALUE][REVOKED] = [1, 2, 3, 4, 5]
del rev_reg_entry[VALUE][PREV_ACCUM]
rev_entry_req = sdk_sign_request_from_dict(looper, sdk_wallet_steward, rev_reg_entry)
sdk_send_and_check([json.dumps(rev_entry_req)], looper, txnPoolNodeSet, sdk_pool_handle)

0 comments on commit 1fd4550

Please sign in to comment.