Skip to content

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

Uxw 4937 combine account password and security tabs (#79677)

Nick Fitzpatricke49a6d6754be
diff --git a/docs/people-and-groups/account-settings.md b/docs/people-and-groups/account-settings.md
index 50ae4fd81b6..4472de18418 100644
--- a/docs/people-and-groups/account-settings.md
+++ b/docs/people-and-groups/account-settings.md
@@ -1,80 +1,80 @@
----
-title: Account settings
-summary: Update your profile, change your password, view login history, manage notifications, and customize your Metabase experience.
-redirect_from:
- - /docs/latest/users-guide/account-settings
----
-
-# Account settings
-
-To access your account settings, click the **profile or grid icon** in the top right corner, then click your **profile name and email.**
-
-## Account profile
-
-You can set your first and last names, change your email address, and set your language. See our list of [supported languages](../configuring-metabase/localization.md).
-
-## Theme
-
-You can choose to display Metabase in light or dark mode.
-
-To quickly toggle dark mode, use the [command palette](../exploration-and-organization/exploration.md#command-palette).
-
-The theme only applies to your account. The theme doesn't apply to chart colors or embedded Metabases.
-
-## Account password
-
-You can change your password here. Note that if your Metabase uses Single Sign-On (SSO), your administrator will have disabled this password section, as your identity provider will manage logins.
-
-If you log in through LDAP, you won't see this password section either, since your directory manages your password. You may get a **Security** tab to enroll in 2FA if your admin has [turned it on](./two-factor-authentication.md#turn-on-two-factor-authentication).
-
-If you're having trouble logging in, see our [People can't log into Metabase](../troubleshooting-guide/cant-log-in.md).
-
-## Two-factor authentication
-
-{% include plans-blockquote.html feature="Two-factor authentication" %}
-
-If your admin has turned on [two-factor authentication](./two-factor-authentication.md) (2FA), you'll see a **Security** tab in your account settings. 2FA adds a second step to logging in: after your password, you enter a code from an authenticator app, so your password alone won't let someone into your account.
-
-### Set up two-factor authentication on your account
-
-1. Click the grid icon in the upper right.
-2. Click your profile.
-3. On the **Security** tab, click **Set up two-factor authentication**.
-4. Confirm your password.
-5. Scan the QR code with an authenticator app like Google Authenticator, 1Password, or Authy. If you can't scan it, enter the key manually in your authenticator app.
-6. Enter the six-digit code from the app.
-7. Save your recovery codes. Metabase shows these ten codes only once, so copy them and store them somewhere safe. Each recovery code only works once. If you [regenerate recovery codes](#regenerate-recovery-codes), the old codes will no longer work.
-
-### Logging in with two-factor authentication
-
-Once you set up two-factor authentication, Metabase will ask for a code every time you log in. After you enter your email and password:
-
-- Enter the six-digit code from your authenticator app.
-- Lost your app? Click **Use a recovery code instead** and enter one of your saved codes.
-- If your admin set up email, click **Email me a code** to get a one-time code in your inbox.
-
-### Regenerate recovery codes
-
-Recovery codes are single-use, so it's worth generating a fresh set if you're running low or think someone else has seen them. On the **Security** tab, click **Generate recovery codes** and confirm with a current authenticator or recovery code. Generating new codes invalidates the old ones.
-
-### Turn off two-factor authentication
-
-In your account settings, on the **Security** tab , click **Disable**. Your account will be protected by your password only, and your recovery codes will stop working.
-
-## Account login history
-
-The login history lists each login, along with some location information (if available), and some client information (like Browser (Firefox/Windows)). If you see any suspicious login attempts, change your password and notify your administrator.
-
-### A note about new login emails
-
-Whenever you log in from a new device, Metabase will send you an email just to let you know someone (presumably you) has logged in from an unrecognized device. If you see this email, but don't remember logging in, or don't recognize the device, change your password and let your administrator know.
-
-## Disable animations in Metabase
-
-This isn't an in-Metabase setting, but just so you know: you can disable UI animations in Metabase (like sidebars sliding around, or rotating spinners) by changing the settings for your operating system so it respects the `prefers-reduced-motion` CSS media feature. This change will also affect other applications, not just Metabase. Check out the instructions for how to set the user preferences for your operating system in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion#user_preferences).
-
-## Notifications
-
-If you subscribe or are added to dashboard subscriptions or alerts, you’ll be able to manage those notifications here (as well as on the relevant question or dashboard themselves).
-
-Metabase excludes notifications for [comments](../documents/introduction.md#comment-notifications) from this page.
+---
+title: Account settings
+summary: Update your profile, change your password, view login history, manage notifications, and customize your Metabase experience.
+redirect_from:
+ - /docs/latest/users-guide/account-settings
+---
+
+# Account settings
+
+To access your account settings, click the **profile or grid icon** in the top right corner, then click your **profile name and email.**
+
+## Account profile
+
+You can set your first and last names, change your email address, and set your language. See our list of [supported languages](../configuring-metabase/localization.md).
+
+## Theme
+
+You can choose to display Metabase in light or dark mode.
+
+To quickly toggle dark mode, use the [command palette](../exploration-and-organization/exploration.md#command-palette).
+
+The theme only applies to your account. The theme doesn't apply to chart colors or embedded Metabases.
+
+## Account password
+
+You can change your password here. Note that if your Metabase uses Single Sign-On (SSO), your administrator will have disabled this password section, as your identity provider will manage logins.
+
+If you log in through LDAP, you won't see this password section either, since your directory manages your password. You may get a **Authentication** tab to enroll in 2FA if your admin has [turned it on](./two-factor-authentication.md#turn-on-two-factor-authentication).
+
+If you're having trouble logging in, see our [People can't log into Metabase](../troubleshooting-guide/cant-log-in.md).
+
+## Two-factor authentication
+
+{% include plans-blockquote.html feature="Two-factor authentication" %}
+
+If your admin has turned on [two-factor authentication](./two-factor-authentication.md) (2FA), you'll see a **Authentication** tab in your account settings. 2FA adds a second step to logging in: after your password, you enter a code from an authenticator app, so your password alone won't let someone into your account.
+
+### Set up two-factor authentication on your account
+
+1. Click the grid icon in the upper right.
+2. Click your profile.
+3. On the **Authentication** tab, click **Set up two-factor authentication**.
+4. Confirm your password.
+5. Scan the QR code with an authenticator app like Google Authenticator, 1Password, or Authy. If you can't scan it, enter the key manually in your authenticator app.
+6. Enter the six-digit code from the app.
+7. Save your recovery codes. Metabase shows these ten codes only once, so copy them and store them somewhere safe. Each recovery code only works once. If you [regenerate recovery codes](#regenerate-recovery-codes), the old codes will no longer work.
+
+### Logging in with two-factor authentication
+
+Once you set up two-factor authentication, Metabase will ask for a code every time you log in. After you enter your email and password:
+
+- Enter the six-digit code from your authenticator app.
+- Lost your app? Click **Use a recovery code instead** and enter one of your saved codes.
+- If your admin set up email, click **Email me a code** to get a one-time code in your inbox.
+
+### Regenerate recovery codes
+
+Recovery codes are single-use, so it's worth generating a fresh set if you're running low or think someone else has seen them. On the **Authentication** tab, click **Generate recovery codes** and confirm with a current authenticator or recovery code. Generating new codes invalidates the old ones.
+
+### Turn off two-factor authentication
+
+In your account settings, on the **Authentication** tab , click **Disable**. Your account will be protected by your password only, and your recovery codes will stop working.
+
+## Account login history
+
+The login history lists each login, along with some location information (if available), and some client information (like Browser (Firefox/Windows)). If you see any suspicious login attempts, change your password and notify your administrator.
+
+### A note about new login emails
+
+Whenever you log in from a new device, Metabase will send you an email just to let you know someone (presumably you) has logged in from an unrecognized device. If you see this email, but don't remember logging in, or don't recognize the device, change your password and let your administrator know.
+
+## Disable animations in Metabase
+
+This isn't an in-Metabase setting, but just so you know: you can disable UI animations in Metabase (like sidebars sliding around, or rotating spinners) by changing the settings for your operating system so it respects the `prefers-reduced-motion` CSS media feature. This change will also affect other applications, not just Metabase. Check out the instructions for how to set the user preferences for your operating system in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion#user_preferences).
+
+## Notifications
+
+If you subscribe or are added to dashboard subscriptions or alerts, you’ll be able to manage those notifications here (as well as on the relevant question or dashboard themselves).
+
+Metabase excludes notifications for [comments](../documents/introduction.md#comment-notifications) from this page.
diff --git a/docs/people-and-groups/two-factor-authentication.md b/docs/people-and-groups/two-factor-authentication.md
index 46ca68690a4..a76a7a9ffa9 100644
--- a/docs/people-and-groups/two-factor-authentication.md
+++ b/docs/people-and-groups/two-factor-authentication.md
@@ -13,12 +13,12 @@ Metabase's native 2FA applies to password logins and LDAP logins. 2FA for Single
## Turn on two-factor authentication
-An admin can turn 2FA on for your Metabase:
-
-1. Go to **Admin settings** > **Settings** > **Authentication**.
-2. Find the **Two-factor authentication** card.
-3. Toggle it to **Enabled**.
-Once enabled, a **Security** tab shows up in each person's account settings, where they can enroll in 2FA.
+An admin can turn 2FA on for your Metabase:
+
+1. Go to **Admin settings** > **Settings** > **Authentication**.
+2. Find the **Two-factor authentication** card.
+3. Toggle it to **Enabled**.
+ Once enabled, a **Two-factor authentication** section shows up in each person's account settings under the **Authentication** tab, where they can enroll in 2FA.
If you configure Metabase through environment variables or a [config file](../configuring-metabase/config-file.md), the matching setting is [`MB_MFA_ENFORCEMENT`](../configuring-metabase/environment-variables.md#mb_mfa_enforcement). Set `MB_MFA_ENFORCEMENT` to `optional` to let people enroll, or `off` to turn 2FA off.
diff --git a/e2e/test/scenarios/admin-2/multi-factor-auth.cy.spec.ts b/e2e/test/scenarios/admin-2/multi-factor-auth.cy.spec.ts
index e8f7ba2ecce..53d28cc3c68 100644
--- a/e2e/test/scenarios/admin-2/multi-factor-auth.cy.spec.ts
+++ b/e2e/test/scenarios/admin-2/multi-factor-auth.cy.spec.ts
@@ -41,12 +41,19 @@ describe("scenarios > admin > settings > multi-factor authentication", () => {
enableMfa();
- cy.log("User enrolls from account security settings");
+ cy.log("User enrolls from account authentication settings");
cy.signInAsNormalUser();
+
+ cy.log("The old security URL lands on the combined Authentication tab");
cy.visit("/account/security");
+ cy.url().should("contain", "/account/authentication");
cy.findByTestId("account-header")
- .findByRole("tab", { name: "Security" })
+ .findByRole("tab", { name: "Authentication" })
.should("be.visible");
+
+ cy.log("Password and 2FA now share one tab");
+ cy.findByLabelText("Current password").should("be.visible");
+
enrollViaUI().then((secret) => {
totpSecret = secret;
});
@@ -75,7 +82,7 @@ describe("scenarios > admin > settings > multi-factor authentication", () => {
enableMfa();
enrollNormalUser().then(({ secret }) => {
cy.log("Disabling requires a fresh second factor, not just a password");
- cy.visit("/account/security");
+ cy.visit("/account/password");
cy.findByRole("button", { name: "Disable" }).click();
H.modal().within(() => {
cy.findByText(
@@ -111,7 +118,7 @@ describe("scenarios > admin > settings > multi-factor authentication", () => {
cy.findByTestId("greeting-message").should("be.visible");
cy.log("Regenerate the recovery codes");
- cy.visit("/account/security");
+ cy.visit("/account/password");
cy.findByRole("button", { name: "Generate recovery codes" }).click();
H.modal().within(() => {
cy.findByText(
@@ -238,7 +245,7 @@ describe("scenarios > admin > settings > multi-factor authentication", () => {
cy.findByTestId("greeting-message").should("be.visible");
cy.log("Managing the existing enrollment still works without a license");
- cy.visit("/account/security");
+ cy.visit("/account/authentication");
cy.findByRole("button", { name: "Disable" }).click();
H.modal().within(() => {
cy.findByLabelText(
@@ -248,8 +255,7 @@ describe("scenarios > admin > settings > multi-factor authentication", () => {
});
cy.log("Without the feature there is no way back into setup");
- cy.url().should("contain", "/account/profile");
- cy.visit("/account/security");
+ cy.url().should("contain", "/account/authentication");
cy.findByRole("button", {
name: "Set up two-factor authentication",
}).should("be.disabled");
@@ -377,7 +383,7 @@ function enrollViaUI(): Cypress.Chainable<string> {
cy.findByText("Your recovery codes").should("be.visible");
cy.button("Done").click();
});
- return cy.wrap(secret, { log: false });
+ return cy.wrap<string>(secret, { log: false });
});
}
diff --git a/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js b/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js
index 837d3988af2..696410f0f3b 100644
--- a/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js
@@ -53,13 +53,14 @@ describe("user > settings", () => {
cy.get("@membership.all").should("have.length", 0);
});
- it("should have a change password tab", () => {
+ it("should have an authentication tab", () => {
cy.intercept("GET", "/api/user/current").as("getUser");
cy.visit("/account/profile");
cy.wait("@getUser");
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Password").should("exist");
+ cy.findByTestId("account-header")
+ .findByRole("tab", { name: "Authentication" })
+ .should("be.visible");
});
it("should redirect to the login page when the user has signed out but tries to visit `/account/profile` (metabase#15471)", () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.tsx b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.tsx
index 9ec790faad2..3628343b23b 100644
--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.tsx
@@ -3,9 +3,7 @@ import { t } from "ttag";
import { DelayedLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper/DelayedLoadingAndErrorWrapper";
import { useHasTokenFeature } from "metabase/common/hooks";
-import { useNavigate } from "metabase/router";
import { Box, Button, Group, Stack } from "metabase/ui";
-import * as Urls from "metabase/urls";
import { useGetMfaStatusQuery } from "metabase-enterprise/api";
import type { MfaStatus } from "metabase-types/api";
@@ -19,21 +17,17 @@ export function AccountSecurityPanel() {
const { data: status, isLoading, error } = useGetMfaStatusQuery();
const [openedModal, setOpenedModal] = useState<SecurityModal | null>(null);
const hasFeature = useHasTokenFeature("multi-factor-auth");
- const navigate = useNavigate();
const handleCloseModal = () => setOpenedModal(null);
- const handleDisableSuccess = () => {
- setOpenedModal(null);
- if (!hasFeature) {
- navigate(Urls.accountSettings());
- }
- };
-
if (isLoading || error != null || status == null) {
return <DelayedLoadingAndErrorWrapper loading={isLoading} error={error} />;
}
+ if (!status.mfa_enabled) {
+ return null;
+ }
+
return (
<>
<MfaSection
@@ -48,7 +42,7 @@ export function AccountSecurityPanel() {
/>
<DisableModal
opened={openedModal === "disable"}
- onSuccess={handleDisableSuccess}
+ onSuccess={handleCloseModal}
onCancel={handleCloseModal}
/>
<RecoveryCodesModal
diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.unit.spec.tsx
index 91c8dfe444f..0708f263694 100644
--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AccountSecurityPanel/AccountSecurityPanel.unit.spec.tsx
@@ -5,7 +5,11 @@ import {
setupMfaStatusEndpointError,
} from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
-import { renderWithProviders, screen } from "__support__/ui";
+import {
+ renderWithProviders,
+ screen,
+ waitForLoaderToBeRemoved,
+} from "__support__/ui";
import { createMockState } from "metabase/redux/store/mocks";
import type { MfaStatus } from "metabase-types/api";
import {
@@ -103,6 +107,19 @@ describe("AccountSecurityPanel", () => {
).toBeInTheDocument();
});
+ it("should render nothing when the instance has two-factor authentication off", async () => {
+ setup({
+ status: createMockMfaStatus({ mfa_enabled: false, enrolled: true }),
+ });
+
+ await waitForLoaderToBeRemoved();
+
+ expect(
+ screen.queryByText("Two-factor authentication"),
+ ).not.toBeInTheDocument();
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
+ });
+
it("should show an error message when the status cannot be loaded", async () => {
setup({ hasStatusError: true });
diff --git a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx
index fb77ea5e702..232887d84e6 100644
--- a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx
+++ b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.tsx
@@ -21,28 +21,25 @@ export const AccountHeader = ({
path,
onChangeLocation,
}: AccountHeaderProps) => {
- const hasPasswordChange = useMemo(
+ const canChangePassword = useMemo(
() => PLUGIN_IS_PASSWORD_USER.every((predicate) => predicate(user)),
[user],
);
const mfaEnforcement = useSetting("mfa-enforcement");
const isMfaEnabled = mfaEnforcement != null && mfaEnforcement !== "off";
- const hasSecurityTab =
- isMfaEnabled && (hasPasswordChange || user.sso_source === "ldap");
+ const hasAuthenticationTab =
+ canChangePassword || (isMfaEnabled && user.sso_source === "ldap");
const tabs = useMemo(
() => [
{ name: t`Profile`, value: "/account/profile" },
- ...(hasPasswordChange
- ? [{ name: t`Password`, value: "/account/password" }]
- : []),
- ...(hasSecurityTab
- ? [{ name: t`Security`, value: "/account/security" }]
+ ...(hasAuthenticationTab
+ ? [{ name: t`Authentication`, value: "/account/password" }]
: []),
{ name: t`Login History`, value: "/account/login-history" },
{ name: t`Notifications`, value: "/account/notifications" },
],
- [hasPasswordChange, hasSecurityTab],
+ [hasAuthenticationTab],
);
const userFullName = getFullName(user);
diff --git a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx
index ac1183d4484..f404c9d8dc7 100644
--- a/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx
+++ b/frontend/src/metabase/account/app/components/AccountHeader/AccountHeader.unit.spec.tsx
@@ -1,19 +1,18 @@
import { mockSettings } from "__support__/settings";
import { fireEvent, renderWithProviders, screen } from "__support__/ui";
-import { PLUGIN_IS_PASSWORD_USER } from "metabase/plugins";
import { createMockState } from "metabase/redux/store/mocks";
import type { User } from "metabase-types/api";
import { createMockUser } from "metabase-types/api/mocks";
import { AccountHeader } from "./AccountHeader";
-const getUser = () =>
+const getUser = (opts?: Partial<User>) =>
createMockUser({
id: 1,
first_name: "John",
last_name: "Doe",
- sso_source: "google",
+ ...opts,
});
type SetupOpts = {
@@ -39,63 +38,75 @@ function setup({ user = getUser(), isMfaEnabled = false }: SetupOpts = {}) {
}
describe("AccountHeader", () => {
- const ORIGINAL_PLUGIN_IS_PASSWORD_USER = [...PLUGIN_IS_PASSWORD_USER];
-
- beforeEach(() => {
- PLUGIN_IS_PASSWORD_USER.splice(0);
- });
+ it("should show all tabs for a regular user", () => {
+ setup();
- afterEach(() => {
- PLUGIN_IS_PASSWORD_USER.splice(
- 0,
- PLUGIN_IS_PASSWORD_USER.length,
- ...ORIGINAL_PLUGIN_IS_PASSWORD_USER,
- );
+ expect(screen.getByRole("tab", { name: "Profile" })).toBeInTheDocument();
+ expect(
+ screen.getByRole("tab", { name: "Authentication" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("tab", { name: "Login History" }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("tab", { name: "Notifications" }),
+ ).toBeInTheDocument();
});
- it("should show all tabs for a regular user", () => {
- setup();
+ it("should change location when a tab is selected", () => {
+ const { onChangeLocation } = setup();
- expect(screen.getByText("Profile")).toBeInTheDocument();
- expect(screen.getByText("Password")).toBeInTheDocument();
- expect(screen.getByText("Login History")).toBeInTheDocument();
- expect(screen.getByText("Notifications")).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("tab", { name: "Profile" }));
+ expect(onChangeLocation).toHaveBeenCalledWith("/account/profile");
});
- it("should show the password tab if it is enabled by a plugin", () => {
- PLUGIN_IS_PASSWORD_USER.push((user) => user.sso_source === "google");
+ describe("authentication tab", () => {
+ it("should show the tab for a user who can change their password", () => {
+ setup({ user: getUser({ sso_source: null }) });
- setup();
+ expect(
+ screen.getByRole("tab", { name: "Authentication" }),
+ ).toBeInTheDocument();
+ });
- expect(screen.getByText("Password")).toBeInTheDocument();
- });
+ it("should show the tab for a password user when two-factor authentication is disabled for the instance", () => {
+ setup({ user: getUser({ sso_source: null }), isMfaEnabled: false });
- it("should hide the password tab if it is disabled by a plugin", () => {
- PLUGIN_IS_PASSWORD_USER.push((user) => user.sso_source !== "google");
+ expect(
+ screen.getByRole("tab", { name: "Authentication" }),
+ ).toBeInTheDocument();
+ });
- setup();
+ it("should hide the tab for an SSO user who cannot enroll in two-factor authentication", () => {
+ setup({ user: getUser({ sso_source: "google" }) });
- expect(screen.queryByText("Password")).not.toBeInTheDocument();
- });
+ expect(
+ screen.queryByRole("tab", { name: "Authentication" }),
+ ).not.toBeInTheDocument();
+ });
- describe("security tab", () => {
- it("should show the tab when two-factor authentication is enabled for the instance", () => {
- setup({ isMfaEnabled: true });
+ it("should hide the tab for an SSO user even when two-factor authentication is enabled for the instance", () => {
+ setup({ user: getUser({ sso_source: "google" }), isMfaEnabled: true });
- expect(screen.getByText("Security")).toBeInTheDocument();
+ expect(
+ screen.queryByRole("tab", { name: "Authentication" }),
+ ).not.toBeInTheDocument();
});
- it("should hide the tab when two-factor authentication is disabled for the instance", () => {
- setup({ isMfaEnabled: false });
+ it("should show the tab for an LDAP user when two-factor authentication is enabled for the instance", () => {
+ setup({ user: getUser({ sso_source: "ldap" }), isMfaEnabled: true });
- expect(screen.queryByText("Security")).not.toBeInTheDocument();
+ expect(
+ screen.getByRole("tab", { name: "Authentication" }),
+ ).toBeInTheDocument();
});
- });
- it("should change location when a tab is selected", () => {
- const { onChangeLocation } = setup();
+ it("should hide the tab for an LDAP user when two-factor authentication is disabled for the instance", () => {
+ setup({ user: getUser({ sso_source: "ldap" }), isMfaEnabled: false });
- fireEvent.click(screen.getByText("Profile"));
- expect(onChangeLocation).toHaveBeenCalledWith("/account/profile");
+ expect(
+ screen.queryByRole("tab", { name: "Authentication" }),
+ ).not.toBeInTheDocument();
+ });
});
});
diff --git a/frontend/src/metabase/account/password/containers/UserPasswordApp/UserPasswordApp.tsx b/frontend/src/metabase/account/password/containers/UserPasswordApp/UserPasswordApp.tsx
index d808bda48ec..0aaed934b43 100644
--- a/frontend/src/metabase/account/password/containers/UserPasswordApp/UserPasswordApp.tsx
+++ b/frontend/src/metabase/account/password/containers/UserPasswordApp/UserPasswordApp.tsx
@@ -1,14 +1,28 @@
+import { getIsSsoUser } from "metabase/account/selectors";
import { useValidatePassword } from "metabase/common/hooks";
+import { PLUGIN_MULTI_FACTOR_AUTH } from "metabase/plugins";
import { useSelector } from "metabase/redux";
import { getUser } from "metabase/selectors/user";
+import { Stack } from "metabase/ui";
import { checkNotNull } from "metabase/utils/types";
import { UserPasswordForm } from "../../components/UserPasswordForm";
const UserPasswordApp = () => {
const user = checkNotNull(useSelector(getUser));
+ const isSsoUser = useSelector(getIsSsoUser);
const validatePassword = useValidatePassword();
- return <UserPasswordForm user={user} onValidatePassword={validatePassword} />;
+
+ return (
+ <Stack gap="xl">
+ {!isSsoUser && (
+ <Stack gap="md">
+ <UserPasswordForm user={user} onValidatePassword={validatePassword} />
+ </Stack>
+ )}
+ <PLUGIN_MULTI_FACTOR_AUTH.AccountSecurityPanel />
+ </Stack>
+ );
};
// eslint-disable-next-line import/no-default-export -- deprecated usage
diff --git a/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/common.unit.spec.tsx b/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/common.unit.spec.tsx
new file mode 100644
index 00000000000..a1273bf884a
--- /dev/null
+++ b/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/common.unit.spec.tsx
@@ -0,0 +1,24 @@
+import { screen, waitForLoaderToBeRemoved } from "__support__/ui";
+import { createMockMfaStatus } from "metabase-types/api/mocks";
+
+import { setup } from "./setup";
+
+describe("UserPasswordApp (OSS)", () => {
+ it("should show the password form", () => {
+ setup();
+
+ expect(screen.getByLabelText("Current password")).toBeInTheDocument();
+ expect(screen.getByLabelText("Create a password")).toBeInTheDocument();
+ expect(screen.getByLabelText("Confirm your password")).toBeInTheDocument();
+ });
+
+ it("should not show two-factor authentication settings, even when the instance has it on", async () => {
+ setup({ mfaStatus: createMockMfaStatus({ mfa_enabled: true }) });
+
+ await waitForLoaderToBeRemoved();
+
+ expect(
+ screen.queryByText("Two-factor authentication"),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/enterprise.unit.spec.tsx b/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/enterprise.unit.spec.tsx
new file mode 100644
index 00000000000..e34803a4b0d
--- /dev/null
+++ b/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/enterprise.unit.spec.tsx
@@ -0,0 +1,46 @@
+import { screen, waitForLoaderToBeRemoved } from "__support__/ui";
+import { createMockMfaStatus, createMockUser } from "metabase-types/api/mocks";
+
+import { setup } from "./setup";
+
+describe("UserPasswordApp (EE)", () => {
+ it("should show two-factor authentication settings alongside the password form", async () => {
+ setup({
+ hasMfaPlugin: true,
+ tokenFeatures: { "multi-factor-auth": true },
+ });
+
+ expect(
+ await screen.findByText("Two-factor authentication"),
+ ).toBeInTheDocument();
+ expect(screen.getByLabelText("Current password")).toBeInTheDocument();
+ });
+
+ it("should not show two-factor authentication settings when the instance has it off", async () => {
+ setup({
+ hasMfaPlugin: true,
+ mfaStatus: createMockMfaStatus({ mfa_enabled: false, enrolled: true }),
+ tokenFeatures: { "multi-factor-auth": true },
+ });
+
+ await waitForLoaderToBeRemoved();
+
+ expect(
+ screen.queryByText("Two-factor authentication"),
+ ).not.toBeInTheDocument();
+ expect(screen.getByLabelText("Current password")).toBeInTheDocument();
+ });
+
+ it("should show only two-factor authentication settings for an LDAP user", async () => {
+ setup({
+ user: createMockUser({ sso_source: "ldap" }),
+ hasMfaPlugin: true,
+ tokenFeatures: { "multi-factor-auth": true },
+ });
+
+ expect(
+ await screen.findByText("Two-factor authentication"),
+ ).toBeInTheDocument();
+ expect(screen.queryByLabelText("Current password")).not.toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/setup.tsx b/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/setup.tsx
new file mode 100644
index 00000000000..87226f7b203
--- /dev/null
+++ b/frontend/src/metabase/account/password/containers/UserPasswordApp/tests/setup.tsx
@@ -0,0 +1,42 @@
+import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
+import { setupMfaStatusEndpoint } from "__support__/server-mocks";
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders } from "__support__/ui";
+import { createMockState } from "metabase/redux/store/mocks";
+import type { MfaStatus, TokenFeatures, User } from "metabase-types/api";
+import {
+ createMockMfaStatus,
+ createMockTokenFeatures,
+ createMockUser,
+} from "metabase-types/api/mocks";
+
+import UserPasswordApp from "../UserPasswordApp";
+
+type SetupOpts = {
+ user?: User;
+ mfaStatus?: MfaStatus;
+ hasMfaPlugin?: boolean;
+ tokenFeatures?: Partial<TokenFeatures>;
+};
+
+export function setup({
+ user = createMockUser(),
+ mfaStatus = createMockMfaStatus(),
+ hasMfaPlugin = false,
+ tokenFeatures = {},
+}: SetupOpts = {}) {
+ setupMfaStatusEndpoint(mfaStatus);
+
+ if (hasMfaPlugin) {
+ setupEnterpriseOnlyPlugin("multi_factor_auth");
+ }
+
+ renderWithProviders(<UserPasswordApp />, {
+ storeInitialState: createMockState({
+ currentUser: user,
+ settings: mockSettings({
+ "token-features": createMockTokenFeatures(tokenFeatures),
+ }),
+ }),
+ });
+}
diff --git a/frontend/src/metabase/account/profile/containers/UserProfileApp/UserProfileApp.tsx b/frontend/src/metabase/account/profile/containers/UserProfileApp/UserProfileApp.tsx
index e60f56aafa5..661a6c15bc1 100644
--- a/frontend/src/metabase/account/profile/containers/UserProfileApp/UserProfileApp.tsx
+++ b/frontend/src/metabase/account/profile/containers/UserProfileApp/UserProfileApp.tsx
@@ -1,3 +1,4 @@
+import { getIsSsoUser } from "metabase/account/selectors";
import { connect } from "metabase/redux";
import type { State } from "metabase/redux/store";
import { getUser } from "metabase/selectors/user";
@@ -5,7 +6,7 @@ import { checkNotNull } from "metabase/utils/types";
import { updateUser } from "../../actions";
import UserProfileForm from "../../components/UserProfileForm";
-import { getIsSsoUser, getLocales } from "../../selectors";
+import { getLocales } from "../../selectors";
const mapStateToProps = (state: State) => ({
user: checkNotNull(getUser(state)),
diff --git a/frontend/src/metabase/account/profile/selectors.ts b/frontend/src/metabase/account/profile/selectors.ts
index 27f9c204ccd..3d37ae55b4b 100644
--- a/frontend/src/metabase/account/profile/selectors.ts
+++ b/frontend/src/metabase/account/profile/selectors.ts
@@ -1,16 +1,7 @@
import { createSelector } from "@reduxjs/toolkit";
-import { PLUGIN_IS_PASSWORD_USER } from "metabase/plugins";
-import { getUser } from "metabase/selectors/user";
import { getSettings } from "metabase/settings";
-export const getIsSsoUser = createSelector(getUser, (user) => {
- if (!user) {
- return false;
- }
- return !PLUGIN_IS_PASSWORD_USER.every((predicate) => predicate(user));
-});
-
export const getLocales = createSelector([getSettings], (settings) => {
return settings["available-locales"];
});
diff --git a/frontend/src/metabase/account/routes.tsx b/frontend/src/metabase/account/routes.tsx
index 40d455546b7..0534962e6d1 100644
--- a/frontend/src/metabase/account/routes.tsx
+++ b/frontend/src/metabase/account/routes.tsx
@@ -1,6 +1,5 @@
import type { Store } from "@reduxjs/toolkit";
-import { PLUGIN_MULTI_FACTOR_AUTH } from "metabase/plugins";
import type { State } from "metabase/redux/store";
import { Route, type RouteComponent, redirect } from "metabase/router";
@@ -39,12 +38,11 @@ export const getAccountRoutes = (
<Route lazy={accountApp}>
<Route index element={redirect("profile")} />
<Route path="profile" lazy={userProfileApp} />
- <Route path="password" lazy={userPasswordApp} />
- <Route
- path="security"
- element={<PLUGIN_MULTI_FACTOR_AUTH.AccountSecurityPanel />}
- />
+ <Route path="authentication" lazy={userPasswordApp} />
<Route path="login-history" lazy={loginHistoryApp} />
+ {/* Legacy path redirects */}
+ <Route path="security" element={redirect("/account/authentication")} />
+ <Route path="password" element={redirect("/account/authentication")} />
{getNotificationRoutes()}
</Route>
</Route>
diff --git a/frontend/src/metabase/account/selectors.ts b/frontend/src/metabase/account/selectors.ts
new file mode 100644
index 00000000000..cbc190bcec6
--- /dev/null
+++ b/frontend/src/metabase/account/selectors.ts
@@ -0,0 +1,11 @@
+import { createSelector } from "@reduxjs/toolkit";
+
+import { PLUGIN_IS_PASSWORD_USER } from "metabase/plugins";
+import { getUser } from "metabase/selectors/user";
+
+export const getIsSsoUser = createSelector(getUser, (user) => {
+ if (!user) {
+ return false;
+ }
+ return !PLUGIN_IS_PASSWORD_USER.every((predicate) => predicate(user));
+});
diff --git a/frontend/src/metabase/auth/components/Login/tests/premium.unit.spec.tsx b/frontend/src/metabase/auth/components/Login/tests/premium.unit.spec.tsx
index 85aed6bc994..77926129a47 100644
--- a/frontend/src/metabase/auth/components/Login/tests/premium.unit.spec.tsx
+++ b/frontend/src/metabase/auth/components/Login/tests/premium.unit.spec.tsx
@@ -1,3 +1,4 @@
+import "metabase/auth/plugins";
import { screen } from "__support__/ui";
import { setup } from "./setup";
@@ -7,6 +8,7 @@ describe("Login", () => {
setup({
isPasswordLoginEnabled: false,
isGoogleAuthEnabled: true,
+ enterprisePlugins: ["auth"],
tokenFeatures: { disable_password_login: true },
});
diff --git a/frontend/test/__support__/enterprise-typed.ts b/frontend/test/__support__/enterprise-typed.ts
index 12bd09ffb55..3f92c2347df 100644
--- a/frontend/test/__support__/enterprise-typed.ts
+++ b/frontend/test/__support__/enterprise-typed.ts
@@ -52,6 +52,7 @@ export const ENTERPRISE_PLUGIN_NAME_MAPPING = {
google_drive: "metabase-enterprise/google_drive",
content_verification: "metabase-enterprise/content_verification",
moderation: "metabase-enterprise/moderation",
+ multi_factor_auth: "metabase-enterprise/multi_factor_auth",
tenants: "metabase-enterprise/tenants",
// Embedding SDK specific plugins
diff --git a/frontend/test/__support__/ui.tsx b/frontend/test/__support__/ui.tsx
index cf9e60ec72c..2580a623afe 100644
--- a/frontend/test/__support__/ui.tsx
+++ b/frontend/test/__support__/ui.tsx
@@ -27,6 +27,7 @@ import HTML5Backend from "react-dnd-html5-backend";
import { createPortal } from "react-dom";
import _ from "underscore";
+import "metabase/auth/plugins";
import { AppColorSchemeProvider } from "metabase/AppColorSchemeProvider";
import { AppKBarProvider } from "metabase/AppKBarProvider";
import { Api } from "metabase/api";