Pārlūkot izejas kodu

Add tests for changing the database password

oz123 11 gadi atpakaļ
vecāks
revīzija
b04517a692
4 mainītis faili ar 33 papildinājumiem un 6 dzēšanām
  1. 2 1
      pwman/data/database.py
  2. 26 4
      pwman/tests/db_tests.py
  3. 2 1
      pwman/ui/ocli.py
  4. 3 0
      pwman/ui/tools.py

+ 2 - 1
pwman/data/database.py

@@ -65,7 +65,8 @@ class Database(object):
         """
         enc = CryptoEngine.get()
         newkey = enc.changepassword()
-        return self.savekey(newkey)
+        return newkey
+        #  self.savekey(newkey)
 
     def listtags(self, all=False):
         pass  # pragma: no cover

+ 26 - 4
pwman/tests/db_tests.py

@@ -7,20 +7,36 @@ import sys
 
 class DummyCallback(Callback):
 
+    def getsecret(self, question):
+        return str(123) + str(45)
+
+    def getnewsecret(self, question):
+        return str(123) + str(45)
+
+
+class DummyCallback2(Callback):
+
     def getinput(self, question):
-        return '12345'
+        return 'newsecret'
 
     def getsecret(self, question):
-        return '12345'
+        return 'wrong'
 
+    def getnewsecret(self, question):
+        return 'newsecret'
 
-class DummyCallback2(Callback):
+
+class DummyCallback3(Callback):
 
     def getinput(self, question):
         return 'newsecret'
 
     def getsecret(self, question):
+        return '12345'
+
+    def getnewsecret(self, question):
         return 'newsecret'
+
 if 'darwin' in sys.platform:  # pragma: no cover
     from pwman.ui.mac import PwmanCliMacNew as PwmanCliNew
     OSX = True
@@ -124,10 +140,16 @@ class DBTests(unittest.TestCase):
         self.assertEqual(2, len(got_tags))
 
     def test_change_pass(self):
-        self.tester.cli.callback = DummyCallback2
+        enc = CryptoEngine.get()
+        enc._callback = DummyCallback2()
         self.assertRaises(CryptoBadKeyException,
                           self.tester.cli._db.changepassword)
 
+    def test_db_change_pass(self):
+        enc = CryptoEngine.get()
+        enc._callback = DummyCallback3()
+        self.tester.cli._db.changepassword()
+
 
 class CLITests(unittest.TestCase):
     """

+ 2 - 1
pwman/ui/ocli.py

@@ -473,7 +473,8 @@ class PwmanCliOld(cmd.Cmd, HelpUI, BaseUI):
 
     def do_passwd(self, args):
         try:
-            self._db.changepassword()
+            key = self._db.changepassword()
+            self._db._save(key)
         except Exception, e:
             self.error(e)
 

+ 3 - 0
pwman/ui/tools.py

@@ -400,3 +400,6 @@ class CLICallback(Callback):
 
     def getsecret(self, question):
         return getpass.getpass(question + ":")
+
+    def getnewsecret(self, question):
+        return getpass.getpass(question + ":")