def make_cme_wrong_customer_user(user_id): 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): 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, user_id): 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 test_check_credentials_managed_wrong_customer_user_is_denied(with_user): if not is_managed_repo(): pytest.skip("not relevant") user_id, password = with_user assert userdb.check_credentials(user_id, password) is False
def test_check_credentials_managed_global_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
def test_pylint(pylint_test_dir): # Only specify the path to python packages or modules here if sys.version_info[0] >= 3: modules_or_packages = [] else: modules_or_packages = [ "omd/packages/omd/omdlib", "livestatus/api/python/livestatus.py", "cmk_base", "cmk", "web/app/index.wsgi", ] if is_enterprise_repo(): modules_or_packages += [ # TODO: Check if this kind of "overlay" really works. # TODO: Why do we have e.g. a symlink cmk_base/cee -> enterprise/cmk_base/cee? "enterprise/cmk_base/automations/cee.py", "enterprise/cmk_base/cee", "enterprise/cmk_base/default_config/cee.py", "enterprise/cmk_base/modes/cee.py", # TODO: Funny links there, see above. "enterprise/cmk/cee", "enterprise/cmk/gui/cee", ] if is_managed_repo(): modules_or_packages += [ "managed/cmk_base/default_config/cme.py", "managed/cmk/gui/cme", ] # Add the compiled files for things that are no modules yet open(pylint_test_dir + "/__init__.py", "w") _compile_check_and_inventory_plugins(pylint_test_dir) if is_enterprise_repo(): _compile_bakery_plugins(pylint_test_dir) # Not checking compiled check, inventory, bakery plugins with Python 3 if sys.version_info[0] == 2: modules_or_packages += [ pylint_test_dir, ] # We use our own search logic to find scripts without python extension search_paths = [ "omd/packages/omd.bin", "bin", "notifications", "agents/plugins", "agents/special", "active_checks", ] if is_enterprise_repo(): search_paths += [ "enterprise/agents/plugins", "enterprise/bin", "enterprise/misc", ] for path in search_paths: abs_path = cmk_path() + "/" + path for fname in pylint_cmk.get_pylint_files(abs_path, "*"): modules_or_packages.append(path + "/" + fname) exit_code = pylint_cmk.run_pylint(cmk_path(), modules_or_packages) assert exit_code == 0, "PyLint found an error"