up
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Export Center CI / export-ci (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
This commit is contained in:
@@ -1,31 +1,31 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Text.Json;
|
||||
using StellaOps.Scheduler.Models;
|
||||
|
||||
namespace StellaOps.Scheduler.Models.Tests;
|
||||
|
||||
public sealed class PolicyRunModelsTests
|
||||
{
|
||||
[Fact]
|
||||
public void PolicyRunInputs_NormalizesEnvironmentKeys()
|
||||
{
|
||||
var inputs = new PolicyRunInputs(
|
||||
sbomSet: new[] { "sbom:two", "sbom:one" },
|
||||
env: new[]
|
||||
{
|
||||
new KeyValuePair<string, object?>("Sealed", true),
|
||||
new KeyValuePair<string, object?>("Exposure", "internet"),
|
||||
new KeyValuePair<string, object?>("region", JsonSerializer.SerializeToElement("global"))
|
||||
},
|
||||
captureExplain: true);
|
||||
|
||||
Assert.Equal(new[] { "sbom:one", "sbom:two" }, inputs.SbomSet);
|
||||
Assert.True(inputs.CaptureExplain);
|
||||
Assert.Equal(3, inputs.Environment.Count);
|
||||
Assert.True(inputs.Environment.ContainsKey("sealed"));
|
||||
Assert.Equal(JsonValueKind.True, inputs.Environment["sealed"].ValueKind);
|
||||
Assert.Equal("internet", inputs.Environment["exposure"].GetString());
|
||||
Assert.Equal("global", inputs.Environment["region"].GetString());
|
||||
using System.Collections.Immutable;
|
||||
using System.Text.Json;
|
||||
using StellaOps.Scheduler.Models;
|
||||
|
||||
namespace StellaOps.Scheduler.Models.Tests;
|
||||
|
||||
public sealed class PolicyRunModelsTests
|
||||
{
|
||||
[Fact]
|
||||
public void PolicyRunInputs_NormalizesEnvironmentKeys()
|
||||
{
|
||||
var inputs = new PolicyRunInputs(
|
||||
sbomSet: new[] { "sbom:two", "sbom:one" },
|
||||
env: new[]
|
||||
{
|
||||
new KeyValuePair<string, object?>("Sealed", true),
|
||||
new KeyValuePair<string, object?>("Exposure", "internet"),
|
||||
new KeyValuePair<string, object?>("region", JsonSerializer.SerializeToElement("global"))
|
||||
},
|
||||
captureExplain: true);
|
||||
|
||||
Assert.Equal(new[] { "sbom:one", "sbom:two" }, inputs.SbomSet);
|
||||
Assert.True(inputs.CaptureExplain);
|
||||
Assert.Equal(3, inputs.Environment.Count);
|
||||
Assert.True(inputs.Environment.ContainsKey("sealed"));
|
||||
Assert.Equal(JsonValueKind.True, inputs.Environment["sealed"].ValueKind);
|
||||
Assert.Equal("internet", inputs.Environment["exposure"].GetString());
|
||||
Assert.Equal("global", inputs.Environment["region"].GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -90,56 +90,56 @@ public sealed class PolicyRunModelsTests
|
||||
CancelledAt: status == PolicyRunJobStatus.Cancelled ? timestamp : null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyRunStatus_ThrowsOnNegativeAttempts()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new PolicyRunStatus(
|
||||
runId: "run:test",
|
||||
tenantId: "tenant-alpha",
|
||||
policyId: "P-1",
|
||||
policyVersion: 1,
|
||||
mode: PolicyRunMode.Full,
|
||||
status: PolicyRunExecutionStatus.Queued,
|
||||
priority: PolicyRunPriority.Normal,
|
||||
queuedAt: DateTimeOffset.UtcNow,
|
||||
attempts: -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyDiffSummary_NormalizesSeverityKeys()
|
||||
{
|
||||
var summary = new PolicyDiffSummary(
|
||||
added: 1,
|
||||
removed: 2,
|
||||
unchanged: 3,
|
||||
bySeverity: new[]
|
||||
{
|
||||
new KeyValuePair<string, PolicyDiffSeverityDelta>("critical", new PolicyDiffSeverityDelta(1, 0)),
|
||||
new KeyValuePair<string, PolicyDiffSeverityDelta>("HIGH", new PolicyDiffSeverityDelta(0, 1))
|
||||
});
|
||||
|
||||
Assert.True(summary.BySeverity.ContainsKey("Critical"));
|
||||
Assert.True(summary.BySeverity.ContainsKey("High"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyExplainTrace_LowercasesMetadataKeys()
|
||||
{
|
||||
var trace = new PolicyExplainTrace(
|
||||
findingId: "finding:alpha",
|
||||
policyId: "P-1",
|
||||
policyVersion: 1,
|
||||
tenantId: "tenant-alpha",
|
||||
runId: "run:test",
|
||||
verdict: new PolicyExplainVerdict(PolicyVerdictStatus.Passed, SeverityRank.Low, quiet: false, score: 0, rationale: "ok"),
|
||||
evaluatedAt: DateTimeOffset.UtcNow,
|
||||
metadata: ImmutableSortedDictionary.CreateRange(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("TraceId", "trace-1"),
|
||||
new KeyValuePair<string, string>("ComponentPurl", "pkg:npm/a@1.0.0")
|
||||
}));
|
||||
|
||||
Assert.Equal("trace-1", trace.Metadata["traceid"]);
|
||||
Assert.Equal("pkg:npm/a@1.0.0", trace.Metadata["componentpurl"]);
|
||||
}
|
||||
}
|
||||
[Fact]
|
||||
public void PolicyRunStatus_ThrowsOnNegativeAttempts()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new PolicyRunStatus(
|
||||
runId: "run:test",
|
||||
tenantId: "tenant-alpha",
|
||||
policyId: "P-1",
|
||||
policyVersion: 1,
|
||||
mode: PolicyRunMode.Full,
|
||||
status: PolicyRunExecutionStatus.Queued,
|
||||
priority: PolicyRunPriority.Normal,
|
||||
queuedAt: DateTimeOffset.UtcNow,
|
||||
attempts: -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyDiffSummary_NormalizesSeverityKeys()
|
||||
{
|
||||
var summary = new PolicyDiffSummary(
|
||||
added: 1,
|
||||
removed: 2,
|
||||
unchanged: 3,
|
||||
bySeverity: new[]
|
||||
{
|
||||
new KeyValuePair<string, PolicyDiffSeverityDelta>("critical", new PolicyDiffSeverityDelta(1, 0)),
|
||||
new KeyValuePair<string, PolicyDiffSeverityDelta>("HIGH", new PolicyDiffSeverityDelta(0, 1))
|
||||
});
|
||||
|
||||
Assert.True(summary.BySeverity.ContainsKey("Critical"));
|
||||
Assert.True(summary.BySeverity.ContainsKey("High"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PolicyExplainTrace_LowercasesMetadataKeys()
|
||||
{
|
||||
var trace = new PolicyExplainTrace(
|
||||
findingId: "finding:alpha",
|
||||
policyId: "P-1",
|
||||
policyVersion: 1,
|
||||
tenantId: "tenant-alpha",
|
||||
runId: "run:test",
|
||||
verdict: new PolicyExplainVerdict(PolicyVerdictStatus.Passed, SeverityRank.Low, quiet: false, score: 0, rationale: "ok"),
|
||||
evaluatedAt: DateTimeOffset.UtcNow,
|
||||
metadata: ImmutableSortedDictionary.CreateRange(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("TraceId", "trace-1"),
|
||||
new KeyValuePair<string, string>("ComponentPurl", "pkg:npm/a@1.0.0")
|
||||
}));
|
||||
|
||||
Assert.Equal("trace-1", trace.Metadata["traceid"]);
|
||||
Assert.Equal("pkg:npm/a@1.0.0", trace.Metadata["componentpurl"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user