From a43b2ee6af2a3547a5e57239705b74a44494b963 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 15 Jun 2026 12:29:16 -0400 Subject: [PATCH] test(sessions): cover OwnerKeyId service-layer forwarding; doc 11-param ctor Add LastOwnerKeyId capture to FakeSessionManager and assert it equals "operator01" in OpenSession_WithValidRequest_ReturnsSessionDetails, closing the gap where OwnerKeyId threading through the service layer had no test coverage. Add a to the 11-param GatewaySession convenience ctor documenting that OwnerKeyId is null there and authenticated call sites must use the 12-param overload. --- src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs | 5 +++++ .../Gateway/Grpc/MxAccessGatewayServiceTests.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs b/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs index 4a14a91..fc89d76 100644 --- a/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs +++ b/src/ZB.MOM.WW.MxGateway.Server/Sessions/GatewaySession.cs @@ -30,6 +30,11 @@ public sealed class GatewaySession /// Timeout for worker process startup. /// Timeout for worker process shutdown. /// Timestamp when the session opened. + /// + /// Constructs a session with no owner key ( will be null). + /// Authenticated call sites that have a resolved API key identity must use the + /// 12-parameter overload and pass the caller's key id explicitly. + /// public GatewaySession( string sessionId, string backendName, diff --git a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Grpc/MxAccessGatewayServiceTests.cs b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Grpc/MxAccessGatewayServiceTests.cs index 26b8aa4..5ddc009 100644 --- a/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Grpc/MxAccessGatewayServiceTests.cs +++ b/src/ZB.MOM.WW.MxGateway.Tests/Gateway/Grpc/MxAccessGatewayServiceTests.cs @@ -45,6 +45,7 @@ public sealed class MxAccessGatewayServiceTests Assert.Equal(ProtocolStatusCode.Ok, reply.ProtocolStatus.Code); Assert.Contains("unary-invoke", reply.Capabilities); Assert.Equal("Operator Key", sessionManager.LastClientIdentity); + Assert.Equal("operator01", sessionManager.LastOwnerKeyId); Assert.Equal("operator-session", sessionManager.LastOpenRequest?.ClientSessionName); } @@ -508,6 +509,9 @@ public sealed class MxAccessGatewayServiceTests /// The last client identity passed to OpenSessionAsync. public string? LastClientIdentity { get; private set; } + /// The last owner key id passed to OpenSessionAsync. + public string? LastOwnerKeyId { get; private set; } + /// The last session ID passed to ReadEventsAsync. public string? LastReadEventsSessionId { get; private set; } @@ -550,6 +554,7 @@ public sealed class MxAccessGatewayServiceTests { LastOpenRequest = request; LastClientIdentity = clientIdentity; + LastOwnerKeyId = ownerKeyId; return Task.FromResult(OpenSessionResult ?? CreateSession("session-1", processId: 1234)); }