a9393c8913
Lock the behaviors changed by the review-fix commit + the security invariants: - ManagementActorTests: UpdateSms/SmtpConfig now require Administrator (updated the existing success cases from Designer); + UpdateSmsConfig_WithDesignerRole_Returns Unauthorized and _WithEmptyAuthToken_PreservesExistingToken regression tests. - SecretEncryptionTests: SmsConfiguration.AuthToken stored-encrypted round-trip + null round-trip (AccountSid stays plaintext) — guards ApplySecretColumnEncryption. - ArtifactDiffTests: CompareSmsConfiguration New/Identical/Modified + the secret presence-only invariant (value never echoed, presence-flip shows <present> only). - UpdateCommandContractTests: notification sms update core fields Required, --auth-token optional. - NotificationListsPageTests: SMS recipient badge shows phone, not "Name <>". - NotificationOutboxActorDispatchTests: SMS-typed notification routes to the SMS adapter (StubAdapter.Type made configurable), not the Email adapter. - NotificationRecipientTests (new): ForEmail/ForSms + public-ctor invariants.
120 lines
6.0 KiB
C#
120 lines
6.0 KiB
C#
using System.CommandLine;
|
|
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression tests for CLI-014. The <c>Update*Command</c> records in Commons carry
|
|
/// non-nullable "core" fields (e.g. <c>string Name</c>, <c>string Protocol</c>,
|
|
/// <c>string Script</c>) — an update is a <em>whole-entity replace</em>, not a sparse
|
|
/// patch. The CLI must therefore mark those core flags as <c>Required</c>: making them
|
|
/// optional would let an omitted flag send <c>null</c>/empty and silently blank the
|
|
/// field server-side. These tests pin that contract so the documented surface and the
|
|
/// implemented surface stay aligned.
|
|
/// </summary>
|
|
public class UpdateCommandContractTests
|
|
{
|
|
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 UpdateCommand(Command group, params string[] path)
|
|
{
|
|
var current = group;
|
|
foreach (var segment in path)
|
|
current = current.Subcommands.Single(c => c.Name == segment);
|
|
return current;
|
|
}
|
|
|
|
private static void AssertRequired(Command command, params string[] requiredOptionNames)
|
|
{
|
|
foreach (var name in requiredOptionNames)
|
|
{
|
|
var option = command.Options.SingleOrDefault(o => o.Name == name);
|
|
Assert.True(option != null, $"'{command.Name}' is missing expected option '{name}'.");
|
|
Assert.True(option!.Required, $"'{command.Name}' option '{name}' must be Required (whole-replace contract).");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TemplateUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(TemplateCommands.Build(Url, Format, Username, Password), "update"), "--name");
|
|
|
|
[Fact]
|
|
public void TemplateAttributeUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(TemplateCommands.Build(Url, Format, Username, Password), "attribute", "update"), "--name", "--data-type");
|
|
|
|
[Fact]
|
|
public void TemplateAlarmUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(TemplateCommands.Build(Url, Format, Username, Password), "alarm", "update"), "--name", "--trigger-type", "--priority");
|
|
|
|
[Fact]
|
|
public void TemplateScriptUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(TemplateCommands.Build(Url, Format, Username, Password), "script", "update"), "--name", "--code");
|
|
|
|
[Fact]
|
|
public void SiteUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(SiteCommands.Build(Url, Format, Username, Password), "update"), "--name");
|
|
|
|
[Fact]
|
|
public void DataConnectionUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(DataConnectionCommands.Build(Url, Format, Username, Password), "update"), "--name", "--protocol");
|
|
|
|
[Fact]
|
|
public void ExternalSystemUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(ExternalSystemCommands.Build(Url, Format, Username, Password), "update"), "--name", "--endpoint-url", "--auth-type");
|
|
|
|
[Fact]
|
|
public void NotificationUpdate_CoreFieldsRequired()
|
|
{
|
|
// Only --name is unconditionally required. The recipient flags are channel-
|
|
// conditional (SMS Notifications S6): --emails is required for --type email and
|
|
// --phones for --type sms, so neither can be flagged Required at the option level
|
|
// — the create/update builders validate the channel/recipient pairing instead.
|
|
var update = UpdateCommand(NotificationCommands.Build(Url, Format, Username, Password), "update");
|
|
AssertRequired(update, "--name");
|
|
|
|
foreach (var name in new[] { "--emails", "--phones" })
|
|
{
|
|
var option = update.Options.SingleOrDefault(o => o.Name == name);
|
|
Assert.True(option != null, $"notification update is missing option '{name}'.");
|
|
Assert.False(option!.Required, $"notification update option '{name}' must be conditionally validated, not Required.");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void SmsUpdate_CoreFieldsRequired()
|
|
{
|
|
// `notification sms update` is a whole-replace of the SMS provider config, so its
|
|
// identity + non-secret core fields must be Required — a missing --account-sid or
|
|
// --from-number would otherwise send null and wipe a stored value. --auth-token
|
|
// stays optional (preserve-if-omitted; empty == omitted, never "clear").
|
|
var update = UpdateCommand(NotificationCommands.Build(Url, Format, Username, Password), "sms", "update");
|
|
AssertRequired(update, "--id", "--account-sid", "--from-number");
|
|
|
|
var authToken = update.Options.SingleOrDefault(o => o.Name == "--auth-token");
|
|
Assert.True(authToken != null, "sms update is missing option '--auth-token'.");
|
|
Assert.False(authToken!.Required, "sms update '--auth-token' must be optional (preserve-if-omitted).");
|
|
}
|
|
|
|
[Fact]
|
|
public void ApiMethodUpdate_CoreFieldsRequired()
|
|
=> AssertRequired(UpdateCommand(ApiMethodCommands.Build(Url, Format, Username, Password), "update"), "--script");
|
|
|
|
[Fact]
|
|
public void ExternalSystemMethodUpdate_IsGenuinelySparse_CoreFieldsOptional()
|
|
{
|
|
// UpdateExternalSystemMethodCommand is the one update record whose fields are
|
|
// genuinely all-nullable, so its flags are correctly optional. Pin that too so
|
|
// it is not mistakenly forced to Required.
|
|
var update = UpdateCommand(ExternalSystemCommands.Build(Url, Format, Username, Password), "method", "update");
|
|
foreach (var name in new[] { "--name", "--http-method", "--path" })
|
|
{
|
|
var option = update.Options.SingleOrDefault(o => o.Name == name);
|
|
Assert.True(option != null, $"method update is missing option '{name}'.");
|
|
Assert.False(option!.Required, $"method update option '{name}' should be optional (sparse-patch record).");
|
|
}
|
|
}
|
|
}
|