From fa7b3ca774ade5b572fd3330d8d1bd7769662605 Mon Sep 17 00:00:00 2001 From: nolash Date: Wed, 5 Aug 2020 19:54:19 +0200 Subject: [PATCH] Add wrong password test --- src/keystore/postgres.py | 4 ---- test/test_database.py | 7 ++++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/keystore/postgres.py b/src/keystore/postgres.py index fc3b8ec..013964c 100644 --- a/src/keystore/postgres.py +++ b/src/keystore/postgres.py @@ -24,7 +24,6 @@ class ReferenceDatabase: def __init__(self, dbname, **kwargs): - logg.debug(kwargs) self.conn = psycopg2.connect('dbname='+dbname) self.cur = self.conn.cursor() self.symmetric_key = kwargs.get('symmetric_key') @@ -32,7 +31,6 @@ class ReferenceDatabase: def get(self, address, password=None): s = sql.SQL('SELECT key_ciphertext FROM ethereum WHERE wallet_address_hex = %s') - logg.debug(address) self.cur.execute(s, [ address ] ) k = self.cur.fetchone()[0] return self._decrypt(k, password) @@ -41,9 +39,7 @@ class ReferenceDatabase: def new(self, address, password=None): b = os.urandom(32) pk = keyapi.PrivateKey(b) - logg.debug('pk {}'.format(pk.to_hex())) c = self._encrypt(pk.to_bytes(), password) - logg.debug('pkc {} {}'.format(c, len(pk.to_bytes()))) s = sql.SQL('INSERT INTO ethereum (wallet_address_hex, key_ciphertext) VALUES (%s, %s)') self.cur.execute(s, [ address, c.decode('utf-8') ]) diff --git a/test/test_database.py b/test/test_database.py index 777b882..76b8953 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -6,7 +6,7 @@ import base64 import psycopg2 from psycopg2 import sql -from cryptography.fernet import Fernet +from cryptography.fernet import Fernet, InvalidToken from keystore import ReferenceDatabase @@ -52,8 +52,9 @@ class TestDatabase(unittest.TestCase): def test_get_key(self): - pk = self.db.get(self.address_hex, 'foo') - logg.info('pk {}'.format(pk.hex())) + self.db.get(self.address_hex, 'foo') + with self.assertRaises(InvalidToken): + self.db.get(self.address_hex, 'bar') if __name__ == '__main__':