ed2ed0a367
Owner decision 2026-11-15, at IT security's request, pending a family-wide general solution. Removed: the chaining service, hasher, verifier, chain head/tombstone entities and store, the #139 chain-start cutoff, AuditLog:HashChain (incl. ChainBacklog and HeadExport with its File/Syslog sinks and export service), the audit-chain-head-export health check, the VerifyAuditChain / VerifyAuditChainHeads management commands and the `audit verify-chain` / `audit verify-heads` CLI commands, and the two-login plumbing (AuditLog:MaintenanceConnectionString, AuditMaintenanceContext, the keyed audit-maintenance repository/archive). Purge, archive, retention, partition roll-forward and backfill-source-node all run on the runtime connection again, as before #107. Parquet archive (#42) kept, chain-free: format v2 (ten stored columns, no tombstone file, manifest without chain state), the switch guard is the row count only (51003 gone), verify = data-file size, SHA-256 and row count, and superseded-stale cleanup proves coverage by EventId. Format-v1 archives still list, verify and are cleaned up (their tombstone file too). Migration RemoveAuditLogHashChain drops the chain indexes, the scadabridge_audit_chainer role (members first), both chain tables, ChainSeq/RowHash and the purger's AuditMaintenanceGrants grants; writer/purger roles stay. Down restores them. Every chain-column reference is EXEC-deferred for the idempotent script (#126); FlipAuditLogClusteredKey's two chain index statements get the same deferral, behaviour unchanged, so re-running the idempotent script on a migrated database works. The partition-switch staging table adds the chain columns only when the live table has them, so the new binary purges either schema. Deploy gate: old binaries map the chain columns, so the migration ships with the new binaries, both centrals stopped. A leftover AuditLog:HashChain section or MaintenanceConnectionString (DEV/QA still carry AuditLog__HashChain__Enabled=true) is ignored with one startup warning (RetiredAuditSettingsWarning). Claude-Session: https://claude.ai/code/session_01GT67AFKC45MBz1wPZnVbX8
73 lines
3.0 KiB
C#
73 lines
3.0 KiB
C#
using System.CommandLine;
|
|
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
|
|
|
|
/// <summary>
|
|
/// Scaffold tests for the <c>scadabridge audit</c> command group (Audit Log).
|
|
/// Verifies the parent command exists with its subcommands and that every leaf
|
|
/// has an action wired. Also covers <c>backfill-source-node</c>.
|
|
/// </summary>
|
|
public class AuditCommandsScaffoldTests
|
|
{
|
|
private static readonly Option<string> Url = new("--url") { Recursive = true };
|
|
private static readonly Option<string> Username = new("--username") { Recursive = true };
|
|
private static readonly Option<string> Password = new("--password") { Recursive = true };
|
|
private static readonly Option<string> Format = CliOptions.CreateFormatOption();
|
|
|
|
private static Command BuildAudit()
|
|
=> AuditCommands.Build(Url, Format, Username, Password);
|
|
|
|
/// <summary>Verifies that the command group is named <c>audit</c>.</summary>
|
|
[Fact]
|
|
public void Audit_Command_IsNamedAudit()
|
|
{
|
|
var audit = BuildAudit();
|
|
Assert.Equal("audit", audit.Name);
|
|
Assert.False(string.IsNullOrWhiteSpace(audit.Description));
|
|
}
|
|
|
|
/// <summary>Verifies that the audit group exposes the query, export, tree, backfill-source-node and archive subcommands (verify-chain / verify-heads removed with the hash chain, 2026-11-15).</summary>
|
|
[Fact]
|
|
public void Audit_HasFiveSubcommands_QueryExportTreeBackfillSourceNodeArchive()
|
|
{
|
|
var audit = BuildAudit();
|
|
var names = audit.Subcommands.Select(c => c.Name).OrderBy(n => n).ToArray();
|
|
Assert.Equal(
|
|
new[] { "archive", "backfill-source-node", "export", "query", "tree" },
|
|
names);
|
|
}
|
|
|
|
/// <summary>Verifies that the audit help text lists every subcommand.</summary>
|
|
[Fact]
|
|
public void Audit_HelpText_ListsAllSubcommands()
|
|
{
|
|
var root = new RootCommand();
|
|
root.Add(BuildAudit());
|
|
|
|
var output = new StringWriter();
|
|
var exit = root.Parse(new[] { "audit", "--help" })
|
|
.Invoke(new InvocationConfiguration { Output = output });
|
|
|
|
Assert.Equal(0, exit);
|
|
var text = output.ToString();
|
|
Assert.Contains("query", text);
|
|
Assert.Contains("export", text);
|
|
Assert.Contains("tree", text);
|
|
Assert.DoesNotContain("verify-chain", text);
|
|
Assert.Contains("backfill-source-node", text);
|
|
}
|
|
|
|
/// <summary>Verifies that every leaf command in the audit group has an action wired.</summary>
|
|
[Fact]
|
|
public void Audit_EveryLeafCommand_HasAnAction()
|
|
{
|
|
// `archive` is a group (list / verify, ScadaBridge#42; cleanup, ScadaBridge#109): check its leaves, not it.
|
|
var audit = BuildAudit();
|
|
var leaves = audit.Subcommands.SelectMany(c => c.Subcommands.Count == 0 ? [c] : c.Subcommands).ToList();
|
|
Assert.Equal(7, leaves.Count); // query, export, tree, backfill-source-node, archive list|verify|cleanup
|
|
Assert.All(leaves, sub =>
|
|
Assert.True(sub.Action != null, $"Leaf command '{sub.Name}' has no action."));
|
|
}
|
|
}
|