Exemple #1
0
    def test_import_keys_opens_keys_path_and_import_to_gpg(self):
        to_patch = 'passpie.crypt.open'
        mock_open = self.patch(to_patch, self.mock_open(), create=True)
        mock_open().read.return_value = "key data"

        cryptor = Cryptor("path/to/database")
        cryptor._import_keys()
        cryptor._gpg.import_keys.assert_called_once_with(mock_open().read())
Exemple #2
0
    def test_import_keys_opens_keys_path_and_import_to_gpg(self):
        to_patch = 'passpie.crypt.open'
        mock_open = self.patch(to_patch, self.mock_open(), create=True)
        mock_open().read.return_value = "key data"

        cryptor = Cryptor("path/to/database")
        cryptor._import_keys()
        cryptor._gpg.import_keys.assert_called_once_with(
            mock_open().read()
        )
Exemple #3
0
    def test_import_keys_raises_file_not_found_when_keys_not_found(self):
        to_patch = 'passpie.crypt.open'
        mock_open = self.patch(to_patch, self.mock_open(), create=True)
        cryptor = Cryptor("path/to/database")

        mock_open.side_effect = OSError(2, "File Not Found")
        with self.assertRaises(FileNotFoundError):
            cryptor._import_keys()

        mock_open.side_effect = OSError(17, "File exists")
        try:
            cryptor._import_keys()
        except Exception as exc:
            self.assertNotIsInstance(exc, FileNotFoundError)
Exemple #4
0
    def test_import_keys_raises_file_not_found_when_keys_not_found(self):
        to_patch = 'passpie.crypt.open'
        mock_open = self.patch(to_patch, self.mock_open(), create=True)
        cryptor = Cryptor("path/to/database")

        mock_open.side_effect = OSError(2, "File Not Found")
        with self.assertRaises(FileNotFoundError):
            cryptor._import_keys()

        mock_open.side_effect = OSError(17, "File exists")
        try:
            cryptor._import_keys()
        except Exception as exc:
            self.assertNotIsInstance(exc, FileNotFoundError)
Exemple #5
0
    def test_encrypt_returns_gpg_encrypted_data(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        encrypted = "encrypted data"
        cryptor._gpg.encrypt.return_value = self.Mock(data=encrypted)

        self.assertEqual(cryptor.encrypt("data"), str(encrypted))
Exemple #6
0
    def test_decrypt_returns_gpg_decrypted_data(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        decrypted = "decrypted data"
        cryptor._gpg.decrypt.return_value = self.Mock(data=decrypted)

        self.assertEqual(cryptor.decrypt("data", "passphrase"), str(decrypted))
Exemple #7
0
    def test_encrypt_returns_gpg_encrypted_data(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        encrypted = "encrypted data"
        cryptor._gpg.encrypt.return_value = encrypted

        self.assertEqual(cryptor.encrypt("data"), str(encrypted))
Exemple #8
0
    def test_decrypt_returns_gpg_decrypted_data(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        decrypted = "decrypted data"
        cryptor._gpg.decrypt.return_value = decrypted

        self.assertEqual(cryptor.decrypt("data", "passphrase"), str(decrypted))
Exemple #9
0
    def test_passprase_check_with_ensure_raises_value_error_with_ensure(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        cryptor._gpg.sign.return_value = None
        passphrase = "passphrase"

        with self.assertRaises(ValueError):
            cryptor.check(passphrase, ensure=True)
Exemple #10
0
    def test_passprase_check_with_ensure_raises_value_error_with_ensure(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        cryptor._gpg.sign.return_value = None
        passphrase = "passphrase"

        with self.assertRaises(ValueError):
            cryptor.check(passphrase, ensure=True)
Exemple #11
0
    def test_passphrase_check_raises_value_error_when_bad_passphrase(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        passphrase = "passphrase"
        result = cryptor.check(passphrase)

        self.assertTrue(result)
        self.assertTrue(cryptor._gpg.sign.called)
        cryptor._gpg.sign.assert_called_once_with(
            "testing", default_key=cryptor.current_key, passphrase=passphrase)
Exemple #12
0
    def test_passphrase_check_raises_value_error_when_bad_passphrase(self):
        cryptor = Cryptor("path/to/database")
        cryptor._import_keys = self.Mock()
        passphrase = "passphrase"
        result = cryptor.check(passphrase)

        self.assertTrue(result)
        self.assertTrue(cryptor._gpg.sign.called)
        cryptor._gpg.sign.assert_called_once_with(
            "testing",
            default_key=cryptor.current_key,
            passphrase=passphrase
        )