Add Policy DSL Validator, Schema Exporter, and Simulation Smoke tools
- Implemented PolicyDslValidator with command-line options for strict mode and JSON output. - Created PolicySchemaExporter to generate JSON schemas for policy-related models. - Developed PolicySimulationSmoke tool to validate policy simulations against expected outcomes. - Added project files and necessary dependencies for each tool. - Ensured proper error handling and usage instructions across tools.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MongoDB.Bson;
|
||||
using StellaOps.Concelier.Storage.Mongo.Observations;
|
||||
using Xunit;
|
||||
|
||||
namespace StellaOps.Concelier.Storage.Mongo.Tests.Observations;
|
||||
|
||||
public sealed class AdvisoryObservationDocumentFactoryTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToModel_MapsDocumentToModel()
|
||||
{
|
||||
var document = new AdvisoryObservationDocument
|
||||
{
|
||||
Id = "tenant-a:obs-1",
|
||||
Tenant = "tenant-a",
|
||||
CreatedAt = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
|
||||
Source = new AdvisoryObservationSourceDocument
|
||||
{
|
||||
Vendor = "vendor",
|
||||
Stream = "stream",
|
||||
Api = "https://api.example"
|
||||
},
|
||||
Upstream = new AdvisoryObservationUpstreamDocument
|
||||
{
|
||||
UpstreamId = "CVE-2025-1234",
|
||||
DocumentVersion = "1",
|
||||
FetchedAt = DateTime.SpecifyKind(DateTime.UtcNow.AddMinutes(-1), DateTimeKind.Utc),
|
||||
ReceivedAt = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc),
|
||||
ContentHash = "sha256:abc",
|
||||
Signature = new AdvisoryObservationSignatureDocument
|
||||
{
|
||||
Present = true,
|
||||
Format = "pgp",
|
||||
KeyId = "key",
|
||||
Signature = "signature"
|
||||
}
|
||||
},
|
||||
Content = new AdvisoryObservationContentDocument
|
||||
{
|
||||
Format = "CSAF",
|
||||
SpecVersion = "2.0",
|
||||
Raw = BsonDocument.Parse("{\"example\":true}")
|
||||
},
|
||||
Linkset = new AdvisoryObservationLinksetDocument
|
||||
{
|
||||
Aliases = new List<string> { "CVE-2025-1234" },
|
||||
Purls = new List<string> { "pkg:generic/foo@1.0.0" },
|
||||
Cpes = new List<string> { "cpe:/a:vendor:product:1" },
|
||||
References = new List<AdvisoryObservationReferenceDocument>
|
||||
{
|
||||
new() { Type = "advisory", Url = "https://example.com" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var observation = AdvisoryObservationDocumentFactory.ToModel(document);
|
||||
|
||||
Assert.Equal("tenant-a:obs-1", observation.ObservationId);
|
||||
Assert.Equal("tenant-a", observation.Tenant);
|
||||
Assert.Equal("CVE-2025-1234", observation.Upstream.UpstreamId);
|
||||
Assert.Contains("pkg:generic/foo@1.0.0", observation.Linkset.Purls);
|
||||
Assert.Equal("CSAF", observation.Content.Format);
|
||||
Assert.True(observation.Content.Raw?["example"]?.GetValue<bool>());
|
||||
Assert.Equal("advisory", observation.Linkset.References[0].Type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user