[prev in list] [next in list] [prev in thread] [next in thread] 

List:       virt-who-devel
Subject:    [virt-who] fix password test
From:       Radek Novacek <rnovacek () fedoraproject ! org>
Date:       2014-07-03 12:17:12
Message-ID: 20140703121712.83A10616D7 () fedorahosted ! org
[Download RAW message or body]

commit 0beeb12570a992daacd57fe0067869462a9d3e8a
Author: Radek Novacek <rnovacek@redhat.com>
Date:   Tue Jul 1 10:57:21 2014 +0200

    fix password test
    
    Mock checking if it run as root

 password/__init__.py   |    6 +++++-
 tests/test_password.py |    3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/password/__init__.py b/password/__init__.py
index 1c5e867..7e7cf98 100644
--- a/password/__init__.py
+++ b/password/__init__.py
@@ -85,12 +85,16 @@ class Password(object):
             raise InvalidKeyFile(str(e))
 
     @classmethod
+    def _can_write(cls):
+        return os.getuid() == 0
+
+    @classmethod
     def _read_or_generate_key_iv(cls):
         try:
             return cls._read_key_iv()
         except InvalidKeyFile:
             pass
-        if os.getuid() != 0:
+        if not cls._can_write():
             raise UnwrittableKeyFile("Only root can write keyfile")
         key = hexlify(cls._generate_key())
         iv = hexlify(cls._generate_key())
diff --git a/tests/test_password.py b/tests/test_password.py
index 177b18e..7396e80 100644
--- a/tests/test_password.py
+++ b/tests/test_password.py
@@ -21,6 +21,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  \
02110-1301, USA.  import os
 import tempfile
 from binascii import hexlify, unhexlify
+from mock import MagicMock
 
 from base import unittest
 
@@ -51,9 +52,9 @@ class TestPassword(unittest.TestCase):
         self.addCleanup(os.unlink, filename)
         Password.KEYFILE = filename
         pwd = "Test password"
+        Password._can_write = MagicMock(retun_value=True)
         encrypted = Password.encrypt(pwd)
         self.assertEqual(pwd, Password.decrypt(encrypted))
-        self.assertEqual(os)
 
     def testPad(self):
         self.assertEqual(hexlify(Password._pad(unhexlify("00010203040506070809"))), \
"00010203040506070809060606060606") _______________________________________________
virt-who-devel mailing list
virt-who-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/virt-who-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic