mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-21 10:21:14 +00:00
34ee1e0b83
AZ-808: FluentValidation for POST /api/satellite/request - RegionRequestValidator: id non-empty, lat/lon/sizeMeters/zoomLevel ranges - RequestRegionRequest: [JsonRequired] on every property, no implicit defaults - Wired via .WithValidation<RequestRegionRequest>() in MapPost chain - Unit + integration tests + curl probe script - New contract: contracts/api/region-request.md v1.0.0 AZ-811: FluentValidation + envelope filter for GET /api/satellite/tiles/latlon - GetTileByLatLonQuery: nullable record (double?/int?) so the minimal-API binder never short-circuits with BadHttpRequestException before filters - GetTileByLatLonQueryValidator: Cascade(Stop) + NotNull + InclusiveBetween per param; missing surfaces as `\`<name>\` is required.` - RejectUnknownQueryParamsEndpointFilter: reusable IEndpointFilter that rejects any query key outside the allowed set with errors[<key>] map; catches legacy `?Latitude=` typos and hostile probes (`?debug=1&admin=1`) - Handler: [AsParameters] GetTileByLatLonQuery + .Value deref post-validator - Unit (validator + filter) + integration tests + curl probe script - New contract: contracts/api/tile-latlon.md v1.0.0 Shared hygiene - Promote AssertErrorsContainsMention from per-test-file private helpers to ProblemDetailsAssertions (closes batch-1 Low-severity DRY warning) - Sync Swagger param descriptions, README, blackbox/security/perf scripts, uuidv5 doc with the new lat/lon/zoom query-param names Docs - system-flows.md F1/F2 reference the new contracts + validation layers - modules/api_program.md adds Api/Validators + Api/DTOs sections - _autodev_state.md: batch 2 of 4 complete; next batch = AZ-809 All smoke tests green (mode=smoke, exit 0). AZ-808 + AZ-811 transitioned to In Testing on Jira. Co-authored-by: Cursor <cursoragent@cursor.com>
174 lines
7.9 KiB
C#
174 lines
7.9 KiB
C#
namespace SatelliteProvider.IntegrationTests;
|
|
|
|
// AZ-811: end-to-end coverage for GET /api/satellite/tiles/latlon strict input
|
|
// validation. Two enforcement layers:
|
|
// 1. RejectUnknownQueryParamsEndpointFilter — rejects any query key outside
|
|
// {lat, lon, zoom}, catching typos like `?latitude=` that pre-AZ-811
|
|
// silently bound to 0.
|
|
// 2. WithValidation<GetTileByLatLonQuery> — range-checks lat, lon, zoom.
|
|
// Both surface RFC 7807 ValidationProblemDetails per error-shape.md v1.0.0.
|
|
public static class GetTileByLatLonValidationTests
|
|
{
|
|
private const string LatLonPath = "/api/satellite/tiles/latlon";
|
|
|
|
public static async Task RunAll(HttpClient httpClient)
|
|
{
|
|
RouteTestHelpers.PrintTestHeader("Test: GET /api/satellite/tiles/latlon strict validation (AZ-811)");
|
|
|
|
await HappyPath_Returns200(httpClient);
|
|
|
|
// Validator rules (range)
|
|
await LatOutOfRange_Returns400(httpClient);
|
|
await LonOutOfRange_Returns400(httpClient);
|
|
await ZoomOutOfRange_Returns400(httpClient);
|
|
|
|
// Validator rules (missing required)
|
|
await MissingLat_Returns400(httpClient);
|
|
|
|
// Envelope rule: unknown query params
|
|
await UnknownQueryParam_LegacyLatitude_Returns400(httpClient);
|
|
await UnknownQueryParam_Hostile_Returns400(httpClient);
|
|
|
|
// Type mismatch (delegates to GlobalExceptionHandler via model-binding)
|
|
await LatTypeMismatch_Returns400(httpClient);
|
|
|
|
Console.WriteLine("✓ GET lat/lon validation tests: PASSED");
|
|
}
|
|
|
|
private static async Task HappyPath_Returns200(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 AC-2: well-formed query → HTTP 200");
|
|
|
|
// Act
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lat=47.461747&lon=37.647063&zoom=18");
|
|
var status = (int)response.StatusCode;
|
|
var bodyText = await response.Content.ReadAsStringAsync();
|
|
|
|
// Assert
|
|
if (status != 200)
|
|
{
|
|
throw new Exception($"AZ-811 happy path: expected HTTP 200, got {status}. Body: {bodyText}");
|
|
}
|
|
|
|
Console.WriteLine(" ✓ {lat,lon,zoom} accepted with HTTP 200");
|
|
}
|
|
|
|
private static async Task LatOutOfRange_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 1: lat out of range (-90..90) → HTTP 400");
|
|
|
|
// Act
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lat=91&lon=37.647063&zoom=18");
|
|
var problem = await ProblemDetailsAssertions.ReadProblemDetailsAsync(response, "AZ-811 lat out of range");
|
|
|
|
// Assert
|
|
ProblemDetailsAssertions.AssertValidationProblem(problem, expectedStatus: 400, label: "AZ-811 lat out of range", expectedErrorPath: "lat");
|
|
|
|
Console.WriteLine(" ✓ lat=91 rejected with errors[\"lat\"]");
|
|
}
|
|
|
|
private static async Task LonOutOfRange_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 2: lon out of range (-180..180) → HTTP 400");
|
|
|
|
// Act
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lat=47.461747&lon=181&zoom=18");
|
|
var problem = await ProblemDetailsAssertions.ReadProblemDetailsAsync(response, "AZ-811 lon out of range");
|
|
|
|
// Assert
|
|
ProblemDetailsAssertions.AssertValidationProblem(problem, expectedStatus: 400, label: "AZ-811 lon out of range", expectedErrorPath: "lon");
|
|
|
|
Console.WriteLine(" ✓ lon=181 rejected with errors[\"lon\"]");
|
|
}
|
|
|
|
private static async Task ZoomOutOfRange_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 3: zoom out of range (0..22) → HTTP 400");
|
|
|
|
// Act
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lat=47.461747&lon=37.647063&zoom=30");
|
|
var problem = await ProblemDetailsAssertions.ReadProblemDetailsAsync(response, "AZ-811 zoom out of range");
|
|
|
|
// Assert
|
|
ProblemDetailsAssertions.AssertValidationProblem(problem, expectedStatus: 400, label: "AZ-811 zoom out of range", expectedErrorPath: "zoom");
|
|
|
|
Console.WriteLine(" ✓ zoom=30 rejected with errors[\"zoom\"]");
|
|
}
|
|
|
|
private static async Task MissingLat_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 1: missing `lat` query param → HTTP 400 with errors.lat");
|
|
|
|
// Act — only lon + zoom supplied; the validator's NotNull rule on Lat must
|
|
// fire (binder produces Lat=null because the DTO is nullable; see
|
|
// GetTileByLatLonQuery for why).
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lon=37.647063&zoom=18");
|
|
var problem = await ProblemDetailsAssertions.ReadProblemDetailsAsync(response, "AZ-811 missing lat");
|
|
|
|
// Assert
|
|
ProblemDetailsAssertions.AssertValidationProblem(problem, expectedStatus: 400, label: "AZ-811 missing lat", expectedErrorPath: "lat");
|
|
|
|
Console.WriteLine(" ✓ Missing lat rejected with errors[\"lat\"] = `lat` is required");
|
|
}
|
|
|
|
private static async Task UnknownQueryParam_LegacyLatitude_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 4: legacy `?Latitude=&Longitude=&ZoomLevel=` (pre-AZ-811 wire format) → HTTP 400 (envelope filter)");
|
|
|
|
// Act — exact pre-AZ-811 wire format; must now fail explicitly instead
|
|
// of silently binding to lat=0/lon=0/zoom=0 (typo class).
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?Latitude=47.461747&Longitude=37.647063&ZoomLevel=18");
|
|
var problem = await ProblemDetailsAssertions.ReadProblemDetailsAsync(response, "AZ-811 legacy param names");
|
|
|
|
// Assert
|
|
ProblemDetailsAssertions.AssertValidationProblem(problem, expectedStatus: 400, label: "AZ-811 legacy param names");
|
|
ProblemDetailsAssertions.AssertErrorsContainsMention(problem, expectedMention: "Latitude", label: "AZ-811 legacy param names");
|
|
|
|
Console.WriteLine(" ✓ Legacy ?Latitude=&Longitude=&ZoomLevel= rejected by envelope filter");
|
|
}
|
|
|
|
private static async Task UnknownQueryParam_Hostile_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 4: hostile/typo query keys → HTTP 400 (envelope filter)");
|
|
|
|
// Act
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lat=47.461747&lon=37.647063&zoom=18&debug=1&admin=true");
|
|
var problem = await ProblemDetailsAssertions.ReadProblemDetailsAsync(response, "AZ-811 hostile params");
|
|
|
|
// Assert
|
|
ProblemDetailsAssertions.AssertValidationProblem(problem, expectedStatus: 400, label: "AZ-811 hostile params");
|
|
ProblemDetailsAssertions.AssertErrorsContainsMention(problem, expectedMention: "debug", label: "AZ-811 hostile params");
|
|
ProblemDetailsAssertions.AssertErrorsContainsMention(problem, expectedMention: "admin", label: "AZ-811 hostile params");
|
|
|
|
Console.WriteLine(" ✓ ?debug=1&admin=true rejected; errors map names BOTH unknown keys");
|
|
}
|
|
|
|
private static async Task LatTypeMismatch_Returns400(HttpClient httpClient)
|
|
{
|
|
Console.WriteLine();
|
|
Console.WriteLine("AZ-811 rule 5: lat type mismatch (non-numeric) → HTTP 400");
|
|
|
|
// Act
|
|
var response = await httpClient.GetAsync($"{LatLonPath}?lat=fifty&lon=37.647063&zoom=18");
|
|
var status = (int)response.StatusCode;
|
|
|
|
// Assert — ASP.NET query-param binding produces 400 for type mismatch via
|
|
// BadHttpRequestException; the exact ProblemDetails shape varies depending
|
|
// on whether the GlobalExceptionHandler intercepts. Either way the wire
|
|
// contract is HTTP 400, no body leak.
|
|
if (status != 400)
|
|
{
|
|
throw new Exception($"AZ-811 type mismatch: expected HTTP 400, got {status}.");
|
|
}
|
|
|
|
Console.WriteLine(" ✓ lat=fifty rejected with HTTP 400");
|
|
}
|
|
}
|