Skip to content

Commit e217a7d

Browse files
committed
fix(Http4s700): bridge must not re-serve disabled v7 endpoints via v6
When api_disabled_endpoints or api_disabled_versions gates a v7 path, ResourceDocMiddleware returns OptionT.none. The v700→v600 bridge was picking that up and forwarding to Http4s600, which served a 200. Fix: build a lazy ResourceDocIndex from v7's own resourceDocs and guard the bridge — only bridge paths whose URL+method matches no v7 ResourceDoc. Paths that have a v7 doc but returned OptionT.none (disabled) stay none. Fixes ResourceDocMiddlewareEnableDisablePropsTest scenarios: - api_disabled_endpoints contains the operationId → 404 - api_disabled_versions disables every endpoint of that version
1 parent 17faa09 commit e217a7d

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

obp-api/src/main/scala/code/api/v7_0_0/Http4s700.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import code.api.util.{APIUtil, ApiRole, ApiVersionUtils, CallContext, CustomJson
1111
import code.api.util.ApiRole.{canCreateEntitlementAtAnyBank, canCreateEntitlementAtOneBank, canCreateOrganisation, canCreateRoutingScheme, canDeleteEntitlementAtAnyBank, canDeleteOrganisation, canDeleteRoutingScheme, canGetAccountAccessTrace, canGetAnyOrganisation, canGetAnyUser, canGetCacheConfig, canGetCacheInfo, canGetCacheNamespaces, canGetConnectorHealth, canGetCustomersAtOneBank, canGetDatabasePoolInfo, canGetMigrations, canUpdateBankSupportedRoutingScheme, canUpdateOrganisation, canUpdateRoutingScheme, canUpdateSystemView}
1212
import code.api.util.ApiTag._
1313
import code.api.util.ErrorMessages._
14-
import code.api.util.http4s.{ErrorResponseConverter, Http4sRequestAttributes, IdempotencyMiddleware, RequestScopeConnection, ResourceDocMiddleware}
14+
import code.api.util.http4s.{ErrorResponseConverter, Http4sRequestAttributes, IdempotencyMiddleware, RequestScopeConnection, ResourceDocMiddleware, ResourceDocMatcher}
1515
import code.api.util.http4s.Http4sRequestAttributes.{EndpointHelpers, RequestOps}
1616
import code.api.util.newstyle.ViewNewStyle
1717
import code.api.v1_4_0.JSONFactory1_4_0
@@ -3585,12 +3585,19 @@ object Http4s700 {
35853585
}
35863586

35873587
// ─── path-rewriting bridge: /obp/v7.0.0/… → /obp/v6.0.0/… ─────────────
3588-
// Catches v7.0.0 paths not handled by Http4s700's own endpoints and forwards
3589-
// them to Http4s600 (which has all 243 v6.0.0 endpoints). This replaces the
3590-
// old Lift-bridge rewrite, which failed because OBPAPI6_0_0.routes = Nil.
3588+
// Catches v7.0.0 paths with NO matching v7 ResourceDoc and forwards them to
3589+
// Http4s600 (which has all 243 v6.0.0 endpoints). Paths that DO have a v7
3590+
// ResourceDoc are intentionally excluded: if the middleware returned
3591+
// OptionT.none for such a path (e.g. api_disabled_endpoints), the bridge must
3592+
// not silently re-serve them from v6. The index is built lazily from the same
3593+
// resourceDocs buffer that the middleware uses, so it stays in sync.
3594+
private lazy val v7ResourceDocIndex: ResourceDocMatcher.ResourceDocIndex =
3595+
ResourceDocMatcher.buildIndex(resourceDocs)
3596+
35913597
private val v700ToV600Bridge: HttpRoutes[IO] = Kleisli[HttpF, Request[IO], Response[IO]] { req =>
35923598
val rawPath = req.uri.path.renderString
3593-
if (rawPath.startsWith("/obp/v7.0.0/")) {
3599+
if (rawPath.startsWith("/obp/v7.0.0/") &&
3600+
ResourceDocMatcher.findResourceDoc(req.method.name, req.uri.path, v7ResourceDocIndex).isEmpty) {
35943601
val rewritten = rawPath.replaceFirst("/obp/v7\\.0\\.0/", "/obp/v6.0.0/")
35953602
val newUri = req.uri.withPath(Uri.Path.unsafeFromString(rewritten))
35963603
code.api.v6_0_0.Http4s600.wrappedRoutesV600Services.run(req.withUri(newUri))

0 commit comments

Comments
 (0)