Esempio n. 1
0
class FileCrypterTest(unittest.TestCase):

    test_file_path = os.path.realpath(__file__)

    def setUp(self):
        super(FileCrypterTest, self).setUp()

        self.file_crypter = FileCrypter()

    def test_can_encrypt_and_decrypt_file(self):
        """fab.tests.security.file_crypter_test  Can encrypt and decrypt a specified file"""

        password = "******"
        self.file_crypter.encrypt(password, self.test_file_path)
        self.file_crypter.decrypt(password, self.test_file_path + '.enc', self.test_file_path + '.dec')

        self.assertEqual(self._file_contents(self.test_file_path), self._file_contents(self.test_file_path + '.dec'))

    def _file_contents(self, file_path):
        with open(file_path, 'r') as a_file:
            return a_file.readlines()

    def tearDown(self):
        self._delete_file(self.test_file_path + '.enc')
        self._delete_file(self.test_file_path + '.dec')

    def _delete_file(self, file_path):
        if os.path.exists(file_path):
            os.remove(file_path)
Esempio n. 2
0
class FileCrypterTest(unittest.TestCase):

    test_file_path = os.path.realpath(__file__)

    def setUp(self):
        super(FileCrypterTest, self).setUp()

        self.file_crypter = FileCrypter()

    def test_can_encrypt_and_decrypt_file(self):
        """fab.tests.security.file_crypter_test  Can encrypt and decrypt a specified file"""

        password = "******"
        self.file_crypter.encrypt(password, self.test_file_path)
        self.file_crypter.decrypt(password, self.test_file_path + '.enc',
                                  self.test_file_path + '.dec')

        self.assertEqual(self._file_contents(self.test_file_path),
                         self._file_contents(self.test_file_path + '.dec'))

    def _file_contents(self, file_path):
        with open(file_path, 'r') as a_file:
            return a_file.readlines()

    def tearDown(self):
        self._delete_file(self.test_file_path + '.enc')
        self._delete_file(self.test_file_path + '.dec')

    def _delete_file(self, file_path):
        if os.path.exists(file_path):
            os.remove(file_path)
Esempio n. 3
0
    def setUp(self):
        super(FileCrypterTest, self).setUp()

        self.file_crypter = FileCrypter()
Esempio n. 4
0
    def setUp(self):
        super(FileCrypterTest, self).setUp()

        self.file_crypter = FileCrypter()