Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Implement SSO setup checklist locking for steps 2 and 3 until JWT is configured (#71345)

Nicolò Prettocfb3ab406c10
diff --git a/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.tsx b/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.tsx
index 52d7f5b966e..2ab4b3993e5 100644
--- a/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.tsx
+++ b/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.tsx
@@ -20,6 +20,9 @@ export const SetupSsoPage = () => {
const { data: checklistResponse } = useGetEmbeddingHubChecklistQuery();
const checklist = checklistResponse?.checklist;
+ // Prefer in-session success state; fall back to backend detection on reload.
+ const [isJwtConfigured, setIsJwtConfigured] = useState(false);
+
// UI-only confirmation state for step 2
const [isAddEndpointConfirmed, setIsAddEndpointConfirmed] = useState(false);
@@ -31,13 +34,22 @@ export const SetupSsoPage = () => {
const completedSteps = useMemo(() => {
const isSsoAuthManualTested =
checklist?.["sso-auth-manual-tested"] ?? false;
+ const isJwtSetupDone =
+ isJwtConfigured || (checklist?.["sso-configured"] ?? false);
return {
- "setup-jwt": checklist?.["sso-configured"] ?? false,
+ "setup-jwt": isJwtSetupDone,
"add-endpoint": isAddEndpointConfirmed || isSsoAuthManualTested,
"test-jwt": isSsoAuthManualTested,
};
- }, [checklist, isAddEndpointConfirmed]);
+ }, [checklist, isAddEndpointConfirmed, isJwtConfigured]);
+
+ const lockedSteps = useMemo(() => {
+ return {
+ "add-endpoint": !completedSteps["setup-jwt"],
+ "test-jwt": !completedSteps["setup-jwt"],
+ };
+ }, [completedSteps]);
return (
<Stack mx="auto" gap="sm" maw={680}>
@@ -55,13 +67,18 @@ export const SetupSsoPage = () => {
<OnboardingStepper
ref={stepperRef}
completedSteps={completedSteps}
- lockedSteps={{}}
+ lockedSteps={lockedSteps}
>
<OnboardingStepper.Step
stepId="setup-jwt"
title={t`Set up JWT authentication`}
>
- <SetupJwtStep onSuccess={() => stepperRef.current?.goToNextStep()} />
+ <SetupJwtStep
+ onSuccess={() => {
+ setIsJwtConfigured(true);
+ stepperRef.current?.goToNextStep();
+ }}
+ />
</OnboardingStepper.Step>
<OnboardingStepper.Step
diff --git a/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.unit.spec.tsx b/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.unit.spec.tsx
new file mode 100644
index 00000000000..8ed91c102c3
--- /dev/null
+++ b/frontend/src/metabase/embedding/embedding-hub/components/SetupSsoPage/SetupSsoPage.unit.spec.tsx
@@ -0,0 +1,135 @@
+import userEvent from "@testing-library/user-event";
+import fetchMock from "fetch-mock";
+import { Route } from "react-router";
+
+import {
+ findRequests,
+ setupPropertiesEndpoints,
+ setupUpdateSettingsEndpoint,
+} from "__support__/server-mocks";
+import { renderWithProviders, screen } from "__support__/ui";
+import type { EmbeddingHubChecklist } from "metabase/api/embedding-hub";
+import { createMockSettings } from "metabase-types/api/mocks";
+import {
+ createMockSettingsState,
+ createMockState,
+} from "metabase-types/store/mocks";
+
+import { SetupSsoPage } from "./SetupSsoPage";
+
+const defaultChecklist: EmbeddingHubChecklist = {
+ "add-data": false,
+ "configure-row-column-security": false,
+ "create-dashboard": false,
+ "create-tenants": false,
+ "create-test-embed": false,
+ "data-permissions-and-enable-tenants": false,
+ "embed-production": false,
+ "enable-tenants": false,
+ "move-dashboard-to-shared": false,
+ "setup-data-segregation-strategy": false,
+ "sso-auth-manual-tested": false,
+ "sso-configured": false,
+};
+
+const setup = ({
+ checklist = {},
+}: {
+ checklist?: Partial<EmbeddingHubChecklist>;
+} = {}) => {
+ const settings = createMockSettings();
+
+ setupPropertiesEndpoints(settings);
+ setupUpdateSettingsEndpoint();
+
+ fetchMock.get("path:/api/ee/embedding-hub/checklist", {
+ checklist: { ...defaultChecklist, ...checklist },
+ "data-isolation-strategy": null,
+ });
+ fetchMock.get("path:/api/util/random_token", {
+ token: "test-signing-key",
+ });
+
+ return renderWithProviders(
+ <Route path="/admin/embedding/setup-guide/sso" component={SetupSsoPage} />,
+ {
+ storeInitialState: createMockState({
+ settings: createMockSettingsState(settings),
+ }),
+ withRouter: true,
+ initialRoute: "/admin/embedding/setup-guide/sso",
+ },
+ );
+};
+
+describe("SetupSsoPage", () => {
+ it("locks steps 2 and 3 until JWT authentication is configured", async () => {
+ setup();
+
+ await screen.findByRole("button", {
+ name: "Enable JWT authentication and continue",
+ });
+
+ const addEndpointStep = screen.getByRole("listitem", {
+ name: "Add a new endpoint to your app",
+ });
+ const testJwtStep = screen.getByRole("listitem", {
+ name: "Test that JWT authentication is working correctly",
+ });
+
+ expect(addEndpointStep).toHaveAttribute("data-locked", "true");
+ expect(testJwtStep).toHaveAttribute("data-locked", "true");
+
+ await userEvent.click(addEndpointStep);
+
+ expect(
+ screen.getByRole("button", {
+ name: "Enable JWT authentication and continue",
+ }),
+ ).toBeVisible();
+ expect(screen.queryByText("JWT Signing Key")).not.toBeInTheDocument();
+ expect(
+ screen.queryByText("Try logging in with SSO. Did it work?"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("unlocks later steps immediately after step 1 succeeds", async () => {
+ setup();
+
+ const enableJwtButton = await screen.findByRole("button", {
+ name: "Enable JWT authentication and continue",
+ });
+
+ await userEvent.type(
+ screen.getByLabelText(/JWT Identity Provider URI/i),
+ "https://jwt.example.com/auth",
+ );
+ await userEvent.click(enableJwtButton);
+
+ expect(await screen.findByText("JWT Signing Key")).toBeVisible();
+
+ expect(
+ screen.getByRole("listitem", { name: "Set up JWT authentication" }),
+ ).toHaveAttribute("data-completed", "true");
+ expect(
+ screen.getByRole("listitem", { name: "Add a new endpoint to your app" }),
+ ).toHaveAttribute("data-locked", "false");
+ expect(
+ screen.getByRole("listitem", {
+ name: "Test that JWT authentication is working correctly",
+ }),
+ ).toHaveAttribute("data-locked", "false");
+
+ const puts = await findRequests("PUT");
+ expect(puts).toHaveLength(1);
+
+ const [{ url, body }] = puts;
+ expect(url).toContain("/api/setting");
+ expect(body).toEqual({
+ "jwt-identity-provider-uri": "https://jwt.example.com/auth",
+ "jwt-shared-secret": "test-signing-key",
+ "jwt-enabled": true,
+ "jwt-group-sync": true,
+ });
+ });
+});