Skip to content

Commit

Permalink
INDY-1914: Fix and tests for schema attr limit
Browse files Browse the repository at this point in the history
Signed-off-by: ArtObr <[email protected]>
  • Loading branch information
ArtObr committed Jan 9, 2019
1 parent 9664d94 commit abe2863
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ So, if the Schema needs to be evolved, a new Schema with a new version or name n

Dictionary with Schema's data:

- `attr_names`: array of attribute name strings
- `attr_names`: array of attribute name strings (125 attributes maximum)
- `name`: Schema's name string
- `version`: Schema's version string

Expand Down
2 changes: 2 additions & 0 deletions indy_common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@
PACKAGES_TO_HOLD = ['indy-plenum', 'indy-node', 'python3-indy-crypto', 'libindy-crypto']

authPolicy = LOCAL_AUTH_POLICY

SCHEMA_ATTRIBUTES_LIMIT = 125
4 changes: 3 additions & 1 deletion indy_common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from copy import deepcopy
from hashlib import sha256

from indy_common.config import SCHEMA_ATTRIBUTES_LIMIT
from indy_common.constants import TXN_TYPE, ATTRIB, GET_ATTR, \
DATA, GET_NYM, GET_SCHEMA, GET_CLAIM_DEF, ACTION, \
POOL_UPGRADE, POOL_CONFIG, \
Expand Down Expand Up @@ -80,7 +81,8 @@ class SchemaField(MessageValidator):
(SCHEMA_VERSION, VersionField(components_number=(2, 3,), max_length=VERSION_FIELD_LIMIT)),
(SCHEMA_ATTR_NAMES, IterableField(
LimitedLengthStringField(max_length=NAME_FIELD_LIMIT),
min_length=1)),
min_length=1,
max_length=SCHEMA_ATTRIBUTES_LIMIT)),
)


Expand Down
41 changes: 40 additions & 1 deletion indy_node/test/schema/test_send_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pytest

from indy_common.config import SCHEMA_ATTRIBUTES_LIMIT
from indy_node.test.api.helper import validate_write_reply, sdk_write_schema_and_check
from plenum.common.exceptions import RequestRejectedException
from plenum.common.exceptions import RequestRejectedException, RequestNackedException
from plenum.common.util import randomString
from plenum.config import NAME_FIELD_LIMIT


def test_send_schema_multiple_attrib(looper, sdk_pool_handle,
Expand Down Expand Up @@ -48,3 +51,39 @@ def test_can_not_send_same_schema(looper, sdk_pool_handle,
ex_info.match(
"can have one and only one SCHEMA with name business and version 1.8"
)


def test_schema_maximum_attrib(looper, sdk_pool_handle,
sdk_wallet_trust_anchor):
attribs = []
string = randomString(NAME_FIELD_LIMIT)
for i in range(SCHEMA_ATTRIBUTES_LIMIT):
i = str(i)
attribs.append(string[:-len(i)] + i)

sdk_write_schema_and_check(
looper, sdk_pool_handle,
sdk_wallet_trust_anchor,
attribs,
"business1",
"1.9"
)


def test_schema_over_maximum_attrib(looper, sdk_pool_handle,
sdk_wallet_trust_anchor):
attribs = []
for i in range(SCHEMA_ATTRIBUTES_LIMIT + 1):
attribs.append('attrib' + str(i))

with pytest.raises(RequestNackedException) as ex_info:
sdk_write_schema_and_check(
looper, sdk_pool_handle,
sdk_wallet_trust_anchor,
attribs,
"business2",
"2.0"
)
ex_info.match(
"length should be at most {}".format(SCHEMA_ATTRIBUTES_LIMIT)
)

0 comments on commit abe2863

Please sign in to comment.