[anaconda-storage-branch] Added crypto.py unittest; Updated devicelibs tests baseclass.py and lvm.py

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



baseclass.py needed some imports to work properly.
Updated the test for getMaxLVSize() in lvm.py to not pass PE size as argument.
---
 tests/storage/devicelibs/baseclass.py |    4 +
 tests/storage/devicelibs/crypto.py    |  123 +++++++++++++++++++++++++++++++++
 tests/storage/devicelibs/lvm.py       |    3 +-
 3 files changed, 128 insertions(+), 2 deletions(-)
 create mode 100644 tests/storage/devicelibs/crypto.py

diff --git a/tests/storage/devicelibs/baseclass.py b/tests/storage/devicelibs/baseclass.py
index d1264f5..efc9c80 100644
--- a/tests/storage/devicelibs/baseclass.py
+++ b/tests/storage/devicelibs/baseclass.py
@@ -2,6 +2,10 @@ import unittest
 import os
 import subprocess
 
+# need to import these first before doing anything
+import anaconda_log
+import upgrade
+
 class TestDevicelibs(unittest.TestCase):
 
     _LOOP_DEVICES = (("/dev/loop0", "/tmp/test-virtdev0"),
diff --git a/tests/storage/devicelibs/crypto.py b/tests/storage/devicelibs/crypto.py
new file mode 100644
index 0000000..dfe89b3
--- /dev/null
+++ b/tests/storage/devicelibs/crypto.py
@@ -0,0 +1,123 @@
+import baseclass
+import unittest
+import storage.devicelibs.crypto as crypto
+
+import tempfile
+import os
+
+class TestCrypto(baseclass.TestDevicelibs):
+
+    def runTest(self):
+        ##
+        ## is_luks
+        ##
+        # pass
+        self.assertEqual(crypto.is_luks(self._LOOP_DEV0), -22)
+        self.assertEqual(crypto.is_luks("/not/existing/device"), -22)
+
+        ##
+        ## luks_format
+        ##
+        # pass
+        self.assertEqual(crypto.luks_format(self._LOOP_DEV0, passphrase="secret", cipher="aes-cbc-essiv:sha256", key_size=256), None)
+
+        # make a key file
+        handle, keyfile = tempfile.mkstemp(prefix="key", text=False)
+        os.write(handle, "nobodyknows")
+        os.close(handle)
+
+        # format with key file
+        self.assertEqual(crypto.luks_format(self._LOOP_DEV1, key_file=keyfile, cipher="aes-cbc-essiv:sha256", key_size=256), None)
+
+        # fail
+        self.assertRaises(crypto.CryptoError, crypto.luks_format, "/not/existing/device", passphrase="secret", cipher="aes-cbc-essiv:sha256", key_size=256)
+        # no passhprase or key file
+        self.assertRaises(ValueError, crypto.luks_format, self._LOOP_DEV1, cipher="aes-cbc-essiv:sha256", key_size=256)
+
+        ##
+        ## is_luks
+        ##
+        # pass
+        self.assertEqual(crypto.is_luks(self._LOOP_DEV0), 0)    # 0 = is luks
+        self.assertEqual(crypto.is_luks(self._LOOP_DEV1), 0)
+
+        ##
+        ## luks_add_key
+        ##
+        # pass
+        self.assertEqual(crypto.luks_add_key(self._LOOP_DEV0, new_passphrase="another-secret", passphrase="secret"), None)
+
+        # make another key file
+        handle, new_keyfile = tempfile.mkstemp(prefix="key", text=False)
+        os.write(handle, "area51")
+        os.close(handle)
+
+        # add new key file
+        self.assertEqual(crypto.luks_add_key(self._LOOP_DEV1, new_key_file=new_keyfile, key_file=keyfile), None)
+
+        # fail
+        self.assertRaises(RuntimeError, crypto.luks_add_key, self._LOOP_DEV0, new_passphrase="another-secret", passphrase="wrong-passphrase")
+
+        ##
+        ## luks_remove_key
+        ##
+        # fail
+        self.assertRaises(RuntimeError, crypto.luks_remove_key, self._LOOP_DEV0, del_passphrase="another-secret", passphrase="wrong-pasphrase")
+
+        # pass
+        self.assertEqual(crypto.luks_remove_key(self._LOOP_DEV0, del_passphrase="another-secret", passphrase="secret"), None)
+
+        # remove key file
+        self.assertEqual(crypto.luks_remove_key(self._LOOP_DEV1, del_key_file=new_keyfile, key_file=keyfile), None)
+
+        ##
+        ## luks_open
+        ##
+        # pass
+        self.assertEqual(crypto.luks_open(self._LOOP_DEV0, "crypted", passphrase="secret"), None)
+        self.assertEqual(crypto.luks_open(self._LOOP_DEV1, "encrypted", key_file=keyfile), None)
+
+        # fail
+        self.assertRaises(crypto.CryptoError, crypto.luks_open, "/not/existing/device", "another-crypted", passphrase="secret")
+        self.assertRaises(crypto.CryptoError, crypto.luks_open, "/not/existing/device", "another-crypted", key_file=keyfile)
+        # no passhprase or key file
+        self.assertRaises(ValueError, crypto.luks_open, self._LOOP_DEV1, "another-crypted")
+
+        ##
+        ## luks_status
+        ##
+        # pass
+        self.assertEqual(crypto.luks_status("crypted"), True)
+        self.assertEqual(crypto.luks_status("encrypted"), True)
+        self.assertEqual(crypto.luks_status("another-crypted"), False)
+
+        ##
+        ## luks_uuid
+        ##
+        # pass
+        uuid = crypto.luks_uuid(self._LOOP_DEV0)
+        self.assertEqual(crypto.luks_uuid(self._LOOP_DEV0), uuid)
+        uuid = crypto.luks_uuid(self._LOOP_DEV1)
+        self.assertEqual(crypto.luks_uuid(self._LOOP_DEV1), uuid)
+
+        ##
+        ## luks_close
+        ##
+        # pass
+        self.assertEqual(crypto.luks_close("crypted"), None)
+        self.assertEqual(crypto.luks_close("encrypted"), None)
+
+        # fail
+        self.assertRaises(crypto.CryptoError, crypto.luks_close, "wrong-name")
+        # already closed
+        self.assertRaises(crypto.CryptoError, crypto.luks_close, "crypted")
+        self.assertRaises(crypto.CryptoError, crypto.luks_close, "encrypted")
+
+        # cleanup
+        os.unlink(keyfile)
+        os.unlink(new_keyfile)
+
+
+if __name__ == "__main__":
+    suite = unittest.TestLoader().loadTestsFromTestCase(TestCrypto)
+    unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/tests/storage/devicelibs/lvm.py b/tests/storage/devicelibs/lvm.py
index 210ad9d..62c52d1 100644
--- a/tests/storage/devicelibs/lvm.py
+++ b/tests/storage/devicelibs/lvm.py
@@ -202,8 +202,7 @@ class TestLVM(baseclass.TestDevicelibs):
 
     #def testGetMaxLVSize(self):
         # pass
-        # why do we specify the PE ? not needed...
-        self.assertEqual(lvm.getMaxLVSize(4), 16*1024**2)
+        self.assertEqual(lvm.getMaxLVSize(), 16*1024**2)
 
     #def testSafeLVMName(self):
         # pass
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux