T-106: Create test_workflow_service.py with state-machine transitions for the complete test lifecycle (draft -> red_executing -> blue_evaluating -> in_review -> validated/rejected), dual validation by Red/Blue leads, and reopen capability with field cleanup. T-107: Update status_service.py to use detection_result from Blue Team instead of legacy result field, and differentiate between partial progress (some validated) vs all-in-progress states. T-108: Create atomic_import_service.py that downloads the Atomic Red Team repo as a ZIP (avoiding API rate limits), parses all atomics YAML files, and creates idempotent TestTemplate records mapped to MITRE techniques. Includes validation tests for all three tasks (19 checks total).
46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
"""TestTemplate model — predefined test catalog entries."""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import Column, String, Text, Boolean, DateTime, Index
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class TestTemplate(Base):
|
|
"""
|
|
Predefined test template mapped to a MITRE ATT&CK technique.
|
|
|
|
Templates come from several sources:
|
|
- **atomic_red_team**: Atomic Red Team by Red Canary
|
|
- **mitre**: MITRE ATT&CK procedure examples
|
|
- **custom**: Manually created by teams
|
|
|
|
Users can instantiate a real Test from a template.
|
|
"""
|
|
__tablename__ = "test_templates"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
mitre_technique_id = Column(String, nullable=False) # e.g. "T1059.001"
|
|
name = Column(String, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
source = Column(String, nullable=False) # atomic_red_team / mitre / custom
|
|
source_url = Column(String, nullable=True)
|
|
attack_procedure = Column(Text, nullable=True) # Suggested attack procedure
|
|
expected_detection = Column(Text, nullable=True) # What blue team should detect
|
|
platform = Column(String, nullable=True) # windows / linux / macos
|
|
tool_suggested = Column(String, nullable=True)
|
|
severity = Column(String, nullable=True) # low / medium / high / critical
|
|
atomic_test_id = Column(String, nullable=True) # ID in Atomic Red Team repo
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
__table_args__ = (
|
|
Index('ix_test_templates_mitre_technique_id', 'mitre_technique_id'),
|
|
Index('ix_test_templates_source', 'source'),
|
|
Index('ix_test_templates_platform', 'platform'),
|
|
Index('ix_test_templates_severity', 'severity'),
|
|
)
|