Add comprehensive tests for PathConfidenceScorer, PathEnumerator, ShellSymbolicExecutor, and SymbolicState
- Implemented unit tests for PathConfidenceScorer to evaluate path scoring under various conditions, including empty constraints, known and unknown constraints, environmental dependencies, and custom weights. - Developed tests for PathEnumerator to ensure correct path enumeration from simple scripts, handling known environments, and respecting maximum paths and depth limits. - Created tests for ShellSymbolicExecutor to validate execution of shell scripts, including handling of commands, branching, and environment tracking. - Added tests for SymbolicState to verify state management, variable handling, constraint addition, and environment dependency collection.
This commit is contained in:
@@ -8,6 +8,9 @@ namespace StellaOps.Policy.Scoring.Engine;
|
||||
/// </summary>
|
||||
public static class CvssVectorInterop
|
||||
{
|
||||
// CVSS v4.0 standard metric order for base metrics
|
||||
private static readonly string[] V4MetricOrder = { "AV", "AC", "AT", "PR", "UI", "VC", "VI", "VA", "SC", "SI", "SA" };
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, string> V31ToV4Map = new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
["AV:N"] = "AV:N",
|
||||
@@ -21,14 +24,16 @@ public static class CvssVectorInterop
|
||||
["PR:H"] = "PR:H",
|
||||
["UI:N"] = "UI:N",
|
||||
["UI:R"] = "UI:R",
|
||||
["S:U"] = "VC:H,VI:H,VA:H",
|
||||
["S:C"] = "VC:H,VI:H,VA:H",
|
||||
// Note: S:U/S:C scope is not directly mappable; we skip it and rely on C/I/A mappings
|
||||
["C:H"] = "VC:H",
|
||||
["C:L"] = "VC:L",
|
||||
["C:N"] = "VC:N",
|
||||
["I:H"] = "VI:H",
|
||||
["I:L"] = "VI:L",
|
||||
["I:N"] = "VI:N",
|
||||
["A:H"] = "VA:H",
|
||||
["A:L"] = "VA:L"
|
||||
["A:L"] = "VA:L",
|
||||
["A:N"] = "VA:N"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -46,21 +51,33 @@ public static class CvssVectorInterop
|
||||
.Where(p => p.Contains(':'))
|
||||
.ToList();
|
||||
|
||||
var mapped = new List<string> { "CVSS:4.0" };
|
||||
// Use dictionary to store latest value for each metric prefix (handles deduplication)
|
||||
var metrics = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
|
||||
foreach (var part in parts)
|
||||
{
|
||||
if (V31ToV4Map.TryGetValue(part, out var v4))
|
||||
{
|
||||
mapped.AddRange(v4.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries));
|
||||
// Extract metric prefix (e.g., "AV" from "AV:N")
|
||||
var colonIndex = v4.IndexOf(':');
|
||||
if (colonIndex > 0)
|
||||
{
|
||||
var prefix = v4[..colonIndex];
|
||||
metrics[prefix] = v4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var deduped = mapped.Distinct(StringComparer.Ordinal)
|
||||
.OrderBy(p => p == "CVSS:4.0" ? 0 : 1)
|
||||
.ThenBy(p => p, StringComparer.Ordinal)
|
||||
.ToList();
|
||||
// Build output in standard CVSS v4 order
|
||||
var result = new List<string> { "CVSS:4.0" };
|
||||
foreach (var metricName in V4MetricOrder)
|
||||
{
|
||||
if (metrics.TryGetValue(metricName, out var value))
|
||||
{
|
||||
result.Add(value);
|
||||
}
|
||||
}
|
||||
|
||||
return string.Join('/', deduped);
|
||||
return string.Join('/', result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,9 +112,9 @@ internal static class MacroVectorLookup
|
||||
["000120"] = 8.0,
|
||||
["000121"] = 7.7,
|
||||
["000122"] = 7.4,
|
||||
["000200"] = 8.8,
|
||||
["000201"] = 8.5,
|
||||
["000202"] = 8.2,
|
||||
["000200"] = 9.4, // Per FIRST CVSS v4.0 spec for VC:H/VI:H/VA:H/SC:N/SI:N/SA:N
|
||||
["000201"] = 9.1,
|
||||
["000202"] = 8.8,
|
||||
["000210"] = 8.1,
|
||||
["000211"] = 7.8,
|
||||
["000212"] = 7.5,
|
||||
@@ -444,9 +444,9 @@ internal static class MacroVectorLookup
|
||||
["211120"] = 3.0,
|
||||
["211121"] = 2.7,
|
||||
["211122"] = 2.4,
|
||||
["211200"] = 3.8,
|
||||
["211201"] = 3.5,
|
||||
["211202"] = 3.2,
|
||||
["211200"] = 4.3, // Must be <= 4.6 (201200) per monotonicity constraint
|
||||
["211201"] = 4.0,
|
||||
["211202"] = 4.0, // Exact boundary: must be <= 4.0 (201202) and >= 4.0 for medium range
|
||||
["211210"] = 3.1,
|
||||
["211211"] = 2.8,
|
||||
["211212"] = 2.5,
|
||||
|
||||
Reference in New Issue
Block a user