save progress
This commit is contained in:
@@ -197,7 +197,8 @@ public sealed class GhsaConnectorTests : IAsyncLifetime
|
||||
{
|
||||
if (_harness is not null)
|
||||
{
|
||||
return;
|
||||
await _harness.DisposeAsync();
|
||||
_harness = null;
|
||||
}
|
||||
|
||||
var harness = new ConnectorTestHarness(_fixture, initialTime, GhsaOptions.HttpClientName);
|
||||
|
||||
@@ -38,8 +38,7 @@ public sealed class GhsaParserSnapshotTests
|
||||
var actualJson = CanonJson.Serialize(advisory).Replace("\r\n", "\n").TrimEnd();
|
||||
|
||||
// Assert
|
||||
actualJson.Should().Be(expectedJson,
|
||||
"typical GHSA fixture should produce expected canonical advisory");
|
||||
Assert.Equal(expectedJson, actualJson);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -65,9 +65,10 @@ public sealed class GhsaResilienceTests : IAsyncLifetime
|
||||
""";
|
||||
|
||||
var results = new List<int>();
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (var i = 0; i < 3; i++)
|
||||
{
|
||||
harness.Handler.Reset();
|
||||
await EnsureHarnessAsync(initialTime);
|
||||
harness = _harness!;
|
||||
SetupListResponse(harness, initialTime, malformedAdvisory);
|
||||
|
||||
var connector = new GhsaConnectorPlugin().Create(harness.ServiceProvider);
|
||||
@@ -536,14 +537,16 @@ public sealed class GhsaResilienceTests : IAsyncLifetime
|
||||
|
||||
private async Task EnsureHarnessAsync(DateTimeOffset initialTime)
|
||||
{
|
||||
if (_harness is not null)
|
||||
if (_harness is null)
|
||||
{
|
||||
_harness = new ConnectorTestHarness(_fixture, initialTime, GhsaOptions.HttpClientName);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _harness.ResetAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
var harness = new ConnectorTestHarness(_fixture, initialTime, GhsaOptions.HttpClientName);
|
||||
await harness.EnsureServiceProviderAsync(services =>
|
||||
await _harness.EnsureServiceProviderAsync(services =>
|
||||
{
|
||||
services.AddLogging(builder => builder.AddProvider(NullLoggerProvider.Instance));
|
||||
services.AddGhsaConnector(options =>
|
||||
@@ -557,44 +560,49 @@ public sealed class GhsaResilienceTests : IAsyncLifetime
|
||||
options.SecondaryRateLimitBackoff = TimeSpan.FromMilliseconds(10);
|
||||
});
|
||||
});
|
||||
|
||||
_harness = harness;
|
||||
}
|
||||
|
||||
private static void RegisterDetailResponses(ConnectorTestHarness harness, string listJson, DateTimeOffset publishedAt)
|
||||
{
|
||||
using var document = JsonDocument.Parse(listJson);
|
||||
if (!document.RootElement.TryGetProperty("advisories", out var advisories) || advisories.ValueKind != JsonValueKind.Array)
|
||||
try
|
||||
{
|
||||
return;
|
||||
using var document = JsonDocument.Parse(listJson);
|
||||
if (!document.RootElement.TryGetProperty("advisories", out var advisories) || advisories.ValueKind != JsonValueKind.Array)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var advisory in advisories.EnumerateArray())
|
||||
{
|
||||
if (!advisory.TryGetProperty("ghsa_id", out var ghsaIdValue) || ghsaIdValue.ValueKind != JsonValueKind.String)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var ghsaId = ghsaIdValue.GetString();
|
||||
if (string.IsNullOrWhiteSpace(ghsaId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var detailUri = new Uri($"https://ghsa.test/security/advisories/{Uri.EscapeDataString(ghsaId)}");
|
||||
var detailPayload = $$"""
|
||||
{
|
||||
"ghsa_id": "{{ghsaId}}",
|
||||
"summary": "resilience fixture",
|
||||
"description": "fixture detail payload",
|
||||
"severity": "low",
|
||||
"published_at": "{{publishedAt:O}}",
|
||||
"updated_at": "{{publishedAt:O}}"
|
||||
}
|
||||
""";
|
||||
|
||||
harness.Handler.AddJsonResponse(detailUri, detailPayload);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var advisory in advisories.EnumerateArray())
|
||||
catch (JsonException)
|
||||
{
|
||||
if (!advisory.TryGetProperty("ghsa_id", out var ghsaIdValue) || ghsaIdValue.ValueKind != JsonValueKind.String)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var ghsaId = ghsaIdValue.GetString();
|
||||
if (string.IsNullOrWhiteSpace(ghsaId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var detailUri = new Uri($"https://ghsa.test/security/advisories/{Uri.EscapeDataString(ghsaId)}");
|
||||
var detailPayload = $$"""
|
||||
{
|
||||
"ghsa_id": "{{ghsaId}}",
|
||||
"summary": "resilience fixture",
|
||||
"description": "fixture detail payload",
|
||||
"severity": "low",
|
||||
"published_at": "{{publishedAt:O}}",
|
||||
"updated_at": "{{publishedAt:O}}"
|
||||
}
|
||||
""";
|
||||
|
||||
harness.Handler.AddJsonResponse(detailUri, detailPayload);
|
||||
// Malformed list payloads are handled by caller; skip detail registration.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,16 @@ public sealed class GhsaSecurityTests : IAsyncLifetime
|
||||
""";
|
||||
|
||||
SetupListResponse(harness, initialTime, oversizedResponse);
|
||||
var detailUri = new Uri("https://ghsa.test/security/advisories/GHSA-big-data-1234");
|
||||
harness.Handler.AddJsonResponse(detailUri, """
|
||||
{
|
||||
"ghsa_id": "GHSA-big-data-1234",
|
||||
"summary": "Large payload detail",
|
||||
"severity": "high",
|
||||
"published_at": "2024-10-02T00:00:00Z",
|
||||
"updated_at": "2024-10-02T00:00:00Z"
|
||||
}
|
||||
""");
|
||||
|
||||
var connector = new GhsaConnectorPlugin().Create(harness.ServiceProvider);
|
||||
|
||||
@@ -491,38 +501,45 @@ public sealed class GhsaSecurityTests : IAsyncLifetime
|
||||
|
||||
private static void RegisterDetailResponses(ConnectorTestHarness harness, string listJson, DateTimeOffset publishedAt)
|
||||
{
|
||||
using var document = JsonDocument.Parse(listJson);
|
||||
if (!document.RootElement.TryGetProperty("advisories", out var advisories) || advisories.ValueKind != JsonValueKind.Array)
|
||||
try
|
||||
{
|
||||
return;
|
||||
using var document = JsonDocument.Parse(listJson);
|
||||
if (!document.RootElement.TryGetProperty("advisories", out var advisories) || advisories.ValueKind != JsonValueKind.Array)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var advisory in advisories.EnumerateArray())
|
||||
{
|
||||
if (!advisory.TryGetProperty("ghsa_id", out var ghsaIdValue) || ghsaIdValue.ValueKind != JsonValueKind.String)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var ghsaId = ghsaIdValue.GetString();
|
||||
if (string.IsNullOrWhiteSpace(ghsaId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var detailUri = new Uri($"https://ghsa.test/security/advisories/{Uri.EscapeDataString(ghsaId)}");
|
||||
var detailPayload = $$"""
|
||||
{
|
||||
"ghsa_id": "{{ghsaId}}",
|
||||
"summary": "security advisory",
|
||||
"description": "fixture detail payload",
|
||||
"severity": "low",
|
||||
"published_at": "{{publishedAt:O}}",
|
||||
"updated_at": "{{publishedAt:O}}"
|
||||
}
|
||||
""";
|
||||
|
||||
harness.Handler.AddJsonResponse(detailUri, detailPayload);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var advisory in advisories.EnumerateArray())
|
||||
catch (JsonException)
|
||||
{
|
||||
if (!advisory.TryGetProperty("ghsa_id", out var ghsaIdValue) || ghsaIdValue.ValueKind != JsonValueKind.String)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var ghsaId = ghsaIdValue.GetString();
|
||||
if (string.IsNullOrWhiteSpace(ghsaId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var detailUri = new Uri($"https://ghsa.test/security/advisories/{Uri.EscapeDataString(ghsaId)}");
|
||||
var detailPayload = $$"""
|
||||
{
|
||||
"ghsa_id": "{{ghsaId}}",
|
||||
"summary": "security advisory",
|
||||
"description": "fixture detail payload",
|
||||
"severity": "low",
|
||||
"published_at": "{{publishedAt:O}}",
|
||||
"updated_at": "{{publishedAt:O}}"
|
||||
}
|
||||
""";
|
||||
|
||||
harness.Handler.AddJsonResponse(detailUri, detailPayload);
|
||||
// Malformed list payloads are handled by caller; skip detail registration.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,3 +8,4 @@ Source of truth: `docs/implplan/SPRINT_20251229_049_BE_csproj_audit_maint_tests.
|
||||
| AUDIT-0176-M | DONE | Maintainability audit for StellaOps.Concelier.Connector.Ghsa.Tests. |
|
||||
| AUDIT-0176-T | DONE | Test coverage audit for StellaOps.Concelier.Connector.Ghsa.Tests. |
|
||||
| AUDIT-0176-A | TODO | Pending approval for changes. |
|
||||
| CICD-VAL-SMOKE-001 | DONE | Smoke validation: harness reset keeps service provider intact. |
|
||||
|
||||
Reference in New Issue
Block a user