sqlinsight-pro/tests/SQLInsight.IntegrationTests/HubFixture.cs
Claude 7088efff52
Some checks are pending
CI / Build og unit tests (push) Waiting to run
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
Fase 3: Hub portal for vendor staff
Server-rendered portal on the Hub: staff login (PBKDF2 hashes, rate
limited, antiforgery, local-only return URLs), customer overview with
the most widespread problems across customers, customer and finding
pages, support cases linked to findings, and license revocation that
takes effect on the next agent submission. add-staff CLI command.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
2026-09-29 08:58:34 +00:00

57 lines
2.1 KiB
C#

using System.Security.Cryptography;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using SQLInsight.Hub;
using SQLInsight.Licensing;
using Testcontainers.PostgreSql;
namespace SQLInsight.IntegrationTests;
/// <summary>
/// SQLInsight Hub in-process on a real PostgreSQL, with a test signing key the hub trusts.
/// </summary>
public sealed class HubFixture : IAsyncLifetime
{
public const string KeyId = "itest";
private readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder("postgres:17-alpine").Build();
private readonly ECDsa _key = ECDsa.Create(ECCurve.NamedCurves.nistP256);
public WebApplicationFactory<HubServerOptions> Factory { get; private set; } = null!;
public string PublicKey => Convert.ToBase64String(_key.ExportSubjectPublicKeyInfo());
public string ConnectionString => _postgres.GetConnectionString();
public async Task InitializeAsync()
{
await _postgres.StartAsync();
Factory = new WebApplicationFactory<HubServerOptions>().WithWebHostBuilder(b =>
{
b.UseEnvironment("Development");
b.UseSetting("ConnectionStrings:Hub", ConnectionString);
b.UseSetting($"SQLInsight:Hub:TrustedKeys:{KeyId}", PublicKey);
b.UseSetting("SQLInsight:Hub:LoginAttemptsPerMinute", "1000");
});
await HubProgram.MigrateAsync(Factory.Services);
}
public string License(string customer, LicensePlan plan = LicensePlan.Professional, int maxInstances = 0, DateTimeOffset? expires = null, string? id = null) =>
SignedDocument.Sign(new License
{
LicenseId = id ?? Guid.NewGuid().ToString("N"),
Customer = customer,
Plan = plan,
IssuedAt = DateTimeOffset.UtcNow.AddDays(-1),
ExpiresAt = expires ?? DateTimeOffset.UtcNow.AddYears(1),
MaxInstances = maxInstances,
KeyId = KeyId,
}, _key);
public async Task DisposeAsync()
{
await Factory.DisposeAsync();
await _postgres.DisposeAsync();
_key.Dispose();
}
}