def test_check_credentials_managed_global_user_is_allowed( with_user: tuple[UserId, str]) -> None: if not is_managed_repo(): pytest.skip("not relevant") user_id, password = with_user assert userdb.check_credentials(user_id, password) == user_id
def test_check_credentials_managed_wrong_customer_user_is_denied( with_user: tuple[UserId, str]) -> None: if not is_managed_repo(): pytest.skip("not relevant") user_id, password = with_user assert userdb.check_credentials(user_id, password) is False
def make_cme_wrong_customer_user(user_id: UserId) -> None: if not is_managed_repo(): pytest.skip("not relevant") users = _load_users_uncached(lock=True) users[user_id]["customer"] = "wrong-customer" userdb.save_users(users)
def make_cme_global_user(user_id: UserId) -> None: if not is_managed_repo(): pytest.skip("not relevant") import cmk.gui.cme.managed as managed # pylint: disable=no-name-in-module users = _load_users_uncached(lock=True) users[user_id]["customer"] = managed.SCOPE_GLOBAL userdb.save_users(users)
def fixture_edition_short(monkeypatch, request): edition_short = request.param if edition_short == "cme" and not is_managed_repo(): pytest.skip("Needed files are not available") if edition_short == "cee" and not is_enterprise_repo(): pytest.skip("Needed files are not available") monkeypatch.setattr(cmk_version, "edition_short", lambda: edition_short) yield edition_short
def make_cme(monkeypatch: MonkeyPatch, user_id: UserId) -> None: if not is_managed_repo(): pytest.skip("not relevant") monkeypatch.setattr(cmk.utils.version, "omd_version", lambda: "2.0.0i1.cme") assert cmk.utils.version.is_managed_edition() monkeypatch.setattr(config, "current_customer", "test-customer") # Fix CRE mypy tests that do not have this attribute defined assert config.current_customer == "test-customer" # type: ignore[attr-defined]
def fixture_edition(monkeypatch, request) -> Iterable[cmk_version.Edition]: edition_short = request.param if edition_short == "cpe" and not is_plus_repo(): pytest.skip("Needed files are not available") if edition_short == "cme" and not is_managed_repo(): pytest.skip("Needed files are not available") if edition_short == "cee" and not is_enterprise_repo(): pytest.skip("Needed files are not available") yield cmk_version.Edition[edition_short.upper()]
def test_default_config_from_plugins(): expected = [ "roles", "debug", "screenshotmode", "profile", "users", "admin_users", "guest_users", "default_user_role", "user_online_maxage", "log_levels", "slow_views_duration_threshold", "multisite_users", "multisite_hostgroups", "multisite_servicegroups", "multisite_contactgroups", "sidebar", "sidebar_update_interval", "sidebar_show_scrollbar", "sidebar_notify_interval", "quicksearch_dropdown_limit", "quicksearch_search_order", "failed_notification_horizon", "soft_query_limit", "hard_query_limit", "sound_url", "enable_sounds", "sounds", "view_option_refreshes", "view_option_columns", "doculink_urlformat", "view_action_defaults", "custom_links", "debug_livestatus_queries", "show_livestatus_errors", "liveproxyd_enabled", "visible_views", "hidden_views", "service_view_grouping", "custom_style_sheet", "ui_theme", "show_mode", "start_url", "page_heading", "login_screen", "reschedule_timeout", "filter_columns", "default_language", "hide_languages", "default_ts_format", "selection_livetime", "auth_by_http_header", "table_row_limit", "multisite_draw_ruleicon", "adhoc_downtime", "pagetitle_date_format", "staleness_threshold", "escape_plugin_output", "virtual_host_trees", "crash_report_url", "crash_report_target", "guitests_enabled", "bulk_discovery_default_settings", "use_siteicons", "graph_timeranges", "userdb_automatic_sync", "user_login", "user_connections", "default_user_profile", "log_logon_failures", "lock_on_logon_failures", "user_idle_timeout", "single_user_session", "password_policy", "user_localizations", "user_icons_and_actions", "custom_service_attributes", "user_downtime_timeranges", "builtin_icon_visibility", "trusted_certificate_authorities", "mkeventd_enabled", "mkeventd_pprint_rules", "mkeventd_notify_contactgroup", "mkeventd_notify_facility", "mkeventd_notify_remotehost", "mkeventd_connect_timeout", "log_level", "log_rulehits", "rule_optimizer", "mkeventd_service_levels", "wato_host_tags", "wato_aux_tags", "wato_tags", "wato_enabled", "wato_hide_filenames", "wato_hide_hosttags", "wato_upload_insecure_snapshots", "wato_hide_varnames", "wato_hide_help_in_lists", "wato_activate_changes_concurrency", "wato_max_snapshots", "wato_num_hostspecs", "wato_num_itemspecs", "wato_activation_method", "wato_write_nagvis_auth", "wato_use_git", "wato_hidden_users", "wato_user_attrs", "wato_host_attrs", "wato_read_only", "wato_hide_folders_without_read_permissions", "wato_pprint_config", "wato_icon_categories", "wato_activate_changes_comment_mode", "rest_api_etag_locking", "aggregation_rules", "aggregations", "host_aggregations", "bi_packs", "default_bi_layout", "bi_layouts", "bi_compile_log", "bi_precompile_on_demand", "bi_use_legacy_compilation", "sites", "config_storage_format", "tags", ] if is_enterprise_repo(): expected += [ "agent_deployment_enabled", "agent_deployment_host_selection", "agent_deployment_central", "agent_deployment_remote", "agent_signature_keys", "have_combined_graphs", "reporting_use", "reporting_rangespec", "reporting_filename", "reporting_view_limit", "reporting_font_size", "reporting_lineheight", "reporting_font_family", "reporting_pagesize", "reporting_margins", "reporting_mirror_margins", "reporting_date_format", "reporting_time_format", "reporting_table_layout", "reporting_graph_layout", "reporting_email_options", "subscription_settings", "ntop_connection", ] if is_managed_repo(): expected += [ "customers", "current_customer", ] default_config = cmk.gui.config.get_default_config() assert sorted(list(default_config.keys())) == sorted(expected) default_config2 = asdict(cmk.gui.config.make_config_object(default_config)) assert sorted(default_config2.keys()) == sorted(expected)
def test_check_credentials_managed_customer_user_is_allowed(with_user): if not is_managed_repo(): pytest.skip("not relevant") user_id, password = with_user assert userdb.check_credentials(user_id, password) == user_id
# user_id needs to be used here because it executes a reload of the config and the monkeypatch of # the config needs to be done after loading the config @pytest.fixture() def make_cme(monkeypatch: MonkeyPatch, user_id: UserId) -> None: monkeypatch.setattr(cmk.utils.version, "omd_version", lambda: "2.0.0i1.cme") assert cmk.utils.version.is_managed_edition() monkeypatch.setattr(active_config, "current_customer", "test-customer") # Fix CRE mypy tests that do not have this attribute defined assert active_config.current_customer == "test-customer" # type: ignore[attr-defined] @pytest.mark.skipif(not is_managed_repo(), reason="managed-edition-only test") @pytest.mark.usefixtures("make_cme") def test_check_credentials_managed_global_user_is_allowed( with_user: tuple[UserId, str]) -> None: user_id, password = with_user now = datetime.now() import cmk.gui.cme.managed as managed # pylint: disable=no-name-in-module users = _load_users_uncached(lock=True) users[user_id]["customer"] = managed.SCOPE_GLOBAL userdb.save_users(users, now) assert userdb.check_credentials(user_id, password, now) == user_id @pytest.mark.skipif(not is_managed_repo(), reason="managed-edition-only test") @pytest.mark.usefixtures("make_cme")