User: Truncate bios when updating a remote user.
authorlain <lain@soykaf.club>
Mon, 11 May 2020 10:50:25 +0000 (12:50 +0200)
committerrinpatch <rinpatch@sdf.org>
Tue, 12 May 2020 21:33:38 +0000 (00:33 +0300)
lib/pleroma/user.ex
test/user_test.exs
test/web/activity_pub/activity_pub_controller_test.exs
test/web/mastodon_api/controllers/suggestion_controller_test.exs

index 2f0333da00a48577bbec3f869d43713f431b7b62..3e8f19e30519039ceee3360114a765e145f36b2b 100644 (file)
@@ -501,7 +501,15 @@ defmodule Pleroma.User do
 
     params = Map.put(params, :last_refreshed_at, NaiveDateTime.utc_now())
 
-    params = if remote?, do: truncate_fields_param(params), else: params
+    params =
+      if remote? do
+        params
+        |> truncate_fields_param()
+        |> truncate_if_exists(:name, name_limit)
+        |> truncate_if_exists(:bio, bio_limit)
+      else
+        params
+      end
 
     struct
     |> cast(
index e63c44360f6092c604dc5d1eac82d3afac2d288f..368bdae12a1844aa1f4c6e065d281fab31ab9bbc 100644 (file)
@@ -570,7 +570,10 @@ defmodule Pleroma.UserTest do
       assert fetched_user == "not found nonexistant"
     end
 
+    clear_config([:instance, :user_bio_length])
+
     test "updates an existing user, if stale" do
+      Pleroma.Config.put([:instance, :user_bio_length], 1)
       a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
 
       orig_user =
index c418232daeaec5465705721a544498a8651a23c7..153adc70315f29b8c4d462521d132fa730c5a650 100644 (file)
@@ -310,7 +310,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
   end
 
   describe "/inbox" do
+    clear_config([:instance, :user_bio_length])
+
     test "it inserts an incoming activity into the database", %{conn: conn} do
+      Pleroma.Config.put([:instance, :user_bio_length], 1)
+
       data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
 
       conn =
index 8d0e70db86750cf99165a44c903afd25e6331b8c..f120bd0cd17828d5f0da7fdfcd67935b226bfd88 100644 (file)
@@ -5,8 +5,6 @@
 defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
   use Pleroma.Web.ConnCase
 
-  alias Pleroma.Config
-
   setup do: oauth_access(["read"])
 
   test "returns empty result", %{conn: conn} do