fix(backend): sprint 3 post-review — migration nullable + dead code + tactic names + tests

- Migration 0003: enforce techniques NOT NULL via batch_alter_table (AC-13.1 DDL spec)
- Migration 0003: remove unused _sims table proxy and orphaned column/table imports
- mitre.py: rename _TACTIC_NAMES → TACTIC_NAMES (public); add all 12 correct display names
- mitre.py: use TACTIC_NAMES dict in _build_matrix() to fix "Command And Control" → "Command and Control"
- test_mitre.py: add T1071 fixture entry under command-and-control; assert tactic_name lowercase "and"
- test_simulations_techniques.py: real Alembic round-trip test asserting techniques NOT NULL after upgrade
This commit is contained in:
Knacky
2026-05-27 04:31:10 +02:00
parent 4596f09e71
commit 393b6ed416
3 changed files with 81 additions and 3 deletions

View File

@@ -70,6 +70,14 @@ _FIXTURE_BUNDLE = {
],
"kill_chain_phases": [],
},
{
"type": "attack-pattern",
"name": "Application Layer Protocol",
"external_references": [
{"source_name": "mitre-attack", "external_id": "T1071"}
],
"kill_chain_phases": [{"phase_name": "command-and-control", "kill_chain_name": "mitre-attack"}],
},
{
# Not an attack-pattern — must be ignored.
"type": "relationship",
@@ -110,7 +118,7 @@ def bundle_file(tmp_path: pathlib.Path) -> pathlib.Path:
def test_load_bundle_success(bundle_file: pathlib.Path) -> None:
mitre_svc.load_bundle(bundle_file)
assert mitre_svc.mitre_loaded is True
assert len(mitre_svc._index) == 5 # 6 attack-patterns minus 1 revoked = 5
assert len(mitre_svc._index) == 6 # 7 attack-patterns minus 1 revoked = 6
def test_load_bundle_missing_file() -> None:
@@ -375,3 +383,12 @@ def test_matrix_endpoint_all_roles(
for token in (redteam_token, soc_token, admin_token):
resp = client.get("/api/mitre/matrix", headers=_h(token))
assert resp.status_code == 200
def test_get_matrix_command_and_control_display_name(bundle_file: pathlib.Path) -> None:
"""MITRE official name uses lowercase 'and' — not title-cased."""
mitre_svc.load_bundle(bundle_file)
matrix = mitre_svc.get_matrix()
c2 = next((t for t in matrix if t["tactic_id"] == "command-and-control"), None)
assert c2 is not None
assert c2["tactic_name"] == "Command and Control"