Files
Heimdall/tests/Heimdall.Api.Tests/PlaceholderTest.cs
T
Arnaud Dartois ba968a5f23 fix(security): harden Docker, CSRF, EventsHub scoping, secret logging, tests
- Docker: remove default passwords from prod compose (required env vars)
- CSRF: validate antiforgery tokens on /_auth/signin and /_auth/signout
- EventsHub: broadcast to site-scoped Group() instead of Clients.All
- SettingsController: redact secret values in logs
- Create SetAgentSettingValidator + UpdateAppSettingValidator classes
- Replace 3 placeholder test projects with meaningful tests
- Remove FluentValidation auto-validation (incompatible with .NET 10)
2026-07-19 20:53:48 +00:00

49 lines
1.5 KiB
C#

using Heimdall.Api.Filters;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging.Abstractions;
namespace Heimdall.Api.Tests;
public class ExceptionFilterTests
{
private static ExceptionContext CreateContext(Exception exception)
{
var httpContext = new DefaultHttpContext();
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
return new ExceptionContext(actionContext, [])
{
Exception = exception
};
}
[Fact]
public void OnException_LogsErrorAndReturns500()
{
var filter = new ExceptionFilter(NullLogger<ExceptionFilter>.Instance);
var context = CreateContext(new InvalidOperationException("Test error"));
filter.OnException(context);
Assert.True(context.ExceptionHandled);
var result = Assert.IsType<ObjectResult>(context.Result);
Assert.Equal(500, result.StatusCode);
}
[Fact]
public void OnException_ResponseContainsErrorCode()
{
var filter = new ExceptionFilter(NullLogger<ExceptionFilter>.Instance);
var context = CreateContext(new InvalidOperationException("Any error"));
filter.OnException(context);
var result = Assert.IsType<ObjectResult>(context.Result);
Assert.Equal(500, result.StatusCode);
Assert.NotNull(result.Value);
}
}