Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
d1930c082e
4 changed files with 11 additions and 7 deletions
|
@ -14,6 +14,7 @@ CREATE TABLE IF NOT EXISTS COMMENT (
|
|||
ParentId TEXT DEFAULT NULL,
|
||||
Signature TEXT DEFAULT NULL,
|
||||
Timestamp INTEGER NOT NULL,
|
||||
SigningTs TEXT DEFAULT NULL,
|
||||
CONSTRAINT COMMENT_PRIMARY_KEY PRIMARY KEY (CommentId) ON CONFLICT IGNORE,
|
||||
CONSTRAINT COMMENT_SIGNATURE_SK UNIQUE (Signature) ON CONFLICT ABORT,
|
||||
CONSTRAINT COMMENT_CHANNEL_FK FOREIGN KEY (ChannelId) REFERENCES CHANNEL(ClaimId)
|
||||
|
@ -22,7 +23,7 @@ CREATE TABLE IF NOT EXISTS COMMENT (
|
|||
ON UPDATE CASCADE ON DELETE NO ACTION -- setting null implies comment is top level
|
||||
);
|
||||
|
||||
ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
||||
-- ALTER TABLE COMMENT ADD COLUMN SigningTs TEXT DEFAULT NULL;
|
||||
|
||||
-- DROP TABLE IF EXISTS CHANNEL;
|
||||
CREATE TABLE IF NOT EXISTS CHANNEL(
|
||||
|
|
|
@ -94,9 +94,8 @@ def insert_comment(conn: sqlite3.Connection, claim_id: str = None, comment: str
|
|||
channel_id: str = None, signature: str = None, signing_ts: str = None,
|
||||
parent_id: str = None) -> str:
|
||||
timestamp = int(time.time())
|
||||
prehash = ':'.join((claim_id, comment, str(timestamp),))
|
||||
prehash = bytes(prehash.encode('utf-8'))
|
||||
comment_id = nacl.hash.sha256(prehash).decode('utf-8')
|
||||
prehash = b':'.join((claim_id.encode(), comment.encode(), str(timestamp).encode(),))
|
||||
comment_id = nacl.hash.sha256(prehash).decode()
|
||||
with conn:
|
||||
conn.execute(
|
||||
"""
|
||||
|
|
|
@ -2,8 +2,10 @@ import logging
|
|||
import sqlite3
|
||||
|
||||
from src.database import get_comment_or_none
|
||||
from src.database import insert_comment, insert_channel
|
||||
from src.misc import validate_channel, validate_signature
|
||||
from src.database import insert_comment
|
||||
from src.database import insert_channel
|
||||
from src.misc import validate_channel
|
||||
from src.misc import validate_signature
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -16,7 +18,7 @@ def create_comment(conn: sqlite3.Connection, comment: str, claim_id: str, channe
|
|||
try:
|
||||
comment_id = insert_comment(
|
||||
conn=conn, comment=comment, claim_id=claim_id, channel_id=channel_id,
|
||||
signature=signature, parent_id=parent_id
|
||||
signature=signature, parent_id=parent_id, signing_ts=signing_ts
|
||||
)
|
||||
return get_comment_or_none(conn, comment_id)
|
||||
except sqlite3.IntegrityError as ie:
|
||||
|
|
|
@ -75,6 +75,7 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
signing_ts='asdasd'
|
||||
)
|
||||
self.assertIsNotNone(comment)
|
||||
self.assertIn('signing_ts', comment)
|
||||
previous_id = comment['comment_id']
|
||||
reply = create_comment(
|
||||
conn=self.conn,
|
||||
|
@ -88,6 +89,7 @@ class TestCommentCreation(DatabaseTestCase):
|
|||
)
|
||||
self.assertIsNotNone(reply)
|
||||
self.assertEqual(reply['parent_id'], comment['comment_id'])
|
||||
self.assertIn('signing_ts', reply)
|
||||
|
||||
def test04UsernameVariations(self):
|
||||
self.assertRaises(
|
||||
|
|
Loading…
Reference in a new issue