mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-26 06:21:13 +00:00
Sanitize 400 error messages in GlobalExceptionHandler and validation filters to use static strings. This change improves consistency and prevents leaking internal exception details. Updated tests to reflect new error messages for JSON parsing and bad request scenarios.
This commit is contained in:
@@ -108,7 +108,36 @@ public class GlobalExceptionHandlerTests
|
||||
root.GetProperty("errors")
|
||||
.GetProperty("tiles[0].foo")[0]
|
||||
.GetString()
|
||||
.Should().Contain("could not be mapped");
|
||||
.Should().Be("The field value is invalid.");
|
||||
root.GetProperty("errors")
|
||||
.GetProperty("tiles[0].foo")[0]
|
||||
.GetString()
|
||||
.Should().NotContain("TileInventoryRequest");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TryHandleAsync_BadHttpRequestExceptionWithoutJson_UsesStaticDetail()
|
||||
{
|
||||
// Arrange
|
||||
var loggerMock = new Mock<ILogger<GlobalExceptionHandler>>();
|
||||
var handler = new GlobalExceptionHandler(loggerMock.Object);
|
||||
var httpContext = new DefaultHttpContext { TraceIdentifier = "trace-bind-static" };
|
||||
httpContext.Response.Body = new MemoryStream();
|
||||
var bindFailure = new BadHttpRequestException(
|
||||
"Failed to bind parameter \"double Latitude\" from \"abc\".",
|
||||
StatusCodes.Status400BadRequest);
|
||||
|
||||
// Act
|
||||
var handled = await handler.TryHandleAsync(httpContext, bindFailure, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
handled.Should().BeTrue();
|
||||
httpContext.Response.Body.Position = 0;
|
||||
using var doc = JsonDocument.Parse(httpContext.Response.Body);
|
||||
doc.RootElement.GetProperty("detail").GetString()
|
||||
.Should().Be("The request could not be processed.");
|
||||
doc.RootElement.GetProperty("detail").GetString()
|
||||
.Should().NotContain("Latitude");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -173,7 +173,7 @@ public class UavTileUploadHandlerTests : IDisposable
|
||||
|
||||
// Assert
|
||||
result.EnvelopeRejected.Should().BeTrue();
|
||||
result.EnvelopeError.Should().Contain("Invalid `metadata` JSON");
|
||||
result.EnvelopeError.Should().Be("`metadata` could not be parsed as JSON.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user