sqlinsight-pro/tests/SQLInsight.Rules.Tests/PatchLevelRuleTests.cs
Claude 3c35f92785
Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Waiting to run
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
Fase 1: patch level rule with build catalog; README status
SQLI-VER-002 flags instances behind the newest known CU, security update
or final service pack (catalog as of 2026-09-29, shipped as rule pack
data and called out when older than 120 days).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
2026-09-29 07:03:25 +00:00

59 lines
2.1 KiB
C#

using SQLInsight.Core.Findings;
using SQLInsight.Core.Instances;
using SQLInsight.Rules.Engine;
using SQLInsight.Rules.Lifecycle;
using static SQLInsight.Rules.Tests.TestInstances;
namespace SQLInsight.Rules.Tests;
public class PatchLevelRuleTests
{
private static readonly PatchLevelRule Rule = new(BuildCatalog.LoadEmbedded(), SupportLifecycleCatalog.LoadEmbedded());
[Fact]
public void Catalog_has_a_build_for_every_known_release()
{
var catalog = BuildCatalog.LoadEmbedded();
foreach (var release in Enum.GetValues<SqlServerRelease>().Where(r => r != SqlServerRelease.Unknown))
{
var latest = catalog.Latest(release);
Assert.NotNull(latest);
Assert.Equal(release, latest.Build.Release);
}
}
[Fact]
public void Current_build_passes()
{
Assert.Equal(RuleOutcome.Passed, Rule.Evaluate(Context("16.0.4295.3")).Outcome);
Assert.Equal(RuleOutcome.Passed, Rule.Evaluate(Context("16.0.4300.1")).Outcome); // newer than the catalog
}
[Fact]
public void Old_cu_on_supported_release_is_high()
{
var finding = Assert.Single(Rule.Evaluate(Context("15.0.4430.1")).Findings); // 2019 CU32 without 2026 security updates
Assert.Equal(Severity.High, finding.Severity);
Assert.Contains("KB5122772", finding.Recommendation, StringComparison.Ordinal);
Assert.Contains("sikkerhedsopdatering", finding.Explanation, StringComparison.Ordinal);
}
[Fact]
public void Missing_service_pack_on_unsupported_release_is_medium()
{
var finding = Assert.Single(Rule.Evaluate(Context("10.50.4000.0")).Findings); // 2008 R2 SP2
Assert.Equal(Severity.Medium, finding.Severity);
Assert.Contains("SP3", finding.Title, StringComparison.Ordinal);
}
[Fact]
public void Old_catalog_is_called_out()
{
var finding = Assert.Single(Rule.Evaluate(Context("15.0.4430.1", new DateTimeOffset(2027, 6, 1, 0, 0, 0, TimeSpan.Zero))).Findings);
Assert.Contains(finding.Evidence, e => e.Value.Contains("forældet", StringComparison.Ordinal));
}
}