Browse Source

Properly write and read database is old and new format

oz123 10 years ago
parent
commit
09614ea2d2

+ 1 - 1
pwman/data/convertdb.py

@@ -196,7 +196,7 @@ class DBConverter(object):
         cur.execute("SELECT DBVERSION FROM DBVERSION")
         cur.execute("SELECT DBVERSION FROM DBVERSION")
         row = cur.fetchone()
         row = cur.fetchone()
         if not row:
         if not row:
-            return "0.3"  # pragma: no cover
+            return "0.3"
         else:
         else:
             return row[0]
             return row[0]
 
 

+ 2 - 1
pwman/tests/crypto_tests.py

@@ -32,7 +32,8 @@ class CryptoTest(unittest.TestCase):
         self.assertTrue(True)
         self.assertTrue(True)
 
 
     def test_get(self):
     def test_get(self):
-        old_engine = CryptoEngine.get()
+        CryptoEngine._instance_new = None
+        old_engine = CryptoEngine.get(0.4)
         self.assertIsInstance(old_engine, CryptoEngineOld)
         self.assertIsInstance(old_engine, CryptoEngineOld)
         CryptoEngine._instance = None
         CryptoEngine._instance = None
         new_engine = CryptoEngine.get(dbver=0.5)
         new_engine = CryptoEngine.get(dbver=0.5)

+ 0 - 3
pwman/tests/db_tests.py

@@ -66,9 +66,6 @@ def node_factory(username, password, url, notes, tags=None):
 
 
     return node
     return node
 
 
-# TODO: fix hard coded db versions! 0.4 should be replaced with
-#  from pwman.data.database import __DB_FORMAT__
-
 _saveconfig = False
 _saveconfig = False
 
 
 PwmanCliNew, OSX = get_ui_platform(sys.platform)
 PwmanCliNew, OSX = get_ui_platform(sys.platform)

+ 5 - 5
pwman/tests/test_converter.py

@@ -378,6 +378,8 @@ class CreateTestDataBases(object):
             enc1.set_cryptedkey(key)
             enc1.set_cryptedkey(key)
 
 
         self.add_nodes_to_db1()
         self.add_nodes_to_db1()
+        CryptoEngine._instance = None
+
         self.db2._open()
         self.db2._open()
         enc2 = CryptoEngine.get(dbver=0.5)
         enc2 = CryptoEngine.get(dbver=0.5)
         enc2.set_callback(DummyCallback4())
         enc2.set_callback(DummyCallback4())
@@ -406,10 +408,8 @@ if __name__ == '__main__':
     tester.run()
     tester.run()
     # afther the test databases are created, invoking
     # afther the test databases are created, invoking
     # pwman3 -d konverter-v0.5.db
     # pwman3 -d konverter-v0.5.db
-    # initiates an OldCrypto instance, which can not
-    # decrypt the database, which is expected!
-    # However, this database has the false database version
-    # select DBVERSION from DBVERSION
-    # returns -> 0.4, which is wrong. This should be 0.5
     assert "0.4" == DBConverter.detect_db_version('konverter-v0.4.db')
     assert "0.4" == DBConverter.detect_db_version('konverter-v0.4.db')
     assert "0.5" == DBConverter.detect_db_version('konverter-v0.5.db')
     assert "0.5" == DBConverter.detect_db_version('konverter-v0.5.db')
+
+    # python scripts/pwman3 -d konverter-v0.5.db -e AES,
+    # works !