Skip to content

Commit

Permalink
fix default role variable sync
Browse files Browse the repository at this point in the history
We define default builtin roles in multiple places. Lets at least check
they are in sync

Change-Id: Ia127b9ad81b1a3de214c80beaf171d609d85ef88
  • Loading branch information
kain88-de committed Oct 22, 2024
1 parent 0cbecd6 commit a75b13a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cmk/gui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class CMEConfig: # type: ignore[no-redef]

# hard coded in various permissions
default_authorized_builtin_role_ids: Final[list[RoleName]] = ["user", "admin", "guest"]
default_unauthorized_builtin_role_ids: Final[list[RoleName]] = ["agent_registration"]
default_unauthorized_builtin_role_ids: Final[list[RoleName]] = [
"agent_registration",
"no_permissions",
]
builtin_role_ids: Final[list[RoleName]] = [
*default_authorized_builtin_role_ids,
*default_unauthorized_builtin_role_ids,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/cmk/gui/test_logged_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def fixture_monitoring_user() -> Iterator[LoggedInUser]:
user_dir.joinpath("favorites.mk").write_text(str(MONITORING_USER_FAVORITES))

assert default_authorized_builtin_role_ids == ["user", "admin", "guest"]
assert default_unauthorized_builtin_role_ids == ["agent_registration"]
assert builtin_role_ids == ["user", "admin", "guest", "agent_registration"]
assert default_unauthorized_builtin_role_ids == ["agent_registration", "no_permissions"]
assert builtin_role_ids == ["user", "admin", "guest", "agent_registration", "no_permissions"]
assert "test" not in active_config.admin_users

with create_and_destroy_user(username="test") as user:
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/cmk/gui/userdb/test_roles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (C) 2024 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
from cmk.gui.config import builtin_role_ids
from cmk.gui.userdb._roles import BuiltInUserRoleValues


def test_buildin_role_ids_var_is_complete() -> None:
ids = [m.value for m in BuiltInUserRoleValues]
assert set(ids) == set(builtin_role_ids)
2 changes: 2 additions & 0 deletions tests/unit/cmk/gui/watolib/test_user_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def test_cloning_user_roles(request_context: None) -> None:
"guestx",
"userx",
"agent_registrationx",
"no_permissionsx",
}


Expand All @@ -83,6 +84,7 @@ def test_get_default_user_roles(request_context: None) -> None:
"guest",
"user",
"agent_registration",
"no_permissions",
}


Expand Down

0 comments on commit a75b13a

Please sign in to comment.