formatting & prevents comment from being altered #14

Merged
osilkin98 merged 1 commit from alteration-fix into master 2019-09-06 17:43:02 +02:00
2 changed files with 16 additions and 13 deletions

View file

@ -3,16 +3,15 @@ import sqlite3
from asyncio import coroutine from asyncio import coroutine
from src.database.queries import hide_comments_by_id
from src.database.queries import delete_comment_by_id from src.database.queries import delete_comment_by_id
from src.database.queries import get_comment_or_none
from src.database.queries import insert_comment
from src.database.queries import insert_channel
from src.database.queries import get_claim_ids_from_comment_ids from src.database.queries import get_claim_ids_from_comment_ids
from src.server.misc import validate_signature_from_claim from src.database.queries import get_comment_or_none
from src.database.queries import hide_comments_by_id
from src.database.queries import insert_channel
from src.database.queries import insert_comment
from src.server.misc import channel_matches_pattern_or_error from src.server.misc import channel_matches_pattern_or_error
from src.server.misc import get_claim_from_id from src.server.misc import get_claim_from_id
from src.server.misc import validate_signature_from_claim
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -22,8 +21,13 @@ def create_comment_or_error(conn, comment, claim_id, channel_id=None, channel_na
if channel_id or channel_name or signature or signing_ts: if channel_id or channel_name or signature or signing_ts:
insert_channel_or_error(conn, channel_name, channel_id) insert_channel_or_error(conn, channel_name, channel_id)
comment_id = insert_comment( comment_id = insert_comment(
conn=conn, comment=comment, claim_id=claim_id, channel_id=channel_id, conn=conn,
signature=signature, parent_id=parent_id, signing_ts=signing_ts comment=comment,
claim_id=claim_id,
channel_id=channel_id,
signature=signature,
parent_id=parent_id,
signing_ts=signing_ts
) )
return get_comment_or_none(conn, comment_id) return get_comment_or_none(conn, comment_id)

View file

@ -1,19 +1,18 @@
import binascii import binascii
import hashlib
import logging import logging
import re import re
from json import JSONDecodeError from json import JSONDecodeError
import hashlib
import aiohttp import aiohttp
import ecdsa import ecdsa
from aiohttp import ClientConnectorError from aiohttp import ClientConnectorError
from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import load_der_public_key
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives.asymmetric.utils import Prehashed from cryptography.hazmat.primitives.asymmetric.utils import Prehashed
from cryptography.exceptions import InvalidSignature from cryptography.hazmat.primitives.serialization import load_der_public_key
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -130,7 +129,7 @@ def validate_signature_from_claim(claim, signature, signing_ts, data: str):
def clean_input_params(kwargs: dict): def clean_input_params(kwargs: dict):
for k, v in kwargs.items(): for k, v in kwargs.items():
if type(v) is str: if type(v) is str and k is not 'comment':
kwargs[k] = v.strip() kwargs[k] = v.strip()
if k in ID_LIST: if k in ID_LIST:
kwargs[k] = v.lower() kwargs[k] = v.lower()