Implement US-13 patient authentication and persistent ownership
This commit is contained in:
1 parent
ebf50827d6
commit
0ce9b2b168
36 files changed
+1203
-28
No files matched your search
@@ -1,3 +1,5 @@
|
||||
using Microsoft.AspNetCore.Authentication.BearerToken;
|
||||
using HealthApp.TestSupport;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
@@ -22,6 +24,11 @@ public sealed class ObservationApiFixture : IAsyncLifetime
|
||||
private WebApplicationFactory<ApiGateway.Program>? gateway;
|
||||
public string ConnectionString { get; private set; } = "";
|
||||
public HttpClient Client { get; private set; } = null!;
|
||||
public HttpClient RawClient { get; private set; } = null!;
|
||||
public HttpClient CreateDirectPatientClient() => service!.CreateClient();
|
||||
public HttpClient CreateDirectObservationClient() => observation!.CreateClient();
|
||||
public HttpClient CreateDirectInsightsClient() => insights!.CreateClient();
|
||||
public AuthenticatedTestClient Authentication { get; } = new();
|
||||
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
@@ -57,31 +64,39 @@ public sealed class ObservationApiFixture : IAsyncLifetime
|
||||
{
|
||||
service = new WebApplicationFactory<PatientProfileService.Program>().WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
builder.ConfigureKestrel(options => options.Listen(IPAddress.Loopback, 0));
|
||||
builder.ConfigureAppConfiguration((_, configuration) => configuration.AddInMemoryCollection(
|
||||
new Dictionary<string, string?> { ["ConnectionStrings:PatientDatabase"] = ConnectionString }));
|
||||
new Dictionary<string, string?> { ["ConnectionStrings:PatientDatabase"] = ConnectionString, ["InternalAccess:GatewayKey"] = Authentication.GatewayKey }));
|
||||
});
|
||||
service.UseKestrel(0);
|
||||
using var serviceClient = service.CreateClient();
|
||||
|
||||
gateway = new WebApplicationFactory<ApiGateway.Program>().WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
builder.ConfigureKestrel(options => options.Listen(IPAddress.Loopback, 0));
|
||||
builder.ConfigureAppConfiguration((_, configuration) => configuration.AddInMemoryCollection(
|
||||
builder.ConfigureAppConfiguration((_, configuration) => configuration.AddInMemoryCollection(Authentication.Configuration()).AddInMemoryCollection(
|
||||
new Dictionary<string, string?> { ["Services:PatientProfile:BaseUrl"] = serviceClient.BaseAddress!.ToString(),
|
||||
["Services:Insights:BaseUrl"] = "http://127.0.0.1:1/",
|
||||
["Services:Observation:BaseUrl"] = "http://127.0.0.1:1/" }));
|
||||
});
|
||||
gateway = gateway.WithWebHostBuilder(builder => builder.ConfigureServices(services =>
|
||||
services.PostConfigure<BearerTokenOptions>("Bearer", options => options.TimeProvider = Authentication.Clock)));
|
||||
gateway.UseKestrel(0);
|
||||
Client = gateway.CreateClient();
|
||||
RawClient = gateway.CreateClient();
|
||||
Client = Authentication.Wrap(RawClient);
|
||||
observation = new WebApplicationFactory<ObservationService.Program>().WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
builder.ConfigureKestrel(options => options.Listen(IPAddress.Loopback, 0));
|
||||
builder.ConfigureAppConfiguration((_, configuration) => configuration.AddInMemoryCollection(
|
||||
new Dictionary<string, string?>
|
||||
{
|
||||
["ConnectionStrings:ObservationDatabase"] = ObservationConnectionString,
|
||||
["Services:ApiGateway:BaseUrl"] = Client.BaseAddress!.ToString()
|
||||
["Services:ApiGateway:BaseUrl"] = Client.BaseAddress!.ToString(),
|
||||
["InternalAccess:GatewayKey"] = Authentication.GatewayKey,
|
||||
["Services:ApiGateway:Key"] = Authentication.ObservationServiceKey
|
||||
}));
|
||||
});
|
||||
observation.UseKestrel(0);
|
||||
@@ -89,9 +104,10 @@ public sealed class ObservationApiFixture : IAsyncLifetime
|
||||
gateway.Services.GetRequiredService<IConfiguration>()["Services:Observation:BaseUrl"] = observationClient.BaseAddress!.ToString();
|
||||
insights = new WebApplicationFactory<InsightsService.Program>().WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.UseEnvironment("Development");
|
||||
builder.ConfigureKestrel(options => options.Listen(IPAddress.Loopback, 0));
|
||||
builder.ConfigureAppConfiguration((_, configuration) => configuration.AddInMemoryCollection(
|
||||
new Dictionary<string, string?> { ["Services:ApiGateway:BaseUrl"] = Client.BaseAddress!.ToString() }));
|
||||
new Dictionary<string, string?> { ["Services:ApiGateway:BaseUrl"] = Client.BaseAddress!.ToString(), ["InternalAccess:GatewayKey"] = Authentication.GatewayKey, ["Services:ApiGateway:Key"] = Authentication.InsightsServiceKey }));
|
||||
});
|
||||
insights.UseKestrel(0);
|
||||
using var insightsClient = insights.CreateClient();
|
||||
@@ -101,6 +117,7 @@ public sealed class ObservationApiFixture : IAsyncLifetime
|
||||
public async Task RestartHostsAsync()
|
||||
{
|
||||
Client.Dispose();
|
||||
RawClient.Dispose();
|
||||
await insights!.DisposeAsync();
|
||||
if (observation is not null) await observation.DisposeAsync();
|
||||
await gateway!.DisposeAsync();
|
||||
@@ -123,10 +140,12 @@ public sealed class ObservationApiFixture : IAsyncLifetime
|
||||
public async Task DisposeAsync()
|
||||
{
|
||||
Client?.Dispose();
|
||||
RawClient?.Dispose();
|
||||
if (insights is not null) await insights.DisposeAsync();
|
||||
if (observation is not null) await observation.DisposeAsync();
|
||||
if (gateway is not null) await gateway.DisposeAsync();
|
||||
if (service is not null) await service.DisposeAsync();
|
||||
if (Directory.Exists(Authentication.KeyDirectory)) Directory.Delete(Authentication.KeyDirectory, true);
|
||||
if (string.IsNullOrEmpty(adminConnectionString)) return;
|
||||
|
||||
NpgsqlConnection.ClearAllPools();
|
||||
|
||||
Reference in new issue
Block a user