feat(backend): add PostgreSQL schema, RLS policies, and multi-tenant middleware
- Add EF Core migrations for initial schema (clubs, members, work_items, shifts, shift_signups) - Implement RLS policies with SET LOCAL for tenant isolation - Add Finbuckle multi-tenant middleware with ClaimStrategy + HeaderStrategy fallback - Create TenantValidationMiddleware to enforce JWT claims match X-Tenant-Id header - Add tenant-aware DB interceptors (SaveChangesTenantInterceptor, TenantDbConnectionInterceptor) - Configure AppDbContext with tenant scoping and RLS support - Add test infrastructure: CustomWebApplicationFactory, TestAuthHandler, DatabaseFixture - Write TDD integration tests for multi-tenant isolation and RLS enforcement - Add health check null safety for connection string Tasks: 7 (PostgreSQL schema + migrations + RLS), 8 (Finbuckle multi-tenancy + validation), 12 (test infrastructure)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace WorkClub.Tests.Integration.Infrastructure;
|
||||
|
||||
public abstract class IntegrationTestBase : IClassFixture<CustomWebApplicationFactory<Program>>, IAsyncLifetime
|
||||
{
|
||||
protected readonly HttpClient Client;
|
||||
protected readonly CustomWebApplicationFactory<Program> Factory;
|
||||
|
||||
protected IntegrationTestBase(CustomWebApplicationFactory<Program> factory)
|
||||
{
|
||||
Factory = factory;
|
||||
Client = factory.CreateClient();
|
||||
}
|
||||
|
||||
protected void AuthenticateAs(string email, Dictionary<string, string> clubs)
|
||||
{
|
||||
var clubsJson = JsonSerializer.Serialize(clubs);
|
||||
Client.DefaultRequestHeaders.Remove("X-Test-Clubs");
|
||||
Client.DefaultRequestHeaders.Add("X-Test-Clubs", clubsJson);
|
||||
|
||||
Client.DefaultRequestHeaders.Remove("X-Test-Email");
|
||||
Client.DefaultRequestHeaders.Add("X-Test-Email", email);
|
||||
}
|
||||
|
||||
protected void SetTenant(string tenantId)
|
||||
{
|
||||
Client.DefaultRequestHeaders.Remove("X-Tenant-Id");
|
||||
Client.DefaultRequestHeaders.Add("X-Tenant-Id", tenantId);
|
||||
}
|
||||
|
||||
public virtual Task InitializeAsync() => Task.CompletedTask;
|
||||
|
||||
public virtual Task DisposeAsync() => Task.CompletedTask;
|
||||
}
|
||||
Reference in New Issue
Block a user