2026-03-03 14:32:21 +01:00
|
|
|
using System.Net;
|
|
|
|
|
using System.Text;
|
2026-03-06 09:19:32 +01:00
|
|
|
using WorkClub.Tests.Integration.Infrastructure;
|
2026-03-03 14:32:21 +01:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace WorkClub.Tests.Integration.Middleware;
|
|
|
|
|
|
2026-03-06 09:19:32 +01:00
|
|
|
public class TenantValidationTests : IntegrationTestBase
|
2026-03-03 14:32:21 +01:00
|
|
|
{
|
2026-03-06 09:19:32 +01:00
|
|
|
public TenantValidationTests(CustomWebApplicationFactory<Program> factory) : base(factory)
|
2026-03-03 14:32:21 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Request_WithValidTenantId_Returns200()
|
|
|
|
|
{
|
2026-03-06 09:19:32 +01:00
|
|
|
AuthenticateAs("test@test.com", new Dictionary<string, string> { ["club-1"] = "admin" });
|
|
|
|
|
SetTenant("club-1");
|
2026-03-03 14:32:21 +01:00
|
|
|
|
2026-03-06 09:19:32 +01:00
|
|
|
var response = await Client.GetAsync("/api/test");
|
2026-03-03 14:32:21 +01:00
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Request_WithNonMemberTenantId_Returns403()
|
|
|
|
|
{
|
2026-03-06 09:19:32 +01:00
|
|
|
AuthenticateAs("test@test.com", new Dictionary<string, string> { ["club-1"] = "admin" });
|
|
|
|
|
SetTenant("club-2");
|
2026-03-05 11:07:19 +01:00
|
|
|
|
2026-03-06 09:19:32 +01:00
|
|
|
var response = await Client.GetAsync("/api/test");
|
2026-03-03 14:32:21 +01:00
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Request_WithoutTenantIdHeader_Returns400()
|
|
|
|
|
{
|
2026-03-06 09:19:32 +01:00
|
|
|
AuthenticateAs("test@test.com", new Dictionary<string, string> { ["club-1"] = "admin" });
|
2026-03-03 14:32:21 +01:00
|
|
|
|
2026-03-06 09:19:32 +01:00
|
|
|
var response = await Client.GetAsync("/api/test");
|
2026-03-03 14:32:21 +01:00
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Request_WithoutAuthentication_Returns401()
|
|
|
|
|
{
|
2026-03-06 09:19:32 +01:00
|
|
|
AuthenticateAsUnauthenticated();
|
|
|
|
|
SetTenant("club-1");
|
2026-03-03 14:32:21 +01:00
|
|
|
|
2026-03-06 09:19:32 +01:00
|
|
|
var response = await Client.GetAsync("/api/test");
|
2026-03-03 14:32:21 +01:00
|
|
|
|
|
|
|
|
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
|
|
|
|
|
}
|
|
|
|
|
}
|