From abe2863d6313b0b3850bdb2b197e52a95cacabe8 Mon Sep 17 00:00:00 2001 From: ArtObr Date: Wed, 9 Jan 2019 19:20:30 +0300 Subject: [PATCH] INDY-1914: Fix and tests for schema attr limit Signed-off-by: ArtObr --- docs/requests.md | 2 +- indy_common/config.py | 2 ++ indy_common/types.py | 4 ++- indy_node/test/schema/test_send_schema.py | 41 ++++++++++++++++++++++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/docs/requests.md b/docs/requests.md index a92363ed9..ac25444ce 100644 --- a/docs/requests.md +++ b/docs/requests.md @@ -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 diff --git a/indy_common/config.py b/indy_common/config.py index 37af80164..526016a2a 100644 --- a/indy_common/config.py +++ b/indy_common/config.py @@ -103,3 +103,5 @@ PACKAGES_TO_HOLD = ['indy-plenum', 'indy-node', 'python3-indy-crypto', 'libindy-crypto'] authPolicy = LOCAL_AUTH_POLICY + +SCHEMA_ATTRIBUTES_LIMIT = 125 diff --git a/indy_common/types.py b/indy_common/types.py index 82f154fed..341f25001 100644 --- a/indy_common/types.py +++ b/indy_common/types.py @@ -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, \ @@ -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)), ) diff --git a/indy_node/test/schema/test_send_schema.py b/indy_node/test/schema/test_send_schema.py index caf65c81e..39364c6c2 100644 --- a/indy_node/test/schema/test_send_schema.py +++ b/indy_node/test/schema/test_send_schema.py @@ -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, @@ -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) + )