Files
Aegis/backend/app/models/test_template.py
T
kitos 60f9464ec5
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
refactor(tests): merge detect_suggested_procedure into expected_detection
Two overlapping TestTemplate fields (expected_detection: narrative
guidance from imports/leads; detect_suggested_procedure: concrete
commands from approved suggestions) are now one. Blue-side procedure
suggestions target expected_detection directly, appending onto
whatever is already there rather than overwriting it — same
merge-not-overwrite behavior already used for the red side. Existing
detect_suggested_procedure data is folded into expected_detection
before the column is dropped.
2026-07-15 10:29:13 +02:00

72 lines
3.6 KiB
Python

"""TestTemplate model — predefined test catalog entries."""
# Import uuid
import uuid
# Import Boolean, Column, DateTime, Index, String, Text,... from sqlalchemy
from sqlalchemy import Boolean, Column, DateTime, Index, String, Text, func
# Import UUID from sqlalchemy.dialects.postgresql
from sqlalchemy.dialects.postgresql import UUID
# Import Base from app.database
from app.database import Base
# Define class TestTemplate
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.
"""
# Assign __tablename__ = "test_templates"
__tablename__ = "test_templates"
# Assign id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
# Assign mitre_technique_id = Column(String, nullable=False) # e.g. "T1059.001"
mitre_technique_id = Column(String, nullable=False) # e.g. "T1059.001"
# Assign name = Column(String, nullable=False)
name = Column(String, nullable=False)
# Assign description = Column(Text, nullable=True)
description = Column(Text, nullable=True)
# Assign source = Column(String, nullable=False) # atomic_red_te...
source = Column(String, nullable=False) # atomic_red_team / mitre / custom
# Assign source_url = Column(String, nullable=True)
source_url = Column(String, nullable=True)
# Assign attack_procedure = Column(Text, nullable=True) # Suggested attack procedure
attack_procedure = Column(Text, nullable=True) # Suggested attack procedure
# What blue team should detect — narrative guidance from imports/leads,
# plus concrete commands appended via approved procedure suggestions
# (Blue's counterpart to attack_procedure). External syncs never touch
# an existing row (they only insert brand-new ones), so anything added
# here is safe across re-syncs.
expected_detection = Column(Text, nullable=True)
# Assign platform = Column(String, nullable=True) # windows / linux...
platform = Column(String, nullable=True) # windows / linux / macos
# Assign tool_suggested = Column(String, nullable=True)
tool_suggested = Column(String, nullable=True)
# Assign severity = Column(String, nullable=True) # low / medium / ...
severity = Column(String, nullable=True) # low / medium / high / critical
# Assign atomic_test_id = Column(String, nullable=True) # ID in Atomic Red Team...
atomic_test_id = Column(String, nullable=True) # ID in Atomic Red Team repo
# Assign suggested_remediation = Column(Text, nullable=True)
suggested_remediation = Column(Text, nullable=True)
# Assign is_active = Column(Boolean, default=True)
is_active = Column(Boolean, default=True)
# Assign created_at = Column(DateTime(timezone=True), server_default=func.now())
created_at = Column(DateTime(timezone=True), server_default=func.now())
# Assign __table_args__ = (
__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'),
)