def setup_external_auth_ipa(**data): """Sets up the appliance for an external authentication with IPA. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ ssh = SSHClient() ensure_browser_open() login_admin() if data["ipaserver"] not in get_ntp_servers(): set_ntp_servers(data["ipaserver"]) sleep(120) auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False)) auth.setup() logout() creds = credentials.get(data.pop("credentials"), {}) data.update(**creds) rc, out = ssh.run_command( "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} " "--ipaprincipal {principal} --ipapassword {password}".format(**data)) assert rc == 0, out assert "failed" not in out.lower( ), "External auth setup failed:\n{}".format(out) login_admin()
def test_login(): """ Tests that the appliance can be logged into and shows dashboard page. """ pytest.sel.get(pytest.sel.base_url()) login.login_admin() assert dashboard.page.is_displayed(), "Could not determine if logged in" login.logout() assert login.page.is_displayed()
def reset_password(): login.update_password(username, current_password, password) assert login.logged_in(), "password reset failed" login.logout() login.login(username, password) assert login.logged_in(), "password reset failed" login.logout()
def test_user_change_password(request): user = ac.User( name="user {}".format(fauxfactory.gen_alphanumeric()), credential=Credential( principal="user_principal_{}".format(fauxfactory.gen_alphanumeric()), secret="very_secret", verify_secret="very_secret" ), email="*****@*****.**", group=usergrp, ) user.create() request.addfinalizer(user.delete) request.addfinalizer(login.login_admin) login.logout() assert not login.logged_in() login.login(user.credential.principal, user.credential.secret) assert login.current_full_name() == user.name login.login_admin() with update(user): user.credential = Credential( principal=user.credential.principal, secret="another_very_secret", verify_secret="another_very_secret", ) login.logout() assert not login.logged_in() login.login(user.credential.principal, user.credential.secret) assert login.current_full_name() == user.name
def __enter__(self): if self._restore_user != self.appliance.user: from cfme.login import logout logger.info('Switching to new user: %s', self.credential.principal) self._restore_user = self.appliance.user logout() self.appliance.user = self
def __exit__(self, *args, **kwargs): if self._restore_user != store.user: from cfme.login import logout logger.info('Restoring to old user: %s', self._restore_user.credential.principal) logout() store.user = self._restore_user self._restore_user = None
def test_user_change_password(request): user = ac.User( name="user {}".format(fauxfactory.gen_alphanumeric()), credential=Credential(principal="user_principal_{}".format( fauxfactory.gen_alphanumeric()), secret="very_secret", verify_secret="very_secret"), email="*****@*****.**", group=usergrp, ) user.create() request.addfinalizer(user.delete) request.addfinalizer(login.login_admin) login.logout() assert not login.logged_in() login.login(user.credential.principal, user.credential.secret) assert login.current_full_name() == user.name login.login_admin() with update(user): user.credential = Credential( principal=user.credential.principal, secret="another_very_secret", verify_secret="another_very_secret", ) login.logout() assert not login.logged_in() login.login(user.credential.principal, user.credential.secret) assert login.current_full_name() == user.name
def __enter__(self): if self._restore_user != store.user: from cfme.login import logout logger.info('Switching to new user: %s', self.credential.principal) self._restore_user = store.user logout() store.user = self
def __enter__(self): if self._restore_user != store.user: from cfme.login import logout logger.info('Switching to new user: {}'.format(self.credential.principal)) self._restore_user = store.user logout() store.user = self
def __exit__(self, *args, **kwargs): if self._restore_user != self.appliance.user: from cfme.login import logout logger.info('Restoring to old user: %s', self._restore_user.credential.principal) logout() self.appliance.user = self._restore_user self._restore_user = None
def __exit__(self, *args, **kwargs): if self._restore_user != store.user: from cfme.login import logout logger.info('Restoring to old user: {}'.format(self._restore_user.credential.principal)) logout() store.user = self._restore_user self._restore_user = None
def setup_external_auth_openldap(**data): """Sets up the appliance for an external authentication with OpenLdap. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaddress'], } appliance_obj = appliance.IPAppliance() appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = appliance_obj.address appliance_fqdn = '{}.{}'.format(appliance_name, data['domain_name']) ldapserver_ssh = SSHClient(**connect_kwargs) # updating the /etc/hosts is a workaround due to the # https://bugzilla.redhat.com/show_bug.cgi?id=1360928 command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ldapserver_ssh.run_command(command) ldapserver_ssh.get_file(remote_file=data['cert_filepath'], local_path=conf_path.strpath) ldapserver_ssh.close() ensure_browser_open() login_admin() auth = ExternalAuthSetting(get_groups=data.pop("get_groups", True)) auth.setup() appliance_obj.configure_appliance_for_openldap_ext_auth(appliance_fqdn) logout()
def setup_external_auth_ipa(**data): """Sets up the appliance for an external authentication with IPA. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ ssh = SSHClient() ensure_browser_open() login_admin() if data["ipaserver"] not in get_ntp_servers(): set_ntp_servers(data["ipaserver"]) sleep(120) auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False)) auth.setup() logout() creds = credentials.get(data.pop("credentials"), {}) data.update(**creds) rc, out = ssh.run_command( "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} " "--ipaprincipal {principal} --ipapassword {password}".format(**data) ) assert rc == 0, out assert "failed" not in out.lower(), "External auth setup failed:\n{}".format(out) login_admin()
def setup_external_auth_openldap(**data): """Sets up the appliance for an external authentication with OpenLdap. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaddress'], } appliance_obj = appliance.IPAppliance() appliance_name = 'cfmeappliance{}'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = appliance_obj.address appliance_fqdn = '{}.{}'.format(appliance_name, data['domain_name']) with SSHClient(**connect_kwargs) as ldapserver_ssh: # updating the /etc/hosts is a workaround due to the # https://bugzilla.redhat.com/show_bug.cgi?id=1360928 command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ldapserver_ssh.run_command(command) ldapserver_ssh.get_file(remote_file=data['cert_filepath'], local_path=conf_path.strpath) ensure_browser_open() login_admin() auth = ExternalAuthSetting(get_groups=data.pop("get_groups", True)) auth.setup() appliance_obj.configure_appliance_for_openldap_ext_auth(appliance_fqdn) logout()
def test_login(method): """ Tests that the appliance can be logged into and shows dashboard page. """ pytest.sel.get(pytest.sel.base_url()) assert not pytest.sel.is_displayed(dashboard.page.user_dropdown) login.login_admin(submit_method=method) assert pytest.sel.is_displayed(dashboard.page.user_dropdown), "Could not determine if logged in" login.logout() assert login.page.is_displayed()
def disable_external_auth_ipa(): """Unconfigure external auth.""" ssh = SSHClient() ensure_browser_open() login_admin() auth = DatabaseAuthSetting() auth.update() assert ssh.run_command("appliance_console_cli --uninstall-ipa") appliance.IPAppliance().wait_for_web_ui() logout()
def disable_external_auth_ipa(): """Unconfigure external auth.""" with SSHClient() as ssh_client: ensure_browser_open() login_admin() auth = DatabaseAuthSetting() auth.update() assert ssh_client.run_command("appliance_console_cli --uninstall-ipa") appliance.IPAppliance().wait_for_web_ui() logout()
def check_logged_out(): if browser.browser() is not None: browser.quit() browser.ensure_browser_open() login.logout() yield if browser.browser() is not None: browser.quit() browser.ensure_browser_open() login.logout()
def test_start_page(request, setup_a_provider, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) visual.login_page = start_page login.logout() login.login_admin() level = re.split(r"\/", start_page) assert menu.is_page_active(level[0].strip(), level[1].strip()), "Landing Page Failed"
def test_start_page(request, setup_a_provider, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) visual.login_page = start_page login.logout() login.login_admin() match_args = landing_pages[start_page] assert match_location(**match_args), "Landing Page Failed"
def test_start_page(request, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) visual.login_page = start_page login.logout() login.login_admin() match_args = landing_pages[start_page] assert match_location(**match_args), "Landing Page Failed"
def test_default_aws_iam_group_roles(browser, group_name, group_data): """Basic default AWS_IAM group role RBAC test Validates expected menu and submenu names are present for default AWS IAM groups """ if group_name not in credentials: pytest.fail("No match in credentials file for group '%s'" % group_name) username = credentials[group_name + '_aws_iam']['username'] password = credentials[group_name + '_aws_iam']['password'] force_login_user(username, password) validate_menus(group_name, group_data) logout()
def really_logout(): """A convenience function logging out This function simply ensures that we are logged out and that a new browser is loaded ready for use. """ try: logout() except AttributeError: try: browser().quit() except AttributeError: ensure_browser_open()
def disable_external_auth_openldap(): auth = DatabaseAuthSetting() auth.update() sssd_conf = '/etc/sssd/sssd.conf' httpd_auth = '/etc/pam.d/httpd-auth' manageiq_remoteuser = '******' manageiq_ext_auth = '/etc/httpd/conf.d/manageiq-external-auth.conf' command = 'rm -rf {} && rm -rf {} && rm -rf {} && rm -rf {}'.format( sssd_conf, httpd_auth, manageiq_ext_auth, manageiq_remoteuser) ssh = SSHClient() assert ssh.run_command(command) ssh.run_command('systemctl restart evmserverd') appliance.IPAppliance().wait_for_web_ui() logout()
def disable_external_auth_openldap(): auth = DatabaseAuthSetting() auth.update() sssd_conf = '/etc/sssd/sssd.conf' httpd_auth = '/etc/pam.d/httpd-auth' manageiq_remoteuser = '******' manageiq_ext_auth = '/etc/httpd/conf.d/manageiq-external-auth.conf' command = 'rm -rf {} && rm -rf {} && rm -rf {} && rm -rf {}'.format( sssd_conf, httpd_auth, manageiq_ext_auth, manageiq_remoteuser) with SSHClient() as ssh_client: assert ssh_client.run_command(command) ssh_client.run_command('systemctl restart evmserverd') appliance.IPAppliance().wait_for_web_ui() logout()
def test_infra_start_page(request, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) if visual.login_page != start_page: visual.login_page = start_page login.logout() login.login_admin() steps = map(lambda x: x.strip(), start_page.split('/')) longer_steps = copy(steps) longer_steps.insert(0, None)
def test_start_page(request, setup_a_provider, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) if visual.login_page != start_page: visual.login_page = start_page login.logout() login.login_admin() steps = map(lambda x: x.strip(), start_page.split('/')) longer_steps = copy(steps) longer_steps.insert(0, None)
def test_start_page(request, setup_a_provider, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) visual.login_page = start_page login.logout() login.login_admin() level = re.split(r"\/", start_page) two_level = level[0].strip(), level[1].strip() three_level = None, level[0].strip(), level[1].strip() # BUG - https://bugzilla.redhat.com/show_bug.cgi?id=1331327 assert (menu.nav.is_page_active(*two_level) or menu.nav.is_page_active(*three_level)), \ "Landing Page Failed"
def test_start_page(request, setup_a_provider, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) visual.login_page = start_page login.logout() login.login_admin() level = re.split(r"\/", start_page) if current_version() >= 5.6: levels = (None, level[0].strip(), level[1].strip()) else: levels = (level[0].strip(), level[1].strip()) assert menu.nav.is_page_active(*levels), "Landing Page Failed"
def test_auth_configure(request, configure_auth, group, user, data): """This test checks whether different cfme auth modes are working correctly. authmodes tested as part of this test: ext_ipa, ext_openldap, miq_openldap e.g. test_auth[ext-ipa_create-group] Prerequisities: * ``cfme_data.yaml`` file Steps: * Make sure corresponding auth_modes data is updated to ``cfme_data.yaml`` * this test fetches the auth_modes from yaml and generates tests per auth_mode. """ request.addfinalizer(auth_finalizer) with user: login.login(user, submit_method='click_on_login') assert login.current_full_name() == data['fullname'] login.logout() login.login_admin() assert user.exists is True
def setup_external_auth_ipa(**data): """Sets up the appliance for an external authentication with IPA. Keywords: get_groups: Get User Groups from External Authentication (httpd). ipaserver: IPA server address. iparealm: Realm. credentials: Key of the credential in credentials.yaml """ connect_kwargs = { 'username': credentials['host_default']['username'], 'password': credentials['host_default']['password'], 'hostname': data['ipaserver'], } import fauxfactory appliance_name = 'cfmeappliance'.format(fauxfactory.gen_alpha(7).lower()) appliance_address = appliance.IPAppliance().address appliance_fqdn = '{}.{}'.format(appliance_name, data['iparealm'].lower()) ipaserver_ssh = SSHClient(**connect_kwargs) # updating the /etc/hosts is a workaround due to the # https://bugzilla.redhat.com/show_bug.cgi?id=1360928 command = 'echo "{}\t{}" >> /etc/hosts'.format(appliance_address, appliance_fqdn) ipaserver_ssh.run_command(command) ipaserver_ssh.close() ssh = SSHClient() rc, out = ssh.run_command('appliance_console_cli --host {}'.format(appliance_fqdn)) assert rc == 0, out ssh.run_command('echo "127.0.0.1\t{}" > /etc/hosts'.format(appliance_fqdn)) ensure_browser_open() login_admin() if data["ipaserver"] not in get_ntp_servers(): set_ntp_servers(data["ipaserver"]) sleep(120) auth = ExternalAuthSetting(get_groups=data.pop("get_groups", False)) auth.setup() logout() creds = credentials.get(data.pop("credentials"), {}) data.update(**creds) rc, out = ssh.run_command( "appliance_console_cli --ipaserver {ipaserver} --iparealm {iparealm} " "--ipaprincipal {principal} --ipapassword {password}".format(**data) ) assert rc == 0, out assert "failed" not in out.lower(), "External auth setup failed:\n{}".format(out) login_admin()
def test_set_default_host_filter(provider, request): """ Test for setting default filter for hosts.""" # Add cleanup finalizer def unset_default_host_filter(): navigate_to(Host, 'All') list_acc.select('Filters', 'ALL', by_title=False) pytest.sel.click(host.default_host_filter_btn) request.addfinalizer(unset_default_host_filter) navigate_to(Host, 'All') list_acc.select('Filters', 'Status / Running', by_title=False) pytest.sel.click(host.default_host_filter_btn) logout() login_admin() navigate_to(Host, 'All') assert list_acc.is_selected('Filters', 'Status / Running (Default)', by_title=False),\ 'Status / Running filter not set as default'
def test_set_default_host_filter(provider, request): """ Test for setting default filter for hosts.""" # Add cleanup finalizer def unset_default_host_filter(): pytest.sel.force_navigate('infrastructure_hosts') list_acc.select('Filters', 'ALL', by_title=False) pytest.sel.click(host.default_host_filter_btn) request.addfinalizer(unset_default_host_filter) pytest.sel.force_navigate('infrastructure_hosts') list_acc.select('Filters', 'Status / Running', by_title=False) pytest.sel.click(host.default_host_filter_btn) logout() login_admin() pytest.sel.force_navigate('infrastructure_hosts') assert (list_acc.is_selected('Filters', 'Status / Running (Default)', by_title=False), 'Status / Running filter not set as default')
def test_set_default_datastore_filter(provider, request): """ Test for setting default filter for datastores.""" # Add cleanup finalizer def unset_default_datastore_filter(): navigate_to(Datastore, 'All') list_acc.select('Filters', 'ALL', by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) request.addfinalizer(unset_default_datastore_filter) navigate_to(Datastore, 'All') list_acc.select('Filters', 'Store Type / NFS', by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) logout() login_admin() navigate_to(Datastore, 'All') assert list_acc.is_selected('Filters', 'Store Type / NFS (Default)', by_title=False),\ 'Store Type / NFS not set as default'
def test_set_default_datastore_filter(provider, request): """ Test for setting default filter for datastores.""" # Add cleanup finalizer def unset_default_datastore_filter(): pytest.sel.force_navigate('infrastructure_datastores') list_acc.select('Filters', 'ALL', by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) request.addfinalizer(unset_default_datastore_filter) pytest.sel.force_navigate('infrastructure_datastores') list_acc.select('Filters', 'Store Type / NFS', by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) logout() login_admin() pytest.sel.force_navigate('infrastructure_datastores') assert (list_acc.is_selected('Filters', 'Store Type / NFS (Default)', by_title=False), 'Store Type / NFS not set as default')
def test_start_page(request, setup_a_provider, start_page): """ Tests start page Metadata: test_flag: visuals """ request.addfinalizer(set_default_page) if visual.login_page != start_page: visual.login_page = start_page login.logout() login.login_admin() steps = map(lambda x: x.strip(), start_page.split('/')) longer_steps = copy(steps) longer_steps.insert(0, None) # BUG - https://bugzilla.redhat.com/show_bug.cgi?id=1331327 nav = menu.nav nav.initialize() assert nav.is_page_active(*steps) or nav.is_page_active(*longer_steps), "Landing Page Failed"
def test_set_default_datastore_filter(request): """ Test for setting default filter for datastores.""" # Add cleanup finalizer def unset_default_datastore_filter(): navigate_to(Datastore, 'All') list_acc.select('Filters', 'ALL', by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) request.addfinalizer(unset_default_datastore_filter) navigate_to(Datastore, 'All') list_acc.select('Filters', 'Store Type / NFS', by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) logout() login_admin() navigate_to(Datastore, 'All') assert list_acc.is_selected('Filters', 'Store Type / NFS (Default)', by_title=False),\ 'Store Type / NFS not set as default'
def test_set_default_host_filter(request): """ Test for setting default filter for hosts.""" # Add cleanup finalizer def unset_default_host_filter(): navigate_to(Host, 'All') list_acc.select('Filters', 'ALL', by_title=False) pytest.sel.click(host.default_host_filter_btn) request.addfinalizer(unset_default_host_filter) navigate_to(Host, 'All') list_acc.select('Filters', 'Status / Running', by_title=False) pytest.sel.click(host.default_host_filter_btn) logout() login_admin() navigate_to(Host, 'All') assert list_acc.is_selected('Filters', 'Status / Running (Default)', by_title=False),\ 'Status / Running filter not set as default'
def test_set_default_datastore_filter(provider, request): """ Test for setting default filter for datastores.""" # Add cleanup finalizer def unset_default_datastore_filter(): pytest.sel.force_navigate("infrastructure_datastores") list_acc.select("Filters", "ALL", by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) request.addfinalizer(unset_default_datastore_filter) pytest.sel.force_navigate("infrastructure_datastores") list_acc.select("Filters", "Store Type / NFS", by_title=False) pytest.sel.click(datastore.default_datastore_filter_btn) logout() login_admin() pytest.sel.force_navigate("infrastructure_datastores") assert list_acc.is_selected( "Filters", "Store Type / NFS (Default)", by_title=False ), "Store Type / NFS not set as default"
def test_set_default_host_filter(provider, request): """ Test for setting default filter for hosts.""" # Add cleanup finalizer def unset_default_host_filter(): pytest.sel.force_navigate("infrastructure_hosts") list_acc.select("Filters", "ALL", by_title=False) pytest.sel.click(host.default_host_filter_btn) request.addfinalizer(unset_default_host_filter) pytest.sel.force_navigate("infrastructure_hosts") list_acc.select("Filters", "Status / Running", by_title=False) pytest.sel.click(host.default_host_filter_btn) logout() login_admin() pytest.sel.force_navigate("infrastructure_hosts") assert list_acc.is_selected( "Filters", "Status / Running (Default)", by_title=False ), "Status / Running filter not set as default"
def test_openldap_auth(request, group, add_from_ldap, configure_openldap_auth_mode): data = cfme_data.get("openldap_test", {}) if add_from_ldap: group.add_group_from_ldap_lookup() else: group.create() request.addfinalizer(group.delete) credentials = Credential( principal=data["username"], secret=data["password"], verify_secret=data["password"], ) user = User(name=data["fullname"], credential=credentials) request.addfinalizer(user.delete) request.addfinalizer(login.login_admin) with user: login.login(user) assert login.current_full_name() == data["fullname"] login.logout() login.login_admin() assert user.exists is True
def test_logout(logged_in): """ Tests that the provider can be logged out of. """ login.logout() assert login.page.is_displayed()
def check_logged_out(): login.logout() yield login.logout()