d1fc336e18
GET /api/audit/export?format=parquet returned 501. It now streams the same 24 columns as csv/jsonl (AuditExportRow, CsvHeader order) as one Parquet file, one 10,000-row row group at a time. Each row group is encoded into a small non-seekable staging buffer and copied to the response asynchronously, because Kestrel rejects the synchronous writes the Parquet writer issues. New management commands, with CLI parity: - ListAuditArchives -> `audit archive list` (AuditArchiveListResult: enabled flag + every manifest). - VerifyAuditArchive(Name) -> `audit archive verify --name` (files, chain, purge anchor); exit 0 verified, 3 not verified, 1 error, 2 unauthorized. Both carry verify-chain's gate: OperationalAudit roles (Administrator, Viewer), site-scoped non-Administrator refused because an archive spans every site. VerifyAuditArchive uses the long-running Ask timeout. Error codes ARCHIVE_NOT_CONFIGURED, INVALID_ARGUMENT, NOT_FOUND. RequiredRoleMatrixTests freezes both gates; ManagementSurfaceParityTests now probes `audit archive list|verify` alongside `audit verify-chain`. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
73 lines
2.9 KiB
C#
73 lines
2.9 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, verify-chain, backfill-source-node and archive subcommands.</summary>
|
|
[Fact]
|
|
public void Audit_HasSixSubcommands_QueryExportTreeVerifyChainBackfillSourceNodeArchive()
|
|
{
|
|
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", "verify-chain" },
|
|
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.Contains("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): 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);
|
|
Assert.All(leaves, sub =>
|
|
Assert.True(sub.Action != null, $"Leaf command '{sub.Name}' has no action."));
|
|
}
|
|
}
|