def test_do_not_throw_error_for_empty_key_dict(self): pgp = openpgp.OpenPGPScheme(self._soledad, gpgbinary=self.gpg_binary_path) rf = RandomRefreshPublicKey(pgp, self._key_manager()) pgp.get_all_keys = Mock(return_value=defer.succeed([])) random_address = yield rf._get_random_key() self.assertTrue(random_address is None)
def test_get_random_address(self): pgp = openpgp.OpenPGPScheme(self._soledad, gpgbinary=self.gpg_binary_path) rf = RandomRefreshPublicKey(pgp, self._key_manager()) key = OpenPGPKey(address='*****@*****.**') key_another = OpenPGPKey(address='*****@*****.**') pgp.get_all_keys = Mock(return_value=defer.succeed([key, key_another])) random_key = yield rf._get_random_key() self.assertTrue(random_key.address == key.address or random_key.address == key_another.address)
def test_put_new_key_in_local_storage(self): pgp = openpgp.OpenPGPScheme(self._soledad, gpgbinary=self.gpg_binary_path) km = self._key_manager() rf = RandomRefreshPublicKey(pgp, km) rf._get_random_key = Mock( return_value=defer.succeed(OpenPGPKey( fingerprint=KEY_FINGERPRINT))) km._nicknym.fetch_key_with_fingerprint = Mock( return_value=defer.succeed(PUBLIC_KEY_2)) yield rf.maybe_refresh_key()
def test_log_error_if_fetch_by_fingerprint_returns_wrong_key(self): pgp = openpgp.OpenPGPScheme(self._soledad, gpgbinary=self.gpg_binary_path) km = self._key_manager() with patch.object(Logger, 'error') as mock_logger_error: rf = RandomRefreshPublicKey(pgp, km) rf._get_random_key = \ Mock(return_value=defer.succeed(OpenPGPKey( fingerprint=KEY_FINGERPRINT))) km._nicknym.fetch_key_with_fingerprint = \ Mock(return_value=defer.succeed(PUBLIC_KEY_2)) yield rf.maybe_refresh_key() mock_logger_error.assert_called_with( ERROR_UNEQUAL_FINGERPRINTS % (KEY_FINGERPRINT, KEY_FINGERPRINT_2))