The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Consolidate data-apps e2e tests (#84009)
Chris Vandoodewaard0043f5cc0f28
diff --git a/e2e/support/assets/data-apps/isolation/src/App.tsx b/e2e/support/assets/data-apps/isolation/src/App.tsxindex 8bca01fc91e..0358c9d86c9 100644--- a/e2e/support/assets/data-apps/isolation/src/App.tsx+++ b/e2e/support/assets/data-apps/isolation/src/App.tsx@@ -16,24 +16,40 @@ import { describeError, getEnv } from "./utils";export default function App() {const env = getEnv();const [result, setResult] = useState("pending");+ const [probeId, setProbeId] = useState<string | null>(null);const [reactMode, setReactMode] = useState<ReactMode | null>(null);const firedRef = useRef(false);+ const timerRef = useRef<number | undefined>(undefined);+ const currentProbeRef = useRef<string | null>(null);useProbeCustomElement(setResult);// If a probe never reports, `no-probe-observed` fails the spec (the probe// never fired) rather than hanging.- const arm = () =>- window.setTimeout(+ const arm = (id: string) => {+ currentProbeRef.current = id;+ window.clearTimeout(timerRef.current);+ setProbeId(id);+ setResult("pending");+ timerRef.current = window.setTimeout(() => setResult((r) => (r === "pending" ? "no-probe-observed" : r)),20000,);+ };- const fire = (run: () => void) => {- arm();+ const reportFor = (id: string) => (value: string) => {+ if (currentProbeRef.current === id) {+ setResult(value);+ }+ };++ const fire = (id: string) => {+ arm(id);try {- run();+ createProbes(env, reportFor(id))+ .find((p) => p.id === id)+ ?.run();} catch (err) {setResult(`isolated:${describeError(err)}`);}@@ -44,14 +60,16 @@ export default function App() {return (<div data-testid="data-app-isolation" style={{ padding: 24 }}><h1>Isolation probe</h1>- <div data-testid="isolation-result">{result}</div>+ <div data-testid="isolation-result" data-probe-id={probeId ?? ""}>+ {result}+ </div><div style={{ display: "flex", gap: 8, marginTop: 16, flexWrap: "wrap" }}>{probes.map((probe) => (<buttonkey={probe.id}data-testid={`isolation-${probe.id}`}- onClick={() => fire(probe.run)}+ onClick={() => fire(probe.id)}>{probe.label}</button>@@ -61,7 +79,7 @@ export default function App() {key={probe.id}data-testid={`isolation-${probe.id}`}onClick={() => {- arm();+ arm(probe.id);firedRef.current = false;setReactMode(probe.mode);}}diff --git a/e2e/test/scenarios/data-apps/admin.cy.spec.ts b/e2e/test/scenarios/data-apps/admin.cy.spec.tsindex 84697a63443..d2f825c905e 100644--- a/e2e/test/scenarios/data-apps/admin.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/admin.cy.spec.ts@@ -139,17 +139,13 @@ describe("scenarios > data apps > upsell (OSS)", { tags: "@OSS" }, () => {// settings page shows the upsell instead of the management UI.});- it("shows the data-apps upsell instead of the management UI", () => {+ it("shows the data-apps upsell instead of the management UI, and marks the Data apps settings nav item with an upsell gem", () => {cy.visit("/admin/settings/apps");H.main().within(() => {cy.findByText("Build custom data apps").should("be.visible");cy.findByText("Try for free").should("be.visible");});- });-- it("marks the Data apps settings nav item with an upsell gem", () => {- cy.visit("/admin/settings/apps");cy.findByRole("link", { name: /Data apps/ }).within(() => {cy.findByTestId("upsell-gem").should("be.visible");diff --git a/e2e/test/scenarios/data-apps/resources-production-actions.cy.spec.ts b/e2e/test/scenarios/data-apps/resources-production-actions.cy.spec.tsindex 6cae23a578b..6a56b7f1e90 100644--- a/e2e/test/scenarios/data-apps/resources-production-actions.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/resources-production-actions.cy.spec.ts@@ -80,7 +80,8 @@ describe(.then((app) => cy.wrap({ app, actionCopy }, { log: false }));});- it("serializes the action an author copies, with no model, as its file holds it", () => {+ it("serializes the action an author copies, and executes the app's copy rather than the authored action, for a member of the app's group", () => {+ cy.log("serialize an action with no model, as its file holds it");H.createDataAppScoreboardAction().then((source) => {// Executing the action reads this, so the copy must keep it.cy.request("PUT", `/api/action/${source.id}`, {@@ -109,9 +110,8 @@ describe(.that.deep.include({ hidden: true, defaultValue: 0 });});});- });- it("executes the app's copy rather than the authored action, for a member of the app's group", () => {+ cy.log("execute the app's copy of a separate action");publishApp().then(({ app, actionCopy }) => {H.assignTestGroupToDataApp(app.name).then((groupId) => {H.addUserToGroup(groupId, USERS.normal.email);diff --git a/e2e/test/scenarios/data-apps/resources-production.cy.spec.ts b/e2e/test/scenarios/data-apps/resources-production.cy.spec.tsindex 3b1faf127c9..5d6930a1db7 100644--- a/e2e/test/scenarios/data-apps/resources-production.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/resources-production.cy.spec.ts@@ -112,7 +112,7 @@ describe("scenarios > data apps > resources in production", () => {),);- it("runs the saved question rather than the authored table query", () => {+ it("runs the saved question rather than the authored table query, and both return the same rows", () => {publishApp().then(({ cardId }) => {cy.intercept("POST", "/api/dataset").as("dataset");H.mockDataApp(APP_SLUG, { displayName: APP_DISPLAY_NAME });@@ -133,15 +133,12 @@ describe("scenarios > data apps > resources in production", () => {undefined,);});- });- });- // The swap is only safe if the saved question the author wrote returns what- // the definition does. The dev preview runs the definition; production runs- // the card. A deployed app cannot run the definition at all, so the two sides- // are captured separately rather than side by side.- it("returns the same rows from the saved question as from the authored query", () => {- publishApp().then(({ cardId }) => {+ // The swap is only safe if the saved question the author wrote returns what+ // the definition does. The dev preview runs the definition; production runs+ // the card. A deployed app cannot run the definition at all, so the two sides+ // are captured separately rather than side by side.+ cy.log("the saved question returns the same rows as the authored query");cy.request("POST", "/api/dataset", {type: "query",database: SAMPLE_DB_ID,diff --git a/e2e/test/scenarios/data-apps/sandbox.cy.spec.ts b/e2e/test/scenarios/data-apps/sandbox.cy.spec.tsindex ba92be95e1f..068dd43a036 100644--- a/e2e/test/scenarios/data-apps/sandbox.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/sandbox.cy.spec.ts@@ -21,58 +21,6 @@ describe("scenarios > data apps > sandbox & isolation", () => {const ALLOWED_URL = `${ALLOWED_ORIGIN}/ping`;const BLOCKED_URL = "https://blocked.data-app.test/ping";- it("blocks disallowed APIs and cross-origin fetch, but permits allowed_hosts", () => {- // The allowed host is stubbed with a CORS header so the sandbox's real- // network call resolves; the blocked host is never intercepted because the- // sandbox rejects it before it reaches the network.- cy.intercept("GET", ALLOWED_URL, {- statusCode: 200,- headers: { "access-control-allow-origin": "*" },- body: "pong",- });-- H.mockDataApp(APP_NAME, {- displayName: APP_DISPLAY_NAME,- allowedHosts: [ALLOWED_ORIGIN],- testEnv: {- ...TEST_ENV,- sandbox: { allowedUrl: ALLOWED_URL, blockedUrl: BLOCKED_URL },- },- });-- H.openDataApp(APP_NAME);- H.dataAppIframe(APP_DISPLAY_NAME).within(() => {- cy.findByRole("heading", { name: "Orders overview" }).should(- "be.visible",- );- cy.findByRole("link", { name: "Sandbox" }).click();-- // A blocked DOM API throws synchronously inside the sandbox.- cy.findByTestId("probe-script", { timeout: 30000 }).should(- "have.text",- "blocked",- );-- // A fetch to a host not in allowed_hosts is rejected by the sandbox.- cy.findByTestId("blocked-fetch-result", { timeout: 30000 }).should(- "contain",- "not in allowed_hosts",- );-- // A fetch to a host in allowed_hosts reaches the (stubbed) network.- cy.findByTestId("allowed-fetch-result", { timeout: 30000 }).should(- "have.text",- "ok: 200",- );- });- });- });-- describe("sandbox breadth", () => {- const ALLOWED_ORIGIN = "https://allowed.data-app.test";- const ALLOWED_URL = `${ALLOWED_ORIGIN}/ping`;- const BLOCKED_URL = "https://blocked.data-app.test/ping";-// Method/constructor calls the sandbox distortion replaces with a throwing// shim. (Getter-only reads like `localStorage` aren't intercepted, so they// aren't asserted here.)@@ -86,7 +34,10 @@ describe("scenarios > data apps > sandbox & isolation", () => {"sendbeacon",];- it("blocks a broad set of dangerous globals, strips innerHTML, and gates XHR", () => {+ it("blocks dangerous globals, strips innerHTML, gates XHR, and blocks cross-origin fetch but permits allowed_hosts", () => {+ // The allowed host is stubbed with a CORS header so the sandbox's real+ // network call resolves; the blocked host is never intercepted because the+ // sandbox rejects it before it reaches the network.cy.intercept("GET", ALLOWED_URL, {statusCode: 200,headers: { "access-control-allow-origin": "*" },@@ -118,6 +69,18 @@ describe("scenarios > data apps > sandbox & isolation", () => {cy.findByTestId("probe-innerhtml").should("have.text", "stripped");+ // A fetch to a host not in allowed_hosts is rejected by the sandbox.+ cy.findByTestId("blocked-fetch-result", { timeout: 30000 }).should(+ "contain",+ "not in allowed_hosts",+ );++ // A fetch to a host in allowed_hosts reaches the (stubbed) network.+ cy.findByTestId("allowed-fetch-result", { timeout: 30000 }).should(+ "have.text",+ "ok: 200",+ );+// XHR is hard-blocked entirely — data apps are fetch-only. It can't opt out// of following a redirect back to the instance, so it's never allowlisted// like fetch: both blocked and allowed hosts are refused.@@ -131,24 +94,44 @@ describe("scenarios > data apps > sandbox & isolation", () => {});describe("isolation", () => {- const openIsolationPage = () => {+ it("serves the embed document with locked-down headers, renders the app in a sandboxed iframe, and keeps the app's CSS and JS globals inside it", () => {H.mockDataApp(APP_NAME, {displayName: APP_DISPLAY_NAME,testEnv: TEST_ENV,});++ cy.request({+ url: `/embed/apps/${APP_NAME}`,+ followRedirect: false,+ }).then((res) => {+ expect(res.status).to.eq(200);+ expect(String(res.body)).to.contain("app-data-app");+ const csp = String(res.headers["content-security-policy"] ?? "");+ expect(csp).to.contain("frame-ancestors 'self'");+ expect(csp).to.contain("default-src 'none'");+ expect(csp).to.contain("form-action 'none'");+ // The data-app document deliberately does NOT grant 'unsafe-eval' — it's+ // confined to the sandbox-host realm doc (see the BE sandbox-host-endpoint-test).+ expect(csp).to.not.contain("'unsafe-eval'");+ expect(String(res.headers["x-frame-options"] ?? "")).to.match(+ /sameorigin/i,+ );+ });+H.openDataApp(APP_NAME);++ cy.get(`iframe[title="${APP_DISPLAY_NAME}"]`)+ .should("have.attr", "sandbox")+ .and("contain", "allow-scripts")+ .and("not.contain", "allow-top-navigation")+ .and("not.contain", "allow-popups-to-escape-sandbox");+H.dataAppIframe(APP_DISPLAY_NAME).within(() => {cy.findByRole("heading", { name: "Orders overview" }).should("be.visible",);cy.findByRole("link", { name: "Isolation" }).click();- });- };- it("keeps the app's CSS inside the iframe", () => {- openIsolationPage();-- H.dataAppIframe(APP_DISPLAY_NAME).within(() => {// The injected <style> applies to the app's own document.cy.findByTestId("css-injected").should("have.text", "ok");cy.findByTestId("isolation-css-probe").should(@@ -156,6 +139,9 @@ describe("scenarios > data apps > sandbox & isolation", () => {"color","rgb(0, 128, 0)",);++ // The app set the global in its own realm and read it back.+ cy.findByTestId("js-marker").should("have.text", "in-app");});// The aggressive `body` rule injected in the iframe does not reach the@@ -165,54 +151,9 @@ describe("scenarios > data apps > sandbox & isolation", () => {"background-color","rgb(0, 128, 0)",);- });-- it("keeps the app's JS globals out of the parent realm (near-membrane)", () => {- openIsolationPage();-- H.dataAppIframe(APP_DISPLAY_NAME).within(() => {- // The app set the global in its own realm and read it back.- cy.findByTestId("js-marker").should("have.text", "in-app");- });// The parent window never sees the app's global.cy.window().should("not.have.property", "__DATA_APP_ISOLATION_MARKER__");});});-- describe("iframe security headers", () => {- it("serves the embed document with the expected CSP + framing headers", () => {- H.mockDataApp(APP_NAME, { displayName: APP_DISPLAY_NAME });-- cy.request({- url: `/embed/apps/${APP_NAME}`,- failOnStatusCode: false,- }).then((res) => {- expect(res.status).to.equal(200);-- const csp = String(res.headers["content-security-policy"] ?? "");- expect(csp).to.contain("frame-ancestors 'self'");- expect(csp).to.contain("default-src 'none'");- expect(csp).to.contain("form-action 'none'");- // The data-app document deliberately does NOT grant 'unsafe-eval' — it's- // confined to the sandbox-host realm doc (see the BE sandbox-host-endpoint-test).- expect(csp).to.not.contain("'unsafe-eval'");- expect(String(res.headers["x-frame-options"] ?? "")).to.match(- /sameorigin/i,- );- });- });-- it("renders the app in a locked-down sandboxed iframe", () => {- H.mockDataApp(APP_NAME, {- displayName: APP_DISPLAY_NAME,- testEnv: TEST_ENV,- });-- H.openDataApp(APP_NAME);- cy.get(`iframe[title="${APP_DISPLAY_NAME}"]`)- .should("have.attr", "sandbox")- .and("contain", "allow-scripts");- });- });});diff --git a/e2e/test/scenarios/data-apps/sandboxing_isolation.cy.spec.ts b/e2e/test/scenarios/data-apps/sandboxing_isolation.cy.spec.tsindex dd51946489e..795fa56c458 100644--- a/e2e/test/scenarios/data-apps/sandboxing_isolation.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/sandboxing_isolation.cy.spec.ts@@ -18,222 +18,100 @@ describe("scenarios > data apps > sandbox isolation", () => {H.mockDataApp(APP_NAME, { displayName: APP_DISPLAY_NAME, testEnv });H.openDataApp(APP_NAME);- };-- /**- * Click a probe and assert it reported that the boundary held. Every probe- * stops at the first sign it reached across the boundary: `isolated:` means it- * did not, `reached:` means it did. `pending` / `no-probe-observed` mean the- * probe never fired, which is also a failure — none of those contain- * `isolated:`, so a single assertion covers all three.- */- const runProbe = (buttonTestId: string) => {H.dataAppIframe(APP_DISPLAY_NAME).within(() => {- cy.findByTestId(buttonTestId).scrollIntoView().click();-- cy.findByTestId("isolation-result", { timeout: 30000 })- .should("not.have.text", "pending")- .invoke("text")- .then((text) => {- cy.log(`isolation-result: ${text}`);- expect(text, "the boundary held").to.contain("isolated:");- });+ cy.findByTestId("isolation-result", { timeout: 30000 }).should(+ "have.text",+ "pending",+ );});};/**- * For the probes whose element is refused during React's own render pass.- *- * The guard throws from `createElement` inside the reconciler, and the app's- * `BoundaryReporter` never catches it: that boundary is declared in the GUEST- * realm while HOST React renders the tree, and React's error-boundary detection- * does not survive the membrane. The throw therefore reaches the host boundary- * and takes the data app down — which is the correct outcome, but it also- * destroys the probe, so there is no `isolation-result` left to read. Assert on- * the guard's own message instead.+ * Click each probe in turn and record what it reported, then assert that the+ * boundary held for all of them at once, so every failing probe shows. Every+ * probe stops at the first sign it reached across the boundary: `isolated:`+ * means it did not, `reached:` means it did. `no-probe-observed` means the+ * probe never fired, which is also a failure. The fixture resets the result to+ * `pending` and tags it with the probe's id on each click, so a result is only+ * read once it belongs to the probe just clicked.*/- const runProbeExpectingGuard = (buttonTestId: string) => {+ const runProbes = (probeIds: string[]) => {+ const results: Record<string, string> = {};+H.dataAppIframe(APP_DISPLAY_NAME).within(() => {- cy.findByTestId(buttonTestId).scrollIntoView().click();+ probeIds.forEach((probeId) => {+ cy.findByTestId(`isolation-${probeId}`).scrollIntoView().click();++ cy.findByTestId("isolation-result", { timeout: 30000 })+ .should(($result) => {+ expect($result.attr("data-probe-id")).to.eq(probeId);+ expect($result.text()).not.to.eq("pending");+ })+ .invoke("text")+ .then((text) => {+ cy.log(`${probeId}: ${text}`);+ results[probeId] = text;+ });+ });});- cy.contains("blocked host createElement", { timeout: 30000 }).should(- "exist",- );+ cy.then(() => {+ expect(Object.keys(results), "every probe reported").to.deep.eq(probeIds);+ expect(+ probeIds+ .filter((probeId) => !results[probeId].includes("isolated:"))+ .map((probeId) => `${probeId}: ${results[probeId]}`),+ "probes that crossed the boundary",+ ).to.deep.eq([]);+ });};- it("keeps a document.createElement about:blank iframe within the gated realm", () => {- setup();- runProbe("isolation-create-element");- });-- it("gates a host-React about:blank iframe", () => {- setup();- runProbeExpectingGuard("isolation-react-about-blank");- });-- it("gates an iframe pointing at Metabase itself", () => {- setup();- runProbeExpectingGuard("isolation-react-src");- });-- it("gates a srcdoc iframe", () => {- setup();- runProbeExpectingGuard("isolation-react-srcdoc");- });-- it("keeps a window.open realm within the gated realm", () => {- setup();- runProbe("isolation-window-open");- });-- it("gates the Worker constructor", () => {- setup();- runProbe("isolation-worker");- });-- it("gates the SharedWorker constructor", () => {- setup();- runProbe("isolation-shared-worker");- });-- it("gates the service worker registration API", () => {- setup();- runProbe("isolation-service-worker");- });-- it("gates dynamic import", () => {- setup();- runProbe("isolation-dynamic-import");- });-- it("keeps a dangerouslySetInnerHTML iframe within the gated realm", () => {- setup();- runProbe("isolation-inner-html");- });-- it("keeps a Function-constructor fetch gated", () => {- setup();- runProbe("isolation-function-constructor");- });-- it("keeps a DOMParser iframe within the gated realm", () => {- setup();- runProbe("isolation-dom-parser");- });-- it("keeps a createHTMLDocument iframe adopted into the realm gated", () => {- setup();- runProbe("isolation-adopt-html-doc-iframe");- });-- it("keeps a createHTMLDocument iframe imported into the realm gated", () => {- setup();- runProbe("isolation-import-html-doc-iframe");- });-- it("keeps a createDocument iframe adopted into the realm gated", () => {- setup();- runProbe("isolation-xml-doc-iframe");- });-- it("keeps a template owner-document iframe adopted into the realm gated", () => {- setup();- runProbe("isolation-template-doc-iframe");- });-- it("keeps a raw API out of the SDK endowments", () => {- setup();- runProbe("isolation-endowment-api");- });-- it("keeps an Error.prepareStackTrace realm reference gated", () => {- setup();- runProbe("isolation-stack-trace-realm");- });-- it("keeps window.parent within the gated realm", () => {- setup();- runProbe("isolation-window-parent");- });-- it("keeps window.top within the gated realm", () => {- setup();- runProbe("isolation-window-top");- });-- it("keeps window.frameElement's owner realm gated", () => {- setup();- runProbe("isolation-frame-element");- });-- it("keeps window.parent.parent within the gated realm", () => {- setup();- runProbe("isolation-parent-chain");- });-- it("gates document.cookie on the parent realm", () => {- setup();- runProbe("isolation-parent-cookie");- });-- it("gates localStorage on the parent realm", () => {- setup();- runProbe("isolation-parent-local-storage");- });-- it("gates sessionStorage on the parent realm", () => {- setup();- runProbe("isolation-parent-session-storage");- });-- it("gates indexedDB on the parent realm", () => {- setup();- runProbe("isolation-parent-indexeddb");- });-- it("gates caches on the parent realm", () => {- setup();- runProbe("isolation-parent-caches");- });+ const guardMessage = () =>+ cy.contains("blocked host createElement", { timeout: 30000 });- it("keeps indexed window.frames access gated", () => {+ it("keeps the realms the app creates within the gated realm", () => {setup();- runProbe("isolation-window-frames");- });- it("keeps window.opener's realm gated", () => {- setup();- runProbe("isolation-window-opener");+ runProbes([+ "window-frames",+ "create-element",+ "dom-parser",+ "adopt-html-doc-iframe",+ "import-html-doc-iframe",+ "xml-doc-iframe",+ "template-doc-iframe",+ "range-fragment-iframe",+ "inner-html",+ "custom-element",+ "window-open",+ ]);});- it("gates FontFace.load", () => {- setup();- runProbe("isolation-font-face");- });-- it("gates cookieStore", () => {- setup();- runProbe("isolation-cookie-store");- });-- it("gates performance resource timing", () => {- setup();- runProbe("isolation-perf-resource-timing");- });+ // The 403s the marker produces are backend behaviour, covered by+ // `data_app_scope_test.clj`. What only e2e can prove is the premise those 403s rest+ // on: that the real transport stamps `X-Metabase-Client: data-app` on the requests the+ // SDK makes from inside the sandbox. The header cannot be spoofed to gain access —+ // host-realm code the membraned guest can't reach sets it, and it only ever narrows —+ // but if it ever stopped being sent, the confinement would silently stop applying.+ it("keeps the host window, its storage and a host iframe's realm gated, and marks the SDK's requests as data-app", () => {+ const markedPaths = new Set<string>();- it("keeps a Range.createContextualFragment iframe within the gated realm", () => {- setup();- runProbe("isolation-range-fragment-iframe");- });+ cy.intercept("/api/**", (req) => {+ if (req.headers["x-metabase-client"] === "data-app") {+ markedPaths.add(new URL(req.url).pathname);+ }+ });- it("keeps a custom element's upgrade callback in the gated realm", () => {setup();- runProbe("isolation-custom-element");- });- it("keeps a host iframe's realm gated", () => {- setup();+ // `/api/user/current` is the whole marked surface this fixture produces — it renders+ // isolation probes, not questions, and the SDK's bootstrap takes site settings from+ // the auth prefetch rather than refetching `/api/session/properties`.+ cy.wrap(markedPaths, { timeout: 30000 }).should((paths) => {+ expect([...paths], "requests marked as data-app").to.include(+ "/api/user/current",+ );+ });// A srcless (about:blank) iframe is same-origin, so its `contentWindow` is a// live realm with an un-gated `fetch` — the same capability html2canvas's@@ -252,7 +130,72 @@ describe("scenarios > data apps > sandbox isolation", () => {);});- runProbe("isolation-child-frame-grab");+ runProbes([+ "child-frame-grab",+ "window-parent",+ "window-top",+ "frame-element",+ "parent-chain",+ "window-opener",+ "parent-cookie",+ "parent-local-storage",+ "parent-session-storage",+ "parent-indexeddb",+ "parent-caches",+ ]);+ });++ it("gates the APIs that run code, read host data or reach a host realm", () => {+ setup();++ runProbes([+ "perf-resource-timing",+ "function-constructor",+ "worker",+ "shared-worker",+ "service-worker",+ "dynamic-import",+ "font-face",+ "cookie-store",+ "endowment-api",+ "stack-trace-realm",+ ]);+ });++ /**+ * For the probes whose element is refused during React's own render pass.+ *+ * The guard throws from `createElement` inside the reconciler, and the app's+ * `BoundaryReporter` never catches it: that boundary is declared in the GUEST+ * realm while HOST React renders the tree, and React's error-boundary detection+ * does not survive the membrane. The throw therefore reaches the host boundary+ * and takes the data app down — which is the correct outcome, but it also+ * destroys the probe, so there is no `isolation-result` left to read. Assert on+ * the guard's own message instead, and open the app again for each probe.+ */+ it("gates host-React iframes: about:blank, Metabase itself and srcdoc", () => {+ const instanceUrl = Cypress.config("baseUrl") ?? "";+ const testEnv: IsolationTestEnv = { instanceUrl };++ H.mockDataApp(APP_NAME, { displayName: APP_DISPLAY_NAME, testEnv });++ ["react-about-blank", "react-src", "react-srcdoc"].forEach((probeId) => {+ cy.log(probeId);+ H.openDataApp(APP_NAME);++ H.dataAppIframe(APP_DISPLAY_NAME).within(() => {+ cy.findByTestId("isolation-result", { timeout: 30000 }).should(+ "have.text",+ "pending",+ );+ });+ guardMessage().should("not.exist");++ H.dataAppIframe(APP_DISPLAY_NAME).within(() => {+ cy.findByTestId(`isolation-${probeId}`).scrollIntoView().click();+ });+ guardMessage().should("exist");+ });});it("gates an allowed_host redirect to the instance", () => {@@ -278,7 +221,7 @@ describe("scenarios > data apps > sandbox isolation", () => {statusCode: 307,headers: { ...cors, Location: `${instanceUrl}/api/session/properties` },});- });+ }).as("allowedHostRedirect");H.mockDataApp(APP_NAME, {displayName: APP_DISPLAY_NAME,@@ -286,40 +229,14 @@ describe("scenarios > data apps > sandbox isolation", () => {allowedHosts: ["http://localhost:4444"],});H.openDataApp(APP_NAME);-- runProbe("isolation-allowed-host-redirect");- });-- // The 403s the marker produces are backend behaviour, covered by- // `data_app_scope_test.clj`. What only e2e can prove is the premise those 403s rest- // on: that the real transport stamps `X-Metabase-Client: data-app` on the requests the- // SDK makes from inside the sandbox. The header cannot be spoofed to gain access —- // host-realm code the membraned guest can't reach sets it, and it only ever narrows —- // but if it ever stopped being sent, the confinement would silently stop applying.- it("marks the requests the SDK makes from inside the sandbox as data-app", () => {- const markedPaths = new Set<string>();-- cy.intercept("/api/**", (req) => {- if (req.headers["x-metabase-client"] === "data-app") {- markedPaths.add(new URL(req.url).pathname);- }- });-- setup();-- // Wait for the guest bundle to have rendered — the SDK's bootstrap requests are- // still in flight while it loads, so asserting earlier races them.H.dataAppIframe(APP_DISPLAY_NAME).within(() => {- cy.findByTestId("isolation-result", { timeout: 30000 }).should("exist");- });-- // `/api/user/current` is the whole marked surface this fixture produces — it renders- // isolation probes, not questions, and the SDK's bootstrap takes site settings from- // the auth prefetch rather than refetching `/api/session/properties`.- cy.then(() => {- expect([...markedPaths], "requests marked as data-app").to.include(- "/api/user/current",+ cy.findByTestId("isolation-result", { timeout: 30000 }).should(+ "have.text",+ "pending",);});++ runProbes(["allowed-host-redirect"]);+ cy.wait("@allowedHostRedirect");});});diff --git a/e2e/test/scenarios/data-apps/sdk.cy.spec.ts b/e2e/test/scenarios/data-apps/sdk.cy.spec.tsindex cd36ffe053a..277f46fd9d7 100644--- a/e2e/test/scenarios/data-apps/sdk.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/sdk.cy.spec.ts@@ -35,7 +35,8 @@ describe("scenarios > data apps > SDK runtime", () => {},});- it("surfaces the useMetabaseQuery error state", () => {+ it("surfaces the useMetabaseQuery error state, and re-runs the query when the app calls refetch", () => {+ cy.intercept("POST", "/api/dataset").as("datasetQuery");setupQueryStatesApp();visitAppRoute("query-states");@@ -44,15 +45,7 @@ describe("scenarios > data apps > SDK runtime", () => {"have.text","error",);- });- });-- it("re-runs the query when the app calls refetch", () => {- cy.intercept("POST", "/api/dataset").as("datasetQuery");- setupQueryStatesApp();- visitAppRoute("query-states");- H.dataAppIframe(APP_DISPLAY_NAME).within(() => {// The query has to have resolved before refetching means anything.cy.findByTestId("query-value", { timeout: 30000 }).invoke("text")diff --git a/e2e/test/scenarios/data-apps/sync.cy.spec.ts b/e2e/test/scenarios/data-apps/sync.cy.spec.tsindex 35d9c0baf03..e45c87614d2 100644--- a/e2e/test/scenarios/data-apps/sync.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/sync.cy.spec.ts@@ -17,11 +17,10 @@ describe("scenarios > data apps > repo sync", () => {H.setupGitSync();});- it("materializes each app with its bundle", () => {+ it("materializes each app with its bundle, then removes an app whose files are removed from the repo on the next sync", () => {H.copySyncedCollectionFixture();H.copySyncedDataAppsFixture();H.commitToRepo("Add data apps");-H.configureGitAndPullChanges("read-write");cy.visit("/admin/settings/apps");@@ -57,13 +56,6 @@ describe("scenarios > data apps > repo sync", () => {.should("eq", app.resource_collection_id);expect(app.table_ids).to.deep.eq([ORDERS_ID]);});- });-- it("removes an app whose directory and collection files are removed from the repo on the next sync", () => {- H.copySyncedCollectionFixture();- H.copySyncedDataAppsFixture();- H.commitToRepo("Add data apps");- H.configureGitAndPullChanges("read-write");// An author deletes an app by deleting its directory and its collection's// files in one commit; the pull deletes the app, and the app deletes itsdiff --git a/e2e/test/scenarios/data-apps/user-access.cy.spec.ts b/e2e/test/scenarios/data-apps/user-access.cy.spec.tsindex ecaa4f6bf45..c7ce75dd8ca 100644--- a/e2e/test/scenarios/data-apps/user-access.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/user-access.cy.spec.ts@@ -42,59 +42,78 @@ describe("scenarios > data apps > authentication", () => {ALLOWED_HOST,);});+ cy.request(`/api/apps/${SYNCED_APP_SLUG}/bundle`).then((res) => {+ expect(+ String(res.headers["x-metabase-data-app-allowed-hosts"]),+ ).to.contain(ALLOWED_HOST);+ });cy.signOut();});- it("does not serve the iframe document or its allowed hosts", () => {+ it("does not serve the app, its bundle, its metadata or its allowed hosts", () => {cy.request({url: `/embed/apps/${SYNCED_APP_SLUG}`,failOnStatusCode: false,followRedirect: false,- }).then((res) => {- expect(res.status).to.eq(302);- expect(String(res.headers["location"])).to.contain("/auth/login");- expect(- String(res.headers["content-security-policy"] ?? ""),- ).not.to.contain(ALLOWED_HOST);- });- });-- it("does not put the allowed hosts on the top-level app page", () => {+ }).as("iframeDocument");cy.request({url: `/apps/${SYNCED_APP_SLUG}`,failOnStatusCode: false,followRedirect: false,- }).then((res) => {- // The SPA shell is still served; the React app sends the visitor to- // login. Anchor on it so a 404 or an empty response can't pass the- // negative check below.- expect(res.status).to.eq(200);- expect(String(res.headers["content-type"])).to.contain("text/html");- expect(res.headers["content-security-policy"]).to.be.a("string");- expect(res.headers["content-security-policy"]).not.to.contain(- ALLOWED_HOST,- );- });- });-- it("refuses the bundle and app metadata", () => {+ }).as("appPage");cy.request({url: `/api/apps/${SYNCED_APP_SLUG}/bundle`,failOnStatusCode: false,- }).then((res) => {- expect(res.status).to.eq(401);- expect(res.headers).not.to.have.property(- "x-metabase-data-app-allowed-hosts",- );- });-+ }).as("bundle");cy.request({url: `/api/apps/${SYNCED_APP_SLUG}`,failOnStatusCode: false,- })- .its("status")- .should("eq", 401);+ }).as("metadata");++ cy.then(function () {+ const iframeDocument: Cypress.Response<unknown> = this.iframeDocument;+ const appPage: Cypress.Response<unknown> = this.appPage;+ const bundle: Cypress.Response<unknown> = this.bundle;+ const metadata: Cypress.Response<unknown> = this.metadata;+ const appPageCsp = appPage.headers["content-security-policy"];++ // The SPA shell is still served for the app page; the React app sends+ // the visitor to login. Anchor on it so a 404 or an empty response can't+ // pass the negative checks.+ expect({+ iframeDocumentStatus: iframeDocument.status,+ iframeDocumentRedirectsToLogin: String(+ iframeDocument.headers["location"],+ ).includes("/auth/login"),+ iframeDocumentCspHasAllowedHost: String(+ iframeDocument.headers["content-security-policy"] ?? "",+ ).includes(ALLOWED_HOST),+ appPageStatus: appPage.status,+ appPageIsHtml: String(appPage.headers["content-type"]).includes(+ "text/html",+ ),+ appPageHasCsp: typeof appPageCsp === "string",+ appPageCspHasAllowedHost: String(appPageCsp ?? "").includes(+ ALLOWED_HOST,+ ),+ bundleStatus: bundle.status,+ bundleHasAllowedHostsHeader:+ "x-metabase-data-app-allowed-hosts" in bundle.headers,+ metadataStatus: metadata.status,+ }).to.deep.equal({+ iframeDocumentStatus: 302,+ iframeDocumentRedirectsToLogin: true,+ iframeDocumentCspHasAllowedHost: false,+ appPageStatus: 200,+ appPageIsHtml: true,+ appPageHasCsp: true,+ appPageCspHasAllowedHost: false,+ bundleStatus: 401,+ bundleHasAllowedHostsHeader: false,+ metadataStatus: 401,+ });+ });});});});diff --git a/e2e/test/scenarios/data-apps/viewing.cy.spec.ts b/e2e/test/scenarios/data-apps/viewing.cy.spec.tsindex ff3ea761cb4..fc9e1e7c1f4 100644--- a/e2e/test/scenarios/data-apps/viewing.cy.spec.ts+++ b/e2e/test/scenarios/data-apps/viewing.cy.spec.ts@@ -110,12 +110,22 @@ describe("scenarios > data apps > viewing & routing", () => {});describe("internal routing", () => {- it("mirrors internal route changes into the parent URL", () => {+ it("starts on a deep-linked sub-route, and mirrors link and imperative route changes into the parent URL", () => {H.mockDataApp(APP_NAME, {displayName: APP_DISPLAY_NAME,testEnv: TEST_ENV,});+ cy.log("deep-link directly to a sub-route");+ visitAppRoute("details");+ H.dataAppIframe(APP_DISPLAY_NAME).within(() => {+ cy.findByRole("heading", { name: "Order details" }).should(+ "be.visible",+ );+ cy.findByTestId("current-pathname").should("have.text", "/details");+ });++ cy.log("navigate with a DataAppLink");H.openDataApp(APP_NAME);H.dataAppIframe(APP_DISPLAY_NAME).within(() => {cy.findByRole("heading", { name: "Orders overview" }).should(@@ -133,29 +143,8 @@ describe("scenarios > data apps > viewing & routing", () => {// The iframe's client-side navigation is mirrored to the parent's URL bar// (via replaceState), so the top-level path reflects the nested route.cy.location("pathname").should("eq", `/apps/${APP_NAME}/details`);- });-- it("starts on the target page when deep-linked directly to a sub-route", () => {- H.mockDataApp(APP_NAME, {- displayName: APP_DISPLAY_NAME,- testEnv: TEST_ENV,- });-- visitAppRoute("details");- H.dataAppIframe(APP_DISPLAY_NAME).within(() => {- cy.findByRole("heading", { name: "Order details" }).should(- "be.visible",- );- cy.findByTestId("current-pathname").should("have.text", "/details");- });- });-- it("navigates imperatively via useDataAppLocation().navigate", () => {- H.mockDataApp(APP_NAME, {- displayName: APP_DISPLAY_NAME,- testEnv: TEST_ENV,- });+ cy.log("navigate imperatively via useDataAppLocation().navigate");H.openDataApp(APP_NAME);H.dataAppIframe(APP_DISPLAY_NAME).within(() => {cy.findByRole("heading", { name: "Orders overview" }).should(