diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml index 2427c20a7685aa7336cd62bf8b0df4e3c1361a82..3408310a7e98c5f38b6119369507f66b7dad118f 100644 --- a/.gitlab-ci.yaml +++ b/.gitlab-ci.yaml @@ -73,7 +73,8 @@ hivemind_sync: script: - pip3 install --user --upgrade pip setuptools - - scripts/ci_sync.sh "$HIVEMIND_DB_NAME" "$HIVEMIND_POSTGRESQL_CONNECTION_STRING" "$HIVEMIND_SOURCE_HIVED_URL" $HIVEMIND_MAX_BLOCK $HIVEMIND_HTTP_PORT + # WARNING: hardcoded 5000017 for max block + - scripts/ci_sync.sh "$HIVEMIND_DB_NAME" "$HIVEMIND_POSTGRESQL_CONNECTION_STRING" "$HIVEMIND_SOURCE_HIVED_URL" 5000017 $HIVEMIND_HTTP_PORT artifacts: paths: diff --git a/hive/indexer/accounts.py b/hive/indexer/accounts.py index 7af31b4c4fae3926a06af6ec130b322cb4470962..98c4f862de9f12ecacf74019158b73caaf81d077 100644 --- a/hive/indexer/accounts.py +++ b/hive/indexer/accounts.py @@ -83,8 +83,6 @@ class Accounts(DbAdapterHolder): """Check if an account name exists.""" if isinstance(names, str): return names in cls._ids - if isinstance(names, list): - return all(name in cls._ids for name in names) return False @classmethod diff --git a/hive/indexer/follow.py b/hive/indexer/follow.py index 1dcc90cf6ab82e38770b39095d1eabb11866f096..f2c727a5b359427a37566a4927f85de7f3a20f11 100644 --- a/hive/indexer/follow.py +++ b/hive/indexer/follow.py @@ -2,6 +2,7 @@ import logging from time import perf_counter as perf +from json import dumps from funcy.seqs import first from hive.db.adapter import Db @@ -12,6 +13,7 @@ from hive.indexer.accounts import Accounts from hive.indexer.db_adapter_holder import DbAdapterHolder from hive.utils.normalize import escape_characters + log = logging.getLogger(__name__) FOLLOWERS = 'followers' @@ -99,11 +101,22 @@ class Follow(DbAdapterHolder): or not 'following' in op): return None + # follower/following is empty + if not op['follower'] or not op['following']: + return None + op['following'] = op['following'] if isinstance(op['following'], list) else [op['following']] + # mimic original behaviour + # if following name does not exist do not process it: basically equal to drop op for single following entry - # follower/following is empty - if not op['follower'] or not op['following']: + op['following'] = [op for op in op['following'] if Accounts.exists(op)] + + # if follower name does not exist drop op + if not Accounts.exists(op['follower']): + return None + + if op['follower'] in op['following'] or op['follower'] != account: return None what = first(op['what']) or '' @@ -115,16 +128,6 @@ class Follow(DbAdapterHolder): if what not in defs: return None - all_accounts = list(op['following']) - all_accounts.append(op['follower']) - if (op['follower'] in op['following'] - or op['follower'] != account): - return None - - non_existent_names = Accounts.check_names(all_accounts) - if non_existent_names: - log.warning("Follow op validation, following names does not exists in database: {}".format(non_existent_names)) - return dict(flr=escape_characters(op['follower']), flg=[escape_characters(following) for following in op['following']], state=defs[what], diff --git a/hive/utils/normalize.py b/hive/utils/normalize.py index ee7b220167553f5e3d1d786021c0a2c89c96a189..f0a2f61421d6a3c1d09ff0e3dc1e5fe340b2398d 100644 --- a/hive/utils/normalize.py +++ b/hive/utils/normalize.py @@ -68,6 +68,7 @@ def to_nai(value): def escape_characters(text): """ Escape special charactes """ + assert isinstance(text, str), "Expected string got: {}".format(type(text)) if len(text.strip()) == 0: return "'" + text + "'" diff --git a/mock_data/block_data/follow_op/mock_block_data_follow.json b/mock_data/block_data/follow_op/mock_block_data_follow.json index fd6cb77fc7d31c7cd55775cc7467550dd6429ca8..d2a7532821ebb878460e8c5a283e6d1dde318702 100644 --- a/mock_data/block_data/follow_op/mock_block_data_follow.json +++ b/mock_data/block_data/follow_op/mock_block_data_follow.json @@ -269,6 +269,17 @@ "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"t'es'ter3\", \"<html><body><p>PPPPP</p></body></html>\"],\"what\":[\"blog\"]}]" } }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "tester1" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"tester7\", \"<script>alert('hello world');</script>\"],\"what\":[\"blog\"]}]" + } + }, { "type": "custom_json_operation", "value": { @@ -352,7 +363,7 @@ "tester1" ], "id": "follow", - "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"tester3\", \"tester4\"],\"what\":[\"blogo-doggo\"]}]" + "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"tester3\", \"gtg\"],\"what\":[\"blogo-doggo\"]}]" } }, { @@ -363,7 +374,84 @@ "te'%@ter1" ], "id": "follow", - "json": "[\"follow\",{\"follower\":\"te'%@ter1\",\"following\":[\"tester3\", \"tester4\"],\"what\":[\"blog\"]}]" + "json": "[\"follow\",{\"follower\":\"te'%@ter1\",\"following\":[\"gtg\", \"tester4\"],\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "{\"tester1\":\"tester1\"}" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":{\"tester1\":\"tester1\"},\"following\":{\"gtg\":\"gtg\"},\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "tester1" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":{\"gtg\":\"gtg\"},\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "tester1" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"tester3\", [\"gtg\"]],\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "tester1" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":[\"tester1\"],\"following\":[\"tester3\", [\"gtg\"]],\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "[\"tester1\"]" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":[\"tester1\"],\"following\":[\"tester3\", {\"gtg\":\"gtg\"}],\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "tester1" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"tester3\", {\"gtg\":\"gtg\"}],\"what\":[\"blog\"]}]" + } + }, + { + "type": "custom_json_operation", + "value": { + "required_auths": [], + "required_posting_auths": [ + "tester1" + ], + "id": "follow", + "json": "[\"follow\",{\"follower\":\"tester1\",\"following\":[\"tester7\", \"<script>alert('hello world');</script>\"],\"what\":[\"blog\"]}]" } } ]