From 0a2277a081bc0fbff87af71661bc3b5dcab08043 Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:05:25 +1300 Subject: [PATCH 1/2] Read PLAY entitlement by canonical tenant UUID Game Session PLAY resolves the canonical tenant UUID from Game Design (new ResolveCanonicalTenant read, same-namespace Game Session only) and asks Account for entitlement by that UUID, with no numeric fallback. Account reads the tenant's current demo source; script-seeded preview tenants with no Account source are entitled only under the pre-v1 gate waiver, listed in the player access tracker. Paid hosting stays unavailable here. Co-Authored-By: Claude Opus 5.5 --- design/grpc-docs/grpc-api.md | 36 +++++++++- .../player-access-and-session.md | 2 + protos/account/v1/account_service.proto | 1 + .../game-design/v1/game_design_service.proto | 11 +++ .../dto/RuntimeEntitlementsDto.java | 4 +- ...AccountTenantAuthorityEventRepository.java | 12 ++++ .../service/AccountService.java | 2 +- .../service/impl/AccountGrpcService.java | 4 +- .../service/impl/AccountServiceImpl.java | 72 ++++++++++++++++--- ...timeEntitlementNoWriteIntegrationTest.java | 2 +- .../service/impl/AccountGrpcServiceTest.java | 38 +++++----- .../service/impl/AccountServiceImplTest.java | 37 +++++++++- .../LegacySubscriptionContainmentTest.java | 7 +- .../service/impl/GameDesignGrpcService.java | 63 ++++++++++++++++ .../impl/GameDesignGrpcServiceAuthTest.java | 47 ++++++++++++ .../gamesession/client/GameDesignClient.java | 19 +++++ .../command/text/PlayCommandHandler.java | 32 ++++++++- .../command/text/PlayCommandHandlerTest.java | 52 ++++++++++++-- .../text/SessionResumptionFlowTest.java | 19 ++++- .../text/TextCommandInterpreterTest.java | 19 ++++- 20 files changed, 434 insertions(+), 45 deletions(-) diff --git a/design/grpc-docs/grpc-api.md b/design/grpc-docs/grpc-api.md index 1c97743007..d10b13f60c 100644 --- a/design/grpc-docs/grpc-api.md +++ b/design/grpc-docs/grpc-api.md @@ -661,6 +661,8 @@ for conventions on schema evolution and error handling. See each service's - [ReconnectionSettingsOverride](#gamedesign-v1-ReconnectionSettingsOverride) - [RepairPublishedVersionAssetsRequest](#gamedesign-v1-RepairPublishedVersionAssetsRequest) - [RepairPublishedVersionAssetsResponse](#gamedesign-v1-RepairPublishedVersionAssetsResponse) + - [ResolveCanonicalTenantRequest](#gamedesign-v1-ResolveCanonicalTenantRequest) + - [ResolveCanonicalTenantResponse](#gamedesign-v1-ResolveCanonicalTenantResponse) - [ResolveHelpTopicRequest](#gamedesign-v1-ResolveHelpTopicRequest) - [ResolveHelpTopicResponse](#gamedesign-v1-ResolveHelpTopicResponse) - [ResolveLaunchDescriptorRequest](#gamedesign-v1-ResolveLaunchDescriptorRequest) @@ -1947,7 +1949,7 @@ Result of a CreateAccount call. | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| tenant_id | [string](#string) | | | +| tenant_id | [string](#string) | | Canonical tenant UUID. | | request_id | [string](#string) | | | @@ -11224,6 +11226,37 @@ Complete immutable registration receipt, without another RPC's transient rea + + +### ResolveCanonicalTenantRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| tenant_id | [string](#string) | | | + + + + + + + + +### ResolveCanonicalTenantResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| canonical_tenant_id | [string](#string) | | | +| error | [shared.v1.ErrorDetail](#shared-v1-ErrorDetail) | | | + + + + + + ### ResolveHelpTopicRequest @@ -11805,6 +11838,7 @@ Standalone, unregistered exact version-state read for an already-intaken authore | GetDesignControlPlaneDigest | [GetDesignControlPlaneDigestRequest](#gamedesign-v1-GetDesignControlPlaneDigestRequest) | [GetDesignControlPlaneDigestResponse](#gamedesign-v1-GetDesignControlPlaneDigestResponse) | | | GetPublishedReleaseBundle | [GetPublishedReleaseBundleRequest](#gamedesign-v1-GetPublishedReleaseBundleRequest) | [GetPublishedReleaseBundleResponse](#gamedesign-v1-GetPublishedReleaseBundleResponse) | | | GetVersionState | [GetVersionStateRequest](#gamedesign-v1-GetVersionStateRequest) | [GetVersionStateResponse](#gamedesign-v1-GetVersionStateResponse) | | +| ResolveCanonicalTenant | [ResolveCanonicalTenantRequest](#gamedesign-v1-ResolveCanonicalTenantRequest) | [ResolveCanonicalTenantResponse](#gamedesign-v1-ResolveCanonicalTenantResponse) | Canonical tenant UUID for a Game Design tenant key; Game Design owns tenant identity. | | CompareAndSetVersionState | [CompareAndSetVersionStateRequest](#gamedesign-v1-CompareAndSetVersionStateRequest) | [CompareAndSetVersionStateResponse](#gamedesign-v1-CompareAndSetVersionStateResponse) | | | ResolveLaunchDescriptor | [ResolveLaunchDescriptorRequest](#gamedesign-v1-ResolveLaunchDescriptorRequest) | [ResolveLaunchDescriptorResponse](#gamedesign-v1-ResolveLaunchDescriptorResponse) | | | GetLaunchDescriptor | [GetLaunchDescriptorRequest](#gamedesign-v1-GetLaunchDescriptorRequest) | [GetLaunchDescriptorResponse](#gamedesign-v1-GetLaunchDescriptorResponse) | | diff --git a/design/project-management/implementation-tracking/player-access-and-session.md b/design/project-management/implementation-tracking/player-access-and-session.md index aea029334a..42f1829c61 100644 --- a/design/project-management/implementation-tracking/player-access-and-session.md +++ b/design/project-management/implementation-tracking/player-access-and-session.md @@ -21,6 +21,8 @@ Under ADR 0185 (no data carry-over before v1, proposed in #3459), Compose smoke | Waived gate | Owed before v1 | | --- | --- | | Gateway `gameplayRouteReadiness` reports ready | Canonical Account connect-context production, shared replay fencing and dedicated Gateway signing keys | +| Account runtime entitlement grants a tenant UUID that has no Account tenant source (script-seeded preview tenants) | Seeded tenants created through the real Game Design to Account tenant-creation flow, giving each an Account demo or paid source | +| Direct-text PLAY runs on the existing direct LOGIN until the authenticated LOGIN, WORLDS, REALMS and JOIN receiver lands (stacked straight after UUID PLAY is green) | Deployed Account JWT signer materializer and public-JWKS API binding, protected Coordination Redis (TLS, ACL, AOF acknowledgement) and the external Coordination qualification authority, then PLAY moved onto the authenticated receiver | ### Direct-text scope and JOIN identifier cutover diff --git a/protos/account/v1/account_service.proto b/protos/account/v1/account_service.proto index 0d5cc807cb..53cbbd75b8 100644 --- a/protos/account/v1/account_service.proto +++ b/protos/account/v1/account_service.proto @@ -255,6 +255,7 @@ message GetRealmAccessGrantForRuntimeResponse { } message GetTenantEntitlementsForRuntimeRequest { + // Canonical tenant UUID. string tenant_id = 1; string request_id = 2; } diff --git a/protos/game-design/v1/game_design_service.proto b/protos/game-design/v1/game_design_service.proto index e368953555..8ea02e66b1 100644 --- a/protos/game-design/v1/game_design_service.proto +++ b/protos/game-design/v1/game_design_service.proto @@ -31,6 +31,8 @@ service GameDesignService { rpc GetPublishedReleaseBundle(GetPublishedReleaseBundleRequest) returns (GetPublishedReleaseBundleResponse); rpc GetVersionState(GetVersionStateRequest) returns (GetVersionStateResponse); + // Canonical tenant UUID for a Game Design tenant key; Game Design owns tenant identity. + rpc ResolveCanonicalTenant(ResolveCanonicalTenantRequest) returns (ResolveCanonicalTenantResponse); rpc CompareAndSetVersionState(CompareAndSetVersionStateRequest) returns (CompareAndSetVersionStateResponse); rpc ResolveLaunchDescriptor(ResolveLaunchDescriptorRequest) @@ -332,6 +334,15 @@ message GetPublishedReleaseBundleResponse { shared.v1.ErrorDetail error = 2; } +message ResolveCanonicalTenantRequest { + string tenant_id = 1; +} + +message ResolveCanonicalTenantResponse { + string canonical_tenant_id = 1; + shared.v1.ErrorDetail error = 2; +} + message GetVersionStateRequest { string tenant_id = 1; int64 version_id = 2; diff --git a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/dto/RuntimeEntitlementsDto.java b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/dto/RuntimeEntitlementsDto.java index 19ad9cfe05..816e74c4ee 100644 --- a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/dto/RuntimeEntitlementsDto.java +++ b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/dto/RuntimeEntitlementsDto.java @@ -1,7 +1,9 @@ package net.firedevops.firemud.accountservice.dto; +import java.util.UUID; + public record RuntimeEntitlementsDto( - Long tenantId, + UUID tenantId, boolean gameplayAvailable, boolean allowPublicJoin, long entitlementVersion, diff --git a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/repository/AccountTenantAuthorityEventRepository.java b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/repository/AccountTenantAuthorityEventRepository.java index ac817af7f1..7d625c64f3 100644 --- a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/repository/AccountTenantAuthorityEventRepository.java +++ b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/repository/AccountTenantAuthorityEventRepository.java @@ -11,6 +11,7 @@ import net.firedevops.firemud.common.tenant.FreshTenantCreationEvidence; import org.jooq.DSLContext; import org.jooq.Record; +import org.jooq.impl.DSL; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -57,6 +58,17 @@ public AccountTenantAuthorityEventRepository( this.generations = Objects.requireNonNull(generations); } + /** Whether any current tenant source row exists; it grants no entitlement authority. */ + @Transactional(propagation = Propagation.MANDATORY) + public boolean hasCurrentSource(UUID tenantId) { + requireTransaction(); + requireTenant(tenantId); + return dsl.fetchExists( + dsl.selectOne() + .from(DSL.table(DSL.name("account_tenant_authority_source_records"))) + .where(DSL.field(DSL.name("tenant_uuid"), UUID.class).eq(tenantId))); + } + /** Data-only routing hint over the exact current source; it grants no entitlement authority. */ @Transactional(propagation = Propagation.MANDATORY) public SourceSelection readCurrentSourceSelection(UUID tenantId) { diff --git a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/AccountService.java b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/AccountService.java index 93c117a14c..1fdb2fe3ca 100644 --- a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/AccountService.java +++ b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/AccountService.java @@ -79,7 +79,7 @@ RealmAccessGrantResult getRealmAccessGrantForRuntime( void revokeRealmAccess(Long accountId, Long tenantId, String worldSlug, String realmSlug); - RuntimeEntitlementsDto getTenantEntitlementsForRuntime(Long tenantId, String requestId); + RuntimeEntitlementsDto getTenantEntitlementsForRuntime(UUID tenantId, String requestId); ProfileDto getProfile(Long tenantId, Long accountId); diff --git a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountGrpcService.java b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountGrpcService.java index a0addcc784..eb469c7a02 100644 --- a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountGrpcService.java +++ b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountGrpcService.java @@ -725,12 +725,12 @@ public void getTenantEntitlementsForRuntime( StreamObserver responseObserver) { try { requireRuntimeEntitlementsPeer(); - long tenantId = requirePositiveRequestId(request.getTenantId(), "tenantId"); + UUID tenantId = requireCanonicalUuid(request.getTenantId(), "tenantId"); String requestId = requireText(request.getRequestId(), "requestId"); var dto = accountService.getTenantEntitlementsForRuntime(tenantId, requestId); GetTenantEntitlementsForRuntimeResponse response = GetTenantEntitlementsForRuntimeResponse.newBuilder() - .setTenantId(String.valueOf(dto.tenantId())) + .setTenantId(dto.tenantId().toString()) .setGameplayAvailable(dto.gameplayAvailable()) .setAllowPublicJoin(dto.allowPublicJoin()) .setEntitlementVersion(dto.entitlementVersion()) diff --git a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountServiceImpl.java b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountServiceImpl.java index 17deafaa58..c32b739f58 100644 --- a/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountServiceImpl.java +++ b/services/account-service/src/main/java/net/firedevops/firemud/accountservice/service/impl/AccountServiceImpl.java @@ -126,6 +126,7 @@ import net.firedevops.firemud.common.gamesession.CanonicalGameplayAdmissionDecisionReadGrpcCodec.PublishedRealmEvidence; import net.firedevops.firemud.common.gamesession.CanonicalGameplayAdmissionDecisionReadGrpcCodec.RetainedTargetSelector; import net.firedevops.firemud.common.gamesession.CanonicalGameplayAdmissionDecisionReadGrpcCodec.Target; +import net.firedevops.firemud.common.prev1.PreV1GateWaivers; import net.firedevops.firemud.common.security.JwtAuthProperties; import net.firedevops.firemud.common.security.JwtClaims; import net.firedevops.firemud.common.security.JwtUtil; @@ -170,6 +171,7 @@ public class AccountServiceImpl implements AccountService { private volatile AccountCanonicalPublicRealmScopeOwner canonicalPublicRealmScopeOwner; private volatile CanonicalScopeConsumers canonicalScopeConsumers; private volatile AccountBootstrapRosterReadClient accountBootstrapRosterReadClient; + private volatile RuntimeEntitlementSources runtimeEntitlementSources; private final AccountRepository accountRepository; private final AccountAuthorityGenerationRepository accountAuthorityGenerationRepository; @@ -475,6 +477,24 @@ public List listBootstrapWorlds(String bootstrapToken) { return owner.listWorlds(bootstrapToken); } + /** Canonical tenant entitlement sources for the runtime PLAY read, keyed by tenant UUID. */ + @Autowired(required = false) + public void setRuntimeEntitlementSources( + AccountTenantAuthorityEventRepository tenantSources, + AccountDemoTenantEntitlementRepository demos, + PreV1GateWaivers waivers) { + runtimeEntitlementSources = + new RuntimeEntitlementSources( + Objects.requireNonNull(tenantSources), + Objects.requireNonNull(demos), + Objects.requireNonNull(waivers)); + } + + private record RuntimeEntitlementSources( + AccountTenantAuthorityEventRepository tenantSources, + AccountDemoTenantEntitlementRepository demos, + PreV1GateWaivers waivers) {} + /** * Explicit held composition; the owner retains the signed V2 selector before publication. Its * direct-text entry point authenticates the existing Game Session caller separately. @@ -1240,12 +1260,47 @@ private String responseAccountUuid(Account account, Long accountId) { } } - private RuntimeEntitlementsDto readTenantEntitlements(long tenantId, boolean lockSubscription) { - // Retained numeric rows cannot supply canonical identity, provider provenance, current-row - // selection, or a committed billing checkpoint. Deny before any historical evidence read. - throw new AuthenticationException( - "ENTITLEMENT_UNAVAILABLE", - "Canonical tenant entitlement authority is unavailable; retry later"); + private RuntimeEntitlementsDto readTenantEntitlements(UUID tenantId) { + RuntimeEntitlementSources sources = runtimeEntitlementSources; + if (sources == null) { + throw new AuthenticationException( + "ENTITLEMENT_UNAVAILABLE", + "Canonical tenant entitlement authority is unavailable; retry later"); + } + try { + return Objects.requireNonNull( + joinTransactionTemplate.execute(status -> readTenantEntitlements(sources, tenantId))); + } catch (AuthenticationException denied) { + throw denied; + } catch (RuntimeException failure) { + throw new AuthenticationException( + "ENTITLEMENT_UNAVAILABLE", + "Canonical tenant entitlement authority is unavailable; retry later", + failure); + } + } + + private RuntimeEntitlementsDto readTenantEntitlements( + RuntimeEntitlementSources sources, UUID tenantId) { + if (sources.waivers().enabled() && !sources.tenantSources().hasCurrentSource(tenantId)) { + // Pre-v1 waiver (ADR 0185): script-seeded preview tenants have no Account tenant-creation + // source yet, so they are entitled for gameplay without one. + return new RuntimeEntitlementsDto(tenantId, true, true, 1L, 1L, Instant.now().toString()); + } + SourceSelection source = sources.tenantSources().readCurrentSourceSelection(tenantId); + if (source.kind() != AccountTenantAuthorityEventRepository.SourceKind.NON_PAID_DEMO) { + // Paid hosting needs the provider observation outside SQL; it is not composed here yet. + throw new AuthenticationException( + "ENTITLEMENT_UNAVAILABLE", "Paid tenant entitlement read is unavailable; retry later"); + } + var demo = sources.demos().readCurrent(tenantId); + return new RuntimeEntitlementsDto( + tenantId, + demo.gameplayAvailable(), + demo.allowPublicJoin(), + demo.entitlementVersion(), + demo.tenantBillingSequence(), + Instant.now().toString()); } @Override @@ -1350,10 +1405,9 @@ public void revokeRealmAccess(Long accountId, Long tenantId, String worldSlug, S } @Override - @Transactional(readOnly = true) @Timed(value = "account.runtime_entitlements") - public RuntimeEntitlementsDto getTenantEntitlementsForRuntime(Long tenantId, String requestId) { - return readTenantEntitlements(tenantId, false); + public RuntimeEntitlementsDto getTenantEntitlementsForRuntime(UUID tenantId, String requestId) { + return readTenantEntitlements(Objects.requireNonNull(tenantId, "tenantId")); } private BootstrapContext requireBootstrapContext(String bootstrapToken) { diff --git a/services/account-service/src/test/java/integration/net/firedevops/firemud/accountservice/AccountRuntimeEntitlementNoWriteIntegrationTest.java b/services/account-service/src/test/java/integration/net/firedevops/firemud/accountservice/AccountRuntimeEntitlementNoWriteIntegrationTest.java index f5d00ed59b..0db6da68b0 100644 --- a/services/account-service/src/test/java/integration/net/firedevops/firemud/accountservice/AccountRuntimeEntitlementNoWriteIntegrationTest.java +++ b/services/account-service/src/test/java/integration/net/firedevops/firemud/accountservice/AccountRuntimeEntitlementNoWriteIntegrationTest.java @@ -103,7 +103,7 @@ class AccountRuntimeEntitlementNoWriteIntegrationTest { "account_tenant_capacity_recovery_evidence"); private static final GetTenantEntitlementsForRuntimeRequest REQUEST = GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21") .setRequestId("default-runtime-entitlement-no-write") .build(); diff --git a/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountGrpcServiceTest.java b/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountGrpcServiceTest.java index 3aae3e801b..b16d289231 100644 --- a/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountGrpcServiceTest.java +++ b/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountGrpcServiceTest.java @@ -78,6 +78,9 @@ import org.springframework.transaction.CannotCreateTransactionException; class AccountGrpcServiceTest { + private static final java.util.UUID ENTITLEMENT_TENANT = + java.util.UUID.fromString("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21"); + @Test void canonicalGameplayEnvelopeNeverFallsBackToLegacyCredentialAuthentication() { var accounts = Mockito.mock(AccountService.class); @@ -2608,10 +2611,10 @@ void getRealmAccessGrantForRuntimeFailsUnavailableOnMismatchedAuthorityEvidence( void getTenantEntitlementsForRuntimeReturnsResponse() { PingService pingService = Mockito.mock(PingService.class); AccountService accountService = Mockito.mock(AccountService.class); - Mockito.when(accountService.getTenantEntitlementsForRuntime(1L, "req-2")) + Mockito.when(accountService.getTenantEntitlementsForRuntime(ENTITLEMENT_TENANT, "req-2")) .thenReturn( new net.firedevops.firemud.accountservice.dto.RuntimeEntitlementsDto( - 1L, true, true, 19L, 311L, "2026-03-30T00:00:00Z")); + ENTITLEMENT_TENANT, true, true, 19L, 311L, "2026-03-30T00:00:00Z")); AccountGrpcService service = new AccountGrpcService(pingService, accountService, null, WORKLOAD_NAMESPACE); @@ -2621,28 +2624,28 @@ void getTenantEntitlementsForRuntimeReturnsResponse() { () -> service.getTenantEntitlementsForRuntime( GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId(ENTITLEMENT_TENANT.toString()) .setRequestId("req-2") .build(), observer)); assertNotNull(observer.response()); - assertEquals("1", observer.response().getTenantId()); + assertEquals(ENTITLEMENT_TENANT.toString(), observer.response().getTenantId()); assertTrue(observer.response().getGameplayAvailable()); assertTrue(observer.response().getAllowPublicJoin()); assertEquals(19L, observer.response().getEntitlementVersion()); assertTrue(observer.completed()); - Mockito.verify(accountService).getTenantEntitlementsForRuntime(1L, "req-2"); + Mockito.verify(accountService).getTenantEntitlementsForRuntime(ENTITLEMENT_TENANT, "req-2"); } @Test void getTenantEntitlementsForRuntimeAllowsWorldManagementPeer() { PingService pingService = Mockito.mock(PingService.class); AccountService accountService = Mockito.mock(AccountService.class); - Mockito.when(accountService.getTenantEntitlementsForRuntime(1L, "req-world")) + Mockito.when(accountService.getTenantEntitlementsForRuntime(ENTITLEMENT_TENANT, "req-world")) .thenReturn( new net.firedevops.firemud.accountservice.dto.RuntimeEntitlementsDto( - 1L, true, true, 19L, 311L, "2026-03-30T00:00:00Z")); + ENTITLEMENT_TENANT, true, true, 19L, 311L, "2026-03-30T00:00:00Z")); AccountGrpcService service = new AccountGrpcService(pingService, accountService, null, WORKLOAD_NAMESPACE); RecordingObserver observer = new RecordingObserver<>(); @@ -2652,14 +2655,14 @@ void getTenantEntitlementsForRuntimeAllowsWorldManagementPeer() { () -> service.getTenantEntitlementsForRuntime( GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId(ENTITLEMENT_TENANT.toString()) .setRequestId("req-world") .build(), observer)); - assertEquals("1", observer.response().getTenantId()); + assertEquals(ENTITLEMENT_TENANT.toString(), observer.response().getTenantId()); assertTrue(observer.completed()); - Mockito.verify(accountService).getTenantEntitlementsForRuntime(1L, "req-world"); + Mockito.verify(accountService).getTenantEntitlementsForRuntime(ENTITLEMENT_TENANT, "req-world"); } @Test @@ -2709,11 +2712,11 @@ void getTenantEntitlementsForRuntimeRejectsMalformedTenantOrRequestBeforeLookup( .setRequestId("req-1") .build(), GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId(ENTITLEMENT_TENANT.toString()) .setRequestId(" ") .build(), GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId(ENTITLEMENT_TENANT.toString()) .setRequestId("x".repeat(129)) .build()); @@ -2729,7 +2732,7 @@ void getTenantEntitlementsForRuntimeRejectsMalformedTenantOrRequestBeforeLookup( private static GetTenantEntitlementsForRuntimeRequest validEntitlementRequest() { return GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId(ENTITLEMENT_TENANT.toString()) .setRequestId("req-2") .build(); } @@ -2738,7 +2741,8 @@ private static GetTenantEntitlementsForRuntimeRequest validEntitlementRequest() void getTenantEntitlementsForRuntimeReturnsUnavailableAuthorityError() { PingService pingService = Mockito.mock(PingService.class); AccountService accountService = Mockito.mock(AccountService.class); - Mockito.when(accountService.getTenantEntitlementsForRuntime(1L, "req-ambiguous")) + Mockito.when( + accountService.getTenantEntitlementsForRuntime(ENTITLEMENT_TENANT, "req-ambiguous")) .thenThrow( new AuthenticationException( "ENTITLEMENT_UNAVAILABLE", @@ -2752,7 +2756,7 @@ void getTenantEntitlementsForRuntimeReturnsUnavailableAuthorityError() { () -> service.getTenantEntitlementsForRuntime( GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("1") + .setTenantId(ENTITLEMENT_TENANT.toString()) .setRequestId("req-ambiguous") .build(), new StreamObserver() { @@ -2774,7 +2778,7 @@ public void onCompleted() {} } @Test - void getTenantEntitlementsForRuntimeRejectsZeroTenantIdBeforeLookup() { + void getTenantEntitlementsForRuntimeRejectsNonUuidTenantIdBeforeLookup() { PingService pingService = Mockito.mock(PingService.class); AccountService accountService = Mockito.mock(AccountService.class); AccountGrpcService service = @@ -2804,7 +2808,7 @@ public void onCompleted() {} assertNotNull(ref.get()); assertEquals("INVALID_ARGUMENT", ref.get().getError().getCode()); - assertEquals("tenantId must be positive", ref.get().getError().getMessage()); + Mockito.verifyNoInteractions(accountService); Mockito.verifyNoInteractions(accountService); } diff --git a/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountServiceImplTest.java b/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountServiceImplTest.java index ee0851233d..1f83e596ae 100644 --- a/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountServiceImplTest.java +++ b/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/AccountServiceImplTest.java @@ -3589,12 +3589,47 @@ void getTenantMembershipForRuntimeRejectsMissingAccount() { () -> service.getTenantMembershipForRuntime(11L, 7L, "req-1")); } + @Test + void runtimeEntitlementGrantsSourcelessSeededTenantOnlyUnderPreV1Waiver() { + var tenant = java.util.UUID.fromString("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21"); + var sources = + org.mockito.Mockito.mock( + net.firedevops.firemud.accountservice.repository.AccountTenantAuthorityEventRepository + .class); + var demos = + org.mockito.Mockito.mock( + net.firedevops.firemud.accountservice.repository.AccountDemoTenantEntitlementRepository + .class); + when(sources.hasCurrentSource(tenant)).thenReturn(false); + service.setRuntimeEntitlementSources( + sources, demos, net.firedevops.firemud.common.prev1.PreV1GateWaivers.enabledForTest()); + + var granted = service.getTenantEntitlementsForRuntime(tenant, "req-seeded"); + + assertEquals(tenant, granted.tenantId()); + assertTrue(granted.gameplayAvailable()); + verifyNoInteractions(demos); + + when(sources.readCurrentSourceSelection(tenant)) + .thenThrow(new IllegalStateException("Current tenant source is absent")); + service.setRuntimeEntitlementSources( + sources, demos, net.firedevops.firemud.common.prev1.PreV1GateWaivers.disabled()); + AuthenticationException denied = + assertThrows( + AuthenticationException.class, + () -> service.getTenantEntitlementsForRuntime(tenant, "req-unwaived")); + assertEquals("ENTITLEMENT_UNAVAILABLE", denied.getCode()); + } + @Test void getTenantEntitlementsForRuntimeFailsClosedBeforeReadingLegacyEvidence() { AuthenticationException exception = assertThrows( AuthenticationException.class, - () -> service.getTenantEntitlementsForRuntime(7L, "req-current-entitlement")); + () -> + service.getTenantEntitlementsForRuntime( + java.util.UUID.fromString("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21"), + "req-current-entitlement")); assertEquals("ENTITLEMENT_UNAVAILABLE", exception.getCode()); verifyNoInteractions(retainedSubscriptionEvidenceRepository); diff --git a/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/LegacySubscriptionContainmentTest.java b/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/LegacySubscriptionContainmentTest.java index 51af089c77..2fe8d19951 100644 --- a/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/LegacySubscriptionContainmentTest.java +++ b/services/account-service/src/test/java/unit/net/firedevops/firemud/accountservice/service/impl/LegacySubscriptionContainmentTest.java @@ -73,7 +73,10 @@ void retainedStatusAndCountersCannotProduceAPositiveServiceOrRuntimeRpc(String s AuthenticationException denied = assertThrows( AuthenticationException.class, - () -> service.getTenantEntitlementsForRuntime(7L, "retained-is-not-authority")); + () -> + service.getTenantEntitlementsForRuntime( + java.util.UUID.fromString("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21"), + "retained-is-not-authority")); assertThat(denied.getCode()).isEqualTo("ENTITLEMENT_UNAVAILABLE"); AccountGrpcService rpc = new AccountGrpcService(null, service, null, "test"); @@ -104,7 +107,7 @@ public void onCompleted() {} () -> rpc.getTenantEntitlementsForRuntime( GetTenantEntitlementsForRuntimeRequest.newBuilder() - .setTenantId("7") + .setTenantId("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21") .setRequestId("retained-is-not-authority") .build(), observer)); diff --git a/services/game-design-service/src/main/java/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcService.java b/services/game-design-service/src/main/java/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcService.java index 952e81d7de..f5b53374de 100644 --- a/services/game-design-service/src/main/java/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcService.java +++ b/services/game-design-service/src/main/java/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcService.java @@ -154,6 +154,14 @@ public class GameDesignGrpcService extends GameDesignServiceGrpc.GameDesignServi justification = "MeterRegistry is injected and not exposed") private final MeterRegistry meterRegistry; + private net.firedevops.firemud.gamedesign.repository.GameRepository gameRepository; + + @org.springframework.beans.factory.annotation.Autowired(required = false) + public void setGameRepository( + net.firedevops.firemud.gamedesign.repository.GameRepository repository) { + this.gameRepository = repository; + } + @Override @Timed(value = "gamedesignGrpc.ping") public void ping(PingRequest request, StreamObserver responseObserver) { @@ -829,6 +837,49 @@ public void getVersionState( responseObserver.onCompleted(); } + @Override + @Timed(value = "gamedesignGrpc.resolveCanonicalTenant") + public void resolveCanonicalTenant( + net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantRequest request, + StreamObserver + responseObserver) { + var builder = net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantResponse.newBuilder(); + try { + requireCanonicalTenantReadAccess(); + if (gameRepository == null) { + throw new IllegalStateException("Game Design tenant identity is unavailable"); + } + var identity = + gameRepository + .findRuntimeTenantIdentityByTenantKey(request.getTenantId()) + .orElseThrow(() -> new IllegalArgumentException("Unknown Game Design tenant")); + if (identity.canonicalTenantId() == null) { + throw new IllegalArgumentException("Game Design tenant has no canonical identity"); + } + builder.setCanonicalTenantId(identity.canonicalTenantId().toString()); + } catch (AdminAuthorizationException ex) { + builder.setError( + GrpcAppErrors.error( + meterRegistry, + logger, + "ResolveCanonicalTenant", + "PERMISSION_DENIED", + ex.getMessage())); + } catch (IllegalArgumentException ex) { + builder.setError( + GrpcAppErrors.error( + meterRegistry, + logger, + "ResolveCanonicalTenant", + "INVALID_ARGUMENT", + ex.getMessage())); + } catch (Exception ex) { + builder.setError(GrpcAppErrors.internal(meterRegistry, logger, "ResolveCanonicalTenant", ex)); + } + responseObserver.onNext(builder.build()); + responseObserver.onCompleted(); + } + @Override @Timed(value = "gamedesignGrpc.compareAndSetVersionState") public void compareAndSetVersionState( @@ -2328,6 +2379,18 @@ private void requirePublishedReleaseBundleReadAccess() { Set.of("game-session-service", "world-management-service", "automation-scripting-service")); } + /** Exact same-namespace Game Session workload; tenant identity grants no launch authority. */ + private void requireCanonicalTenantReadAccess() { + GrpcPeerIdentity peer = GrpcPeerIdentity.current(); + if (!GrpcPeerIdentity.isValidNamespace(workloadNamespace) + || peer == null + || !workloadNamespace.equals(peer.namespace()) + || !peer.isService("game-session-service")) { + throw new AdminAuthorizationException( + "Exact same-namespace Game Session workload identity is required"); + } + } + private void requireCandidatePeerThenDeny(Set candidateServices) { GrpcPeerIdentity peer = GrpcPeerIdentity.current(); if (!GrpcPeerIdentity.isValidNamespace(workloadNamespace) diff --git a/services/game-design-service/src/test/java/unit/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcServiceAuthTest.java b/services/game-design-service/src/test/java/unit/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcServiceAuthTest.java index 31a422d571..7be58a8223 100644 --- a/services/game-design-service/src/test/java/unit/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcServiceAuthTest.java +++ b/services/game-design-service/src/test/java/unit/net/firedevops/firemud/gamedesign/service/impl/GameDesignGrpcServiceAuthTest.java @@ -127,6 +127,53 @@ public void onCompleted() {} assertEquals("Admin role required", ref.get().getError().getMessage()); } + @Test + void canonicalTenantReadServesOnlySameNamespaceGameSession() { + var tenant = java.util.UUID.fromString("5b8d4c0e-3a1f-4f6e-9b2d-7c1e0a9f3d21"); + var games = Mockito.mock(net.firedevops.firemud.gamedesign.repository.GameRepository.class); + Mockito.when(games.findRuntimeTenantIdentityByTenantKey("1")) + .thenReturn( + Optional.of( + new net.firedevops.firemud.gamedesign.repository.GameTenantIdentity( + tenant, + net.firedevops.firemud.gamedesign.repository.GameTenantIdentity.ProvenanceKind + .NEW_GAME_ROW, + 1L, + null))); + GameDesignGrpcService service = + newService( + Mockito.mock(VersionService.class), Mockito.mock(VersionAssetArtifactService.class)); + ReflectionTestUtils.setField(service, "workloadNamespace", WORKLOAD_NAMESPACE); + service.setGameRepository(games); + var request = + net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantRequest.newBuilder() + .setTenantId("1") + .build(); + + AtomicReference served = + new AtomicReference<>(); + Context.current() + .withValue( + GrpcPeerIdentity.CONTEXT_KEY, + GrpcPeerIdentity.parseUri( + "spiffe://firemud/ns/" + WORKLOAD_NAMESPACE + "/sa/game-session-service") + .orElseThrow()) + .run(() -> service.resolveCanonicalTenant(request, responseObserver(served))); + assertEquals(tenant.toString(), served.get().getCanonicalTenantId()); + + this.assertDeniedMatrix( + observer -> service.resolveCanonicalTenant(request, observer), + response -> response.getError().getCode(), + "world-management-service", + "account-service"); + this.assertDenied( + observer -> service.resolveCanonicalTenant(request, observer), + response -> response.getError().getCode(), + "game-session-service", + "other-namespace", + Identity.PEER); + } + @Test void publishedReleaseBundleReadDeniesEveryIdentityBeforeOwnerServiceAccess() { VersionService versionService = Mockito.mock(VersionService.class); diff --git a/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/client/GameDesignClient.java b/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/client/GameDesignClient.java index b51ca577e4..cb9d7a6c31 100644 --- a/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/client/GameDesignClient.java +++ b/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/client/GameDesignClient.java @@ -154,6 +154,25 @@ public GetPublishedPluginVersionResponse getPublishedPluginVersion( } } + /** Canonical tenant UUID for a Game Design tenant key, or empty when Game Design has none. */ + public java.util.Optional resolveCanonicalTenantId(long tenantId) { + var response = + callStub() + .resolveCanonicalTenant( + net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantRequest.newBuilder() + .setTenantId(Long.toString(tenantId)) + .build()); + if (response.hasError() || response.getCanonicalTenantId().isEmpty()) { + return java.util.Optional.empty(); + } + var parsed = java.util.UUID.fromString(response.getCanonicalTenantId()); + if (!parsed.toString().equals(response.getCanonicalTenantId()) + || parsed.equals(new java.util.UUID(0L, 0L))) { + return java.util.Optional.empty(); + } + return java.util.Optional.of(parsed); + } + public GetVersionStateResponse getVersionState(long tenantId, long versionId) { return callStub() .getVersionState( diff --git a/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/command/text/PlayCommandHandler.java b/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/command/text/PlayCommandHandler.java index 9bc88481bc..f15b746802 100644 --- a/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/command/text/PlayCommandHandler.java +++ b/services/game-session-service/src/main/java/net/firedevops/firemud/gamesession/command/text/PlayCommandHandler.java @@ -76,6 +76,7 @@ public class PlayCommandHandler { private final MeterRegistry meterRegistry; private final Counter takeoverCounter; private final Counter resumeCounter; + private volatile net.firedevops.firemud.gamesession.client.GameDesignClient gameDesignClient; public PlayCommandHandler( SessionAuthenticationService sessionAuthenticationService, @@ -627,6 +628,25 @@ private static GameplayCommand scriptEventCommand(SessionContext context, TextCo null); } + /** Game Design owns tenant identity; PLAY reads Account entitlement by canonical tenant UUID. */ + @org.springframework.beans.factory.annotation.Autowired(required = false) + public void setGameDesignClient( + net.firedevops.firemud.gamesession.client.GameDesignClient gameDesignClient) { + this.gameDesignClient = gameDesignClient; + } + + private Optional resolveCanonicalTenantId(long tenantId) { + var client = gameDesignClient; + if (client == null) { + return Optional.empty(); + } + try { + return client.resolveCanonicalTenantId(tenantId); + } catch (RuntimeException unavailable) { + return Optional.empty(); + } + } + private Optional validateRuntimeAdmission( SessionContext context, GameplayWorldCatalog.WorldView selectedWorld, @@ -634,9 +654,15 @@ private Optional validateRuntimeAdmission( String tenantTag, long requestedCharacterId) { String requestId = context.sessionId() + ":" + UUID.randomUUID(); + Optional canonicalTenantId = resolveCanonicalTenantId(selectedRealm.tenantId()); + if (canonicalTenantId.isEmpty()) { + return Optional.of( + entitlementUnavailableFailure( + tenantTag, Long.toString(selectedRealm.gameInstanceId()), requestedCharacterId)); + } GetTenantEntitlementsForRuntimeResponse entitlementResponse = accountClient.getTenantEntitlementsForRuntime( - Long.toString(selectedRealm.tenantId()), requestId); + canonicalTenantId.orElseThrow().toString(), requestId); Optional entitlementFailure = validateEntitlementsResponse( entitlementResponse, @@ -644,6 +670,7 @@ private Optional validateRuntimeAdmission( tenantTag, selectedWorld, selectedRealm, + canonicalTenantId.orElseThrow(), requestedCharacterId); if (entitlementFailure.isPresent()) { return entitlementFailure; @@ -928,6 +955,7 @@ private Optional validateEntitlementsResponse( String tenantTag, GameplayWorldCatalog.WorldView selectedWorld, GameplayWorldCatalog.RealmView selectedRealm, + UUID canonicalTenantId, long requestedCharacterId) { if (response == null) { return Optional.of( @@ -947,7 +975,7 @@ private Optional validateEntitlementsResponse( context, tenantTag, selectedWorld, selectedRealm, requestedCharacterId)); } try { - if (!Long.toString(selectedRealm.tenantId()).equals(response.getTenantId()) + if (!canonicalTenantId.toString().equals(response.getTenantId()) || response.getEntitlementVersion() <= 0L || response.getTenantBillingSequence() <= 0L || !isWithinEntitlementReplyWindow( diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/PlayCommandHandlerTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/PlayCommandHandlerTest.java index f97868fd5b..db24931010 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/PlayCommandHandlerTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/PlayCommandHandlerTest.java @@ -105,6 +105,7 @@ void setUp() { gameplayPresenceLifecycleService, scriptEventPublisher, meterRegistry); + handler.setGameDesignClient(tenantIdentity()); when(moderationPolicyClient.evaluateGameplayAdmission(Mockito.anyLong(), Mockito.anyString())) .thenReturn( net.firedevops.firemud.loggingadmin.v1.EvaluateModerationPolicyResponse.newBuilder() @@ -127,7 +128,7 @@ void setUp() { .thenAnswer( invocation -> GetTenantEntitlementsForRuntimeResponse.newBuilder() - .setTenantId("22") + .setTenantId(canonicalTenantFor(22L).toString()) .setGameplayAvailable(true) .setAllowPublicJoin(true) .setEntitlementVersion(1L) @@ -437,6 +438,7 @@ void playComposesSelectionCardinalityAndSuccessFromOneActualPointerList() { gameplayPresenceLifecycleService, scriptEventPublisher, meterRegistry); + localHandler.setGameDesignClient(tenantIdentity()); SessionContext context = new SessionContext(1L, 22L, ACCOUNT_ID, "demo@example.com", 0L, null, 0L, "jwt-token"); when(sessionAuthenticationService.resolveSessionContext("1")).thenReturn(Optional.of(context)); @@ -544,7 +546,8 @@ void playPromotesSessionIntoGameplay() { var admissionOrder = Mockito.inOrder(accountClient, entityManagementClient); admissionOrder .verify(accountClient) - .getTenantEntitlementsForRuntime(Mockito.eq("22"), Mockito.anyString()); + .getTenantEntitlementsForRuntime( + Mockito.eq(canonicalTenantFor(22L).toString()), Mockito.anyString()); admissionOrder .verify(accountClient) .getTenantMembershipForRuntime( @@ -1281,6 +1284,7 @@ void playDoesNotAdmitV6QuarantinedPointerWithoutCatalogIdentity() { gameplayPresenceLifecycleService, scriptEventPublisher, meterRegistry); + authorityBackedHandler.setGameDesignClient(tenantIdentity()); SessionContext context = new SessionContext(1L, 22L, ACCOUNT_ID, 0L, 0L, "jwt-token"); when(sessionAuthenticationService.resolveSessionContext("1")).thenReturn(Optional.of(context)); @@ -1336,6 +1340,7 @@ void retainedPointerWithUnknownStateScopeCannotBindOrSpawn() { gameplayPresenceLifecycleService, scriptEventPublisher, meterRegistry); + pointerBackedHandler.setGameDesignClient(tenantIdentity()); SessionContext context = new SessionContext(1L, 22L, ACCOUNT_ID, "demo@example.com", 0L, null, 0L, "jwt-token"); when(sessionAuthenticationService.resolveSessionContext("1")).thenReturn(Optional.of(context)); @@ -1921,6 +1926,24 @@ void entitlementFreshnessExpiresAtConservativeDeadlineAndGuardsFutureSkew() { .isFalse(); } + @Test + void playFailsClosedWhenGameDesignHasNoCanonicalTenant() { + SessionContext context = + new SessionContext(1L, 22L, ACCOUNT_ID, "demo@example.com", 0L, null, 0L, "jwt-token"); + when(sessionAuthenticationService.resolveSessionContext("1")).thenReturn(Optional.of(context)); + var noIdentity = Mockito.mock(net.firedevops.firemud.gamesession.client.GameDesignClient.class); + when(noIdentity.resolveCanonicalTenantId(Mockito.anyLong())).thenReturn(Optional.empty()); + handler.setGameDesignClient(noIdentity); + + var result = handler.handle("1", new TextCommandParser().parse("PLAY demo")); + + assertThat(result.commandResult().accepted()).isFalse(); + assertThat(result.commandResult().errorCode()).isEqualTo("ENTITLEMENT_UNAVAILABLE"); + verify(accountClient, never()) + .getTenantEntitlementsForRuntime(Mockito.anyString(), Mockito.anyString()); + verifyNoGameplayBindingSideEffects(); + } + @ParameterizedTest @CsvSource({ "22,1,1,-5,true", "22,1,1,-11,false", "22,1,1,-299,false", @@ -1936,7 +1959,7 @@ void entitlementEvidenceHasItsOwnStrictFreshnessAndTenantVersionGuards( when(accountClient.getTenantEntitlementsForRuntime(Mockito.anyString(), Mockito.anyString())) .thenReturn( entitlementResponse(true).toBuilder() - .setTenantId(tenantId) + .setTenantId("22".equals(tenantId) ? canonicalTenantFor(22L).toString() : tenantId) .setEntitlementVersion(version) .setTenantBillingSequence(sequence) .setEvaluatedAt(Instant.now().plusSeconds(secondsFromNow).toString()) @@ -2205,7 +2228,8 @@ void privateGrantOutcomeNeverFallsBackToJoinOrInvokesLaterAdmission(String scena var order = Mockito.inOrder(accountClient); order .verify(accountClient) - .getTenantEntitlementsForRuntime(Mockito.eq("22"), Mockito.anyString()); + .getTenantEntitlementsForRuntime( + Mockito.eq(canonicalTenantFor(22L).toString()), Mockito.anyString()); order .verify(accountClient) .getTenantMembershipForRuntime( @@ -2242,7 +2266,7 @@ void deniedSelectedRealmDoesNotClearUnrelatedSameTenantGameplayBinding() { private static GetTenantEntitlementsForRuntimeResponse entitlementResponse( boolean allowPublicJoin) { return GetTenantEntitlementsForRuntimeResponse.newBuilder() - .setTenantId("22") + .setTenantId(canonicalTenantFor(22L).toString()) .setGameplayAvailable(true) .setAllowPublicJoin(allowPublicJoin) .setEntitlementVersion(12L) @@ -2378,7 +2402,7 @@ void playBlockedByEntitlementsReturnsBillingBlocked() { when(accountClient.getTenantEntitlementsForRuntime(Mockito.anyString(), Mockito.anyString())) .thenReturn( GetTenantEntitlementsForRuntimeResponse.newBuilder() - .setTenantId("22") + .setTenantId(canonicalTenantFor(22L).toString()) .setGameplayAvailable(false) .setEntitlementVersion(5L) .setTenantBillingSequence(5L) @@ -2793,4 +2817,20 @@ void changedFirstPartyOwnerDeniesPlayBeforeLegacyAdmissionEffects() { scriptEventPublisher); Mockito.verify(sessionContextService, never()).save(Mockito.any()); } + + private static java.util.UUID canonicalTenantFor(long tenantId) { + return java.util.UUID.nameUUIDFromBytes( + ("tenant-" + tenantId).getBytes(java.nio.charset.StandardCharsets.UTF_8)); + } + + private static net.firedevops.firemud.gamesession.client.GameDesignClient tenantIdentity() { + var client = + org.mockito.Mockito.mock(net.firedevops.firemud.gamesession.client.GameDesignClient.class); + org.mockito.Mockito.when( + client.resolveCanonicalTenantId(org.mockito.ArgumentMatchers.anyLong())) + .thenAnswer( + invocation -> + java.util.Optional.of(canonicalTenantFor(invocation.getArgument(0, Long.class)))); + return client; + } } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/SessionResumptionFlowTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/SessionResumptionFlowTest.java index 9b04f0e80c..7020850209 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/SessionResumptionFlowTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/SessionResumptionFlowTest.java @@ -194,7 +194,7 @@ void setUp() { .thenAnswer( invocation -> GetTenantEntitlementsForRuntimeResponse.newBuilder() - .setTenantId("22") + .setTenantId(canonicalTenantFor(22L).toString()) .setGameplayAvailable(true) .setAllowPublicJoin(true) .setEntitlementVersion(1L) @@ -290,6 +290,7 @@ void setUp() { gameplayPresenceLifecycleService, scriptEventPublisher, meterRegistry); + playHandler.setGameDesignClient(tenantIdentity()); worldsHandler = new WorldsCommandHandler(worldCatalog); AfkCommandHandler afkHandler = new AfkCommandHandler(sessionAuthenticationService, gameplayPresenceService); @@ -745,4 +746,20 @@ private boolean hasGameplayIdentity(SessionContext context) { return context.gameInstanceId() > 0 && context.characterId() > 0; } } + + private static java.util.UUID canonicalTenantFor(long tenantId) { + return java.util.UUID.nameUUIDFromBytes( + ("tenant-" + tenantId).getBytes(java.nio.charset.StandardCharsets.UTF_8)); + } + + private static net.firedevops.firemud.gamesession.client.GameDesignClient tenantIdentity() { + var client = + org.mockito.Mockito.mock(net.firedevops.firemud.gamesession.client.GameDesignClient.class); + org.mockito.Mockito.when( + client.resolveCanonicalTenantId(org.mockito.ArgumentMatchers.anyLong())) + .thenAnswer( + invocation -> + java.util.Optional.of(canonicalTenantFor(invocation.getArgument(0, Long.class)))); + return client; + } } diff --git a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterTest.java b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterTest.java index 4d10a006c7..1ac2c5bb05 100644 --- a/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterTest.java +++ b/services/game-session-service/src/test/java/unit/net/firedevops/firemud/gamesession/command/text/TextCommandInterpreterTest.java @@ -195,7 +195,7 @@ void setUp() { .thenAnswer( invocation -> GetTenantEntitlementsForRuntimeResponse.newBuilder() - .setTenantId("22") + .setTenantId(canonicalTenantFor(22L).toString()) .setGameplayAvailable(true) .setAllowPublicJoin(true) .setEntitlementVersion(1L) @@ -385,6 +385,7 @@ void setUp() { gameplayPresenceLifecycleService, scriptEventPublisher, meterRegistry); + playHandler.setGameDesignClient(tenantIdentity()); AfkCommandHandler afkHandler = new AfkCommandHandler(sessionAuthenticationService, gameplayPresenceService); WhoCommandHandler whoHandler = @@ -1208,4 +1209,20 @@ private boolean hasGameplayIdentity(SessionContext context) { return context.gameInstanceId() > 0 && context.characterId() > 0; } } + + private static java.util.UUID canonicalTenantFor(long tenantId) { + return java.util.UUID.nameUUIDFromBytes( + ("tenant-" + tenantId).getBytes(java.nio.charset.StandardCharsets.UTF_8)); + } + + private static net.firedevops.firemud.gamesession.client.GameDesignClient tenantIdentity() { + var client = + org.mockito.Mockito.mock(net.firedevops.firemud.gamesession.client.GameDesignClient.class); + org.mockito.Mockito.when( + client.resolveCanonicalTenantId(org.mockito.ArgumentMatchers.anyLong())) + .thenAnswer( + invocation -> + java.util.Optional.of(canonicalTenantFor(invocation.getArgument(0, Long.class)))); + return client; + } } From 6e377b1f301589af80f4dd5e035067b57b50985c Mon Sep 17 00:00:00 2001 From: Ben Hook <5009589+benhook1013@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:28:31 +1300 Subject: [PATCH 2/2] Resolve canonical tenants in the Game Design cross-service stub Co-Authored-By: Claude Opus 5.5 --- .../test/stubs/GameDesignStubServer.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/stubs/GameDesignStubServer.java b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/stubs/GameDesignStubServer.java index 7f3b60c570..7ba89eeb68 100644 --- a/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/stubs/GameDesignStubServer.java +++ b/services/game-session-service/src/testFixtures/java/net/firedevops/firemud/gamesession/test/stubs/GameDesignStubServer.java @@ -36,11 +36,32 @@ public void getPublishedReleaseBundle( .build()); responseObserver.onCompleted(); } + + @Override + public void resolveCanonicalTenant( + net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantRequest request, + StreamObserver< + net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantResponse> + responseObserver) { + responseObserver.onNext( + net.firedevops.firemud.gamedesign.v1.ResolveCanonicalTenantResponse + .newBuilder() + .setCanonicalTenantId( + canonicalTenantFor(request.getTenantId()).toString()) + .build()); + responseObserver.onCompleted(); + } }) .build() .start(); } + /** Deterministic canonical tenant UUID for a stub Game Design tenant key. */ + public static java.util.UUID canonicalTenantFor(String tenantKey) { + return java.util.UUID.nameUUIDFromBytes( + ("tenant-" + tenantKey).getBytes(java.nio.charset.StandardCharsets.UTF_8)); + } + public String endpoint() { return "localhost:" + server.getPort(); }