The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Move slack connect tests over to oss + fix API routes (#71525)
Noah Moss7089932b8953
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 5afb83cddf9..2092d13ead0 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -2651,7 +2651,6 @@:api #{}:uses #{driverpremium-features- ssoenterprise/advanced-configenterprise/scimenterprise/semantic-search@@ -3344,6 +3343,7 @@"test[-.]dataset" ; anything that contains `test.dataset` or `test-dataset`"test\\.impl" ; anything that contains `test.impl`"test-setup" ; anything that contains `test-setup`+ "test[-_]helpers" ; anything that contains `test-helpers` or `test_helpers`"^metabase(?:-enterprise)?\\.test"}}}} ; anything starting with `metabase.test` or `metabase-enterprise.test`;; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!diff --git a/enterprise/backend/src/metabase_enterprise/analytics/stats.clj b/enterprise/backend/src/metabase_enterprise/analytics/stats.cljindex 42b4e3939d9..fdc5a2929f7 100644--- a/enterprise/backend/src/metabase_enterprise/analytics/stats.clj+++ b/enterprise/backend/src/metabase_enterprise/analytics/stats.clj@@ -6,7 +6,6 @@[metabase-enterprise.sso.settings :as ee-sso-settings][metabase.driver :as driver][metabase.premium-features.core :as premium-features :refer [defenterprise]]- [metabase.sso.settings :as sso-settings][toucan2.core :as t2]))(defenterprise ee-snowplow-features-data@@ -20,9 +19,6 @@{:name :sso-saml:available (premium-features/enable-sso-saml?):enabled (ee-sso-settings/saml-enabled)}- {:name :sso-slack- :available (premium-features/enable-sso-slack?)- :enabled (sso-settings/slack-connect-enabled)}{:name :scim:available (premium-features/enable-scim?):enabled (boolean (scim/scim-enabled))}diff --git a/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj b/enterprise/backend/src/metabase_enterprise/sso/api/sso.cljindex 4fd75703c35..0e97b9dfd8b 100644--- a/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj+++ b/enterprise/backend/src/metabase_enterprise/sso/api/sso.clj@@ -12,7 +12,6 @@[metabase.api.macros :as api.macros][metabase.request.core :as request][metabase.session.core :as session]- [metabase.sso.integrations.slack-connect :as slack-connect-integration][metabase.system.core :as system][metabase.util :as u][metabase.util.log :as log]@@ -151,30 +150,6 @@(log/error e "Error handling SLO")(sso-error-page e :out))))-;; GET /auth/sso/slack-connect-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/slack-connect"- "Initiate Slack Connect SSO flow."- [_route-params _query-params _body request]- (try- (slack-connect-integration/sso-initiate request)- (catch Throwable e- (log/error e "Error initiating Slack Connect SSO")- (throw e))))--;; GET /auth/sso/slack-connect/callback-;;-#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/slack-connect/callback"- "Slack Connect OIDC callback."- [_route-params _query-params _body request]- (try- (slack-connect-integration/sso-callback request)- (catch Throwable e- (log/error e "Error handling Slack Connect callback")- (throw e))))-;; Key schema that excludes `/` so /:key does not greedily match /:key/callback(def ^:private ProviderKey[:string {:api/regex #"[a-z0-9][a-z0-9-]*"}])diff --git a/enterprise/backend/test/metabase_enterprise/api/session_test.clj b/enterprise/backend/test/metabase_enterprise/api/session_test.cljindex dcbe1a63125..f4bd95e4326 100644--- a/enterprise/backend/test/metabase_enterprise/api/session_test.clj+++ b/enterprise/backend/test/metabase_enterprise/api/session_test.clj@@ -44,7 +44,6 @@:sso-ldap:sso-oidc:sso-saml- :sso-slack:support-users:transforms-basic:transforms-python@@ -90,7 +89,6 @@:sso_ldap true:sso_oidc true:sso_saml true- :sso_slack true:support-users true:table_data_editing false:transforms-basic truediff --git a/enterprise/backend/test/metabase_enterprise/sso/integrations/slack_connect_test.clj b/enterprise/backend/test/metabase_enterprise/sso/integrations/slack_connect_test.cljindex 7ad7b96ef45..bd93040a7b8 100644--- a/enterprise/backend/test/metabase_enterprise/sso/integrations/slack_connect_test.clj+++ b/enterprise/backend/test/metabase_enterprise/sso/integrations/slack_connect_test.clj@@ -1,354 +1,29 @@(ns metabase-enterprise.sso.integrations.slack-connect-test+ "EE-specific tests for Slack Connect that require EE SSO types like SAML."(:require[clojure.string :as str][clojure.test :refer :all]- [metabase-enterprise.sso.test-setup :as sso.test-setup]- [metabase.auth-identity.core :as auth-identity]- [metabase.sso.oidc.state :as oidc.state]- [metabase.sso.settings :as sso-settings]+ [metabase.sso.integrations.slack-connect-test :as slack-connect-test]+ [metabase.sso.test-helpers :as sso.test-helpers][metabase.test :as mt]- [metabase.test.fixtures :as fixtures]- [metabase.test.http-client :as client]- [metabase.util.encryption :as encryption]- [methodical.core :as methodical]- [ring.util.codec :as codec]- [toucan2.core :as t2]))+ [metabase.test.fixtures :as fixtures]))(set! *warn-on-reflection* true)(use-fixtures :once (fixtures/initialize :test-users))--(def ^:private test-encryption-key- "Test encryption key for OIDC state encryption."- "Orw0AAyzkO/kPTLJRxiyKoBHXa/d6ZcO+p+gpZO/wSQ=")--(def ^:private test-secret- "Hashed test encryption key."- (encryption/secret-key->hash test-encryption-key))--(defmacro ^:private with-test-encryption!- "Wraps body with test encryption key enabled. Use for tests that involve OIDC state cookies."- [& body]- `(with-redefs [encryption/default-secret-key test-secret]- ~@body))--(defn- do-with-url-prefix-disabled- "Test fixture that disables API URL prefix."- [thunk]- (binding [client/*url-prefix* ""]- (thunk)))--(use-fixtures :each do-with-url-prefix-disabled)--(def ^:private default-redirect-uri "/")--(methodical/defmethod auth-identity/authenticate :provider/test-successful-oidc- [_provider request]- (if (some #(contains? request %) [:code :error :state])- {:success? true- :claims {}- :user-data {:email "[email protected]"}- :provider-id "test-provider-id"}- {:success? :redirect- :redirect-url "http://example.com/slack"- :state "test-state"- :nonce "test-nonce"}))--(methodical/prefer-method! #'auth-identity/authenticate :provider/test-successful-oidc :provider/oidc)--(defmacro ^:private with-successful-oidc! [& body]- `(do- (derive :provider/slack-connect :provider/test-successful-oidc)- ~@body- (underive :provider/slack-connect :provider/test-successful-oidc)))--;;; -------------------------------------------------- Prerequisites Tests ----------------------------------------------------(deftest sso-prereqs-test- (with-test-encryption!- (sso.test-setup/do-with-other-sso-types-disabled!- (fn []- (testing "SSO requests fail if Slack Connect hasn't been configured or enabled"- (mt/with-temporary-setting-values- [slack-connect-enabled false- slack-connect-client-id nil- slack-connect-client-secret nil]- (is (= "Slack Connect is not enabled"- (mt/client :get 400 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}})))))-- (testing "SSO requests fail if Slack Connect is enabled but hasn't been configured"- (mt/with-temporary-setting-values- [slack-connect-enabled true- slack-connect-client-id nil]- (is (= "Slack Connect is not enabled"- (mt/client :get 400 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}})))))-- (testing "SSO requests fail if Slack Connect is configured but hasn't been enabled"- (mt/with-temporary-setting-values- [slack-connect-enabled false- slack-connect-client-id "test-slack-client-id"- slack-connect-client-secret "test-slack-client-secret"]- (is (= "Slack Connect is not enabled"- (mt/client :get 400 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}})))))-- (testing "The client secret must also be included for SSO to be configured"- (mt/with-temporary-setting-values- [slack-connect-enabled true- slack-connect-client-id "test-slack-client-id"- slack-connect-client-secret nil]- (is (= "Slack Connect is not enabled"- (mt/client :get 400 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}})))))))))--;;; -------------------------------------------------- Redirect Tests ----------------------------------------------------(deftest redirect-test- (testing "with Slack Connect configured, a GET request should result in a redirect to Slack"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (with-successful-oidc!- (let [result (mt/client-full-response :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)- redirect-url (get-in result [:headers "Location"])- oidc-state-cookie (->> (get-in result [:headers "Set-Cookie"])- (filter #(str/includes? % "metabase.OIDC_STATE"))- first)]- (is (str/starts-with? redirect-url "http://example.com/slack"))- (testing "OIDC state is stored in encrypted cookie"- (is (some? oidc-state-cookie))- ;; Verify the cookie contains encrypted data (base64-like)- (let [cookie-value (second (re-find #"metabase\.OIDC_STATE=([^;]+)" oidc-state-cookie))]- (is (some? cookie-value))- ;; Decrypt and verify contents (URL-decode since base64 chars +/= are encoded in cookies)- (let [state-data (oidc.state/decrypt-state (codec/url-decode cookie-value))]- (is (= "test-state" (:state state-data)))- (is (= "test-nonce" (:nonce state-data)))- (is (= "/" (:redirect state-data)))- (is (= "slack-connect" (:provider state-data))))))))))))+(use-fixtures :each slack-connect-test/do-with-url-prefix-disabled)(deftest multiple-sso-methods-test(testing "with SAML and Slack Connect configured, a GET request to /auth/sso/slack-connect should redirect to Slack"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!+ (slack-connect-test/with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!(mt/with-temporary-setting-values- [saml-enabled true- saml-identity-provider-uri "http://test.idp.metabase.com"+ [saml-enabled true+ saml-identity-provider-uri "http://test.idp.metabase.com"saml-identity-provider-certificate (slurp "test_resources/sso/auth0-public-idp.cert")]- (with-successful-oidc!- (let [result (mt/client-full-response :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)+ (slack-connect-test/with-successful-oidc!+ (let [result (mt/client-full-response :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect slack-connect-test/default-redirect-uri)redirect-url (get-in result [:headers "Location"])](is (str/starts-with? redirect-url "http://example.com/slack")))))))))--;;; -------------------------------------------------- POST Not Allowed Tests ----------------------------------------------------(deftest post-not-allowed-test- (testing "slack-connect is no longer available via the old POST /auth/sso multimethod dispatch"- (sso.test-setup/with-slack-default-setup!- ;; The old endpoint returned 405 via the defmethod sso-post :slack-connect.- ;; Now that slack-connect has been removed from the multimethod dispatch and- ;; uses dedicated GET routes, POSTing with preferred_method=slack-connect- ;; should no longer reach slack-connect code. With no other SSO enabled,- ;; the default dispatch returns "SSO has not been enabled and/or configured".- (is (some? (mt/client :post 400 "/auth/sso"- {:request-options {:content-type :x-www-form-urlencoded}}))))))--;;; -------------------------------------------------- Callback Tests ----------------------------------------------------(deftest callback-state-validation-test- (testing "callback should fail if state cookie is missing"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (let [response (mt/client-full-response :get 401 "/auth/sso/slack-connect/callback"- {:request-options {:redirect-strategy :none}}- :code "test-code"- :state "some-state")]- ;; Without a state cookie, the callback fails with invalid/expired state error- (is (str/includes? (:body response) "OIDC state cookie is invalid, expired, or missing")))))))--(deftest callback-state-validation-csrf-test- (testing "callback with mismatched state should indicate possible CSRF attack"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (with-successful-oidc!- ;; First, initiate auth to set state cookie- (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)- ;; Convert Set-Cookie headers to Cookie header format (extract name=value parts)- set-cookies (get-in init-response [:headers "Set-Cookie"])- cookie-header (->> set-cookies- (map #(first (str/split % #";"))) ; Extract name=value before first ;- (str/join "; "))- response (mt/client-real-response :get 401 "/auth/sso/slack-connect/callback"- {:request-options {:redirect-strategy :none- :headers {"Cookie" cookie-header}}}- :code "test-code"- :state "wrong-state")]- ;; State mismatch should indicate possible CSRF attack- (is (str/includes? (str (:body response)) "CSRF"))))))))--(deftest happy-path-callback-test- (testing "successful callback with valid code and state"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (with-successful-oidc!- ;; First, initiate auth to set state cookie- (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)- ;; Convert Set-Cookie headers to Cookie header format- set-cookies (get-in init-response [:headers "Set-Cookie"])- cookie-header (->> set-cookies- (map #(first (str/split % #";")))- (str/join "; "))- response (mt/client-real-response :get 302 "/auth/sso/slack-connect/callback"- {:request-options {:redirect-strategy :none- :headers {"Cookie" cookie-header}}}- :code "test-code"- :state "test-state")]- (is (sso.test-setup/successful-login? response))- (is (= default-redirect-uri (get-in response [:headers "Location"])))))))))--;;; -------------------------------------------------- Link-Only Mode Tests ----------------------------------------------------(deftest link-only-mode-requires-session-test- (testing "link-only mode should require authenticated session for initial request"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (mt/with-temporary-setting-values- [slack-connect-authentication-mode "link-only"]- (let [response (mt/client-full-response :get 401 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)]- (is (str/includes? (str (get response :body)) "authenticated session"))))))))--(deftest link-only-mode-with-session-test- (testing "link-only mode should work with authenticated session"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (mt/with-temporary-setting-values- [slack-connect-authentication-mode "link-only"]- (with-successful-oidc!- (let [response (mt/user-http-request-full-response- :rasta :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)]- (is (str/starts-with? (get-in response [:headers "Location"]) "http://example.com/slack")))))))))--;;; -------------------------------------------------- Open Redirect Protection Tests ----------------------------------------------------(deftest no-open-redirect-test- (testing "Check that we prevent open redirects to untrusted sites"- (sso.test-setup/with-slack-default-setup!- (doseq [redirect-uri ["https://badsite.com"- "//badsite.com"- "https:///badsite.com"]]- (let [result (mt/client :get 400 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect redirect-uri)]- (is (str/includes? (str (or (:message result) result)) "Invalid redirect URL")))))))--;;; -------------------------------------------------- User Provisioning Tests ----------------------------------------------------(deftest create-new-account-test- (testing "A new account will be created for a Slack user we haven't seen before"- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (mt/with-model-cleanup [:model/User]- (with-successful-oidc!- (t2/delete! :model/User :email "[email protected]")- (letfn [(new-user-exists? []- (boolean (seq (t2/select :model/User :%lower.email "[email protected]"))))]- (is (false? (new-user-exists?)))- ;; Initiate auth- (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)- ;; Convert Set-Cookie headers to Cookie header format- set-cookies (get-in init-response [:headers "Set-Cookie"])- cookie-header (->> set-cookies- (map #(first (str/split % #";")))- (str/join "; "))- response (mt/client-real-response :get 302 "/auth/sso/slack-connect/callback"- {:request-options {:redirect-strategy :none- :headers {"Cookie" cookie-header}}}- :code "test-code"- :state "test-state")]- ;; Complete callback- (is (sso.test-setup/successful-login? response))- (let [new-user (t2/select-one :model/User :email "[email protected]")]- (testing "new user"- (is- (=- {:email "[email protected]"- :first_name nil- :is_qbnewb true- :is_superuser false- :id true- :last_name nil- :date_joined true- :common_name "[email protected]"- :tenant_id false- :is_data_analyst false}- (-> (mt/boolean-ids-and-timestamps [new-user])- first- (dissoc :last_login)))))- (testing "User Invite Event is logged."- (is- (= "[email protected]"- (get-in (mt/latest-audit-log-entry :user-invited (:id new-user))- [:details :email])))))))))))))--(deftest create-new-slack-user-no-user-provisioning-test- (testing "When user provisioning is disabled, throw an error if we attempt to create a new user."- (with-test-encryption!- (sso.test-setup/with-slack-default-setup!- (mt/with-temporary-setting-values [slack-connect-user-provisioning-enabled false- site-name "test"]- (with-successful-oidc!- (with-redefs [auth-identity/login!- (fn [_provider _request]- {:success? false- :error :user-provisioning-disabled- :message "Sorry, but you'll need a test account to view this page. Please contact your administrator."})]- ;; Initiate auth- (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"- {:request-options {:redirect-strategy :none}}- :redirect default-redirect-uri)- set-cookies (get-in init-response [:headers "Set-Cookie"])- cookie-header (->> set-cookies- (map #(first (str/split % #";")))- (str/join "; "))]- ;; Try callback - should fail- (mt/client-real-response :get 401 "/auth/sso/slack-connect/callback"- {:request-options {:redirect-strategy :none- :headers {"Cookie" cookie-header}}}- :code "test-code"- :state "test-state")))))))))--;;; -------------------------------------------------- Authentication Mode Validation Tests ----------------------------------------------------(deftest authentication-mode-validation-test- (testing "authentication mode setting only accepts valid values"- ;; Don't use sso.test-setup/with-slack-default-setup! here because it sets env vars- ;; which take precedence over DB values when reading settings.- ;; This test only needs to verify the setter validates input correctly.- (mt/with-temporary-setting-values- [slack-connect-authentication-mode nil]- (testing "valid values are accepted"- (sso-settings/slack-connect-authentication-mode! "sso")- (is (= "sso" (sso-settings/slack-connect-authentication-mode)))- (sso-settings/slack-connect-authentication-mode! "link-only")- (is (= "link-only" (sso-settings/slack-connect-authentication-mode))))-- (testing "invalid values are rejected"- (is (thrown-with-msg?- clojure.lang.ExceptionInfo- #"Invalid authentication mode"- (sso-settings/slack-connect-authentication-mode! "invalid")))))))diff --git a/enterprise/backend/test/metabase_enterprise/sso/test_setup.clj b/enterprise/backend/test/metabase_enterprise/sso/test_setup.cljindex 216a0dc3dad..96380d93b0d 100644--- a/enterprise/backend/test/metabase_enterprise/sso/test_setup.clj+++ b/enterprise/backend/test/metabase_enterprise/sso/test_setup.clj@@ -1,48 +1,28 @@(ns metabase-enterprise.sso.test-setup- "Shared test helpers for SSO tests.+ "Shared test helpers for enterprise SSO tests (SAML, JWT, OIDC).- These utilities are used across multiple SSO integration tests (SAML, JWT, Slack Connect, etc.)- to avoid circular dependencies between test namespaces."+ For Slack Connect and generic SSO helpers, see [[metabase.sso.test-helpers]]."(:require- [clojure.string :as str]- [metabase.config.core :as config][metabase.premium-features.token-check :as token-check]- [metabase.request.core :as request]- [metabase.server.instance :as server.instance]+ [metabase.sso.test-helpers :as sso.test-helpers][metabase.test :as mt]- [metabase.util :as u]- [metabase.util.random :as u.random]- [toucan2.core :as t2]))+ [metabase.util.random :as u.random]))(set! *warn-on-reflection* true)-;;; -------------------------------------------------- Generic Helpers --------------------------------------------------+(def successful-login?+ "Return true if the response indicates a successful user login."+ sso.test-helpers/successful-login?)-(defn successful-login?- "Return true if the response indicates a successful user login.- Checks for the presence of a session cookie in the response."- [resp]- (or- (string? (get-in resp [:cookies request/metabase-session-cookie :value]))- (some #(str/starts-with? % request/metabase-session-cookie) (get-in resp [:headers "Set-Cookie"]))))--(defn call-with-login-attributes-cleared!- "Execute `thunk` and ensure login_attributes are cleared afterward.-- If login_attributes remain after tests run, depending on the order that the tests run,- lots of tests will fail as the login_attributes data from this test is unexpected in- those other tests."- [thunk]- (try- (thunk)- (finally- (u/ignore-exceptions- (t2/update! :model/User {} {:login_attributes nil})- (t2/update! :model/User {:email "[email protected]"} {:first_name "Rasta" :last_name "Toucan" :sso_source nil})))))+(def call-with-login-attributes-cleared!+ "Execute thunk and ensure login_attributes are cleared afterward."+ sso.test-helpers/call-with-login-attributes-cleared!)(defn do-with-other-sso-types-disabled!"Execute `thunk` with LDAP, SAML, JWT, and Slack Connect SSO types disabled.- Useful when testing a specific SSO provider in isolation."+ Useful when testing a specific SSO provider in isolation.++ This EE version disables all SSO types including EE-only SAML and JWT."[thunk](mt/with-temporary-setting-values[ldap-enabled false@@ -93,26 +73,16 @@"Default JWT secret for tests. Note: this is regenerated on each test run."(u.random/secure-hex 32))-(defn- localhost-site-url- "Return a valid localhost site URL for tests, even when no Jetty server is running.- The CLI test runner often executes without a live server instance, so `server-port`- can be nil in that mode."- []- (str "http://localhost:"- (or (server.instance/server-port)- (config/config-str :mb-jetty-port)- 3000)))-(defn call-with-default-jwt-config!"Execute `f` with default JWT configuration set up."[f](let [current-features (token-check/*token-features*)](mt/with-additional-premium-features #{:sso-jwt}(mt/with-temporary-setting-values- [jwt-enabled true+ [jwt-enabled truejwt-identity-provider-uri default-jwt-idp-uri- jwt-shared-secret default-jwt-secret- site-url (localhost-site-url)]+ jwt-shared-secret default-jwt-secret+ site-url (sso.test-helpers/localhost-site-url)](mt/with-premium-features current-features(f))))))@@ -132,26 +102,6 @@(fn []~@body)))))))))))-;;; -------------------------------------------------- Slack Connect Setup ----------------------------------------------------(def ^:private default-slack-client-id "test-slack-client-id")-(def ^:private default-slack-client-secret "test-slack-client-secret")--(defn call-with-default-slack-config!- "Execute `f` with default Slack Connect configuration set up."- [f]- (let [current-features (token-check/*token-features*)]- (mt/with-additional-premium-features #{:sso-slack}- (mt/with-temporary-setting-values- [slack-connect-enabled true- slack-connect-client-id default-slack-client-id- slack-connect-client-secret default-slack-client-secret- slack-connect-authentication-mode "sso"- slack-connect-user-provisioning-enabled true- site-url (localhost-site-url)]- (mt/with-premium-features current-features- (f))))))-;;; -------------------------------------------------- OIDC (Generic) Setup --------------------------------------------------(def ^:private default-oidc-provider@@ -170,7 +120,7 @@(mt/with-additional-premium-features #{:sso-oidc}(mt/with-temporary-setting-values[oidc-providers [default-oidc-provider]- site-url (localhost-site-url)]+ site-url (sso.test-helpers/localhost-site-url)](mt/with-premium-features current-features(f))))))@@ -187,18 +137,3 @@(call-with-default-oidc-config!(fn []~@body))))))))))--(defmacro with-slack-default-setup!- "Set up default Slack Connect configuration for tests.- Includes premium features, other SSO types disabled, login attributes cleanup, and default Slack config."- [& body]- `(mt/test-helpers-set-global-values!- (mt/with-premium-features #{:audit-app}- (do-with-other-sso-types-disabled!- (fn []- (mt/with-additional-premium-features #{:sso-slack}- (call-with-login-attributes-cleared!- (fn []- (call-with-default-slack-config!- (fn []- ~@body))))))))))diff --git a/src/metabase/analytics/stats.clj b/src/metabase/analytics/stats.cljindex 723bed0ece3..6cc5e1c00a3 100644--- a/src/metabase/analytics/stats.clj+++ b/src/metabase/analytics/stats.clj@@ -795,7 +795,7 @@(defn- ee-snowplow-features-data'[]- (let [features [:sso-jwt :sso-saml :sso-slack :scim :sandboxes :email-allow-list :semantic-search]]+ (let [features [:sso-jwt :sso-saml :scim :sandboxes :email-allow-list :semantic-search]](map(fn [feature]{:name featurediff --git a/src/metabase/premium_features/core.clj b/src/metabase/premium_features/core.cljindex 49b27bd2416..be91a665069 100644--- a/src/metabase/premium_features/core.clj+++ b/src/metabase/premium_features/core.clj@@ -74,7 +74,6 @@enable-sso-ldap?enable-sso-oidc?enable-sso-saml?- enable-sso-slack?enable-support-users?enable-basic-transforms?enable-python-transforms?diff --git a/src/metabase/premium_features/settings.clj b/src/metabase/premium_features/settings.cljindex 69fa5abdfc8..1b11909dbf9 100644--- a/src/metabase/premium_features/settings.clj+++ b/src/metabase/premium_features/settings.clj@@ -146,10 +146,6 @@"Should we enable SAML-based authentication?":sso-saml)-(define-premium-feature ^{:added "0.59.0"} enable-sso-slack?- "Should we enable Slack Connect (OIDC) authentication?"- :sso-slack)-(define-premium-feature ^{:added "0.59.0"} enable-sso-oidc?"Should we enable OIDC-based authentication?":sso-oidc)@@ -171,7 +167,6 @@[](or (enable-sso-jwt?)(enable-sso-saml?)- (enable-sso-slack?)(enable-sso-oidc?)(enable-sso-ldap?)(enable-sso-google?)))@@ -354,7 +349,6 @@:sso_ldap (enable-sso-ldap?):sso_saml (enable-sso-saml?):sso_oidc (enable-sso-oidc?)- :sso_slack (enable-sso-slack?):support-users (enable-support-users?):table_data_editing (table-data-editing?):tenants (enable-tenants?)diff --git a/src/metabase/server/auth_wrapper.clj b/src/metabase/server/auth_wrapper.cljindex c98944bdec4..d08248aba94 100644--- a/src/metabase/server/auth_wrapper.clj+++ b/src/metabase/server/auth_wrapper.clj@@ -11,26 +11,21 @@[_req respond _raise](respond bad-req)))-(def ^{:arglists '([request respond raise])} ee-missing-routes- "Ring routes for auth (SAML) API endpoints.- Slack Connect routes are always available (OSS). Other SSO routes require EE."- ;; follows the same form as [[metabase-enterprise.sso.api.routes]]. Compojure is a bit opaque so need to manually keep- ;; them in sync.+(def ^:private ee-missing-routes+ "Fallback routes when EE is not available. Returns 'not enabled' for non-slack-connect SSO routes."(handlers/route-map-handler- {"/auth" {"/sso" (handlers/route-map-handler- {"/slack-connect" slack-connect.api/routes- "/" not-enabled})}+ {"/auth" {"/sso" not-enabled}"/api" {"/saml" not-enabled"/ee" {"/sso" {"/oidc" not-enabled}}}}));; This needs to be injected into [[metabase.server.routes/routes]] -- not [[metabase.api-routes.core/routes]] !!!-;;-;; TODO -- should we make a `metabase-enterprise.routes` namespace where this can live instead of injecting it-;; directly?-;;-;; TODO -- we need to feature-flag this based on the `:sso-` feature flags(def routes- "Ring routes for auth (SAML) api endpoints. If enterprise is not present, will return a nicer message"- (if (and config/ee-available? (not *compile-files*))- (requiring-resolve 'metabase-enterprise.sso.api.routes/routes)- ee-missing-routes))+ "Ring routes for auth API endpoints.+ Slack Connect (OSS) is always available. Other SSO routes (SAML, JWT, OIDC) require EE."+ (handlers/routes+ ;; Slack Connect routes always available (OSS)+ (handlers/route-map-handler {"/auth" {"/sso" {"/slack-connect" slack-connect.api/routes}}})+ ;; Other SSO routes require EE+ (if (and config/ee-available? (not *compile-files*))+ (requiring-resolve 'metabase-enterprise.sso.api.routes/routes)+ ee-missing-routes)))diff --git a/src/metabase/slackbot/api.clj b/src/metabase/slackbot/api.cljindex 324c461e9f4..9263469d6e0 100644--- a/src/metabase/slackbot/api.clj+++ b/src/metabase/slackbot/api.clj@@ -51,8 +51,7 @@^Runnable (bound-fn* f)))(defn clear-slack-bot-settings!- "Clears all slackbot-related settings when Slack token is cleared.- This ensures enable-sso-slack? becomes false."+ "Clears all slackbot-related settings when Slack token is cleared."[](setting/set-many! {:slack-connect-enabled false:slack-connect-client-id nildiff --git a/src/metabase/sso/api/slack_connect.clj b/src/metabase/sso/api/slack_connect.cljindex 68421f462ef..1357becb93d 100644--- a/src/metabase/sso/api/slack_connect.clj+++ b/src/metabase/sso/api/slack_connect.clj@@ -8,7 +8,7 @@;; GET /auth/sso/slack-connect;;#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/slack-connect"+(api.macros/defendpoint :get "/""Initiate Slack Connect SSO flow."[_route-params _query-params _body request](try@@ -20,7 +20,7 @@;; GET /auth/sso/slack-connect/callback;;#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}-(api.macros/defendpoint :get "/slack-connect/callback"+(api.macros/defendpoint :get "/callback""Slack Connect OIDC callback."[_route-params _query-params _body request](try@@ -30,5 +30,5 @@(throw e))))(def ^{:arglists '([request respond raise])} routes- "`/auth/sso` Slack Connect routes."+ "`/auth/sso/slack-connect` routes."(api.macros/ns-handler *ns*))diff --git a/test/metabase/sso/integrations/slack_connect_test.clj b/test/metabase/sso/integrations/slack_connect_test.cljnew file mode 100644index 00000000000..8821d423b08--- /dev/null+++ b/test/metabase/sso/integrations/slack_connect_test.clj@@ -0,0 +1,339 @@+(ns metabase.sso.integrations.slack-connect-test+ (:require+ [clojure.string :as str]+ [clojure.test :refer :all]+ [metabase.auth-identity.core :as auth-identity]+ [metabase.sso.oidc.state :as oidc.state]+ [metabase.sso.settings :as sso-settings]+ [metabase.sso.test-helpers :as sso.test-helpers]+ [metabase.test :as mt]+ [metabase.test.fixtures :as fixtures]+ [metabase.test.http-client :as client]+ [metabase.util.encryption :as encryption]+ [methodical.core :as methodical]+ [ring.util.codec :as codec]+ [toucan2.core :as t2]))++(set! *warn-on-reflection* true)++(use-fixtures :once (fixtures/initialize :test-users))++(def test-encryption-key+ "Test encryption key for OIDC state encryption."+ "Orw0AAyzkO/kPTLJRxiyKoBHXa/d6ZcO+p+gpZO/wSQ=")++(def test-secret+ "Hashed test encryption key."+ (encryption/secret-key->hash test-encryption-key))++(defmacro with-test-encryption!+ "Wraps body with test encryption key enabled. Use for tests that involve OIDC state cookies."+ [& body]+ `(with-redefs [encryption/default-secret-key test-secret]+ ~@body))++(defn do-with-url-prefix-disabled+ "Test fixture that disables API URL prefix."+ [thunk]+ (binding [client/*url-prefix* ""]+ (thunk)))++(use-fixtures :each do-with-url-prefix-disabled)++(def default-redirect-uri "/")++(methodical/defmethod auth-identity/authenticate :provider/test-successful-oidc+ [_provider request]+ (if (some #(contains? request %) [:code :error :state])+ {:success? true+ :claims {}+ :user-data {:email "[email protected]"}+ :provider-id "test-provider-id"}+ {:success? :redirect+ :redirect-url "http://example.com/slack"+ :state "test-state"+ :nonce "test-nonce"}))++(methodical/prefer-method! #'auth-identity/authenticate :provider/test-successful-oidc :provider/oidc)++(defmacro with-successful-oidc! [& body]+ `(do+ (derive :provider/slack-connect :provider/test-successful-oidc)+ ~@body+ (underive :provider/slack-connect :provider/test-successful-oidc)))++;;; -------------------------------------------------- Prerequisites Tests --------------------------------------------------++(deftest sso-prereqs-test+ (with-test-encryption!+ (sso.test-helpers/do-with-other-sso-types-disabled!+ (fn []+ (testing "SSO requests fail if Slack Connect hasn't been configured or enabled"+ (mt/with-temporary-setting-values+ [slack-connect-enabled false+ slack-connect-client-id nil+ slack-connect-client-secret nil]+ (is (= "Slack Connect is not enabled"+ (mt/client :get 400 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}})))))++ (testing "SSO requests fail if Slack Connect is enabled but hasn't been configured"+ (mt/with-temporary-setting-values+ [slack-connect-enabled true+ slack-connect-client-id nil]+ (is (= "Slack Connect is not enabled"+ (mt/client :get 400 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}})))))++ (testing "SSO requests fail if Slack Connect is configured but hasn't been enabled"+ (mt/with-temporary-setting-values+ [slack-connect-enabled false+ slack-connect-client-id "test-slack-client-id"+ slack-connect-client-secret "test-slack-client-secret"]+ (is (= "Slack Connect is not enabled"+ (mt/client :get 400 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}})))))++ (testing "The client secret must also be included for SSO to be configured"+ (mt/with-temporary-setting-values+ [slack-connect-enabled true+ slack-connect-client-id "test-slack-client-id"+ slack-connect-client-secret nil]+ (is (= "Slack Connect is not enabled"+ (mt/client :get 400 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}})))))))))++;;; -------------------------------------------------- Redirect Tests --------------------------------------------------++(deftest redirect-test+ (testing "with Slack Connect configured, a GET request should result in a redirect to Slack"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (with-successful-oidc!+ (let [result (mt/client-full-response :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)+ redirect-url (get-in result [:headers "Location"])+ oidc-state-cookie (->> (get-in result [:headers "Set-Cookie"])+ (filter #(str/includes? % "metabase.OIDC_STATE"))+ first)]+ (is (str/starts-with? redirect-url "http://example.com/slack"))+ (testing "OIDC state is stored in encrypted cookie"+ (is (some? oidc-state-cookie))+ ;; Verify the cookie contains encrypted data (base64-like)+ (let [cookie-value (second (re-find #"metabase\.OIDC_STATE=([^;]+)" oidc-state-cookie))]+ (is (some? cookie-value))+ ;; Decrypt and verify contents (URL-decode since base64 chars +/= are encoded in cookies)+ (let [state-data (oidc.state/decrypt-state (codec/url-decode cookie-value))]+ (is (= "test-state" (:state state-data)))+ (is (= "test-nonce" (:nonce state-data)))+ (is (= "/" (:redirect state-data)))+ (is (= "slack-connect" (:provider state-data))))))))))))++;;; -------------------------------------------------- POST Not Allowed Tests --------------------------------------------------++(deftest post-not-allowed-test+ (testing "slack-connect is no longer available via the old POST /auth/sso multimethod dispatch"+ (sso.test-helpers/with-slack-default-setup!+ ;; The old endpoint returned 405 via the defmethod sso-post :slack-connect.+ ;; Now that slack-connect has been removed from the multimethod dispatch and+ ;; uses dedicated GET routes, POSTing with preferred_method=slack-connect+ ;; should no longer reach slack-connect code. With no other SSO enabled,+ ;; the default dispatch returns "SSO has not been enabled and/or configured".+ (is (some? (mt/client :post 400 "/auth/sso"+ {:request-options {:content-type :x-www-form-urlencoded}}))))))++;;; -------------------------------------------------- Callback Tests --------------------------------------------------++(deftest callback-state-validation-test+ (testing "callback should fail if state cookie is missing"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (let [response (mt/client-full-response :get 401 "/auth/sso/slack-connect/callback"+ {:request-options {:redirect-strategy :none}}+ :code "test-code"+ :state "some-state")]+ ;; Without a state cookie, the callback fails with invalid/expired state error+ (is (str/includes? (:body response) "OIDC state cookie is invalid, expired, or missing")))))))++(deftest callback-state-validation-csrf-test+ (testing "callback with mismatched state should indicate possible CSRF attack"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (with-successful-oidc!+ ;; First, initiate auth to set state cookie+ (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)+ ;; Convert Set-Cookie headers to Cookie header format (extract name=value parts)+ set-cookies (get-in init-response [:headers "Set-Cookie"])+ cookie-header (->> set-cookies+ (map #(first (str/split % #";"))) ; Extract name=value before first ;+ (str/join "; "))+ response (mt/client-real-response :get 401 "/auth/sso/slack-connect/callback"+ {:request-options {:redirect-strategy :none+ :headers {"Cookie" cookie-header}}}+ :code "test-code"+ :state "wrong-state")]+ ;; State mismatch should indicate possible CSRF attack+ (is (str/includes? (str (:body response)) "CSRF"))))))))++(deftest happy-path-callback-test+ (testing "successful callback with valid code and state"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (with-successful-oidc!+ ;; First, initiate auth to set state cookie+ (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)+ ;; Convert Set-Cookie headers to Cookie header format+ set-cookies (get-in init-response [:headers "Set-Cookie"])+ cookie-header (->> set-cookies+ (map #(first (str/split % #";")))+ (str/join "; "))+ response (mt/client-real-response :get 302 "/auth/sso/slack-connect/callback"+ {:request-options {:redirect-strategy :none+ :headers {"Cookie" cookie-header}}}+ :code "test-code"+ :state "test-state")]+ (is (sso.test-helpers/successful-login? response))+ (is (= default-redirect-uri (get-in response [:headers "Location"])))))))))++;;; -------------------------------------------------- Link-Only Mode Tests --------------------------------------------------++(deftest link-only-mode-requires-session-test+ (testing "link-only mode should require authenticated session for initial request"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (mt/with-temporary-setting-values+ [slack-connect-authentication-mode "link-only"]+ (let [response (mt/client-full-response :get 401 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)]+ (is (str/includes? (str (get response :body)) "authenticated session"))))))))++(deftest link-only-mode-with-session-test+ (testing "link-only mode should work with authenticated session"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (mt/with-temporary-setting-values+ [slack-connect-authentication-mode "link-only"]+ (with-successful-oidc!+ (let [response (mt/user-http-request-full-response+ :rasta :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)]+ (is (str/starts-with? (get-in response [:headers "Location"]) "http://example.com/slack")))))))))++;;; -------------------------------------------------- Open Redirect Protection Tests --------------------------------------------------++(deftest no-open-redirect-test+ (testing "Check that we prevent open redirects to untrusted sites"+ (sso.test-helpers/with-slack-default-setup!+ (doseq [redirect-uri ["https://badsite.com"+ "//badsite.com"+ "https:///badsite.com"]]+ (let [result (mt/client :get 400 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect redirect-uri)]+ (is (str/includes? (str (or (:message result) result)) "Invalid redirect URL")))))))++;;; -------------------------------------------------- User Provisioning Tests --------------------------------------------------++(deftest create-new-account-test+ (testing "A new account will be created for a Slack user we haven't seen before"+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (mt/with-model-cleanup [:model/User]+ (with-successful-oidc!+ (t2/delete! :model/User :email "[email protected]")+ (letfn [(new-user-exists? []+ (boolean (seq (t2/select :model/User :%lower.email "[email protected]"))))]+ (is (false? (new-user-exists?)))+ ;; Initiate auth+ (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)+ ;; Convert Set-Cookie headers to Cookie header format+ set-cookies (get-in init-response [:headers "Set-Cookie"])+ cookie-header (->> set-cookies+ (map #(first (str/split % #";")))+ (str/join "; "))+ response (mt/client-real-response :get 302 "/auth/sso/slack-connect/callback"+ {:request-options {:redirect-strategy :none+ :headers {"Cookie" cookie-header}}}+ :code "test-code"+ :state "test-state")]+ ;; Complete callback+ (is (sso.test-helpers/successful-login? response))+ (let [new-user (t2/select-one :model/User :email "[email protected]")]+ (testing "new user"+ (is+ (=+ {:email "[email protected]"+ :first_name nil+ :is_qbnewb true+ :is_superuser false+ :id true+ :last_name nil+ :date_joined true+ :common_name "[email protected]"+ :tenant_id false+ :is_data_analyst false}+ (-> (mt/boolean-ids-and-timestamps [new-user])+ first+ (dissoc :last_login)))))+ (testing "User Invite Event is logged."+ (is+ (= "[email protected]"+ (get-in (mt/latest-audit-log-entry :user-invited (:id new-user))+ [:details :email])))))))))))))++(deftest create-new-slack-user-no-user-provisioning-test+ (testing "When user provisioning is disabled, throw an error if we attempt to create a new user."+ (with-test-encryption!+ (sso.test-helpers/with-slack-default-setup!+ (mt/with-temporary-setting-values [slack-connect-user-provisioning-enabled false+ site-name "test"]+ (with-successful-oidc!+ (with-redefs [auth-identity/login!+ (fn [_provider _request]+ {:success? false+ :error :user-provisioning-disabled+ :message "Sorry, but you'll need a test account to view this page. Please contact your administrator."})]+ ;; Initiate auth+ (let [init-response (mt/client-full-response :get 302 "/auth/sso/slack-connect"+ {:request-options {:redirect-strategy :none}}+ :redirect default-redirect-uri)+ set-cookies (get-in init-response [:headers "Set-Cookie"])+ cookie-header (->> set-cookies+ (map #(first (str/split % #";")))+ (str/join "; "))]+ ;; Try callback - should fail+ (mt/client-real-response :get 401 "/auth/sso/slack-connect/callback"+ {:request-options {:redirect-strategy :none+ :headers {"Cookie" cookie-header}}}+ :code "test-code"+ :state "test-state")))))))))++;;; -------------------------------------------------- Authentication Mode Validation Tests --------------------------------------------------++(deftest authentication-mode-validation-test+ (testing "authentication mode setting only accepts valid values"+ ;; Don't use sso.test-helpers/with-slack-default-setup! here because it sets env vars+ ;; which take precedence over DB values when reading settings.+ ;; This test only needs to verify the setter validates input correctly.+ (mt/with-temporary-setting-values+ [slack-connect-authentication-mode nil]+ (testing "valid values are accepted"+ (sso-settings/slack-connect-authentication-mode! "sso")+ (is (= "sso" (sso-settings/slack-connect-authentication-mode)))+ (sso-settings/slack-connect-authentication-mode! "link-only")+ (is (= "link-only" (sso-settings/slack-connect-authentication-mode))))++ (testing "invalid values are rejected"+ (is (thrown-with-msg?+ clojure.lang.ExceptionInfo+ #"Invalid authentication mode"+ (sso-settings/slack-connect-authentication-mode! "invalid")))))))diff --git a/test/metabase/sso/test_helpers.clj b/test/metabase/sso/test_helpers.cljnew file mode 100644index 00000000000..67aaf23fe7a--- /dev/null+++ b/test/metabase/sso/test_helpers.clj@@ -0,0 +1,90 @@+(ns metabase.sso.test-helpers+ "Shared test helpers for SSO tests."+ (:require+ [clojure.string :as str]+ [metabase.config.core :as config]+ [metabase.request.core :as request]+ [metabase.server.instance :as server.instance]+ [metabase.test :as mt]+ [metabase.util :as u]+ [toucan2.core :as t2]))++(set! *warn-on-reflection* true)++;;; -------------------------------------------------- Generic Helpers --------------------------------------------------++(defn successful-login?+ "Return true if the response indicates a successful user login.+ Checks for the presence of a session cookie in the response."+ [resp]+ (or+ (string? (get-in resp [:cookies request/metabase-session-cookie :value]))+ (some #(str/starts-with? % request/metabase-session-cookie) (get-in resp [:headers "Set-Cookie"]))))++(defn call-with-login-attributes-cleared!+ "Execute `thunk` and ensure login_attributes are cleared afterward.++ If login_attributes remain after tests run, depending on the order that the tests run,+ lots of tests will fail as the login_attributes data from this test is unexpected in+ those other tests."+ [thunk]+ (try+ (thunk)+ (finally+ (u/ignore-exceptions+ (t2/update! :model/User {} {:login_attributes nil})+ (t2/update! :model/User {:email "[email protected]"} {:first_name "Rasta" :last_name "Toucan" :sso_source nil})))))++(defn do-with-other-sso-types-disabled!+ "Execute `thunk` with LDAP and Slack Connect SSO types disabled.+ Useful when testing a specific SSO provider in isolation.++ Note: This OSS version only disables OSS SSO types. EE tests should use+ [[metabase-enterprise.sso.test-setup/do-with-other-sso-types-disabled!]]+ which also disables SAML and JWT."+ [thunk]+ (mt/with-temporary-setting-values+ [ldap-enabled false+ slack-connect-enabled false]+ (thunk)))++(defn localhost-site-url+ "Return a valid localhost site URL for tests, even when no Jetty server is running.+ The CLI test runner often executes without a live server instance, so `server-port`+ can be nil in that mode."+ []+ (str "http://localhost:"+ (or (server.instance/server-port)+ (config/config-str :mb-jetty-port)+ 3000)))++;;; -------------------------------------------------- Slack Connect Setup --------------------------------------------------++(def ^:private default-slack-client-id "test-slack-client-id")+(def ^:private default-slack-client-secret "test-slack-client-secret")++(defn call-with-default-slack-config!+ "Execute `f` with default Slack Connect configuration set up."+ [f]+ (mt/with-temporary-setting-values+ [slack-connect-enabled true+ slack-connect-client-id default-slack-client-id+ slack-connect-client-secret default-slack-client-secret+ slack-connect-authentication-mode "sso"+ slack-connect-user-provisioning-enabled true+ site-url (localhost-site-url)]+ (f)))++(defmacro with-slack-default-setup!+ "Set up default Slack Connect configuration for tests.+ Includes other SSO types disabled, login attributes cleanup, and default Slack config."+ [& body]+ `(mt/test-helpers-set-global-values!+ (mt/with-premium-features #{:audit-app}+ (do-with-other-sso-types-disabled!+ (fn []+ (call-with-login-attributes-cleared!+ (fn []+ (call-with-default-slack-config!+ (fn []+ ~@body)))))))))