After the rebase onto 1.4 the 16 SQLI-WIN/SQLI-SYN scripts had their own /* */ format, so SqlScriptTests (rule ids, review header, -- Kilde: blocks) failed. - The scripts have main's header (Regel-id, Titel, Alvor, Versioner, Vurdering, Grænseværdier, Rettigheder, Data kommer fra, Regelkode, Read-only); the Windows WQL/XPath stays word for word in comments. - The synthetic SQL check's SQL is registered (SyntheticCheckRunner.UseDatabaseSql, BeginTransactionSql, RollbackSql, SyntheticCheckSettings.DefaultQuery) and shown as -- Kilde: blocks in SQLI-SYN-001/002 and _collectors/SyntheticCheckRunner.sql. - SqlScriptTests know ServerRuleCatalog; only those rules may be without SQL blocks. - ServerScriptTests: every CimQueries query/filter is in a SQLI-WIN script word for word. - The SQL check cancels the rest of a large answer instead of draining it on close. - Rule counts: README (108 built-in: 92 SQL Server + 13 Windows + 3 synthetic), SQL Scripts/README (rule table, 124 rules, Windows/synthetic section), RuleCatalogTests, CONTRIBUTING (how to add a server rule). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using SQLInsight.Rules.Servers;
|
|
|
|
namespace SQLInsight.Rules.Tests;
|
|
|
|
/// <summary>Every Windows server and synthetic check rule has its reviewable script in SQL Scripts/ (named by its id).</summary>
|
|
public class ServerRuleScriptTests
|
|
{
|
|
private static DirectoryInfo Scripts()
|
|
{
|
|
for (var directory = new DirectoryInfo(AppContext.BaseDirectory); directory is not null; directory = directory.Parent)
|
|
{
|
|
var candidate = new DirectoryInfo(Path.Combine(directory.FullName, "SQL Scripts"));
|
|
if (candidate.Exists)
|
|
{
|
|
return candidate;
|
|
}
|
|
}
|
|
|
|
throw new DirectoryNotFoundException("SQL Scripts/ blev ikke fundet over testens mappe.");
|
|
}
|
|
|
|
[Fact]
|
|
public void Every_server_and_check_rule_has_a_script_with_its_id_and_title()
|
|
{
|
|
var folder = Scripts();
|
|
|
|
Assert.All(ServerRuleCatalog.All, rule =>
|
|
{
|
|
var file = Path.Combine(folder.FullName, rule.Id + ".sql");
|
|
Assert.True(File.Exists(file), $"{rule.Id}.sql mangler i SQL Scripts/.");
|
|
var text = File.ReadAllText(file).Replace("\r\n", "\n", StringComparison.Ordinal);
|
|
Assert.Contains($"-- Regel-id: {rule.Id}\n", text, StringComparison.Ordinal);
|
|
Assert.Contains($"-- Titel: {rule.Title}\n", text, StringComparison.Ordinal);
|
|
Assert.Contains("-- Vurdering", text, StringComparison.Ordinal);
|
|
Assert.DoesNotContain("sysadmin", text, StringComparison.OrdinalIgnoreCase);
|
|
});
|
|
}
|
|
}
|