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
white_label - do not use hardcoded metabase in filenames for nonOSS (#81979)
thackervishalad22a8730c4b
diff --git a/src/metabase/channel/render/image_bundle.clj b/src/metabase/channel/render/image_bundle.cljindex 0705955f2b6..1da333c4ef4 100644--- a/src/metabase/channel/render/image_bundle.clj+++ b/src/metabase/channel/render/image_bundle.clj@@ -3,7 +3,9 @@either encode the image inline in a URL (when `render-type` is `:inline`), or create the hashes/references neededfor an attached image (`render-type` of `:attachment`)"(:require- [clojure.java.io :as io])+ [clojure.java.io :as io]+ [metabase.appearance.core :as appearance]+ [metabase.util :as u])(:import(java.util Arrays)(org.apache.commons.io IOUtils)@@ -29,7 +31,7 @@(defn- write-byte-array-to-temp-file[^bytes img-bytes]- (let [f (doto (java.io.File/createTempFile "metabase_channel_image_" ".png")+ (let [f (doto (java.io.File/createTempFile (str (u/slugify (appearance/application-name)) "_channel_image_") ".png").deleteOnExit)](with-open [fos (java.io.FileOutputStream. f)](.write fos img-bytes))diff --git a/test/metabase/channel/render/image_bundle_test.clj b/test/metabase/channel/render/image_bundle_test.cljnew file mode 100644index 00000000000..6edc3b96a79--- /dev/null+++ b/test/metabase/channel/render/image_bundle_test.clj@@ -0,0 +1,29 @@+(ns metabase.channel.render.image-bundle-test+ (:require+ [clojure.java.io :as io]+ [clojure.string :as str]+ [clojure.test :refer :all]+ [metabase.channel.render.image-bundle :as image-bundle]+ [metabase.test :as mt]))++(set! *warn-on-reflection* true)++(deftest make-image-bundle-test+ (testing "Filename prefixes generated for attachments for EE with whitelabel feature flag uses the application name as the prefix"+ (mt/when-ee-evailable+ (mt/with-premium-features #{:whitelabel}+ (mt/with-temporary-setting-values [application-name "Zorptech Blimwix"]+ (let [bundle (image-bundle/make-image-bundle :attachment (byte-array [1 2 3]))+ filename (.getName (io/as-file (:image-url bundle)))]+ (is (str/starts-with? filename "zorptech_blimwix_channel_image_")))))))+ (testing "Filename prefixes generated for attachments for OSS or EE-without-whitelabel feature flag defaults to Metabase as the prefix"+ (let [bundle (image-bundle/make-image-bundle :attachment (byte-array [1 2 3]))+ filename (.getName (io/as-file (:image-url bundle)))]+ (is (str/starts-with? filename "metabase_channel_image_"))))+ (testing "Special characters in the application name are slugified into underscores rather than leaking into the filename"+ (mt/when-ee-evailable+ (mt/with-premium-features #{:whitelabel}+ (mt/with-temporary-setting-values [application-name "Zog & Blerp's!"]+ (let [bundle (image-bundle/make-image-bundle :attachment (byte-array [1 2 3]))+ filename (.getName (io/as-file (:image-url bundle)))]+ (is (str/starts-with? filename "zog___blerp_s__channel_image_"))))))))