fix(grpc-data): A4 F4 — an admitted folder event item promotes a projected folder that materialised before its mapping was condition-bearing
OnProjectedFolderMaterialised promotes condition-bearing mapping folders to SubscribeToEvents only at materialisation, and IsConditionBearingMapping needs the mapping's authority active. On a freshly restarted consumer the projected pages materialise before that authority activates, and nothing re-promoted them, so a folder-first event item was refused BadNotSupported by the SDK (MonitoredNodeMonitoredItemManager checks EventNotifier) until an i=2253 item opened demand and a condition got wired there. SubscribeToEvents: once the projected-notifier admission (mapping gate) passes, PromoteProjectedEventFolder re-evaluates IsConditionBearingMapping and promotes the folder before the SDK attach. Unauthorized callers are refused before it. Test: F4_a_folder_materialised_before_its_mapping_was_condition_bearing_… (control: refused while not condition-bearing; red with the promotion removed).
This commit is contained in:
@@ -6567,6 +6567,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
if (projectedNotifier is { } notifierId)
|
||||
{
|
||||
if (!ImportedNotifierAdmits(IdentityOf(context), notifierId)) return StatusCodes.BadUserAccessDenied;
|
||||
PromoteProjectedEventFolder(notifierId); // A4 F4: admitted ⇒ a notifier, even if it materialised before its authority
|
||||
}
|
||||
else if (SecurityFilteringActive && !unsubscribe
|
||||
&& IsHandleInNamespace(sourceId) is { } source
|
||||
|
||||
@@ -623,6 +623,27 @@ public sealed partial class OtOpcUaNodeManager : IProjectedConditionSink
|
||||
if (_importedConditions.Find(id) is { } c) WireImportedFolder(c, folder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A4 F4: promotes, just before the SDK attaches an ADMITTED event item to it (and refuses a node without
|
||||
/// <c>SubscribeToEvents</c>, <c>BadNotSupported</c>), a materialised projected folder whose mapping was not yet
|
||||
/// condition-bearing when it materialised — its authority activates at the consumer's first barrier, after the projected
|
||||
/// pages were served. Nothing re-promoted it, so a folder-first client on a freshly restarted consumer was refused until an
|
||||
/// <c>i=2253</c> item opened demand and a condition got wired there. One dictionary probe; caller holds no lock.
|
||||
/// </summary>
|
||||
/// <param name="folderId">The projected notifier the item targets.</param>
|
||||
private void PromoteProjectedEventFolder(NodeId folderId)
|
||||
{
|
||||
if (ProjectedConditionAccess is not { } access) return;
|
||||
lock (Lock)
|
||||
{
|
||||
if (_importedConditions.PromotedFolders.Contains(folderId) || !_importedConditions.FolderKeys.TryGetValue(folderId, out var key)) return;
|
||||
if (!access.IsConditionBearingMapping(key.Mapping) || FindProjectedFolder(key) is not { } folder) return;
|
||||
_importedConditions.PromotedFolders.Add(folder.NodeId);
|
||||
folder.EventNotifier = (byte)(folder.EventNotifier | EventNotifiers.SubscribeToEvents);
|
||||
folder.ClearChangeMasks(SystemContext, includeChildren: false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A projected folder is being removed: unwire it symmetrically first (N7) and drop it from the index. Under Lock.</summary>
|
||||
private void OnProjectedFolderRemoving(NodeId folderId)
|
||||
{
|
||||
|
||||
+41
-1
@@ -326,6 +326,39 @@ public sealed class ImportedConditionEventWireTests
|
||||
await Events.WaitUntilAsync(() => events.Of(grantedItem).Any(e => Message(e) == "arrived"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A4 F4: on a freshly restarted consumer the projected folders materialise before the mapping's authority is active, so
|
||||
/// materialisation does not promote them. A folder-first event item once the authority IS active must still be admitted
|
||||
/// (it opens the demand that brings the conditions in) — it was refused <c>BadNotSupported</c> by the SDK because nothing
|
||||
/// re-promoted the folder.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task F4_a_folder_materialised_before_its_mapping_was_condition_bearing_still_admits_a_folder_first_event_item()
|
||||
{
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
await using var rig = await ServerEventRig.StartAsync("a4-f4-folderfirst", encrypted: false, ct);
|
||||
var access = new FakeConditionAccess { ConditionBearing = false };
|
||||
access.Allowed.Add(Granted);
|
||||
var f = Fixture.Install(rig, access);
|
||||
using var granted = await rig.ConnectAsync(anonymous: false, ct);
|
||||
|
||||
// Control (the defect's precondition): while the mapping is not condition-bearing the folder is no notifier — refused.
|
||||
var early = await SubscribeAsync(granted, new Events(), ct);
|
||||
var refused = AddItem(early, f.AnchorB);
|
||||
await early.ApplyChangesAsync(ct);
|
||||
(refused.Status.Error?.StatusCode ?? StatusCodes.Good).Code.ShouldBe(StatusCodes.BadNotSupported.Code, "not condition-bearing yet");
|
||||
|
||||
access.ConditionBearing = true; // the authority activates after materialisation (first barrier of a restarted consumer)
|
||||
var events = new Events();
|
||||
var sub = await SubscribeAsync(granted, events, ct);
|
||||
var item = AddItem(sub, f.AnchorB);
|
||||
await sub.ApplyChangesAsync(ct);
|
||||
(item.Status.Error?.StatusCode ?? StatusCodes.Good).Code.ShouldBe(StatusCodes.Good.Code, "folder-first item admitted");
|
||||
access.Outstanding.ShouldBe(1, "the folder-only client opened condition demand");
|
||||
f.Apply(Update(Key2, version: 3, active: true, acked: false, [f.BPlacement()], message: "arrived-f4"));
|
||||
await Events.WaitUntilAsync(() => events.Of(item).Any(e => Message(e) == "arrived-f4"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Deviation6_removing_an_imported_condition_sends_RefreshRequired_only_to_the_items_that_could_see_it()
|
||||
{
|
||||
@@ -453,7 +486,9 @@ public sealed class ImportedConditionEventWireTests
|
||||
public long AuthorityGeneration => Interlocked.Read(ref Generation);
|
||||
public bool CanSubscribeFolder(RoleCarryingUserIdentity? caller, string mappingId, string folderLocalSubject) =>
|
||||
caller is not null && Allowed.Contains(caller.Principal);
|
||||
public bool IsConditionBearingMapping(string mappingId) => true;
|
||||
/// <summary>A4 F4: false models a mapping whose authority was not yet active when its folders materialised.</summary>
|
||||
public volatile bool ConditionBearing = true;
|
||||
public bool IsConditionBearingMapping(string mappingId) => ConditionBearing;
|
||||
/// <summary>Leases currently held (acquired minus released).</summary>
|
||||
public int Outstanding;
|
||||
public IDisposable? AcquireEventDemand(RoleCarryingUserIdentity? caller)
|
||||
@@ -484,6 +519,11 @@ public sealed class ImportedConditionEventWireTests
|
||||
{
|
||||
var access = new FakeConditionAccess();
|
||||
access.Allowed.Add(grantedPrincipal);
|
||||
return Install(rig, access);
|
||||
}
|
||||
|
||||
public static Fixture Install(ServerEventRig rig, FakeConditionAccess access)
|
||||
{
|
||||
rig.Nm.ProjectedConditionAccess = access; // bound before projections materialise, as the host does
|
||||
var (anchor, anchorB, device, definition) = Materialise(rig.Nm);
|
||||
return new Fixture { Rig = rig, Access = access, Anchor = anchor, AnchorB = anchorB, DeviceFolder = device, DeviceDefinition = definition };
|
||||
|
||||
Reference in New Issue
Block a user