Commit Graph
45 Commits
Author SHA1 Message Date
Arnaud Dartois b851a20dde test(web): add bUnit tests for StatusChip and FilterBar with ManualMockKeyInterceptorService 2026-07-23 20:40:56 +00:00
Arnaud Dartois 3d7137a865 test(web): add bUnit shared component tests for PaginationBar, EmptyState, LoadingSkeleton, SectionCard 2026-07-23 19:38:30 +00:00
Arnaud Dartois 0745903fef test: add remaining handler tests for Users, Groups, Persons, Assignments, Discovery; more Agent + E2E tests 2026-07-23 19:19:05 +00:00
Arnaud Dartois a94afed6b5 test(e2e): add Playwright E2E tests for Blazor pages; refactor Program.cs to support test server 2026-07-23 18:12:47 +00:00
Arnaud Dartois 262adc07cf test(agent): add service tests for CameraStream, ConfigReceiver, FrameAnalyzer, SystemMetrics, DTOs 2026-07-23 15:37:20 +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 5d06c39160 test(infrastructure): add service tests for Security, Data, Discovery, Jobs layers 2026-07-23 15:08:09 +00:00
Arnaud Dartois fed55bb1ab test(application): add CQRS handler tests for Sites, Cameras, Agents, Auth, Events, Settings, Groups, Users, Assignments, Discovery, Persons, Stats, Audit 2026-07-23 14:32:33 +00:00
Arnaud Dartois ddd0664a71 fix(test): replace NSubstitute-based DbSet mock with InMemoryDbSet - fixes nested substitution issue 2026-07-23 14:22:21 +00:00
Arnaud Dartois d9c2a24949 test(application): add MockDbSetHelper and CreateSiteHandler tests 2026-07-23 09:59:30 +00:00
Arnaud Dartois 7da799c0c4 test(application): add AutoMapper mapping profile validation tests 2026-07-23 09:56:11 +00:00
Arnaud Dartois 6ba08d1f39 test(application): add ValidationBehavior and LoggingBehavior pipeline tests 2026-07-23 09:54:47 +00:00
Arnaud Dartois 7328c12dbf test(application): add ServiceResult and ServiceResult<T> unit tests 2026-07-23 09:53:07 +00:00
Arnaud Dartois a44414a543 test(domain): add entity tests for CameraAssignment, CameraCredentials, CameraEvent, Group, Person, CameraDiscoveryResult, DiscoveredStreamUrl, UserGroup, CameraDetectionProfile; augment CameraTests and AgentTests 2026-07-23 09:52:30 +00:00
Arnaud Dartois 1525fabffe test(domain): add ApiKey, AppSetting, AgentSetting, AuditLog, RevokedRefreshToken entity tests 2026-07-23 09:50:43 +00:00
Arnaud Dartois 3cedffb43c test(domain): add enum values tests for all 11 enum types 2026-07-23 09:49:35 +00:00
Arnaud Dartois c02ebe460e test(domain): add Entity<TId> and ValueObject equality tests 2026-07-23 09:48:58 +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 0ef4642f6d fix(tests): restore DATABASE_URL fallback for CI in shared PostgreSqlContainerFixture
The shared fixture (Heimdall.TestCommon) was refactored from per-project
fixtures but lost the DATABASE_URL env var check. Without it, the fixture
always starts a Testcontainers PostgreSQL container, which fails in CI
when Docker disk space is exhausted (initdb: No space left on device).

Now checks DATABASE_URL first — if set (CI mode), skips Testcontainers
and uses the CI-provided PostgreSQL service. Falls back to Testcontainers
for local development.
2026-07-21 19:59:27 +00:00
Arnaud Dartois 6825880b52 fix: share single PostgreSQL container across test projects via static ref-count
Use a static PostgreSqlContainer with reference counting so both
Infrastructure and Integration test projects share one PostgreSQL
container instead of each starting their own. Fixes resource
conflict in CI where only the first test project could connect.
2026-07-21 19:05:54 +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 7be5d42e85 fix(identity): DB refresh tokens, auto-refresh handler, 2FA endpoints, JWT fix
- DB-backed RevokedRefreshToken entity + migration (remplace ConcurrentDictionary\n  en memoire, fonctionne en multi-instance et survive aux redemarrages)\n- TokenRefreshHandler: auto-refresh des JWT 401 via DelegatingHandler\n  (avec SemaphoreSlim pour eviter les refresh storms)\n- Fix: GenerateRefreshToken genere maintenant un JWT valide au lieu de\n  bytes aleatoires (ValidateRefreshToken attendait un JWT - flux casse)\n- Fix: Login.razor gere Requires2fa correctement (affiche champ code 2FA)\n- Ajout: endpoints POST /api/auth/2fa/enable et /2fa/disable\n- Ajout: Disable2faAsync dans IAuthService\n- Fix: GenerateTemporaryPassword garantit les 4 categories de charactere\n  (uppercase, lowercase, digit, non-alphanumeric)\n- Fix: TestFactory ajoute Jwt:RefreshKey manquant\n\nBuild: 0 errors, 0 warnings\nTests: 226/226 passed
2026-07-21 08:57:53 +00:00
Arnaud Dartois 1d70455abb fix(web): make integration tests work with Heimdall.Web as entry point
- Add InternalsVisibleTo for Heimdall.Api.Tests and
  Heimdall.IntegrationTests in Web.csproj
- Add partial class Program for WebApplicationFactory<Program>
- Pass builder.Environment.EnvironmentName instead of env var
  so AddInfrastructure correctly detects Testing environment
- Skip DATABASE_URL check, Hangfire setup, migrations, and
  recurring jobs when environment is Testing
- Update test project references from Heimdall.Api to Heimdall.Web
2026-07-20 20:32:32 +00:00
Arnaud Dartois 630e7987fe refactor(docker): merge worker and web into single heimdall image
Combine Heimdall.Web and Heimdall.Workers into one process/image.
Hangfire background jobs now run inside the web process.

- Move job classes to Infrastructure/Jobs/ (no Worker SDK dependency)
- Add Hangfire server + recurring jobs to Web/Program.cs
- Add missing AddInfrastructure/AddApplication DI registrations to Web
- Rename image: heimdall (was heimdall-web / heimdall-workers)
- Remove src/Heimdall.Workers project entirely
- Remove tests/Heimdall.Workers.Tests (placeholder)
- Simplify Dockerfile: single build target, no workers publish
- Update docker-compose files: one service heimdall, no workers
- Update Makefile, .env.example
2026-07-20 17:22:56 +00:00
Arnaud Dartois 562aabdfc8 feat(api+web): merge REST API and Blazor UI into single process
Previously the API (heimdall-central) and Blazor UI (heimdall-web) ran as
separate containers with the Blazor Server making internal HTTP calls to
the API. This caused the Blazor circuit to disconnect when the API was
unreachable (network error → "Une erreur réseau est survenue").

Now both serve from the same .NET process on the same port:
- All 16 API controllers, ExceptionFilter, and SignalR hubs integrated
  into Heimdall.Web
- JWT auth, CORS, rate limiting configured in the unified Program.cs
- Dockerfile.central entrypoint runs web/Heimdall.Web.dll
- docker-compose simplified: heimdall-central service removed
- CI publishes heimdall-web image instead of heimdall-central

Also fixes timezone validation on Alpine/tzdata-less environments
and enables FluentValidation auto-validation in the API project.
2026-07-20 10:30:01 +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 153be535d4 fix(multiple): auth, workers, EF Core, MudTheme fixes
- Auth: AssignmentsController auth bug, ReleaseCamera result, logout endpoint
- Security: open redirect fix
- Workers: AgentState thread-safety, CameraStreamService async, HttpClientFactory
- EF Core: AddCameraDiscoveryFields migration, DI interceptors, retry helper
- UI: MudTheme palette config, aria-labels on icon buttons
2026-07-19 19:58:45 +00:00
Arnaud Dartois c5728fa810 feat(events): add SignalR real-time event broadcasting to web UI 2026-07-19 15:24:52 +00:00
Arnaud Dartois 76b261378c fix: resolve review findings — thread safety, N+1, DTO layering, sentry, S3 retry 2026-07-19 13:43: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 3fc42be4b2 test(agent): add unit tests for AgentState, AgentHealthCheck, AgentRegistrationService
13 tests covering:
- AgentState file persistence (save, load, corrupt file, empty ID, clear)
- AgentHealthCheck (healthy, degraded, unhealthy states)
- AgentRegistrationService (successful registration, retry on failure,
  all retries exhausted, reuse existing identity, offline heartbeat on stop)
2026-07-18 14:16:13 +00:00
Arnaud Dartois cb500e0354 fix(deps): override transitive AngleSharp 1.4.0 with 1.5.2 to fix NU1902 vulnerability
bunit 2.8.4-preview transitively pulls AngleSharp 1.4.0 which has a
known moderate severity vulnerability (GHSA-pgww-w46g-26qg). Adding
a direct PackageReference to AngleSharp 1.5.2 overrides the transitive
version and resolves the CI build failure.
2026-07-18 11:41:33 +00:00
Arnaud Dartois e83b493ce0 test: add placeholder tests to empty test projects
- Add PlaceholderTest.cs to Api.Tests, Application.Tests, Infrastructure.Tests,
  Web.Tests, Workers.Tests (1 passing test each)
- Prevents 'no test available' warnings in CI
2026-07-17 17:39:30 +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
Arnaud Dartois b217c932e8 feat(mvp): implement MVP multi-site platform
Complete MVP implementation (Étape 1) covering:
- Domain: primitives (Entity<TId>, ValueObject), 10 entities, 6 enums
- EF Core: AppDbContext + Identity, 8 EntityTypeConfigurations, audit/soft-delete interceptors, initial migration
- Application: service interfaces, DTOs, FluentValidation, ServiceResult pattern
- Security: Identity + JWT + API Key multi-auth, role-based permissions, constant-time key validation
- API: Auth/Sites/Agents controllers with explicit auth scheme policies
- Workers: Hangfire PostgreSQL setup with schema isolation, HeartbeatMonitorJob
- Agent: registration service + 30s heartbeat loop
- Docker: multi-stage Dockerfiles for central + agent, docker-compose.yml
- CI/CD: GitHub Actions pipeline with build+test and Docker build
- Tests: 13 domain tests (Site, Agent, Camera entities)

Architecture decisions per deliberation council:
- API Key via AuthenticationHandler<T> (not middleware)
- Explicit [Authorize(AuthenticationSchemes)] on all endpoints
- Event/Recording/Person/Vehicle deferred from initial migration
- Hangfire compatible with .NET 10 (v1.8.17)
2026-07-16 20:53:56 +00:00
Arnaud Dartois bfb3e06bc1 feat: initialize .NET 10 Clean Architecture solution
Create Heimdall solution with 17 projects following Clean
Architecture for a maintainable and loosely coupled codebase.

src/ (9 projects):
- Domain, Domain.Primitives, Contracts (core layer, no deps)
- Application (ref. Domain) — CQRS/MediatR ready
- Infrastructure (ref. Application + Domain) — EF Core
  PostgreSQL ready
- Api, Web (Blazor), Agent, Workers (hosts, ref. Application +
  Infrastructure)

tests/ (8 projects):
- xUnit + Shouldly + NSubstitute + bUnit (Web.Tests)
- One test project per source project (Domain -> IntegrationTests)

Config: Directory.Build.props (Nullable, ImplicitUsings,
TreatWarningsAsErrors)
2026-07-16 19:09:28 +00:00