test: preserve server SDK 2.0 value security and history contracts

This commit is contained in:
Joseph Doherty
2026-11-10 10:37:52 -05:00
parent ac5e9d84f0
commit 9cddc9306b
45 changed files with 1215 additions and 641 deletions
@@ -54,7 +54,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var (_, errors) = ReadRaw(nm, identity: null, nodeId);
errors[0].StatusCode.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied);
errors[0].StatusCode.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied.Code);
}
finally { await host.DisposeAsync(); }
}
@@ -81,10 +81,10 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var (results, errors) = ReadRaw(nm, Identity(), nodeId);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
// Not BadHistoryOperationUnsupported: "you may not read this" and "this node has no history"
// are different facts, and reporting the wrong one sends an operator debugging historisation.
results[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
results[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
}
finally { await host.DisposeAsync(); }
}
@@ -106,16 +106,16 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
nm.Authorizer = Authorizer(enabled: true, GrantOn(NodePermissions.Read));
var (deniedResults, deniedErrors) = ReadRaw(nm, Identity(), modified: true, nodeId);
deniedErrors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
deniedResults[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
deniedErrors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
deniedResults[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
nm.Authorizer = Authorizer(enabled: true, GrantOn(NodePermissions.HistoryRead));
var (allowedResults, allowedErrors) = ReadRaw(nm, Identity(), modified: true, nodeId);
// A real trail entry must come back: Null's BadHistoryOperationUnsupported is also what the SDK pre-seeds,
// so asserting it would pass even if the grant never reached the modified branch.
allowedErrors[0].StatusCode.Code.ShouldBe(StatusCodes.Good);
allowedResults[0].StatusCode.Code.ShouldBe(StatusCodes.Good);
var data = ExtensionObject.ToEncodeable(allowedResults[0].HistoryData).ShouldBeOfType<HistoryModifiedData>();
allowedErrors[0].StatusCode.Code.ShouldBe(StatusCodes.Good.Code);
allowedResults[0].StatusCode.Code.ShouldBe(StatusCodes.Good.Code);
var data = ExtensionObject.ToEncodeable(allowedResults[0].HistoryData)!.ShouldBeOfType<HistoryModifiedData>();
data.DataValues.Count.ShouldBe(1);
data.ModificationInfos[0].UserName.ShouldBe("alice");
}
@@ -136,7 +136,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var (_, errors) = ReadRaw(nm, Identity(), nodeId);
errors[0].StatusCode.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied);
errors[0].StatusCode.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied.Code);
}
finally { await host.DisposeAsync(); }
}
@@ -177,8 +177,8 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var (_, errors) = ReadRaw(nm, Identity(), allowed, denied);
errors[0].StatusCode.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied);
errors[1].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
errors[0].StatusCode.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied.Code);
errors[1].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
}
finally { await host.DisposeAsync(); }
}
@@ -235,7 +235,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var errors = Write(nm, Identity(), nodeId, 42f);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.Good);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.Good.Code);
gateway.Writes.ShouldHaveSingleItem();
}
finally { await host.DisposeAsync(); }
@@ -260,7 +260,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var errors = Write(nm, Identity(), nodeId, 42f);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
gateway.Writes.ShouldBeEmpty();
}
finally { await host.DisposeAsync(); }
@@ -284,7 +284,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
var errors = Write(nm, Identity(), nodeId, 42f);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
errors[0].StatusCode.Code.ShouldBe(StatusCodes.BadUserAccessDenied.Code);
gateway.Writes.ShouldBeEmpty();
}
finally { await host.DisposeAsync(); }
@@ -303,7 +303,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
OtOpcUaNodeManager nm, IUserIdentity? identity, NodeId nodeId, object value)
{
var context = new OperationContext(
new RequestHeader(), secureChannelContext: null, RequestType.Write, identity);
new RequestHeader(), secureChannelContext: null, RequestType.Write, requestLifetime: RequestLifetime.None, identity);
var writes = new List<WriteValue>
{
@@ -311,7 +311,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
{
NodeId = nodeId,
AttributeId = Attributes.Value,
Value = new DataValue(new Variant(value)) { StatusCode = StatusCodes.Good },
Value = new DataValue(SdkValueBoundary.FromClr(value), StatusCodes.Good),
},
};
var errors = Enumerable.Repeat<ServiceResult>(null!, writes.Count).ToList();
@@ -341,7 +341,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
CancellationToken cancellationToken)
{
var t = DateTime.UtcNow.AddMinutes(-5);
var prior = new DataValueSnapshot(1.5, StatusCodes.Good, t, t);
var prior = new DataValueSnapshot(1.5, StatusCodes.Good.Code, t, t);
return Task.FromResult(new HistoryModifiedReadResult(
[new HistoryModifiedValue(prior, DateTime.UtcNow, HistoryModificationType.Replace, "alice", 1, t)], false));
}
@@ -374,7 +374,7 @@ public sealed class NodeManagerAclEnforcementTests : IDisposable
OtOpcUaNodeManager nm, IUserIdentity? identity, bool modified, params NodeId[] nodeIds)
{
var context = new OperationContext(
new RequestHeader(), secureChannelContext: null, RequestType.HistoryRead, identity);
new RequestHeader(), secureChannelContext: null, RequestType.HistoryRead, requestLifetime: RequestLifetime.None, identity);
var nodesToRead = nodeIds.Select(id => new HistoryReadValueId { NodeId = id }).ToList();
var results = Enumerable.Repeat<SdkHistoryReadResult>(null!, nodeIds.Length).ToList();