Enhance test infrastructure and configuration for JWKS and Docker setup
ci/woodpecker/push/build-arm Pipeline was successful

- Updated Azaion.Missions.csproj to exclude test sources from service compilation, preventing build failures due to test project dependencies.
- Modified docker-compose.test.yml to preload the pg_stat_statements extension for testing and adjusted JWT refresh intervals for better test execution timing.
- Enhanced Dockerfile to install wget for health checks and ensure proper initialization of the container.
- Introduced a test-only endpoint for JWKS refresh to facilitate end-to-end testing without relying on the default refresh intervals.
- Updated DTOs in ApiDtos.cs to reflect camelCase naming conventions for consistency with service responses.
- Improved test cases to handle JWKS rotation and refresh scenarios effectively, ensuring robust validation of JWT handling.

This commit lays the groundwork for more reliable and efficient testing of the Azaion.Missions project.
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-05-16 10:20:38 +03:00
parent 001e80fe96
commit 3398ec49a0
29 changed files with 785 additions and 111 deletions
@@ -49,6 +49,7 @@ public sealed class DefaultVehicleRaceTests : TestBase, IClassFixture<DbResetFix
var observations = new int[Iterations];
// Act
for (int i = 0; i < Iterations; i++)
{
ResetVehiclesAndSeedOneDefault();
@@ -101,10 +102,11 @@ public sealed class DefaultVehicleRaceTests : TestBase, IClassFixture<DbResetFix
await conn.OpenAsync();
await using var cmd = conn.CreateCommand();
cmd.CommandText = """
INSERT INTO vehicles (id, name, is_default, created_at, updated_at)
VALUES (@id, @name, TRUE, NOW(), NOW());
INSERT INTO vehicles (id, model, name, is_default)
VALUES (@id, @model, @name, TRUE);
""";
cmd.Parameters.AddWithValue("id", vehicleId);
cmd.Parameters.AddWithValue("model", "race-model");
cmd.Parameters.AddWithValue("name", $"race-side-{vehicleId:N}");
await cmd.ExecuteNonQueryAsync();
return new SideChannelState(true, null);
@@ -122,8 +124,8 @@ public sealed class DefaultVehicleRaceTests : TestBase, IClassFixture<DbResetFix
using var cmd = conn.CreateCommand();
cmd.CommandText = """
TRUNCATE vehicles RESTART IDENTITY CASCADE;
INSERT INTO vehicles (id, name, is_default, created_at, updated_at)
VALUES (gen_random_uuid(), 'seed-default', TRUE, NOW(), NOW());
INSERT INTO vehicles (id, model, name, is_default)
VALUES (gen_random_uuid(), 'seed-model', 'seed-default', TRUE);
""";
cmd.ExecuteNonQuery();
}
@@ -53,21 +53,13 @@ public sealed class JwksRotationNoRestartTests : TestBase, IClassFixture<DbReset
using (var resp = await CallVehiclesAsync(t2.Jwt))
await HttpAssertions.AssertStatusAsync(resp, HttpStatusCode.Unauthorized);
// Act 2 — wait for refresh.
var refreshDeadline = DateTime.UtcNow.AddSeconds(90);
var refreshed = false;
while (DateTime.UtcNow < refreshDeadline)
{
using var resp = await CallVehiclesAsync(t2.Jwt);
if (resp.StatusCode == HttpStatusCode.OK)
{
refreshed = true;
break;
}
await Task.Delay(TimeSpan.FromSeconds(3));
}
Assert.True(refreshed,
"JWKS refresh did not propagate to missions within 90s");
// Act 2 — force JWKS refresh via the test-only hook (the library's
// 5-minute floor on AutomaticRefreshInterval forbids the proactive
// path and our custom IssuerSigningKeyResolver bypasses the JwtBearer
// signature-failure refresh path; see Helpers/JwksRefreshHelper.cs).
await JwksRefreshHelper.ForceRefreshAsync(Missions);
using (var resp = await CallVehiclesAsync(t2.Jwt))
await HttpAssertions.AssertStatusAsync(resp, HttpStatusCode.OK);
// Assert — service did NOT restart.
var startedAtAfter = MissionsContainerHelper.GetStartedAt("missions-sut");