Commit Graph
38 Commits
Author SHA1 Message Date
arnaud.dartois 1d60f04691 fix(auth): safely report cookie sign-in failures (#310)
Heimdall Gitea / Detect CI scope (push) Successful in 33s
Heimdall Gitea / Build and tests (push) Successful in 26m42s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 8m45s
Heimdall Gitea / Build and scan agent image (push) Successful in 9m14s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m34s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m37s
Heimdall Gitea / CI policy (push) Successful in 2s
## Résumé
Le flux navigateur reçoit maintenant un résultat HTTP explicite du pont cookie; les échecs de cookie sont diagnostiqués sans exposer les messages d’exception ni les données de session. La validation 2FA par code de récupération recharge également l’utilisateur après rotation du security stamp avant d’émettre la session.

## Issue
Refs #304 — l’observation GlitchTip post-déploiement reste nécessaire avant résolution.

## Travail effectué
- `/_auth/signin` renvoie des erreurs génériques et journalise uniquement l’étape et le type d’exception.
- Le pont JavaScript retourne le statut HTTP; les interruptions de circuit sont distinctes des réponses non-2xx.
- Suppression des adresses e-mail des journaux auth/2FA.
- Correction du chemin code de récupération 2FA pour émettre un jeton cohérent avec le security stamp actualisé.
- Ajout de tests unitaires et d’intégration; documentation dans `skills/heimdall-identity/SKILL.md`.

## Preuves
- `dotnet restore tests/Heimdall.Web.Tests/Heimdall.Web.Tests.csproj --locked-mode` — réussi.
- `dotnet restore tests/Heimdall.IntegrationTests/Heimdall.IntegrationTests.csproj --locked-mode` — réussi.
- `AuthHelperTests` — 6/6 réussis.
- Tests d’intégration ciblés 2FA/recovery-cookie/TOTP-cookie/token malformé — 3/3 réussis.
- Acceptance Compose source-built `heimdall-auth-cookie-20261108170745-28547` — bootstrap 200, TOTP 200, cookie sign-in 200, API avec cookie 200, jeton malformé 401 générique, secrets absents des logs. Nettoyage vérifié: conteneurs/volumes/réseau absents et tag `heimdall:heimdall-auth-cookie-20261108170745-28547-central` supprimé.
- Analyse de l’événement GlitchTip: le circuit navigateur se déconnecte avant toute trace HTTP observée de `/_auth/signin`; la cause de cette occurrence production reste donc non démontrée. La correction améliore la visibilité sûre et le flux synthétique, sans prétendre reproduire cet événement.

## À suivre
Après déploiement de ce commit, observer GlitchTip pendant au moins sept jours et vérifier si HEIMDALL-DU réapparaît. Ne pas résoudre l’issue avant cette preuve réelle.

Reviewed-on: #310
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-08 20:03:03 +01:00
arnaud.dartois 4498e39d34 fix(auth): streamline cookie session validation (#273)
Heimdall Gitea / Detect CI scope (push) Successful in 5s
Heimdall Gitea / Build and tests (push) Successful in 17m43s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 5m55s
Heimdall Gitea / Build and scan agent image (push) Successful in 7m37s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m19s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 18m33s
Heimdall Gitea / CI policy (push) Successful in 2s
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-07 08:35:19 +01:00
arnaud.dartois 636154572b Complete remaining Heimdall features and acceptance
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00
arnaud.dartois 89c4c43922 fix(identity): harden user lifecycle and permissions (#136)
Heimdall Gitea / Detect CI scope (push) Successful in 7s
Heimdall Gitea / Build and tests (push) Successful in 14m48s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 4m27s
Heimdall Gitea / Build and scan agent image (push) Successful in 15m42s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m27s
Heimdall Gitea / CI policy (push) Successful in 2s
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-04 13:33:30 +01:00
Arnaud Dartois 8195ee4ab8 feat(auth): require initial administrator setup
Heimdall Gitea / Detect CI scope (pull_request) Successful in 4s
Heimdall Gitea / Build and tests (pull_request) Successful in 20m32s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m36s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 11m34s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 2s
2026-10-27 22:19:52 +01:00
Arnaud Dartois 1d5f995af4 test(health): update seeded settings in integration tests
Heimdall Gitea / Detect CI scope (pull_request) Successful in 4s
Heimdall Gitea / Build and tests (pull_request) Successful in 13m1s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 4m32s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 11m19s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 1s
2026-10-25 20:44:31 +01:00
Arnaud Dartois 6b2a37823b test(health): cover readiness and agent degradation
Heimdall Gitea / Detect CI scope (pull_request) Successful in 4s
Heimdall Gitea / Build and tests (pull_request) Failing after 5m5s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 2s
2026-10-25 20:33:40 +01:00
Arnaud Dartois b793bae739 Connect manual camera snapshots to agent capture
Heimdall Gitea / Build and tests (pull_request) Failing after 56s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
2026-10-23 07:20:47 +02:00
Arnaud Dartois 88da58723f Store detection snapshots in managed storage
Heimdall Gitea / Build and tests (pull_request) Failing after 1m26s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
2026-10-22 20:50:40 +02:00
Arnaud Dartois cb1a4dd2ad Merge remote-tracking branch 'origin/main' into audit/snapshot-gallery
Heimdall Gitea / Build and tests (pull_request) Failing after 2m41s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
# Conflicts:
#	tests/Heimdall.IntegrationTests/Controllers/EventsControllerTests.cs
2026-10-20 21:06:20 +02:00
Arnaud Dartois 99aa8d4b28 test(gallery): verify translated snapshot search paging 2026-10-20 21:00:38 +02:00
Arnaud Dartois 5c533a8167 Merge remote-tracking branch 'origin/main' into audit-build-gitea
Heimdall Gitea / Publish versioned release (pull_request) Canceled after 0s
Heimdall Gitea / Build and tests (pull_request) Canceled after 2h17m47s
2026-10-20 07:39:27 +02:00
Arnaud Dartois a717653dc9 test(ci): align unknown-resource reception with forbidden security contract 2026-10-20 07:38:05 +02:00
Arnaud Dartois 26321bb81c fix(auth): secure 2FA challenges and session revocation 2026-10-20 07:21:28 +02:00
Arnaud Dartois 80e21d63e6 fix(tests): repair PersonsController integration tests and fix EF concurrency on RegisterFace
- Add DbUpdateConcurrencyException to SaveChangesWithRetryAsync transient check
- RegisterFaceHandler adds KnownFace via DbContext Set to avoid phantom UPDATE
- Validate empty embedding (400) before person existence check
- CreateViewerClientAsync bootstraps admin first so 2nd user is Viewer
- Rename GetAll_WithViewerAuth test to match PersonRead permission on Viewer
- PersonsControllerTests: all 20 tests green
2026-10-10 19:47:09 +02:00
Arnaud Dartois a5f1d0ff74 test(api): add integration tests for PersonsController
- Add CreateViewerClientAsync helper to TestHelpers
- 12 new integration tests: faces CRUD, vehicles, events filter,
  permissions (Viewer forbidden), cascade delete, audit logging
2026-10-10 17:50:43 +02:00
Arnaud Dartois f54bb596af feat(cameras): activer/désactiver une caméra depuis la liste (toggle status) (#151)
## Résumé

Ajoute un bouton toggle (play/stop) dans chaque tuile de la liste des caméras pour activer/désactiver une caméra directement depuis la vue liste, sans passer par la page détail.

## Changements

### API
- **`POST /api/cameras/{id}/toggle-status`** — endpoint dédié qui bascule entre `Online` et `Disabled`
- `ToggleCameraStatusCommand` + handler (Application layer)
- `ToggleCameraStatusAsync` dans `HeimdallApiClient`

### UI
- **`CameraTile.razor`** — bouton toggle ajouté (play/stop) entre View et Snapshot
- **`CamerasPage.razor`** — callback `OnToggleStatus` câblé + snackbar feedback
- **`CameraDetail.razor`** — migré vers le nouvel endpoint dédié (au lieu de `UpdateCameraAsync` avec status)

### Tests
- 4 unit tests (`ToggleCameraStatusCommandTests`)
- 2 integration tests (toggle + 404)
- Fix bUnit `CameraDetailTests` (mock PUT → POST)

## Closes
- Issue #59

Reviewed-on: https://forgejo.tordais.cc/nonobis/Heimdall/pulls/151
2026-08-19 22:38:34 +02:00
Arnaud Dartois a4503e76ac fix(ci): répare 31 tests cassés — 401 API, login prerender off, culture bUnit
Trois régressions distinctes cassent la CI depuis le run 207 :

1. Auth API (29 tests d'intégration) : depuis 16d739e, les contrôleurs
   acceptent JwtBearer+Cookies ; le challenge par défaut étant le cookie,
   les requêtes API non authentifiées étaient redirigées 302 vers /login
   au lieu de répondre 401/403 (le client de test suivait → 200 OK).
   → IsApiRequest() dans OnRedirectToLogin/OnRedirectToAccessDenied :
     requête /api/* ou Accept: application/json → 401/403 direct.

2. Get_LoginPage_ReturnsOk : depuis db703be (prerender:false), /login sert
   le shell Blazor sans le contenu du composant en SSR. Le test vérifie
   désormais le shell (_framework/blazor.web.js) au lieu de 'Se connecter'.

3. Tests bUnit (2) : le runner CI a une locale fr-FR → {Confidence:P0}
   rend '87 %' au lieu de '87%'. MudTestBase force en-US (statique +
   thread courant) pour un rendu déterministe partout.

Vérifié : 1042/1042 tests verts, y compris sous LANG=fr_FR.UTF-8.
2026-08-11 12:35:45 +02:00
Arnaud Dartois 53b6240a3e fix(auth): répare l'authentification de bout en bout (cookie + JWT + rendu Blazor)
Anomalies corrigées :
- MudPopoverProvider manquant dans les layouts → circuit Blazor mourait sur
  l'ouverture de menus/popovers (dashboard jamais rendu après login)
- AddIdentity redéfinissait le schéma par défaut sur Identity.Application
  alors que /_auth/signin signait avec Cookies → cookie posé mais jamais
  validé, tout rechargement de page redirigeait vers /login. Forçage du
  schéma par défaut sur Cookies + schémas JwtBearer explicites sur les
  endpoints API d'AuthController et SettingsController
- Policy 'AdminUsers' utilisée par register-admin mais jamais enregistrée
  → 500 à l'appel. Ajoutée (RequireRole Admin)
- HeimdallAuthStateProvider ne lisait que le sessionStorage navigateur :
  pendant le prerender SSR, HttpContext.User (cookie) n'était pas utilisé
  → pages protégées redirigées vers /login. Fallback cookie ajouté
- SameOriginHttpMessageHandler : résolution de l'origine via
  IServerAddressesFeature quand IHttpContextAccessor est null (circuit
  Blazor post-hydratation) au lieu de heimdall.local → DNS cassé
- UpdateUserValidator rejetait le thème 'Auto' (défaut de l'UI) → 400
  à l'édition. Accepte désormais auto (case-insensitive)

Tests :
- E2E Playwright complets (login/logout/register/user management) : 33/33
- Integration (Testcontainers PostgreSQL) : 120/120 (valeur 'bool' du
  valueType, bootstrap admin via /register auto-admin, header X-API-Key,
  /proc/meminfo optionnel pour les LXC restreints)
- Exécution E2E séquentielle (xunit.runner.json) pour éliminer le flakiness
2026-08-09 23:43:11 +02:00
Arnaud Dartois 64753b9ba6 fix(ci): reparation tests integration + infrastructure
- TestHelpers.CreateAdminClientAsync: bootstrap via register normal
  (first user = admin) + active les flags public-registration et
  admin-registration.enabled
- JwtService.GetUserIdFromExpiredToken: utilise GetJwtRefreshKey()
  (methode appelee avec refresh tokens, signes avec Jwt:RefreshKey)
- AuthDataServiceTests.RevokeRefreshTokenAsync_StoresToken:
  utilise SHA256 hash (nouveau comportement ExtractJti fallback)
2026-07-28 15:14:54 +00:00
Arnaud Dartois ba985ed3c2 fix(auth): RegisterAdmin — [Authorize] + feature flag auth.admin-registration.enabled
#14: Remplacé le guard environment (Testing/Development) par:
- [Authorize(Policy = "AdminUsers")] sur l'endpoint
- Feature flag auth.admin-registration.enabled en DB (default: absent = disabled)
- Suppression de la dependance IWebHostEnvironment du controller
- Test mis a jour: bootstrap via register normal, puis flag, puis RegisterAdmin
2026-07-28 14:57:28 +00:00
Arnaud Dartois a6b2a21ebc fix: corriger les issues mineures du review
🟡 SnapshotUrl: validation sécurité SSRF (scheme + loopback)
🟡 Integration tests: skip graceful sans PostgreSQL (TestContainers)
2026-07-27 09:09:14 +00:00
Arnaud Dartois d0da78188a test(auth): add integration tests for authentication redirect flow
Add AuthFlowTests to catch Blazor redirect bugs:
- Get_Root_WithoutAuth_RedirectsToLogin: unauthenticated GET /
  must redirect to /login (would have caught the /Account/Login bug)
- Get_LoginPage_ReturnsOk: verify login page renders
- Get_ProtectedApi_WithoutAuth_ReturnsUnauthorized: API auth check
- RegisterAdmin_ThenLogin_ReturnsJwt_AndAccessesProtectedApi:
  full auth flow with JWT token refresh
- Register_WithWeakPassword_ReturnsBadRequest: password validation
- Register_ReturnsValidAuthResponse: success path
2026-07-24 19:39:47 +00:00
Arnaud Dartois 06247d4f5c test(web): add Web.Tests unit tests and extended IntegrationTests 2026-07-23 15:27:34 +00:00
Arnaud Dartois 649af93f56 feat(cqrs): add MediatR, AutoMapper and pipeline infrastructure
- Add MediatR 12.5.0, AutoMapper 13.0.1 packages
- Create ValidationBehavior (FluentValidation pipeline)
- Create LoggingBehavior (structured logging pipeline)
- Create MappingProfile with IMapFrom<T> convention
- Make ServiceResult properties public for pipeline use
- Update Application DI with MediatR + AutoMapper registration
2026-07-22 19:31:51 +00:00
Arnaud Dartois b167c2afcf fix: share one PostgreSQL Testcontainer across all test projects
Create Heimdall.TestCommon project with a single PostgreSqlContainerFixture
shared by both Infrastructure and Integration tests. This prevents Docker
resource conflicts from starting two PostgreSQL containers and ensures
both test suites connect to the same database instance.

- Move shared fixture to tests/Heimdall.TestCommon
- Remove duplicate fixtures from each test project
- Keep test isolation (truncation) and FK fix from previous commit
- Revert DATABASE_URL env var check (Testcontainers works in CI)
2026-07-21 18:48:39 +00:00
Arnaud Dartois 53e0d4c199 fix: resolve CI test failures after InMemory->Testcontainers migration
Three issues fixed:
- Camera.AssignAgent(Guid.Empty) violated FK constraint; changed to
  nullable Guid? and pass null on camera release
- Test fixtures now check DATABASE_URL env var first, falling back to
  Testcontainers locally (CI has no Docker socket)
- Added database truncation before each test via IAsyncLifetime to
  prevent shared state between test methods (InMemory was fresh per test,
  real PostgreSQL persists data)
2026-07-21 17:46:32 +00:00
Arnaud Dartois 58a3ce5b1b chore: vire toute trace d'InMemory, remplace par Testcontainers PostgreSQL
- Supprime InMemory de tous les .csproj (Infrastructure, Domain.Tests, IntegrationTests)\n- Supprime le branchement Database:Provider=InMemory de DependencyInjection.cs\n  (plus que du PostgreSQL natif)\n- Infrastructure.Tests: CameraAssignment + CameraEvent tests -> Testcontainers\n- PostgreSqlContainerFixture ajoute aux Infrastructure.Tests\n- appsettings.Testing.json: retire Database:Provider et Hangfire:Enabled\n- 4 tests echouent encore: bugs pre-existants masques par InMemory\n  (FK non respectees, donnees de test erronees)\n\nTests: 222/226 passed (4 pre-existants lies aux FK)
2026-07-21 12:19:43 +00:00
Arnaud Dartois ee7894646f test: remplace InMemory par Testcontainers PostgreSQL
- Ajoute Testcontainers.PostgreSql v4.13.0\n- PostgreSqlContainerFixture: collection fixture xUnit avec postgres:17-alpine\n- HeimdallWebApplicationFactory: accepte connectionString pour vrai PostgreSQL\n- PostgresTestBase: classe de base pour tous les tests integration\n- Ajoute [Collection("Postgres")] aux 9 classes de test\n- Database:MigrateOnStartup active quand PostgreSQL est utilise\n- Programme le Hangfire (skip en test via isTesting)\n\nAvant: InMemory (pas de contraintes, comportement different)\nApres: Vrai PostgreSQL dans un container temporaire\n\nTests: 226/226 passed (61 integration avec vrai PostgreSQL)
2026-07-21 10:24:11 +00:00
Arnaud Dartois a33a436c26 chore: apply auto-fixes and code improvements
- AuthService: fix public registration logic revert
- JwtService: add ILogger dependency
- SoftDeleteInterceptor removed (merged)
- XML doc comments on all services
- Error boundary + error page in Blazor
- Optimize StatsService queries
- ApiClient error handling improvements
2026-07-20 09:50:43 +00:00
Arnaud Dartois ba968a5f23 fix(security): harden Docker, CSRF, EventsHub scoping, secret logging, tests
- Docker: remove default passwords from prod compose (required env vars)
- CSRF: validate antiforgery tokens on /_auth/signin and /_auth/signout
- EventsHub: broadcast to site-scoped Group() instead of Clients.All
- SettingsController: redact secret values in logs
- Create SetAgentSettingValidator + UpdateAppSettingValidator classes
- Replace 3 placeholder test projects with meaningful tests
- Remove FluentValidation auto-validation (incompatible with .NET 10)
2026-07-19 20:53:48 +00:00
Arnaud Dartois 8ac8baf20a feat(storage): add S3 snapshot service and comprehensive tests for phases 2-3
Adds S3-compatible snapshot storage (Alarik) with AWS Signature V4,
upload, thumbnail, and delete operations. Backfills Phase 2 & 3 with
27 new tests covering camera assignment strategies, event CRUD with
filtering, snapshot attachment, and API contract validation.

- SnapshotService with S3 REST API via HttpClient + SigV4 signing
- 10 unit tests for CameraAssignmentService (assign, release, failover, history)
- 9 unit tests for CameraEventService (create, query, filter, delete, snapshot)
- 8 integration tests for AssignmentsController + EventsController
- SnapshotService registration with 5-min timeout HTTP client
2026-07-19 13:14:05 +00:00
Arnaud Dartois 2152fca3c6 feat(discovery): implement camera detection and dedup pipeline
Manual camera configuration does not scale beyond a few devices.
Automated discovery is needed to support deployments with 50+
cameras across heterogeneous protocols (ONVIF, mDNS, HTTP, ARP).

Phase 1 introduces 5 network probe services, a stream tester, an
orchestrating discovery service with IP+MAC deduplication, 11 REST
endpoints, a pre-verification endpoint, 57 tests, and DI registration.
2026-07-19 12:00:16 +00:00
Arnaud Dartois c2837af089 feat(mvp): complete MVP hardening — API, Web, config system, SignalR, tests 2026-07-18 18:58:20 +00:00
Arnaud Dartois da123ec544 fix(tests): InMemory DB isolation + refactor test helpers
- Fix: InMemory database name now unique per test factory instance
  (was using process-wide env var, now per-host config via UseSetting)
- Refactor: all integration tests use shared TestHelpers.CreateAdminClientAsync
- New: register-admin endpoint (test/dev only) creates Admin users directly
- New: TestHelpers.cs with extension method for admin client creation
- Cleanup: removed bootstrap template files, old Counter/Weather pages
- Cleanup: simplified app.css with MudBlazor-only styles
- Seed: demo admin + demo site created in Development mode
2026-07-17 13:15:25 +00:00
Arnaud Dartois d4a86b8c7f feat(mvp): docker-compose snippet in UI, agent flow tests
- Site detail: generate registration token with copy/paste docker-compose snippet
- Docker snippet: pre-filled with token + agent hostname, ready to copy
- Agents integration tests: register with valid token, heartbeat with API key,
  invalid token rejection (3 new tests)
- TokenResult DTO for API client
- IJSRuntime clipboard copy for docker-compose snippet
2026-07-17 07:00:58 +00:00
Arnaud Dartois 6d5ec0c201 feat(mvp): cameras API, Docker production, tests, security, Makefile
- Cameras API: CRUD with service/controller/DTOs + Blazor page
- Docker: production-grade compose with healthchecks, .env, Makefile, networks
- Healthchecks: /healthz (liveness) and /readyz (readiness) endpoints
- Testing: 13 integration tests (Auth, Sites, Users, Cameras controllers)
  - Users: create, list, lock, reset-password
  - Cameras: create with site, list by site
- Environment: .env.example, docker-compose.override.yml for dev
- Infrastructure: ICameraService registered in DI
2026-07-17 06:18:56 +00:00
Arnaud Dartois 38816aec8a feat(mvp): complete Blazor UI + User Management + integration tests 2026-07-16 21:19:16 +00:00