Files
Aegis/backend/tests/test_hold_resume.py
T
kitos be2a3fdced
Aegis CI / lint-and-test (push) Has been cancelled
Snyk Security Scan / Python vulnerabilities (backend) (push) Has been cancelled
Snyk Security Scan / npm vulnerabilities (frontend) (push) Has been cancelled
Snyk Security Scan / Docker image vulnerabilities (backend) (push) Has been cancelled
fix: multiple test-workflow bugs — draft wipe, dark date pickers, Jira status strings, Tempo gate, hold timer
- Fix the red/blue draft form losing unsaved fields (e.g. execution_start_time) whenever an evidence upload refetches the test — the hydration effect now runs once per test, not on every refetch.
- Add color-scheme: dark so native date/time picker popups match the app theme instead of rendering white.
- Fix _STATE_TO_JIRA_STATUS: real Jira statuses are 'To Do' and 'Red Team test review', not 'To-Do' and 'RT Test Review' — confirmed live against the actual workflow transitions, which is why Submit to Blue Team never moved the ticket past 'In Progress'.
- Tempo worklog sync was silently blocked by TEMPO_ENABLED defaulting to False with no admin-facing toggle, even after configuring a Tempo token via Settings. Now bypassed once an admin or personal token is actually configured, mirroring Jira's DB-backed enabled flag.
- Hold now actually pauses the running phase timer (paused_at), and Resume accumulates the held duration into red/blue_paused_seconds — previously the timer kept counting through a hold.
2026-07-10 15:24:19 +02:00

91 lines
2.8 KiB
Python

"""Tests for POST /tests/{id}/hold and /resume — must pause/resume the phase timer."""
from datetime import datetime, timedelta
from app.models.test import Test
from app.models.technique import Technique
from app.models.enums import TestState
def _seed_technique(db) -> Technique:
technique = Technique(
mitre_id="T9999", name="Test Technique", tactic="execution", platforms=["linux"],
)
db.add(technique)
db.commit()
db.refresh(technique)
return technique
def _seed_executing_test(db, technique, created_by) -> Test:
test = Test(
technique_id=technique.id,
name="Holdable test",
created_by=created_by,
state=TestState.red_executing,
red_started_at=datetime.utcnow() - timedelta(minutes=10),
)
db.add(test)
db.commit()
db.refresh(test)
return test
def test_hold_pauses_the_running_timer(client, db, red_tech_headers, red_tech_user):
technique = _seed_technique(db)
test = _seed_executing_test(db, technique, red_tech_user.id)
assert test.paused_at is None
resp = client.post(
f"/api/v1/tests/{test.id}/hold",
json={"reason": "waiting on lab access"},
headers=red_tech_headers,
)
assert resp.status_code == 200, resp.text
assert resp.json()["paused_at"] is not None
db.refresh(test)
assert test.paused_at is not None
def test_resume_clears_pause_and_accumulates_seconds(client, db, red_tech_headers, red_tech_user):
technique = _seed_technique(db)
test = _seed_executing_test(db, technique, red_tech_user.id)
resp = client.post(
f"/api/v1/tests/{test.id}/hold",
json={"reason": "waiting on lab access"},
headers=red_tech_headers,
)
assert resp.status_code == 200
resp = client.post(f"/api/v1/tests/{test.id}/resume", headers=red_tech_headers)
assert resp.status_code == 200, resp.text
assert resp.json()["paused_at"] is None
db.refresh(test)
assert test.paused_at is None
assert test.red_paused_seconds >= 0
def test_hold_does_not_double_pause_an_already_paused_timer(client, db, red_tech_headers, red_tech_user):
"""If the operator already paused the timer manually, holding must not
overwrite paused_at (which would reset the elapsed-pause calculation)."""
technique = _seed_technique(db)
test = _seed_executing_test(db, technique, red_tech_user.id)
resp = client.post(f"/api/v1/tests/{test.id}/pause-timer", headers=red_tech_headers)
assert resp.status_code == 200
db.refresh(test)
manual_pause_time = test.paused_at
resp = client.post(
f"/api/v1/tests/{test.id}/hold",
json={"reason": "waiting on lab access"},
headers=red_tech_headers,
)
assert resp.status_code == 200
db.refresh(test)
assert test.paused_at == manual_pause_time