Skip to content

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

2FA E2E tests (#77671)

Alexander Polyankin25eebabf11c6
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.edn
index 23153120b3f..3d5a90ca0b7 100644
--- a/.clj-kondo/config/modules/config.edn
+++ b/.clj-kondo/config/modules/config.edn
@@ -2342,6 +2342,7 @@
permissions
premium-features
search
+ session
util}
:model-imports #{:model/AiUsageLog
:model/Card
diff --git a/.clj-kondo/config/test-helpers/config.edn b/.clj-kondo/config/test-helpers/config.edn
index a1befed6ee1..44d0c9a4f48 100644
--- a/.clj-kondo/config/test-helpers/config.edn
+++ b/.clj-kondo/config/test-helpers/config.edn
@@ -36,6 +36,9 @@
;; Definitely thread safe
metabase.test.util.dynamic-redefs/patch-vars!
+ ;; test-only cleanup of in-memory throttle state (atom resets)
+ metabase.session.api/reset-throttlers-for-testing!
+
;; TODO: most of these symbols shouldn't be here, we should go through them and
;; find the functions/macros that use them and make sure their names end with !
;; best way to do this is try remove each of these and rely on kondo output to find places where it's used
diff --git a/bun.lock b/bun.lock
index a1dd3938662..456b35e1692 100644
--- a/bun.lock
+++ b/bun.lock
@@ -358,6 +358,7 @@
"open": "^10.1.0",
"open-cli": "^8.0.0",
"openapi-typescript": "^7.10.0",
+ "otpauth": "^9.5.1",
"oxfmt": "^0.38.0",
"patch-package": "^8.0.1",
"pg": "^8.8.0",
@@ -1232,7 +1233,7 @@
"@nicolo-ribaudo/eslint-scope-5-internals": ["@nicolo-ribaudo/[email protected]", "", { "dependencies": { "eslint-scope": "5.1.1" } }, "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg=="],
- "@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A=="],
+ "@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg=="],
"@nodable/entities": ["@nodable/[email protected]", "", {}, "sha512-nyT7T3nbMyBI/lvr6L5TyWbFJAI9FTgVRakNoBqCD+PmID8DzFrrNdLLtHMwMszOtqZa8PAOV24ZqDnQrhQINA=="],
@@ -4288,6 +4289,8 @@
"ospath": ["[email protected]", "", {}, "sha512-o6E5qJV5zkAbIDNhGSIlyOhScKXgQrSRMilfph0clDfM0nEnBOlKlH4sWDmG95BW/CvwNz0vmm7dJVtU2KlMiA=="],
+ "otpauth": ["[email protected]", "", { "dependencies": { "@noble/hashes": "2.2.0" } }, "sha512-fJmDAHc8wImfqqqOXIlBvT1dEKrZK0Cmb2VEgScpNTolCz0PHh6ExUZGv4sLtOsWNaHCQlD+rRqaPgnoxFoZjQ=="],
+
"outdent": ["[email protected]", "", {}, "sha512-KiOAIsdpUTcAXuykya5fnVVT+/5uS0Q1mrkRHcF89tpieSmY33O/tmc54CqwA+bfhbtEfZUNLHaPUiB9X3jt1A=="],
"outvariant": ["[email protected]", "", {}, "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA=="],
@@ -5826,6 +5829,8 @@
"@redocly/openapi-core/ajv": ["@redocly/[email protected]", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-BieiCML/IgP6x99HZByJSt7fJE4ipgzO7KAFss92Bs+PEI35BhY7vGIysFXLT+YmS7nHtQjZjhOQyPPEf7xGHA=="],
+ "@redocly/respect-core/@noble/hashes": ["@noble/[email protected]", "", {}, "sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A=="],
+
"@redocly/respect-core/ajv": ["@redocly/[email protected]", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-BieiCML/IgP6x99HZByJSt7fJE4ipgzO7KAFss92Bs+PEI35BhY7vGIysFXLT+YmS7nHtQjZjhOQyPPEf7xGHA=="],
"@redocly/respect-core/colorette": ["[email protected]", "", {}, "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w=="],
diff --git a/e2e/support/helpers/e2e-setup-helpers.js b/e2e/support/helpers/e2e-setup-helpers.js
index 6517ce1de2c..01283a80f0e 100644
--- a/e2e/support/helpers/e2e-setup-helpers.js
+++ b/e2e/support/helpers/e2e-setup-helpers.js
@@ -48,6 +48,12 @@ export function restore(name = "default") {
resetWritableDb({ type: dbType });
}
+ cy.request({
+ method: "POST",
+ url: "/api/testing/reset-throttlers",
+ failOnStatusCode: false,
+ });
+
return cy.request("POST", `/api/testing/restore/${name}`);
}
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
new file mode 100644
index 00000000000..f244d2bab72
--- /dev/null
+++ b/e2e/test/scenarios/admin-2/multi-factor-auth.cy.spec.ts
@@ -0,0 +1,352 @@
+const { H } = cy;
+import * as OTPAuth from "otpauth";
+
+import { USERS } from "e2e/support/cypress_data";
+import { NORMAL_USER_ID } from "e2e/support/cypress_sample_instance_data";
+
+const { normal } = USERS;
+
+const NEW_PASSWORD = "NewPassword2fa!123";
+
+type MaildevEmail = { subject: string; html: string };
+
+describe("scenarios > admin > settings > multi-factor authentication", () => {
+ beforeEach(() => {
+ H.restore();
+ H.clearInbox();
+ cy.signInAsAdmin();
+ H.activateToken("bleeding-edge");
+ cy.intercept("PUT", "/api/setting/mfa-enforcement").as("updateEnforcement");
+ cy.intercept("POST", "/api/ee/mfa/enroll").as("enroll");
+ });
+
+ it("admin can enable and disable 2FA in authentication settings", () => {
+ cy.visit("/admin/settings/authentication");
+ mfaSetting().scrollIntoView();
+ mfaSetting().findByText("Two-factor authentication").should("be.visible");
+ mfaToggle().should("not.be.checked").click();
+ cy.wait("@updateEnforcement");
+ mfaSetting()
+ .should("contain", "0 enrolled users")
+ .and("contain", "users without 2FA");
+
+ cy.log("Disable it again");
+ mfaToggle().should("be.checked").click();
+ cy.wait("@updateEnforcement");
+ mfaToggle().should("not.be.checked");
+ mfaSetting().should("not.contain", "enrolled");
+ });
+
+ it("user can set up 2FA in account settings and sign in with an authenticator code", () => {
+ let totpSecret = "";
+
+ enableMfa();
+
+ cy.log("User enrolls from account security settings");
+ cy.signInAsNormalUser();
+ cy.visit("/account/security");
+ cy.findByTestId("account-header")
+ .findByRole("tab", { name: "Security" })
+ .should("be.visible");
+ enrollViaUI().then((secret) => {
+ totpSecret = secret;
+ });
+ cy.findByRole("button", { name: "Disable" }).should("be.visible");
+ cy.findByRole("button", { name: "Generate recovery codes" }).should(
+ "be.visible",
+ );
+
+ cy.log("Signing in now requires an authenticator code");
+ signInWithPassword();
+ cy.findByTestId("login-page")
+ .findByText("Enter the 6-digit code from your authenticator app.")
+ .should("be.visible");
+ // The backend rejects a reused TOTP time step, so take the code for the
+ // next 30-second window — validation accepts one step of clock skew.
+ cy.then(() => generateTotpCode(totpSecret, Date.now() / 1000 + 30)).then(
+ (code) => {
+ cy.findByLabelText("Authenticator code").type(code);
+ },
+ );
+ cy.button("Verify").click();
+ cy.findByTestId("greeting-message").should("be.visible");
+ });
+
+ it("user can disable 2FA themselves and re-enroll", () => {
+ enableMfa();
+ enrollNormalUser().then(({ secret }) => {
+ cy.log("Disabling requires a fresh second factor, not just a password");
+ cy.visit("/account/security");
+ cy.findByRole("button", { name: "Disable" }).click();
+ H.modal().within(() => {
+ cy.findByText(
+ "Are you sure you want to disable two-factor authentication? Your account will be protected by your password only, and your recovery codes will stop working.",
+ ).should("be.visible");
+ cy.findByLabelText(
+ "Confirm with an authenticator code or a recovery code",
+ ).type(generateTotpCode(secret, Date.now() / 1000 + 30));
+ cy.button("Disable").click();
+ });
+ });
+ cy.findByRole("button", {
+ name: "Set up two-factor authentication",
+ }).should("be.enabled");
+
+ cy.log("Re-enroll from scratch with a new secret");
+ enrollViaUI();
+ cy.findByRole("button", { name: "Disable" }).should("be.visible");
+ });
+
+ it("recovery codes sign the user in once and regeneration invalidates the old set", () => {
+ enableMfa();
+ cy.intercept("POST", "/api/ee/mfa/recovery-codes").as("regenerate");
+
+ enrollNormalUser().then(({ secret, recoveryCodes }) => {
+ cy.log("Sign in with a recovery code instead of an authenticator code");
+ signInWithPassword();
+ cy.findByTestId("login-page")
+ .findByText("Use a recovery code instead")
+ .click();
+ cy.findByLabelText("Recovery code").type(recoveryCodes[0]);
+ cy.button("Verify").click();
+ cy.findByTestId("greeting-message").should("be.visible");
+
+ cy.log("Regenerate the recovery codes");
+ cy.visit("/account/security");
+ cy.findByRole("button", { name: "Generate recovery codes" }).click();
+ H.modal().within(() => {
+ cy.findByText(
+ "This will generate a new set of recovery codes and invalidate all of your old ones.",
+ ).should("be.visible");
+ cy.findByLabelText(
+ "Confirm with an authenticator code or a recovery code",
+ ).type(generateTotpCode(secret, Date.now() / 1000 + 30));
+ cy.button("Generate new codes").click();
+ cy.findByText("Your recovery codes").should("be.visible");
+ cy.button("Done").click();
+ });
+
+ cy.log("Old codes no longer work; new ones do");
+ cy.wait("@regenerate").then(({ response }) => {
+ const newCodes = response?.body.recovery_codes;
+ signInWithPassword();
+ cy.findByTestId("login-page")
+ .findByText("Use a recovery code instead")
+ .click();
+ cy.findByLabelText("Recovery code").type(recoveryCodes[1]);
+ cy.button("Verify").click();
+ cy.findByTestId("login-page")
+ .findByRole("alert")
+ .should("contain", "Invalid authentication code.");
+ cy.findByLabelText("Recovery code").clear().type(newCodes[0]);
+ // the submit button transiently reads "Failed" after the rejected
+ // attempt but stays clickable, so match either label
+ cy.button(/Verify|Failed/).click();
+ cy.findByTestId("greeting-message").should("be.visible");
+ });
+ });
+ });
+
+ it("an emailed one-time code works as a fallback second factor", () => {
+ enableMfa();
+ H.setupSMTP();
+ enrollNormalUser();
+
+ signInWithPassword();
+ cy.findByTestId("login-page")
+ .findByText("Enter the 6-digit code from your authenticator app.")
+ .should("be.visible");
+
+ cy.findByTestId("login-page").findByText("Email me a code").click();
+ cy.findByTestId("login-page")
+ .findByText("Code sent — check your email")
+ .should("be.visible");
+
+ H.getInbox().then(({ body: emails }: { body: MaildevEmail[] }) => {
+ const otpEmail = emails.find((email) =>
+ email.subject.includes("Your sign-in code"),
+ );
+ expect(otpEmail, "sign-in code email").to.exist;
+ const code = otpEmail?.html.match(/>\s*(\d{6})\s*</)?.[1];
+ expect(code, "6-digit code in the email body").to.be.a("string");
+ cy.findByLabelText("Authenticator code").type(String(code));
+ });
+ cy.button("Verify").click();
+ cy.findByTestId("greeting-message").should("be.visible");
+ });
+
+ it("resetting a forgotten password does not bypass the second factor", () => {
+ enableMfa();
+ H.setupSMTP();
+ enrollNormalUser().then(({ secret }) => {
+ cy.log("Request a reset link and set a new password");
+ cy.signOut();
+ cy.visit("/auth/forgot_password");
+ cy.findByLabelText("Email address").type(normal.email);
+ cy.button("Send password reset email").click();
+ cy.findByTestId("login-page")
+ .findByText(/If the email exists/)
+ .should("be.visible");
+
+ // the reset email is sent asynchronously and lands next to the "2FA
+ // enabled" notification from enrollment — wait for both to be there
+ H.getInbox(2).then(({ body: emails }: { body: MaildevEmail[] }) => {
+ const resetEmail = emails.find((email) =>
+ email.subject.includes("Password Reset"),
+ );
+ expect(resetEmail, "password reset email").to.exist;
+ cy.visit(getResetLink(String(resetEmail?.html)));
+ });
+ cy.findByLabelText("Create a password").type(NEW_PASSWORD);
+ cy.findByLabelText("Confirm your password").type(NEW_PASSWORD);
+ cy.button("Save new password").click();
+
+ cy.log("No session is minted — the new password still needs a code");
+ cy.url().should("contain", "/auth/login");
+ cy.findByLabelText("Email address").type(normal.email);
+ cy.findByLabelText("Password").type(NEW_PASSWORD);
+ cy.button("Sign in").click();
+ cy.findByTestId("login-page")
+ .findByText("Enter the 6-digit code from your authenticator app.")
+ .should("be.visible");
+ cy.then(() => generateTotpCode(secret, Date.now() / 1000 + 30)).then(
+ (code) => {
+ cy.findByLabelText("Authenticator code").type(code);
+ },
+ );
+ cy.button("Verify").click();
+ cy.findByTestId("greeting-message").should("be.visible");
+ });
+ });
+
+ it("an enrolled user is still challenged and can disable 2FA after the license lapses", () => {
+ enableMfa();
+ enrollNormalUser().then(({ secret, recoveryCodes }) => {
+ cy.log("Drop the premium token — the gate must fail closed");
+ cy.signInAsAdmin();
+ H.deleteToken();
+
+ signInWithPassword();
+ cy.findByTestId("login-page")
+ .findByText("Enter the 6-digit code from your authenticator app.")
+ .should("be.visible");
+ cy.then(() => generateTotpCode(secret, Date.now() / 1000 + 30)).then(
+ (code) => {
+ cy.findByLabelText("Authenticator code").type(code);
+ },
+ );
+ cy.button("Verify").click();
+ cy.findByTestId("greeting-message").should("be.visible");
+
+ cy.log("Managing the existing enrollment still works without a license");
+ cy.visit("/account/security");
+ cy.findByRole("button", { name: "Disable" }).click();
+ H.modal().within(() => {
+ cy.findByLabelText(
+ "Confirm with an authenticator code or a recovery code",
+ ).type(recoveryCodes[0]);
+ cy.button("Disable").click();
+ });
+
+ cy.log("Without the feature there is no way back into setup");
+ cy.url().should("contain", "/account/profile");
+ cy.visit("/account/security");
+ cy.findByRole("button", {
+ name: "Set up two-factor authentication",
+ }).should("be.disabled");
+ });
+ });
+
+ it("admin can remove a user's enrollment to unlock them", () => {
+ enableMfa();
+ enrollNormalUser();
+
+ cy.log("Admin sees the enrollment and removes it (lockout escape hatch)");
+ cy.signInAsAdmin();
+ cy.visit("/admin/settings/authentication");
+ mfaSetting().scrollIntoView().should("contain", "1 enrolled user");
+ cy.request("POST", "/api/ee/mfa/admin/remove", {
+ user_id: NORMAL_USER_ID,
+ });
+
+ cy.log("After the reset the user signs in with just a password");
+ signInWithPassword();
+ cy.findByTestId("greeting-message").should("be.visible");
+ cy.url().should("not.contain", "/auth/login");
+ });
+});
+
+function mfaSetting() {
+ return cy.findByTestId("mfa-setting");
+}
+
+function mfaToggle() {
+ return mfaSetting().findByLabelText(/Enabled|Disabled/);
+}
+
+function enableMfa() {
+ return cy.request("PUT", "/api/setting/mfa-enforcement", {
+ value: "optional",
+ });
+}
+
+function enrollNormalUser() {
+ cy.signInAsNormalUser();
+ return cy
+ .request("POST", "/api/ee/mfa/enroll", { password: normal.password })
+ .then(({ body: { secret } }) =>
+ cy
+ .request("POST", "/api/ee/mfa/enroll/confirm", {
+ code: generateTotpCode(secret, Date.now() / 1000),
+ })
+ .then(({ body: { recovery_codes } }) => ({
+ secret,
+ recoveryCodes: recovery_codes,
+ })),
+ );
+}
+
+function enrollViaUI(): Cypress.Chainable<string> {
+ cy.findByRole("button", {
+ name: "Set up two-factor authentication",
+ }).click();
+ H.modal().within(() => {
+ cy.findByLabelText("Confirm your password to begin").type(normal.password);
+ cy.button("Continue").click();
+ });
+ return cy.wait("@enroll").then(({ response }) => {
+ const secret = response?.body.secret;
+ H.modal().within(() => {
+ cy.findByLabelText(
+ "Enter the 6-digit code from the authenticator app",
+ ).type(generateTotpCode(secret, Date.now() / 1000));
+ cy.button("Set up authentication").click();
+ cy.findByText("Your recovery codes").should("be.visible");
+ cy.button("Done").click();
+ });
+ return cy.wrap(secret, { log: false });
+ });
+}
+
+function signInWithPassword() {
+ cy.signOut();
+ cy.visit("/auth/login");
+ cy.findByLabelText("Email address").type(normal.email);
+ cy.findByLabelText("Password").type(normal.password);
+ cy.button("Sign in").click();
+}
+
+function getResetLink(html: string) {
+ const [, anchor] = html.match(/<a (.*)>/) ?? [];
+ const [, href] = String(anchor).match(/href="([^"]+)"/) ?? [];
+ return String(href);
+}
+
+function generateTotpCode(secret: string, unixSeconds: number): string {
+ return new OTPAuth.TOTP({
+ secret: OTPAuth.Secret.fromBase32(secret),
+ algorithm: "SHA1",
+ digits: 6,
+ period: 30,
+ }).generate({ timestamp: unixSeconds * 1000 });
+}
diff --git a/enterprise/backend/src/metabase_enterprise/mfa/management.clj b/enterprise/backend/src/metabase_enterprise/mfa/management.clj
index 21c8631cc5d..5b3f4206f1c 100644
--- a/enterprise/backend/src/metabase_enterprise/mfa/management.clj
+++ b/enterprise/backend/src/metabase_enterprise/mfa/management.clj
@@ -46,6 +46,14 @@
[[(throttlers throttler-key) api/*current-user-id*]]
f))
+(premium-features/defenterprise reset-mfa-throttlers-for-testing!
+ "EE implementation: clear the accumulated state of the MFA management throttlers
+ (enroll/disable/regenerate). Only for the testing API — see [[metabase.testing-api.api]]."
+ :feature :none
+ []
+ (doseq [throttler (vals throttlers)]
+ (reset! (:attempts throttler) nil)))
+
(defn- verify-user-password
"Re-verify the signed-in user's first-factor password, dispatched by how they authenticate:
against the local hash for password users, by LDAP bind for LDAP-only users.
diff --git a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx
index bb08550f6dc..5c8f1fd753f 100644
--- a/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/multi_factor_auth/components/AdminAuthCard/AdminAuthCard.tsx
@@ -31,7 +31,7 @@ export function AdminAuthCard() {
};
return (
- <SettingsSection>
+ <SettingsSection data-testid="mfa-setting">
<SettingHeader
id="mfa-enforcement"
title={t`Two-factor authentication`}
diff --git a/package.json b/package.json
index d2950f7184c..db32c9bf972 100644
--- a/package.json
+++ b/package.json
@@ -367,6 +367,7 @@
"open": "^10.1.0",
"open-cli": "^8.0.0",
"openapi-typescript": "^7.10.0",
+ "otpauth": "^9.5.1",
"oxfmt": "^0.38.0",
"patch-package": "^8.0.1",
"pg": "^8.8.0",
diff --git a/src/metabase/session/api.clj b/src/metabase/session/api.clj
index 091ba17e4a2..46cf4951693 100644
--- a/src/metabase/session/api.clj
+++ b/src/metabase/session/api.clj
@@ -315,6 +315,19 @@
"Throttler for password_reset. There's no good field to mark so use password as a default."
(throttle/make-throttler :password :attempts-threshold 10))
+(defn reset-throttlers-for-testing!
+ "Clear the accumulated state of every login/verification throttler in this namespace. Throttler
+ state is in-memory with an hour-long `:attempt-ttl-ms`, so failed attempts survive an app-db
+ snapshot restore; the testing API (see [[metabase.testing-api.api]]) exposes this so E2E runs
+ can start from a clean slate."
+ []
+ (doseq [throttler (concat (vals login-throttlers)
+ (vals verify-throttlers)
+ (vals email-otp-send-throttlers)
+ (vals forgot-password-throttlers)
+ [reset-password-throttler])]
+ (reset! (:attempts throttler) nil)))
+
;; TODO (Cam 10/28/25) -- fix this endpoint route to use kebab-case for consistency with the rest of our REST API
;;
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
diff --git a/src/metabase/testing_api/api.clj b/src/metabase/testing_api/api.clj
index 15ce59b5f71..ec86683d371 100644
--- a/src/metabase/testing_api/api.clj
+++ b/src/metabase/testing_api/api.clj
@@ -21,6 +21,7 @@
[metabase.search.core :as search]
[metabase.search.ingestion :as search.ingestion]
[metabase.search.task.search-index :as task.search-index]
+ [metabase.session.api :as session.api]
[metabase.util.date-2 :as u.date]
[metabase.util.files :as u.files]
[metabase.util.json :as json]
@@ -244,6 +245,22 @@
metabase-enterprise.metabot.usage
[])
+(defenterprise reset-mfa-throttlers-for-testing!
+ "Clears the accumulated MFA management throttle state (enroll/disable/regenerate) on EE.
+ No-op on OSS."
+ metabase-enterprise.mfa.management
+ [])
+
+(api.macros/defendpoint :post "/reset-throttlers" :- [:map [:success [:= true]]]
+ "Reset all in-memory login/MFA throttle state. Throttlers count failed attempts for up to an
+ hour and are not touched by a snapshot restore, so repeated E2E runs that deliberately submit
+ wrong credentials or codes would otherwise trip \"Too many attempts\". Intended only for E2E
+ tests."
+ []
+ (session.api/reset-throttlers-for-testing!)
+ (reset-mfa-throttlers-for-testing!)
+ {:success true})
+
;; TODO (Cam 2025-11-25) please add a response schema to this API endpoint, it makes it easier for our customers to
;; use our API + we will need it when we make auto-TypeScript-signature generation happen
;;
diff --git a/test/metabase/session/api_test.clj b/test/metabase/session/api_test.clj
index 37dd128db84..374b4719ee3 100644
--- a/test/metabase/session/api_test.clj
+++ b/test/metabase/session/api_test.clj
@@ -33,9 +33,7 @@
(use-fixtures :once (fixtures/initialize :db :web-server :test-users))
(defn- reset-throttlers []
- (doseq [throttler (vals @#'api.session/login-throttlers)]
- (reset! (:attempts throttler) nil))
- (reset! (:attempts (var-get #'api.session/reset-password-throttler)) nil))
+ (api.session/reset-throttlers-for-testing!))
(use-fixtures :each (fn [f] (reset-throttlers) (f)))
diff --git a/test/metabase/testing_api/api_test.clj b/test/metabase/testing_api/api_test.clj
index 0204d65ecf3..35c191ccb4d 100644
--- a/test/metabase/testing_api/api_test.clj
+++ b/test/metabase/testing_api/api_test.clj
@@ -8,6 +8,7 @@
[metabase.app-db.core :as mdb]
[metabase.search.appdb.index :as search.index]
[metabase.search.core :as search]
+ [metabase.session.api :as session.api]
[metabase.test :as mt]
[metabase.testing-api.api :as testing]
[metabase.util :as u]
@@ -115,3 +116,14 @@
(mt/user-http-request :rasta :post 200 "testing/set-time")))))
(finally
(alter-var-root #'java-time.clock/*clock* (constantly nil)))))
+
+(deftest reset-throttlers-test
+ (let [throttler (:username @#'session.api/login-throttlers)]
+ (try
+ (reset! (:attempts throttler) (list ["[email protected]" (System/currentTimeMillis)]))
+ (testing "POST /api/testing/reset-throttlers clears accumulated throttle state"
+ (is (= {:success true}
+ (mt/user-http-request :rasta :post 200 "testing/reset-throttlers")))
+ (is (empty? @(:attempts throttler))))
+ (finally
+ (reset! (:attempts throttler) nil)))))