Files
Heimdall/tests/Heimdall.IntegrationTests/Controllers/SitesControllerTests.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

44 lines
1.5 KiB
C#

using System.Net.Http.Json;
using Heimdall.IntegrationTests.Factories;
using Shouldly;
namespace Heimdall.IntegrationTests.Controllers;
public class SitesControllerTests : IClassFixture<HeimdallWebApplicationFactory>
{
private readonly HeimdallWebApplicationFactory _factory;
public SitesControllerTests(HeimdallWebApplicationFactory factory) => _factory = factory;
[Fact]
public async Task GetSites_WithoutAuth_ReturnsUnauthorized()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
}
[Fact]
public async Task CreateSite_WithAuth_ReturnsOk()
{
var client = await _factory.CreateAdminClientAsync();
var response = await client.PostAsJsonAsync("api/sites", new
{
name = "Site Test",
address = "Paris",
timezone = "Europe/Paris"
});
var body = await response.Content.ReadAsStringAsync();
await File.WriteAllTextAsync("/tmp/test-response-body.txt", body);
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
}
[Fact]
public async Task ListSites_WithAuth_ReturnsOk()
{
var client = await _factory.CreateAdminClientAsync();
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
}
}