Heimdall Gitea / Detect CI scope (pull_request) Successful in 4s
Heimdall Gitea / Build and tests (pull_request) Successful in 20m32s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 8m36s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 11m34s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Successful in 2s
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Heimdall.Application.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
namespace Heimdall.IntegrationTests.Factories;
|
|
|
|
/// <summary>
|
|
/// WebApplicationFactory for integration tests.
|
|
/// Requires a PostgreSQL connection string from <see cref="PostgreSqlContainerFixture"/>.
|
|
/// </summary>
|
|
public class HeimdallWebApplicationFactory : WebApplicationFactory<Program>
|
|
{
|
|
private readonly string _connectionString;
|
|
|
|
/// <summary>Creates a factory connected to a real PostgreSQL instance via Testcontainers.</summary>
|
|
public HeimdallWebApplicationFactory(string connectionString)
|
|
{
|
|
_connectionString = connectionString;
|
|
}
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.UseEnvironment("Testing");
|
|
builder.UseSetting("Cors:AllowedOrigins", "*");
|
|
|
|
builder.UseSetting("ConnectionStrings:Default", _connectionString);
|
|
builder.UseSetting("Database:MigrateOnStartup", "true");
|
|
|
|
// JWT config
|
|
builder.UseSetting("Jwt:Key", "ThisIsATestKeyThatIsAtLeast32BytesLong!");
|
|
builder.UseSetting("Jwt:RefreshKey", "ThisIsATestRefreshKeyThatIsAlso32Bytes!");
|
|
builder.UseSetting("Jwt:Issuer", "heimdall-test");
|
|
builder.UseSetting("Jwt:Audience", "heimdall-test");
|
|
|
|
// Stub HIBP: integration tests must never depend on an external breach-check
|
|
// API nor on a test password that happens not to be in the HIBP database
|
|
// (that made the registration command return 400: "password has appeared in a
|
|
// data breach"). Force "not breached" in tests only — production code path
|
|
// (HaveIBeenPwnedBreachChecker) is untouched.
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
services.RemoveAll<IPasswordBreachChecker>();
|
|
services.AddScoped<IPasswordBreachChecker, NoopPasswordBreachChecker>();
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>Test-only stub: never flags a password as breached. Avoids network + HIBP flakiness.</summary>
|
|
internal sealed class NoopPasswordBreachChecker : IPasswordBreachChecker
|
|
{
|
|
public Task<bool> IsPasswordBreachedAsync(string password, CancellationToken ct = default)
|
|
=> Task.FromResult(false);
|
|
}
|