Example #1
0
def test_crypt_make_key_input_handles_unicode_encode_error(mocker):
    passphrase = 's3cr3t'

    class ExpectedUnicodeException(UnicodeEncodeError):
        def __init__(self):
            pass

    side_effect = [ExpectedUnicodeException, KEY_INPUT.format(passphrase)]
    mock_key_input = mocker.patch('passpie.crypt.KEY_INPUT',
                                  new=mocker.MagicMock())
    mock_key_input.format.side_effect = side_effect

    key_input = make_key_input(passphrase)

    assert key_input == KEY_INPUT.format(passphrase)
Example #2
0
def test_crypt_make_key_input_handles_unicode_encode_error(mocker):
    passphrase = 's3cr3t'
    class ExpectedUnicodeException(UnicodeEncodeError):
        def __init__(self):
            pass

    side_effect = [
        ExpectedUnicodeException,
        KEY_INPUT.format(passphrase)
    ]
    mock_key_input = mocker.patch('passpie.crypt.KEY_INPUT', new=mocker.MagicMock())
    mock_key_input.format.side_effect = side_effect

    key_input = make_key_input(passphrase)

    assert key_input == KEY_INPUT.format(passphrase)
Example #3
0
    def test_create_keys_export_public_and_secret_keys_into_keyspath(self):
        cryptor = Cryptor("path/to/database")
        passphrase = "passphrase"
        self.patch("passpie.crypt.os.path.exists",
                   self.Mock(return_value=False))
        keys = self.Mock(fingerprint="HEX")
        cryptor._gpg.gen_key.return_value = keys
        mock_open = self.patch("passpie.crypt.mkdir_open",
                               self.mock_open(), create=True)
        mock_keyfile = self.Mock()
        mock_open().__enter__.return_value = mock_keyfile

        cryptor.create_keys(passphrase)

        key_input = KEY_INPUT.format(passphrase)
        cryptor._gpg.gen_key.assert_called_once_with(key_input)
        cryptor._gpg.export_keys.assert_any_call(keys.fingerprint)

        pubkey = cryptor._gpg.export_keys(keys.fingerprint)
        seckey = cryptor._gpg.export_keys(keys.fingerprint, secret=True)
        cryptor._gpg.export_keys.assert_any_call(keys.fingerprint, secret=True)
        mock_keyfile.write.called_once_with(pubkey + seckey)
Example #4
0
    def test_create_keys_export_public_and_secret_keys_into_keyspath(self):
        cryptor = Cryptor("path/to/database")
        passphrase = "passphrase"
        self.patch("passpie.crypt.os.path.exists",
                   self.Mock(return_value=False))
        keys = self.Mock(fingerprint="HEX")
        cryptor._gpg.gen_key.return_value = keys
        mock_open = self.patch("passpie.crypt.mkdir_open",
                               self.mock_open(),
                               create=True)
        mock_keyfile = self.Mock()
        mock_open().__enter__.return_value = mock_keyfile

        cryptor.create_keys(passphrase)

        key_input = KEY_INPUT.format(passphrase)
        cryptor._gpg.gen_key.assert_called_once_with(key_input)
        cryptor._gpg.export_keys.assert_any_call(keys.fingerprint)

        pubkey = cryptor._gpg.export_keys(keys.fingerprint)
        seckey = cryptor._gpg.export_keys(keys.fingerprint, secret=True)
        cryptor._gpg.export_keys.assert_any_call(keys.fingerprint, secret=True)
        mock_keyfile.write.called_once_with(pubkey + seckey)
Example #5
0
def test_crypt_make_key_input_handles_unicode_encode_error_handling(mocker):
    passphrase = 'passphrase'
    key_length = '2064'
    key_input = KEY_INPUT.format(key_length, passphrase)
    assert key_input == make_key_input(passphrase, key_length)
Example #6
0
    def test_key_input_format_with_unicode_characters(self):
        unicode_string = 'áçéèúü'

        self.assertIsNotNone(KEY_INPUT.format(unicode_string))
Example #7
0
    def test_key_input_format_with_unicode_characters(self):
        unicode_string = 'áçéèúü'

        self.assertIsNotNone(KEY_INPUT.format(unicode_string))
Example #8
0
def test_crypt_make_key_input_handles_unicode_encode_error_handling(mocker):
    passphrase = 'passphrase'
    key_length = '2064'
    key_input = KEY_INPUT.format(key_length, passphrase)
    assert key_input == make_key_input(passphrase, key_length)