Unverified Commit ae6c6c77 authored by Justin Welch's avatar Justin Welch Committed by GitHub

Merge pull request #223 from steemit/netuoso-221-custom-json-validator

Community - adjust custom_json validator
parents 74a41ccb 39ff4b99
......@@ -41,6 +41,7 @@ funcy = "*"
vprof = "*"
[packages]
attrs = "==19.1.0"
aiodns = "*"
aiohttp = "*"
aredis = "*"
......
......@@ -34,7 +34,7 @@ NONE_TYPE = type(None)
ID_TYPES = (int, str, float, NONE_TYPE)
PARAMS_TYPES = (list, dict, NONE_TYPE)
CUSTOM_JSON_SIZE_LIMIT = 2000
CUSTOM_JSON_SIZE_LIMIT = 8192
CUSTOM_JSON_FOLLOW_RATE = 2
BROADCAST_TRANSACTION_METHODS = {
......@@ -199,7 +199,7 @@ def limit_broadcast_transaction_request(request: JSONRPCRequest, limits=None) ->
def limit_custom_json_op_length(ops: list, size_limit=None):
if any(len(op[1]['json']) > size_limit for op in ops):
if any(len(op[1]['json'].encode('utf-8')) > size_limit for op in ops):
raise JussiCustomJsonOpLengthError(size_limit=size_limit)
......
......@@ -1594,7 +1594,7 @@ INVALID_BROADCAST_TRANSACTIONS = [
{
"required_auths": [],
"id": "follow",
"json": 'a' * 2001,
"json": 'a' * 8193,
"required_posting_auths": ["steemit"]
}
]
......@@ -1666,7 +1666,7 @@ INVALID_BROADCAST_TRANSACTIONS = [
{
"required_auths": [],
"id": "follow",
"json": 'a' * 2001,
"json": 'a' * 8193,
"required_posting_auths": ["steemit"]
}
]
......
......@@ -294,7 +294,16 @@ def test_is_valid_jussi_response_using_steemd(steemd_request_and_response):
{
"required_auths": [],
"id": "follow",
"json": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"json": "a"*8192,
"required_posting_auths": ["steemit"]
}
]], False),
([[
'custom_json',
{
"required_auths": [],
"id": "follow",
"json": "😂"*2048,
"required_posting_auths": ["steemit"]
}
]], False),
......@@ -302,9 +311,9 @@ def test_is_valid_jussi_response_using_steemd(steemd_request_and_response):
def test_is_valid_custom_json_op_length(ops, expected):
if expected is False:
with pytest.raises(JussiCustomJsonOpLengthError):
limit_custom_json_op_length(ops, size_limit=1000)
limit_custom_json_op_length(ops, size_limit=8191)
else:
limit_custom_json_op_length(ops, size_limit=1000)
limit_custom_json_op_length(ops, size_limit=100)
@pytest.mark.parametrize('ops, expected', [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment