Merge pull request 'Remove "default" image description' (#493) from ilja/akkoma:remov...
[akkoma] / test / pleroma / web / activity_pub / activity_pub_test.exs
index 1ba1ad96a28d82b73287c77ff241a82d77f4da6f..b65575f01421eb684c707c2c9ce562b5df6d1bd0 100644 (file)
@@ -725,13 +725,19 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       user = insert(:user)
       other_user = insert(:user)
 
-      {:ok, normally_visible} = CommonAPI.post(other_user, %{status: "hello :)", visibility: "public"})
+      {:ok, normally_visible} =
+        CommonAPI.post(other_user, %{status: "hello :)", visibility: "public"})
+
       {:ok, public} = CommonAPI.post(user, %{status: "maji #tenshi", visibility: "public"})
       {:ok, _unrelated} = CommonAPI.post(user, %{status: "dai #tensh", visibility: "public"})
       {:ok, unlisted} = CommonAPI.post(user, %{status: "maji #tenshi", visibility: "unlisted"})
       {:ok, _private} = CommonAPI.post(user, %{status: "maji #tenshi", visibility: "private"})
 
-      activities = ActivityPub.fetch_activities([other_user.follower_address], %{followed_hashtags: [hashtag.id]})
+      activities =
+        ActivityPub.fetch_activities([other_user.follower_address], %{
+          followed_hashtags: [hashtag.id]
+        })
+
       assert length(activities) == 3
       normal_id = normally_visible.id
       public_id = public.id
@@ -1297,31 +1303,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
       %{test_file: test_file}
     end
 
-    test "sets a description if given", %{test_file: file} do
-      {:ok, %Object{} = object} = ActivityPub.upload(file, description: "a cool file")
-      assert object.data["name"] == "a cool file"
-    end
-
-    test "it sets the default description depending on the configuration", %{test_file: file} do
-      clear_config([Pleroma.Upload, :default_description])
-
-      clear_config([Pleroma.Upload, :default_description], nil)
-      {:ok, %Object{} = object} = ActivityPub.upload(file)
-      assert object.data["name"] == ""
-
-      clear_config([Pleroma.Upload, :default_description], :filename)
-      {:ok, %Object{} = object} = ActivityPub.upload(file)
-      assert object.data["name"] == "an_image.jpg"
-
-      clear_config([Pleroma.Upload, :default_description], "unnamed attachment")
+    test "strips / from filename", %{test_file: file} do
+      file = %Plug.Upload{file | filename: "../../../../../nested/bad.jpg"}
       {:ok, %Object{} = object} = ActivityPub.upload(file)
-      assert object.data["name"] == "unnamed attachment"
+      [%{"href" => href}] = object.data["url"]
+      assert Regex.match?(~r"/bad.jpg$", href)
+      refute Regex.match?(~r"/nested/", href)
     end
 
-    test "copies the file to the configured folder", %{test_file: file} do
-      clear_config([Pleroma.Upload, :default_description], :filename)
-      {:ok, %Object{} = object} = ActivityPub.upload(file)
-      assert object.data["name"] == "an_image.jpg"
+    test "sets a description if given", %{test_file: file} do
+      {:ok, %Object{} = object} = ActivityPub.upload(file, description: "a cool file")
+      assert object.data["name"] == "a cool file"
     end
 
     test "works with base64 encoded images" do