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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
test(cypress): add X-Integration-Type header validation coverage (#14657)
HS-QUALIBOTd06af6f77550
diff --git a/cypress-tests/cypress/e2e/configs/Payment/Commons.js b/cypress-tests/cypress/e2e/configs/Payment/Commons.jsindex 07850b11c0..b3ed784749 100644--- a/cypress-tests/cypress/e2e/configs/Payment/Commons.js+++ b/cypress-tests/cypress/e2e/configs/Payment/Commons.js@@ -4431,6 +4431,31 @@ export const connectorDetails = {},},}),+ // Builds the same message validate_integration_type (server_integration.rs)+ // produces for a header/merchant-integration_type mismatch. Used by+ // integrationTypeChecker/paymentUpdate in commands.js, which+ // 54-IntegrationTypeValidation.cy.js calls into.+ IntegrationTypeValidation: (expectedStatus, header, merchantConfig) => ({+ Request: {+ currency: "USD",+ amount: 6540,+ },+ Response: {+ status: expectedStatus,+ body:+ expectedStatus === 200+ ? { status: "requires_payment_method" }+ : {+ error: {+ code: "IR_06",+ message: integrationTypeMismatchMessage(+ header,+ merchantConfig+ ),+ },+ },+ },+ }),},upi_pm: {PaymentIntent: getCustomExchange({@@ -5981,6 +6006,15 @@ export const connectorDetails = {},};+// Builds the same message validate_integration_type (server_integration.rs)+// produces for a header/merchant-integration_type mismatch. Used by+// integrationTypeChecker/paymentUpdate in commands.js, which+// 54-IntegrationTypeValidation.cy.js calls into.+export function integrationTypeMismatchMessage(header, merchantConfig) {+ const headerLabel = header ?? "client";+ const merchantLabel = merchantConfig ?? "client";+ return `\`x-integration-type\` header value \`${headerLabel}\` does not match the merchant integration type \`${merchantLabel}\``;+}// Separate keys, not a reuse of ConfirmWithOfferApplied/// AppliedOfferOnRetrieve in place, so that connectors which can't actually// complete a saved-card confirm (e.g. ilixium, which doesn't implementdiff --git a/cypress-tests/cypress/e2e/spec/Payment/54-IntegrationTypeValidation.cy.js b/cypress-tests/cypress/e2e/spec/Payment/54-IntegrationTypeValidation.cy.jsnew file mode 100644index 0000000000..d5d5430ea6--- /dev/null+++ b/cypress-tests/cypress/e2e/spec/Payment/54-IntegrationTypeValidation.cy.js@@ -0,0 +1,162 @@+import * as fixtures from "../../../fixtures/imports";+import State from "../../../utils/State";++let globalState;++const MATRIX = [+ { merchantConfig: undefined, header: undefined, expectedStatus: 200 },+ { merchantConfig: undefined, header: "client", expectedStatus: 200 },+ { merchantConfig: undefined, header: "server", expectedStatus: 422 },+ { merchantConfig: "client", header: undefined, expectedStatus: 200 },+ { merchantConfig: "client", header: "client", expectedStatus: 200 },+ { merchantConfig: "client", header: "server", expectedStatus: 422 },+ { merchantConfig: "server", header: undefined, expectedStatus: 422 },+ { merchantConfig: "server", header: "client", expectedStatus: 422 },+ { merchantConfig: "server", header: "server", expectedStatus: 200 },+ {+ merchantConfig: "client_and_server",+ header: undefined,+ expectedStatus: 200,+ },+ {+ merchantConfig: "client_and_server",+ header: "client",+ expectedStatus: 200,+ },+ {+ merchantConfig: "client_and_server",+ header: "server",+ expectedStatus: 200,+ },+];++// requires = DimensionsWithProcessorAndProviderMerchantId (dimension_config.rs)+function merchantIntegrationTypeContext() {+ const merchantId = globalState.get("merchantId");+ return {+ processor_merchant_id: merchantId,+ provider_merchant_id: merchantId,+ };+}++describe("X-Integration-Type header validation against merchant integration_type", () => {+ let specShouldSkip = false;++ before("seed global state", () => {+ cy.task("getGlobalState").then((state) => {+ globalState = new State(state);++ // The whole matrix below depends on the merchant's+ // system.payment_integration_type actually being set via Superposition.+ // Without credentials, createSuperpositionConfig silently no-ops (by+ // design), so the merchant stays on the default "client" type and every+ // "server"-header scenario fails for the wrong reason. Skip instead of+ // failing, same as 54-BlockImplicitCustomerCreation.cy.js / 42-RequiresCVV.cy.js.+ if (+ !globalState.get("superpositionBaseUrl") ||+ !globalState.get("superpositionSecret") ||+ !globalState.get("superpositionAuthToken")+ ) {+ cy.task(+ "cli_log",+ "Superposition credentials not set — skipping IntegrationTypeValidation spec"+ );+ specShouldSkip = true;+ }+ });+ });++ beforeEach(function () {+ if (specShouldSkip) {+ this.skip();+ }+ });++ after("flush global state", () => {+ if (!specShouldSkip) {+ cy.deleteSuperpositionContext(+ globalState,+ merchantIntegrationTypeContext()+ );+ }+ cy.task("setGlobalState", globalState.data);+ });++ MATRIX.forEach(({ merchantConfig, header, expectedStatus }) => {+ const label = `merchant=${merchantConfig ?? "unset"} header=${header ?? "none"} -> ${expectedStatus}`;+ let updatePaymentId;++ context(label, () => {+ before("apply merchant integration_type config", function () {+ if (specShouldSkip) {+ this.skip();+ }+ if (merchantConfig) {+ cy.createSuperpositionConfig(+ globalState,+ "system.payment_integration_type",+ merchantConfig,+ merchantIntegrationTypeContext()+ );+ } else {+ cy.deleteSuperpositionContext(+ globalState,+ merchantIntegrationTypeContext()+ );+ }+ });++ before("create payment for update test", function () {+ // Mocha's this.skip() in the sibling "apply merchant integration_type+ // config" hook above only cascades to the `it`s in this context, not+ // to this hook — it still runs regardless, so it needs its own guard.+ if (specShouldSkip) {+ this.skip();+ }++ // A header value guaranteed to pass under the config just set above,+ // independent of whatever header this scenario tests against — a+ // "server" merchant only accepts a "server" header, everything else+ // accepts no header.+ const validHeader = merchantConfig === "server" ? "server" : undefined;++ cy.integrationTypeChecker(fixtures.createPaymentBody, globalState, {+ expectedStatus: 200,+ header: validHeader,+ merchantConfig,+ });++ // integrationTypeChecker doesn't return its response chain; capture+ // the payment id from globalState now, before the "create intent"+ // test below runs and overwrites it with its own payment.+ cy.then(() => {+ updatePaymentId = globalState.get("paymentID");+ });+ });++ after("clean up merchant integration_type config", () => {+ cy.deleteSuperpositionContext(+ globalState,+ merchantIntegrationTypeContext()+ );+ });++ it(`create intent: ${label}`, () => {+ cy.integrationTypeChecker(fixtures.createPaymentBody, globalState, {+ expectedStatus,+ header,+ merchantConfig,+ });+ });++ it(`update intent: ${label}`, () => {+ cy.paymentUpdate(+ updatePaymentId,+ { amount: 7000, currency: "USD" },+ globalState,+ { headerValue: header, expectedStatus, merchantConfig }+ );+ });+ });+ });+});diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.jsindex 1b7d33a4e2..aec1271376 100644--- a/cypress-tests/cypress/support/commands.js+++ b/cypress-tests/cypress/support/commands.js@@ -36,6 +36,10 @@ import getConnectorDetails, {shouldIncludeConnector,stringifyWithBigInt,} from "../e2e/configs/Payment/Utils";+import {+ connectorDetails as commonConnectorDetails,+ integrationTypeMismatchMessage,+} from "../e2e/configs/Payment/Commons";import { OFFER_QUOTE_ID_PLACEHOLDER } from "../e2e/configs/Payment/Commons";import { injectGotymePayoutBankTransfer } from "../e2e/configs/Payout/Utils";import { execConfig, validateConfig } from "../utils/featureFlags";@@ -2987,7 +2991,8 @@ Cypress.Commands.add(authentication_type,capture_method,globalState,- connectedMerchantId+ connectedMerchantId,+ integrationTypeHeader) => {const {Configs: configs = {},@@ -3036,6 +3041,10 @@ Cypress.Commands.add(headers["x-connected-merchant-id"] = connectedMerchantId;}+ if (integrationTypeHeader !== undefined) {+ headers["X-Integration-Type"] = integrationTypeHeader;+ }+globalState.set("paymentAmount", body.amount);globalState.set("paymentCurrency", body.currency);globalState.set("captureMethod", capture_method);@@ -8872,6 +8881,76 @@ Cypress.Commands.add("setupConfigs", (globalState, key, value) => {cy.setConfigs(globalState, key, value, "CREATE");});+// Creates a payment intent with an optional X-Integration-Type header and+// asserts the expected status/body for it, via+// connectorDetails.card_pm.IntegrationTypeValidation (Payment/Commons.js) —+// success shape, or the full IR_06 mismatch error (code + message) built+// from the header/merchantConfig actually in effect for this call.+Cypress.Commands.add(+ "integrationTypeChecker",+ (+ createPaymentBody,+ globalState,+ { expectedStatus, header, merchantConfig } = {}+ ) => {+ cy.createPaymentIntentTest(+ createPaymentBody,+ commonConnectorDetails.card_pm.IntegrationTypeValidation(+ expectedStatus,+ header,+ merchantConfig+ ),+ "no_three_ds",+ "automatic",+ globalState,+ undefined,+ header+ );+ }+);++Cypress.Commands.add(+ "paymentUpdate",+ (+ paymentId,+ requestBody,+ globalState,+ { headerValue, expectedStatus, merchantConfig } = {}+ ) => {+ const headers = {+ "Content-Type": "application/json",+ "api-key": globalState.get("apiKey"),+ };+ if (headerValue !== undefined) {+ headers["X-Integration-Type"] = headerValue;+ }++ return cy+ .request({+ method: "POST",+ url: `${globalState.get("baseUrl")}/payments/${paymentId}`,+ headers,+ body: requestBody,+ failOnStatusCode: false,+ })+ .then((response) => {+ logRequestId(response.headers["x-request-id"]);++ expect(response.status).to.equal(expectedStatus);+ if (expectedStatus === 200) {+ expect(response.body.amount).to.equal(requestBody.amount);+ } else {+ expect(response.body).to.have.property("error");+ expect(response.body.error.code).to.equal("IR_06");+ expect(response.body.error.message).to.equal(+ integrationTypeMismatchMessage(headerValue, merchantConfig)+ );+ }+ return cy.wrap(response);+ });+ }+);+// UCS Configuration CommandsCypress.Commands.add("setupUCSConfigs", (globalState) => {cy.setupConfigs(globalState, "ucs_enabled", "true");@@ -13218,8 +13297,13 @@ Cypress.Commands.add();});});- // Polling interval is 10 s in CI and 15 s in all other envs- cy.wait(15000);+ // Polling interval is 10 s in CI (ROUTER__SUPERPOSITION__POLLING_INTERVAL)+ // and 15 s elsewhere. Wait for two full CI poll cycles plus a buffer —+ // a single 15 s wait only has ~5 s of margin over one CI poll tick, which+ // isn't enough if the write lands just after a tick or there's network+ // jitter: the next test can then run against stale config (seen as+ // flaky failures in 54-IntegrationTypeValidation.cy.js in CI).+ cy.wait(21000);});