Commit b3340700 authored by Dimitrios Gogos's avatar Dimitrios Gogos
Browse files

feat: update role definitions and adjust tests for authentication module

parent e1a1c1f7
Loading
Loading
Loading
Loading
+2 −5
Changes for src/portal_service/domain/models.py: 2 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ from pydantic import BaseModel

class Role(StrEnum):
    APP_PROVIDER = "app-provider"
    PLATFORM_OPERATOR = "platform-operator"
    OPERATOR = "operator"
    PLATFORM_ADMIN = "platform-admin"


@@ -47,7 +47,4 @@ class TokenClaims(BaseModel):
    @property
    def is_human(self) -> bool:
        """True when the token belongs to a human user (not a service account)."""
        return any(
            r in self.roles
            for r in (Role.APP_PROVIDER, Role.PLATFORM_OPERATOR, Role.PLATFORM_ADMIN)
        )
        return any(r in self.roles for r in (Role.APP_PROVIDER, Role.OPERATOR, Role.PLATFORM_ADMIN))
+0 −0

Empty file added.

+1 −1
Changes for tests/test_auth_deps.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ def test_require_any_role_sufficient_passes() -> None:

def test_require_any_role_accepts_either_role() -> None:
    admin = TokenClaims(sub="s", iss="i", exp=1, iat=0, realm_access={"roles": ["platform-admin"]})
    dep = auth_module.require_any_role(Role.PLATFORM_OPERATOR, Role.PLATFORM_ADMIN)
    dep = auth_module.require_any_role(Role.OPERATOR, Role.PLATFORM_ADMIN)
    assert _run_guard(dep, user=admin, auth_settings=JWT) is admin