Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

test(cypress): add OMP cross-merchant/cross-profile isolation test suite (#15137)

Gnanasundari24801d681fd961
diff --git a/cypress-tests/cypress/e2e/configs/Security/Commons.js b/cypress-tests/cypress/e2e/configs/Security/Commons.js
new file mode 100644
index 0000000000..7f4dda42db
--- /dev/null
+++ b/cypress-tests/cypress/e2e/configs/Security/Commons.js
@@ -0,0 +1,103 @@
+// Shared test data for cypress/e2e/spec/Security/OMPScoping/, following the
+// same getCustomExchange(Request/Response) convention as
+// configs/Payment/Commons.js and configs/Payout/Commons.js - each uses its
+// own domain's getCustomExchange (Payment vs Payout) since each merges
+// overrides onto that domain's own default exchange (e.g. Payment's
+// defaults to a 501 not-implemented Response; see Modifiers.js in each
+// folder), not a generic shared one.
+import { getCustomExchange as getPaymentCustomExchange } from "../Payment/Modifiers";
+import { getCustomExchange as getPayoutCustomExchange } from "../Payout/Modifiers";
+
+// PI_PA / PI_PB creation in 00-Setup.cy.js. Matches the shape
+// configs/Payment/Commons.js's own PaymentIntent getter uses.
+export const PaymentIntent = () =>
+ getPaymentCustomExchange({
+ Request: { currency: "USD" },
+ Response: {
+ status: 200,
+ body: { status: "requires_payment_method" },
+ },
+ });
+
+// PO_PA / PO_PB creation in 00-Setup.cy.js. Matches Adyenplatform's card_pm
+// "Confirm" fixture shape (configs/Payout/AdyenPlatform.js) - with
+// confirm=true, auto_fulfill=false, Adyenplatform returns
+// "requires_fulfillment" rather than failing outright. Adyenplatform is
+// hardcoded as the payout connector in 00-Setup.cy.js regardless of
+// CYPRESS_CONNECTOR, since it's the only connector in this repo's creds
+// file with a payout-capable ("_payout") credentials entry but no plain
+// payment one - so this Request intentionally doesn't vary by connector.
+export const CardPayout = () =>
+ getPayoutCustomExchange({
+ Request: {
+ payout_method_data: {
+ card: {
+ card_number: "4111111111111111",
+ expiry_month: "03",
+ expiry_year: "2030",
+ card_holder_name: "John Smith",
+ },
+ },
+ currency: "EUR",
+ payout_type: "card",
+ },
+ Response: { status: 200, body: {} },
+ });
+
+// Profile acquirer create/update bodies, used in 03-ProfileAcquirer.cy.js -
+// a plain object (not getCustomExchange-wrapped) since profile_acquirer has
+// no connector-specific default exchange of its own to merge onto.
+export function acquirerBody(profileId, overrides = {}) {
+ return {
+ acquirer_assigned_merchant_id: "omp_test_merchant_id",
+ merchant_name: "OMP Scoping Test Merchant",
+ network: "Visa",
+ acquirer_bin: "123456",
+ profile_id: profileId,
+ ...overrides,
+ };
+}
+
+// Known, live-confirmed exact error responses shared across multiple specs
+// in this folder, for use as `expectedError` on cy.ompAssertDeniedAndUnchanged
+// (see cypress/support/security-commands.js). Defined once here rather than
+// inlined per test so the same confirmed value isn't duplicated/drifted
+// across files - add an entry only once its exact status/code/message has
+// actually been observed on a live run, never guessed.
+//
+// IMPORTANT: these are NOT one universal "JWT profile mismatch" error - the
+// exact response depends on which core module's check actually runs, and
+// that has been seen to change with the router version. Payments'
+// cross-profile retrieve used to go through the generic auth-layer
+// comparison (validate_payment_profile / validate_profile_id_from_auth_layer,
+// IR_16) but PR #15080 ("fix(payments): enforce authenticated payment
+// scope", commit d07de03379) moved it to a profile-scoped SQL query that
+// returns a plain not-found (HE_02) instead - confirmed by seeing BOTH
+// responses live for the identical test, traced to version skew between
+// router pods during a rolling deploy, not request-level non-determinism.
+// Keep each resource's entry separate; don't assume one endpoint's exact
+// error still applies to another after a fix like this lands.
+export const OMP_ERRORS = {
+ // Business Profile's cross-profile update check (JWTAuthMerchantAndProfileFromRoute
+ // comparing the JWT's own profile against the path profile_id) - this
+ // core module wasn't touched by PR #15080, so IR_16 is still expected
+ // here. Confirmed live.
+ JWT_PROFILE_MISMATCH: {
+ status: 400,
+ code: "IR_16",
+ message:
+ "Profile id authentication failed. Please use the correct JWT token",
+ },
+ // Payments' cross-profile retrieve (GET /payments/{id}?force_sync=true
+ // with a JWT): post-#15080, the profile-scoped DB query simply doesn't
+ // match the row, so this is PaymentNotFound, not an auth-layer mismatch.
+ // Confirmed live on current main. If this starts failing again with
+ // IR_16 400 instead, that's the test environment serving a stale,
+ // pre-#15080 router build on some pods, not a test or server-logic bug -
+ // check for a rolling-deploy/version-skew issue before changing this back.
+ PAYMENT_PROFILE_SCOPED_NOT_FOUND: {
+ status: 404,
+ code: "HE_02",
+ message: "Payment does not exist in our records",
+ },
+};
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/00-Setup.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/00-Setup.cy.js
new file mode 100644
index 0000000000..ce1ad91533
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/00-Setup.cy.js
@@ -0,0 +1,522 @@
+import * as fixtures from "../../../../fixtures/imports";
+import State from "../../../../utils/State";
+import { payment_methods_enabled } from "../../../configs/Payment/Commons";
+import getConnectorDetails from "../../../configs/Payment/Utils";
+import { PaymentIntent, CardPayout } from "../../../configs/Security/Commons";
+
+// Shared fixtures for the OMP (merchant/profile) scoping test matrix.
+// Downstream specs in this folder read everything this file stores in
+// globalState; none of them re-create these resources.
+//
+// Naming follows the test sheet convention:
+// M1 / M2 merchants
+// PA / PB business profiles, both under M1
+// KEY_M1 merchant API key for M1 -> globalState "apiKeyM1"
+// JWT_PA dashboard-user session scoped to M1/PA -> "userInfoTokenPA"
+// MCA_PA / MCA_PB, PI_PA / PI_PB, PO_PA / PO_PB paired resources per profile
+//
+// ASSUMPTION (unverified against a running server): the dashboard signup
+// flow (signupUserWithMerchant) provisions its own fresh merchant for the
+// new user rather than attaching to a merchant created via the admin API.
+// To avoid fighting that, M1 itself IS the merchant the signup flow
+// creates, and its default business profile becomes PA. PB is a second
+// profile created afterward under the same M1 using the admin API key.
+// If signupUserWithMerchant turns out to support joining an existing
+// merchant, this can be simplified to create M1 up front instead.
+let globalState;
+
+describe("OMP Scoping - shared fixtures", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("M1 / PA via dashboard signup", () => {
+ it("signs up a dashboard user, creating M1 with default profile PA", () => {
+ cy.signupUserWithMerchant("OmpScopingM1", globalState);
+ cy.userLogin(globalState);
+ cy.terminate2Fa(globalState);
+ cy.userInfo(globalState);
+
+ cy.then(() => {
+ globalState.set("merchantIdM1", globalState.get("merchantId"));
+ globalState.set("profileIdPA", globalState.get("profileId"));
+ globalState.set("userInfoTokenPA", globalState.get("userInfoToken"));
+ });
+ });
+
+ it("creates KEY_M1 (merchant API key for M1)", () => {
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ });
+
+ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);
+
+ cy.then(() => {
+ globalState.set("apiKeyM1", globalState.get("apiKey"));
+ });
+ });
+
+ it("creates business profile PB under M1", () => {
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ });
+
+ cy.createBusinessProfileTest(
+ fixtures.businessProfile.bpCreate,
+ globalState,
+ "pb"
+ );
+
+ cy.then(() => {
+ globalState.set("profileIdPB", globalState.get("pbId"));
+ });
+ });
+ });
+
+ context("M2 - a wholly separate merchant", () => {
+ it("creates M2 with its own default profile", () => {
+ cy.merchantCreateCallTest(fixtures.merchantCreateBody, globalState, {
+ merchantIdStateKey: "merchantIdM2",
+ profileIdStateKey: "profileIdM2Default",
+ publishableKeyStateKey: "publishableKeyM2",
+ });
+ });
+
+ it("creates KEY_M2 (merchant API key for M2)", () => {
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM2"));
+ });
+
+ cy.apiKeyCreateTest(fixtures.apiKeyCreateBody, globalState);
+
+ cy.then(() => {
+ globalState.set("apiKeyM2", globalState.get("apiKey"));
+ });
+ });
+ });
+
+ context("Paired resources under M1 - one per profile (PA, PB)", () => {
+ // MCA_PA and MCA_PB are intentionally created with the SAME connector,
+ // hardcoded to "stripe" rather than whatever CYPRESS_CONNECTOR happens
+ // to be set to - stripe is the most reliably stable connector in this
+ // repo's creds file, and OMP scoping is about merchant/profile
+ // ownership, not connector behavior, so there's no reason to let an
+ // unrelated env var make this suite flaky. Restored to the original
+ // CYPRESS_CONNECTOR afterward in case any later step in this file
+ // depends on it. Payouts use "adyenplatform" and Connector Onboarding
+ // uses "paypal" for the same reliability reason, each is its own
+ // dedicated MCA, not a change to this one.
+ it("creates MCA_PA and MCA_PB", () => {
+ const originalConnectorId = globalState.get("connectorId");
+
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ globalState.set("connectorId", "stripe");
+ // createConnectorCallTest resolves the profile via
+ // globalState.get(`${profilePrefix}Id`) - "pa"/"pb" prefixes read
+ // "paId"/"pbId", which only PB's creation (via
+ // createBusinessProfileTest) populated. PA's profile id lives under
+ // "profileIdPA" (set by the signup flow), so mirror it into "paId".
+ globalState.set("paId", globalState.get("profileIdPA"));
+ });
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ fixtures.createConnectorBody,
+ payment_methods_enabled,
+ globalState,
+ "pa",
+ "mcaPa"
+ );
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ fixtures.createConnectorBody,
+ payment_methods_enabled,
+ globalState,
+ "pb",
+ "mcaPb"
+ );
+
+ cy.then(() => {
+ globalState.set("connectorId", originalConnectorId);
+ });
+ });
+
+ it("creates MCA_PAYPAL_PA and MCA_PAYPAL_PB, so connector onboarding sync has real PayPal MCAs to test against", () => {
+ // POST /connector_onboarding/sync returns 400 IR_20 "Connector
+ // onboarding flow not supported" for any non-PayPal connector,
+ // confirmed live - the feature is PayPal-only. MCA_PA (whatever
+ // CYPRESS_CONNECTOR is) can't be used for 06-ConnectorOnboarding.cy.js's
+ // checks, so this creates PayPal-specific MCAs under BOTH profiles -
+ // same connectorId-override pattern as the Adyenplatform payout
+ // connector step above.
+ //
+ // Both profiles, not just PA: the actual ownership check compares
+ // the target MCA's real profile against the authenticated profile,
+ // not an arbitrary profile_id field in the request body - confirmed
+ // live when a single PA-owned MCA plus a spoofed body.profile_id
+ // returned 200 instead of denial (PA's own MCA + PA's own auth is
+ // never a real mismatch, no matter what the body claims). A genuine
+ // cross-profile test needs an MCA that actually belongs to PB.
+ const paymentsConnectorId = globalState.get("connectorId");
+
+ cy.then(() => {
+ globalState.set("connectorId", "paypal");
+ });
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ structuredClone(fixtures.createConnectorBody),
+ payment_methods_enabled,
+ globalState,
+ "pa",
+ "mcaPaypalPa"
+ );
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ structuredClone(fixtures.createConnectorBody),
+ payment_methods_enabled,
+ globalState,
+ "pb",
+ "mcaPaypalPb"
+ );
+
+ cy.then(() => {
+ globalState.set("connectorId", paymentsConnectorId);
+ });
+ });
+
+ it("creates a netcetera authentication_processor connector for PA and configures it on PA's business profile", () => {
+ // Standalone /authentication eligibility and /authentication/sync
+ // (04-Authentication.cy.js) need PA's business profile to actually
+ // have authentication_connector_details set
+ // (crates/router/src/core/authentication/utils.rs:603-610) - without
+ // it, eligibility can't proceed past the profile check into real
+ // 3DS processing. Same setup 47-StepUpAuth.cy.js already does for its
+ // own profile: create a netcetera MCA with connector_type
+ // "authentication_processor" under PA, then update PA's business
+ // profile with authentication_connector_details pointing at it.
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ });
+
+ const createConnectorBody = {
+ ...structuredClone(fixtures.createConnectorBody),
+ connector_name: "netcetera",
+ };
+
+ cy.createAuthenticationProcessorConnectorTest(
+ createConnectorBody,
+ globalState,
+ "pa",
+ "authProcessorConnectorPa"
+ );
+
+ cy.then(() => {
+ if (!globalState.get("authProcessorConnectorPaId")) {
+ cy.task(
+ "cli_log",
+ "Skipping: netcetera authentication_processor connector creation did not succeed."
+ );
+ return;
+ }
+
+ cy.UpdateBusinessProfileTest(
+ {
+ authentication_connector_details: {
+ authentication_connectors: ["netcetera"],
+ three_ds_requestor_url: "https://example.com",
+ },
+ },
+ false,
+ false,
+ false,
+ false,
+ false,
+ globalState,
+ "pa"
+ );
+ });
+ });
+
+ it("creates PI_PA and PI_PB (payment intents)", () => {
+ // Request/Response come from configs/Security/Commons.js, the same
+ // bundling convention configs/Payment/Commons.js uses for its own
+ // PaymentIntent getter.
+ //
+ // These intents run against whichever single connector
+ // CYPRESS_CONNECTOR is set to for this run - the suite doesn't loop
+ // over multiple connectors, because OMP (profile/merchant) scoping is
+ // enforced in the router layer before any connector is ever reached,
+ // so the connector choice is orthogonal to what this suite verifies.
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ globalState.set("profileId", globalState.get("profileIdPA"));
+ });
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ { Configs: {}, ...PaymentIntent() },
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("paymentIdPA", globalState.get("paymentID"));
+ globalState.set("profileId", globalState.get("profileIdPB"));
+ });
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ { Configs: {}, ...PaymentIntent() },
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("paymentIdPB", globalState.get("paymentID"));
+ });
+ });
+
+ it("creates a payout_processor connector for PA and PB", () => {
+ // createConfirmPayoutTest's generic payment_processor MCA can't route
+ // payouts - payouts specifically need a "payout_processor" MCA, whose
+ // credentials come from the `${connectorId}_payout` entry in the
+ // connector creds file (see createPayoutConnectorCallTest). Adyenplatform
+ // has no plain (non-payout) creds entry in this repo's creds.json, so
+ // it can only ever be a payout connector, not a payment one - hence
+ // the connectorId is temporarily overridden to "adyenplatform" for
+ // just this step and restored afterward, independent of whatever
+ // connector the rest of the suite runs payments against.
+ const paymentsConnectorId = globalState.get("connectorId");
+
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ globalState.set("profileId", globalState.get("profileIdPA"));
+ globalState.set("connectorId", "adyenplatform");
+ });
+
+ cy.createPayoutConnectorCallTest(
+ "payout_processor",
+ structuredClone(fixtures.createConnectorBody),
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("profileId", globalState.get("profileIdPB"));
+ });
+
+ cy.createPayoutConnectorCallTest(
+ "payout_processor",
+ structuredClone(fixtures.createConnectorBody),
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("connectorId", paymentsConnectorId);
+ });
+ });
+
+ it("creates PO_PA and PO_PB (payouts), if the connector supports payouts", () => {
+ if (!globalState.get("payoutsExecution")) {
+ cy.task(
+ "cli_log",
+ "Skipping PO_PA/PO_PB: configured connector has no payout " +
+ "credentials in the creds file. 02-Payouts.cy.js must gate on " +
+ "the same payoutsExecution flag."
+ );
+ return;
+ }
+
+ // createConfirmPayoutTest reads customer_id from
+ // globalState.get("customerId") - must exist before a payout can be
+ // created, and payouts need a customer regardless of profile.
+ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
+
+ cy.createConfirmPayoutTest(
+ structuredClone(fixtures.createPayoutBody),
+ {
+ ...CardPayout(),
+ Request: {
+ ...CardPayout().Request,
+ profile_id: globalState.get("profileIdPA"),
+ },
+ },
+ true,
+ false,
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("payoutIdPA", globalState.get("payoutID"));
+ });
+
+ cy.createConfirmPayoutTest(
+ structuredClone(fixtures.createPayoutBody),
+ {
+ ...CardPayout(),
+ Request: {
+ ...CardPayout().Request,
+ profile_id: globalState.get("profileIdPB"),
+ },
+ },
+ true,
+ false,
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("payoutIdPB", globalState.get("payoutID"));
+ });
+ });
+
+ // GAP (see feasibility check): this suite has no command that fabricates
+ // a dispute. The existing 47-DisputeTests.cy.js only reads whatever
+ // disputes already exist for the merchant/connector and skips its own
+ // assertions when none are found. D_PA / D_PB can only be populated by
+ // listing real disputes against a connector sandbox that actually has
+ // dispute data - there is nothing to create here. Downstream specs
+ // (05-Disputes.cy.js) must follow the same "skip if none found" gate
+ // this repo already uses rather than assume D_PA/D_PB exist.
+ it("looks up any pre-existing disputes for D_PA / D_PB (best effort)", () => {
+ cy.task(
+ "cli_log",
+ "No dispute-fabrication command exists in this suite; 05-Disputes.cy.js " +
+ "will list disputes per profile at runtime and skip cases if none exist."
+ );
+ });
+ });
+
+ context("PC - dedicated profile for incremental/extend authorization", () => {
+ // incremental_authorization and extend_authorization both gate on
+ // payment status (requires_capture, plus incremental_authorization_allowed
+ // for the former) in their own get_trackers, BEFORE the generic
+ // cross-profile check ever runs - a payment stuck in
+ // requires_payment_method (like PI_PA/PI_PB, never confirmed) can't
+ // reach that check at all, confirmed live (01-Payments.cy.js's two
+ // tests on PI_PB returned 400/412 from the status gate itself, not a
+ // real profile-mismatch denial). Reaching the real check needs a
+ // payment genuinely confirmed into requires_capture with incremental
+ // auth enabled, which in this repo's test matrix is cybersource-only
+ // (see 29-IncrementalAuth.cy.js). A dedicated profile with ONLY
+ // cybersource enabled avoids routing ambiguity with PA/PB's existing
+ // stripe/paypal connectors.
+ it("creates profile PC and a dedicated cybersource MCA", () => {
+ const originalConnectorId = globalState.get("connectorId");
+
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ });
+
+ cy.createBusinessProfileTest(
+ fixtures.businessProfile.bpCreate,
+ globalState,
+ "pc"
+ );
+
+ cy.then(() => {
+ globalState.set("profileIdPC", globalState.get("pcId"));
+ globalState.set("connectorId", "cybersource");
+ globalState.set("profileId", globalState.get("profileIdPC"));
+ });
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ structuredClone(fixtures.createConnectorBody),
+ payment_methods_enabled,
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("connectorId", originalConnectorId);
+ });
+ });
+
+ it("creates PI_INCREMENTAL_PC - a cybersource payment confirmed into requires_capture with incremental auth enabled", () => {
+ cy.then(() => {
+ return cy.ompGetMerchantAccount(
+ globalState.get("merchantIdM1"),
+ globalState
+ );
+ }).then((res) => {
+ globalState.set("publishableKeyM1", res.body?.publishable_key);
+ });
+
+ cy.then(() => {
+ globalState.set("profileId", globalState.get("profileIdPC"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ globalState.set("publishableKey", globalState.get("publishableKeyM1"));
+ });
+
+ const cybersourceCardPm = getConnectorDetails("cybersource")["card_pm"];
+
+ const intentData = {
+ ...cybersourceCardPm["PaymentIntentOffSession"],
+ Request: {
+ ...cybersourceCardPm["PaymentIntentOffSession"].Request,
+ request_incremental_authorization: true,
+ },
+ };
+
+ cy.createPaymentIntentTest(
+ fixtures.createPaymentBody,
+ intentData,
+ "no_three_ds",
+ "manual",
+ globalState
+ );
+
+ cy.confirmCallTest(
+ fixtures.confirmBody,
+ cybersourceCardPm["SaveCardUseNo3DSManualCaptureOffSession"],
+ true,
+ globalState
+ );
+
+ // Not cy.incrementalAuth: that command strictly asserts the
+ // connector-side amount increase actually lands (amount_capturable
+ // equals the requested bump) - cybersource's sandbox accepted this
+ // call (200) but didn't apply the increase, confirmed live. That's a
+ // connector-sandbox quirk unrelated to what this fixture needs: only
+ // incremental_authorization_allowed=true and status=requires_capture
+ // matter for the OMP cross-profile tests that consume this payment,
+ // not whether the increment itself numerically succeeded.
+ cy.then(() => {
+ const paymentId = globalState.get("paymentID");
+ return cy.ompIncrementalAuthorization(
+ paymentId,
+ { type: "apiKey", apiKey: globalState.get("apiKeyM1") },
+ { amount: 8000 },
+ globalState
+ );
+ }).then((res) => {
+ expect(res.status, "incremental_authorization call").to.eq(200);
+ expect(
+ res.body?.incremental_authorization_allowed,
+ "incremental_authorization_allowed"
+ ).to.eq(true);
+ expect(res.body?.status, "status").to.eq("requires_capture");
+ });
+
+ cy.then(() => {
+ globalState.set("paymentIdIncrementalPC", globalState.get("paymentID"));
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/01-Payments.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/01-Payments.cy.js
new file mode 100644
index 0000000000..cd4cf61437
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/01-Payments.cy.js
@@ -0,0 +1,325 @@
+import State from "../../../../utils/State";
+import { OMP_ERRORS } from "../../../configs/Security/Commons";
+
+// PI_PA / PI_PB are two payment intents under the same merchant (M1) but
+// different profiles (PA / PB), created in 00-Setup.cy.js. A user
+// authenticated for PA must never be able to read or act on PB's payment,
+// even though both sit under the same merchant.
+//
+// Positive controls for confirm/capture/cancel/session/complete_authorize
+// only assert the call is accepted into normal processing (not rejected as
+// a profile-mismatch) rather than asserting full business success - PI_PA
+// was never confirmed with a real payment method in 00-Setup, so a 400 for
+// "missing payment method" is expected and unrelated to scoping. Retrieve
+// and update have no such precondition, so those get full positive checks.
+let globalState;
+let apiKeyM1;
+let merchantIdM2;
+let profileIdPA;
+let jwtPA;
+let paymentIdPA;
+let paymentIdPB;
+let paymentIdIncrementalPC;
+
+describe("OMP Scoping - Payments", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ profileIdPA = globalState.get("profileIdPA");
+ jwtPA = globalState.get("userInfoTokenPA");
+ paymentIdPA = globalState.get("paymentIdPA");
+ paymentIdPB = globalState.get("paymentIdPB");
+ paymentIdIncrementalPC = globalState.get("paymentIdIncrementalPC");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ // Ground-truth snapshot for the "resource unchanged after a denied
+ // request" check - deliberately merchant-wide (no X-Profile-Id), not
+ // scoped to PA. Scoping the snapshot fetch to PA would make it 404 for
+ // PI_PB too, and the before/after comparison would trivially pass
+ // without proving anything.
+ function fetchPayment(paymentId) {
+ return () =>
+ cy.ompRetrievePayment(
+ paymentId,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ );
+ }
+
+ context("Retrieve", () => {
+ it("PA retrieves its own PI_PA (positive)", () => {
+ cy.ompRetrievePayment(
+ paymentIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.payment_id).to.eq(paymentIdPA);
+ });
+ });
+
+ it("retrieve cross-profile PI_PB denied (JWT)", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompRetrievePayment(
+ paymentIdPB,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ globalState
+ ),
+ // Confirmed live on current main: PR #15080 moved this check to a
+ // profile-scoped DB query, so a cross-profile payment is a plain
+ // not-found (HE_02), not the generic auth-layer IR_16 mismatch seen
+ // on other resources - see the comment on
+ // OMP_ERRORS.PAYMENT_PROFILE_SCOPED_NOT_FOUND for why this differs
+ // from Business Profile's equivalent check.
+ expectedError: OMP_ERRORS.PAYMENT_PROFILE_SCOPED_NOT_FOUND,
+ });
+ });
+
+ it("retrieve cross-profile PI_PB denied (API key + X-Profile-Id)", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompRetrievePayment(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ),
+ });
+ });
+
+ it("non-existent payment ID returns 404, not a leak", () => {
+ cy.ompRetrievePayment(
+ "pay_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("malformed payment ID returns 4xx, not 500", () => {
+ cy.ompRetrievePayment(
+ "!!not-a-valid-id!!",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid/garbage bearer token on retrieve is rejected", () => {
+ // Substitute for "expired JWT": minting a genuinely expired token
+ // isn't possible from a black-box API test without the signing
+ // secret, so this checks the same rejection path with a malformed one.
+ cy.ompRetrievePayment(paymentIdPA, { type: "invalid" }, globalState).then(
+ (res) => {
+ expect(res.status).to.eq(401);
+ }
+ );
+ });
+ });
+
+ context("Update", () => {
+ it("PA updates its own PI_PA (positive)", () => {
+ cy.ompUpdatePayment(
+ paymentIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount: 150, currency: "USD" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("update cross-profile PI_PB denied, no mutation", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompUpdatePayment(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount: 999, currency: "USD" },
+ globalState
+ ),
+ });
+ });
+ });
+
+ context("Confirm / capture / cancel / session / complete_authorize", () => {
+ it("confirm cross-profile PI_PB denied before any connector call", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompConfirmPayment(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { client_secret: "", confirm: true },
+ globalState
+ ),
+ });
+ });
+
+ it("PA's confirm on its own PI_PA is accepted into processing (positive)", () => {
+ // client_secret is only valid on the publishable-key/SDK confirm path;
+ // server-to-server confirm via api-key must omit it. PI_PA has no
+ // payment method attached (00-Setup.cy.js never confirmed it with real
+ // card data), so this can't assert a single exact success status -
+ // the business outcome legitimately varies (e.g. a missing-payment-
+ // method 400). What this test actually has to prove is narrower: the
+ // profile check passed, i.e. none of the denial statuses a
+ // cross-profile request would get (401/403/404/412) showed up here.
+ cy.ompConfirmPayment(
+ paymentIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { confirm: true },
+ globalState
+ ).then((res) => {
+ expect([401, 403, 404, 412]).to.not.include(res.status);
+ });
+ });
+
+ it("capture cross-profile PI_PB denied, no connector call", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompCapturePayment(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount_to_capture: 100 },
+ globalState
+ ),
+ });
+ });
+
+ it("capture rejects mismatched merchant_id in body", () => {
+ cy.ompCapturePayment(
+ paymentIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount_to_capture: 100, merchant_id: merchantIdM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("cancel cross-profile PI_PB denied", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompCancelPayment(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { cancellation_reason: "requested_by_customer" },
+ globalState
+ ),
+ });
+ });
+
+ it("session token call for cross-profile PI_PB denied", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompCreatePaymentSessionTokens(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { payment_id: paymentIdPB, client_secret: "", wallets: [] },
+ globalState
+ ),
+ });
+ });
+
+ it("complete_authorize for cross-profile PI_PB denied", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompCompletePaymentAuthorize(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ {},
+ globalState
+ ),
+ });
+ });
+
+ // PI_PB can't be used for these two: both operations' own get_trackers
+ // has an early payment-status gate that runs BEFORE the generic
+ // cross-profile check (core_utils::validate_profile_id_from_auth_layer,
+ // payments.rs:886) - incremental_authorization requires status
+ // RequiresCapture plus incremental_authorization_allowed=true
+ // (operations/payments_incremental_authorization.rs:85-96);
+ // extend_authorization requires RequiresCapture or
+ // PartiallyAuthorizedAndRequiresCapture
+ // (operations/payments_extend_authorization.rs:78-85). PI_PB sits in
+ // requires_payment_method (never confirmed), so a test against it would
+ // short-circuit on that status gate instead of the real profile check -
+ // a false pass, confirmed live (same pattern as the Connector Onboarding
+ // and Dispute-fetch comments elsewhere in this folder).
+ //
+ // PI_INCREMENTAL_PC (00-Setup.cy.js) is a dedicated cybersource-backed
+ // payment actually sitting in requires_capture with
+ // incremental_authorization_allowed=true, so these two reach the real
+ // check: PA's auth against a payment that belongs to profile PC.
+ it("incremental_authorization for cross-profile PI_INCREMENTAL_PC denied", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdIncrementalPC),
+ negativeRequest: () =>
+ cy.ompIncrementalAuthorization(
+ paymentIdIncrementalPC,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount: 9000 },
+ globalState
+ ),
+ });
+ });
+
+ it("extend_authorization for cross-profile PI_INCREMENTAL_PC denied", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdIncrementalPC),
+ negativeRequest: () =>
+ cy.ompExtendAuthorization(
+ paymentIdIncrementalPC,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ),
+ });
+ });
+ });
+
+ context("Attempt-ID operations", () => {
+ // /payments/{id}/list-attempts is a V2-only route (web::scope("/v2/payments")
+ // in crates/router/src/routes/app.rs), out of scope per the V2 decision.
+ // The V1 way to see a payment's attempts is expand_attempts=true on the
+ // regular retrieve endpoint.
+ it("listing attempts for cross-profile PI_PB denied", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayment(paymentIdPB),
+ negativeRequest: () =>
+ cy.ompRetrievePayment(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState,
+ { expandAttempts: true }
+ ),
+ });
+ });
+
+ it("PA lists attempts for its own PI_PA (positive)", () => {
+ cy.ompRetrievePayment(
+ paymentIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState,
+ { expandAttempts: true }
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/02-Payouts.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/02-Payouts.cy.js
new file mode 100644
index 0000000000..746b76e389
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/02-Payouts.cy.js
@@ -0,0 +1,257 @@
+import * as fixtures from "../../../../fixtures/imports";
+import State from "../../../../utils/State";
+import { CardPayout } from "../../../configs/Security/Commons";
+
+// PO_PA / PO_PB are payouts under M1, one per profile, created in
+// 00-Setup.cy.js (skipped there if the configured payout connector has no
+// credentials - gate on the same payoutsExecution flag here, matching the
+// existing Payout/*.cy.js convention in this repo).
+//
+// update/confirm/cancel/fulfill are ApiKeyAuth-only routes (verified against
+// crates/router/src/routes/app.rs) - there is no JWT alternative, so these
+// negative tests use the merchant API key plus X-Profile-Id.
+let globalState;
+let apiKeyM1;
+let merchantIdM2;
+let profileIdPA;
+let profileIdPB;
+let payoutIdPA;
+let payoutIdPB;
+let payoutsExecution;
+
+describe("OMP Scoping - Payouts", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ payoutIdPA = globalState.get("payoutIdPA");
+ payoutIdPB = globalState.get("payoutIdPB");
+ payoutsExecution = globalState.get("payoutsExecution");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ beforeEach(function () {
+ if (!payoutsExecution) {
+ cy.task(
+ "cli_log",
+ "Skipping: no payout_processor credentials in the creds file (see 00-Setup.cy.js)."
+ );
+ this.skip();
+ }
+ });
+
+ // Ground-truth snapshot, deliberately merchant-wide (no X-Profile-Id) so
+ // comparing PB's "before"/"after" state isn't trivially masked by PA's
+ // own denied access to it.
+ function fetchPayout(payoutId) {
+ return () =>
+ cy.ompRetrievePayout(
+ payoutId,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ );
+ }
+
+ context("Update / confirm / cancel / fulfill - cross-profile denial", () => {
+ it("payout update blocked cross-profile", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayout(payoutIdPB),
+ negativeRequest: () =>
+ cy.ompUpdatePayout(
+ payoutIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { metadata: { attempted_by: "PA" } },
+ globalState
+ ),
+ });
+ });
+
+ it("payout confirm blocked cross-profile", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayout(payoutIdPB),
+ negativeRequest: () =>
+ cy.ompConfirmPayout(
+ payoutIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { confirm: true },
+ globalState
+ ),
+ });
+ });
+
+ it("payout cancel blocked cross-profile", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayout(payoutIdPB),
+ negativeRequest: () =>
+ cy.ompCancelPayout(
+ payoutIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ {},
+ globalState
+ ),
+ });
+ });
+
+ it("payout fulfill blocked cross-profile", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchPayout(payoutIdPB),
+ negativeRequest: () =>
+ cy.ompFulfillPayout(
+ payoutIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ {},
+ globalState
+ ),
+ });
+ });
+
+ it("PA updates its own payout (positive)", () => {
+ // PO_PA itself is already in requires_fulfillment (confirm=true,
+ // auto_fulfill=false at creation in 00-Setup.cy.js) - update is
+ // blocked there by a hard status gate before any field is even
+ // inspected (is_payout_initiated/is_payout_terminal_state in
+ // crates/router/src/core/payouts/helpers.rs), and fulfilling it only
+ // moves it to a terminal state, which is also blocked. The only
+ // status update is ever permitted on is pre-confirm, so this test
+ // creates its own throwaway unconfirmed payout rather than reusing
+ // PO_PA, which can never be updated again once created.
+ cy.createConfirmPayoutTest(
+ structuredClone(fixtures.createPayoutBody),
+ {
+ ...CardPayout(),
+ Request: {
+ ...CardPayout().Request,
+ profile_id: profileIdPA,
+ },
+ },
+ false,
+ false,
+ globalState
+ );
+
+ cy.then(() => {
+ const throwawayPayoutId = globalState.get("payoutID");
+
+ cy.ompUpdatePayout(
+ throwawayPayoutId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { metadata: { attempted_by: "PA" } },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+ });
+ });
+
+ context("Inconsistent merchant_id / profile_id in request body", () => {
+ it("payout update rejects inconsistent merchant_id", () => {
+ cy.ompUpdatePayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { merchant_id: merchantIdM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("payout confirm rejects inconsistent merchant_id", () => {
+ cy.ompConfirmPayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { confirm: true, merchant_id: merchantIdM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("payout update rejects inconsistent profile_id", () => {
+ cy.ompUpdatePayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { profile_id: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("payout confirm rejects inconsistent profile_id", () => {
+ cy.ompConfirmPayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { confirm: true, profile_id: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+ });
+
+ context("Edge cases", () => {
+ it("non-existent payout ID returns 404", () => {
+ cy.ompUpdatePayout(
+ "payout_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { metadata: {} },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("malformed profile_id in payout body is rejected, not 500", () => {
+ cy.ompUpdatePayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { profile_id: "!!not-a-valid-id!!" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid credential on payout update is rejected", () => {
+ cy.ompUpdatePayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: "not_a_real_api_key" },
+ { metadata: {} },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+
+ it("revoked API key is rejected on payout update", () => {
+ // Creating/revoking an API key needs the admin API key, not a
+ // merchant's own api-key (see getManagementAuthHeaders in
+ // commands.js) - the merchant key is only valid for routes that
+ // operate as that merchant, and key management isn't one of them.
+ const merchantIdM1 = globalState.get("merchantIdM1");
+
+ cy.ompCreateThrowawayApiKey(merchantIdM1, globalState).then(
+ ({ apiKey: throwawayKey, keyId }) => {
+ cy.ompRevokeApiKey(merchantIdM1, keyId, globalState).then(() => {
+ cy.ompUpdatePayout(
+ payoutIdPA,
+ { type: "apiKey", apiKey: throwawayKey },
+ { metadata: {} },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ }
+ );
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/03-ProfileAcquirer.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/03-ProfileAcquirer.cy.js
new file mode 100644
index 0000000000..744ed88508
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/03-ProfileAcquirer.cy.js
@@ -0,0 +1,145 @@
+import State from "../../../../utils/State";
+import { acquirerBody } from "../../../configs/Security/Commons";
+
+// Create binds a profile JWT to the body's profile_id; update binds it to
+// the path's profile_id. The merchant API key's legacy (unscoped) behavior
+// is deliberately retained - see the "API key create is unscoped" case.
+//
+// Routes (verified against crates/router/src/routes/profile_acquirer.rs,
+// app.rs): POST /profile_acquirer, POST /profile_acquirer/{profile_id}/{id},
+// gated #[cfg(all(feature = "olap", feature = "v1"))] (default build), auth
+// is JWTAuth{permission: ProfileAccountWrite} or ApiKeyAuth.
+let globalState;
+let apiKeyM1;
+let profileIdPA;
+let profileIdPB;
+let jwtPA;
+
+describe("OMP Scoping - Profile Acquirer", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ jwtPA = globalState.get("userInfoTokenPA");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("create with matching PA body profile succeeds (positive)", () => {
+ cy.ompCreateProfileAcquirer(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ acquirerBody(profileIdPA),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ cy.wrap(res.body).as("acquirerPA");
+ });
+ });
+
+ it("create rejects body profile mismatch", () => {
+ cy.ompCreateProfileAcquirer(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ acquirerBody(profileIdPB),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ expect(res.body?.error?.code).to.eq("IR_17");
+ });
+ });
+
+ it("API key create is unscoped (legacy behavior, positive/compat)", () => {
+ cy.ompCreateProfileAcquirer(
+ { type: "apiKey", apiKey: apiKeyM1 },
+ acquirerBody(profileIdPB),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ context("Update", () => {
+ let acquirerIdPA;
+
+ before("create a profile_acquirer under PA to update", () => {
+ cy.ompCreateProfileAcquirer(
+ { type: "apiKey", apiKey: apiKeyM1 },
+ acquirerBody(profileIdPA),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ acquirerIdPA = res.body.profile_acquirer_id;
+ });
+ });
+
+ it("update with matching PA path profile succeeds (positive)", () => {
+ // network is required on any update that isn't purely toggling
+ // is_default (IR_06 otherwise).
+ cy.ompUpdateProfileAcquirer(
+ profileIdPA,
+ acquirerIdPA,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ { merchant_name: "Updated by PA", network: "Visa" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("update rejects path profile mismatch", () => {
+ // No confirmed GET/retrieve route exists for profile_acquirer, so this
+ // only asserts the denial itself, not a before/after unchanged
+ // comparison like other specs in this folder.
+ cy.ompUpdateProfileAcquirer(
+ profileIdPB,
+ acquirerIdPA,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ { merchant_name: "Should be rejected" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ expect(res.body?.error?.code).to.eq("IR_17");
+ });
+ });
+
+ it("update on non-existent profile_acquirer_id returns 404", () => {
+ cy.ompUpdateProfileAcquirer(
+ profileIdPA,
+ "pacq_nonexistent_omp_test",
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ { merchant_name: "x" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on update is rejected", () => {
+ cy.ompUpdateProfileAcquirer(
+ profileIdPA,
+ acquirerIdPA,
+ { type: "invalid" },
+ { merchant_name: "x" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("Edge cases on create", () => {
+ it("malformed profile_id in create body is rejected, not 500", () => {
+ cy.ompCreateProfileAcquirer(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ acquirerBody("!!not-a-valid-id!!"),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/04-Authentication.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/04-Authentication.cy.js
new file mode 100644
index 0000000000..a53f377c17
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/04-Authentication.cy.js
@@ -0,0 +1,190 @@
+import State from "../../../../utils/State";
+
+// These are standalone 3DS AuthenticationCreateRequest records
+// (crates/api_models/src/authentication.rs), distinct from a payment's own
+// authentication flow.
+//
+// Routes (verified): POST /authentication (ApiKeyAuth), POST
+// /authentication/{id}/eligibility and POST
+// /authentication/{merchant_id}/{id}/sync (SDK-aware auth, api-key capable).
+// Eligibility/sync compare the authenticated profile against the stored
+// record's profile BEFORE any connector (e.g. Netcetera) call - this repo
+// has no Netcetera sandbox creds configured, so positive controls here only
+// assert the call isn't rejected for profile-mismatch reasons, not that a
+// full 3DS flow succeeds.
+let globalState;
+let apiKeyM1;
+let merchantIdM1;
+let profileIdPA;
+let profileIdPB;
+
+// AuthenticationEligibilityRequest requires payment_method_data and
+// payment_method (crates/api_models/src/authentication.rs) - an empty body
+// fails deserialization (400) before the profile check ever runs, which
+// would make every eligibility test below pass "by accident" regardless of
+// whether the actual profile check works. A valid minimal card body makes
+// sure any 4xx seen is attributable to the profile check, not this.
+const eligibilityBody = {
+ payment_method_data: {
+ card: {
+ card_number: "4242424242424242",
+ card_exp_month: "12",
+ card_exp_year: "28",
+ card_cvc: "123",
+ },
+ },
+ payment_method: "card",
+};
+
+describe("OMP Scoping - Authentication", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ merchantIdM1 = globalState.get("merchantIdM1");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("Create", () => {
+ // POST /authentication is ApiKeyAuth-only (HeaderAuth(ApiKeyAuth)) - no
+ // JWT alternative, unlike eligibility/sync below.
+ it("create rejects explicit cross-profile request", () => {
+ cy.ompCreateAuthentication(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount: 1000, currency: "USD", profile_id: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(400);
+ expect(res.body?.error?.code).to.eq("IR_16");
+ });
+ });
+
+ it("create with no profile_id defaults to auth profile (positive)", () => {
+ cy.ompCreateAuthentication(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { amount: 1000, currency: "USD" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.profile_id).to.eq(profileIdPA);
+ });
+ });
+ });
+
+ context("Eligibility / sync", () => {
+ let authPBId;
+ let authPAId;
+
+ before("create one authentication record under each profile", () => {
+ cy.ompCreateAuthentication(
+ { type: "apiKey", apiKey: apiKeyM1 },
+ { amount: 1000, currency: "USD", profile_id: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ authPBId = res.body.authentication_id;
+ });
+
+ cy.ompCreateAuthentication(
+ { type: "apiKey", apiKey: apiKeyM1 },
+ { amount: 1000, currency: "USD", profile_id: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ authPAId = res.body.authentication_id;
+ });
+ });
+
+ it("eligibility on a PB authentication denied for PA auth", () => {
+ cy.ompAuthenticationEligibility(
+ authPBId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ eligibilityBody,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("sync on a PB authentication denied for PA auth", () => {
+ cy.ompAuthenticationSync(
+ merchantIdM1,
+ authPBId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ {},
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("eligibility rejects conflicting request profile", () => {
+ cy.ompAuthenticationEligibility(
+ authPAId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { ...eligibilityBody, profile_id: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("eligibility on own PA authentication succeeds (positive)", () => {
+ // Expected 200 (the profile check passes correctly, which is this
+ // test's actual purpose). PA's business profile has a netcetera
+ // authentication_processor connector configured in 00-Setup.cy.js
+ // specifically so eligibility can proceed past the profile check into
+ // real 3DS processing, instead of failing early with 422 IR_29
+ // "authentication_connector_details is not available in business
+ // profile" (crates/router/src/core/authentication/utils.rs:603-610).
+ cy.ompAuthenticationEligibility(
+ authPAId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ eligibilityBody,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("eligibility on a non-existent authentication ID is rejected, not 500", () => {
+ // Server returns 400 here rather than 404 - ID format/lookup
+ // validation runs before an existence check.
+ cy.ompAuthenticationEligibility(
+ "auth_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ eligibilityBody,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("malformed authentication ID returns 4xx, not 500", () => {
+ cy.ompAuthenticationEligibility(
+ "!!bad-id!!",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ eligibilityBody,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid credential on create is rejected", () => {
+ cy.ompCreateAuthentication(
+ { type: "invalid" },
+ { amount: 1000, currency: "USD" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/05-Disputes.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/05-Disputes.cy.js
new file mode 100644
index 0000000000..d6ffbdb872
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/05-Disputes.cy.js
@@ -0,0 +1,205 @@
+import State from "../../../../utils/State";
+
+// Covers both evidence deletion and connector dispute fetch, merged into
+// one file per the endpoint-wise grouping decision rather than one file per
+// fix.
+//
+// GAP (documented in 00-Setup.cy.js): this suite has no command that
+// fabricates a dispute - disputes only exist from a real connector
+// chargeback. D_PA / D_PB are looked up at runtime from whatever disputes
+// already exist for this merchant; if none are found for a profile, that
+// profile's tests skip, matching the existing 47-DisputeTests.cy.js
+// convention in this repo rather than failing on missing fixtures.
+//
+// Routes (verified): DELETE /disputes/evidence, GET /disputes/{connector_id}/fetch
+// (param is connector_id, i.e. the MCA id), GET /disputes/{dispute_id}
+// (retrieve, for before/after snapshots) - all ApiKeyAuth(allow_connected_scope_operation)
+// or JWTAuth(ProfileDispute{Read,Write}).
+//
+// CAUTION: the "delete evidence on own D_PA succeeds" positive control
+// actually deletes real evidence on a real dispute. It's gated behind
+// DELETE_REAL_DISPUTE_EVIDENCE=true (not set by default) so this file never
+// destroys real sandbox data just by running - flip it on deliberately if
+// you want that case exercised.
+let globalState;
+let apiKeyM1;
+let profileIdPA;
+let profileIdPB;
+let mcaPaId;
+let mcaPbId;
+let disputePA;
+let disputePB;
+
+function findDisputeForProfile(disputes, profileId) {
+ return (disputes || []).find((d) => d.profile_id === profileId);
+}
+
+describe("OMP Scoping - Disputes", () => {
+ before("seed global state and look up real disputes per profile", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ mcaPaId = globalState.get("mcaPaId");
+ mcaPbId = globalState.get("mcaPbId");
+ });
+
+ cy.then(() => {
+ return cy.ompListDisputes(
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ );
+ }).then((res) => {
+ const disputes = Array.isArray(res.body) ? res.body : res.body?.data;
+ disputePA = findDisputeForProfile(disputes, profileIdPA);
+ disputePB = findDisputeForProfile(disputes, profileIdPB);
+
+ if (!disputePA || !disputePB) {
+ cy.task(
+ "cli_log",
+ "No real dispute found for one or both profiles - dispute scoping " +
+ "tests in this file will skip. See the GAP comment at the top of " +
+ "this file."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ function fetchDispute(disputeId) {
+ return () =>
+ cy.ompRetrieveDispute(
+ disputeId,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ );
+ }
+
+ context("Evidence deletion", () => {
+ beforeEach(function () {
+ if (!disputePB) this.skip();
+ });
+
+ it("delete evidence on cross-profile D_PB denied, evidence unchanged", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchDispute(disputePB.dispute_id),
+ negativeRequest: () =>
+ cy.ompDeleteDisputeEvidence(
+ disputePB.dispute_id,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ),
+ });
+ });
+
+ it("delete evidence on own D_PA succeeds (positive, destructive - opt-in only)", function () {
+ if (Cypress.env("DELETE_REAL_DISPUTE_EVIDENCE") !== true) {
+ cy.task(
+ "cli_log",
+ "Skipping: set CYPRESS_DELETE_REAL_DISPUTE_EVIDENCE=true to run " +
+ "this destructive positive control."
+ );
+ this.skip();
+ }
+ if (!disputePA) this.skip();
+
+ cy.ompDeleteDisputeEvidence(
+ disputePA.dispute_id,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("deleting evidence on a non-existent dispute_id returns 404", () => {
+ cy.ompDeleteDisputeEvidence(
+ "dp_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("malformed dispute_id returns 4xx, not 500", () => {
+ cy.ompDeleteDisputeEvidence(
+ "!!bad!!",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid credential on evidence deletion is rejected", () => {
+ cy.ompDeleteDisputeEvidence(
+ "dp_nonexistent_omp_test",
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("Connector fetch", () => {
+ // ompFetchDisputesFromConnector supplies a default fetch_from/fetch_till
+ // window itself - omitting those required query params returns 400
+ // "missing field `fetch_from`" before auth even runs, which would make
+ // every test below pass for the wrong reason regardless of profile or
+ // credentials (confirmed live, same false-pass risk as the Connector
+ // Onboarding PayPal-only check).
+ it("fetch disputes on cross-profile MCA_PB denied", () => {
+ cy.ompFetchDisputesFromConnector(
+ mcaPbId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("fetch disputes on own MCA_PA isn't profile-rejected (positive)", () => {
+ // Can't assert a single exact success status here - the real
+ // business outcome depends on whether the connector sandbox actually
+ // has dispute data to fetch, which this suite doesn't control. What
+ // this test actually has to prove is narrower: the profile check
+ // passed, i.e. none of the denial statuses a cross-profile request
+ // would get (401/403/404/412) showed up here.
+ cy.ompFetchDisputesFromConnector(
+ mcaPaId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect([401, 403, 404, 412]).to.not.include(res.status);
+ });
+ });
+
+ it("fetch on a non-existent MCA id is rejected, not 500", () => {
+ // Server returns 400 (ID format/lookup validation) rather than 404
+ // here, same pattern seen elsewhere in this folder.
+ cy.ompFetchDisputesFromConnector(
+ "mca_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid credential on connector fetch is rejected", () => {
+ cy.ompFetchDisputesFromConnector(
+ mcaPaId,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/06-ConnectorOnboarding.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/06-ConnectorOnboarding.cy.js
new file mode 100644
index 0000000000..155c89a00f
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/06-ConnectorOnboarding.cy.js
@@ -0,0 +1,174 @@
+import State from "../../../../utils/State";
+
+// Sync validates that its connector_id (an MCA) belongs to the request's
+// profile_id before passing that profile along to the PayPal MCA update.
+// Action URL retrieval and tracking-ID reset stay merchant-only by design
+// (not part of the fix), so those two just get a light sanity check here,
+// not a security assertion.
+//
+// All three routes (sync, action_url, reset_tracking_id) return 400 IR_20
+// "Connector onboarding flow not supported" for ANY non-PayPal connector,
+// confirmed live - the feature is PayPal-only. Crucially, that check fires
+// independent of the profile match/mismatch being tested here, so using
+// MCA_PA (whatever CYPRESS_CONNECTOR is) would make even the NEGATIVE
+// profile-mismatch test "pass" for the wrong reason (always 400, whether
+// or not the profile actually matched). MCA_PAYPAL_PA / MCA_PAYPAL_PB
+// (00-Setup.cy.js) exist specifically so every test below is attributable
+// to the actual profile check, not connector support.
+//
+// The negative test below targets MCA_PAYPAL_PB (genuinely owned by PB)
+// with PA's auth - a real cross-profile attempt. An earlier version of this
+// test instead took PA's own MCA_PAYPAL_PA and only varied the request
+// body's profile_id field to PB; that returned 200, because the actual
+// ownership check compares the MCA's real stored profile against the
+// authenticated profile, not an arbitrary profile_id value the caller can
+// put in the body - PA's own MCA + PA's own auth is never a real mismatch
+// no matter what the body claims.
+//
+// Routes (verified): POST /connector_onboarding/sync, /action_url,
+// /reset_tracking_id - all JWTAuth(MerchantAccountWrite) only, no ApiKeyAuth
+// alternative, cfg #[cfg(all(feature = "olap", feature = "v1"))] (default).
+let globalState;
+let merchantIdM1;
+let profileIdPA;
+let jwtPA;
+let mcaPaypalPaId;
+let mcaPaypalPbId;
+
+describe("OMP Scoping - Connector Onboarding", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ merchantIdM1 = globalState.get("merchantIdM1");
+ profileIdPA = globalState.get("profileIdPA");
+ jwtPA = globalState.get("userInfoTokenPA");
+ mcaPaypalPaId = globalState.get("mcaPaypalPaId");
+ mcaPaypalPbId = globalState.get("mcaPaypalPbId");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ function fetchMcaPaypalPB() {
+ return () =>
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPaypalPbId,
+ { type: "apiKey", apiKey: globalState.get("apiKeyM1") },
+ globalState
+ );
+ }
+
+ it("sync rejects connector/profile mismatch, MCA_PAYPAL_PB unchanged", () => {
+ // Not OMP_ERRORS.JWT_PROFILE_MISMATCH (configs/Security/Commons.js):
+ // that constant is the generic "JWT's own profile vs. the resource's
+ // own stored profile" check (validate_profile_id_from_auth_layer,
+ // confirmed on Payments retrieve and Business Profile update). This
+ // check is different - it compares the request body's profile_id
+ // against the MCA_PAYPAL_PB's real stored profile
+ // (utils/connector_onboarding.rs:73), not the JWT's own profile - so
+ // its exact error may carry a different message even if it shares the
+ // same underlying function. Needs its own live confirmation before
+ // asserting an exact expectedError here.
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchMcaPaypalPB(),
+ negativeRequest: () =>
+ cy.ompConnectorOnboardingSync(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ {
+ connector_id: mcaPaypalPbId,
+ profile_id: profileIdPA,
+ connector: "paypal",
+ },
+ globalState
+ ),
+ });
+ });
+
+ it("sync with matching profile succeeds (positive)", () => {
+ cy.ompConnectorOnboardingSync(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ {
+ connector_id: mcaPaypalPaId,
+ profile_id: profileIdPA,
+ connector: "paypal",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("sync on a non-existent connector_id returns 404", () => {
+ cy.ompConnectorOnboardingSync(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ {
+ connector_id: "mca_nonexistent_omp_test",
+ profile_id: profileIdPA,
+ connector: "paypal",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("malformed profile_id in sync body returns 4xx, not 500", () => {
+ cy.ompConnectorOnboardingSync(
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ {
+ connector_id: mcaPaypalPaId,
+ profile_id: "!!bad!!",
+ connector: "paypal",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid credential on sync is rejected", () => {
+ cy.ompConnectorOnboardingSync(
+ { type: "invalid" },
+ {
+ connector_id: mcaPaypalPaId,
+ profile_id: profileIdPA,
+ connector: "paypal",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+
+ context(
+ "Unchanged by design - informational only, not a security assertion",
+ () => {
+ it("action URL retrieval remains merchant-only", () => {
+ cy.ompConnectorOnboardingActionUrl(
+ { type: "jwt", token: jwtPA },
+ {
+ connector: "paypal",
+ connector_id: mcaPaypalPaId,
+ return_url: "https://example.com",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("tracking-ID reset remains merchant-only", () => {
+ cy.ompConnectorOnboardingResetTrackingId(
+ { type: "jwt", token: jwtPA },
+ { connector: "paypal", connector_id: mcaPaypalPaId },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+ }
+ );
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/07-ApplePay.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/07-ApplePay.cy.js
new file mode 100644
index 0000000000..c87ae748d0
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/07-ApplePay.cy.js
@@ -0,0 +1,160 @@
+import State from "../../../../utils/State";
+
+// V2 auth alignment for applepay-verified-domains is V2-only and out of
+// scope per the V2 decision - not covered here.
+//
+// Routes (verified): POST /verify/apple_pay/{merchant_id} (registration AND
+// verification are the same endpoint - there is no separate "register"
+// route in V1), GET /verify/applepay_verified_domains?merchant_id=&merchant_connector_account_id=.
+// Both ApiKeyAuth or JWTAuth, cfg #[cfg(all(feature = "olap", feature = "v1"))].
+//
+// domain_names needs a real, hosted domain rather than a placeholder like
+// "example.com" - Apple's actual domain association check runs as part of
+// verify/register, confirmed live ("Applepay verification Failed" / IR_06
+// for an unverifiable domain). Using a placeholder everywhere would make
+// the cross-profile/ownership denial tests below "pass" for the wrong
+// reason if domain verification happens to run before the profile check -
+// same false-pass risk as the Connector Onboarding PayPal-only check. A
+// real domain keeps every 4xx seen here attributable to profile/ownership,
+// not domain verification.
+//
+// The actual domain isn't hardcoded here - set APPLE_PAY_TEST_DOMAIN in
+// cypress.env.json (or CYPRESS_APPLE_PAY_TEST_DOMAIN) to a real, hosted
+// domain for this environment. Falls back to a non-hosted placeholder,
+// which will always fail Apple's association check (expected - the
+// profile/ownership checks above it still run and still matter).
+const APPLE_PAY_TEST_DOMAIN =
+ Cypress.env("APPLE_PAY_TEST_DOMAIN") || "example.com";
+
+let globalState;
+let apiKeyM1;
+let merchantIdM1;
+let merchantIdM2;
+let profileIdPA;
+let jwtPA;
+let mcaPaId;
+let mcaPbId;
+
+describe("OMP Scoping - Apple Pay", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ merchantIdM1 = globalState.get("merchantIdM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ profileIdPA = globalState.get("profileIdPA");
+ jwtPA = globalState.get("userInfoTokenPA");
+ mcaPaId = globalState.get("mcaPaId");
+ mcaPbId = globalState.get("mcaPbId");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("verify/register rejected for a merchant_id the credential doesn't own", () => {
+ cy.ompVerifyApplePay(
+ merchantIdM2,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ {
+ domain_names: [APPLE_PAY_TEST_DOMAIN],
+ merchant_connector_account_id: mcaPaId,
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("domain registration against cross-profile MCA_PB denied", () => {
+ cy.ompVerifyApplePay(
+ merchantIdM1,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ {
+ domain_names: [APPLE_PAY_TEST_DOMAIN],
+ merchant_connector_account_id: mcaPbId,
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("verified-domains read for cross-profile MCA_PB denied", () => {
+ cy.ompGetApplePayVerifiedDomains(
+ merchantIdM1,
+ mcaPbId,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("verify/register and verified-domains read work for PA's own MCA_PA (positive)", () => {
+ // The profile/ownership check itself passes correctly here (that's this
+ // test's actual purpose, and the 3 cross-profile denial tests above
+ // confirm the fix works) - verify_merchant_creds_for_applepay only
+ // DB-checks that the MCA exists and belongs to the right profile, then
+ // calls Apple using server-wide config (state.conf.applepay_merchant_configs:
+ // cert/key/merchant identifier), unrelated to which MCA was passed.
+ //
+ // Expecting 422 IR_06 "Applepay verification Failed" here is a known,
+ // confirmed environment limitation on this deployment, not the OMP
+ // scoping behavior under test: either integ's registered Apple Pay
+ // merchant cert/identity is stale/misconfigured, or the domain's
+ // .well-known/apple-developer-merchantid-domain-association file
+ // doesn't match that identity - asserting the real 5xx-free error here
+ // (rather than a vague "not 5xx") keeps this test meaningful without
+ // masking the gap. Once the environment is fixed, change this back to
+ // expect(res.status).to.eq(200).
+ cy.ompVerifyApplePay(
+ merchantIdM1,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ {
+ domain_names: [APPLE_PAY_TEST_DOMAIN],
+ merchant_connector_account_id: mcaPaId,
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(422);
+ expect(res.body?.error?.code).to.eq("IR_06");
+ expect(res.body?.error?.message).to.eq("Applepay verification Failed");
+ });
+
+ cy.ompGetApplePayVerifiedDomains(
+ merchantIdM1,
+ mcaPaId,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("verified-domains read for a non-existent MCA returns 404", () => {
+ cy.ompGetApplePayVerifiedDomains(
+ merchantIdM1,
+ "mca_nonexistent_omp_test",
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on verify/register is rejected", () => {
+ cy.ompVerifyApplePay(
+ merchantIdM1,
+ { type: "invalid" },
+ {
+ domain_names: [APPLE_PAY_TEST_DOMAIN],
+ merchant_connector_account_id: mcaPaId,
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/08-BusinessProfile.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/08-BusinessProfile.cy.js
new file mode 100644
index 0000000000..7820eec506
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/08-BusinessProfile.cy.js
@@ -0,0 +1,160 @@
+import State from "../../../../utils/State";
+import { OMP_ERRORS } from "../../../configs/Security/Commons";
+
+// Covers cached profile reads and the connector-agnostic MIT toggle.
+// Profile reads are cached; cached profile reads must still enforce
+// merchant ownership, and the connector-agnostic MIT toggle must use the
+// authenticated processor merchant for its profile lookup.
+//
+// Routes (verified): GET/POST /account/{account_id}/business_profile/{profile_id},
+// POST .../toggle_connector_agnostic_mit - both ApiKeyAuth or JWTAuth,
+// cfg #[cfg(all(feature = "olap", feature = "v1"))].
+let globalState;
+let apiKeyM1;
+let apiKeyM2;
+let merchantIdM1;
+let merchantIdM2;
+let profileIdPA;
+let profileIdPB;
+let jwtPA;
+
+describe("OMP Scoping - Business Profile", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ apiKeyM2 = globalState.get("apiKeyM2");
+ merchantIdM1 = globalState.get("merchantIdM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ jwtPA = globalState.get("userInfoTokenPA");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ function fetchProfilePB() {
+ return () =>
+ cy.ompRetrieveBusinessProfile(
+ merchantIdM1,
+ profileIdPB,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ );
+ }
+
+ it("cached profile read never leaks PB through M2's route/creds", () => {
+ // Warm the cache via a legitimate M1 read first.
+ cy.ompRetrieveBusinessProfile(
+ merchantIdM1,
+ profileIdPB,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((warmRes) => {
+ expect(warmRes.status).to.eq(200);
+ });
+
+ cy.ompRetrieveBusinessProfile(
+ merchantIdM2,
+ profileIdPB,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ expect(res.body?.profile_id).to.not.eq(profileIdPB);
+ });
+ });
+
+ it("MIT toggle blocked cross-merchant, PB toggle unchanged", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchProfilePB(),
+ negativeRequest: () =>
+ cy.ompToggleConnectorAgnosticMit(
+ merchantIdM2,
+ profileIdPB,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ { enabled: true },
+ globalState
+ ),
+ });
+ });
+
+ it("update rejects cross-profile path, PB unchanged (JWT, same merchant)", () => {
+ // Everything above is M1-vs-M2 (cross-merchant, API key). This is the
+ // PA-vs-PB case within the SAME merchant - JWTAuthMerchantAndProfileFromRoute
+ // requires the JWT's own profile to equal the path profile_id, so PA's
+ // JWT must be denied here even though the account_id (M1) matches.
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchProfilePB(),
+ negativeRequest: () =>
+ cy.ompUpdateBusinessProfile(
+ merchantIdM1,
+ profileIdPB,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ { profile_name: "Should be rejected" },
+ globalState
+ ),
+ // Confirmed live - same generic JWT profile-mismatch path as the
+ // Payments retrieve test, not specific to Business Profile.
+ expectedError: OMP_ERRORS.JWT_PROFILE_MISMATCH,
+ });
+ });
+
+ it("PA can update its own business profile (JWT, positive)", () => {
+ cy.ompUpdateBusinessProfile(
+ merchantIdM1,
+ profileIdPA,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ { profile_name: "OMP Scoping Test PA" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("M1 can read and toggle PB's own profile (positive)", () => {
+ cy.ompRetrieveBusinessProfile(
+ merchantIdM1,
+ profileIdPB,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+
+ cy.ompToggleConnectorAgnosticMit(
+ merchantIdM1,
+ profileIdPB,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ { enabled: true },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("retrieving a non-existent profile returns 404", () => {
+ cy.ompRetrieveBusinessProfile(
+ merchantIdM1,
+ "pro_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on profile read is rejected", () => {
+ cy.ompRetrieveBusinessProfile(
+ merchantIdM1,
+ profileIdPB,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/09-Blocklist.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/09-Blocklist.cy.js
new file mode 100644
index 0000000000..79870ea630
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/09-Blocklist.cy.js
@@ -0,0 +1,175 @@
+import State from "../../../../utils/State";
+
+// GET /blocklist no longer accepts publishable-key/client-secret SDK auth;
+// a JWT listing uses the JWT's own profile rather than a conflicting
+// X-Profile-Id header; an API key with no resolved profile stays
+// merchant-wide (legacy behavior).
+//
+// Route (verified): GET/POST/DELETE /blocklist, cfg
+// #[cfg(all(feature = "olap", feature = "v1"))], auth is
+// check_sdk_auth_and_get_auth (dynamic: api-key, or publishable
+// key/client-secret SDK auth) by default - GET is narrowed specifically.
+let globalState;
+let apiKeyM1;
+let publishableKeyM1;
+let profileIdPA;
+let profileIdPB;
+let jwtPA;
+
+describe("OMP Scoping - Blocklist", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ jwtPA = globalState.get("userInfoTokenPA");
+ });
+
+ // publishableKeyM1 is only set by merchantCreateCallTest, which M1
+ // (created via the dashboard signup flow in 00-Setup.cy.js) never went
+ // through - fetch it from the merchant account directly.
+ cy.then(() => {
+ return cy.ompGetMerchantAccount(
+ globalState.get("merchantIdM1"),
+ globalState
+ );
+ }).then((res) => {
+ publishableKeyM1 = res.body?.publishable_key;
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("publishable-key/client-secret SDK auth is rejected on GET", () => {
+ cy.ompGetBlocklist(
+ { type: "apiKey", apiKey: publishableKeyM1 },
+ "?data_kind=card_bin",
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("JWT + conflicting X-Profile-Id never returns the other profile's entries", () => {
+ // Must be unique per run - the server rejects re-blocking a bin that's
+ // already blocked (IR_16 "provided bin is already blocked"), so a fixed
+ // value collides across repeated test runs.
+ const pbOnlyBin = String(Date.now()).slice(-6);
+
+ cy.ompCreateBlocklistEntry(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ { type: "card_bin", data: pbOnlyBin },
+ globalState
+ ).then((createRes) => {
+ expect(createRes.status).to.eq(200);
+ });
+
+ // JWT scoped to PA, but the header asks for PB - the fix must use the
+ // JWT's own profile (PA), never PB's. The list response
+ // (ListBlocklistResponse) is { count, total_count, data: [...] }, and
+ // each entry (BlocklistResponse) carries profile_id but not the raw
+ // bin value - that's the field this check actually has to assert on.
+ cy.ompGetBlocklist(
+ { type: "jwt", token: jwtPA, profileId: profileIdPB },
+ "?data_kind=card_bin",
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ const returnedProfileIds = (res.body?.data || []).map(
+ (entry) => entry.profile_id
+ );
+ expect(returnedProfileIds).to.not.include(profileIdPB);
+ });
+ });
+
+ it("create with JWT-PA + conflicting X-Profile-Id uses the JWT's own profile, not the header", () => {
+ // Mirrors the GET test above for the write path: the fix must use the
+ // JWT's own profile (PA) to scope where the entry is created, never the
+ // conflicting header value (PB).
+ const paOnlyBin = String(Date.now()).slice(-6);
+
+ cy.ompCreateBlocklistEntry(
+ { type: "jwt", token: jwtPA, profileId: profileIdPB },
+ { type: "card_bin", data: paOnlyBin },
+ globalState
+ ).then((createRes) => {
+ expect(createRes.status).to.eq(200);
+ expect(createRes.body?.profile_id).to.eq(profileIdPA);
+ });
+ });
+
+ it("delete rejects a bin that belongs to a different profile, entry unchanged", () => {
+ // delete_entry_from_blocklist resolves profile_id from the caller
+ // (header/JWT, defaulting if omitted) and queries by
+ // (merchant_id, bin, profile_id) - a PA-scoped delete for a PB-owned
+ // bin simply won't match that row (core/blocklist/utils.rs:513-524,
+ // GenericNotFoundError), not because of an explicit profile check but
+ // because the row lookup itself is profile-scoped. Confirm the entry
+ // survives via /blocklist/lookup, which reports BlocklistResponse's
+ // omitted raw bin value as a blocked:true/false flag instead.
+ // Must be a plain 6-digit number - "card_bin" (unlike "generic_card_bin")
+ // validates exactly 6 digits server-side (IR_05 otherwise, confirmed
+ // live). Date.now() alone is enough to avoid colliding with the bin the
+ // "JWT + conflicting X-Profile-Id" test above creates, since tests run
+ // at different timestamps.
+ const pbOnlyBin = String(Date.now()).slice(-6);
+
+ cy.ompCreateBlocklistEntry(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ { type: "card_bin", data: pbOnlyBin },
+ globalState
+ ).then((createRes) => {
+ expect(createRes.status).to.eq(200);
+ });
+
+ cy.ompDeleteBlocklistEntry(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { type: "card_bin", data: pbOnlyBin },
+ globalState
+ ).then((deleteRes) => {
+ expect(deleteRes.status).to.eq(404);
+ });
+
+ cy.ompLookupBlocklist(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ pbOnlyBin,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body?.blocked).to.eq(true);
+ });
+ });
+
+ it("merchant API key with no profile header stays merchant-wide (positive/compat)", () => {
+ cy.ompGetBlocklist(
+ { type: "apiKey", apiKey: apiKeyM1 },
+ "?data_kind=card_bin",
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("malformed query parameters return 4xx, not 500", () => {
+ cy.ompGetBlocklist(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ "?limit=abc&offset=-1",
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("invalid credential on GET is rejected", () => {
+ cy.ompGetBlocklist(
+ { type: "invalid" },
+ "?data_kind=card_bin",
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/support/e2e.js b/cypress-tests/cypress/support/e2e.js
index 71c92d77d3..4192924ba6 100644
--- a/cypress-tests/cypress/support/e2e.js
+++ b/cypress-tests/cypress/support/e2e.js
@@ -1,5 +1,6 @@
import "cypress-mochawesome-reporter/register";
import "./commands";
+import "./security-commands";
import "./redirectionHandler";
Cypress.on("window:before:load", (win) => {
diff --git a/cypress-tests/cypress/support/security-commands.js b/cypress-tests/cypress/support/security-commands.js
new file mode 100644
index 0000000000..fcff880557
--- /dev/null
+++ b/cypress-tests/cypress/support/security-commands.js
@@ -0,0 +1,559 @@
+// Cypress custom commands used only by cypress/e2e/spec/Security/OMPScoping/.
+// Split out of commands.js into its own file so the OMP (merchant/profile)
+// scoping test helpers don't keep growing a 14k-line shared file - every
+// command here is self-contained and doesn't depend on anything defined in
+// commands.js. Loaded directly by cypress/support/e2e.js.
+//
+// auth variants:
+// { type: "apiKey", apiKey, profileId? }
+// { type: "jwt", token, profileId? }
+// { type: "none" } - no Authorization/api-key header
+// { type: "invalid" } - garbage bearer token, substitutes
+// for an expired JWT (minting a
+// genuinely expired one isn't
+// possible from a black-box API
+// test without the signing secret)
+
+function buildOmpHeaders(auth = {}) {
+ const headers = {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ };
+
+ switch (auth.type) {
+ case "apiKey":
+ headers["api-key"] = auth.apiKey;
+ break;
+ case "jwt":
+ headers["Authorization"] = `Bearer ${auth.token}`;
+ break;
+ case "invalid":
+ headers["Authorization"] = "Bearer not-a-real-token";
+ break;
+ case "none":
+ break;
+ default:
+ throw new Error(`ompRequest: unknown auth.type "${auth.type}"`);
+ }
+
+ if (auth.profileId) {
+ headers["X-Profile-Id"] = auth.profileId;
+ }
+
+ return headers;
+}
+
+Cypress.Commands.add(
+ "ompRequest",
+ ({ method, url, auth, body, failOnStatusCode = false }) => {
+ return cy
+ .request({
+ method,
+ url,
+ headers: buildOmpHeaders(auth),
+ body,
+ failOnStatusCode,
+ })
+ .then((response) => {
+ // Cypress.log, not cy.task: cy.task queues an async command, and
+ // returning `response` synchronously right after it trips
+ // Cypress's "mixing sync and async code" check.
+ Cypress.log({
+ name: "ompRequest",
+ message: `${method} ${url} -> ${response.status}`,
+ });
+ return response;
+ });
+ }
+);
+
+// Housekeeping timestamps that get bumped as a side effect of merely
+// reading a resource (e.g. force_sync=true re-touching a payment on every
+// GET) - confirmed live on PI_INCREMENTAL_PC (a real confirmed/captured
+// payment; PI_PA/PI_PB never left requires_payment_method, so this never
+// surfaced there). Not meaningful mutation evidence for a security check -
+// a denied request that merely caused a read-driven timestamp bump isn't a
+// scoping bug.
+const VOLATILE_RESOURCE_FIELDS = ["modified_at", "updated"];
+
+// Asserts a cross-scope request was denied (anything but 2xx) and that the
+// target resource is unchanged, per the test sheet's "evidence to retain"
+// convention: fetch -> attempt the negative request -> re-fetch -> compare.
+//
+// Checks the full denial response, not just the status code:
+// - Always: the body is a well-formed Hyperswitch error envelope
+// ({ error: { type, code, message } }, all non-empty strings) - catches a
+// "denial" that's actually an empty/malformed body rather than a real
+// error response, which `status >= 400` alone would miss.
+// - If `expectedError` is given ({ status?, code?, message? }), each
+// provided field must match exactly - use this when the exact error is
+// known and worth pinning down (e.g. a specific IR_xx code), not just
+// "some 4xx happened."
+Cypress.Commands.add(
+ "ompAssertDeniedAndUnchanged",
+ ({ fetch, negativeRequest, expectedError }) => {
+ return fetch().then((before) => {
+ return negativeRequest().then((negativeResponse) => {
+ expect(
+ negativeResponse.status,
+ "negative request must be denied"
+ ).to.be.gte(400);
+
+ const errorBody = negativeResponse.body?.error;
+ expect(
+ errorBody,
+ "denial response must carry a well-formed error envelope: " +
+ JSON.stringify(negativeResponse.body)
+ ).to.exist;
+ expect(errorBody?.type, "error.type").to.be.a("string").and.not.be
+ .empty;
+ expect(errorBody?.code, "error.code").to.be.a("string").and.not.be
+ .empty;
+ expect(errorBody?.message, "error.message").to.be.a("string").and.not.be
+ .empty;
+
+ if (expectedError?.status !== undefined) {
+ expect(negativeResponse.status, "expected exact status").to.eq(
+ expectedError.status
+ );
+ }
+ if (expectedError?.code !== undefined) {
+ expect(errorBody?.code, "expected exact error.code").to.eq(
+ expectedError.code
+ );
+ }
+ if (expectedError?.message !== undefined) {
+ expect(errorBody?.message, "expected exact error.message").to.eq(
+ expectedError.message
+ );
+ }
+
+ return fetch().then((after) => {
+ // Chai's deep.equal failure dump gets truncated in the Cypress
+ // reporter UI on anything but a small object, making it hard to
+ // tell which field actually differs. Log that explicitly first so
+ // a failure here is diagnosable without needing devtools.
+ const changedKeys = Object.keys({ ...before.body, ...after.body })
+ .filter((key) => !VOLATILE_RESOURCE_FIELDS.includes(key))
+ .filter(
+ (key) =>
+ JSON.stringify(before.body?.[key]) !==
+ JSON.stringify(after.body?.[key])
+ )
+ .map((key) => ({
+ key,
+ before: before.body?.[key],
+ after: after.body?.[key],
+ }));
+
+ if (changedKeys.length > 0) {
+ Cypress.log({
+ name: "ompAssertDeniedAndUnchanged",
+ message: `fields changed despite denial: ${JSON.stringify(changedKeys)}`,
+ });
+ }
+
+ expect(
+ changedKeys,
+ "target resource must be unchanged after a denied request - " +
+ "changed fields: " +
+ JSON.stringify(changedKeys)
+ ).to.deep.equal([]);
+ });
+ });
+ });
+ }
+);
+
+// Creates a throwaway merchant API key using the admin API key (key
+// management is always admin-authenticated, never via a merchant's own
+// api-key - see getManagementAuthHeaders above). Used by the "revoked API
+// key is rejected" edge cases in cypress/e2e/spec/Security/OMPScoping/.
+Cypress.Commands.add("ompCreateThrowawayApiKey", (merchantId, globalState) => {
+ const adminApiKey = globalState.get("adminApiKey");
+ const baseUrl = globalState.get("baseUrl");
+
+ return cy
+ .request({
+ method: "POST",
+ url: `${baseUrl}/api_keys/${merchantId}`,
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ Authorization: `admin-api-key=${adminApiKey}`,
+ },
+ body: {
+ name: "omp-scoping-throwaway-key",
+ expiration: "2069-09-23T01:02:03.000Z",
+ },
+ failOnStatusCode: false,
+ })
+ .then((response) => {
+ expect(response.status, "throwaway API key creation must succeed").to.eq(
+ 200
+ );
+ return { apiKey: response.body.api_key, keyId: response.body.key_id };
+ });
+});
+
+// Revokes a merchant API key via the admin API key - pair for
+// ompCreateThrowawayApiKey above.
+Cypress.Commands.add("ompRevokeApiKey", (merchantId, keyId, globalState) => {
+ const adminApiKey = globalState.get("adminApiKey");
+ const baseUrl = globalState.get("baseUrl");
+
+ return cy
+ .request({
+ method: "DELETE",
+ url: `${baseUrl}/api_keys/${merchantId}/${keyId}`,
+ headers: { Authorization: `admin-api-key=${adminApiKey}` },
+ failOnStatusCode: false,
+ })
+ .then((response) => {
+ expect(response.status, "API key revocation must succeed").to.eq(200);
+ return response;
+ });
+});
+
+// Fetches a merchant account via the admin API key, for reading fields
+// (e.g. publishable_key) that aren't captured anywhere else when the
+// merchant was created via the dashboard signup flow rather than
+// merchantCreateCallTest. Used by cypress/e2e/spec/Security/OMPScoping/.
+Cypress.Commands.add("ompGetMerchantAccount", (merchantId, globalState) => {
+ const adminApiKey = globalState.get("adminApiKey");
+ const baseUrl = globalState.get("baseUrl");
+
+ return cy.request({
+ method: "GET",
+ url: `${baseUrl}/accounts/${merchantId}`,
+ // V2AdminApiAuth parses the admin key from Authorization in the exact
+ // form "admin-api-key=<key>" (services/authentication.rs:1748-1755) - a
+ // plain api-key header returns 401, confirmed live. Same scheme as
+ // ompCreateThrowawayApiKey/ompRevokeApiKey above.
+ headers: { Authorization: `admin-api-key=${adminApiKey}` },
+ failOnStatusCode: false,
+ });
+});
+
+// Shared by every OMP endpoint command below - consolidates the
+// repeated "read baseUrl, build the full URL, call cy.ompRequest" pattern
+// into one place instead of duplicating it per command, per review
+// feedback. Each command stays a separately named, purpose-built function
+// (per the earlier "define cy.request in commands.js" feedback); only the
+// boilerplate inside each one is shared now.
+function ompCall(method, path, auth, body, globalState) {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({ method, url: `${baseUrl}${path}`, auth, body });
+}
+
+// --- OMP scoping: Payments (cypress/e2e/spec/Security/OMPScoping/01-Payments.cy.js) ---
+
+Cypress.Commands.add(
+ "ompRetrievePayment",
+ (paymentId, auth, globalState, options = {}) => {
+ const expand = options.expandAttempts ? "&expand_attempts=true" : "";
+ return ompCall(
+ "GET",
+ `/payments/${paymentId}?force_sync=true${expand}`,
+ auth,
+ undefined,
+ globalState
+ );
+ }
+);
+
+Cypress.Commands.add("ompUpdatePayment", (paymentId, auth, body, globalState) =>
+ ompCall("POST", `/payments/${paymentId}`, auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompConfirmPayment",
+ (paymentId, auth, body, globalState) =>
+ ompCall("POST", `/payments/${paymentId}/confirm`, auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompCapturePayment",
+ (paymentId, auth, body, globalState) =>
+ ompCall("POST", `/payments/${paymentId}/capture`, auth, body, globalState)
+);
+
+Cypress.Commands.add("ompCancelPayment", (paymentId, auth, body, globalState) =>
+ ompCall("POST", `/payments/${paymentId}/cancel`, auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompIncrementalAuthorization",
+ (paymentId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/payments/${paymentId}/incremental_authorization`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompExtendAuthorization", (paymentId, auth, globalState) =>
+ ompCall(
+ "POST",
+ `/payments/${paymentId}/extend_authorization`,
+ auth,
+ {},
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompCreatePaymentSessionTokens",
+ (auth, body, globalState) =>
+ ompCall("POST", "/payments/session_tokens", auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompCompletePaymentAuthorize",
+ (paymentId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/payments/${paymentId}/complete_authorize`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+// --- OMP scoping: Payouts (cypress/e2e/spec/Security/OMPScoping/02-Payouts.cy.js) ---
+
+Cypress.Commands.add("ompRetrievePayout", (payoutId, auth, globalState) =>
+ ompCall("GET", `/payouts/${payoutId}`, auth, undefined, globalState)
+);
+
+Cypress.Commands.add("ompUpdatePayout", (payoutId, auth, body, globalState) =>
+ ompCall("PUT", `/payouts/${payoutId}`, auth, body, globalState)
+);
+
+Cypress.Commands.add("ompConfirmPayout", (payoutId, auth, body, globalState) =>
+ ompCall("POST", `/payouts/${payoutId}/confirm`, auth, body, globalState)
+);
+
+Cypress.Commands.add("ompCancelPayout", (payoutId, auth, body, globalState) =>
+ ompCall("POST", `/payouts/${payoutId}/cancel`, auth, body, globalState)
+);
+
+Cypress.Commands.add("ompFulfillPayout", (payoutId, auth, body, globalState) =>
+ ompCall("POST", `/payouts/${payoutId}/fulfill`, auth, body, globalState)
+);
+
+// --- OMP scoping: Profile Acquirer (cypress/e2e/spec/Security/OMPScoping/03-ProfileAcquirer.cy.js) ---
+
+Cypress.Commands.add("ompCreateProfileAcquirer", (auth, body, globalState) =>
+ ompCall("POST", "/profile_acquirer", auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompUpdateProfileAcquirer",
+ (profileId, acquirerId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/profile_acquirer/${profileId}/${acquirerId}`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+// --- OMP scoping: Authentication (cypress/e2e/spec/Security/OMPScoping/04-Authentication.cy.js) ---
+
+Cypress.Commands.add("ompCreateAuthentication", (auth, body, globalState) =>
+ ompCall("POST", "/authentication", auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompAuthenticationEligibility",
+ (authenticationId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/authentication/${authenticationId}/eligibility`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompAuthenticationSync",
+ (merchantId, authenticationId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/authentication/${merchantId}/${authenticationId}/sync`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+// --- OMP scoping: Disputes (cypress/e2e/spec/Security/OMPScoping/05-Disputes.cy.js) ---
+
+Cypress.Commands.add("ompListDisputes", (auth, globalState) =>
+ ompCall("GET", "/disputes/list", auth, undefined, globalState)
+);
+
+Cypress.Commands.add("ompRetrieveDispute", (disputeId, auth, globalState) =>
+ ompCall("GET", `/disputes/${disputeId}`, auth, undefined, globalState)
+);
+
+Cypress.Commands.add(
+ "ompDeleteDisputeEvidence",
+ (disputeId, auth, globalState) =>
+ ompCall(
+ "DELETE",
+ "/disputes/evidence",
+ auth,
+ { dispute_id: disputeId },
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompFetchDisputesFromConnector",
+ (connectorId, auth, globalState, fetchWindow = {}) => {
+ // fetch_from/fetch_till are REQUIRED query params
+ // (crates/router/src/types/api/disputes.rs:16-18, format
+ // YYYY-MM-DDTHH:MM:SS) and are deserialized before auth even runs -
+ // omitting them returns 400 "missing field `fetch_from`" regardless of
+ // credentials or profile, which would make every test using this
+ // command pass for the wrong reason (confirmed live). Default window is
+ // the last 24 hours so every call reaches the real profile check.
+ const toQueryFormat = (date) => date.toISOString().slice(0, 19);
+ const now = new Date();
+ const fetchTill = fetchWindow.fetchTill || toQueryFormat(now);
+ const fetchFrom =
+ fetchWindow.fetchFrom ||
+ toQueryFormat(new Date(now.getTime() - 24 * 60 * 60 * 1000));
+
+ return ompCall(
+ "GET",
+ `/disputes/${connectorId}/fetch?fetch_from=${fetchFrom}&fetch_till=${fetchTill}`,
+ auth,
+ undefined,
+ globalState
+ );
+ }
+);
+
+// --- OMP scoping: Connector Onboarding + MCA retrieve
+// (cypress/e2e/spec/Security/OMPScoping/06-ConnectorOnboarding.cy.js) ---
+
+Cypress.Commands.add("ompRetrieveMca", (merchantId, mcaId, auth, globalState) =>
+ ompCall(
+ "GET",
+ `/account/${merchantId}/connectors/${mcaId}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompConnectorOnboardingSync", (auth, body, globalState) =>
+ ompCall("POST", "/connector_onboarding/sync", auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompConnectorOnboardingActionUrl",
+ (auth, body, globalState) =>
+ ompCall("POST", "/connector_onboarding/action_url", auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompConnectorOnboardingResetTrackingId",
+ (auth, body, globalState) =>
+ ompCall(
+ "POST",
+ "/connector_onboarding/reset_tracking_id",
+ auth,
+ body,
+ globalState
+ )
+);
+
+// --- OMP scoping: Apple Pay (cypress/e2e/spec/Security/OMPScoping/07-ApplePay.cy.js) ---
+
+Cypress.Commands.add(
+ "ompVerifyApplePay",
+ (merchantId, auth, body, globalState) =>
+ ompCall("POST", `/verify/apple_pay/${merchantId}`, auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompGetApplePayVerifiedDomains",
+ (merchantId, mcaId, auth, globalState) =>
+ ompCall(
+ "GET",
+ `/verify/applepay_verified_domains?merchant_id=${merchantId}&merchant_connector_account_id=${mcaId}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+// --- OMP scoping: Business Profile (cypress/e2e/spec/Security/OMPScoping/08-BusinessProfile.cy.js) ---
+
+Cypress.Commands.add(
+ "ompRetrieveBusinessProfile",
+ (accountId, profileId, auth, globalState) =>
+ ompCall(
+ "GET",
+ `/account/${accountId}/business_profile/${profileId}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompUpdateBusinessProfile",
+ (accountId, profileId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/account/${accountId}/business_profile/${profileId}`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompToggleConnectorAgnosticMit",
+ (accountId, profileId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/account/${accountId}/business_profile/${profileId}/toggle_connector_agnostic_mit`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+// --- OMP scoping: Blocklist (cypress/e2e/spec/Security/OMPScoping/09-Blocklist.cy.js) ---
+
+Cypress.Commands.add("ompGetBlocklist", (auth, queryString, globalState) =>
+ ompCall("GET", `/blocklist${queryString}`, auth, undefined, globalState)
+);
+
+Cypress.Commands.add("ompCreateBlocklistEntry", (auth, body, globalState) =>
+ ompCall("POST", "/blocklist", auth, body, globalState)
+);
+
+Cypress.Commands.add("ompDeleteBlocklistEntry", (auth, body, globalState) =>
+ ompCall("DELETE", "/blocklist", auth, body, globalState)
+);
+
+Cypress.Commands.add("ompLookupBlocklist", (auth, data, globalState) =>
+ ompCall(
+ "GET",
+ `/blocklist/lookup?data=${encodeURIComponent(data)}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
diff --git a/cypress-tests/package.json b/cypress-tests/package.json
index 577e4c617f..e4476b0ed5 100644
--- a/cypress-tests/package.json
+++ b/cypress-tests/package.json
@@ -15,6 +15,7 @@
"cypress:payouts": "cypress run --headless --spec 'cypress/e2e/spec/Payout/**/*'",
"cypress:platform": "cypress run --headless --spec 'cypress/e2e/spec/Platform/**/*'",
"cypress:routing": "cypress run --headless --spec 'cypress/e2e/spec/Routing/**/*'",
+ "cypress:security": "cypress run --headless --spec 'cypress/e2e/spec/Security/**/*'",
"cypress:specs": "node scripts/run-cypress.js",
"report:generate": "node scripts/report-generator.js",
"report:open": "open dashboard/index.html || start dashboard/index.html || xdg-open dashboard/index.html",