AZ-491 (3 SP): eliminate the cycle-2 duplicate of JWT-minting logic that existed in both SatelliteProvider.Tests/TestUtilities/ JwtTokenFactory.cs (unit-side) and SatelliteProvider.IntegrationTests/ JwtTestHelpers.cs (integration-side), where the same Expires < NotBefore bug needed parallel fixes in commitsf64d0d7+11b7074. Option A chosen: new SatelliteProvider.TestSupport class library (no test framework) holds the canonical JwtTokenFactory.Create / CreateExpired / TamperSignature. Both Tests and IntegrationTests consume it via ProjectReference; production projects (Api, Common, DataAccess, Services.*) cannot depend on it. The notBefore-shift workaround is preserved with an inline regression-prevention comment back-referencing the cycle-2 fix commits. SatelliteProvider.IntegrationTests/JwtTestHelpers.cs is stripped to runner-only concerns: ResolveSecretOrThrow, AttachDefaultAuthorization, and the DefaultSubject = "integration-tests" constant. Call sites in Program.cs, JwtIntegrationTests.cs, and UavUploadTests.cs (10 sites) switched to JwtTokenFactory.* with JwtTestHelpers.DefaultSubject explicitly passed for the runner subject - behavior parity preserved. Dockerfile for IntegrationTests gets the new TestSupport csproj in its pre-restore COPY layer. Api Dockerfile unchanged (TestSupport is NOT a production dependency). A new code-review SKILL.md Phase 6 checklist row flags near-identical helper logic across test projects as a Medium / Maintainability finding with explicit cycle-2 retro back-reference, so this whole pattern stops at one occurrence. module-layout.md adds a TestSupport Shared/Cross-Cutting entry documenting the production-isolation invariant. tests_unit.md + tests_integration.md updated to describe the consolidated layout. sln updated. Test-suite gate (AC-2 + AC-3) deferred to Step 16 Final Test Run per implement-skill convention. Per-batch review verdict: PASS_WITH_WARNINGS with 1 Low (pre-existing 7.0.3 version pin preserved verbatim from cycle-2 IntegrationTests csproj for parity; not blocking; deferred bump). Co-authored-by: Cursor <cursoragent@cursor.com>
4.4 KiB
Module: Tests/SatelliteProvider.Tests
Purpose
Unit test project for component-internal logic. Original AZ-2/AZ-3 era had only a placeholder dummy; the suite has since grown across the AZ-285..AZ-380 baseline + cycle 1 (AZ-484) + cycle 2 (AZ-487, AZ-488) tracks. The "dummy test only" note in older revisions of this file is obsolete — the project now hosts the full unit suite executed by scripts/run-tests.sh --unit-only and CI's 01-test.yml.
Public Interface (test classes)
Existing baseline (pre-cycle-2) test classes cover TileService, RegionService, RouteService, geo math, repositories, validators, idempotency, and migration helpers — not enumerated exhaustively here. Cycle-2 additions:
AZ-487 — JWT validation baseline
Authentication/AuthenticationServiceCollectionExtensionsTests—AddSatelliteJwt_RegistersJwtBearerScheme,AddSatelliteJwt_ThrowsOnMissingSecret,AddSatelliteJwt_ThrowsOnShortSecret.Authentication/JwtTokenFactoryTests—Create_ProducesTokenValidatedByMatchingParameters,CreateExpired_TokenFailsValidationWithLifetimeException,Create_WithExtraClaims_PropagatesClaimsThroughValidation.TestUtilities/JwtTokenFactory— helper that mints HS256 tokens with the sameTokenValidationParametersused in production. AdjustsnotBeforefor negative-lifetime requests soJwtSecurityTokenaccepts the value and downstream lifetime validation can fire (IDX12401workaround documented inline).
AZ-488 — UAV tile upload
UavTileQualityGateTests— one happy path + ≥ 1 reject path per rule (Rule 1 INVALID_FORMAT × 2, Rule 2 SIZE_OUT_OF_BAND × 2, Rule 3 WRONG_DIMENSIONS × 1, Rule 4 CAPTURED_AT_FUTURE / _TOO_OLD × 2, Rule 5 IMAGE_TOO_UNIFORM × 1) + rule-ordering determinism. Uses aFixedTimeProviderfor Rule-4 isolation andUavTileImageFactoryfor deterministic JPEG fixtures.UavTileUploadHandlerTests— end-to-end with a mockedITileRepository: 1-item happy path, 3-item mixed batch (file written +InsertAsynccalled only for accepted), per-source UPSERT pass-through.UavTileFilePathTests— verifiesBuildUavTileFilePathproducestiles/uav/{z}/{x}/{y}.jpgfor sample (z, x, y) tuples and that integer-typed coordinates make string-injection of path traversal impossible.Authentication/PermissionsRequirementTests—PermissionsAuthorizationHandlercorrectly accepts apermissionsclaim shaped as a single string OR as a JSON array, rejects when the requested permission is absent, and short-circuits when the principal has nopermissionsclaim at all.TestUtilities/UavTileImageFactory— programmatic JPEG factories used by the gate + handler tests:CreateValidJpeg(width, height, seed),CreateUniformJpeg,CreatePng(for Rule 1 negative path).
Internal Logic
- Tests follow Arrange / Act / Assert. Time-dependent paths inject a
FixedTimeProvider(cycle-2 addition) so Rule 4 has deterministic age windows. JwtSecurityTokenHandler.MapInboundClaims = falseis set explicitly in JWT tests so claims read by their original names (sub,permissions, …) rather than the framework-remapped names.
Dependencies
- Project references:
SatelliteProvider.Services.TileDownloader,SatelliteProvider.Services.RegionProcessing,SatelliteProvider.Services.RouteManagement,SatelliteProvider.Common,SatelliteProvider.DataAccess,SatelliteProvider.Api(for the Authentication tests — added in AZ-487),SatelliteProvider.TestSupport(added by AZ-491; provides the canonicalJwtTokenFactoryconsumed by both this project andSatelliteProvider.IntegrationTests). - NuGet: xUnit (2.5.3), Moq (4.20.72), FluentAssertions (8.8.0), coverlet.collector (6.0.0), Microsoft.NET.Test.Sdk (17.8.0), Microsoft.Extensions.* (Caching.Memory, Configuration, DI, Logging, Options, Http),
Microsoft.AspNetCore.Authentication.JwtBearer8.0.25 (consumed transitively via theProjectReferencetoSatelliteProvider.Api; AZ-487 added the dependency at 8.0.21, AZ-496 bumped it to 8.0.25),SixLabors.ImageSharp3.1.11 (added by AZ-488 for the gate tests). appsettings.jsoncopied to output (used by Authentication tests for theJwtsection binding scenario).
Consumers
- CI pipeline (
01-test.yml) andscripts/run-tests.sh --unit-onlyrundotnet testagainst this project.
Tests
This IS the test module. Cycle-2 added ~25 unit tests on top of the existing baseline; the full project executes in seconds (no external services required).