feat(compliance): update retention policy and enhance password reset validation
Deploy Development / deploy (push) Successful in 37s
Test Suite / pytest-backend (push) Successful in 34s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 8s
Test Suite / playwright-tests (push) Successful in 26s

- Adjusted retention policy to align with compliance requirements:
  - Changed HIDDEN_TO_PURGE_DAYS from 90 to 30 days.
- Enhanced password reset functionality to enforce a minimum password length of 8 characters.
- Updated tests to validate new password requirements and retention logic.
- Corrected umlaut in copyright error messages for clarity.
This commit is contained in:
Lars committed 2026-05-10 08:26:15 +02:00
1 parent be0385922d
commit fc33bfbdeb
9 files changed
+294 -86

No files matched your search

+2 -1
View File
@@ -21,7 +21,8 @@ LC_TRASH_SOFT = "trash_soft"
LC_TRASH_HIDDEN = "trash_hidden"
SOFT_TO_HIDDEN_DAYS = max(1, int(os.getenv("MEDIA_TRASH_SOFT_TO_HIDDEN_DAYS", "30")))
HIDDEN_TO_PURGE_DAYS = max(1, int(os.getenv("MEDIA_TRASH_HIDDEN_TO_PURGE_DAYS", "90")))
# P-03b: Default gemaess fachlichem Loeschkonzept (Audit 2026-05-09): 30+30 Tage.
HIDDEN_TO_PURGE_DAYS = max(1, int(os.getenv("MEDIA_TRASH_HIDDEN_TO_PURGE_DAYS", "30")))
def assert_can_manage_media_asset_lifecycle(cur: Any, tenant: Any, asset: dict) -> None:
+1 -1
View File
@@ -26,7 +26,7 @@ class PasswordResetRequest(BaseModel):
class PasswordResetConfirm(BaseModel):
token: str
new_password: str
new_password: str = Field(min_length=8, max_length=128)
class ProfileCreate(BaseModel):
"""Nur für POST /api/profiles (Plattform-Admin): neues Nutzerprofil ohne Self-Registration."""
+2 -2
View File
@@ -1167,7 +1167,7 @@ def bulk_media_patch(
{
"id": asset_id,
"detail": (
"Fur Vereins- oder offizielle Medien ist eine "
"Für Vereins- oder offizielle Medien ist eine "
"Urheberrechtsangabe (copyright_notice) Pflicht."
),
}
@@ -1280,7 +1280,7 @@ def patch_media_asset(
raise HTTPException(
status_code=400,
detail=(
"Fur Vereins- oder offizielle Medien ist eine Urheberrechtsangabe "
"Für Vereins- oder offizielle Medien ist eine Urheberrechtsangabe "
"(copyright_notice) Pflicht. Bitte vor oder zusammen mit der "
"Freigabe angeben."
),
@@ -0,0 +1,100 @@
"""
P-05b: POST /api/auth/reset-password muss Passwoerter unter 8 Zeichen ablehnen.
Prueft Pydantic-Validierung (HTTP 422) BEVOR die DB befragt wird.
"""
from __future__ import annotations
import os
from unittest.mock import MagicMock, patch
import pytest
from fastapi.testclient import TestClient
os.environ.setdefault("SKIP_DB_MIGRATE", "1")
from main import app
@pytest.fixture
def client() -> TestClient:
return TestClient(app)
def _mock_db_valid_token() -> MagicMock:
mock_cur = MagicMock()
mock_cur.fetchone.return_value = {"profile_id": 1}
mock_conn = MagicMock()
mock_cm = MagicMock()
mock_cm.__enter__.return_value = mock_conn
mock_cm.__exit__.return_value = False
return mock_cm, mock_cur
# ── Mindestlaenge-Grenzwerte ──────────────────────────────────────────────────
@pytest.mark.parametrize("short_pw", ["", "a", "1234567"])
def test_reset_password_too_short_rejected(client: TestClient, short_pw: str) -> None:
"""Passwort < 8 Zeichen muss mit 422 abgelehnt werden (Pydantic-Validierung)."""
r = client.post(
"/api/auth/reset-password",
json={"token": "sometoken", "new_password": short_pw},
)
assert r.status_code == 422, (
f"Erwartet 422 fuer Passwort {short_pw!r} ({len(short_pw)} Zeichen), "
f"erhalten {r.status_code}"
)
def test_reset_password_exactly_8_chars_accepted(client: TestClient) -> None:
"""Passwort mit genau 8 Zeichen muss die Validierung passieren."""
mock_cm, mock_cur = _mock_db_valid_token()
with patch("routers.auth.get_db", return_value=mock_cm), patch(
"routers.auth.get_cursor", return_value=mock_cur
):
r = client.post(
"/api/auth/reset-password",
json={"token": "sometoken", "new_password": "12345678"},
)
assert r.status_code == 200
assert r.json().get("ok") is True
def test_reset_password_long_password_accepted(client: TestClient) -> None:
"""Langes Passwort (>= 8 Zeichen) muss akzeptiert werden."""
mock_cm, mock_cur = _mock_db_valid_token()
with patch("routers.auth.get_db", return_value=mock_cm), patch(
"routers.auth.get_cursor", return_value=mock_cur
):
r = client.post(
"/api/auth/reset-password",
json={"token": "sometoken", "new_password": "sicheresPasswort123!"},
)
assert r.status_code == 200
def test_reset_password_missing_field_rejected(client: TestClient) -> None:
"""Fehlendes new_password-Feld muss mit 422 abgelehnt werden."""
r = client.post(
"/api/auth/reset-password",
json={"token": "sometoken"},
)
assert r.status_code == 422
def test_reset_password_invalid_token_returns_400(client: TestClient) -> None:
"""Gueltiges Passwort aber ungueltiger Token muss 400 liefern."""
mock_cur = MagicMock()
mock_cur.fetchone.return_value = None
mock_conn = MagicMock()
mock_cm = MagicMock()
mock_cm.__enter__.return_value = mock_conn
mock_cm.__exit__.return_value = False
with patch("routers.auth.get_db", return_value=mock_cm), patch(
"routers.auth.get_cursor", return_value=mock_cur
):
r = client.post(
"/api/auth/reset-password",
json={"token": "ungueltig", "new_password": "validesPw123"},
)
assert r.status_code == 400
@@ -125,13 +125,11 @@ def test_patch_promote_to_official_without_copyright_returns_400(client: TestCli
def test_patch_promote_to_club_with_copyright_in_body_allowed(client: TestClient) -> None:
"""Promotion private -> club MIT copyright_notice im Body darf nicht 400 liefern."""
"""Promotion private -> club MIT copyright_notice im Body muss 200 liefern."""
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
mock_cm, mock_cur = _make_db_mocks(_PRIVATE_ASSET)
mock_cur.fetchone.side_effect = [
_PRIVATE_ASSET,
{**_PRIVATE_ASSET, "visibility": "club", "copyright_notice": "Verein 2026"},
]
updated_asset = {**_PRIVATE_ASSET, "visibility": "club", "copyright_notice": "Verein 2026"}
mock_cur.fetchone.side_effect = [_PRIVATE_ASSET, updated_asset]
with ExitStack() as stack:
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
@@ -143,17 +141,19 @@ def test_patch_promote_to_club_with_copyright_in_body_allowed(client: TestClient
headers={"X-Auth-Token": "t"},
)
assert r.status_code != 400 or "copyright" not in r.json().get("detail", "").lower()
assert r.status_code == 200
body = r.json()
assert body["id"] == 42
assert body["visibility"] == "club"
assert body["copyright_notice"] == "Verein 2026"
def test_patch_promote_to_club_existing_copyright_allowed(client: TestClient) -> None:
"""Asset hat bereits copyright_notice -> Promotion ohne Body-Copyright erlaubt."""
"""Asset hat bereits copyright_notice -> Promotion ohne Body-Copyright muss 200 liefern."""
app.dependency_overrides[get_tenant_context] = lambda: _SUPERADMIN_TENANT
promoted_asset = {**_ASSET_WITH_COPYRIGHT, "visibility": "club"}
mock_cm, mock_cur = _make_db_mocks(_ASSET_WITH_COPYRIGHT)
mock_cur.fetchone.side_effect = [
_ASSET_WITH_COPYRIGHT,
{**_ASSET_WITH_COPYRIGHT, "visibility": "club"},
]
mock_cur.fetchone.side_effect = [_ASSET_WITH_COPYRIGHT, promoted_asset]
with ExitStack() as stack:
stack.enter_context(patch("routers.media_assets.get_db", return_value=mock_cm))
@@ -165,7 +165,11 @@ def test_patch_promote_to_club_existing_copyright_allowed(client: TestClient) ->
headers={"X-Auth-Token": "t"},
)
assert r.status_code != 400 or "copyright" not in r.json().get("detail", "").lower()
assert r.status_code == 200
body = r.json()
assert body["id"] == 42
assert body["visibility"] == "club"
assert body["copyright_notice"] == "Verein 2026"
def test_patch_filename_only_no_copyright_check(client: TestClient) -> None:
+13 -4
View File
@@ -1,11 +1,11 @@
# Shinkan Jinkendo Version Information
APP_VERSION = "0.8.66"
BUILD_DATE = "2026-05-09"
APP_VERSION = "0.8.67"
BUILD_DATE = "2026-05-10"
DB_SCHEMA_VERSION = "20260508049"
MODULE_VERSIONS = {
"auth": "1.2.2", # Passwort-Mindestlange PUT /auth/pin: 4 auf 8 Zeichen angehoben
"auth": "1.2.3", # P-05b: reset-password min_length=8 via Pydantic PasswordResetConfirm
"profiles": "1.7.0", # exercise_list_prefs JSONB (Standard Übungsfilter); Patch via ProfileUpdate + Json()
"tenant_context": "1.0.5", # Plattform-Admin: effective_club ohne Header aus Profil active_club_id wenn Verein existiert
"clubs": "0.4.1", # Alle geschützten Endpoints Depends(get_tenant_context); profile_id/role aus TenantContext
@@ -13,7 +13,7 @@ MODULE_VERSIONS = {
"club_join_requests": "1.0.1", # Depends(get_tenant_context)
"admin_users": "1.0.0", # GET /api/admin/users
"platform_media_storage": "1.0.0", # GET/PUT /api/admin/platform-media-storage (Superadmin-Pfad unter MEDIA_ROOT)
"media_assets": "1.12.2", # P-04: Copyright-Pflicht bei Promotion auf club/official in PATCH und bulk-patch
"media_assets": "1.12.3", # P-04b: Umlautkorrektur Fehlermeldung; Tests gehaertet
"groups": "0.1.0",
"skills": "0.1.0",
"methods": "0.1.0",
@@ -29,6 +29,15 @@ MODULE_VERSIONS = {
}
CHANGELOG = [
{
"version": "0.8.67",
"date": "2026-05-10",
"changes": [
"Sicherheit P-05b: PasswordResetConfirm.new_password min_length=8 (POST /auth/reset-password)",
"Sicherheit P-03b: Retention-Default HIDDEN_TO_PURGE 90->30 Tage (gemaess Loeschkonzept 30+30)",
"Sicherheit P-04: Positive Promotion-Tests haerten (explizit 200 + Payload); Umlaut in Fehlermeldung",
],
},
{
"version": "0.8.66",
"date": "2026-05-09",