fix: auto-detect kill chain phase when adding tests to custom campaigns

This commit is contained in:
2026-02-17 17:53:15 +01:00
parent 222979574a
commit 8f764d8e39

View File

@@ -24,6 +24,7 @@ from app.services.campaign_service import (
validate_no_circular_dependency,
get_campaign_progress,
generate_campaign_from_threat_actor,
TACTIC_TO_PHASE,
)
from app.services.campaign_scheduler_service import calculate_next_run
from app.services.notification_service import create_notification
@@ -331,13 +332,20 @@ def add_test_to_campaign(
if depends_on:
validate_no_circular_dependency(db, uuid.UUID(campaign_id), ct_id, depends_on)
# Auto-detect kill chain phase from the test's technique tactic if not provided
phase = payload.phase
if not phase and test.technique_id:
technique = db.query(Technique).filter(Technique.id == test.technique_id).first()
if technique and technique.tactic:
phase = TACTIC_TO_PHASE.get(technique.tactic, None)
campaign_test = CampaignTest(
id=ct_id,
campaign_id=campaign_id,
test_id=payload.test_id,
order_index=order_index,
depends_on=depends_on,
phase=payload.phase,
phase=phase,
)
db.add(campaign_test)
db.commit()