def cleanup_if_exists(self, conjur_url: str): """ For each credential attribute, check if exists for the conjur_url identifier and delete if exists """ for attr in KEYSTORE_ATTRIBUTES: try: if KeystoreWrapper.get_password(conjur_url, attr) is not None: KeystoreWrapper.delete_password(conjur_url, attr) # Catches when credentials do not exist in the keyring. If the key does not exist, # the user has already logged out. we still try to remove other leftovers except Exception: # pylint: disable=broad-except logging.debug(f"Cleanup failed for key '{attr}' from the " f"'{self.keyring_name} credential store.' " f"\n{traceback.format_exc()}")
def remove_credentials(self, conjur_url: str): """ Method for removing user credentials in the system's keyring """ logging.debug("Attempting to remove credentials from " f"the '{self.keyring_name}' credential store...") for attr in KEYSTORE_ATTRIBUTES: try: KeystoreWrapper.delete_password(conjur_url, attr) # Catches when credentials do not exist in the keyring. If the key does not exist, # the user has already logged out. we still try to remove other leftovers except KeyringWrapperDeletionError: logging.debug( f"Unable to delete key '{attr}' from the " f"'{self.keyring_name}' credential store. Key may not exist." f"\n{traceback.format_exc()}") logging.debug("Successfully removed credentials from the " f"'{self.keyring_name}' credential store")
def test_get_delete_password_use_proper_log_level(self, mock): logging.getLogger('keyring').setLevel(logging.DEBUG) KeystoreWrapper.delete_password("", "") self.assertEquals(logging.getLogger('keyring').level, logging.INFO)
def test_delete_password_raises_expected_exceptions(self, mock_delete_password): with self.assertRaises(KeyringWrapperDeletionError): KeystoreWrapper.delete_password(TEST_HOSTNAME, "some_key")
def test_delete_password_raises_keyring_error(self, mock_delete_password): with self.assertRaises(KeyringWrapperGeneralError): KeystoreWrapper.delete_password(TEST_HOSTNAME, "some_key")
def test_delete_password_calls_keyring_delete_password(self, mock_keyring): KeystoreWrapper.delete_password(TEST_HOSTNAME, "key") mock_keyring.assert_called_once_with(TEST_HOSTNAME, "key")