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

This commit is contained in:
StellaOps Bot
2025-12-13 00:20:26 +02:00
parent e1f1bef4c1
commit 564df71bfb
2376 changed files with 334389 additions and 328032 deletions

View File

@@ -1,60 +1,60 @@
using System.Text.Json.Nodes;
using StellaOps.Notifier.Worker.Processing;
using StellaOps.Notify.Models;
using Xunit;
namespace StellaOps.Notifier.Tests;
public sealed class RuleEvaluatorTests
{
[Fact]
public void Evaluate_MatchingPolicyViolation_ReturnsActions()
{
var rule = NotifyRule.Create(
ruleId: "rule-critical",
tenantId: "tenant-a",
name: "Critical policy violation",
match: NotifyRuleMatch.Create(
eventKinds: new[] { "policy.violation" },
labels: new[] { "kev" },
minSeverity: "high",
verdicts: new[] { "fail" }),
actions: new[]
{
NotifyRuleAction.Create(
actionId: "act-slack",
channel: "chn-slack",
throttle: TimeSpan.FromMinutes(10))
});
var payload = new JsonObject
{
["verdict"] = "fail",
["severity"] = "critical",
["labels"] = new JsonArray("kev", "policy")
};
var notifyEvent = NotifyEvent.Create(
eventId: Guid.NewGuid(),
kind: "policy.violation",
tenant: "tenant-a",
ts: DateTimeOffset.UtcNow,
payload: payload,
scope: NotifyEventScope.Create(repo: "registry.local/api", digest: "sha256:123"),
actor: "policy-engine",
version: "1",
attributes: new[]
{
new KeyValuePair<string, string>("severity", "critical"),
new KeyValuePair<string, string>("verdict", "fail"),
new KeyValuePair<string, string>("kev", "true")
});
var evaluator = new DefaultNotifyRuleEvaluator();
var outcome = evaluator.Evaluate(rule, notifyEvent);
Assert.True(outcome.IsMatch);
Assert.Single(outcome.Actions);
Assert.Equal("act-slack", outcome.Actions[0].ActionId);
}
}
using System.Text.Json.Nodes;
using StellaOps.Notifier.Worker.Processing;
using StellaOps.Notify.Models;
using Xunit;
namespace StellaOps.Notifier.Tests;
public sealed class RuleEvaluatorTests
{
[Fact]
public void Evaluate_MatchingPolicyViolation_ReturnsActions()
{
var rule = NotifyRule.Create(
ruleId: "rule-critical",
tenantId: "tenant-a",
name: "Critical policy violation",
match: NotifyRuleMatch.Create(
eventKinds: new[] { "policy.violation" },
labels: new[] { "kev" },
minSeverity: "high",
verdicts: new[] { "fail" }),
actions: new[]
{
NotifyRuleAction.Create(
actionId: "act-slack",
channel: "chn-slack",
throttle: TimeSpan.FromMinutes(10))
});
var payload = new JsonObject
{
["verdict"] = "fail",
["severity"] = "critical",
["labels"] = new JsonArray("kev", "policy")
};
var notifyEvent = NotifyEvent.Create(
eventId: Guid.NewGuid(),
kind: "policy.violation",
tenant: "tenant-a",
ts: DateTimeOffset.UtcNow,
payload: payload,
scope: NotifyEventScope.Create(repo: "registry.local/api", digest: "sha256:123"),
actor: "policy-engine",
version: "1",
attributes: new[]
{
new KeyValuePair<string, string>("severity", "critical"),
new KeyValuePair<string, string>("verdict", "fail"),
new KeyValuePair<string, string>("kev", "true")
});
var evaluator = new DefaultNotifyRuleEvaluator();
var outcome = evaluator.Evaluate(rule, notifyEvent);
Assert.True(outcome.IsMatch);
Assert.Single(outcome.Actions);
Assert.Equal("act-slack", outcome.Actions[0].ActionId);
}
}