mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 14:01:14 +00:00
1802d32107
Replaces the 501 stub at POST /api/satellite/upload with a multipart
batch endpoint that ingests UAV-captured tiles, runs each item through
a 5-rule quality gate, and persists accepted tiles via the AZ-484
multi-source storage path with source='uav'.
Quality gate (in fixed order, first failure wins): JPEG format
(content-type + magic), size band 5 KiB-5 MiB, exact 256x256
dimensions, captured-at age (no future >30 s skew, no older than
7 days), luminance variance on 32x32 downsample. Closed reject-reason
enumeration in v1.0.0 contract.
Authorization: custom PermissionsRequirement / PermissionsAuthorization
Handler that reads the JWT `permissions` claim (tolerates both
repeated-string and JSON-array shapes). Endpoint protected by
RequiresGpsPermission policy; 401 without token, 403 without GPS perm.
Persistence: file-first to ./tiles/uav/{z}/{x}/{y}.jpg, then
ITileRepository.InsertAsync UPSERT (per-source UPSERT contract from
AZ-484). Per-item failures reported in response without aborting the
batch. Kestrel MaxRequestBodySize and FormOptions limits set to
MaxBatchSize x MaxBytes (default 100 x 5 MiB = 500 MiB).
New frozen contract: _docs/02_document/contracts/api/uav-tile-upload.md
v1.0.0. PT-08 NFR added to performance-tests.md as Deferred (harness
work tracked in PT-07 leftover, per AZ-488 § Risk 4).
Tests: 11 quality-gate unit tests, 5 handler unit tests, 3 file-path
unit tests, 12 permission-handler unit tests, 7 integration tests
(AC-1..AC-6, AC-8). All 253 unit tests + smoke integration suite
green.
Co-authored-by: Cursor <cursoragent@cursor.com>
108 lines
3.5 KiB
C#
108 lines
3.5 KiB
C#
using System.Security.Claims;
|
|
using FluentAssertions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using SatelliteProvider.Api.Authentication;
|
|
|
|
namespace SatelliteProvider.Tests.Authentication;
|
|
|
|
public class PermissionsRequirementTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_RejectsBlankPermission()
|
|
{
|
|
// Act
|
|
var act = () => new PermissionsRequirement(" ");
|
|
|
|
// Assert
|
|
act.Should().Throw<ArgumentException>();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handler_SucceedsWhenSingleStringClaimMatches()
|
|
{
|
|
// Arrange
|
|
var requirement = new PermissionsRequirement(SatellitePermissions.Gps);
|
|
var handler = new PermissionsAuthorizationHandler();
|
|
var user = BuildUser(new Claim(PermissionsAuthorizationHandler.ClaimType, "GPS"));
|
|
var context = new AuthorizationHandlerContext(new[] { requirement }, user, null);
|
|
|
|
// Act
|
|
await handler.HandleAsync(context);
|
|
|
|
// Assert
|
|
context.HasSucceeded.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handler_SucceedsWhenMultipleClaimsContainTarget()
|
|
{
|
|
// Arrange
|
|
var requirement = new PermissionsRequirement(SatellitePermissions.Gps);
|
|
var handler = new PermissionsAuthorizationHandler();
|
|
var user = BuildUser(
|
|
new Claim(PermissionsAuthorizationHandler.ClaimType, "FL"),
|
|
new Claim(PermissionsAuthorizationHandler.ClaimType, "GPS"));
|
|
var context = new AuthorizationHandlerContext(new[] { requirement }, user, null);
|
|
|
|
// Act
|
|
await handler.HandleAsync(context);
|
|
|
|
// Assert
|
|
context.HasSucceeded.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handler_SucceedsWhenSingleClaimEncodesJsonArray()
|
|
{
|
|
// Arrange
|
|
var requirement = new PermissionsRequirement(SatellitePermissions.Gps);
|
|
var handler = new PermissionsAuthorizationHandler();
|
|
var user = BuildUser(new Claim(PermissionsAuthorizationHandler.ClaimType, "[\"FL\",\"GPS\"]"));
|
|
var context = new AuthorizationHandlerContext(new[] { requirement }, user, null);
|
|
|
|
// Act
|
|
await handler.HandleAsync(context);
|
|
|
|
// Assert
|
|
context.HasSucceeded.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handler_DoesNotSucceedWhenClaimIsMissing()
|
|
{
|
|
// Arrange
|
|
var requirement = new PermissionsRequirement(SatellitePermissions.Gps);
|
|
var handler = new PermissionsAuthorizationHandler();
|
|
var user = BuildUser(new Claim(PermissionsAuthorizationHandler.ClaimType, "FL"));
|
|
var context = new AuthorizationHandlerContext(new[] { requirement }, user, null);
|
|
|
|
// Act
|
|
await handler.HandleAsync(context);
|
|
|
|
// Assert
|
|
context.HasSucceeded.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Handler_DoesNotSucceedWhenUserIsAnonymous()
|
|
{
|
|
// Arrange
|
|
var requirement = new PermissionsRequirement(SatellitePermissions.Gps);
|
|
var handler = new PermissionsAuthorizationHandler();
|
|
var anon = new ClaimsPrincipal(new ClaimsIdentity());
|
|
var context = new AuthorizationHandlerContext(new[] { requirement }, anon, null);
|
|
|
|
// Act
|
|
await handler.HandleAsync(context);
|
|
|
|
// Assert
|
|
context.HasSucceeded.Should().BeFalse();
|
|
}
|
|
|
|
private static ClaimsPrincipal BuildUser(params Claim[] claims)
|
|
{
|
|
var identity = new ClaimsIdentity(claims, authenticationType: "Test");
|
|
return new ClaimsPrincipal(identity);
|
|
}
|
|
}
|