save progress
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -530,12 +531,14 @@ public sealed class GhsaResilienceTests : IAsyncLifetime
|
||||
var since = initialTime - TimeSpan.FromDays(30);
|
||||
var listUri = new Uri($"https://ghsa.test/security/advisories?updated_since={Uri.EscapeDataString(since.ToString("O"))}&updated_until={Uri.EscapeDataString(initialTime.ToString("O"))}&page=1&per_page=5");
|
||||
harness.Handler.AddJsonResponse(listUri, json);
|
||||
RegisterDetailResponses(harness, json, initialTime);
|
||||
}
|
||||
|
||||
private async Task EnsureHarnessAsync(DateTimeOffset initialTime)
|
||||
{
|
||||
if (_harness is not null)
|
||||
{
|
||||
await _harness.ResetAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -558,6 +561,43 @@ public sealed class GhsaResilienceTests : IAsyncLifetime
|
||||
_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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
await ValueTask.CompletedTask;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -458,12 +459,14 @@ public sealed class GhsaSecurityTests : IAsyncLifetime
|
||||
var since = initialTime - TimeSpan.FromDays(30);
|
||||
var listUri = new Uri($"https://ghsa.test/security/advisories?updated_since={Uri.EscapeDataString(since.ToString("O"))}&updated_until={Uri.EscapeDataString(initialTime.ToString("O"))}&page=1&per_page=5");
|
||||
harness.Handler.AddJsonResponse(listUri, json);
|
||||
RegisterDetailResponses(harness, json, initialTime);
|
||||
}
|
||||
|
||||
private async Task EnsureHarnessAsync(DateTimeOffset initialTime)
|
||||
{
|
||||
if (_harness is not null)
|
||||
{
|
||||
await _harness.ResetAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -486,6 +489,43 @@ public sealed class GhsaSecurityTests : IAsyncLifetime
|
||||
_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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask InitializeAsync()
|
||||
{
|
||||
await ValueTask.CompletedTask;
|
||||
|
||||
Reference in New Issue
Block a user