Files
git.stella-ops.org/src/Scanner/__Tests/StellaOps.Scanner.WebService.Tests/ScannerApplicationFixture.cs
2026-01-17 21:32:08 +02:00

34 lines
1.0 KiB
C#

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();
/// <summary>
/// Creates an HTTP client with test authentication enabled.
/// </summary>
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();
}
}