1c8fa436ab
- start_execution now blocks a test from starting before its campaign's start_date, closing a gap where the field was persisted but never enforced - GET /tests gains a reviewer_id "my reviews" filter for the red_review/ blue_review lead-gate stage, distinct from pending_validation_side (which only ever covered the later in_review stage and ignored assignment entirely) - get_coverage_by_tactic now returns all 14 MITRE tactics in canonical kill-chain order instead of an alphabetical, partial list — the regular Dashboard and Executive Dashboard both consume this endpoint and previously disagreed on order/completeness - test-template listing now includes existing_test_count per technique so the catalog can warn before creating a likely-duplicate test
133 lines
4.2 KiB
Python
133 lines
4.2 KiB
Python
"""Pydantic schemas for TestTemplate endpoints."""
|
|
|
|
# Import uuid
|
|
import uuid
|
|
|
|
# Import datetime from datetime
|
|
from datetime import datetime
|
|
|
|
# Import BaseModel, ConfigDict from pydantic
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
# ── Full output ─────────────────────────────────────────────────────
|
|
|
|
|
|
class TestTemplateOut(BaseModel):
|
|
"""Complete representation of a test template."""
|
|
|
|
# id: uuid.UUID
|
|
id: uuid.UUID
|
|
# mitre_technique_id: str
|
|
mitre_technique_id: str
|
|
# name: str
|
|
name: str
|
|
# Assign description = None
|
|
description: str | None = None
|
|
# source: str
|
|
source: str
|
|
# Assign source_url = None
|
|
source_url: str | None = None
|
|
# Assign attack_procedure = None
|
|
attack_procedure: str | None = None
|
|
# Assign expected_detection = None
|
|
expected_detection: str | None = None
|
|
# Assign platform = None
|
|
platform: str | None = None
|
|
# Assign tool_suggested = None
|
|
tool_suggested: str | None = None
|
|
# Assign severity = None
|
|
severity: str | None = None
|
|
# Assign atomic_test_id = None
|
|
atomic_test_id: str | None = None
|
|
# Assign suggested_remediation = None
|
|
suggested_remediation: str | None = None
|
|
# Assign is_active = True
|
|
is_active: bool = True
|
|
# Assign created_at = None
|
|
created_at: datetime | None = None
|
|
|
|
# Assign model_config = ConfigDict(from_attributes=True)
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
# ── Create ──────────────────────────────────────────────────────────
|
|
|
|
|
|
class TestTemplateCreate(BaseModel):
|
|
"""Payload for creating a custom test template."""
|
|
|
|
# mitre_technique_id: str
|
|
mitre_technique_id: str
|
|
# name: str
|
|
name: str
|
|
# Assign description = None
|
|
description: str | None = None
|
|
# Assign source = "custom"
|
|
source: str = "custom"
|
|
# Assign source_url = None
|
|
source_url: str | None = None
|
|
# Assign attack_procedure = None
|
|
attack_procedure: str | None = None
|
|
# Assign expected_detection = None
|
|
expected_detection: str | None = None
|
|
# Assign platform = None
|
|
platform: str | None = None
|
|
# Assign tool_suggested = None
|
|
tool_suggested: str | None = None
|
|
# Assign severity = None
|
|
severity: str | None = None
|
|
# Assign atomic_test_id = None
|
|
atomic_test_id: str | None = None
|
|
# Assign suggested_remediation = None
|
|
suggested_remediation: str | None = None
|
|
|
|
|
|
# ── Summary (for listings) ─────────────────────────────────────────
|
|
|
|
|
|
class TestTemplateSummary(BaseModel):
|
|
"""Lightweight representation for listing templates."""
|
|
|
|
# id: uuid.UUID
|
|
id: uuid.UUID
|
|
# mitre_technique_id: str
|
|
mitre_technique_id: str
|
|
# name: str
|
|
name: str
|
|
# source: str
|
|
source: str
|
|
# Assign platform = None
|
|
platform: str | None = None
|
|
# Assign severity = None
|
|
severity: str | None = None
|
|
# Assign is_active = True
|
|
is_active: bool = True
|
|
# Number of existing Test rows for this template's technique — lets the
|
|
# catalog UI warn before creating a likely-duplicate test.
|
|
existing_test_count: int = 0
|
|
|
|
# Assign model_config = ConfigDict(from_attributes=True)
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
# ── Instantiate (create a real Test from a template) ────────────────
|
|
|
|
|
|
class TestTemplateInstantiate(BaseModel):
|
|
"""Payload to create a real test from an existing template.
|
|
|
|
Optional override fields take precedence over the template values when provided.
|
|
"""
|
|
|
|
# template_id: uuid.UUID
|
|
template_id: uuid.UUID
|
|
# technique_id: str # accepts both UUID and MITRE ID (e.g. "T1059.001")
|
|
technique_id: str # accepts both UUID and MITRE ID (e.g. "T1059.001")
|
|
|
|
# User-editable overrides (if omitted the template value is used)
|
|
name: str | None = None
|
|
description: str | None = None
|
|
platform: str | None = None
|
|
procedure_text: str | None = None
|
|
tool_used: str | None = None
|