Skip to content

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

[GDGT-3087] mount /api/email routes with auth middleware (#79807)

YB98ea8d0a0add
diff --git a/src/metabase/api_routes/routes.clj b/src/metabase/api_routes/routes.clj
index 2df28749a0e..ad717565164 100644
--- a/src/metabase/api_routes/routes.clj
+++ b/src/metabase/api_routes/routes.clj
@@ -195,7 +195,7 @@
"/docs" (metabase.api.docs/make-routes #'routes)
"/document" (+auth metabase.documents.api/routes)
"/eid-translation" (+auth 'metabase.eid-translation.api)
- "/email" metabase.channel.api/email-routes
+ "/email" (+auth metabase.channel.api/email-routes)
"/embed" (+message-only-exceptions metabase.embedding-rest.api/embedding-routes)
"/embed-mcp" (+auth metabase.mcp.callback-api/routes)
"/embed-theme" (+auth metabase.embedding-rest.api/theme-routes)
diff --git a/test/metabase/channel/api/email_test.clj b/test/metabase/channel/api/email_test.clj
index 2da8081d64f..57a15ed2d3b 100644
--- a/test/metabase/channel/api/email_test.clj
+++ b/test/metabase/channel/api/email_test.clj
@@ -154,3 +154,17 @@
:email-smtp-username nil
:email-smtp-password nil}
(email-settings)))))))))
+
+(deftest endpoints-require-authentication-test
+ ;; +auth must reject before the handler's :setting permission check, so anon callers
+ ;; get 401 rather than 403.
+ (testing "/api/email endpoints reject unauthenticated callers"
+ (testing "PUT /api/email"
+ (is (= "Unauthenticated"
+ (mt/client :put 401 "email" default-email-settings))))
+ (testing "DELETE /api/email"
+ (is (= "Unauthenticated"
+ (mt/client :delete 401 "email"))))
+ (testing "POST /api/email/test"
+ (is (= "Unauthenticated"
+ (mt/client :post 401 "email/test"))))))