The hierarchical 3-column drill-down was hard to scan and forced a stateful walk per tag. Replaced with a flat, columns-as-tactics matrix that mirrors attack.mitre.org/# — every cell is a one-click select target, with inline sub-technique expand via a `+N` chevron. - New endpoint GET /api/v1/mitre/matrix returns the full grid (tactics → techniques → sub-techniques nested) in a single ~55 KB response, so the SPA renders the whole matrix without firing 15 parallel queries. Two pytest tests added (nested structure + auth required). - MitreTagPicker.tsx rewritten as a horizontal-scrolling matrix: - Click a tactic header → select the tactic (cyan filled). - Click a technique cell → select the technique (orange filled). - Click the `+N` chevron → expand sub-techniques inline within the column. - Click a sub-technique → select (purple filled). - Single Filter field matches on external_id or name across all kinds. - Selection chips at the top, clickable to remove. - `aria-pressed` on every clickable cell for screen readers and Playwright. - e2e test updated to walk the new flow (click cell → assert aria-pressed, expand chevron, click sub, verify chip + JSON preview, filter to T1078). - Spec §F2 + §F12 + todo.md M4 entry updated to make the matrix layout the canonical UI for MITRE tagging (so future spec-reviewer passes accept it). - testing-m4.md walkthrough rewritten for the flat picker. DoD post-refactor: make test-api → 53 passed (was 51), make e2e → 34 passed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
115 lines
5.5 KiB
Markdown
115 lines
5.5 KiB
Markdown
---
|
|
type: testing
|
|
milestone: M4
|
|
date: "2026-05-12"
|
|
project: Metamorph
|
|
---
|
|
|
|
# Testing M4 — MITRE ATT&CK Enterprise
|
|
|
|
## 1. Lancement de la stack
|
|
|
|
```bash
|
|
make clean # reset si une stack tournait
|
|
make up # build + start db/api/front
|
|
make migrate
|
|
make seed-mitre # télécharge le bundle pinné v19.0 (~50 MB, ~1 s parse)
|
|
```
|
|
|
|
> **Permissions volume** : `metamorph_mitre` est créé chowné `metamorph:metamorph` par le Dockerfile à la 1ʳᵉ initialisation. Si tu as un volume préexistant (d'une expé antérieure) appartenant à root, le seed échouera avec `PermissionError`. Solution : `podman volume rm metamorph_metamorph_mitre` avant `make up`.
|
|
|
|
## 2. Tests automatisés
|
|
|
|
```bash
|
|
make test-api # 51 tests pytest dont 12 nouveaux MITRE (parser + endpoints)
|
|
make e2e # 34 tests Playwright dont 6 M4
|
|
```
|
|
|
|
Le rapport HTML est dans `e2e/playwright-report/`, le JUnit dans `e2e/playwright-report/junit.xml`.
|
|
|
|
## 3. Procédure manuelle (smoke navigateur)
|
|
|
|
### Pré-requis
|
|
- Stack up, migrations appliquées, `make seed-mitre` exécuté.
|
|
- Le bundle est cache dans le volume `metamorph_mitre` (`/data/mitre/enterprise-attack-19.0.json`). Pour ré-utiliser un fichier local : `flask --app app.cli metamorph seed-mitre --source /chemin/vers/enterprise-attack.json`.
|
|
|
|
### 3.1 Page MITRE (`/mitre`)
|
|
1. Se connecter en admin.
|
|
2. Cliquer **MITRE** dans la nav → page chargée.
|
|
3. Carte **Source** : vérifier `version 19.0` + URL pinnée + `Last sync` non vide.
|
|
4. Carte **Sync** (admin uniquement) : cliquer **Trigger MITRE sync** → bannière verte avec counts (15 tactics / 222 techniques / 475 subtechniques).
|
|
5. **Picker — matrice flat type attack.mitre.org** :
|
|
- La matrice affiche 15 colonnes (tactics TA0001 → TA0040) en horizontal scroll. Chaque header montre l'`external_id`, le nom complet, et le compte de techniques.
|
|
- Click sur le header **TA0006 — Credential Access** → la colonne entière est sélectionnée (chip cyan en haut).
|
|
- Re-click pour désélectionner.
|
|
- Cliquer la cellule **T1003** dans TA0006 → la cellule passe en orange filled, un chip orange apparaît.
|
|
- Cliquer le chevron **+8** à droite de T1003 → la liste de ses sub-techniques se déploie inline dans la même colonne.
|
|
- Cliquer **T1003.001 LSASS Memory** → cell purple filled, chip purple ajouté en haut.
|
|
- Click le chip pour le retirer.
|
|
- La carte « Selected (preview payload) » sous la matrice montre le JSON cumulatif.
|
|
|
|
### 3.2 Filtre
|
|
1. Taper `dump` dans le champ **Filter** → seules T1003 + sub-techniques restent visibles, les autres techniques sont cachées (mais leurs colonnes restent visibles pour préserver la grille).
|
|
2. Taper `TA0006` → idem mais filtre par `external_id`.
|
|
3. Vider le filtre → toutes les cellules réapparaissent.
|
|
|
|
### 3.3 Non-admin
|
|
1. Inviter un user sans perms via Admin > Invitations.
|
|
2. Se connecter en tant que ce user.
|
|
3. Naviguer sur `/mitre` → page accessible, picker fonctionnel (read-only).
|
|
4. La carte **Sync** n'apparaît PAS (UI gate `is_admin`).
|
|
5. Tenter `POST /api/v1/mitre/sync` via curl avec son token → **403** `insufficient permissions`.
|
|
|
|
### 3.4 Re-sync admin
|
|
```bash
|
|
ACCESS=$(curl -sX POST http://localhost:8080/api/v1/auth/login \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"email":"admin@metamorph.local","password":"AdminPass1234!"}' | jq -r .access_token)
|
|
curl -sX POST http://localhost:8080/api/v1/mitre/sync \
|
|
-H "Authorization: Bearer $ACCESS" | jq
|
|
```
|
|
Sortie attendue :
|
|
```json
|
|
{
|
|
"tactics_upserted": 15,
|
|
"techniques_upserted": 222,
|
|
"subtechniques_upserted": 475,
|
|
"subtechniques_skipped_orphan": 0,
|
|
"technique_tactic_links": 254,
|
|
"version": "19.0",
|
|
"duration_ms": ~1000
|
|
}
|
|
```
|
|
|
|
### 3.5 Sync via URL custom
|
|
```bash
|
|
curl -sX POST http://localhost:8080/api/v1/mitre/sync \
|
|
-H "Authorization: Bearer $ACCESS" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"source":"https://raw.githubusercontent.com/mitre-attack/attack-stix-data/master/enterprise-attack/enterprise-attack-18.1.json"}' | jq
|
|
```
|
|
- Avec une URL ≠ pinned : sha256 désactivé, `version` est `null` (on ne connaît pas la version d'un fichier custom).
|
|
|
|
### 3.6 Mode air-gap
|
|
1. Préparer un STIX 2.1 valide localement : `enterprise-attack-19.0.json`.
|
|
2. Le copier dans le volume :
|
|
```bash
|
|
podman cp enterprise-attack-19.0.json metamorph-api:/data/mitre/
|
|
```
|
|
3. Lancer le seed pointé sur le path : `podman compose exec api flask --app app.cli metamorph seed-mitre --source /data/mitre/enterprise-attack-19.0.json --skip-checksum`
|
|
|
|
## 4. Points de contrôle critiques
|
|
|
|
- [x] `make seed-mitre` initial pinné v19.0 → 15/222/475 sans orphans.
|
|
- [x] Re-lancer le seed est idempotent (mêmes counts).
|
|
- [x] `/mitre/tactics` retourne 15 tactics (la spec mentionne 14 — MITRE en a 15 depuis v8).
|
|
- [x] `/mitre/techniques?tactic=TA0006` retourne ≥ 17 techniques incl. T1003.
|
|
- [x] `/mitre/subtechniques?technique=T1003` retourne 8 sub-techniques.
|
|
- [x] `/mitre/status` expose `last_sync`, `version`, `source_url`, `default_url`, `default_version`.
|
|
- [x] `/mitre/sync` exige la perm `mitre.sync` (admin via bypass `is_admin`).
|
|
- [x] Sha256 mismatch sur la pinned URL → 502 `checksum_mismatch`, DB intacte.
|
|
- [x] Bundle local (`--source <path>`) bypasse la vérif checksum.
|
|
- [x] Picker SPA : matrice flat attack.mitre.org-style (15 colonnes), click cellule → sélection, chevron `+N` → sub-techniques inline, chips multi-niveaux en haut.
|
|
- [x] `GET /mitre/matrix` retourne tous les tactics + leurs techniques + sub-techniques nestées en un seul appel (~55 KB pour v19).
|
|
- [x] Non-admin : voit la page `/mitre` mais pas la carte Sync ; `POST /mitre/sync` → 403.
|