X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fweb%2Fcommon_api_test.exs;h=5ab3a48ad97881b6858e19c325415221ab8bb490;hb=51a9f97e87823cbd9e92c375f4bc4c0bfa8b79db;hp=3b7ac20336ddc6909ba264e50b32ab364770d8a0;hpb=b122b6ffa318af30586f9da0532135959804a6a0;p=akkoma diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 3b7ac2033..5ab3a48ad 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPITest do @@ -39,7 +39,7 @@ defmodule Pleroma.Web.CommonAPITest do poll: %{expires_in: 600, options: ["reimu", "marisa"]} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["type"] == "Question" assert object.data["oneOf"] |> length() == 2 @@ -174,7 +174,7 @@ defmodule Pleroma.Web.CommonAPITest do assert other_user.ap_id not in activity.recipients - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "uguu
uguuu" end @@ -194,7 +194,7 @@ defmodule Pleroma.Web.CommonAPITest do assert other_user.ap_id not in activity.recipients - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "https://example.org is the site of Object.prune() with_mock Pleroma.Web.Federator, @@ -475,7 +475,7 @@ defmodule Pleroma.Web.CommonAPITest do jafnhar = insert(:user) tridi = insert(:user) - Pleroma.Config.put([:instance, :safe_dm_mentions], true) + clear_config([:instance, :safe_dm_mentions], true) {:ok, activity} = CommonAPI.post(har, %{ @@ -491,22 +491,34 @@ defmodule Pleroma.Web.CommonAPITest do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) - assert object.data["tag"] == [] - assert object.data["hashtags"] == ["2hu"] + assert object.data["tag"] == ["2hu"] end test "it adds emoji in the object" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"}) - assert Object.normalize(activity).data["emoji"]["firefox"] + assert Object.normalize(activity, fetch: false).data["emoji"]["firefox"] end describe "posting" do + test "it adds an emoji on an external site" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{status: "hey :external_emoji:"}) + + assert %{"external_emoji" => url} = Object.normalize(activity).data["emoji"] + assert url == "https://example.com/emoji.png" + + {:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"}) + + assert %{"blank" => url} = Object.normalize(activity).data["emoji"] + assert url == "#{Pleroma.Web.Endpoint.url()}/emoji/blank.png" + end + test "deactivated users can't post" do - user = insert(:user, deactivated: true) + user = insert(:user, is_active: false) assert {:error, _} = CommonAPI.post(user, %{status: "ye"}) end @@ -540,7 +552,7 @@ defmodule Pleroma.Web.CommonAPITest do content_type: "text/html" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

2hu

alert('xss')" assert object.data["source"] == post @@ -557,7 +569,7 @@ defmodule Pleroma.Web.CommonAPITest do content_type: "text/markdown" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

2hu

alert('xss')" assert object.data["source"] == post @@ -630,7 +642,7 @@ defmodule Pleroma.Web.CommonAPITest do end test "it validates character limits are correctly enforced" do - Pleroma.Config.put([:instance, :limit], 5) + clear_config([:instance, :limit], 5) user = insert(:user) @@ -732,6 +744,22 @@ defmodule Pleroma.Web.CommonAPITest do refute Visibility.visible_for_user?(announce_activity, nil) end + test "author can repeat own private statuses" do + author = insert(:user) + follower = insert(:user) + CommonAPI.follow(follower, author) + + {:ok, activity} = CommonAPI.post(author, %{status: "cofe", visibility: "private"}) + + {:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, author) + + assert Visibility.is_private?(announce_activity) + refute Visibility.visible_for_user?(announce_activity, nil) + + assert Visibility.visible_for_user?(activity, follower) + assert {:error, :not_found} = CommonAPI.repeat(activity.id, follower) + end + test "favoriting a status" do user = insert(:user) other_user = insert(:user) @@ -765,7 +793,7 @@ defmodule Pleroma.Web.CommonAPITest do describe "pinned statuses" do setup do - Pleroma.Config.put([:instance, :max_pinned_statuses], 1) + clear_config([:instance, :max_pinned_statuses], 1) user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"}) @@ -1212,7 +1240,7 @@ defmodule Pleroma.Web.CommonAPITest do poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _, object} = CommonAPI.vote(other_user, object, [0]) @@ -1232,7 +1260,7 @@ defmodule Pleroma.Web.CommonAPITest do length: 180_000 }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" @@ -1251,7 +1279,7 @@ defmodule Pleroma.Web.CommonAPITest do visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1"