audit work, fixed StellaOps.sln warnings/errors, fixed tests, sprints work, new advisories
This commit is contained in:
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Npgsql;
|
||||
@@ -17,6 +18,7 @@ using StellaOps.Scanner.Reachability.Slices;
|
||||
using StellaOps.Scanner.Storage;
|
||||
using StellaOps.Scanner.Surface.Validation;
|
||||
using StellaOps.Scanner.Triage;
|
||||
using StellaOps.Determinism;
|
||||
using StellaOps.Scanner.WebService.Diagnostics;
|
||||
using StellaOps.Scanner.WebService.Services;
|
||||
|
||||
@@ -24,7 +26,8 @@ namespace StellaOps.Scanner.WebService.Tests;
|
||||
|
||||
public sealed class ScannerApplicationFactory : WebApplicationFactory<ServiceStatus>
|
||||
{
|
||||
private readonly ScannerWebServicePostgresFixture postgresFixture;
|
||||
private readonly ScannerWebServicePostgresFixture? postgresFixture;
|
||||
private readonly bool skipPostgres;
|
||||
private readonly Dictionary<string, string?> configuration = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["scanner:api:basePath"] = "/api/v1",
|
||||
@@ -51,22 +54,44 @@ public sealed class ScannerApplicationFactory : WebApplicationFactory<ServiceSta
|
||||
private Action<IServiceCollection>? configureServices;
|
||||
private bool useTestAuthentication;
|
||||
|
||||
public ScannerApplicationFactory()
|
||||
public ScannerApplicationFactory() : this(skipPostgres: false)
|
||||
{
|
||||
postgresFixture = new ScannerWebServicePostgresFixture();
|
||||
postgresFixture.InitializeAsync().GetAwaiter().GetResult();
|
||||
|
||||
var connectionBuilder = new NpgsqlConnectionStringBuilder(postgresFixture.ConnectionString)
|
||||
{
|
||||
SearchPath = $"{postgresFixture.SchemaName},public"
|
||||
};
|
||||
configuration["scanner:storage:dsn"] = connectionBuilder.ToString();
|
||||
configuration["scanner:storage:database"] = postgresFixture.SchemaName;
|
||||
}
|
||||
|
||||
public ScannerApplicationFactory(
|
||||
Action<IDictionary<string, string?>>? configureConfiguration = null,
|
||||
Action<IServiceCollection>? configureServices = null)
|
||||
private ScannerApplicationFactory(bool skipPostgres)
|
||||
{
|
||||
this.skipPostgres = skipPostgres;
|
||||
|
||||
if (!skipPostgres)
|
||||
{
|
||||
postgresFixture = new ScannerWebServicePostgresFixture();
|
||||
postgresFixture.InitializeAsync().GetAwaiter().GetResult();
|
||||
|
||||
var connectionBuilder = new NpgsqlConnectionStringBuilder(postgresFixture.ConnectionString)
|
||||
{
|
||||
SearchPath = $"{postgresFixture.SchemaName},public"
|
||||
};
|
||||
configuration["scanner:storage:dsn"] = connectionBuilder.ToString();
|
||||
configuration["scanner:storage:database"] = postgresFixture.SchemaName;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Lightweight mode: use stub connection string
|
||||
configuration["scanner:storage:dsn"] = "Host=localhost;Database=test;";
|
||||
configuration["scanner:storage:database"] = "test";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a lightweight factory that skips PostgreSQL/Testcontainers initialization.
|
||||
/// Use this for tests that mock all database services.
|
||||
/// </summary>
|
||||
public static ScannerApplicationFactory CreateLightweight() => new(skipPostgres: true);
|
||||
|
||||
// Note: Made internal to satisfy xUnit fixture requirement of single public constructor
|
||||
internal ScannerApplicationFactory(
|
||||
Action<IDictionary<string, string?>>? configureConfiguration,
|
||||
Action<IServiceCollection>? configureServices)
|
||||
: this()
|
||||
{
|
||||
this.configureConfiguration = configureConfiguration;
|
||||
@@ -154,6 +179,13 @@ public sealed class ScannerApplicationFactory : WebApplicationFactory<ServiceSta
|
||||
services.RemoveAll<ISurfaceValidatorRunner>();
|
||||
services.AddSingleton<ISurfaceValidatorRunner, TestSurfaceValidatorRunner>();
|
||||
services.TryAddSingleton<ISliceQueryService, NullSliceQueryService>();
|
||||
services.TryAddSingleton<IGuidProvider, SystemGuidProvider>();
|
||||
|
||||
if (skipPostgres)
|
||||
{
|
||||
// Remove all hosted services that require PostgreSQL (migrations, etc.)
|
||||
services.RemoveAll<IHostedService>();
|
||||
}
|
||||
|
||||
if (useTestAuthentication)
|
||||
{
|
||||
@@ -172,7 +204,7 @@ public sealed class ScannerApplicationFactory : WebApplicationFactory<ServiceSta
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
if (disposing && postgresFixture is not null)
|
||||
{
|
||||
postgresFixture.DisposeAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user