Files
pvemanager/backend/tests/test_interrupted_operations.py
markmorado 09186e23b9
Some checks failed
Backend Tests / pytest (Python 3.12) (push) Has been cancelled
Deploy to Production / backend-tests (push) Has been cancelled
Deploy to Production / frontend-build (push) Has been cancelled
Frontend Checks / Build & typecheck (push) Has been cancelled
SonarCloud / SonarCloud Analysis (push) Has been cancelled
Deploy to Production / Trigger production update (push) Has been cancelled
Security audit: tenant isolation, injection fixes, hardening and performance
Security
- Enforce guest ownership and server assignment across Proxmox endpoints
  (VM/LXC actions, firewall, backups, tasks, bulk operations, deploy,
  LXC/ISO creation, golden template) and WebSocket channels
- Keep the panel's PVE root ticket server-side for consoles; single-use
  WebSocket tickets instead of the JWT in URLs; re-check access on open
  WebSocket bridges
- Validate identifiers that reach Proxmox API paths and node shell
  commands; reject backup archives / foreign volumes in create requests
- Close privilege escalation in user management, TOTP replay, reset-link
  poisoning, X-Forwarded-For spoofing, stored XSS (group icons, SVG logos)
- SSH host key pinning (TOFU), encrypted 2FA seeds and notification
  secrets, password changes end other sessions, redact secrets in logs
- Quotas count in-flight creations; 2FA failures count toward lockout

Fixes
- Consoles on non-default API ports, large App Store/script files,
  interrupted tasks after restart, impersonation lost on token refresh,
  HTTPExceptions swallowed into 500s, WebSocket client reconnects

Performance and process
- Fewer DB writes and queries on hot paths, lazy-loaded locales and
  heavy pages, off-loop blocking work, indexes (migrations 44-46)
- Deploy waits for backend tests and frontend build; frontend checks
  workflow; API bound to loopback without the SSL profile
2026-10-23 00:04:16 +05:00

31 lines
1.7 KiB
Python

"""Operations run in threads of the backend process are failed after a restart."""
import app.db
from app.models import AppOperation, DeployTask, InstalledApp, ScriptExecution, TaskQueue
from app.services import task_queue_service
def test_restart_fails_operations_nothing_will_finish(db_session, seed_users, monkeypatch):
monkeypatch.setattr(task_queue_service, "SessionLocal", app.db.SessionLocal)
uid = seed_users["user"].id
db_session.add_all([
DeployTask(status="running", name="vm1", template_id=1, server_id=1, user_id=uid),
DeployTask(status="pending", name="vm2", template_id=1, server_id=1, user_id=uid),
DeployTask(status="completed", name="vm3", template_id=1, server_id=1, user_id=uid),
AppOperation(type="install", status="running", user_id=uid),
ScriptExecution(server_id=1, target_type="node", status="running", user_id=uid),
TaskQueue(task_type="bulk_start", status="running", user_id=uid, total_items=1,
completed_items=0, failed_items=0, task_data=[], results=[]),
InstalledApp(name="nginx", status="installing", owner_id=uid),
InstalledApp(name="ok", status="running", owner_id=uid),
])
db_session.commit()
assert task_queue_service.recover_interrupted_tasks() == 6
db_session.expire_all()
assert sorted(t.status for t in db_session.query(DeployTask)) == ["completed", "failed", "failed"]
assert db_session.query(AppOperation).one().status == "failed"
assert db_session.query(ScriptExecution).one().status == "failed"
assert db_session.query(TaskQueue).one().status == "failed"
assert {a.name: a.status for a in db_session.query(InstalledApp)} == {"nginx": "error", "ok": "running"}