feat(tests): archive round history on reopen, stop pausing from setting Jira On Hold
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
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
- Reopening a test for rework (red or blue) now archives the round that's ending into a new test_round_history table before resetting the live fields — procedure/results/detection data is preserved instead of overwritten, and Phase Timeline renders every past round alongside the current one, so Blue Team keeps visibility into earlier Red attempts. - Each archived round also posts a permanent Jira comment (push_round_archived) since Jira's custom fields only ever show the latest value once the next round resubmits — the comment thread is what preserves full history there. - push_pause_event no longer transitions the Jira issue to "On Hold" — a timer pause is not a real Hold, and flipping Jira status for it was misleading. Only the explicit Hold action (push_hold_event) does that now.
This commit is contained in:
@@ -74,7 +74,10 @@ def _make_test(**overrides):
|
||||
|
||||
@patch("app.services.jira_service.has_admin_jira_configured", return_value=True)
|
||||
@patch("app.services.jira_service.get_admin_jira_client")
|
||||
def test_push_pause_event_sets_on_hold(mock_get_client, mock_configured, db):
|
||||
def test_push_pause_event_does_not_change_jira_status(mock_get_client, mock_configured, db):
|
||||
"""A timer pause is not the same as a real Hold — it must never flip the
|
||||
Jira issue to 'On Hold'. Only push_hold_event (a genuine Hold action) is
|
||||
allowed to change status. Regression: pausing used to set 'On Hold'."""
|
||||
mock_jira = MagicMock()
|
||||
mock_get_client.return_value = mock_jira
|
||||
test = _make_test()
|
||||
@@ -84,13 +87,13 @@ def test_push_pause_event_sets_on_hold(mock_get_client, mock_configured, db):
|
||||
|
||||
jira_service.push_pause_event(db, test, MagicMock(username="alice"), resuming=False)
|
||||
|
||||
mock_jira.set_issue_status.assert_called_once_with(link.jira_issue_key, "On Hold")
|
||||
mock_jira.set_issue_status.assert_not_called()
|
||||
mock_jira.issue_add_comment.assert_called_once()
|
||||
|
||||
|
||||
@patch("app.services.jira_service.has_admin_jira_configured", return_value=True)
|
||||
@patch("app.services.jira_service.get_admin_jira_client")
|
||||
def test_push_pause_event_resume_sets_in_progress(mock_get_client, mock_configured, db):
|
||||
def test_push_pause_event_resume_does_not_change_jira_status(mock_get_client, mock_configured, db):
|
||||
mock_jira = MagicMock()
|
||||
mock_get_client.return_value = mock_jira
|
||||
test = _make_test()
|
||||
@@ -100,7 +103,8 @@ def test_push_pause_event_resume_sets_in_progress(mock_get_client, mock_configur
|
||||
|
||||
jira_service.push_pause_event(db, test, MagicMock(username="alice"), resuming=True)
|
||||
|
||||
mock_jira.set_issue_status.assert_called_once_with(link.jira_issue_key, "In Progress")
|
||||
mock_jira.set_issue_status.assert_not_called()
|
||||
mock_jira.issue_add_comment.assert_called_once()
|
||||
|
||||
|
||||
@patch("app.services.jira_service.has_admin_jira_configured", return_value=True)
|
||||
@@ -118,6 +122,39 @@ def test_push_hold_event_sets_blocked(mock_get_client, mock_configured, db):
|
||||
mock_jira.set_issue_status.assert_called_once_with(link.jira_issue_key, "Blocked")
|
||||
|
||||
|
||||
@patch("app.services.jira_service.has_admin_jira_configured", return_value=True)
|
||||
@patch("app.services.jira_service.get_admin_jira_client")
|
||||
def test_push_round_archived_posts_comment_without_changing_status(mock_get_client, mock_configured, db):
|
||||
"""Archiving a round before reopen must leave a permanent Jira comment
|
||||
(custom fields get overwritten by the next round, comments don't) but
|
||||
must not touch the issue's status — that's push_test_event's job."""
|
||||
from app.domain.enums import AttackSuccessResult
|
||||
from app.models.test_round_history import TestRoundHistory
|
||||
|
||||
test = _make_test()
|
||||
link = _make_link(test.id)
|
||||
db.add(link)
|
||||
db.commit()
|
||||
|
||||
round_data = TestRoundHistory(
|
||||
test_id=test.id, team="red", round_number=1,
|
||||
attack_success=AttackSuccessResult.successful, red_summary="Got a shell.",
|
||||
procedure_text="ran mimikatz", tool_used="mimikatz",
|
||||
review_notes="Evidence was incomplete, redo with screenshots",
|
||||
)
|
||||
mock_jira = MagicMock()
|
||||
mock_get_client.return_value = mock_jira
|
||||
|
||||
jira_service.push_round_archived(db, test, MagicMock(username="redlead"), round_data=round_data)
|
||||
|
||||
mock_jira.set_issue_status.assert_not_called()
|
||||
mock_jira.issue_add_comment.assert_called_once()
|
||||
comment = mock_jira.issue_add_comment.call_args[0][1]
|
||||
assert "Round 1" in comment
|
||||
assert "Got a shell." in comment
|
||||
assert "Evidence was incomplete" in comment
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"new_state,expected_status",
|
||||
[
|
||||
|
||||
@@ -142,6 +142,21 @@ def _make_test(state: TestState = TestState.draft, **kwargs) -> MagicMock:
|
||||
t.paused_at = kwargs.get("paused_at", None)
|
||||
t.red_paused_seconds = kwargs.get("red_paused_seconds", 0)
|
||||
t.blue_paused_seconds = kwargs.get("blue_paused_seconds", 0)
|
||||
t.red_round_number = kwargs.get("red_round_number", 1)
|
||||
t.blue_round_number = kwargs.get("blue_round_number", 1)
|
||||
t.procedure_text = kwargs.get("procedure_text", None)
|
||||
t.tool_used = kwargs.get("tool_used", None)
|
||||
t.attack_success = kwargs.get("attack_success", None)
|
||||
t.red_summary = kwargs.get("red_summary", None)
|
||||
t.execution_start_time = kwargs.get("execution_start_time", None)
|
||||
t.execution_end_time = kwargs.get("execution_end_time", None)
|
||||
t.detection_result = kwargs.get("detection_result", None)
|
||||
t.containment_result = kwargs.get("containment_result", None)
|
||||
t.detection_time = kwargs.get("detection_time", None)
|
||||
t.containment_time = kwargs.get("containment_time", None)
|
||||
t.blue_summary = kwargs.get("blue_summary", None)
|
||||
t.red_tech_assignee = kwargs.get("red_tech_assignee", None)
|
||||
t.blue_tech_assignee = kwargs.get("blue_tech_assignee", None)
|
||||
return t
|
||||
|
||||
|
||||
@@ -723,6 +738,81 @@ class TestReviewDecisions:
|
||||
args, kwargs = mock_push.call_args
|
||||
assert args[3] == "blue_evaluating"
|
||||
|
||||
@patch("app.services.test_workflow_service.log_action")
|
||||
def test_reopen_red_review_archives_round_and_resets_fields(self, mock_log):
|
||||
"""Reopening must not erase what Red already submitted — it archives
|
||||
the round (visible via round_history) and only then blanks the live
|
||||
fields for a fresh attempt, bumping the round counter."""
|
||||
from app.models.test_round_history import TestRoundHistory
|
||||
|
||||
test = _make_test(
|
||||
TestState.red_review,
|
||||
procedure_text="ran mimikatz", tool_used="mimikatz",
|
||||
attack_success="successful", red_summary="Got a shell.",
|
||||
)
|
||||
reviewer = _make_user("red_lead")
|
||||
db = _make_db()
|
||||
|
||||
with patch("app.services.jira_service.push_test_event"), \
|
||||
patch("app.services.jira_service.push_round_archived"):
|
||||
from app.services.test_workflow_service import reopen_red_review
|
||||
reopen_red_review(db, test, reviewer, notes="incomplete evidence")
|
||||
|
||||
archived = [c.args[0] for c in db.add.call_args_list if isinstance(c.args[0], TestRoundHistory)]
|
||||
assert len(archived) == 1
|
||||
assert archived[0].team == "red"
|
||||
assert archived[0].round_number == 1
|
||||
assert archived[0].attack_success == "successful"
|
||||
assert archived[0].red_summary == "Got a shell."
|
||||
assert archived[0].review_notes == "incomplete evidence"
|
||||
|
||||
assert test.procedure_text is None
|
||||
assert test.tool_used is None
|
||||
assert test.attack_success is None
|
||||
assert test.red_summary is None
|
||||
assert test.red_round_number == 2
|
||||
|
||||
@patch("app.services.test_workflow_service.log_action")
|
||||
def test_reopen_blue_review_archives_round_and_resets_fields(self, mock_log):
|
||||
from app.models.test_round_history import TestRoundHistory
|
||||
|
||||
test = _make_test(
|
||||
TestState.blue_review,
|
||||
detection_result="detected", blue_summary="Caught it via EDR.",
|
||||
)
|
||||
reviewer = _make_user("blue_lead")
|
||||
db = _make_db()
|
||||
|
||||
with patch("app.services.jira_service.push_test_event"), \
|
||||
patch("app.services.jira_service.push_round_archived"):
|
||||
from app.services.test_workflow_service import reopen_blue_review
|
||||
reopen_blue_review(db, test, reviewer, notes="missing containment steps")
|
||||
|
||||
archived = [c.args[0] for c in db.add.call_args_list if isinstance(c.args[0], TestRoundHistory)]
|
||||
assert len(archived) == 1
|
||||
assert archived[0].team == "blue"
|
||||
assert archived[0].round_number == 1
|
||||
assert archived[0].detection_result == "detected"
|
||||
assert archived[0].blue_summary == "Caught it via EDR."
|
||||
assert archived[0].review_notes == "missing containment steps"
|
||||
|
||||
assert test.detection_result is None
|
||||
assert test.blue_summary is None
|
||||
assert test.blue_round_number == 2
|
||||
|
||||
@patch("app.services.test_workflow_service.log_action")
|
||||
def test_reopen_red_review_pushes_round_archived_comment_to_jira(self, mock_log):
|
||||
test = _make_test(TestState.red_review)
|
||||
reviewer = _make_user("red_lead")
|
||||
db = _make_db()
|
||||
|
||||
with patch("app.services.jira_service.push_test_event"), \
|
||||
patch("app.services.jira_service.push_round_archived") as mock_archive:
|
||||
from app.services.test_workflow_service import reopen_red_review
|
||||
reopen_red_review(db, test, reviewer, notes="redo it")
|
||||
|
||||
mock_archive.assert_called_once()
|
||||
|
||||
|
||||
class TestStartBlueWork:
|
||||
@patch("app.services.jira_service.push_bt_work_started")
|
||||
|
||||
Reference in New Issue
Block a user