[AZ-794] [AZ-795] [AZ-796] Strict input validation + z/x/y rename
ci/woodpecker/push/01-test Pipeline was successful
ci/woodpecker/push/02-build-push Pipeline was successful

AZ-794: rename inventory wire fields tileZoom/tileX/tileY -> z/x/y
to match the slippy-map URL convention. Contract bumped to v2.0.0.

AZ-795: shared validation infrastructure -- FluentValidation +
ValidationEndpointFilter + GlobalValidatorConfig (camelCase paths).
GlobalExceptionHandler now converts JsonException (UnmappedMember +
JsonRequired) into RFC 7807 ValidationProblemDetails. JSON layer
hardened with UnmappedMemberHandling.Disallow + camelCase naming
policy. New error-shape.md contract.

AZ-796: InventoryRequestValidator covers 9 rules (XOR tiles vs
locationHashes, cap 1000, z 0..22, x/y in slippy bounds, hash
length/charset). 16 unit tests + 16 integration tests + a manual
curl probe script.

Adjacent fixes uncovered by the new strict layer:
- IdempotentPostTests RoutePoint payload corrected to lat/lon
  (the DTO has used JsonPropertyName for ages; previously silently
  ignored under PascalCase fallback).
- TileInventoryTests slippy x/y reduced to fit z=18 bounds.
- docker-compose.yml host port for Postgres moved 5432 -> 5433 to
  avoid sibling-project conflict; appsettings.Development + README
  + AGENTS + architecture + containerization docs aligned.

New coderule (suite + repo): API consumer-facing OpenAPI
descriptions must not contain task IDs, contract filenames, or
version-bump history -- internal change tracking belongs in
commits/contract docs/changelogs. Existing offending descriptions
in Program.cs cleaned up.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-22 10:02:02 +03:00
parent dceaddc436
commit 865dfdb3b9
33 changed files with 1824 additions and 118 deletions
@@ -72,6 +72,45 @@ public class GlobalExceptionHandlerTests
"BadHttpRequestException is a client error and must not be ERROR-logged as a server failure");
}
[Fact]
public async Task TryHandleAsync_DeserializationFailure_WritesValidationProblemDetailsWithJsonPath_AZ795()
{
// Arrange
var loggerMock = new Mock<ILogger<GlobalExceptionHandler>>();
var handler = new GlobalExceptionHandler(loggerMock.Object);
var httpContext = new DefaultHttpContext { TraceIdentifier = "trace-AZ795" };
httpContext.Response.Body = new MemoryStream();
var jsonInner = new JsonException(
"The JSON property 'foo' could not be mapped to any .NET member contained in type 'TileInventoryRequest'.",
"$.tiles[0].foo",
lineNumber: null,
bytePositionInLine: null);
var bindFailure = new BadHttpRequestException(
"Failed to read parameter \"TileInventoryRequest request\" from request body.",
StatusCodes.Status400BadRequest,
jsonInner);
// Act
var handled = await handler.TryHandleAsync(httpContext, bindFailure, CancellationToken.None);
// Assert
handled.Should().BeTrue();
httpContext.Response.StatusCode.Should().Be(StatusCodes.Status400BadRequest);
httpContext.Response.ContentType.Should().Contain("application/problem+json");
httpContext.Response.Body.Position = 0;
using var doc = JsonDocument.Parse(httpContext.Response.Body);
var root = doc.RootElement;
root.GetProperty("status").GetInt32().Should().Be(400);
root.GetProperty("title").GetString().Should().Be("One or more validation errors occurred.");
root.GetProperty("type").GetString().Should().Be("https://tools.ietf.org/html/rfc7231#section-6.5.1");
root.GetProperty("errors")
.GetProperty("tiles[0].foo")[0]
.GetString()
.Should().Contain("could not be mapped");
}
[Fact]
public async Task TryHandleAsync_LogsFullExceptionWithCorrelationId_AC2()
{
@@ -0,0 +1,16 @@
using System.Runtime.CompilerServices;
using SatelliteProvider.Api.Validators;
namespace SatelliteProvider.Tests.TestSupport;
internal static class ValidatorTestModuleInitializer
{
// ModuleInitializer (.NET 5+) runs once per assembly load. We piggy-back the
// production GlobalValidatorConfig.ApplyOnce() so unit tests assert against
// the same FluentValidation property-name casing the live API produces.
[ModuleInitializer]
public static void Initialize()
{
GlobalValidatorConfig.ApplyOnce();
}
}
@@ -0,0 +1,261 @@
using FluentAssertions;
using FluentValidation.TestHelper;
using SatelliteProvider.Api.Validators;
using SatelliteProvider.Common.DTO;
namespace SatelliteProvider.Tests.Validators;
public class InventoryRequestValidatorTests
{
private readonly InventoryRequestValidator _validator = new();
[Fact]
public void Validate_TilesPopulated_LocationHashesNull_Passes()
{
// Arrange
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 18, X = 1, Y = 1 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
[Fact]
public void Validate_LocationHashesPopulated_TilesNull_Passes()
{
// Arrange
var request = new TileInventoryRequest
{
LocationHashes = new[] { Guid.NewGuid() }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
[Fact]
public void Validate_BothPopulated_FailsXorRule()
{
// Arrange
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 18, X = 1, Y = 1 } },
LocationHashes = new[] { Guid.NewGuid() }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("$")
.WithErrorMessage("Populate exactly one of `tiles` or `locationHashes` (sending both, or neither, is not allowed).");
}
[Fact]
public void Validate_NeitherPopulated_FailsXorRule()
{
// Arrange
var request = new TileInventoryRequest();
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("$");
}
[Fact]
public void Validate_BothEmpty_FailsXorRule()
{
// Arrange
var request = new TileInventoryRequest
{
Tiles = Array.Empty<TileCoord>(),
LocationHashes = Array.Empty<Guid>()
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("$");
}
[Fact]
public void Validate_TilesAtCap_Passes()
{
// Arrange
var coords = Enumerable.Range(0, TileInventoryLimits.MaxEntriesPerRequest)
.Select(_ => new TileCoord { Z = 18, X = 1, Y = 1 })
.ToArray();
var request = new TileInventoryRequest { Tiles = coords };
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveValidationErrorFor("tiles");
}
[Fact]
public void Validate_TilesOverCap_FailsCapRule()
{
// Arrange
var coords = Enumerable.Range(0, TileInventoryLimits.MaxEntriesPerRequest + 1)
.Select(_ => new TileCoord { Z = 18, X = 1, Y = 1 })
.ToArray();
var request = new TileInventoryRequest { Tiles = coords };
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("tiles")
.WithErrorMessage($"`tiles` must contain at most {TileInventoryLimits.MaxEntriesPerRequest} entries.");
}
[Fact]
public void Validate_LocationHashesOverCap_FailsCapRule()
{
// Arrange
var hashes = Enumerable.Range(0, TileInventoryLimits.MaxEntriesPerRequest + 1)
.Select(_ => Guid.NewGuid())
.ToArray();
var request = new TileInventoryRequest { LocationHashes = hashes };
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("locationHashes")
.WithErrorMessage($"`locationHashes` must contain at most {TileInventoryLimits.MaxEntriesPerRequest} entries.");
}
[Theory]
[InlineData(-1)]
[InlineData(23)]
[InlineData(100)]
public void Validate_TileZoomOutOfRange_FailsRangeRule(int z)
{
// Arrange
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = z, X = 0, Y = 0 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("tiles[0].z");
}
[Theory]
[InlineData(0)]
[InlineData(18)]
[InlineData(22)]
public void Validate_TileZoomInRange_PassesRangeRule(int z)
{
// Arrange
var maxAxis = (1 << z) - 1;
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = z, X = maxAxis, Y = maxAxis } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveValidationErrorFor("tiles[0].z");
}
[Fact]
public void Validate_TileXNegative_FailsRangeRule()
{
// Arrange
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 18, X = -1, Y = 0 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("tiles[0].x");
}
[Fact]
public void Validate_TileXAtUpperBound_FailsRangeRule()
{
// Arrange — at z=2, valid x is 0..3, so x=4 is invalid
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 2, X = 4, Y = 0 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("tiles[0].x")
.WithErrorMessage("`x` must be < 2^z = 4 for z=2.");
}
[Fact]
public void Validate_TileYNegative_FailsRangeRule()
{
// Arrange
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 18, X = 0, Y = -1 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("tiles[0].y");
}
[Fact]
public void Validate_TileYAtUpperBound_FailsRangeRule()
{
// Arrange — at z=0, valid y is 0..0, so y=1 is invalid
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 0, X = 0, Y = 1 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationErrorFor("tiles[0].y");
}
[Fact]
public void Validate_AxesAtMaxForZoom_Passes()
{
// Arrange — at z=18, valid x/y is 0..(2^18 - 1) = 0..262143
var request = new TileInventoryRequest
{
Tiles = new[] { new TileCoord { Z = 18, X = 262_143, Y = 262_143 } }
};
// Act
var result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveAnyValidationErrors();
}
}