Renames all 11 projects (5 src + 6 tests), the .slnx solution file, all source-file namespaces, all axaml namespace references, and all v1 documentation references in CLAUDE.md and docs/*.md (excluding docs/v2/ which is already in OtOpcUa form). Also updates the TopShelf service registration name from "LmxOpcUa" to "OtOpcUa" per Phase 0 Task 0.6.
Preserves runtime identifiers per Phase 0 Out-of-Scope rules to avoid breaking v1/v2 client trust during coexistence: OPC UA `ApplicationUri` defaults (`urn:{GalaxyName}:LmxOpcUa`), server `EndpointPath` (`/LmxOpcUa`), `ServerName` default (feeds cert subject CN), `MxAccessConfiguration.ClientName` default (defensive — stays "LmxOpcUa" for MxAccess audit-trail consistency), client OPC UA identifiers (`ApplicationName = "LmxOpcUaClient"`, `ApplicationUri = "urn:localhost:LmxOpcUaClient"`, cert directory `%LocalAppData%\LmxOpcUaClient\pki\`), and the `LmxOpcUaServer` class name (class rename out of Phase 0 scope per Task 0.5 sed pattern; happens in Phase 1 alongside `LmxNodeManager → GenericDriverNodeManager` Core extraction). 23 LmxOpcUa references retained, all enumerated and justified in `docs/v2/implementation/exit-gate-phase-0.md`.
Build clean: 0 errors, 30 warnings (lower than baseline 167). Tests at strict improvement over baseline: 821 passing / 1 failing vs baseline 820 / 2 (one flaky pre-existing failure passed this run; the other still fails — both pre-existing and unrelated to the rename). `Client.UI.Tests`, `Historian.Aveva.Tests`, `Client.Shared.Tests`, `IntegrationTests` all match baseline exactly. Exit gate compliance results recorded in `docs/v2/implementation/exit-gate-phase-0.md` with all 7 checks PASS or DEFERRED-to-PR-review (#7 service install verification needs Windows service permissions on the reviewer's box).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
213 lines
7.9 KiB
C#
213 lines
7.9 KiB
C#
using System.Threading.Tasks;
|
|
using Opc.Ua;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Host.Configuration;
|
|
using ZB.MOM.WW.OtOpcUa.Host.Domain;
|
|
using ZB.MOM.WW.OtOpcUa.Tests.Helpers;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Tests.Integration
|
|
{
|
|
public class PermissionEnforcementTests
|
|
{
|
|
private static FakeAuthenticationProvider CreateTestAuthProvider()
|
|
{
|
|
return new FakeAuthenticationProvider()
|
|
.AddUser("readonly", "readonly123", AppRoles.ReadOnly)
|
|
.AddUser("writeop", "writeop123", AppRoles.WriteOperate)
|
|
.AddUser("writetune", "writetune123", AppRoles.WriteTune)
|
|
.AddUser("writeconfig", "writeconfig123", AppRoles.WriteConfigure)
|
|
.AddUser("alarmack", "alarmack123", AppRoles.AlarmAck)
|
|
.AddUser("admin", "admin123", AppRoles.ReadOnly, AppRoles.WriteOperate, AppRoles.WriteTune,
|
|
AppRoles.WriteConfigure, AppRoles.AlarmAck);
|
|
}
|
|
|
|
private static AuthenticationConfiguration CreateAuthConfig(bool anonymousCanWrite = false)
|
|
{
|
|
return new AuthenticationConfiguration
|
|
{
|
|
AllowAnonymous = true,
|
|
AnonymousCanWrite = anonymousCanWrite
|
|
};
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnonymousRead_Allowed()
|
|
{
|
|
var mxClient = new FakeMxAccessClient();
|
|
mxClient.TagValues["TestMachine_001.MachineID"] = Vtq.Good("hello");
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
mxClient,
|
|
authConfig: CreateAuthConfig(),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl);
|
|
|
|
var result = client.Read(client.MakeNodeId("TestMachine_001.MachineID"));
|
|
result.StatusCode.ShouldNotBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnonymousWrite_Denied_WhenAnonymousCanWriteFalse()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
authConfig: CreateAuthConfig(false),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl);
|
|
|
|
var status = client.Write(client.MakeNodeId("TestMachine_001.MachineID"), "test");
|
|
status.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnonymousWrite_Allowed_WhenAnonymousCanWriteTrue()
|
|
{
|
|
var mxClient = new FakeMxAccessClient();
|
|
mxClient.TagValues["TestMachine_001.MachineID"] = Vtq.Good("initial");
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
mxClient,
|
|
authConfig: CreateAuthConfig(true),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl);
|
|
|
|
var status = client.Write(client.MakeNodeId("TestMachine_001.MachineID"), "test");
|
|
status.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ReadOnlyUser_Write_Denied()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
authConfig: CreateAuthConfig(),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl, username: "readonly", password: "readonly123");
|
|
|
|
var status = client.Write(client.MakeNodeId("TestMachine_001.MachineID"), "test");
|
|
status.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task WriteOperateUser_Write_Allowed()
|
|
{
|
|
var mxClient = new FakeMxAccessClient();
|
|
mxClient.TagValues["TestMachine_001.MachineID"] = Vtq.Good("initial");
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
mxClient,
|
|
authConfig: CreateAuthConfig(),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl, username: "writeop", password: "writeop123");
|
|
|
|
var status = client.Write(client.MakeNodeId("TestMachine_001.MachineID"), "test");
|
|
status.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AlarmAckOnlyUser_Write_Denied()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
authConfig: CreateAuthConfig(),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl, username: "alarmack", password: "alarmack123");
|
|
|
|
var status = client.Write(client.MakeNodeId("TestMachine_001.MachineID"), "test");
|
|
status.Code.ShouldBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AdminUser_Write_Allowed()
|
|
{
|
|
var mxClient = new FakeMxAccessClient();
|
|
mxClient.TagValues["TestMachine_001.MachineID"] = Vtq.Good("initial");
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
mxClient,
|
|
authConfig: CreateAuthConfig(),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
await client.ConnectAsync(fixture.EndpointUrl, username: "admin", password: "admin123");
|
|
|
|
var status = client.Write(client.MakeNodeId("TestMachine_001.MachineID"), "test");
|
|
status.Code.ShouldNotBe(StatusCodes.BadUserAccessDenied);
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public async Task InvalidPassword_ConnectionRejected()
|
|
{
|
|
var fixture = OpcUaServerFixture.WithFakeMxAccessClient(
|
|
authConfig: CreateAuthConfig(),
|
|
authProvider: CreateTestAuthProvider());
|
|
await fixture.InitializeAsync();
|
|
try
|
|
{
|
|
using var client = new OpcUaTestClient();
|
|
|
|
await Should.ThrowAsync<ServiceResultException>(async () =>
|
|
await client.ConnectAsync(fixture.EndpointUrl, username: "readonly", password: "wrongpassword"));
|
|
}
|
|
finally
|
|
{
|
|
await fixture.DisposeAsync();
|
|
}
|
|
}
|
|
}
|
|
} |