fix(opcua): a configured OpcUa:EnabledSecurityProfiles list replaces the default, so None can be dropped (#879)
v2-ci / unit-tests (push) Has been cancelled

ConfigurationBinder appends configured collection items to an existing list, so
the pre-filled [None, Sign, SignAndEncrypt] default made "drop None" a no-op:
every deployment that listed only the secure profiles still advertised an
unsigned/unencrypted None endpoint.

EnabledSecurityProfiles is now null by default; ResolveEnabledSecurityProfiles()
applies the unchanged three-profile default only when nothing is configured.
A set-but-empty list fails startup validation and BuildSecurityPolicies no
longer falls back to a None endpoint on empty input (it throws). Sweep of all
options classes found no other non-empty pre-filled collection default.

Tests: options binding (indexed, JSON, env forms, default, empty, bad name), a
booted-server wire test (no None endpoint, None connection refused with
BadSecurityPolicyRejected, secure connection works; default case is the control).

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 11:38:41 -05:00
parent 1172687d4b
commit a83bf1fa27
11 changed files with 372 additions and 31 deletions
@@ -61,16 +61,13 @@ public sealed class OpcUaApplicationHostSecurityTests : IDisposable
}
/// <summary>
/// Verifies that BuildSecurityPolicies falls back to None when given empty input.
/// lmxopcua#879: an empty profile list is an error, never a silent fallback to an unsecured None endpoint.
/// </summary>
[Fact]
public void BuildSecurityPolicies_empty_input_falls_back_to_none()
public void BuildSecurityPolicies_empty_input_throws_instead_of_falling_back_to_none()
{
var policies = OpcUaApplicationHost.BuildSecurityPolicies(Array.Empty<OpcUaSecurityProfile>()).ToList();
policies.Count.ShouldBe(1);
policies[0].SecurityMode.ShouldBe(MessageSecurityMode.None);
policies[0].SecurityPolicyUri.ShouldBe(SecurityPolicies.None);
Should.Throw<InvalidOperationException>(
() => OpcUaApplicationHost.BuildSecurityPolicies(Array.Empty<OpcUaSecurityProfile>()).ToList());
}
/// <summary>
@@ -118,7 +115,7 @@ public sealed class OpcUaApplicationHostSecurityTests : IDisposable
OpcUaPort = port,
PublicHostname = "localhost",
PkiStoreRoot = _pkiRoot,
EnabledSecurityProfiles =
EnabledSecurityProfiles = new List<OpcUaSecurityProfile>
{
OpcUaSecurityProfile.None,
OpcUaSecurityProfile.Basic256Sha256Sign,