Add unit tests for SBOM ingestion and transformation
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Implement `SbomIngestServiceCollectionExtensionsTests` to verify the SBOM ingestion pipeline exports snapshots correctly. - Create `SbomIngestTransformerTests` to ensure the transformation produces expected nodes and edges, including deduplication of license nodes and normalization of timestamps. - Add `SbomSnapshotExporterTests` to test the export functionality for manifest, adjacency, nodes, and edges. - Introduce `VexOverlayTransformerTests` to validate the transformation of VEX nodes and edges. - Set up project file for the test project with necessary dependencies and configurations. - Include JSON fixture files for testing purposes.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
@@ -298,10 +299,44 @@ public sealed class SourceFetchService
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
throw new InvalidOperationException($"Raw advisory payload from {request.SourceName} is not valid JSON ({request.RequestUri}).", ex);
|
||||
var fallbackDocument = CreateFallbackContentDocument(request, contentBytes, ex);
|
||||
return fallbackDocument;
|
||||
}
|
||||
}
|
||||
|
||||
private static JsonDocument CreateFallbackContentDocument(
|
||||
SourceFetchRequest request,
|
||||
byte[] contentBytes,
|
||||
JsonException parseException)
|
||||
{
|
||||
var payload = new Dictionary<string, object?>
|
||||
{
|
||||
["type"] = "non-json",
|
||||
["encoding"] = "base64",
|
||||
["source"] = request.SourceName,
|
||||
["uri"] = request.RequestUri.ToString(),
|
||||
["mediaTypeHint"] = request.AcceptHeaders?.FirstOrDefault(),
|
||||
["parseError"] = parseException.Message,
|
||||
["raw"] = Convert.ToBase64String(contentBytes),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var text = Encoding.UTF8.GetString(contentBytes);
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
payload["text"] = text;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore decoding failures; base64 field already present
|
||||
}
|
||||
|
||||
var buffer = JsonSerializer.SerializeToUtf8Bytes(payload, new JsonSerializerOptions(JsonSerializerDefaults.Web));
|
||||
return JsonDocument.Parse(buffer);
|
||||
}
|
||||
|
||||
private static ImmutableDictionary<string, string> BuildProvenance(
|
||||
SourceFetchRequest request,
|
||||
HttpResponseMessage response,
|
||||
|
||||
Reference in New Issue
Block a user