Esempio n. 1
0
    def test_decrypt__key_changed__error(self):

        self.mocker.patch(
            'szczypiorek.crypto.get_encryption_key').return_value = ('secret',
                                                                     'hash0')

        with pytest.raises(DecryptionError) as e:
            decrypt(write_encrypted('what is it', 'hash1'))

        assert e.value.args[0] == normalize("""
            It seems that different key was used for encryption and decryption.
        """)
Esempio n. 2
0
    def test_decrypt__broken_gpg__error(self):

        self.mocker.patch(
            'szczypiorek.crypto.get_encryption_key').return_value = ('secret',
                                                                     'hash')

        with pytest.raises(DecryptionError) as e:
            decrypt(write_encrypted('what is it', 'hash'))

        assert e.value.args[0] == normalize("""
            Something went wrong while attempting to decrypt. The big chance
            is that you've used broken encryption key.

            Therefore if you see this message it means that you're trying to
            do something bad. Stop doing that.
        """)
Esempio n. 3
0
    def test_decrypt__wrong_passphrase__error(self):

        self.mocker.patch(
            'szczypiorek.crypto.get_encryption_key').side_effect = [
                ('secret.0', 'hash'), ('secret.1', 'hash')
            ]

        encrypted = encrypt('what is it')

        with pytest.raises(DecryptionError) as e:
            decrypt(encrypted)

        assert e.value.args[0] == normalize("""
            Something went wrong while attempting to decrypt. The big chance
            is that you've used broken encryption key.

            Therefore if you see this message it means that you're trying to
            do something bad. Stop doing that.
        """)
Esempio n. 4
0
    def test_encrypt__encryption_key_exists__success(self):

        create_encryption_key_if_not_exist()

        encrypted = encrypt('hello world').strip()

        content = read_encrypted(encrypted)
        assert content['key_hash'] is not None
        assert content['gpg'].startswith('-----BEGIN PGP MESSAGE-----')
        assert content['gpg'].endswith('-----END PGP MESSAGE-----')
        assert decrypt(encrypted) == 'hello world'
        assert len(
            self.root_dir.join('.szczypiorek_encryption_key').read()) > 128
Esempio n. 5
0
    def test_encrypt__empty_content__success(self):

        self.mocker.patch(
            'szczypiorek.crypto.get_encryption_key').return_value = ('secret',
                                                                     'hash')

        encrypted = encrypt('').strip()

        content = read_encrypted(encrypted)
        assert content['key_hash'] == 'hash'
        assert content['gpg'].startswith('-----BEGIN PGP MESSAGE-----')
        assert content['gpg'].endswith('-----END PGP MESSAGE-----')
        assert decrypt(encrypted) == ''
Esempio n. 6
0
    def test_encrypt__no_encryption_key__success(self):

        assert self.root_dir.join(
            '.szczypiorek_encryption_key').exists() is False

        encrypted = encrypt('hello world').strip()

        content = read_encrypted(encrypted)
        assert content['key_hash'] is not None
        assert content['gpg'].startswith('-----BEGIN PGP MESSAGE-----')
        assert content['gpg'].endswith('-----END PGP MESSAGE-----')
        assert decrypt(encrypted) == 'hello world'
        assert self.root_dir.join(
            '.szczypiorek_encryption_key').exists() is True
Esempio n. 7
0
    def test_decrypt__empty_gpg_content__success(self):

        assert decrypt(encrypt('')) == ''