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): OMP scoping coverage (#15170)

Gnanasundari247e28e7bd8f64
diff --git a/cypress-tests/cypress/e2e/configs/Security/Commons.js b/cypress-tests/cypress/e2e/configs/Security/Commons.js
index 7f4dda42db..16d0802f38 100644
--- a/cypress-tests/cypress/e2e/configs/Security/Commons.js
+++ b/cypress-tests/cypress/e2e/configs/Security/Commons.js
@@ -78,16 +78,38 @@ export function acquirerBody(profileId, overrides = {}) {
// 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: {
+ // The generic validate_profile_id_from_auth_layer check
+ // (core/utils.rs:2967-2990) - MCA retrieve/update (22-MCA.cy.js) go
+ // through this regardless of whether the mismatched profile came from a
+ // JWT or an API key's X-Profile-Id header; same status/code/message
+ // either way. Confirmed live (MCA). NOT used by Business Profile's
+ // update route, despite looking like it should by analogy -
+ // JWTAuthMerchantAndProfileFromRoute funnels its profile mismatch
+ // through the auth-layer IR_17 rejection instead (see
+ // JWT_MERCHANT_MISMATCH below) - confirmed live, correcting an earlier
+ // wrong assumption here. Don't assume this applies to a new
+ // resource without confirming first.
+ PROFILE_ID_AUTH_MISMATCH: {
status: 400,
code: "IR_16",
message:
"Profile id authentication failed. Please use the correct JWT token",
},
+ // The JWTAuthMerchantFromRoute-family auth-layer rejection
+ // (services/authentication.rs:4553-4554,
+ // hyperswitch_domain_models/src/errors/api_error_response.rs:632) - a
+ // JWT whose own merchant_id (or, for JWTAuthMerchantAndProfileFromRoute,
+ // profile_id) differs from the path value. Same status/code/message for
+ // either field; confirmed live on Business Profile's update route
+ // (profile_id mismatch, 08-BusinessProfile.cy.js). Source-confirmed only
+ // (not yet live) for API Keys (23-ApiKeys.cy.js) and Merchant Account
+ // (24-MerchantAccount.cy.js), both plain JWTAuthMerchantFromRoute
+ // (merchant_id mismatch) - verify on first run.
+ JWT_MERCHANT_MISMATCH: {
+ status: 401,
+ code: "IR_17",
+ message: "Access forbidden, invalid JWT token was used",
+ },
// 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.
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
index ce1ad91533..10d8c90d34 100644
--- a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/00-Setup.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/00-Setup.cy.js
@@ -25,6 +25,60 @@ import { PaymentIntent, CardPayout } from "../../../configs/Security/Commons";
// merchant, this can be simplified to create M1 up front instead.
let globalState;
+// Completes the invited-user login chain for a temp-password invite
+// response: signin -> terminate 2FA (lands on force_set_password, since a
+// temp password always has last_password_modified_at=None, user.rs:
+// 1227-1247) -> rotate_password (no token returned) -> signin again with
+// the new password -> terminate 2FA again (lands on user_info this time).
+// Stores the final usable session JWT as globalState "jwtMerchantAdminM1".
+// Only ever called when invite_multiple actually returned a password - see
+// the GAP comment at its call site in 00-Setup.cy.js.
+function completeInvitedUserLogin(email, tempPassword, globalState) {
+ // Generated per-run, not a static literal - a hardcoded password-shaped
+ // string here trips generic secret scanners (confirmed: GitGuardian
+ // flagged a prior literal version of this on push) even though it's a
+ // throwaway value this test sets itself via rotate_password for a
+ // randomly-emailed test user, never a real credential.
+ const newPassword = `OmpScoping_${Date.now()}_Aa1!`;
+ const tokens = {};
+
+ cy.ompUserSignin(email, tempPassword, globalState).then((res) => {
+ expect(res.status, "signin with temp password").to.eq(200);
+ expect(res.body?.token_type).to.eq("totp");
+ tokens.totp1 = res.body.token;
+ });
+
+ cy.then(() => cy.ompTerminate2FaRaw(tokens.totp1, globalState)).then(
+ (res) => {
+ expect(res.status, "terminate 2FA (first pass)").to.eq(200);
+ expect(res.body?.token_type).to.eq("force_set_password");
+ tokens.forceSetPw = res.body.token;
+ }
+ );
+
+ cy.then(() =>
+ cy.ompRotatePassword(tokens.forceSetPw, newPassword, globalState)
+ ).then((res) => {
+ expect(res.status, "rotate password").to.eq(200);
+ });
+
+ cy.then(() => cy.ompUserSignin(email, newPassword, globalState)).then(
+ (res) => {
+ expect(res.status, "signin with rotated password").to.eq(200);
+ expect(res.body?.token_type).to.eq("totp");
+ tokens.totp2 = res.body.token;
+ }
+ );
+
+ return cy
+ .then(() => cy.ompTerminate2FaRaw(tokens.totp2, globalState))
+ .then((res) => {
+ expect(res.status, "terminate 2FA (second pass)").to.eq(200);
+ expect(res.body?.token_type).to.eq("user_info");
+ globalState.set("jwtMerchantAdminM1", res.body.token);
+ });
+}
+
describe("OMP Scoping - shared fixtures", () => {
before("seed global state", () => {
cy.task("getGlobalState").then((state) => {
@@ -400,6 +454,265 @@ describe("OMP Scoping - shared fixtures", () => {
"will list disputes per profile at runtime and skip cases if none exist."
);
});
+
+ it("creates CUSTOMER_M1 under M1", () => {
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ });
+
+ // createCustomerCallTest sets globalState "customerId" - independent
+ // of the payout block's own customer (that one is gated on
+ // payoutsExecution and may not run), so this gets its own customer
+ // regardless of payout connector availability.
+ cy.createCustomerCallTest(fixtures.customerCreateBody, globalState);
+
+ cy.then(() => {
+ globalState.set("customerIdM1", globalState.get("customerId"));
+ });
+ });
+
+ it("creates PAYMENT_METHOD_M1 attached to CUSTOMER_M1", () => {
+ cy.then(() => {
+ globalState.set("customerId", globalState.get("customerIdM1"));
+ });
+
+ // Reuses the shared card_pm "PaymentMethod" fixture
+ // (configs/Payment/Commons.js, same one 24-PaymentMethods.cy.js
+ // uses) rather than hand-rolling card details, per review feedback.
+ cy.createPaymentMethodTest(
+ globalState,
+ getConnectorDetails("commons")["card_pm"]["PaymentMethod"]
+ );
+
+ cy.then(() => {
+ globalState.set(
+ "paymentMethodIdM1",
+ globalState.get("paymentMethodId")
+ );
+ });
+ });
+
+ it("creates a captured CIT payment under PA (also yields MANDATE_PA)", () => {
+ // Reuses the existing citForMandatesCallTest infrastructure
+ // (cypress/support/commands.js, same command the Mandate spec uses)
+ // rather than hand-building confirm/capture logic - this is the only
+ // way to get an actually-captured payment (for Refund) and a real
+ // mandate_id (for Mandate) without re-deriving per-connector card
+ // behavior from scratch. Needs globalState "merchantConnectorId"
+ // (the default key citForMandatesCallTest's profile/connector
+ // resolution reads), distinct from our own "mcaPaId" naming.
+ // Depends on the configured connector having a
+ // MandateSingleUseNo3DSAutoCapture fixture in configs/Payment/ - if
+ // it doesn't, this step (and anything downstream that needs
+ // capturedPaymentIdPA/mandateIdPA) needs live verification.
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ globalState.set("profileId", globalState.get("profileIdPA"));
+ globalState.set("merchantConnectorId", globalState.get("mcaPaId"));
+ });
+
+ const data = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["MandateSingleUseNo3DSAutoCapture"];
+
+ cy.citForMandatesCallTest(
+ fixtures.citConfirmBody,
+ data,
+ true,
+ "automatic",
+ "new_mandate",
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("capturedPaymentIdPA", globalState.get("paymentID"));
+ globalState.set("mandateIdPA", globalState.get("mandateId"));
+ });
+ });
+
+ it("creates REFUND_PA against the captured CIT payment", () => {
+ // refundCallTest reads payment_id from globalState "paymentID", still
+ // set to capturedPaymentIdPA from the step above.
+ const refundData = getConnectorDetails(globalState.get("connectorId"))[
+ "card_pm"
+ ]["Refund"];
+
+ cy.refundCallTest(fixtures.refundBody, refundData, globalState);
+
+ cy.then(() => {
+ globalState.set("refundIdPA", globalState.get("refundId"));
+ });
+ });
+
+ it("creates ROUTING_CONFIG_PA under PA and activates it", () => {
+ cy.then(() => {
+ globalState.set("profileId", globalState.get("profileIdPA"));
+ });
+
+ const routing_data = [
+ {
+ connector: globalState.get("connectorId"),
+ merchant_connector_id: globalState.get("mcaPaId"),
+ },
+ ];
+
+ cy.addRoutingConfig(
+ fixtures.routingConfigBody,
+ { Request: {}, Response: { status: 200, body: {} } },
+ "priority",
+ routing_data,
+ globalState
+ );
+
+ cy.activateRoutingConfig(
+ { Request: {}, Response: { status: 200, body: {} } },
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set(
+ "routingConfigIdPA",
+ globalState.get("routingConfigId")
+ );
+ });
+ });
+
+ it("upserts SURCHARGE_CONFIG_M1 for M1", () => {
+ // Reuses the existing createSurchargeDSLConfig command (Routing/00005-
+ // SurchargeDSLConfiguration.cy.js) rather than a bespoke request -
+ // it already knows this route needs JWT auth (reads
+ // globalState.get("userInfoToken") directly, falling back to api-key
+ // only if that's unset) and needs a full algorithm, not just
+ // merchant_surcharge_configs (confirmed live: omitting it returns
+ // IR_04 "Missing required param: algorithm").
+ const surchargeBody = {
+ name: "omp_scoping_surcharge_config",
+ merchant_surcharge_configs: {},
+ algorithm: {
+ defaultSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 2.5 } },
+ },
+ },
+ rules: [],
+ metadata: {},
+ },
+ };
+
+ cy.createSurchargeDSLConfig(
+ surchargeBody,
+ { Response: { body: {} } },
+ globalState
+ );
+ });
+
+ // DROPPED: a NULL profile_id can't actually be produced through the
+ // public API - connector creation always resolves a profile at
+ // creation time, either explicitly via profile_id or via a legacy
+ // business_country/business_label fallback (confirmed: omitting
+ // profile_id returns IR_04 "Missing required param: profile_id or
+ // business_country, business_label"). The nullable-profile_id
+ // fail-closed behavior (validate_profile_id_from_auth_layer) was
+ // already confirmed by reading its source; there's no reachable
+ // precondition to test it against here.
+
+ it("creates PAYMENT_LINK_PA (a payment with payment_link enabled)", () => {
+ cy.then(() => {
+ globalState.set("merchantId", globalState.get("merchantIdM1"));
+ globalState.set("apiKey", globalState.get("apiKeyM1"));
+ globalState.set("profileId", globalState.get("profileIdPA"));
+ globalState.set("customerId", globalState.get("customerIdM1"));
+ });
+
+ cy.createPaymentIntentWithPaymentLinkTest(
+ fixtures.createPaymentBody,
+ { Request: { currency: "USD" }, Response: { status: 200 } },
+ "no_three_ds",
+ "automatic",
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("paymentLinkPaymentId", globalState.get("paymentID"));
+ });
+ });
+
+ it("creates PAYOUT_LINK_PA", () => {
+ // This repo's Cypress config restricts Payout Link to "wise"
+ // (CONNECTOR_LISTS.INCLUDE.PAYOUT_LINK, configs/Payout/Utils.js), but
+ // that's not an actual backend restriction - core/payout_link.rs
+ // builds its connector list dynamically from whichever
+ // payout_processor MCAs are enabled and support the requested payout
+ // method, not a fixed allowlist. config/development.toml's
+ // [payout_method_filters.adyenplatform] explicitly supports
+ // credit/debit card payouts for EUR/USD/GBP/CAD/JPY across many
+ // countries - exactly the card/EUR combination this suite's own
+ // CardPayout() fixture already uses for PO_PA/PO_PB. adyenplatform is
+ // hardcoded as this suite's payout connector regardless of
+ // CYPRESS_CONNECTOR (see the payout_processor MCA step above), so
+ // just attempt it directly rather than gating on a wise-only check
+ // that - by the time this step runs - was comparing against the
+ // restored Payments connectorId anyway, not the payout one, making
+ // the old gate unconditionally true (PAYOUT_LINK_PA never created,
+ // regardless of CYPRESS_CONNECTOR). If adyenplatform genuinely
+ // doesn't support it, let this fail honestly rather than silently
+ // skip - that's real, actionable information.
+ //
+ // Must use fixtures.createPayoutLinkBody, not the generic
+ // fixtures.createPayoutBody - the dedicated fixture sets
+ // payout_link: true and confirm: false (the payout method is
+ // deferred to the customer filling in the hosted link, not supplied
+ // upfront). Using the generic body (confirmed live) omits
+ // payout_link entirely, so the server tries normal eligible-connector
+ // routing with no payout_type/payout_method_data at all and fails
+ // with IR_39 "No eligible connector was found" - a test-fixture bug,
+ // not a real adyenplatform capability gap.
+ //
+ // Also needs payout_link_config set on PA's business profile first -
+ // confirmed live in two steps: (1) 400 IR_40 "Payout links cannot be
+ // used without setting allowed_domains in profile... set test_mode
+ // to true..." without it, then (2) a plain deserialize error for a
+ // field named "test_mode" - the actual request struct
+ // (BusinessPayoutLinkConfig, api_models/src/admin.rs:3584-3595, via
+ // its flattened BusinessGenericLinkConfig at :3635-3645) names the
+ // boolean field payout_test_mode, not test_mode (the error message's
+ // prose doesn't match the real field name), and allowed_domains
+ // (HashSet<String>, no default) is required regardless of
+ // payout_test_mode - both together, matching this repo's own
+ // Payout/00008-PayoutLinkCreate.cy.js bpWithPayoutLink fixture.
+ globalState.set("payoutLinkExecution", true);
+ cy.then(() => {
+ globalState.set("profileId", globalState.get("profileIdPA"));
+ });
+
+ cy.UpdateBusinessProfileTest(
+ {
+ payout_link_config: {
+ payout_test_mode: true,
+ allowed_domains: ["*.hyperswitch.io"],
+ },
+ },
+ false,
+ false,
+ false,
+ false,
+ false,
+ globalState,
+ "pa"
+ );
+
+ cy.createPayoutWithLinkTest(
+ structuredClone(fixtures.createPayoutLinkBody),
+ { Request: { currency: "EUR" }, Response: { status: 200 } },
+ globalState
+ );
+
+ cy.then(() => {
+ globalState.set("payoutLinkPayoutId", globalState.get("payoutID"));
+ });
+ });
});
context("PC - dedicated profile for incremental/extend authorization", () => {
@@ -519,4 +832,90 @@ describe("OMP Scoping - shared fixtures", () => {
});
});
});
+
+ context(
+ "M3 and a merchant_admin user, for Analytics role-scope tests",
+ () => {
+ // M1's own dashboard user is org_admin (signup_with_merchant_id grants
+ // ROLE_ID_ORGANIZATION_ADMIN, core/user.rs:96-103) and M1 sits in its
+ // own, freshly-created organization - M2 (above) is a SEPARATE org
+ // entirely, so M1-vs-M2 never actually exercised "two merchants under
+ // one org." M3 here is a genuine sibling of M1: created with
+ // organization_id explicitly set to M1's own org, so
+ // CreateOrValidateOrganization validates/reuses that org instead of
+ // minting a new one (core/admin.rs:505-523, 708-719).
+ it("creates M3, a second merchant in M1's own organization", () => {
+ const m1OrganizationId = globalState.get("organizationId");
+ const m3Body = {
+ ...structuredClone(fixtures.merchantCreateBody),
+ organization_id: m1OrganizationId,
+ };
+
+ cy.merchantCreateCallTest(m3Body, globalState, {
+ merchantIdStateKey: "merchantIdM3",
+ profileIdStateKey: "profileIdM3Default",
+ publishableKeyStateKey: "publishableKeyM3",
+ });
+
+ cy.then(() => {
+ // merchantCreateCallTest unconditionally overwrites globalState
+ // "organizationId" with whatever the server echoes back - confirm
+ // it's still M1's org (validated/reused), not a freshly minted one.
+ expect(
+ globalState.get("organizationId"),
+ "M3 must land in M1's existing org, not a fresh one"
+ ).to.eq(m1OrganizationId);
+ });
+ });
+
+ // GAP: bootstrapping a second, merchant_admin-scoped user under M1
+ // would need the real invite flow (POST /user/user/invite_multiple),
+ // but confirmed live: this environment never returns a temp password
+ // in the invite response (is_email_sent-style flow instead - a real
+ // inbox is required to accept the invite), so the no-email-feature
+ // shortcut this was built against (core/user.rs:1080-1249, returns
+ // a password directly when the "email" cargo feature is off) doesn't
+ // apply here. There is no black-box way to complete this invite
+ // without real email access, so this is skipped gracefully rather
+ // than chased further - same convention as the Disputes/Relay
+ // "no fabrication command exists" gaps elsewhere in this file. The
+ // merchant_admin-specific tests in 17-Analytics.cy.js already gate
+ // on jwtMerchantAdminM1 being present and skip themselves when it's
+ // not; the org_admin-vs-sibling tests there don't depend on this
+ // user at all and still run for real.
+ it("invites a merchant_admin user scoped to M1 (best effort - see GAP above)", () => {
+ const inviteEmail = `omp_scoping_merchant_admin_${Date.now()}@example.com`;
+
+ cy.ompInviteUser(
+ { type: "jwt", token: globalState.get("userInfoTokenPA") },
+ [
+ {
+ email: inviteEmail,
+ name: "OMP Scoping Merchant Admin",
+ role_id: "merchant_admin",
+ },
+ ],
+ globalState
+ ).then((res) => {
+ expect(res.status, "invite_multiple call").to.eq(200);
+ const invitee = Array.isArray(res.body) ? res.body[0] : res.body;
+
+ if (!invitee?.password) {
+ cy.task(
+ "cli_log",
+ "Skipping merchant_admin bootstrap: invite_multiple did not " +
+ "return a temp password (this environment requires a real " +
+ "email invite accept, which this suite can't automate). " +
+ "17-Analytics.cy.js's merchant_admin tests will skip."
+ );
+ return;
+ }
+
+ cy.then(() =>
+ completeInvitedUserLogin(inviteEmail, invitee.password, globalState)
+ );
+ });
+ });
+ }
+ );
});
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
index 746b76e389..96671ab5cd 100644
--- a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/02-Payouts.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/02-Payouts.cy.js
@@ -30,6 +30,14 @@ describe("OMP Scoping - Payouts", () => {
payoutIdPA = globalState.get("payoutIdPA");
payoutIdPB = globalState.get("payoutIdPB");
payoutsExecution = globalState.get("payoutsExecution");
+
+ if (!payoutsExecution) {
+ cy.task(
+ "cli_log",
+ "Skipping this suite: no payout_processor credentials in the " +
+ "creds file (see 00-Setup.cy.js)."
+ );
+ }
});
});
@@ -38,13 +46,7 @@ describe("OMP Scoping - Payouts", () => {
});
beforeEach(function () {
- if (!payoutsExecution) {
- cy.task(
- "cli_log",
- "Skipping: no payout_processor credentials in the creds file (see 00-Setup.cy.js)."
- );
- this.skip();
- }
+ if (!payoutsExecution) this.skip();
});
// Ground-truth snapshot, deliberately merchant-wide (no X-Profile-Id) so
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
index 155c89a00f..17d33b9bb7 100644
--- a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/06-ConnectorOnboarding.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/06-ConnectorOnboarding.cy.js
@@ -62,16 +62,15 @@ describe("OMP Scoping - Connector Onboarding", () => {
}
it("sync rejects connector/profile mismatch, MCA_PAYPAL_PB unchanged", () => {
- // Not OMP_ERRORS.JWT_PROFILE_MISMATCH (configs/Security/Commons.js):
+ // Not OMP_ERRORS.PROFILE_ID_AUTH_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.
+ // confirmed on MCA retrieve/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: () =>
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
index 7820eec506..363f837853 100644
--- a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/08-BusinessProfile.cy.js
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/08-BusinessProfile.cy.js
@@ -87,6 +87,13 @@ describe("OMP Scoping - Business Profile", () => {
// 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.
+ // Confirmed live: this comes back as 401 IR_17 "Access forbidden,
+ // invalid JWT token was used" - the SAME auth-layer rejection used for
+ // a merchant_id mismatch (OMP_ERRORS.JWT_MERCHANT_MISMATCH), not the
+ // separate 400 IR_16 validate_profile_id_from_auth_layer check used
+ // elsewhere (Payments/MCA) - JWTAuthMerchantAndProfileFromRoute
+ // apparently funnels both its merchant_id and profile_id comparisons
+ // through one shared rejection path.
cy.ompAssertDeniedAndUnchanged({
fetch: fetchProfilePB(),
negativeRequest: () =>
@@ -99,7 +106,7 @@ describe("OMP Scoping - Business Profile", () => {
),
// Confirmed live - same generic JWT profile-mismatch path as the
// Payments retrieve test, not specific to Business Profile.
- expectedError: OMP_ERRORS.JWT_PROFILE_MISMATCH,
+ expectedError: OMP_ERRORS.JWT_MERCHANT_MISMATCH,
});
});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/11-CustomerPaymentMethodMandate.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/11-CustomerPaymentMethodMandate.cy.js
new file mode 100644
index 0000000000..0b14afd12c
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/11-CustomerPaymentMethodMandate.cy.js
@@ -0,0 +1,219 @@
+import State from "../../../../utils/State";
+import getConnectorDetails from "../../../configs/Payment/Utils";
+
+// Customer, Payment Method, and Mandate are merchant-scoped only - none of
+// their DB tables carry a profile_id column at all, so only the M1-vs-M2
+// (unrelated merchant) isolation model applies here, not PA-vs-PB.
+//
+// Routes (verified): GET/POST/DELETE /customers/{id}, GET/POST/DELETE
+// /payment_methods/{id}, POST /payment_methods, GET /mandates/{id},
+// POST /mandates/revoke/{id} - all ApiKeyAuth or JWTAuth. Customer/Mandate
+// lookups are query-scoped by merchant_id (composite key); Payment Method
+// ownership is a manual per-handler merchant_id comparison rather than a
+// query-level filter (works today, but is a fragile pattern - any future
+// handler that forgets to repeat the check would reopen the gap).
+let globalState;
+let apiKeyM1;
+let apiKeyM2;
+let customerIdM1;
+let paymentMethodIdM1;
+let mandateIdPA;
+
+describe("OMP Scoping - Customer, Payment Method, Mandate", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ apiKeyM2 = globalState.get("apiKeyM2");
+ customerIdM1 = globalState.get("customerIdM1");
+ paymentMethodIdM1 = globalState.get("paymentMethodIdM1");
+ mandateIdPA = globalState.get("mandateIdPA");
+
+ if (!mandateIdPA) {
+ cy.task(
+ "cli_log",
+ "Mandate tests in this suite will skip: no mandateIdPA in " +
+ "globalState - the CIT mandate creation step in " +
+ "00-Setup.cy.js may have failed or the configured connector " +
+ "may not support MandateSingleUseNo3DSAutoCapture."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ context("Customer", () => {
+ it("M2 retrieves M1's customer - denied", () => {
+ cy.ompRetrieveCustomer(
+ customerIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("M2 updates/deletes M1's customer - denied", () => {
+ cy.ompUpdateCustomer(
+ customerIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ { name: "should not be applied" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+
+ cy.ompDeleteCustomer(
+ customerIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("M1 retrieves its own customer (positive)", () => {
+ cy.ompRetrieveCustomer(
+ customerIdM1,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.customer_id).to.eq(customerIdM1);
+ });
+ });
+ });
+
+ context("Payment Method", () => {
+ it("M2 retrieves M1's payment method - denied", () => {
+ // Expected: 404 (clean ownership denial). If this fails with a 500
+ // instead, that's a real defect - the ownership check isn't
+ // preventing a decrypt attempt on M1's payment method data using
+ // M2's merchant key before any response is built. Report it rather
+ // than loosen this assertion to mask it.
+ cy.ompRetrievePaymentMethod(
+ paymentMethodIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("M2 updates/deletes M1's payment method - denied", () => {
+ cy.ompUpdatePaymentMethod(
+ paymentMethodIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ { card: { card_holder_name: "should not be applied" } },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+
+ cy.ompDeletePaymentMethod(
+ paymentMethodIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("M2 creates a payment method against M1's customer_id - denied", () => {
+ // Reuses the shared card_pm "PaymentMethod" fixture's Request
+ // (configs/Payment/Commons.js, same one 24-PaymentMethods.cy.js and
+ // 00-Setup.cy.js's PAYMENT_METHOD_M1 step use) rather than hand-rolling
+ // card details, per review feedback.
+ const { Request: paymentMethodRequest } =
+ getConnectorDetails("commons")["card_pm"]["PaymentMethod"];
+
+ cy.ompCreatePaymentMethod(
+ { type: "apiKey", apiKey: apiKeyM2 },
+ { ...paymentMethodRequest, customer_id: customerIdM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("M1 retrieves its own payment method (positive)", () => {
+ cy.ompRetrievePaymentMethod(
+ paymentMethodIdM1,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.payment_method_id).to.eq(paymentMethodIdM1);
+ });
+ });
+ });
+
+ context("Mandate", () => {
+ beforeEach(function () {
+ if (!mandateIdPA) this.skip();
+ });
+
+ it("M2 retrieves/revokes M1's mandate - denied", () => {
+ cy.ompRetrieveMandate(
+ mandateIdPA,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+
+ cy.ompRevokeMandate(
+ mandateIdPA,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("M1 retrieves its own mandate (positive)", () => {
+ cy.ompRetrieveMandate(
+ mandateIdPA,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+ });
+
+ context("Edge cases", () => {
+ it("retrieving a non-existent customer returns 404", () => {
+ cy.ompRetrieveCustomer(
+ "cus_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("retrieving a non-existent payment method returns 404", () => {
+ cy.ompRetrievePaymentMethod(
+ "pm_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on customer retrieve is rejected", () => {
+ cy.ompRetrieveCustomer(
+ customerIdM1,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/12-Refund.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/12-Refund.cy.js
new file mode 100644
index 0000000000..4b636b106e
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/12-Refund.cy.js
@@ -0,0 +1,125 @@
+import State from "../../../../utils/State";
+
+// Refund has its own profile_id column, independent of the payment_intent
+// it's created against.
+//
+// Routes (verified): GET/POST /refunds/{id}, POST /refunds (create) - all
+// ApiKeyAuth or JWTAuth. Retrieve calls validate_profile_id_from_auth_layer
+// against refund.profile_id directly - clean. Update has NO profile check
+// at all (only merchant-level, via the query filter) - not currently
+// exploitable since the update route has no profile-scoped auth path, but
+// a real asymmetry worth documenting.
+//
+// Create and update both assert the correct, secure behavior (denial) -
+// refund_create_core's authenticated-profile parameter is literally named
+// `_profile_id` (crates/router/src/core/refunds.rs) and refund_update_core
+// has the same gap, so both of these are expected to fail against the
+// current server rather than pass. Leaving them asserting denial (not the
+// current buggy behavior) means they fail honestly and visibly until the
+// missing profile check is added upstream, instead of a green checkmark
+// on incorrect behavior.
+let globalState;
+let apiKeyM1;
+let profileIdPA;
+let profileIdPB;
+let capturedPaymentIdPA;
+let refundIdPA;
+
+describe("OMP Scoping - Refund", () => {
+ 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");
+ capturedPaymentIdPA = globalState.get("capturedPaymentIdPA");
+ refundIdPA = globalState.get("refundIdPA");
+
+ if (!capturedPaymentIdPA || !refundIdPA) {
+ cy.task(
+ "cli_log",
+ "Skipping this suite: no capturedPaymentIdPA/refundIdPA in " +
+ "globalState - the CIT payment + refund creation steps in " +
+ "00-Setup.cy.js may have failed or the configured connector " +
+ "may not support the required fixture scenarios."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ beforeEach(function () {
+ if (!capturedPaymentIdPA || !refundIdPA) {
+ this.skip();
+ }
+ });
+
+ context("Retrieve", () => {
+ it("PA retrieves PB's refund - denied", () => {
+ cy.ompRetrieveRefund(
+ refundIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("PA retrieves its own refund (positive)", () => {
+ cy.ompRetrieveRefund(
+ refundIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.refund_id).to.eq(refundIdPA);
+ });
+ });
+
+ it("retrieving a non-existent refund_id returns 404", () => {
+ cy.ompRetrieveRefund(
+ "ref_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on refund retrieve is rejected", () => {
+ cy.ompRetrieveRefund(refundIdPA, { type: "invalid" }, globalState).then(
+ (res) => {
+ expect(res.status).to.eq(401);
+ }
+ );
+ });
+ });
+
+ context("Update", () => {
+ it("PA updates PB's refund - denied", () => {
+ cy.ompUpdateRefund(
+ refundIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ { metadata: { attempted_by: "PB" } },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+ });
+
+ context("Create", () => {
+ it("create a refund in PB for a payment that exists in PA - denied", () => {
+ cy.ompCreateRefund(
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ { payment_id: capturedPaymentIdPA, reason: "omp_scoping_poc" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/14-Routing.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/14-Routing.cy.js
new file mode 100644
index 0000000000..59fecff341
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/14-Routing.cy.js
@@ -0,0 +1,97 @@
+import State from "../../../../utils/State";
+
+// Routing algorithms are profile-scoped. retrieve/link/unlink/activate all
+// resolve the owning business profile and call
+// validate_profile_id_from_auth_layer explicitly before acting - including
+// when the routing config references another profile's MCA (the MCA's own
+// profile is resolved and checked, not just the routing record's).
+//
+// Routes (verified): GET /routing/{id}, POST /routing/{id}/activate, POST
+// /routing/deactivate - ApiKeyAuth or JWTAuth.
+let globalState;
+let apiKeyM1;
+let profileIdPA;
+let profileIdPB;
+let routingConfigIdPA;
+
+describe("OMP Scoping - Routing", () => {
+ 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");
+ routingConfigIdPA = globalState.get("routingConfigIdPA");
+
+ if (!routingConfigIdPA) {
+ cy.task(
+ "cli_log",
+ "Skipping this suite: no routingConfigIdPA in globalState - the " +
+ "routing config creation step in 00-Setup.cy.js may have failed."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ beforeEach(function () {
+ if (!routingConfigIdPA) this.skip();
+ });
+
+ it("PB retrieves PA's routing algorithm - denied", () => {
+ cy.ompRetrieveRoutingAlgorithm(
+ routingConfigIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("PB activates PA's routing algorithm - denied", () => {
+ cy.ompActivateRoutingAlgorithm(
+ routingConfigIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ {},
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("PA retrieves its own routing algorithm (positive)", () => {
+ cy.ompRetrieveRoutingAlgorithm(
+ routingConfigIdPA,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.id).to.eq(routingConfigIdPA);
+ });
+ });
+
+ context("Edge cases", () => {
+ it("retrieving a non-existent routing algorithm returns 404", () => {
+ cy.ompRetrieveRoutingAlgorithm(
+ "routing_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on routing retrieve is rejected", () => {
+ cy.ompRetrieveRoutingAlgorithm(
+ routingConfigIdPA,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/15-Surcharge.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/15-Surcharge.cy.js
new file mode 100644
index 0000000000..17895c1a3c
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/15-Surcharge.cy.js
@@ -0,0 +1,91 @@
+import State from "../../../../utils/State";
+
+// Surcharge decision config is a merchant-level resource by design - no
+// profile dimension exists in the API at all. The DB key is derived from
+// the authenticated merchant's own id, so cross-merchant access is
+// structurally impossible, not just checked.
+//
+// Route (verified): GET/PUT/DELETE /routing/decision/surcharge - JWT auth
+// preferred (falling back to api-key only if no JWT is present), matching
+// the existing createSurchargeDSLConfig/retrieveSurchargeDSLConfig
+// commands.
+let globalState;
+let apiKeyM2;
+let jwtPA;
+
+describe("OMP Scoping - Surcharge Config", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM2 = globalState.get("apiKeyM2");
+ jwtPA = globalState.get("userInfoTokenPA");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("M2 reads M1's surcharge config - never returns M1's config", () => {
+ cy.ompGetSurchargeConfig(
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ // The surcharge config key is derived from the authenticated
+ // merchant's own id, so M2 can only ever reach its own (likely
+ // nonexistent) config - never M1's "omp_scoping_surcharge_config".
+ if (res.status === 200) {
+ expect(res.body.name).to.not.eq("omp_scoping_surcharge_config");
+ } else {
+ expect(res.status).to.be.within(400, 499);
+ }
+ });
+ });
+
+ it("M2 writes to M1's surcharge config - cannot target M1's key at all", () => {
+ cy.ompPutSurchargeConfig(
+ { type: "apiKey", apiKey: apiKeyM2 },
+ {
+ name: "attempted_cross_merchant_overwrite",
+ merchant_surcharge_configs: {},
+ algorithm: {
+ defaultSelection: {
+ surcharge_details: {
+ surcharge: { type: "rate", value: { percentage: 99 } },
+ },
+ },
+ rules: [],
+ metadata: {},
+ },
+ },
+ globalState
+ ).then((writeRes) => {
+ if (writeRes.status === 200) {
+ // Even if M2's own write succeeds, it must only ever have written
+ // M2's own key - confirm M1's config is untouched.
+ cy.ompGetSurchargeConfig(
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.name).to.eq("omp_scoping_surcharge_config");
+ });
+ }
+ });
+ });
+
+ it("M1 reads its own surcharge config (positive)", () => {
+ cy.ompGetSurchargeConfig({ type: "jwt", token: jwtPA }, globalState).then(
+ (res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.name).to.eq("omp_scoping_surcharge_config");
+ }
+ );
+ });
+
+ it("invalid credential on surcharge read is rejected", () => {
+ cy.ompGetSurchargeConfig({ type: "invalid" }, globalState).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/17-Analytics.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/17-Analytics.cy.js
new file mode 100644
index 0000000000..a9f9d5a4b0
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/17-Analytics.cy.js
@@ -0,0 +1,230 @@
+import State from "../../../../utils/State";
+
+// Analytics handlers build a server-derived AuthInfo (Org/Merchant/Profile
+// level) strictly from the authenticated JWT, and that AuthInfo - never a
+// client-supplied merchant_id/profile_id in the request body - is what's
+// threaded into the actual query builders. Some handlers additionally call
+// validate_analytics_scope() to explicitly reject a body whose filters
+// disagree with the authenticated identity.
+//
+// CAVEAT: only the payments metric query builder was directly re-verified
+// during the audit; refund/dispute/sdk_event/connector_event metric
+// builders in crates/analytics/ were not individually re-checked.
+//
+// Route (verified): POST /analytics/v1/metrics/payments - JWTAuth or
+// PlatformOrgAdminAuth. The handler (get_merchant_payment_metrics,
+// crates/router/src/analytics.rs) deserializes a 1-element array
+// ([GetPaymentMetricRequest; 1]), and that request type is camelCase at
+// the top level (timeRange/groupByNames) while its nested filters stay
+// snake_case - see ompQueryPaymentMetrics in commands.js, which handles
+// the array wrapping so tests here just pass the plain request object.
+let globalState;
+let jwtPA;
+let merchantIdM1;
+let merchantIdM2;
+let merchantIdM3;
+let jwtMerchantAdminM1;
+
+function metricsRequest(filters) {
+ return {
+ timeRange: {
+ start_time: "2020-01-01T00:00:00Z",
+ end_time: "2030-01-01T00:00:00Z",
+ },
+ groupByNames: [],
+ filters,
+ metrics: ["payment_success_count"],
+ distribution: null,
+ delta: false,
+ };
+}
+
+describe("OMP Scoping - Analytics", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ jwtPA = globalState.get("userInfoTokenPA");
+ merchantIdM1 = globalState.get("merchantIdM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ merchantIdM3 = globalState.get("merchantIdM3");
+ jwtMerchantAdminM1 = globalState.get("jwtMerchantAdminM1");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("M1 queries payments metrics with M2's merchant_id spoofed into the filter body", () => {
+ // M1's dashboard user is org_admin (signup_with_merchant_id grants
+ // ROLE_ID_ORGANIZATION_ADMIN, core/user.rs:96-103) - but org_admin
+ // doesn't mean "sees every merchant everywhere": M1 and M2 are each
+ // created in their OWN brand-new organization (00-Setup.cy.js's M1
+ // signup and M2's merchantCreateCallTest both resolve org_id via
+ // CreateOrValidateOrganization::new(None, ...), admin.rs:506-523 -
+ // neither passes an existing organization_id, so each gets a fresh
+ // org). They were never siblings under one org to begin with.
+ //
+ // Even setting that aside, this specific endpoint
+ // (get_merchant_payment_metrics, JWTAuth{MerchantAnalyticsRead})
+ // builds its AuthInfo strictly from the JWT's own merchant_id
+ // (to_merchant_level_auth_info, platform.rs:373-395) and never
+ // expands to other merchants in the org regardless of role -
+ // org-wide access only exists on the separate
+ // get_org_payment_metrics endpoint (OrganizationAnalyticsRead +
+ // PlatformOrgAdminAuth). validate_analytics_scope
+ // (analytics_validator.rs:11-35) rejects any filters.merchant_id
+ // that isn't in that single-merchant list with AccessForbiddenError
+ // (401) - confirmed live. So 401 here is the correct, expected
+ // denial, not a loose "some 4xx" catch-all.
+ cy.ompQueryPaymentMetrics(
+ { type: "jwt", token: jwtPA },
+ metricsRequest({ merchant_id: [merchantIdM2] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+
+ it("M1 queries its own payments metrics (positive)", () => {
+ cy.ompQueryPaymentMetrics(
+ { type: "jwt", token: jwtPA },
+ metricsRequest({ merchant_id: [merchantIdM1] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ context(
+ "org_admin vs merchant_admin scope (M1 and M3, same organization)",
+ () => {
+ // M3 (00-Setup.cy.js) is a genuine sibling of M1 - created with
+ // organization_id explicitly set to M1's own org, unlike M2 above
+ // (which is a wholly separate org). jwtMerchantAdminM1 is a second,
+ // separately-provisioned user with role_id "merchant_admin" (Merchant
+ // entity_type), invited and logged in via the real /user/invite_multiple
+ // + signin flow - not M1's own org_admin session. These are two
+ // independent prerequisites (M3 only needs merchant creation; the
+ // merchant_admin user additionally needs a real email-invite accept
+ // this suite can't automate in every environment), so they're gated
+ // separately below rather than as one combined guard - the org_admin
+ // tests should still run even when the merchant_admin bootstrap
+ // couldn't complete.
+ context("M3 required", () => {
+ before(function () {
+ if (!merchantIdM3) {
+ cy.task(
+ "cli_log",
+ "Skipping: M3 was not provisioned in 00-Setup.cy.js."
+ );
+ }
+ });
+
+ beforeEach(function () {
+ if (!merchantIdM3) this.skip();
+ });
+
+ it("org_admin sees a sibling merchant via the ORG-level endpoint (positive)", () => {
+ // This is the legitimate org-wide access path -
+ // PlatformOrgAdminAuth or JWT(OrganizationAnalyticsRead), AuthInfo
+ // built from to_org_level_auth_info() (analytics.rs:642), not
+ // from the JWT's own merchant_id. An org_admin's JWT querying a
+ // genuinely-same-org sibling here should succeed.
+ cy.ompQueryOrgPaymentMetrics(
+ { type: "jwt", token: jwtPA },
+ metricsRequest({ merchant_id: [merchantIdM3] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("org_admin is still denied on the MERCHANT-level endpoint for a same-org sibling", () => {
+ // The sharper version of the cross-org test above: this time M3
+ // IS a genuine sibling in M1's own org, isolating the variable
+ // the first test couldn't - get_merchant_payment_metrics never
+ // expands to sibling merchants regardless of org_admin role,
+ // confirmed by source (to_merchant_level_auth_info only ever
+ // uses the JWT's own merchant_id). Same org membership doesn't
+ // matter for this specific endpoint; only the endpoint choice
+ // does.
+ cy.ompQueryPaymentMetrics(
+ { type: "jwt", token: jwtPA },
+ metricsRequest({ merchant_id: [merchantIdM3] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("M3 and the merchant_admin user required", () => {
+ before(function () {
+ if (!merchantIdM3 || !jwtMerchantAdminM1) {
+ cy.task(
+ "cli_log",
+ "Skipping: M3 and/or the merchant_admin user were not " +
+ "provisioned in 00-Setup.cy.js (see that file's 'M3 and a " +
+ "merchant_admin user' context for why this might fail - " +
+ "e.g. this environment requires a real email invite accept, " +
+ "which this bootstrap flow doesn't support)."
+ );
+ }
+ });
+
+ beforeEach(function () {
+ if (!merchantIdM3 || !jwtMerchantAdminM1) this.skip();
+ });
+
+ it("merchant_admin queries its own merchant's metrics (positive)", () => {
+ cy.ompQueryPaymentMetrics(
+ { type: "jwt", token: jwtMerchantAdminM1 },
+ metricsRequest({ merchant_id: [merchantIdM1] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("merchant_admin is denied on a same-org sibling merchant's metrics", () => {
+ cy.ompQueryPaymentMetrics(
+ { type: "jwt", token: jwtMerchantAdminM1 },
+ metricsRequest({ merchant_id: [merchantIdM3] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+
+ it("merchant_admin is denied on the ORG-level endpoint entirely", () => {
+ // merchant_admin's role has entity_type Merchant, not
+ // Organization - it shouldn't hold OrganizationAnalyticsRead at
+ // all. Asserting a 4xx range rather than an exact code here:
+ // unlike the MerchantAnalyticsRead paths above (confirmed exact
+ // IR via validate_analytics_scope), the exact rejection shape
+ // for a role that fails the permission check itself (rather
+ // than the merchant_id filter check) hasn't been independently
+ // confirmed - tighten this once seen live.
+ cy.ompQueryOrgPaymentMetrics(
+ { type: "jwt", token: jwtMerchantAdminM1 },
+ metricsRequest({ merchant_id: [merchantIdM1] }),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+ });
+ }
+ );
+
+ it("invalid credential on analytics query is rejected", () => {
+ cy.ompQueryPaymentMetrics(
+ { type: "invalid" },
+ metricsRequest({}),
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/18-Relay.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/18-Relay.cy.js
new file mode 100644
index 0000000000..6e84232a1e
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/18-Relay.cy.js
@@ -0,0 +1,124 @@
+import State from "../../../../utils/State";
+
+// CONFIRMED GAP: relay_retrieve (crates/router/src/core/relay.rs) validates
+// that the CALLER's own profile exists, but never compares the fetched
+// relay record's merchant_id/profile_id against the authenticated context
+// - find_relay_by_id queries by id alone. Un-encrypted metadata fields
+// (status, connector_reference_id, error_code/message, timestamps) leak
+// across profiles on the same merchant freely. Cross-merchant leakage of
+// the encrypted request_data/response_data payload is only incidentally
+// blocked by decryption failing with the wrong merchant's key - that's
+// accidental protection, not an actual check. relay_create itself IS
+// correctly profile-scoped (validates via
+// find_business_profile_by_merchant_id_profile_id before creating) - only
+// retrieve has the gap.
+//
+// GAP: this suite has no command that creates a relay record (it's
+// created by connector-initiated webhook relay / out-of-band events, not
+// a direct "create" API meant for this). The tests below look up whatever
+// relay record already exists for M1 at runtime and skip if none found.
+//
+// Route (verified): GET /relay/{relay_id} - ApiKeyAuth.
+let globalState;
+let apiKeyM1;
+let apiKeyM2;
+let profileIdPA;
+let profileIdPB;
+let relayId;
+
+describe("OMP Scoping - Relay", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ apiKeyM2 = globalState.get("apiKeyM2");
+ profileIdPA = globalState.get("profileIdPA");
+ profileIdPB = globalState.get("profileIdPB");
+ relayId = globalState.get("relayIdPA");
+
+ if (!relayId) {
+ cy.task(
+ "cli_log",
+ "Skipping this suite: no relayIdPA in globalState - this suite " +
+ "has no command that creates a relay record, see the GAP " +
+ "comment at the top of this file. Set it manually if testing " +
+ "against an environment with real relay data."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ beforeEach(function () {
+ if (!relayId) this.skip();
+ });
+
+ it("PB retrieves PA's relay record (same merchant) - metadata leaks (confirmed gap)", () => {
+ cy.ompRetrieveRelay(
+ relayId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPB },
+ globalState
+ ).then((res) => {
+ // No assertion of denial here deliberately - the audit found no
+ // merchant/profile check on relay_retrieve at all. This documents
+ // that un-encrypted metadata is returned regardless of profile.
+ expect(
+ res.status,
+ "retrieve succeeds across profiles - no check exists"
+ ).to.eq(200);
+ cy.task(
+ "cli_log",
+ `CONFIRMED GAP: relay ${relayId} metadata (status=${res.body?.status}) ` +
+ "was returned to profile PB even though it belongs to profile PA."
+ );
+ });
+ });
+
+ it("M2 retrieves M1's relay record (cross-merchant) - payload decrypt fails, metadata still returned", () => {
+ cy.ompRetrieveRelay(
+ relayId,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ cy.task(
+ "cli_log",
+ `Cross-merchant relay retrieve returned status ${res.status} - ` +
+ "documenting actual response shape rather than asserting an " +
+ "outcome, since encrypted-field decryption failure may surface " +
+ "as a 200 with null payload fields, a 500, or a 4xx depending " +
+ "on how the decrypt error propagates."
+ );
+ });
+ });
+
+ it("PA retrieves its own relay record (positive)", () => {
+ cy.ompRetrieveRelay(
+ relayId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("retrieving a non-existent relay_id returns 404", () => {
+ cy.ompRetrieveRelay(
+ "relay_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on relay retrieve is rejected", () => {
+ cy.ompRetrieveRelay(relayId, { type: "invalid" }, globalState).then(
+ (res) => {
+ expect(res.status).to.eq(401);
+ }
+ );
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/19-PaymentLink.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/19-PaymentLink.cy.js
new file mode 100644
index 0000000000..65e060462e
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/19-PaymentLink.cy.js
@@ -0,0 +1,86 @@
+import State from "../../../../utils/State";
+
+// Payment Link's API-key-authenticated retrieve (payment_link_retrieve)
+// explicitly checks payment_link_config.processor_merchant_id/merchant_id
+// against the requestor before returning PaymentLinkNotFound otherwise -
+// this is the meaningful cross-merchant check, since it's the one route
+// with an actual bearer credential involved. The path-based
+// initiate/secure/status routes use MerchantIdAuth(merchant_id) (the
+// path's own merchant_id becomes the authenticated identity) plus
+// merchant-scoped core queries - there's no separate credential to test
+// there, only "does the path's merchant_id/payment_id pair resolve," which
+// is covered by Payment Link's own creation/retrieval working correctly.
+//
+// Route (verified): GET /payment_link/{payment_link_id} - ApiKeyAuth.
+let globalState;
+let apiKeyM1;
+let apiKeyM2;
+let paymentLinkId;
+
+describe("OMP Scoping - Payment Link", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ apiKeyM2 = globalState.get("apiKeyM2");
+ paymentLinkId = globalState.get("paymentLinkId");
+
+ if (!paymentLinkId) {
+ cy.task(
+ "cli_log",
+ "Skipping this suite: no paymentLinkId in globalState - the " +
+ "PAYMENT_LINK_PA creation step in 00-Setup.cy.js may have failed."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ beforeEach(function () {
+ if (!paymentLinkId) this.skip();
+ });
+
+ it("M2 retrieves M1's payment link - denied", () => {
+ cy.ompRetrievePaymentLink(
+ paymentLinkId,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("M1 retrieves its own payment link (positive)", () => {
+ cy.ompRetrievePaymentLink(
+ paymentLinkId,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.payment_link_id).to.eq(paymentLinkId);
+ });
+ });
+
+ it("retrieving a non-existent payment_link_id returns 404", () => {
+ cy.ompRetrievePaymentLink(
+ "plink_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on payment link retrieve is rejected", () => {
+ cy.ompRetrievePaymentLink(
+ paymentLinkId,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/20-PayoutLink.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/20-PayoutLink.cy.js
new file mode 100644
index 0000000000..21f3676d3a
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/20-PayoutLink.cy.js
@@ -0,0 +1,88 @@
+import State from "../../../../utils/State";
+
+// render_payout_link uses auth::MerchantIdAuth(merchant_id) - the path's
+// own merchant_id IS the authenticated identity, there's no separate
+// bearer/api-key credential on this public, customer-facing route at all.
+// The core resolves the payout and payout attempt via merchant-scoped
+// queries (find_payout_by_merchant_id_payout_id,
+// find_payout_attempt_by_merchant_id_payout_id_payout_attempt_id) before
+// resolving the payout_link_id from the payout's own record, not from
+// attacker input - so the cross-merchant check here is entirely "does a
+// path merchant_id that doesn't own this payout_id still resolve," which
+// should be denied.
+//
+// This repo's Cypress config lists Payout Link as "wise"-only
+// (CONNECTOR_LISTS.INCLUDE.PAYOUT_LINK, configs/Payout/Utils.js), but
+// that's not an actual backend restriction - see the PAYOUT_LINK_PA step
+// in 00-Setup.cy.js for why adyenplatform (this suite's payout connector)
+// should work too. Still gated on payoutLinkExecution/payoutLinkPayoutId
+// in case it doesn't - if PAYOUT_LINK_PA creation fails there, this whole
+// file skips rather than running against a payout_id that was never
+// created.
+//
+// Route (verified): GET /payout_link/{merchant_id}/{payout_id}.
+let globalState;
+let merchantIdM1;
+let merchantIdM2;
+let payoutLinkPayoutId;
+let payoutLinkExecution;
+
+describe("OMP Scoping - Payout Link", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ merchantIdM1 = globalState.get("merchantIdM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ payoutLinkPayoutId = globalState.get("payoutLinkPayoutId");
+ payoutLinkExecution = globalState.get("payoutLinkExecution");
+
+ if (!payoutLinkExecution || !payoutLinkPayoutId) {
+ cy.task(
+ "cli_log",
+ "Skipping this suite: PAYOUT_LINK_PA was not created in " +
+ "00-Setup.cy.js - check that step's live result."
+ );
+ }
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ beforeEach(function () {
+ if (!payoutLinkExecution || !payoutLinkPayoutId) {
+ this.skip();
+ }
+ });
+
+ it("M2's path merchant_id cannot reach M1's payout_id - denied", () => {
+ cy.ompRetrievePayoutLinkByPath(
+ merchantIdM2,
+ payoutLinkPayoutId,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("M1's path merchant_id reaches its own payout_id (positive)", () => {
+ cy.ompRetrievePayoutLinkByPath(
+ merchantIdM1,
+ payoutLinkPayoutId,
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("a non-existent payout_id under M1's path returns 404", () => {
+ cy.ompRetrievePayoutLinkByPath(
+ merchantIdM1,
+ "payout_nonexistent_omp_test",
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/21-PaymentCrossReference.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/21-PaymentCrossReference.cy.js
new file mode 100644
index 0000000000..8e87dc1e20
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/21-PaymentCrossReference.cy.js
@@ -0,0 +1,76 @@
+import State from "../../../../utils/State";
+
+// Payment creation referencing a customer_id belonging to a different
+// merchant doesn't leak the other merchant's customer - the lookup
+// (create_customer_if_not_exist / get_customer_if_exists in
+// crates/router/src/core/payments/helpers.rs) is scoped by the
+// authenticated merchant_id, so a cross-merchant customer_id either
+// creates an unrelated shadow record with the same id (Standard
+// merchants) or is explicitly rejected with CustomerNotFound (Platform
+// merchants). Extend Authorization reuses the same shared payments_core
+// ownership check already verified for the rest of the Payment resource
+// in Phase 1.
+//
+// Routes (verified): POST /payments (create),
+// POST /payments/{id}/extend_authorization - both ApiKeyAuth/JWTAuth.
+let globalState;
+let apiKeyM1;
+let apiKeyM2;
+let profileIdPA;
+let customerIdM1;
+let paymentIdPB;
+
+describe("OMP Scoping - Payment cross-reference at create time", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ apiKeyM1 = globalState.get("apiKeyM1");
+ apiKeyM2 = globalState.get("apiKeyM2");
+ profileIdPA = globalState.get("profileIdPA");
+ customerIdM1 = globalState.get("customerIdM1");
+ paymentIdPB = globalState.get("paymentIdPB");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ it("M2 creates a payment supplying M1's customer_id - not a leak", () => {
+ cy.ompCreatePayment(
+ { type: "apiKey", apiKey: apiKeyM2 },
+ { amount: 1000, currency: "USD", customer_id: customerIdM1 },
+ globalState
+ ).then((res) => {
+ // Not asserting denial here deliberately - per the audit, M2's
+ // create either (a) creates its own unrelated shadow customer record
+ // with the same id, or (b) is rejected outright, depending on
+ // merchant type. What must NOT happen is M2 ending up linked to
+ // M1's actual customer data.
+ expect(res.status).to.be.oneOf([200, 400]);
+ if (res.status === 200) {
+ cy.ompRetrieveCustomer(
+ customerIdM1,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((m1CustomerRes) => {
+ expect(
+ m1CustomerRes.body.email,
+ "M1's own customer record must be untouched by M2's create"
+ ).to.not.eq(undefined);
+ });
+ }
+ });
+ });
+
+ it("PA extends authorization on PB's payment - denied", () => {
+ cy.ompExtendPaymentAuthorization(
+ paymentIdPB,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ {},
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/22-MCA.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/22-MCA.cy.js
new file mode 100644
index 0000000000..959847406b
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/22-MCA.cy.js
@@ -0,0 +1,347 @@
+import * as fixtures from "../../../../fixtures/imports";
+import State from "../../../../utils/State";
+import { payment_methods_enabled } from "../../../configs/Payment/Commons";
+import { OMP_ERRORS } from "../../../configs/Security/Commons";
+
+// MCA_PA / MCA_PB (00-Setup.cy.js) - the shared stripe MCAs under PA/PB.
+// Never deleted here (other specs in this folder depend on them); a
+// dedicated throwaway MCA is created for the delete positive control.
+//
+// Routes (verified): GET/POST /account/{merchant_id}/connectors/{mca_id}
+// (retrieve/update) both call core_utils::validate_profile_id_from_auth_layer
+// (core/admin.rs:3002, :3114) - same check, same error as every other
+// nullable-profile resource in this suite, regardless of whether the
+// mismatched profile came from a JWT or an API key's X-Profile-Id header.
+// DELETE /account/{merchant_id}/connectors/{mca_id} is AdminApiAuth or
+// JWTAuthMerchantFromRoute(MerchantConnectorWrite) - confirmed
+// profile-agnostic by design (core/admin.rs delete_connector never calls
+// the profile check); its only ownership enforcement is a combined
+// (merchant_id, mca_id) DB lookup, so a mismatched pair 404s rather than
+// deleting the wrong row. GET /account/{merchant_id}/connectors (list) is
+// merchant-wide; GET /account/{account_id}/profile/connectors filters by
+// the authenticated profile when one is present.
+let globalState;
+let apiKeyM1;
+let merchantIdM1;
+let merchantIdM2;
+let profileIdPA;
+let jwtPA;
+let mcaPaId;
+let mcaPbId;
+
+describe("OMP Scoping - MCA", () => {
+ 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);
+ });
+
+ function fetchMca(mcaId) {
+ return () =>
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaId,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ );
+ }
+
+ context("Retrieve", () => {
+ it("retrieve cross-profile MCA_PB denied (API key + X-Profile-Id)", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchMca(mcaPbId),
+ negativeRequest: () =>
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPbId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ),
+ expectedError: OMP_ERRORS.PROFILE_ID_AUTH_MISMATCH,
+ });
+ });
+
+ it("retrieve cross-profile MCA_PB denied (JWT)", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchMca(mcaPbId),
+ negativeRequest: () =>
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPbId,
+ { type: "jwt", token: jwtPA, profileId: profileIdPA },
+ globalState
+ ),
+ expectedError: OMP_ERRORS.PROFILE_ID_AUTH_MISMATCH,
+ });
+ });
+
+ it("retrieve own MCA_PA with matching profile header succeeds (positive)", () => {
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPaId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.merchant_connector_id).to.eq(mcaPaId);
+ });
+ });
+
+ it("retrieve with no profile header succeeds regardless of profile (merchant-wide, positive/compat)", () => {
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPbId,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("retrieving a non-existent MCA returns 404", () => {
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ "mca_nonexistent_omp_test",
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+ });
+
+ it("invalid credential on retrieve is rejected", () => {
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPaId,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("Update", () => {
+ // MerchantConnectorUpdate (api_models/src/admin.rs:1991-1997) has
+ // #[serde(deny_unknown_fields)] and connector_type is its only
+ // non-Option field - omitting it fails deserialization (400 IR_06)
+ // before auth or the profile check ever run, confirmed live. Every
+ // body below includes it for that reason, not because this suite
+ // cares about changing it.
+ it("update cross-profile MCA_PB denied, unchanged", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchMca(mcaPbId),
+ negativeRequest: () =>
+ cy.ompUpdateMca(
+ merchantIdM1,
+ mcaPbId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { connector_type: "payment_processor", disabled: false },
+ globalState
+ ),
+ expectedError: OMP_ERRORS.PROFILE_ID_AUTH_MISMATCH,
+ });
+ });
+
+ it("update own MCA_PA with matching profile header succeeds (positive)", () => {
+ cy.ompUpdateMca(
+ merchantIdM1,
+ mcaPaId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ { connector_type: "payment_processor", disabled: false },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("invalid credential on update is rejected", () => {
+ cy.ompUpdateMca(
+ merchantIdM1,
+ mcaPaId,
+ { type: "invalid" },
+ { connector_type: "payment_processor", disabled: false },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context(
+ "Delete - never touches MCA_PA/MCA_PB, other specs depend on them",
+ () => {
+ it("delete with mismatched merchant_id/mca_id combo 404s rather than deleting the wrong row", () => {
+ // Admin key (merchant-unbound) + M2's path + MCA_PA's real id (which
+ // actually belongs to M1) - confirmed via source that delete_connector
+ // does a single combined (merchant_id, mca_id) lookup with no
+ // separate profile or secondary ownership check, so a mismatched pair
+ // simply doesn't resolve to a row, rather than deleting M1's MCA
+ // because the admin key has global reach.
+ const adminApiKey = globalState.get("adminApiKey");
+
+ cy.ompDeleteMca(
+ merchantIdM2,
+ mcaPaId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(404);
+ });
+
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ mcaPaId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status, "MCA_PA must still exist").to.eq(200);
+ });
+ });
+
+ it("delete via JWT with mismatched merchant_id is rejected before reaching delete_connector", () => {
+ cy.ompDeleteMca(
+ merchantIdM2,
+ mcaPaId,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+ expect(res.body?.error?.code).to.eq(
+ OMP_ERRORS.JWT_MERCHANT_MISMATCH.code
+ );
+ });
+ });
+
+ it("deletes its own throwaway MCA (positive)", () => {
+ // Explicit, unique connector_label - omitting it makes the server
+ // derive one from the business profile's own profile_name
+ // ("{connector}_{profile_name}"), which collides with any MCA
+ // already carrying that exact label (confirmed live: a prior run
+ // whose delete step failed left this label taken, causing the
+ // next run's create to fail with "already exists" - a self-
+ // collision across repeated runs, not a one-off). A unique label
+ // per run avoids that regardless of whether a previous run's
+ // cleanup succeeded.
+ const throwawayConnectorBody = {
+ ...structuredClone(fixtures.createConnectorBody),
+ connector_label: `stripe_omp_mca_throwaway_${Date.now()}`,
+ };
+
+ cy.then(() => {
+ globalState.set("merchantId", merchantIdM1);
+ globalState.set("apiKey", apiKeyM1);
+ globalState.set("paId", profileIdPA);
+ });
+
+ cy.createConnectorCallTest(
+ "payment_processor",
+ throwawayConnectorBody,
+ payment_methods_enabled,
+ globalState,
+ "pa",
+ "mcaThrowaway"
+ );
+
+ cy.then(() => {
+ const adminApiKey = globalState.get("adminApiKey");
+ const throwawayMcaId = globalState.get("mcaThrowawayId");
+
+ cy.ompDeleteMca(
+ merchantIdM1,
+ throwawayMcaId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+
+ // CONFIRMED DEFECT (not a test bug, not caching nuance we
+ // should accommodate): delete_connector does a genuine SQL
+ // DELETE on this row (core/admin.rs delete_connector ->
+ // db.delete_merchant_connector_account_by_merchant_id_merchant_connector_id
+ // -> diesel generic_delete, not a soft-delete/flag flip). But its
+ // cache invalidation redacts a DIFFERENT key
+ // ("{merchant_id}_{profile_id}", storage_impl/src/
+ // merchant_connector_account.rs:1122-1172) than the one retrieve
+ // reads from ("{merchant_id}_{merchant_connector_id}",
+ // same file :582-593) - so GET keeps serving a stale cache hit
+ // for the just-deleted mca_id even though the row is genuinely
+ // gone from the DB. Asserting the correct expected behavior
+ // (404) and letting it fail honestly, per this suite's standing
+ // rule, rather than loosening this to accommodate a cache bug.
+ cy.ompRetrieveMca(
+ merchantIdM1,
+ throwawayMcaId,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status, "deleted MCA must no longer exist").to.eq(404);
+ });
+ });
+ });
+
+ it("invalid credential on delete is rejected", () => {
+ cy.ompDeleteMca(
+ merchantIdM1,
+ mcaPaId,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ }
+ );
+
+ context("List", () => {
+ it("PA lists M1's connectors, sees both MCA_PA and MCA_PB (merchant-wide, positive)", () => {
+ cy.ompListMca(
+ merchantIdM1,
+ { type: "apiKey", apiKey: apiKeyM1 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ const ids = (res.body || []).map((mca) => mca.merchant_connector_id);
+ expect(ids).to.include(mcaPaId);
+ expect(ids).to.include(mcaPbId);
+ });
+ });
+
+ it("M2's key cannot list M1's connectors via path manipulation", () => {
+ const apiKeyM2 = globalState.get("apiKeyM2");
+
+ cy.ompListMca(
+ merchantIdM1,
+ { type: "apiKey", apiKey: apiKeyM2 },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.be.within(400, 499);
+ });
+ });
+
+ it("profile-scoped list filters to PA only, excludes MCA_PB", () => {
+ cy.ompListProfileConnectors(
+ merchantIdM1,
+ { type: "apiKey", apiKey: apiKeyM1, profileId: profileIdPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ const ids = (res.body || []).map((mca) => mca.merchant_connector_id);
+ expect(ids).to.include(mcaPaId);
+ expect(ids).to.not.include(mcaPbId);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/23-ApiKeys.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/23-ApiKeys.cy.js
new file mode 100644
index 0000000000..66d9fa1e9a
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/23-ApiKeys.cy.js
@@ -0,0 +1,267 @@
+import { OMP_ERRORS } from "../../../configs/Security/Commons";
+import State from "../../../../utils/State";
+
+// API Keys have no profile dimension (merchant-wide only) - these tests are
+// cross-MERCHANT isolation only, contrasting with most of this folder's
+// cross-profile focus.
+//
+// Routes (verified): POST /api_keys/{merchant_id} (create),
+// GET /api_keys/{merchant_id}/list, GET/POST/DELETE
+// /api_keys/{merchant_id}/{key_id} (retrieve/update/revoke) - all
+// PlatformOrgAdminAuthWithMerchantIdFromRoute (global admin key, unrestricted
+// by path merchant_id) or JWTAuthMerchantFromRoute(MerchantApiKey{Read,
+// Write}). A JWT's own merchant_id is compared against the path
+// merchant_id BEFORE the permission check even runs
+// (services/authentication.rs:4553-4554) - mismatch is 401 IR_17 "Access
+// forbidden, invalid JWT token was used", not a profile-style 412/400. A
+// plain merchant API key is not an accepted credential on these routes at
+// all (only JWT or the global admin key, or a platform-account merchant's
+// key scoped by org - not applicable to M1/M2 here).
+let globalState;
+let adminApiKey;
+let merchantIdM1;
+let merchantIdM2;
+let jwtPA;
+
+describe("OMP Scoping - API Keys", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ adminApiKey = globalState.get("adminApiKey");
+ merchantIdM1 = globalState.get("merchantIdM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ jwtPA = globalState.get("userInfoTokenPA");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ let throwawayKeyId;
+
+ before(
+ "create a throwaway API key under M1 to exercise retrieve/update/revoke against",
+ () => {
+ cy.ompCreateApiKey(
+ merchantIdM1,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ {
+ name: "omp-scoping-apikeys-throwaway",
+ expiration: "2069-09-23T01:02:03.000Z",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status, "throwaway API key creation must succeed").to.eq(
+ 200
+ );
+ throwawayKeyId = res.body.key_id;
+ });
+ }
+ );
+
+ context("Create", () => {
+ it("JWT with mismatched path merchant_id is rejected before the handler runs", () => {
+ cy.ompCreateApiKey(
+ merchantIdM2,
+ { type: "jwt", token: jwtPA },
+ { name: "should-be-rejected", expiration: "2069-09-23T01:02:03.000Z" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+ expect(res.body?.error?.code).to.eq(
+ OMP_ERRORS.JWT_MERCHANT_MISMATCH.code
+ );
+ expect(res.body?.error?.message).to.eq(
+ OMP_ERRORS.JWT_MERCHANT_MISMATCH.message
+ );
+ });
+ });
+
+ it("JWT scoped to the correct merchant succeeds (positive)", () => {
+ cy.ompCreateApiKey(
+ merchantIdM1,
+ { type: "jwt", token: jwtPA },
+ {
+ name: "omp-scoping-jwt-create",
+ expiration: "2069-09-23T01:02:03.000Z",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("global admin key works for any merchant_id, unrestricted", () => {
+ cy.ompCreateApiKey(
+ merchantIdM2,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ {
+ name: "omp-scoping-admin-create-m2",
+ expiration: "2069-09-23T01:02:03.000Z",
+ },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("invalid credential on create is rejected", () => {
+ cy.ompCreateApiKey(
+ merchantIdM1,
+ { type: "invalid" },
+ { name: "should-be-rejected", expiration: "2069-09-23T01:02:03.000Z" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("Retrieve / update / revoke", () => {
+ it("retrieve with mismatched path merchant_id is rejected", () => {
+ cy.ompRetrieveApiKey(
+ merchantIdM2,
+ throwawayKeyId,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+ expect(res.body?.error?.code).to.eq(
+ OMP_ERRORS.JWT_MERCHANT_MISMATCH.code
+ );
+ });
+ });
+
+ it("retrieve with the correct merchant_id succeeds (positive)", () => {
+ cy.ompRetrieveApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.key_id).to.eq(throwawayKeyId);
+ });
+ });
+
+ it("update with mismatched path merchant_id is rejected, key unchanged", () => {
+ cy.ompRetrieveApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((before) => {
+ cy.ompUpdateApiKey(
+ merchantIdM2,
+ throwawayKeyId,
+ { type: "jwt", token: jwtPA },
+ { name: "should-be-rejected" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+
+ cy.ompRetrieveApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((after) => {
+ expect(after.body.name).to.eq(before.body.name);
+ });
+ });
+ });
+ });
+
+ it("update with the correct merchant_id succeeds (positive)", () => {
+ cy.ompUpdateApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "jwt", token: jwtPA },
+ { name: "omp-scoping-apikeys-throwaway-renamed" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.name).to.eq("omp-scoping-apikeys-throwaway-renamed");
+ });
+ });
+
+ it("revoke with mismatched path merchant_id is rejected, key still active", () => {
+ cy.ompRevokeApiKeyAs(
+ merchantIdM2,
+ throwawayKeyId,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+ });
+
+ cy.ompRetrieveApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((res) => {
+ expect(
+ res.status,
+ "key must still exist after a rejected revoke"
+ ).to.eq(200);
+ });
+ });
+
+ it("revoke with the correct merchant_id succeeds (positive)", () => {
+ cy.ompRevokeApiKeyAs(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+
+ cy.ompRetrieveApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((res) => {
+ expect(res.status, "revoked key must no longer be retrievable").to.eq(
+ 404
+ );
+ });
+ });
+
+ it("invalid credential on retrieve is rejected", () => {
+ cy.ompRetrieveApiKey(
+ merchantIdM1,
+ throwawayKeyId,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("List", () => {
+ it("list with mismatched path merchant_id is rejected", () => {
+ cy.ompListApiKeys(
+ merchantIdM2,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+ });
+ });
+
+ it("list with the correct merchant_id succeeds (positive)", () => {
+ cy.ompListApiKeys(
+ merchantIdM1,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/e2e/spec/Security/OMPScoping/24-MerchantAccount.cy.js b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/24-MerchantAccount.cy.js
new file mode 100644
index 0000000000..fd8995802d
--- /dev/null
+++ b/cypress-tests/cypress/e2e/spec/Security/OMPScoping/24-MerchantAccount.cy.js
@@ -0,0 +1,156 @@
+import { OMP_ERRORS } from "../../../configs/Security/Commons";
+import State from "../../../../utils/State";
+
+// Merchant Account has no profile dimension (merchant-wide only) - these
+// tests are cross-MERCHANT isolation only, same shape as 23-ApiKeys.cy.js.
+//
+// Routes (verified): GET /accounts/{id} (retrieve), POST /accounts/{id}
+// (update) - both PlatformOrgAdminAuthWithMerchantIdFromRoute (global admin
+// key, unrestricted by path id) or JWTAuthMerchantFromRoute. Identical auth
+// struct/check to API Keys above: a JWT's own merchant_id vs the path id
+// is compared before any permission check
+// (services/authentication.rs:4553-4554), mismatch is 401 IR_17. A plain
+// merchant API key is not an accepted credential on these routes.
+let globalState;
+let adminApiKey;
+let merchantIdM1;
+let merchantIdM2;
+let jwtPA;
+
+describe("OMP Scoping - Merchant Account", () => {
+ before("seed global state", () => {
+ cy.task("getGlobalState").then((state) => {
+ globalState = new State(state);
+ adminApiKey = globalState.get("adminApiKey");
+ merchantIdM1 = globalState.get("merchantIdM1");
+ merchantIdM2 = globalState.get("merchantIdM2");
+ jwtPA = globalState.get("userInfoTokenPA");
+ });
+ });
+
+ after("flush global state", () => {
+ cy.task("setGlobalState", globalState.data);
+ });
+
+ function fetchMerchantAccount(merchantId) {
+ return () =>
+ cy.ompRetrieveMerchantAccount(
+ merchantId,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ );
+ }
+
+ context("Retrieve", () => {
+ it("retrieve with mismatched path merchant_id is rejected", () => {
+ cy.ompRetrieveMerchantAccount(
+ merchantIdM2,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(OMP_ERRORS.JWT_MERCHANT_MISMATCH.status);
+ expect(res.body?.error?.code).to.eq(
+ OMP_ERRORS.JWT_MERCHANT_MISMATCH.code
+ );
+ expect(res.body?.error?.message).to.eq(
+ OMP_ERRORS.JWT_MERCHANT_MISMATCH.message
+ );
+ });
+ });
+
+ it("retrieve with the correct merchant_id succeeds (positive)", () => {
+ cy.ompRetrieveMerchantAccount(
+ merchantIdM1,
+ { type: "jwt", token: jwtPA },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ expect(res.body.merchant_id).to.eq(merchantIdM1);
+ });
+ });
+
+ it("global admin key works for any merchant_id, unrestricted", () => {
+ cy.ompRetrieveMerchantAccount(
+ merchantIdM2,
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("retrieving a non-existent merchant_id is rejected (401, by design)", () => {
+ // Not a 404 - confirmed live and in source. Auth itself
+ // (fetch_merchant_key_store_and_account,
+ // services/authentication.rs:2053-2075) fetches the merchant/key_store
+ // for the path merchant_id and explicitly maps a not-found DB lookup
+ // to ApiErrorResponse::Unauthorized, before the core retrieve logic
+ // (which would otherwise return a clean 404) ever runs - deliberately
+ // avoids distinguishing "wrong credential" from "merchant doesn't
+ // exist" to an unauthenticated-feeling caller.
+ cy.ompRetrieveMerchantAccount(
+ "merchant_nonexistent_omp_test",
+ { type: "adminApiKey", apiKey: adminApiKey },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+
+ it("invalid credential on retrieve is rejected", () => {
+ cy.ompRetrieveMerchantAccount(
+ merchantIdM1,
+ { type: "invalid" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+
+ context("Update", () => {
+ // MerchantAccountUpdate (api_models/src/admin.rs:436-497, V1) requires
+ // merchant_id in the BODY - it's deserialized independently of the
+ // path param, not inherited from it. It's the only required field;
+ // omitting it fails deserialization (400 IR_06) before auth or the
+ // merchant-mismatch check ever run, confirmed live. Every body below
+ // includes it, matching whatever merchant_id is in the path for that
+ // test (deliberately mismatched for the cross-merchant negative test,
+ // so the body's own merchant_id is internally consistent with intent).
+ it("update with mismatched path merchant_id is rejected, M2 unchanged", () => {
+ cy.ompAssertDeniedAndUnchanged({
+ fetch: fetchMerchantAccount(merchantIdM2),
+ negativeRequest: () =>
+ cy.ompUpdateMerchantAccount(
+ merchantIdM2,
+ { type: "jwt", token: jwtPA },
+ { merchant_id: merchantIdM2, merchant_name: "Should be rejected" },
+ globalState
+ ),
+ expectedError: OMP_ERRORS.JWT_MERCHANT_MISMATCH,
+ });
+ });
+
+ it("update with the correct merchant_id succeeds (positive)", () => {
+ cy.ompUpdateMerchantAccount(
+ merchantIdM1,
+ { type: "jwt", token: jwtPA },
+ { merchant_id: merchantIdM1, merchant_name: "OMP Scoping Test M1" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(200);
+ });
+ });
+
+ it("invalid credential on update is rejected", () => {
+ cy.ompUpdateMerchantAccount(
+ merchantIdM1,
+ { type: "invalid" },
+ { merchant_id: merchantIdM1, merchant_name: "Should be rejected" },
+ globalState
+ ).then((res) => {
+ expect(res.status).to.eq(401);
+ });
+ });
+ });
+});
diff --git a/cypress-tests/cypress/support/security-commands.js b/cypress-tests/cypress/support/security-commands.js
index fcff880557..08697e97cc 100644
--- a/cypress-tests/cypress/support/security-commands.js
+++ b/cypress-tests/cypress/support/security-commands.js
@@ -6,6 +6,17 @@
//
// auth variants:
// { type: "apiKey", apiKey, profileId? }
+// { type: "adminApiKey", apiKey } - AdminApiAuth/V2AdminApiAuth.
+// NOT the same header as
+// "apiKey" - confirmed live that
+// a plain api-key header on an
+// admin-only route returns 401,
+// since V2AdminApiAuth parses
+// the key from Authorization in
+// the exact form
+// "admin-api-key=<key>"
+// (services/authentication.rs:
+// 1748-1755), not api-key.
// { type: "jwt", token, profileId? }
// { type: "none" } - no Authorization/api-key header
// { type: "invalid" } - garbage bearer token, substitutes
@@ -24,6 +35,9 @@ function buildOmpHeaders(auth = {}) {
case "apiKey":
headers["api-key"] = auth.apiKey;
break;
+ case "adminApiKey":
+ headers["Authorization"] = `admin-api-key=${auth.apiKey}`;
+ break;
case "jwt":
headers["Authorization"] = `Bearer ${auth.token}`;
break;
@@ -557,3 +571,473 @@ Cypress.Commands.add("ompLookupBlocklist", (auth, data, globalState) =>
globalState
)
);
+
+// --- OMP scoping: shared helpers for resources not yet exercised anywhere
+// else in this suite (cypress/e2e/spec/Security/OMPScoping/) ---
+
+// NOTE: there is deliberately no "create MCA with no profile_id" command
+// here - confirmed live that connector creation always resolves a profile
+// at creation time (explicitly via profile_id, or a legacy
+// business_country/business_label fallback); omitting profile_id returns
+// IR_04 "Missing required param: profile_id or business_country,
+// business_label". A NULL profile_id isn't reachable through the public
+// API, so the nullable-profile_id fail-closed check
+// (validate_profile_id_from_auth_layer) is verified by reading its source
+// only, not by an API-level test.
+
+// --- OMP scoping: Customer (cypress/e2e/spec/Security/OMPScoping/11-CustomerPaymentMethodMandate.cy.js) ---
+
+Cypress.Commands.add("ompRetrieveCustomer", (customerId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/customers/${customerId}`,
+ auth,
+ });
+});
+
+Cypress.Commands.add(
+ "ompUpdateCustomer",
+ (customerId, auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/customers/${customerId}`,
+ auth,
+ body,
+ });
+ }
+);
+
+Cypress.Commands.add("ompDeleteCustomer", (customerId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "DELETE",
+ url: `${baseUrl}/customers/${customerId}`,
+ auth,
+ });
+});
+
+// --- OMP scoping: Payment Method ---
+
+Cypress.Commands.add(
+ "ompRetrievePaymentMethod",
+ (paymentMethodId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/payment_methods/${paymentMethodId}`,
+ auth,
+ });
+ }
+);
+
+Cypress.Commands.add(
+ "ompUpdatePaymentMethod",
+ (paymentMethodId, auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/payment_methods/${paymentMethodId}/update`,
+ auth,
+ body,
+ });
+ }
+);
+
+Cypress.Commands.add(
+ "ompDeletePaymentMethod",
+ (paymentMethodId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "DELETE",
+ url: `${baseUrl}/payment_methods/${paymentMethodId}`,
+ auth,
+ });
+ }
+);
+
+Cypress.Commands.add("ompCreatePaymentMethod", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/payment_methods`,
+ auth,
+ body,
+ });
+});
+
+// --- OMP scoping: Mandate ---
+
+Cypress.Commands.add("ompRetrieveMandate", (mandateId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/mandates/${mandateId}`,
+ auth,
+ });
+});
+
+Cypress.Commands.add("ompRevokeMandate", (mandateId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/mandates/revoke/${mandateId}`,
+ auth,
+ });
+});
+
+// --- OMP scoping: Refund (cypress/e2e/spec/Security/OMPScoping/12-Refund.cy.js) ---
+
+Cypress.Commands.add("ompRetrieveRefund", (refundId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/refunds/${refundId}`,
+ auth,
+ });
+});
+
+Cypress.Commands.add("ompUpdateRefund", (refundId, auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/refunds/${refundId}`,
+ auth,
+ body,
+ });
+});
+
+Cypress.Commands.add("ompCreateRefund", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/refunds`,
+ auth,
+ body,
+ });
+});
+
+// --- OMP scoping: Routing retrieve/unlink (cypress/e2e/spec/Security/OMPScoping/14-Routing.cy.js) ---
+
+Cypress.Commands.add(
+ "ompRetrieveRoutingAlgorithm",
+ (algorithmId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/routing/${algorithmId}`,
+ auth,
+ });
+ }
+);
+
+Cypress.Commands.add(
+ "ompActivateRoutingAlgorithm",
+ (algorithmId, auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/routing/${algorithmId}/activate`,
+ auth,
+ body,
+ });
+ }
+);
+
+Cypress.Commands.add("ompDeactivateRouting", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/routing/deactivate`,
+ auth,
+ body,
+ });
+});
+
+// --- OMP scoping: Analytics (cypress/e2e/spec/Security/OMPScoping/17-Analytics.cy.js) ---
+
+// get_merchant_payment_metrics (crates/router/src/analytics.rs) deserializes
+// web::Json<[GetPaymentMetricRequest; 1]> - a 1-element array, not a plain
+// object - and GetPaymentMetricRequest itself is #[serde(rename_all =
+// "camelCase")] (timeRange/groupByNames), while its nested TimeRange and
+// PaymentFilters types stay snake_case. Callers here pass the plain request
+// object; this command wraps it in the required array so every test
+// doesn't need to know about that oddity.
+Cypress.Commands.add("ompQueryPaymentMetrics", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/analytics/v1/metrics/payments`,
+ auth,
+ body: [body],
+ });
+});
+
+// Org-level variant (get_org_payment_metrics, analytics.rs:628-669) - same
+// array-wrapped GetPaymentMetricRequest body as the merchant-level route
+// above, but AuthInfo is built from auth.platform.to_org_level_auth_info()
+// rather than the request body, and the auth requirement is
+// OrganizationAnalyticsRead (PlatformOrgAdminAuth or JWT), not
+// MerchantAnalyticsRead.
+Cypress.Commands.add("ompQueryOrgPaymentMetrics", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/analytics/v1/org/metrics/payments`,
+ auth,
+ body: [body],
+ });
+});
+
+// --- OMP scoping: role-based user provisioning, for Analytics org_admin vs
+// merchant_admin test cases (17-Analytics.cy.js). No existing Cypress
+// command covers inviting a user or logging one in from scratch (the
+// existing userLogin/terminate2Fa commands assume a single fixed
+// globalState "email"/"password" pair from the initial dashboard signup,
+// not a second, separately-provisioned user) - these are deliberately raw/
+// low-level rather than folded into the existing 3-command signup chain,
+// since the invited-user flow has an extra mandatory step
+// (force_set_password) that signup doesn't.
+
+Cypress.Commands.add("ompInviteUser", (auth, invitees, globalState) =>
+ // Nested scope: outer web::scope("/user") (app.rs:2992) + inner
+ // web::scope("/user") (app.rs:3180) = /user/user/invite_multiple,
+ // confirmed against the route registration - not /user/invite_multiple.
+ ompCall("POST", "/user/user/invite_multiple", auth, invitees, globalState)
+);
+
+Cypress.Commands.add("ompUserSignin", (email, password, globalState) =>
+ ompCall(
+ "POST",
+ "/user/v2/signin?token_only=true",
+ { type: "none" },
+ { email, password },
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompTerminate2FaRaw", (token, globalState) =>
+ ompCall(
+ "GET",
+ "/user/2fa/terminate?skip_two_factor_auth=true",
+ { type: "jwt", token },
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompRotatePassword", (token, newPassword, globalState) =>
+ ompCall(
+ "POST",
+ "/user/rotate_password",
+ { type: "jwt", token },
+ { password: newPassword },
+ globalState
+ )
+);
+
+// --- OMP scoping: Relay (cypress/e2e/spec/Security/OMPScoping/18-Relay.cy.js) ---
+
+Cypress.Commands.add("ompRetrieveRelay", (relayId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/relay/${relayId}`,
+ auth,
+ });
+});
+
+// --- OMP scoping: Payment Link / Payout Link retrieve
+// (cypress/e2e/spec/Security/OMPScoping/19-PaymentLink.cy.js, 20-PayoutLink.cy.js) ---
+
+Cypress.Commands.add(
+ "ompRetrievePaymentLink",
+ (paymentLinkId, auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/payment_link/${paymentLinkId}`,
+ auth,
+ });
+ }
+);
+
+// render_payout_link uses auth::MerchantIdAuth(merchant_id) - the path's
+// own merchant_id IS the authenticated identity, there is no separate
+// bearer/api-key credential on this route at all (it's the public,
+// customer-facing link page). So there's no "auth" parameter here - the
+// cross-merchant check is entirely about whether a path merchant_id that
+// doesn't own payoutId returns not-found.
+Cypress.Commands.add(
+ "ompRetrievePayoutLinkByPath",
+ (merchantId, payoutId, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.request({
+ method: "GET",
+ url: `${baseUrl}/payout_link/${merchantId}/${payoutId}`,
+ failOnStatusCode: false,
+ });
+ }
+);
+
+// --- OMP scoping: Surcharge Config raw get/put
+// (cypress/e2e/spec/Security/OMPScoping/15-Surcharge.cy.js) - distinct from
+// the existing createSurchargeDSLConfig/retrieveSurchargeDSLConfig
+// commands, which take their own Response-comparison data shape; these are
+// the plain ompRequest-style equivalents used for cross-merchant checks. ---
+
+Cypress.Commands.add("ompGetSurchargeConfig", (auth, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "GET",
+ url: `${baseUrl}/routing/decision/surcharge`,
+ auth,
+ });
+});
+
+Cypress.Commands.add("ompPutSurchargeConfig", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "PUT",
+ url: `${baseUrl}/routing/decision/surcharge`,
+ auth,
+ body,
+ });
+});
+
+// --- OMP scoping: generic payment create
+// (cypress/e2e/spec/Security/OMPScoping/21-PaymentCrossReference.cy.js) ---
+
+Cypress.Commands.add("ompCreatePayment", (auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/payments`,
+ auth,
+ body,
+ });
+});
+
+Cypress.Commands.add(
+ "ompExtendPaymentAuthorization",
+ (paymentId, auth, body, globalState) => {
+ const baseUrl = globalState.get("baseUrl");
+ return cy.ompRequest({
+ method: "POST",
+ url: `${baseUrl}/payments/${paymentId}/extend_authorization`,
+ auth,
+ body,
+ });
+ }
+);
+
+// --- OMP scoping: MCA update/delete/list
+// (cypress/e2e/spec/Security/OMPScoping/22-MCA.cy.js) - ompRetrieveMca
+// already exists above, added for 06-ConnectorOnboarding.cy.js. ---
+
+Cypress.Commands.add(
+ "ompUpdateMca",
+ (merchantId, mcaId, auth, body, globalState) =>
+ ompCall(
+ "POST",
+ `/account/${merchantId}/connectors/${mcaId}`,
+ auth,
+ body,
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompDeleteMca", (merchantId, mcaId, auth, globalState) =>
+ ompCall(
+ "DELETE",
+ `/account/${merchantId}/connectors/${mcaId}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompListMca", (merchantId, auth, globalState) =>
+ ompCall(
+ "GET",
+ `/account/${merchantId}/connectors`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompListProfileConnectors",
+ (accountId, auth, globalState) =>
+ ompCall(
+ "GET",
+ `/account/${accountId}/profile/connectors`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+// --- OMP scoping: API Keys
+// (cypress/e2e/spec/Security/OMPScoping/23-ApiKeys.cy.js) - distinct from
+// ompCreateThrowawayApiKey/ompRevokeApiKey above, which are fixed to the
+// admin-key auth scheme for test-fixture housekeeping; these take an
+// arbitrary auth (JWT or admin key) for cross-merchant negative tests. ---
+
+Cypress.Commands.add("ompCreateApiKey", (merchantId, auth, body, globalState) =>
+ ompCall("POST", `/api_keys/${merchantId}`, auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompRetrieveApiKey",
+ (merchantId, keyId, auth, globalState) =>
+ ompCall(
+ "GET",
+ `/api_keys/${merchantId}/${keyId}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add(
+ "ompUpdateApiKey",
+ (merchantId, keyId, auth, body, globalState) =>
+ ompCall("POST", `/api_keys/${merchantId}/${keyId}`, auth, body, globalState)
+);
+
+Cypress.Commands.add(
+ "ompRevokeApiKeyAs",
+ (merchantId, keyId, auth, globalState) =>
+ ompCall(
+ "DELETE",
+ `/api_keys/${merchantId}/${keyId}`,
+ auth,
+ undefined,
+ globalState
+ )
+);
+
+Cypress.Commands.add("ompListApiKeys", (merchantId, auth, globalState) =>
+ ompCall("GET", `/api_keys/${merchantId}/list`, auth, undefined, globalState)
+);
+
+// --- OMP scoping: Merchant Account
+// (cypress/e2e/spec/Security/OMPScoping/24-MerchantAccount.cy.js) - distinct
+// from ompGetMerchantAccount above, which is fixed to the admin-key auth
+// scheme for test-fixture housekeeping (e.g. fetching publishable_key);
+// these take an arbitrary auth for cross-merchant negative tests. ---
+
+Cypress.Commands.add(
+ "ompRetrieveMerchantAccount",
+ (merchantId, auth, globalState) =>
+ ompCall("GET", `/accounts/${merchantId}`, auth, undefined, globalState)
+);
+
+Cypress.Commands.add(
+ "ompUpdateMerchantAccount",
+ (merchantId, auth, body, globalState) =>
+ ompCall("POST", `/accounts/${merchantId}`, auth, body, globalState)
+);