aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@gmail.com>2019-04-30 20:17:52 +0700
committerRoman Chvanikov <chvanikoff@gmail.com>2019-04-30 20:17:52 +0700
commit0f0cc2703b7ffb99c58e72782925ea4dd61db41d (patch)
treef640d180d16797a6da98a7d1e1cb7c6fb6350392 /test
parentb87ad13803df59d88feb736c3d0ff9cf514989d7 (diff)
parent32a4501d2d1cdfef68cbde236482e0c84cce3a7a (diff)
downloadpleroma-0f0cc2703b7ffb99c58e72782925ea4dd61db41d.tar.gz
Merge develop
Diffstat (limited to 'test')
-rw-r--r--test/bookmark_test.exs52
-rw-r--r--test/emoji_test.exs4
-rw-r--r--test/formatter_test.exs8
-rw-r--r--test/healthcheck_test.exs22
-rw-r--r--test/html_test.exs71
-rw-r--r--test/media_proxy_test.exs9
-rw-r--r--test/notification_test.exs4
-rw-r--r--test/tasks/relay_test.exs4
-rw-r--r--test/tasks/user_test.exs16
-rw-r--r--test/user_test.exs71
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs8
-rw-r--r--test/web/activity_pub/activity_pub_test.exs44
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs58
-rw-r--r--test/web/activity_pub/utils_test.exs5
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs24
-rw-r--r--test/web/common_api/common_api_test.exs10
-rw-r--r--test/web/common_api/common_api_utils_test.exs35
-rw-r--r--test/web/mastodon_api/account_view_test.exs35
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs347
-rw-r--r--test/web/mastodon_api/notification_view_test.exs2
-rw-r--r--test/web/mastodon_api/status_view_test.exs23
-rw-r--r--test/web/oauth/oauth_controller_test.exs21
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs8
-rw-r--r--test/web/ostatus/ostatus_test.exs12
-rw-r--r--test/web/push/impl_test.exs71
-rw-r--r--test/web/salmon/salmon_test.exs2
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs40
-rw-r--r--test/web/twitter_api/twitter_api_test.exs43
-rw-r--r--test/web/twitter_api/util_controller_test.exs6
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs6
-rw-r--r--test/web/twitter_api/views/user_view_test.exs51
31 files changed, 844 insertions, 268 deletions
diff --git a/test/bookmark_test.exs b/test/bookmark_test.exs
new file mode 100644
index 000000000..b81c102ef
--- /dev/null
+++ b/test/bookmark_test.exs
@@ -0,0 +1,52 @@
+defmodule Pleroma.BookmarkTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.Bookmark
+ alias Pleroma.Web.CommonAPI
+
+ describe "create/2" do
+ test "with valid params" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
+ {:ok, bookmark} = Bookmark.create(user.id, activity.id)
+ assert bookmark.user_id == user.id
+ assert bookmark.activity_id == activity.id
+ end
+
+ test "with invalid params" do
+ {:error, changeset} = Bookmark.create(nil, "")
+ refute changeset.valid?
+
+ assert changeset.errors == [
+ user_id: {"can't be blank", [validation: :required]},
+ activity_id: {"can't be blank", [validation: :required]}
+ ]
+ end
+ end
+
+ describe "destroy/2" do
+ test "with valid params" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Some cool information"})
+ {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
+
+ {:ok, _deleted_bookmark} = Bookmark.destroy(user.id, activity.id)
+ end
+ end
+
+ describe "get/2" do
+ test "gets a bookmark" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "Scientists Discover The Secret Behind Tenshi Eating A Corndog Being So Cute – Science Daily"
+ })
+
+ {:ok, bookmark} = Bookmark.create(user.id, activity.id)
+ assert bookmark == Bookmark.get(user.id, activity.id)
+ end
+ end
+end
diff --git a/test/emoji_test.exs b/test/emoji_test.exs
index cb1d62d00..2eaa26be6 100644
--- a/test/emoji_test.exs
+++ b/test/emoji_test.exs
@@ -15,7 +15,7 @@ defmodule Pleroma.EmojiTest do
assert tuple_size(emoji) == 3
assert is_binary(code)
assert is_binary(path)
- assert is_binary(tags)
+ assert is_list(tags)
end
test "random emoji", %{emoji_list: emoji_list} do
@@ -25,7 +25,7 @@ defmodule Pleroma.EmojiTest do
assert tuple_size(emoji) == 3
assert is_binary(code)
assert is_binary(path)
- assert is_binary(tags)
+ assert is_list(tags)
end
end
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index e74985c4e..97eb2f583 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -245,10 +245,10 @@ defmodule Pleroma.FormatterTest do
end
test "it adds cool emoji" do
- text = "I love :moominmamma:"
+ text = "I love :firefox:"
expected_result =
- "I love <img height=\"32px\" width=\"32px\" alt=\"moominmamma\" title=\"moominmamma\" src=\"/finmoji/128px/moominmamma-128.png\" />"
+ "I love <img height=\"32px\" width=\"32px\" alt=\"firefox\" title=\"firefox\" src=\"/emoji/Firefox.gif\" />"
assert Formatter.emojify(text) == expected_result
end
@@ -269,10 +269,10 @@ defmodule Pleroma.FormatterTest do
end
test "it returns the emoji used in the text" do
- text = "I love :moominmamma:"
+ text = "I love :firefox:"
assert Formatter.get_emoji(text) == [
- {"moominmamma", "/finmoji/128px/moominmamma-128.png", "Finmoji"}
+ {"firefox", "/emoji/Firefox.gif", ["Gif", "Fun"]}
]
end
diff --git a/test/healthcheck_test.exs b/test/healthcheck_test.exs
new file mode 100644
index 000000000..e05061220
--- /dev/null
+++ b/test/healthcheck_test.exs
@@ -0,0 +1,22 @@
+defmodule Pleroma.HealthcheckTest do
+ use Pleroma.DataCase
+ alias Pleroma.Healthcheck
+
+ test "system_info/0" do
+ result = Healthcheck.system_info() |> Map.from_struct()
+
+ assert Map.keys(result) == [:active, :healthy, :idle, :memory_used, :pool_size]
+ end
+
+ describe "check_health/1" do
+ test "pool size equals active connections" do
+ result = Healthcheck.check_health(%Healthcheck{pool_size: 10, active: 10})
+ refute result.healthy
+ end
+
+ test "chech_health/1" do
+ result = Healthcheck.check_health(%Healthcheck{pool_size: 10, active: 9})
+ assert result.healthy
+ end
+ end
+end
diff --git a/test/html_test.exs b/test/html_test.exs
index 0b5d3d892..08738276e 100644
--- a/test/html_test.exs
+++ b/test/html_test.exs
@@ -20,6 +20,18 @@ defmodule Pleroma.HTMLTest do
<img src="http://example.com/image.jpg" onerror="alert('hacked')">
"""
+ @html_span_class_sample """
+ <span class="animate-spin">hi</span>
+ """
+
+ @html_span_microformats_sample """
+ <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
+ """
+
+ @html_span_invalid_microformats_sample """
+ <span class="h-card"><a class="u-url mention animate-spin">@<span>foo</span></a></span>
+ """
+
describe "StripTags scrubber" do
test "works as expected" do
expected = """
@@ -64,6 +76,36 @@ defmodule Pleroma.HTMLTest do
assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.TwitterText)
end
+
+ test "does not allow spans with invalid classes" do
+ expected = """
+ <span>hi</span>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.TwitterText)
+ end
+
+ test "does allow microformats" do
+ expected = """
+ <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_span_microformats_sample, Pleroma.HTML.Scrubber.TwitterText)
+ end
+
+ test "filters invalid microformats markup" do
+ expected = """
+ <span class="h-card"><a>@<span>foo</span></a></span>
+ """
+
+ assert expected ==
+ HTML.filter_tags(
+ @html_span_invalid_microformats_sample,
+ Pleroma.HTML.Scrubber.TwitterText
+ )
+ end
end
describe "default scrubber" do
@@ -88,5 +130,34 @@ defmodule Pleroma.HTMLTest do
assert expected == HTML.filter_tags(@html_onerror_sample, Pleroma.HTML.Scrubber.Default)
end
+
+ test "does not allow spans with invalid classes" do
+ expected = """
+ <span>hi</span>
+ """
+
+ assert expected == HTML.filter_tags(@html_span_class_sample, Pleroma.HTML.Scrubber.Default)
+ end
+
+ test "does allow microformats" do
+ expected = """
+ <span class="h-card"><a class="u-url mention">@<span>foo</span></a></span>
+ """
+
+ assert expected ==
+ HTML.filter_tags(@html_span_microformats_sample, Pleroma.HTML.Scrubber.Default)
+ end
+
+ test "filters invalid microformats markup" do
+ expected = """
+ <span class="h-card"><a>@<span>foo</span></a></span>
+ """
+
+ assert expected ==
+ HTML.filter_tags(
+ @html_span_invalid_microformats_sample,
+ Pleroma.HTML.Scrubber.Default
+ )
+ end
end
end
diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs
index ddbadfbf5..a4331478e 100644
--- a/test/media_proxy_test.exs
+++ b/test/media_proxy_test.exs
@@ -177,4 +177,13 @@ defmodule Pleroma.MediaProxyTest do
{:ok, decoded} = decode_url(sig, base64)
decoded
end
+
+ test "mediaproxy whitelist" do
+ Pleroma.Config.put([:media_proxy, :enabled], true)
+ Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
+ url = "https://feld.me/foo.png"
+
+ unencoded = url(url)
+ assert unencoded == url
+ end
end
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 3bbce8fcf..eec0a4829 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -48,7 +48,7 @@ defmodule Pleroma.NotificationTest do
describe "create_notification" do
test "it doesn't create a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
user = insert(:user)
{:ok, user} = User.block(user, author)
@@ -126,7 +126,7 @@ defmodule Pleroma.NotificationTest do
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
assert nil == Notification.create_notification(activity, author)
end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 535dc3756..9d260da3e 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -31,7 +31,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
local_user = Relay.get_actor()
assert local_user.ap_id =~ "/relay"
- target_user = User.get_by_ap_id(target_instance)
+ target_user = User.get_cached_by_ap_id(target_instance)
refute target_user.local
activity = Utils.fetch_latest_follow(local_user, target_user)
@@ -48,7 +48,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
%User{ap_id: follower_id} = local_user = Relay.get_actor()
- target_user = User.get_by_ap_id(target_instance)
+ target_user = User.get_cached_by_ap_id(target_instance)
follow_activity = Utils.fetch_latest_follow(local_user, target_user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 242265da5..eaf4ecf84 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -50,7 +50,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "created"
- user = User.get_by_nickname(unsaved.nickname)
+ user = User.get_cached_by_nickname(unsaved.nickname)
assert user.name == unsaved.name
assert user.email == unsaved.email
assert user.bio == unsaved.bio
@@ -75,7 +75,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "will not be created"
- refute User.get_by_nickname(unsaved.nickname)
+ refute User.get_cached_by_nickname(unsaved.nickname)
end
end
@@ -88,7 +88,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
@@ -109,7 +109,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " deactivated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
@@ -121,7 +121,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ " activated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.deactivated
end
@@ -150,7 +150,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ "Successfully unsubscribed"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(user.following)
assert user.info.deactivated
end
@@ -178,7 +178,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* true/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.is_moderator
assert user.info.locked
assert user.info.is_admin
@@ -204,7 +204,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* false/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.is_moderator
refute user.info.locked
refute user.info.is_admin
diff --git a/test/user_test.exs b/test/user_test.exs
index d11d94263..a4d51ac95 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -123,9 +123,9 @@ defmodule Pleroma.UserTest do
{:ok, user} = User.follow(user, followed)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
assert User.ap_followers(followed) in user.following
@@ -188,7 +188,7 @@ defmodule Pleroma.UserTest do
{:ok, user, _activity} = User.unfollow(user, followed)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.following == []
end
@@ -198,7 +198,7 @@ defmodule Pleroma.UserTest do
{:error, _} = User.unfollow(user, user)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.following == [user.ap_id]
end
@@ -556,8 +556,8 @@ defmodule Pleroma.UserTest do
{:ok, res} = User.get_friends(user)
- followed_one = User.get_by_ap_id(followed_one.ap_id)
- followed_two = User.get_by_ap_id(followed_two.ap_id)
+ followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
+ followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
assert Enum.member?(res, followed_one)
assert Enum.member?(res, followed_two)
refute Enum.member?(res, not_followed)
@@ -568,7 +568,7 @@ defmodule Pleroma.UserTest do
test "it sets the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
@@ -579,7 +579,7 @@ defmodule Pleroma.UserTest do
test "it increases the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
@@ -594,7 +594,7 @@ defmodule Pleroma.UserTest do
test "it decreases the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
@@ -696,7 +696,7 @@ defmodule Pleroma.UserTest do
assert User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
@@ -714,7 +714,7 @@ defmodule Pleroma.UserTest do
refute User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
@@ -732,7 +732,7 @@ defmodule Pleroma.UserTest do
assert User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
@@ -852,9 +852,9 @@ defmodule Pleroma.UserTest do
{:ok, _} = User.delete(user)
- followed = User.get_by_id(followed.id)
- follower = User.get_by_id(follower.id)
- user = User.get_by_id(user.id)
+ followed = User.get_cached_by_id(followed.id)
+ follower = User.get_cached_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated
@@ -1005,13 +1005,17 @@ defmodule Pleroma.UserTest do
end
test "works with URIs" do
- results = User.search("http://mastodon.example.org/users/admin", resolve: true)
- result = results |> List.first()
+ [result] = User.search("http://mastodon.example.org/users/admin", resolve: true)
- user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
+ expected =
+ result
+ |> Map.put(:search_rank, nil)
+ |> Map.put(:search_type, nil)
+ |> Map.put(:last_digest_emailed_at, nil)
- assert length(results) == 1
- assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
+ user = User.get_cached_by_ap_id("http://mastodon.example.org/users/admin")
+
+ assert user == expected
end
end
@@ -1125,33 +1129,6 @@ defmodule Pleroma.UserTest do
end
end
- test "bookmarks" do
- user = insert(:user)
-
- {:ok, activity1} =
- CommonAPI.post(user, %{
- "status" => "heweoo!"
- })
-
- id1 = Object.normalize(activity1).data["id"]
-
- {:ok, activity2} =
- CommonAPI.post(user, %{
- "status" => "heweoo!"
- })
-
- id2 = Object.normalize(activity2).data["id"]
-
- assert {:ok, user_state1} = User.bookmark(user, id1)
- assert user_state1.bookmarks == [id1]
-
- assert {:ok, user_state2} = User.unbookmark(user, id1)
- assert user_state2.bookmarks == []
-
- assert {:ok, user_state3} = User.bookmark(user, id2)
- assert user_state3.bookmarks == [id2]
- end
-
test "follower count is updated when a follower is blocked" do
user = insert(:user)
follower = insert(:user)
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 7b1c60f15..30adfda36 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("accept", "application/json")
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
@@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> put_req_header("accept", "application/activity+json")
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
@@ -83,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
)
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
@@ -572,7 +572,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
user = insert(:user)
Enum.each(1..15, fn _ ->
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
other_user = insert(:user)
User.follow(user, other_user)
end)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 389aa02a1..f8e987e58 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -228,18 +228,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = insert(:user)
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "1", "visibility" => "public"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "1",
+ "visibility" => "public"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "unlisted"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "2",
+ "visibility" => "unlisted"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "private"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "2",
+ "visibility" => "private"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "3", "visibility" => "direct"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "3",
+ "visibility" => "direct"
+ })
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 2
end
@@ -772,23 +784,35 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = insert(:user, info: %{note_count: 10})
{:ok, a1} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "public"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "public"
+ })
{:ok, a2} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "unlisted"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "unlisted"
+ })
{:ok, a3} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "private"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "private"
+ })
{:ok, a4} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "direct"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "direct"
+ })
{:ok, _} = Object.normalize(a1) |> ActivityPub.delete()
{:ok, _} = Object.normalize(a2) |> ActivityPub.delete()
{:ok, _} = Object.normalize(a3) |> ActivityPub.delete()
{:ok, _} = Object.normalize(a4) |> ActivityPub.delete()
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 10
end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 6bb81a054..78429c7c6 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -99,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert object["sensitive"] == true
- user = User.get_by_ap_id(object["actor"])
+ user = User.get_cached_by_ap_id(object["actor"])
assert user.info.note_count == 1
end
@@ -212,7 +212,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "http://mastodon.example.org/users/admin"
assert data["type"] == "Follow"
assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
- assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
+ end
+
+ test "it rejects incoming follow requests from blocked users when deny_follow_blocked is enabled" do
+ Pleroma.Config.put([:user, :deny_follow_blocked], true)
+
+ user = insert(:user)
+ target = User.get_or_fetch("http://mastodon.example.org/users/admin")
+
+ {:ok, user} = User.block(user, target)
+
+ data =
+ File.read!("test/fixtures/mastodon-follow-activity.json")
+ |> Poison.decode!()
+ |> Map.put("object", user.ap_id)
+
+ {:ok, %Activity{data: %{"id" => id}}} = Transmogrifier.handle_incoming(data)
+
+ %Activity{} = activity = Activity.get_by_ap_id(id)
+
+ assert activity.data["state"] == "reject"
end
test "it works for incoming follow requests from hubzilla" do
@@ -229,7 +249,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
assert data["type"] == "Follow"
assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
- assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming likes" do
@@ -540,7 +560,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"]["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- refute User.following?(User.get_by_ap_id(data["actor"]), user)
+ refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming blocks" do
@@ -557,7 +577,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- blocker = User.get_by_ap_id(data["actor"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
assert User.blocks?(blocker, user)
end
@@ -584,8 +604,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"] == blocked.ap_id
assert data["actor"] == blocker.ap_id
- blocker = User.get_by_ap_id(data["actor"])
- blocked = User.get_by_ap_id(data["object"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
+ blocked = User.get_cached_by_ap_id(data["object"])
assert User.blocks?(blocker, blocked)
@@ -614,7 +634,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["object"]["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- blocker = User.get_by_ap_id(data["actor"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
refute User.blocks?(blocker, user)
end
@@ -645,7 +665,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
@@ -667,7 +687,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
@@ -687,7 +707,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
@@ -706,7 +726,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(accept_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, followed) == true
end
@@ -725,7 +745,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(accept_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, followed) == true
end
@@ -750,7 +770,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
refute activity.local
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == false
end
@@ -772,7 +792,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == false
end
@@ -946,7 +966,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
test "it strips internal fields" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :moominmamma:"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu :firefox:"})
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
@@ -1026,7 +1046,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
@@ -1034,7 +1054,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.info.note_count == 1
assert user.follower_address == "https://niu.moe/users/rye/followers"
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
activity = Activity.get_by_id(activity.id)
@@ -1063,7 +1083,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
unrelated_activity = Activity.get_by_id(unrelated_activity.id)
refute user.follower_address in unrelated_activity.recipients
- user_two = User.get_by_id(user_two.id)
+ user_two = User.get_cached_by_id(user_two.id)
assert user.follower_address in user_two.following
refute "..." in user_two.following
end
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index 758214e68..c57fae437 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,7 +1,6 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Activity
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
@@ -12,8 +11,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
describe "fetch the latest Follow" do
test "fetches the latest Follow activity" do
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
- follower = Repo.get_by(User, ap_id: activity.data["actor"])
- followed = Repo.get_by(User, ap_id: activity.data["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"])
assert activity == Utils.fetch_latest_follow(follower, followed)
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index b3167a861..b89c42327 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -89,8 +89,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"followed" => user.nickname
})
- user = User.get_by_id(user.id)
- follower = User.get_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, user)
end
@@ -112,8 +112,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"followed" => user.nickname
})
- user = User.get_by_id(user.id)
- follower = User.get_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, user)
end
@@ -145,13 +145,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user2: user2
} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user1.id).tags == ["x", "foo", "bar"]
- assert User.get_by_id(user2.id).tags == ["y", "foo", "bar"]
+ assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
+ assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user3.id).tags == ["unchanged"]
+ assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
@@ -181,13 +181,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user2: user2
} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user1.id).tags == []
- assert User.get_by_id(user2.id).tags == ["y"]
+ assert User.get_cached_by_id(user1.id).tags == []
+ assert User.get_cached_by_id(user2.id).tags == ["y"]
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user3.id).tags == ["unchanged"]
+ assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
@@ -257,7 +257,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated == true
assert json_response(conn, :no_content)
end
@@ -269,7 +269,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: true})
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated == false
assert json_response(conn, :no_content)
end
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 3d2bb8929..a5b07c446 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -40,19 +40,19 @@ defmodule Pleroma.Web.CommonAPITest do
test "it adds emoji in the object" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"})
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":firefox:"})
- assert Object.normalize(activity).data["emoji"]["moominmamma"]
+ assert Object.normalize(activity).data["emoji"]["firefox"]
end
test "it adds emoji when updating profiles" do
- user = insert(:user, %{name: ":karjalanpiirakka:"})
+ user = insert(:user, %{name: ":firefox:"})
CommonAPI.update(user)
user = User.get_cached_by_ap_id(user.ap_id)
- [karjalanpiirakka] = user.info.source_data["tag"]
+ [firefox] = user.info.source_data["tag"]
- assert karjalanpiirakka["name"] == ":karjalanpiirakka:"
+ assert firefox["name"] == ":firefox:"
end
describe "posting" do
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index f0c59d5c3..ab4c62b35 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -37,21 +37,21 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
test "parses emoji from name and bio" do
- {:ok, user} = UserBuilder.insert(%{name: ":karjalanpiirakka:", bio: ":perkele:"})
+ {:ok, user} = UserBuilder.insert(%{name: ":blank:", bio: ":firefox:"})
expected = [
%{
"type" => "Emoji",
- "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"},
- "name" => ":perkele:"
+ "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/emoji/Firefox.gif"},
+ "name" => ":firefox:"
},
%{
"type" => "Emoji",
"icon" => %{
"type" => "Image",
- "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"
+ "url" => "#{Endpoint.url()}/emoji/blank.png"
},
- "name" => ":karjalanpiirakka:"
+ "name" => ":blank:"
}
]
@@ -119,6 +119,31 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert output == expected
end
+ test "works for bare text/bbcode" do
+ text = "[b]hello world[/b]"
+ expected = "<strong>hello world</strong>"
+
+ {output, [], []} = Utils.format_input(text, "text/bbcode")
+
+ assert output == expected
+
+ text = "[b]hello world![/b]\n\nsecond paragraph!"
+ expected = "<strong>hello world!</strong><br>\n<br>\nsecond paragraph!"
+
+ {output, [], []} = Utils.format_input(text, "text/bbcode")
+
+ assert output == expected
+
+ text = "[b]hello world![/b]\n\n<strong>second paragraph!</strong>"
+
+ expected =
+ "<strong>hello world!</strong><br>\n<br>\n&lt;strong&gt;second paragraph!&lt;/strong&gt;"
+
+ {output, [], []} = Utils.format_input(text, "text/bbcode")
+
+ assert output == expected
+ end
+
test "works for text/markdown with mentions" do
{:ok, user} =
UserBuilder.insert(%{nickname: "user__test", ap_id: "http://foo.com/user__test"})
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index d7487bed9..a24f2a050 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -56,14 +56,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
bot: false,
source: %{
note: "",
- privacy: "public",
- sensitive: false
+ sensitive: false,
+ pleroma: %{}
},
pleroma: %{
confirmation_pending: false,
tags: [],
is_admin: false,
is_moderator: false,
+ hide_favorites: true,
+ hide_followers: false,
+ hide_follows: false,
relationship: %{}
}
}
@@ -81,8 +84,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
"follows" => true
}
- assert %{pleroma: %{notification_settings: ^notification_settings}} =
- AccountView.render("account.json", %{user: user, for: user})
+ privacy = user.info.default_scope
+
+ assert %{
+ pleroma: %{notification_settings: ^notification_settings},
+ source: %{privacy: ^privacy}
+ } = AccountView.render("account.json", %{user: user, for: user})
end
test "Represent a Service(bot) account" do
@@ -114,14 +121,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
bot: true,
source: %{
note: "",
- privacy: "public",
- sensitive: false
+ sensitive: false,
+ pleroma: %{}
},
pleroma: %{
confirmation_pending: false,
tags: [],
is_admin: false,
is_moderator: false,
+ hide_favorites: true,
+ hide_followers: false,
+ hide_follows: false,
relationship: %{}
}
}
@@ -169,15 +179,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "represent an embedded relationship" do
user =
insert(:user, %{
- info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
+ info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
nickname: "shp@shitposter.club",
inserted_at: ~N[2017-08-15 15:47:06.597036]
})
other_user = insert(:user)
-
{:ok, other_user} = User.follow(other_user, user)
{:ok, other_user} = User.block(other_user, user)
+ {:ok, _} = User.follow(insert(:user), user)
expected = %{
id: to_string(user.id),
@@ -186,7 +196,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
display_name: user.name,
locked: false,
created_at: "2017-08-15T15:47:06.000Z",
- followers_count: 3,
+ followers_count: 1,
following_count: 0,
statuses_count: 5,
note: user.bio,
@@ -200,14 +210,17 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
bot: true,
source: %{
note: "",
- privacy: "public",
- sensitive: false
+ sensitive: false,
+ pleroma: %{}
},
pleroma: %{
confirmation_pending: false,
tags: [],
is_admin: false,
is_moderator: false,
+ hide_favorites: true,
+ hide_followers: false,
+ hide_follows: false,
relationship: %{
id: to_string(user.id),
following: false,
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 786af2088..c2a12d3c7 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -445,7 +445,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "deleting a status" do
test "when you created it", %{conn: conn} do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
conn =
conn
@@ -1021,6 +1021,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
user1 = insert(:user)
user2 = insert(:user)
user3 = insert(:user)
+ CommonAPI.favorite(activity.id, user2)
+ {:ok, _bookmark} = Pleroma.Bookmark.create(user2.id, activity.id)
{:ok, reblog_activity1, _object} = CommonAPI.repeat(activity.id, user1)
{:ok, _, _object} = CommonAPI.repeat(activity.id, user2)
@@ -1031,7 +1033,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
- "reblogged" => false
+ "reblogged" => false,
+ "favourited" => false,
+ "bookmarked" => false
} = json_response(conn_res, 200)
conn_res =
@@ -1041,7 +1045,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{
"reblog" => %{"id" => id, "reblogged" => true, "reblogs_count" => 2},
- "reblogged" => true
+ "reblogged" => true,
+ "favourited" => true,
+ "bookmarked" => true
} = json_response(conn_res, 200)
assert to_string(activity.id) == id
@@ -1161,7 +1167,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "unimplemented pinned statuses feature", %{conn: conn} do
note = insert(:note_activity)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
conn =
conn
@@ -1172,7 +1178,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "gets an users media", %{conn: conn} do
note = insert(:note_activity)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
file = %Plug.Upload{
content_type: "image/jpg",
@@ -1247,8 +1253,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1267,8 +1273,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1280,8 +1286,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert relationship = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == true
end
@@ -1304,7 +1310,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1314,8 +1320,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert relationship = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
end
@@ -1600,7 +1606,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "following" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1609,7 +1615,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "following" => false} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1620,6 +1626,44 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert id == to_string(other_user.id)
end
+ test "following without reblogs" do
+ follower = insert(:user)
+ followed = insert(:user)
+ other_user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, follower)
+ |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=false")
+
+ assert %{"showing_reblogs" => false} = json_response(conn, 200)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
+ {:ok, reblog, _} = CommonAPI.repeat(activity.id, followed)
+
+ conn =
+ build_conn()
+ |> assign(:user, User.get_cached_by_id(follower.id))
+ |> get("/api/v1/timelines/home")
+
+ assert [] == json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, follower)
+ |> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
+
+ assert %{"showing_reblogs" => true} = json_response(conn, 200)
+
+ conn =
+ build_conn()
+ |> assign(:user, User.get_cached_by_id(follower.id))
+ |> get("/api/v1/timelines/home")
+
+ expected_activity_id = reblog.id
+ assert [%{"id" => ^expected_activity_id}] = json_response(conn, 200)
+ end
+
test "following / unfollowing errors" do
user = insert(:user)
@@ -1665,7 +1709,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "muting" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1720,7 +1764,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
@@ -1944,6 +1988,199 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert [] = json_response(third_conn, 200)
end
+ describe "getting favorites timeline of specified user" do
+ setup do
+ [current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
+ [current_user: current_user, user: user]
+ end
+
+ test "returns list of statuses favorited by specified user", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ [activity | _] = insert_pair(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ [like] = response
+
+ assert length(response) == 1
+ assert like["id"] == activity.id
+ end
+
+ test "returns favorites for specified user_id when user is not logged in", %{
+ conn: conn,
+ user: user
+ } do
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+ end
+
+ test "returns favorited DM only when user is logged in and he is one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ {:ok, direct} =
+ CommonAPI.post(current_user, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 1
+
+ anonymous_response =
+ conn
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(anonymous_response) == 0
+ end
+
+ test "does not return others' favorited DM when user is not one of recipients", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ user_two = insert(:user)
+
+ {:ok, direct} =
+ CommonAPI.post(user_two, %{
+ "status" => "Hi @#{user.nickname}!",
+ "visibility" => "direct"
+ })
+
+ CommonAPI.favorite(direct.id, user)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert length(response) == 0
+ end
+
+ test "paginates favorites using since_id and max_id", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ activities = insert_list(10, :note_activity)
+
+ Enum.each(activities, fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ third_activity = Enum.at(activities, 2)
+ seventh_activity = Enum.at(activities, 6)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
+ since_id: third_activity.id,
+ max_id: seventh_activity.id
+ })
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ refute third_activity in response
+ refute seventh_activity in response
+ end
+
+ test "limits favorites using limit parameter", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ 7
+ |> insert_list(:note_activity)
+ |> Enum.each(fn activity ->
+ CommonAPI.favorite(activity.id, user)
+ end)
+
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
+ |> json_response(:ok)
+
+ assert length(response) == 3
+ end
+
+ test "returns empty response when user does not have any favorited statuses", %{
+ conn: conn,
+ current_user: current_user,
+ user: user
+ } do
+ response =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+ |> json_response(:ok)
+
+ assert Enum.empty?(response)
+ end
+
+ test "returns 404 error when specified user is not exist", %{conn: conn} do
+ conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
+
+ assert json_response(conn, 404) == %{"error" => "Record not found"}
+ end
+
+ test "returns 403 error when user has hidden own favorites", %{
+ conn: conn,
+ current_user: current_user
+ } do
+ user = insert(:user, %{info: %{hide_favorites: true}})
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+
+ test "hides favorites for new users by default", %{conn: conn, current_user: current_user} do
+ user = insert(:user)
+ activity = insert(:note_activity)
+ CommonAPI.favorite(activity.id, user)
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
+
+ assert user.info.hide_favorites
+ assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
+ end
+ end
+
describe "updating credentials" do
test "updates the user's bio", %{conn: conn} do
user = insert(:user)
@@ -1977,6 +2214,78 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user["locked"] == true
end
+ test "updates the user's default scope", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["privacy"] == "cofe"
+ end
+
+ test "updates the user's hide_followers status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_followers: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_followers"] == true
+ end
+
+ test "updates the user's hide_follows status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_follows: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_follows"] == true
+ end
+
+ test "updates the user's hide_favorites status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["pleroma"]["hide_favorites"] == true
+ end
+
+ test "updates the user's show_role status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{show_role: "false"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["pleroma"]["show_role"] == false
+ end
+
+ test "updates the user's no_rich_text status", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
+
+ assert user = json_response(conn, 200)
+ assert user["source"]["pleroma"]["no_rich_text"] == true
+ end
+
test "updates the user's name", %{conn: conn} do
user = insert(:user)
@@ -2080,7 +2389,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
# Stats should count users with missing or nil `info.deactivated` value
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
info_change = Changeset.change(user.info, %{deactivated: nil})
{:ok, _user} =
diff --git a/test/web/mastodon_api/notification_view_test.exs b/test/web/mastodon_api/notification_view_test.exs
index f2c1eb76c..977ea1e87 100644
--- a/test/web/mastodon_api/notification_view_test.exs
+++ b/test/web/mastodon_api/notification_view_test.exs
@@ -21,7 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
mentioned_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
expected = %{
id: to_string(notification.id),
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index a02c7c210..5fddc6c58 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Bookmark
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
@@ -128,6 +129,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
pleroma: %{
local: true,
conversation_id: convo_id,
+ in_reply_to_account_acct: nil,
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["content"])},
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(note.data["object"]["summary"])}
}
@@ -152,6 +154,25 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert status.muted == true
end
+ test "tells if the status is bookmarked" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Cute girls doing cute things"})
+ status = StatusView.render("status.json", %{activity: activity})
+
+ assert status.bookmarked == false
+
+ status = StatusView.render("status.json", %{activity: activity, for: user})
+
+ assert status.bookmarked == false
+
+ {:ok, _bookmark} = Bookmark.create(user.id, activity.id)
+
+ status = StatusView.render("status.json", %{activity: activity, for: user})
+
+ assert status.bookmarked == true
+ end
+
test "a reply" do
note = insert(:note_activity)
user = insert(:user)
@@ -178,7 +199,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("status.json", %{activity: activity})
- actor = User.get_by_ap_id(activity.actor)
+ actor = User.get_cached_by_ap_id(activity.actor)
assert status.mentions ==
Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index fb505fab3..6e96537ec 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -365,6 +365,27 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert html_response(conn, 200) =~ ~s(type="submit")
end
+ test "properly handles internal calls with `authorization`-wrapped params", %{
+ app: app,
+ conn: conn
+ } do
+ conn =
+ get(
+ conn,
+ "/oauth/authorize",
+ %{
+ "authorization" => %{
+ "response_type" => "code",
+ "client_id" => app.client_id,
+ "redirect_uri" => app.redirect_uris,
+ "scope" => "read"
+ }
+ }
+ )
+
+ assert html_response(conn, 200) =~ ~s(type="submit")
+ end
+
test "renders authentication page if user is already authenticated but `force_login` is tru-ish",
%{app: app, conn: conn} do
token = insert(:oauth_token, app_id: app.id)
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 2950f11c0..7441e5fce 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Object
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
@@ -41,7 +40,8 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 200)
# Set a wrong magic-key for a user so it has to refetch
- salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+ salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+
# Wrong key
info_cng =
User.Info.remote_user_creation(salmon_user.info, %{
@@ -52,7 +52,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
salmon_user
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_embed(:info, info_cng)
- |> Repo.update()
+ |> User.update_and_set_cache()
conn =
build_conn()
@@ -86,7 +86,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
test "gets an object", %{conn: conn} do
note_activity = insert(:note_activity)
- user = User.get_by_ap_id(note_activity.data["actor"])
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
url = "/objects/#{uuid}"
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 50467c71f..2916caf8d 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -30,7 +30,7 @@ defmodule Pleroma.Web.OStatusTest do
{:ok, [activity]} = OStatus.handle_incoming(incoming)
object = Object.normalize(activity.data["object"])
- user = User.get_by_ap_id(activity.data["actor"])
+ user = User.get_cached_by_ap_id(activity.data["actor"])
assert user.info.note_count == 1
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
@@ -296,8 +296,8 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_by_ap_id(activity.data["actor"])
- followed = User.get_by_ap_id(activity.data["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"])
assert User.following?(follower, followed)
end
@@ -320,8 +320,8 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_by_ap_id(activity.data["actor"])
- followed = User.get_by_ap_id(activity.data["object"]["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"]["object"])
refute User.following?(follower, followed)
end
@@ -355,7 +355,7 @@ defmodule Pleroma.Web.OStatusTest do
{:ok, user} = OStatus.find_or_make_user(uri)
- user = Pleroma.User.get_by_id(user.id)
+ user = Pleroma.User.get_cached_by_id(user.id)
assert user.name == "Constance Variable"
assert user.nickname == "lambadalambda@social.heldscal.la"
assert user.local == false
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 6bac2c9f6..1e948086a 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -5,6 +5,8 @@
defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase
+ alias Pleroma.Object
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
@@ -52,16 +54,12 @@ defmodule Pleroma.Web.Push.ImplTest do
data: %{alerts: %{"follow" => true, "mention" => false}}
)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "<Lorem ipsum dolor sit amet."})
+
notif =
insert(:notification,
user: user,
- activity: %Pleroma.Activity{
- data: %{
- "type" => "Create",
- "actor" => user.ap_id,
- "object" => %{"content" => "<Lorem ipsum dolor sit amet."}
- }
- }
+ activity: activity
)
assert Impl.perform(notif) == [:ok, :ok]
@@ -100,48 +98,65 @@ defmodule Pleroma.Web.Push.ImplTest do
end
test "renders body for create activity" do
+ user = insert(:user, nickname: "Bob")
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ object = Object.normalize(activity)
+
assert Impl.format_body(
%{
- activity: %{
- data: %{
- "type" => "Create",
- "object" => %{
- "content" =>
- "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
- }
- }
- }
+ activity: activity
},
- %{nickname: "Bob"}
+ user,
+ object
) ==
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
end
test "renders body for follow activity" do
- assert Impl.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
+ user = insert(:user, nickname: "Bob")
+ other_user = insert(:user)
+ {:ok, _, _, activity} = CommonAPI.follow(user, other_user)
+ object = Object.normalize(activity)
+
+ assert Impl.format_body(%{activity: activity}, user, object) ==
"@Bob has followed you"
end
test "renders body for announce activity" do
user = insert(:user)
- note =
- insert(:note, %{
- data: %{
- "content" =>
- "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
- }
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
})
- note_activity = insert(:note_activity, %{note: note})
- announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
+ {:ok, announce_activity, _} = CommonAPI.repeat(activity.id, user)
+ object = Object.normalize(activity)
- assert Impl.format_body(%{activity: announce_activity}, user) ==
+ assert Impl.format_body(%{activity: announce_activity}, user, object) ==
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
end
test "renders body for like activity" do
- assert Impl.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
+ user = insert(:user, nickname: "Bob")
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
+ })
+
+ {:ok, activity, _} = CommonAPI.favorite(activity.id, user)
+ object = Object.normalize(activity)
+
+ assert Impl.format_body(%{activity: activity}, user, object) ==
"@Bob has favorited your post"
end
end
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 35503259b..7532578ca 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -99,7 +99,7 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
}
{:ok, activity} = Repo.insert(%Activity{data: activity_data, recipients: activity_data["to"]})
- user = User.get_by_ap_id(activity.data["actor"])
+ user = User.get_cached_by_ap_id(activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
poster = fn url, _data, _headers ->
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 9a9630c19..43ad71a16 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -270,7 +270,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "returns one status", %{conn: conn} do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
- actor = Repo.get_by!(User, ap_id: activity.data["actor"])
+ actor = User.get_cached_by_ap_id(activity.data["actor"])
conn =
conn
@@ -720,7 +720,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/create.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert User.ap_followers(followed) in current_user.following
assert json_response(conn, 200) ==
@@ -735,8 +735,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/create.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
- followed = User.get_by_id(followed.id)
+ current_user = User.get_cached_by_id(current_user.id)
+ followed = User.get_cached_by_id(followed.id)
refute User.ap_followers(followed) in current_user.following
@@ -765,7 +765,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert current_user.following == [current_user.ap_id]
assert json_response(conn, 200) ==
@@ -789,7 +789,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/blocks/create.json", %{user_id: blocked.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert User.blocks?(current_user, blocked)
assert json_response(conn, 200) ==
@@ -816,7 +816,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert current_user.info.blocks == []
assert json_response(conn, 200) ==
@@ -847,7 +847,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(current_user.nickname, "test")
|> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert is_map(current_user.avatar)
assert json_response(conn, 200) ==
@@ -956,7 +956,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post(request_path)
activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_by_ap_id(note_activity.data["actor"])
+ activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
assert json_response(response, 200) ==
ActivityView.render("activity.json", %{
@@ -994,7 +994,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> post(request_path)
activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_by_ap_id(note_activity.data["actor"])
+ activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
assert json_response(response, 200) ==
ActivityView.render("activity.json", %{
@@ -1022,7 +1022,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
user = json_response(conn, 200)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert user == UserView.render("show.json", %{user: fetched_user})
end
@@ -1116,7 +1116,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
test "it confirms the user account", %{conn: conn, user: user} do
get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
refute user.info.confirmation_pending
refute user.info.confirmation_token
@@ -1742,7 +1742,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
})
assert json_response(conn, 200) == %{"status" => "success"}
- fetched_user = User.get_by_id(current_user.id)
+ fetched_user = User.get_cached_by_id(current_user.id)
assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
end
end
@@ -1783,8 +1783,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1823,8 +1823,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1846,8 +1846,8 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
@@ -1916,7 +1916,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/media/metadata/create" do
setup do
object = insert(:note)
- user = User.get_by_ap_id(object.data["actor"])
+ user = User.get_cached_by_ap_id(object.data["actor"])
%{object: object, user: user}
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 5bea1037a..d601c8f1f 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -41,7 +41,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
input = %{
"status" =>
- "Hello again, @shp.<script></script>\nThis is on another :moominmamma: line. #2hu #epic #phantasmagoric",
+ "Hello again, @shp.<script></script>\nThis is on another :firefox: line. #2hu #epic #phantasmagoric",
"media_ids" => [object.id]
}
@@ -49,7 +49,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
object = Object.normalize(activity.data["object"])
expected_text =
- "Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: line. <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a class='hashtag' data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a class='hashtag' data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
+ "Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :firefox: line. <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a class='hashtag' data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a class='hashtag' data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
assert get_in(object.data, ["content"]) == expected_text
assert get_in(object.data, ["type"]) == "Note"
@@ -65,8 +65,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert Enum.member?(get_in(activity.data, ["to"]), "shp")
assert activity.local == true
- assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
- object.data["emoji"]
+ assert %{"firefox" => "http://localhost:4001/emoji/Firefox.gif"} = object.data["emoji"]
# hashtags
assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
@@ -79,7 +78,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert activity.data["object"] == object.data["id"]
- user = User.get_by_ap_id(user.ap_id)
+ user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.note_count == 1
end
@@ -130,7 +129,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert User.ap_followers(followed) in user.following
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
{:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
@@ -282,7 +281,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -300,7 +299,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -395,7 +394,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -418,7 +417,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Invalid token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on expired token" do
@@ -438,7 +437,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -463,7 +462,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
check_fn = fn invite ->
data = Map.put(data, "token", invite.token)
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
@@ -500,7 +499,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("vinny")
+ refute User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
@@ -535,7 +534,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -556,7 +555,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -586,7 +585,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
@@ -611,7 +610,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
@@ -631,7 +630,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on overdue date" do
@@ -651,7 +650,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on with overdue date and after max" do
@@ -673,7 +672,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
@@ -689,7 +688,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
{:error, error_object} = TwitterAPI.register_user(data)
assert is_binary(error_object[:error])
- refute User.get_by_nickname("lain")
+ refute User.get_cached_by_nickname("lain")
end
test "it assigns an integer conversation_id" do
@@ -710,7 +709,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
id = "https://mastodon.social/users/lambadalambda"
user = insert(:user)
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
- remote = User.get_by_ap_id(id)
+ remote = User.get_cached_by_ap_id(id)
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index c58b49ea4..56474447b 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -245,4 +245,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert html_response(response, 200) =~ "Log in to follow"
end
end
+
+ test "GET /api/pleroma/healthcheck", %{conn: conn} do
+ conn = get(conn, "/api/pleroma/healthcheck")
+
+ assert conn.status in [200, 503]
+ end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index b5440c612..d84ab7420 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -91,16 +91,16 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
test "a create activity with a summary containing emoji" do
{:ok, activity} =
CommonAPI.post(insert(:user), %{
- "spoiler_text" => ":woollysocks: meow",
+ "spoiler_text" => ":firefox: meow",
"status" => "."
})
result = ActivityView.render("activity.json", activity: activity)
- expected = ":woollysocks: meow"
+ expected = ":firefox: meow"
expected_html =
- "<img height=\"32px\" width=\"32px\" alt=\"woollysocks\" title=\"woollysocks\" src=\"http://localhost:4001/finmoji/128px/woollysocks-128.png\" /> meow"
+ "<img height=\"32px\" width=\"32px\" alt=\"firefox\" title=\"firefox\" src=\"http://localhost:4001/emoji/Firefox.gif\" /> meow"
assert result["summary"] == expected
assert result["summary_html"] == expected_html
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 0feaf4b64..c99dbddeb 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -89,29 +89,34 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"following" => false,
"follows_you" => false,
"statusnet_blocking" => false,
- "rights" => %{
- "delete_others_notice" => false,
- "admin" => false
- },
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public",
- "no_rich_text" => false,
"hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
"tags" => []
- }
+ },
+ "rights" => %{"admin" => false, "delete_others_notice" => false},
+ "role" => "member"
}
assert represented == UserView.render("show.json", %{user: user})
end
+ test "User exposes settings for themselves and only for themselves", %{user: user} do
+ as_user = UserView.render("show.json", %{user: user, for: user})
+ assert as_user["default_scope"] == user.info.default_scope
+ assert as_user["no_rich_text"] == user.info.no_rich_text
+ as_stranger = UserView.render("show.json", %{user: user})
+ refute as_stranger["default_scope"]
+ refute as_stranger["no_rich_text"]
+ end
+
test "A user for a given other follower", %{user: user} do
follower = insert(:user, %{following: [User.ap_followers(user)]})
{:ok, user} = User.update_follower_count(user)
@@ -137,24 +142,20 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"following" => true,
"follows_you" => false,
"statusnet_blocking" => false,
- "rights" => %{
- "delete_others_notice" => false,
- "admin" => false
- },
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public",
- "no_rich_text" => false,
"hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
"tags" => []
- }
+ },
+ "rights" => %{"admin" => false, "delete_others_notice" => false},
+ "role" => "member"
}
assert represented == UserView.render("show.json", %{user: user, for: follower})
@@ -186,24 +187,20 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"following" => false,
"follows_you" => true,
"statusnet_blocking" => false,
- "rights" => %{
- "delete_others_notice" => false,
- "admin" => false
- },
"statusnet_profile_url" => follower.ap_id,
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public",
- "no_rich_text" => false,
"hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
"tags" => []
- }
+ },
+ "rights" => %{"admin" => false, "delete_others_notice" => false},
+ "role" => "member"
}
assert represented == UserView.render("show.json", %{user: follower, for: user})
@@ -272,27 +269,23 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
"following" => false,
"follows_you" => false,
"statusnet_blocking" => true,
- "rights" => %{
- "delete_others_notice" => false,
- "admin" => false
- },
"statusnet_profile_url" => user.ap_id,
"cover_photo" => banner,
"background_image" => nil,
"is_local" => true,
"locked" => false,
- "default_scope" => "public",
- "no_rich_text" => false,
"hide_follows" => false,
"hide_followers" => false,
"fields" => [],
"pleroma" => %{
"confirmation_pending" => false,
"tags" => []
- }
+ },
+ "rights" => %{"admin" => false, "delete_others_notice" => false},
+ "role" => "member"
}
- blocker = User.get_by_id(blocker.id)
+ blocker = User.get_cached_by_id(blocker.id)
assert represented == UserView.render("show.json", %{user: user, for: blocker})
end