forked from metabase/metabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDK launch in core app (metabase#48107)
Co-authored-by: Oisin Coveney <oisin@metabase.com> Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev> Co-authored-by: bryan <bryan.maass@gmail.com> Co-authored-by: Nicolò Pretto <info@npretto.com>
- Loading branch information
1 parent
f03e6d8
commit 537ba41
Showing
131 changed files
with
4,919 additions
and
1,518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import jwt from "jsonwebtoken"; | ||
|
||
export function signJwt({ | ||
payload, | ||
secret, | ||
}: { | ||
payload: Record<string, string | number>; | ||
secret: string; | ||
}): string { | ||
return jwt.sign(payload, secret); | ||
} |
199 changes: 199 additions & 0 deletions
199
e2e/test/scenarios/embedding-sdk/static-dashboard-cors.cy.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import { USERS } from "e2e/support/cypress_data"; | ||
import { | ||
ORDERS_DASHBOARD_DASHCARD_ID, | ||
ORDERS_QUESTION_ID, | ||
} from "e2e/support/cypress_sample_instance_data"; | ||
import { | ||
getTextCardDetails, | ||
restore, | ||
setTokenFeatures, | ||
visitFullAppEmbeddingUrl, | ||
} from "e2e/support/helpers"; | ||
import { | ||
EMBEDDING_SDK_STORY_HOST, | ||
describeSDK, | ||
} from "e2e/support/helpers/e2e-embedding-sdk-helpers"; | ||
import { | ||
JWT_SHARED_SECRET, | ||
setupJwt, | ||
} from "e2e/support/helpers/e2e-jwt-helpers"; | ||
|
||
const STORYBOOK_ID = "embeddingsdk-cypressstaticdashboardwithcors--default"; | ||
describeSDK("scenarios > embedding-sdk > static-dashboard", () => { | ||
beforeEach(() => { | ||
restore(); | ||
cy.signInAsAdmin(); | ||
setTokenFeatures("all"); | ||
setupJwt(); | ||
|
||
const textCard = getTextCardDetails({ col: 16, text: "Text text card" }); | ||
const questionCard = { | ||
id: ORDERS_DASHBOARD_DASHCARD_ID, | ||
card_id: ORDERS_QUESTION_ID, | ||
row: 0, | ||
col: 0, | ||
size_x: 16, | ||
size_y: 8, | ||
visualization_settings: { | ||
"card.title": "Test question card", | ||
}, | ||
}; | ||
|
||
cy.createDashboard( | ||
{ | ||
name: "Embedding Sdk Test Dashboard", | ||
dashcards: [questionCard, textCard], | ||
}, | ||
{ wrapId: true }, | ||
); | ||
|
||
cy.intercept("GET", "/api/dashboard/*").as("getDashboard"); | ||
cy.intercept("GET", "/api/user/current").as("getUser"); | ||
cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as( | ||
"dashcardQuery", | ||
); | ||
|
||
cy.task("signJwt", { | ||
payload: { | ||
email: USERS.normal.email, | ||
exp: Math.round(Date.now() / 1000) + 10 * 60, // 10 minute expiration | ||
}, | ||
secret: JWT_SHARED_SECRET, | ||
}).then(jwtToken => { | ||
const ssoUrl = new URL("/auth/sso", Cypress.config().baseUrl); | ||
ssoUrl.searchParams.set("jwt", jwtToken); | ||
ssoUrl.searchParams.set("token", "true"); | ||
cy.request(ssoUrl.toString()).then(({ body }) => { | ||
cy.wrap(body).as("metabaseSsoResponse"); | ||
}); | ||
}); | ||
cy.get("@metabaseSsoResponse").then(ssoResponse => { | ||
cy.intercept("GET", "/sso/metabase", ssoResponse); | ||
}); | ||
}); | ||
|
||
it("should not render dashboard when embedding SDK is not enabled", () => { | ||
cy.request("PUT", "/api/setting", { | ||
"enable-embedding-sdk": false, | ||
}); | ||
cy.signOut(); | ||
|
||
cy.get("@dashboardId").then(dashboardId => { | ||
visitFullAppEmbeddingUrl({ | ||
url: EMBEDDING_SDK_STORY_HOST, | ||
qs: { id: STORYBOOK_ID, viewMode: "story" }, | ||
onBeforeLoad: window => { | ||
window.METABASE_INSTANCE_URL = Cypress.config().baseUrl; | ||
window.DASHBOARD_ID = dashboardId; | ||
}, | ||
}); | ||
}); | ||
|
||
cy.get("#metabase-sdk-root").within(() => { | ||
cy.findByText("Error").should("be.visible"); | ||
cy.findByText( | ||
"Could not authenticate: invalid JWT URI or JWT provider did not return a valid JWT token", | ||
).should("be.visible"); | ||
}); | ||
}); | ||
|
||
it("should show dashboard content", () => { | ||
cy.request("PUT", "/api/setting", { | ||
"enable-embedding-sdk": true, | ||
}); | ||
cy.signOut(); | ||
cy.get("@dashboardId").then(dashboardId => { | ||
visitFullAppEmbeddingUrl({ | ||
url: EMBEDDING_SDK_STORY_HOST, | ||
qs: { id: STORYBOOK_ID, viewMode: "story" }, | ||
onBeforeLoad: window => { | ||
window.METABASE_INSTANCE_URL = Cypress.config().baseUrl; | ||
window.DASHBOARD_ID = dashboardId; | ||
}, | ||
}); | ||
}); | ||
|
||
cy.wait("@getUser").then(({ response }) => { | ||
expect(response?.statusCode).to.equal(200); | ||
}); | ||
|
||
cy.wait("@getDashboard").then(({ response }) => { | ||
expect(response?.statusCode).to.equal(200); | ||
}); | ||
|
||
cy.get("#metabase-sdk-root") | ||
.should("be.visible") | ||
.within(() => { | ||
cy.findByText("Embedding Sdk Test Dashboard").should("be.visible"); // dashboard title | ||
|
||
cy.findByText("Text text card").should("be.visible"); // text card content | ||
|
||
cy.wait("@dashcardQuery"); | ||
cy.findByText("Test question card").should("be.visible"); // question card content | ||
}); | ||
}); | ||
|
||
it("should not render the SDK on non localhost sites when embedding SDK origins is not set", () => { | ||
cy.request("PUT", "/api/setting", { | ||
"enable-embedding-sdk": true, | ||
}); | ||
cy.signOut(); | ||
cy.get("@dashboardId").then(dashboardId => { | ||
visitFullAppEmbeddingUrl({ | ||
url: "http://my-site.local:6006/iframe.html", | ||
qs: { | ||
id: STORYBOOK_ID, | ||
viewMode: "story", | ||
}, | ||
onBeforeLoad: window => { | ||
window.METABASE_INSTANCE_URL = Cypress.config().baseUrl; | ||
window.DASHBOARD_ID = dashboardId; | ||
}, | ||
}); | ||
}); | ||
|
||
cy.get("#metabase-sdk-root").within(() => { | ||
cy.findByText("Error").should("be.visible"); | ||
cy.findByText( | ||
"Could not authenticate: invalid JWT URI or JWT provider did not return a valid JWT token", | ||
).should("be.visible"); | ||
}); | ||
}); | ||
|
||
it("should show dashboard content", () => { | ||
cy.request("PUT", "/api/setting", { | ||
"enable-embedding-sdk": true, | ||
"embedding-app-origins-sdk": "my-site.local:6006", | ||
}); | ||
cy.signOut(); | ||
cy.get("@dashboardId").then(dashboardId => { | ||
visitFullAppEmbeddingUrl({ | ||
url: "http://my-site.local:6006/iframe.html", | ||
qs: { id: STORYBOOK_ID, viewMode: "story" }, | ||
onBeforeLoad: window => { | ||
window.METABASE_INSTANCE_URL = Cypress.config().baseUrl; | ||
window.DASHBOARD_ID = dashboardId; | ||
}, | ||
}); | ||
}); | ||
|
||
cy.wait("@getUser").then(({ response }) => { | ||
expect(response?.statusCode).to.equal(200); | ||
}); | ||
|
||
cy.wait("@getDashboard").then(({ response }) => { | ||
expect(response?.statusCode).to.equal(200); | ||
}); | ||
|
||
cy.get("#metabase-sdk-root") | ||
.should("be.visible") | ||
.within(() => { | ||
cy.findByText("Embedding Sdk Test Dashboard").should("be.visible"); // dashboard title | ||
|
||
cy.findByText("Text text card").should("be.visible"); // text card content | ||
|
||
cy.wait("@dashcardQuery"); | ||
cy.findByText("Test question card").should("be.visible"); // question card content | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.