using System.Net.Http; using System.Net.Http.Headers; using Xunit; namespace StellaOps.Scanner.WebService.Tests; public sealed class ScannerApplicationFixture : IAsyncLifetime { private ScannerApplicationFactory? _authenticatedFactory; public ScannerApplicationFactory Factory { get; } = new(); /// /// Creates an HTTP client with test authentication enabled. /// public HttpClient CreateAuthenticatedClient() { _authenticatedFactory ??= Factory.WithOverrides(useTestAuthentication: true); var client = _authenticatedFactory.CreateClient(); // Add a valid test bearer token (must have at least 3 dot-separated segments per TestAuthenticationHandler) client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "test.valid.token"); return client; } public ValueTask InitializeAsync() => Factory.InitializeAsync(); public async ValueTask DisposeAsync() { _authenticatedFactory = null; await Factory.DisposeAsync(); } }