From 6e4f52f8a2e510273149acbaf629521d1b4aec2e Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 16 Oct 2019 16:16:39 +0200
Subject: Introduce new ingestion pipeline structure, implement internal Likes
with it.
---
test/web/common_api/common_api_test.exs | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 83df44c36..d46a361c5 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -251,9 +251,12 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, post_activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
- {:ok, %Activity{}, _} = CommonAPI.favorite(activity.id, user)
+ {:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
+ assert data["type"] == "Like"
+ assert data["actor"] == user.ap_id
+ assert data["object"] == post_activity.data["object"]
end
test "retweeting a status twice returns an error" do
@@ -270,8 +273,8 @@ defmodule Pleroma.Web.CommonAPITest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
- {:ok, %Activity{}, _object} = CommonAPI.favorite(activity.id, user)
- {:error, _} = CommonAPI.favorite(activity.id, user)
+ {:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
+ {:error, _} = CommonAPI.favorite(user, activity.id)
end
end
--
cgit v1.2.3
From 4ec299ea9c1cf45c42e98d7b33f33a72f5e7a9c0 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 18 Oct 2019 12:11:25 +0200
Subject: CommonAPI tests: Capture logs.
---
test/web/common_api/common_api_test.exs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index d46a361c5..63d7ea79f 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -13,6 +13,7 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ import ExUnit.CaptureLog
require Pleroma.Constants
@@ -274,7 +275,9 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
- {:error, _} = CommonAPI.favorite(user, activity.id)
+ assert capture_log(fn ->
+ assert {:error, _} = CommonAPI.favorite(user, activity.id)
+ end) =~ "[error]"
end
end
--
cgit v1.2.3
From 15bbc34c079018f1c988fe9d445bec50e85bbeaf Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 18 Oct 2019 12:44:53 +0200
Subject: Tests: Capture log.
---
test/web/common_api/common_api_test.exs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 63d7ea79f..8195b1910 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -275,9 +275,10 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
+
assert capture_log(fn ->
- assert {:error, _} = CommonAPI.favorite(user, activity.id)
- end) =~ "[error]"
+ assert {:error, _} = CommonAPI.favorite(user, activity.id)
+ end) =~ "[error]"
end
end
--
cgit v1.2.3
From 514c899275a32e6ef63305f9424c50344d41b12e Mon Sep 17 00:00:00 2001
From: Alexander Strizhakov
Date: Tue, 11 Feb 2020 10:12:57 +0300
Subject: adding gun adapter
---
test/web/common_api/common_api_utils_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 848300ef3..759501a67 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -474,6 +474,13 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
activity = insert(:note_activity, user: user, note: object)
Pleroma.Repo.delete(object)
+ obj_url = activity.data["object"]
+
+ Tesla.Mock.mock(fn
+ %{method: :get, url: ^obj_url} ->
+ %Tesla.Env{status: 404, body: ""}
+ end)
+
assert Utils.maybe_notify_mentioned_recipients(["test-test"], activity) == [
"test-test"
]
--
cgit v1.2.3
From 5af798f24659a1558149cf6deddfa55fbc493ac2 Mon Sep 17 00:00:00 2001
From: Mark Felder
Date: Tue, 10 Mar 2020 13:08:00 -0500
Subject: Fix enforcement of character limits
---
test/web/common_api/common_api_test.exs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 299d968db..b80523160 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -202,13 +202,15 @@ defmodule Pleroma.Web.CommonAPITest do
CommonAPI.post(user, %{"status" => ""})
end
- test "it returns error when character limit is exceeded" do
+ test "it validates character limits are correctly enforced" do
Pleroma.Config.put([:instance, :limit], 5)
user = insert(:user)
assert {:error, "The status is over the character limit"} =
CommonAPI.post(user, %{"status" => "foobar"})
+
+ assert {:ok, activity} = CommonAPI.post(user, %{"status" => "12345"})
end
test "it can handle activities that expire" do
--
cgit v1.2.3
From d1379c4de8ca27fa6d02d20a0029b248efe1d09e Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Thu, 13 Feb 2020 03:39:47 +0100
Subject: Formatting: Do not use \n and prefer
instead
It moves bbcode to bbcode_pleroma as the former is owned by kaniini
and transfering ownership wasn't done in a timely manner.
Closes: https://git.pleroma.social/pleroma/pleroma/issues/1374
Closes: https://git.pleroma.social/pleroma/pleroma/issues/1375
---
test/web/common_api/common_api_utils_test.exs | 28 +++++++++++++--------------
1 file changed, 13 insertions(+), 15 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index b380d10d8..45fc94522 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -89,8 +89,8 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert output == expected
- text = "hello world!
\n\nsecond paragraph
"
- expected = "hello world!
\n\nsecond paragraph
"
+ text = "hello world!
\nsecond paragraph
"
+ expected = "hello world!
\nsecond paragraph
"
{output, [], []} = Utils.format_input(text, "text/html")
@@ -99,14 +99,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "works for bare text/markdown" do
text = "**hello world**"
- expected = "hello world
\n"
+ expected = "hello world
"
{output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
text = "**hello world**\n\n*another paragraph*"
- expected = "hello world
\nanother paragraph
\n"
+ expected = "hello world
another paragraph
"
{output, [], []} = Utils.format_input(text, "text/markdown")
@@ -118,7 +118,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
by someone
"""
- expected = "cool quote
\n
\nby someone
\n"
+ expected = "cool quote
by someone
"
{output, [], []} = Utils.format_input(text, "text/markdown")
@@ -134,7 +134,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert output == expected
text = "[b]hello world![/b]\n\nsecond paragraph!"
- expected = "hello world!
\n
\nsecond paragraph!"
+ expected = "hello world!
second paragraph!"
{output, [], []} = Utils.format_input(text, "text/bbcode")
@@ -143,7 +143,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "[b]hello world![/b]\n\nsecond paragraph!"
expected =
- "hello world!
\n
\n<strong>second paragraph!</strong>"
+ "hello world!
<strong>second paragraph!</strong>"
{output, [], []} = Utils.format_input(text, "text/bbcode")
@@ -156,16 +156,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
- expected =
- ~s(hello world
\nanother @user__test and @user__test google.com paragraph
\n)
-
{output, _, _} = Utils.format_input(text, "text/markdown")
- assert output == expected
+ assert output ==
+ ~s(hello world
another @user__test and @user__test google.com paragraph
)
end
end
--
cgit v1.2.3
From 1c05f539aaea32fe993e5299e656aa44c322e8de Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Fri, 20 Mar 2020 18:33:00 +0300
Subject: Improved in-test `clear_config/n` applicability (setup / setup_all /
in-test usage).
---
test/web/common_api/common_api_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index b80523160..0da0bd2e2 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -17,9 +17,9 @@ defmodule Pleroma.Web.CommonAPITest do
require Pleroma.Constants
- clear_config([:instance, :safe_dm_mentions])
- clear_config([:instance, :limit])
- clear_config([:instance, :max_pinned_statuses])
+ setup do: clear_config([:instance, :safe_dm_mentions])
+ setup do: clear_config([:instance, :limit])
+ setup do: clear_config([:instance, :max_pinned_statuses])
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
--
cgit v1.2.3
From be9d18461a5ed6bd835e2eba8d3b54ba61fc51fb Mon Sep 17 00:00:00 2001
From: Ivan Tashkinov
Date: Sat, 28 Mar 2020 18:49:03 +0300
Subject: FollowingRelationship storage & performance optimizations (state
turned `ecto_enum`-driven integer, reorganized indices etc.).
---
test/web/common_api/common_api_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 0da0bd2e2..e53a7cedd 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -562,7 +562,7 @@ defmodule Pleroma.Web.CommonAPITest do
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed)
- assert User.get_follow_state(follower, followed) == "pending"
+ assert User.get_follow_state(follower, followed) == :follow_pending
assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
assert User.get_follow_state(follower, followed) == nil
@@ -584,7 +584,7 @@ defmodule Pleroma.Web.CommonAPITest do
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
CommonAPI.follow(follower, followed)
- assert User.get_follow_state(follower, followed) == "pending"
+ assert User.get_follow_state(follower, followed) == :follow_pending
assert {:ok, follower} = CommonAPI.unfollow(follower, followed)
assert User.get_follow_state(follower, followed) == nil
--
cgit v1.2.3
From d067eaa7b3bb76e7fc5ae019d6e00510b657171d Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 8 Apr 2020 22:58:31 +0300
Subject: formatter.ex: Use Phoenix.HTML for mention/hashtag generation
Unlike concatenating strings, this makes sure everything is escaped.
Tests had to be changed because Phoenix.HTML runs attributes through
Enum.sort before generation for whatever reason.
---
test/web/common_api/common_api_utils_test.exs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index d383d1714..98cf02d49 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -159,11 +159,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{output, _, _} = Utils.format_input(text, "text/markdown")
assert output ==
- ~s(hello world
another @user__test and @user__test and @user__test google.com paragraph
)
+ }" href="http://foo.com/user__test" rel="ugc">@user__test google.com paragraph
)
end
end
--
cgit v1.2.3
From 8e637ae1a7b75fa08679ae9cf424650fc105de85 Mon Sep 17 00:00:00 2001
From: lain
Date: Thu, 9 Apr 2020 13:20:16 +0200
Subject: CommonAPI: Basic ChatMessage support.
---
test/web/common_api/common_api_test.exs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index f46ad0272..1aea06d24 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Chat
alias Pleroma.Conversation.Participation
alias Pleroma.Object
alias Pleroma.User
@@ -21,6 +22,26 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses])
+ describe "posting chat messages" do
+ test "it posts a chat message" do
+ author = insert(:user)
+ recipient = insert(:user)
+
+ {:ok, activity} = CommonAPI.post_chat_message(author, recipient, "a test message")
+
+ assert activity.data["type"] == "Create"
+ assert activity.local
+ object = Object.normalize(activity)
+
+ assert object.data["type"] == "ChatMessage"
+ assert object.data["to"] == [recipient.ap_id]
+ assert object.data["content"] == "a test message"
+
+ assert Chat.get(author.id, recipient.ap_id)
+ assert Chat.get(recipient.id, author.ap_id)
+ end
+ end
+
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
--
cgit v1.2.3
From 9172d719ccbf84d55236007d329fc880db69fe42 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Fri, 3 Apr 2020 13:03:32 +0200
Subject: profile emojis in User.emoji instead of source_data
---
test/web/common_api/common_api_test.exs | 12 ------------
test/web/common_api/common_api_utils_test.exs | 23 -----------------------
2 files changed, 35 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index f46ad0272..5e78c5758 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -97,18 +97,6 @@ defmodule Pleroma.Web.CommonAPITest do
assert Object.normalize(activity).data["emoji"]["firefox"]
end
- test "it adds emoji when updating profiles" do
- user = insert(:user, %{name: ":firefox:"})
-
- {:ok, activity} = CommonAPI.update(user)
- user = User.get_cached_by_ap_id(user.ap_id)
- [firefox] = user.source_data["tag"]
-
- assert firefox["name"] == ":firefox:"
-
- assert Pleroma.Constants.as_public() in activity.recipients
- end
-
describe "posting" do
test "it supports explicit addressing" do
user = insert(:user)
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 98cf02d49..b21445fe9 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Object
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.Endpoint
use Pleroma.DataCase
import ExUnit.CaptureLog
@@ -42,28 +41,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
end
- test "parses emoji from name and bio" do
- {:ok, user} = UserBuilder.insert(%{name: ":blank:", bio: ":firefox:"})
-
- expected = [
- %{
- "type" => "Emoji",
- "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/emoji/Firefox.gif"},
- "name" => ":firefox:"
- },
- %{
- "type" => "Emoji",
- "icon" => %{
- "type" => "Image",
- "url" => "#{Endpoint.url()}/emoji/blank.png"
- },
- "name" => ":blank:"
- }
- ]
-
- assert expected == Utils.emoji_from_profile(user)
- end
-
describe "format_input/3" do
test "works for bare text/plain" do
text = "hello world!"
--
cgit v1.2.3
From 3d4eca5dd4be297f03c244497d78db03e82a9d81 Mon Sep 17 00:00:00 2001
From: lain
Date: Thu, 16 Apr 2020 12:56:29 +0200
Subject: CommonAPI: Escape HTML for chat messages.
---
test/web/common_api/common_api_test.exs | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 168721c81..abe3e6f8d 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -27,7 +27,12 @@ defmodule Pleroma.Web.CommonAPITest do
author = insert(:user)
recipient = insert(:user)
- {:ok, activity} = CommonAPI.post_chat_message(author, recipient, "a test message")
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ "a test message "
+ )
assert activity.data["type"] == "Create"
assert activity.local
@@ -35,7 +40,9 @@ defmodule Pleroma.Web.CommonAPITest do
assert object.data["type"] == "ChatMessage"
assert object.data["to"] == [recipient.ap_id]
- assert object.data["content"] == "a test message"
+
+ assert object.data["content"] ==
+ "a test message <script>alert('uuu')</script>"
assert Chat.get(author.id, recipient.ap_id)
assert Chat.get(recipient.id, author.ap_id)
--
cgit v1.2.3
From 5b6818b3e5dc39e328f6f8d4b8f4587e5e1cef94 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 20 Apr 2020 12:08:47 +0200
Subject: CommonAPI: Obey local limit for chat messages.
---
test/web/common_api/common_api_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 1984aac8d..c17e30210 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -23,6 +23,8 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :max_pinned_statuses])
describe "posting chat messages" do
+ setup do: clear_config([:instance, :chat_limit])
+
test "it posts a chat message" do
author = insert(:user)
recipient = insert(:user)
@@ -47,6 +49,22 @@ defmodule Pleroma.Web.CommonAPITest do
assert Chat.get(author.id, recipient.ap_id)
assert Chat.get(recipient.id, author.ap_id)
end
+
+ test "it reject messages over the local limit" do
+ Pleroma.Config.put([:instance, :chat_limit], 2)
+
+ author = insert(:user)
+ recipient = insert(:user)
+
+ {:error, message} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ "123"
+ )
+
+ assert message == :content_too_long
+ end
end
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
--
cgit v1.2.3
From 7e53da250e3b41e01073148efea0fc4f49dea9d5 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 20 Apr 2020 14:08:54 +0200
Subject: ChatMessage: Support emoji.
---
test/web/common_api/common_api_test.exs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index c17e30210..86b3648ac 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -33,7 +33,7 @@ defmodule Pleroma.Web.CommonAPITest do
CommonAPI.post_chat_message(
author,
recipient,
- "a test message "
+ "a test message :firefox:"
)
assert activity.data["type"] == "Create"
@@ -44,7 +44,11 @@ defmodule Pleroma.Web.CommonAPITest do
assert object.data["to"] == [recipient.ap_id]
assert object.data["content"] ==
- "a test message <script>alert('uuu')</script>"
+ "a test message <script>alert('uuu')</script> :firefox:"
+
+ assert object.data["emoji"] == %{
+ "firefox" => "http://localhost:4001/emoji/Firefox.gif"
+ }
assert Chat.get(author.id, recipient.ap_id)
assert Chat.get(recipient.id, author.ap_id)
--
cgit v1.2.3
From e62173dfc8b739508345b7ab97477ae04fcdb457 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 22 Apr 2020 18:40:53 +0200
Subject: SideEffects: Run in transaction.
This fixes race conditions.
---
test/web/common_api/common_api_test.exs | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index e130736ec..68a29108a 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -21,6 +21,33 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses])
+ test "favoriting race condition" do
+ user = insert(:user)
+ users_serial = insert_list(10, :user)
+ users = insert_list(10, :user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+
+ users_serial
+ |> Enum.map(fn user ->
+ CommonAPI.favorite(user, activity.id)
+ end)
+
+ object = Object.get_by_ap_id(activity.data["object"])
+ assert object.data["like_count"] == 10
+
+ users
+ |> Enum.map(fn user ->
+ Task.async(fn ->
+ CommonAPI.favorite(user, activity.id)
+ end)
+ end)
+ |> Enum.map(&Task.await/1)
+
+ object = Object.get_by_ap_id(activity.data["object"])
+ assert object.data["like_count"] == 20
+ end
+
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
--
cgit v1.2.3
From 7d38197894692306c940b55045b91d563e138284 Mon Sep 17 00:00:00 2001
From: lain
Date: Thu, 23 Apr 2020 13:33:30 +0200
Subject: CommonAPI: Don't make repeating announces possible
---
test/web/common_api/common_api_test.exs | 18 +++++++++++++++---
test/web/common_api/common_api_utils_test.exs | 20 --------------------
2 files changed, 15 insertions(+), 23 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 68a29108a..e87193c83 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -283,6 +283,16 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
end
+ test "can't repeat a repeat" do
+ user = insert(:user)
+ other_user = insert(:user)
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+ {:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
+
+ refute match?({:ok, %Activity{}, _}, CommonAPI.repeat(announce.id, user))
+ end
+
test "repeating a status privately" do
user = insert(:user)
other_user = insert(:user)
@@ -312,8 +322,8 @@ defmodule Pleroma.Web.CommonAPITest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
- {:ok, %Activity{} = activity, object} = CommonAPI.repeat(activity.id, user)
- {:ok, ^activity, ^object} = CommonAPI.repeat(activity.id, user)
+ {:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
+ {:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
end
test "favoriting a status twice returns ok, but without the like activity" do
@@ -387,7 +397,9 @@ defmodule Pleroma.Web.CommonAPITest do
user = refresh_record(user)
- assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
+ id = activity.id
+
+ assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
user = refresh_record(user)
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index b21445fe9..18a3b3b87 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -335,26 +335,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
end
- describe "get_by_id_or_ap_id/1" do
- test "get activity by id" do
- activity = insert(:note_activity)
- %Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.id)
- assert note.id == activity.id
- end
-
- test "get activity by ap_id" do
- activity = insert(:note_activity)
- %Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.data["object"])
- assert note.id == activity.id
- end
-
- test "get activity by object when type isn't `Create` " do
- activity = insert(:like_activity)
- %Pleroma.Activity{} = like = Utils.get_by_id_or_ap_id(activity.id)
- assert like.data["object"] == activity.data["object"]
- end
- end
-
describe "to_master_date/1" do
test "removes microseconds from date (NaiveDateTime)" do
assert Utils.to_masto_date(~N[2015-01-23 23:50:07.123]) == "2015-01-23T23:50:07.000Z"
--
cgit v1.2.3
From cb12585098e0cc1e2e85d253812e1898e8034b7f Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 24 Apr 2020 14:37:53 +0200
Subject: Announcements: Prevent race condition.
---
test/web/common_api/common_api_test.exs | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index e87193c83..1758662b0 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -48,6 +48,33 @@ defmodule Pleroma.Web.CommonAPITest do
assert object.data["like_count"] == 20
end
+ test "repeating race condition" do
+ user = insert(:user)
+ users_serial = insert_list(10, :user)
+ users = insert_list(10, :user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+
+ users_serial
+ |> Enum.map(fn user ->
+ CommonAPI.repeat(activity.id, user)
+ end)
+
+ object = Object.get_by_ap_id(activity.data["object"])
+ assert object.data["announcement_count"] == 10
+
+ users
+ |> Enum.map(fn user ->
+ Task.async(fn ->
+ CommonAPI.repeat(activity.id, user)
+ end)
+ end)
+ |> Enum.map(&Task.await/1)
+
+ object = Object.get_by_ap_id(activity.data["object"])
+ assert object.data["announcement_count"] == 20
+ end
+
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
--
cgit v1.2.3
From 560f2c1979ca4d49f18abd6de6aac49875bfc771 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 28 Apr 2020 16:50:37 +0400
Subject: Add OpenAPI spec for ReportController
---
test/web/common_api/common_api_test.exs | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 1758662b0..c6ccc02c4 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -485,9 +485,9 @@ defmodule Pleroma.Web.CommonAPITest do
comment = "foobar"
report_data = %{
- "account_id" => target_user.id,
- "comment" => comment,
- "status_ids" => [activity.id]
+ account_id: target_user.id,
+ comment: comment,
+ status_ids: [activity.id]
}
note_obj = %{
@@ -517,9 +517,9 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, %Activity{id: report_id}} =
CommonAPI.report(reporter, %{
- "account_id" => target_user.id,
- "comment" => "I feel offended",
- "status_ids" => [activity.id]
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
})
{:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
@@ -538,9 +538,9 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, %Activity{id: report_id}} =
CommonAPI.report(reporter, %{
- "account_id" => target_user.id,
- "comment" => "I feel offended",
- "status_ids" => [activity.id]
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
})
assert CommonAPI.update_report_state(report_id, "test") == {:error, "Unsupported state"}
@@ -552,16 +552,16 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, %Activity{id: first_report_id}} =
CommonAPI.report(reporter, %{
- "account_id" => target_user.id,
- "comment" => "I feel offended",
- "status_ids" => [activity.id]
+ account_id: target_user.id,
+ comment: "I feel offended",
+ status_ids: [activity.id]
})
{:ok, %Activity{id: second_report_id}} =
CommonAPI.report(reporter, %{
- "account_id" => target_user.id,
- "comment" => "I feel very offended!",
- "status_ids" => [activity.id]
+ account_id: target_user.id,
+ comment: "I feel very offended!",
+ status_ids: [activity.id]
})
{:ok, report_ids} =
--
cgit v1.2.3
From 32b8386edeec3e9b24123c3ccc81a22f1edd5a1c Mon Sep 17 00:00:00 2001
From: lain
Date: Thu, 30 Apr 2020 21:23:18 +0200
Subject: DeleteValidator: Don't federate local deletions of remote objects.
Closes #1497
---
test/web/common_api/common_api_test.exs | 80 +++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 1758662b0..32d91ce02 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -9,11 +9,13 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ import Mock
require Pleroma.Constants
@@ -21,6 +23,84 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses])
+ describe "deletion" do
+ test "it allows users to delete their posts" do
+ user = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ assert {:ok, delete} = CommonAPI.delete(post.id, user)
+ assert delete.local
+ assert called(Pleroma.Web.Federator.publish(delete))
+ end
+
+ refute Activity.get_by_id(post.id)
+ end
+
+ test "it does not allow a user to delete their posts" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+
+ assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
+ assert Activity.get_by_id(post.id)
+ end
+
+ test "it allows moderators to delete other user's posts" do
+ user = insert(:user)
+ moderator = insert(:user, is_moderator: true)
+
+ {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+
+ assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
+ assert delete.local
+
+ refute Activity.get_by_id(post.id)
+ end
+
+ test "it allows admins to delete other user's posts" do
+ user = insert(:user)
+ moderator = insert(:user, is_admin: true)
+
+ {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+
+ assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
+ assert delete.local
+
+ refute Activity.get_by_id(post.id)
+ end
+
+ test "superusers deleting non-local posts won't federate the delete" do
+ # This is the user of the ingested activity
+ _user =
+ insert(:user,
+ local: false,
+ ap_id: "http://mastodon.example.org/users/admin",
+ last_refreshed_at: NaiveDateTime.utc_now()
+ )
+
+ moderator = insert(:user, is_admin: true)
+
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Jason.decode!()
+
+ {:ok, post} = Transmogrifier.handle_incoming(data)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
+ assert delete.local
+ refute called(Pleroma.Web.Federator.publish(:_))
+ end
+
+ refute Activity.get_by_id(post.id)
+ end
+ end
+
test "favoriting race condition" do
user = insert(:user)
users_serial = insert_list(10, :user)
--
cgit v1.2.3
From 66a8e1312dc82fa755a635984f89a5314917d209 Mon Sep 17 00:00:00 2001
From: eugenijm
Date: Mon, 27 Apr 2020 17:41:38 +0300
Subject: Mastodon API: do not create a following relationship if the
corresponding follow request doesn't exist when calling `POST
/api/v1/follow_requests/:id/authorize`
---
test/web/common_api/common_api_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index c6ccc02c4..bc0c1a791 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -697,6 +697,14 @@ defmodule Pleroma.Web.CommonAPITest do
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
end
+
+ test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
+ user = insert(:user, locked: true)
+ not_follower = insert(:user)
+ CommonAPI.accept_follow_request(not_follower, user)
+
+ assert Pleroma.FollowingRelationship.following?(not_follower, user) == false
+ end
end
describe "vote/3" do
--
cgit v1.2.3
From db55dc944581b1d4b50d1608b2e991050ea29bb3 Mon Sep 17 00:00:00 2001
From: lain
Date: Tue, 5 May 2020 12:28:28 +0200
Subject: ActivityPub: Remove `react_with_emoji`.
---
test/web/common_api/common_api_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index bc0c1a791..74171fcd9 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -278,7 +278,7 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
- {:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+ {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
assert reaction.data["actor"] == user.ap_id
assert reaction.data["content"] == "👍"
@@ -293,7 +293,7 @@ defmodule Pleroma.Web.CommonAPITest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
- {:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+ {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
{:ok, unreaction, _} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
--
cgit v1.2.3
From b34debe61540cf845ccf4ac93066e45a1d9c8f85 Mon Sep 17 00:00:00 2001
From: lain
Date: Tue, 5 May 2020 16:17:09 +0200
Subject: Undoing: Move undoing reactions to the pipeline everywhere.
---
test/web/common_api/common_api_test.exs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index bc0c1a791..0664b7f90 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -295,10 +295,11 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
{:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍")
- {:ok, unreaction, _} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
+ {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
assert unreaction.data["type"] == "Undo"
assert unreaction.data["object"] == reaction.data["id"]
+ assert unreaction.local
end
test "repeating a status" do
--
cgit v1.2.3
From 03529f6a0528ed01c7a956bb80628910584a9580 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 8 May 2020 18:26:35 +0200
Subject: Transmogrifier: Don't modify attachments for chats.
---
test/web/common_api/common_api_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 61affda5d..5501ba18b 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -54,6 +54,8 @@ defmodule Pleroma.Web.CommonAPITest do
assert Chat.get(author.id, recipient.ap_id)
assert Chat.get(recipient.id, author.ap_id)
+
+ assert :ok == Pleroma.Web.Federator.perform(:publish, activity)
end
test "it reject messages over the local limit" do
--
cgit v1.2.3
From 5367a00257c6f862a4a8080e0176f676ce491e4d Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 11 May 2020 15:06:23 +0200
Subject: Deletion: Handle the case of pruned objects.
---
test/web/common_api/common_api_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 2fd17a1b8..c524d1c0c 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -24,6 +24,24 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :max_pinned_statuses])
describe "deletion" do
+ test "it works with pruned objects" do
+ user = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+
+ Object.normalize(post, false)
+ |> Object.prune()
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ assert {:ok, delete} = CommonAPI.delete(post.id, user)
+ assert delete.local
+ assert called(Pleroma.Web.Federator.publish(delete))
+ end
+
+ refute Activity.get_by_id(post.id)
+ end
+
test "it allows users to delete their posts" do
user = insert(:user)
--
cgit v1.2.3
From 7803a85d2ced092fbd8e0f1bde0944bd27f8d649 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 12 May 2020 23:59:26 +0400
Subject: Add OpenAPI spec for StatusController
---
test/web/common_api/common_api_test.exs | 112 +++++++++++++-------------
test/web/common_api/common_api_utils_test.exs | 14 ++--
2 files changed, 62 insertions(+), 64 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index c524d1c0c..26e41c313 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -27,7 +27,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "it works with pruned objects" do
user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
Object.normalize(post, false)
|> Object.prune()
@@ -45,7 +45,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "it allows users to delete their posts" do
user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do
@@ -61,7 +61,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
assert {:error, "Could not delete"} = CommonAPI.delete(post.id, other_user)
assert Activity.get_by_id(post.id)
@@ -71,7 +71,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
moderator = insert(:user, is_moderator: true)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
assert delete.local
@@ -83,7 +83,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
moderator = insert(:user, is_admin: true)
- {:ok, post} = CommonAPI.post(user, %{"status" => "namu amida butsu"})
+ {:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
assert {:ok, delete} = CommonAPI.delete(post.id, moderator)
assert delete.local
@@ -124,7 +124,7 @@ defmodule Pleroma.Web.CommonAPITest do
users_serial = insert_list(10, :user)
users = insert_list(10, :user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+ {:ok, activity} = CommonAPI.post(user, %{status: "."})
users_serial
|> Enum.map(fn user ->
@@ -151,7 +151,7 @@ defmodule Pleroma.Web.CommonAPITest do
users_serial = insert_list(10, :user)
users = insert_list(10, :user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "."})
+ {:ok, activity} = CommonAPI.post(user, %{status: "."})
users_serial
|> Enum.map(fn user ->
@@ -175,12 +175,12 @@ defmodule Pleroma.Web.CommonAPITest do
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
[participation] = Participation.for_user(user)
{:ok, convo_reply} =
- CommonAPI.post(user, %{"status" => ".", "in_reply_to_conversation_id" => participation.id})
+ CommonAPI.post(user, %{status: ".", in_reply_to_conversation_id: participation.id})
assert Visibility.is_direct?(convo_reply)
@@ -194,8 +194,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(har, %{
- "status" => "@#{jafnhar.nickname} hey",
- "visibility" => "direct"
+ status: "@#{jafnhar.nickname} hey",
+ visibility: "direct"
})
assert har.ap_id in activity.recipients
@@ -205,10 +205,10 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(har, %{
- "status" => "I don't really like @#{tridi.nickname}",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity.id,
- "in_reply_to_conversation_id" => participation.id
+ status: "I don't really like @#{tridi.nickname}",
+ visibility: "direct",
+ in_reply_to_status_id: activity.id,
+ in_reply_to_conversation_id: participation.id
})
assert har.ap_id in activity.recipients
@@ -225,8 +225,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(har, %{
- "status" => "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
- "visibility" => "direct"
+ status: "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
+ visibility: "direct"
})
refute tridi.ap_id in activity.recipients
@@ -235,7 +235,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "it de-duplicates tags" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"})
object = Object.normalize(activity)
@@ -244,7 +244,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "it adds emoji in the object" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => ":firefox:"})
+ {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"})
assert Object.normalize(activity).data["emoji"]["firefox"]
end
@@ -258,9 +258,9 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" =>
+ status:
"Hey, I think @#{user_three.nickname} is ugly. @#{user_four.nickname} is alright though.",
- "to" => [user_two.nickname, user_four.nickname, "nonexistent"]
+ to: [user_two.nickname, user_four.nickname, "nonexistent"]
})
assert user.ap_id in activity.recipients
@@ -276,8 +276,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => post,
- "content_type" => "text/html"
+ status: post,
+ content_type: "text/html"
})
object = Object.normalize(activity)
@@ -292,8 +292,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => post,
- "content_type" => "text/markdown"
+ status: post,
+ content_type: "text/markdown"
})
object = Object.normalize(activity)
@@ -304,21 +304,21 @@ defmodule Pleroma.Web.CommonAPITest do
test "it does not allow replies to direct messages that are not direct messages themselves" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "suya..", "visibility" => "direct"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "suya..", visibility: "direct"})
assert {:ok, _} =
CommonAPI.post(user, %{
- "status" => "suya..",
- "visibility" => "direct",
- "in_reply_to_status_id" => activity.id
+ status: "suya..",
+ visibility: "direct",
+ in_reply_to_status_id: activity.id
})
Enum.each(["public", "private", "unlisted"], fn visibility ->
assert {:error, "The message visibility must be direct"} =
CommonAPI.post(user, %{
- "status" => "suya..",
- "visibility" => visibility,
- "in_reply_to_status_id" => activity.id
+ status: "suya..",
+ visibility: visibility,
+ in_reply_to_status_id: activity.id
})
end)
end
@@ -327,8 +327,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
{:ok, list} = Pleroma.List.create("foo", user)
- {:ok, activity} =
- CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})
assert activity.data["bcc"] == [list.ap_id]
assert activity.recipients == [list.ap_id, user.ap_id]
@@ -339,7 +338,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
assert {:error, "Cannot post an empty status without attachments"} =
- CommonAPI.post(user, %{"status" => ""})
+ CommonAPI.post(user, %{status: ""})
end
test "it validates character limits are correctly enforced" do
@@ -348,9 +347,9 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
assert {:error, "The status is over the character limit"} =
- CommonAPI.post(user, %{"status" => "foobar"})
+ CommonAPI.post(user, %{status: "foobar"})
- assert {:ok, activity} = CommonAPI.post(user, %{"status" => "12345"})
+ assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
end
test "it can handle activities that expire" do
@@ -361,8 +360,7 @@ defmodule Pleroma.Web.CommonAPITest do
|> NaiveDateTime.truncate(:second)
|> NaiveDateTime.add(1_000_000, :second)
- assert {:ok, activity} =
- CommonAPI.post(user, %{"status" => "chai", "expires_in" => 1_000_000})
+ assert {:ok, activity} = CommonAPI.post(user, %{status: "chai", expires_in: 1_000_000})
assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
assert expiration.scheduled_at == expires_at
@@ -374,14 +372,14 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
assert reaction.data["actor"] == user.ap_id
assert reaction.data["content"] == "👍"
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")
end
@@ -390,7 +388,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
{:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
@@ -404,7 +402,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
end
@@ -412,7 +410,7 @@ defmodule Pleroma.Web.CommonAPITest do
test "can't repeat a repeat" do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
@@ -423,10 +421,10 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{} = announce_activity, _} =
- CommonAPI.repeat(activity.id, user, %{"visibility" => "private"})
+ CommonAPI.repeat(activity.id, user, %{visibility: "private"})
assert Visibility.is_private?(announce_activity)
end
@@ -435,7 +433,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, post_activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, post_activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{data: data}} = CommonAPI.favorite(user, post_activity.id)
assert data["type"] == "Like"
@@ -447,7 +445,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
{:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
end
@@ -456,7 +454,7 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
{:ok, %Activity{}} = CommonAPI.favorite(user, activity.id)
assert {:ok, :already_liked} = CommonAPI.favorite(user, activity.id)
end
@@ -467,7 +465,7 @@ defmodule Pleroma.Web.CommonAPITest do
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!"})
[user: user, activity: activity]
end
@@ -484,8 +482,8 @@ defmodule Pleroma.Web.CommonAPITest do
test "pin poll", %{user: user} do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "How is fediverse today?",
- "poll" => %{"options" => ["Absolutely outstanding", "Not good"], "expires_in" => 20}
+ status: "How is fediverse today?",
+ poll: %{options: ["Absolutely outstanding", "Not good"], expires_in: 20}
})
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
@@ -497,7 +495,7 @@ defmodule Pleroma.Web.CommonAPITest do
end
test "unlisted statuses can be pinned", %{user: user} do
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "HI!!!", visibility: "unlisted"})
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
@@ -508,7 +506,7 @@ defmodule Pleroma.Web.CommonAPITest do
end
test "max pinned statuses", %{user: user, activity: activity_one} do
- {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{status: "HI!!!"})
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
@@ -576,7 +574,7 @@ defmodule Pleroma.Web.CommonAPITest do
reporter = insert(:user)
target_user = insert(:user)
- {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+ {:ok, activity} = CommonAPI.post(target_user, %{status: "foobar"})
reporter_ap_id = reporter.ap_id
target_ap_id = target_user.ap_id
@@ -813,8 +811,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.post(user, %{
- "status" => "Am I cute?",
- "poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
+ status: "Am I cute?",
+ poll: %{options: ["Yes", "No"], expires_in: 20}
})
object = Object.normalize(activity)
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 18a3b3b87..5708db6a4 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -228,7 +228,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
@@ -261,7 +261,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
@@ -292,7 +292,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
@@ -322,7 +322,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
user = insert(:user)
mentioned_user = insert(:user)
third_user = insert(:user)
- {:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
+ {:ok, activity} = CommonAPI.post(third_user, %{status: "uguu"})
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
@@ -463,8 +463,8 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
desc = Jason.encode!(%{object.id => "test-desc"})
assert Utils.attachments_from_ids(%{
- "media_ids" => ["#{object.id}"],
- "descriptions" => desc
+ media_ids: ["#{object.id}"],
+ descriptions: desc
}) == [
Map.merge(object.data, %{"name" => "test-desc"})
]
@@ -472,7 +472,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "returns attachments without descs" do
object = insert(:note)
- assert Utils.attachments_from_ids(%{"media_ids" => ["#{object.id}"]}) == [object.data]
+ assert Utils.attachments_from_ids(%{media_ids: ["#{object.id}"]}) == [object.data]
end
test "returns [] when not pass media_ids" do
--
cgit v1.2.3
From 0f0acc740d30c47d093f27875d4decf0693b2845 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 13 May 2020 15:31:28 +0200
Subject: Chat: Allow posting without content if an attachment is present.
---
test/web/common_api/common_api_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index fd2c486a1..46ffd2888 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -27,6 +27,29 @@ defmodule Pleroma.Web.CommonAPITest do
describe "posting chat messages" do
setup do: clear_config([:instance, :chat_limit])
+ test "it posts a chat message without content but with an attachment" do
+ author = insert(:user)
+ recipient = insert(:user)
+
+ file = %Plug.Upload{
+ content_type: "image/jpg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, upload} = ActivityPub.upload(file, actor: author.ap_id)
+
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ nil,
+ media_id: upload.id
+ )
+
+ assert activity
+ end
+
test "it posts a chat message" do
author = insert(:user)
recipient = insert(:user)
--
cgit v1.2.3
From 2dcb26a6e52b18c62aaa1ef464d94685732496ab Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 16 May 2020 12:28:24 +0200
Subject: CommonAPI: Unblock a user even if we don't have an activity.
---
test/web/common_api/common_api_test.exs | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 26e41c313..fd8299013 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -23,6 +23,18 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses])
+ describe "unblocking" do
+ test "it works even without an existing block activity" do
+ blocked = insert(:user)
+ blocker = insert(:user)
+ User.block(blocker, blocked)
+
+ assert User.blocks?(blocker, blocked)
+ assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked)
+ refute User.blocks?(blocker, blocked)
+ end
+ end
+
describe "deletion" do
test "it works with pruned objects" do
user = insert(:user)
--
cgit v1.2.3
From 524d04d9218f8e72bf88ab5e7d4b407452ae40bc Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 19 May 2020 15:53:18 +0400
Subject: Add OpenAPI spec for PleromaAPI.ScrobbleController
---
test/web/common_api/common_api_test.exs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index fd8299013..52e95397c 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -841,10 +841,10 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.listen(user, %{
- "title" => "lain radio episode 1",
- "album" => "lain radio",
- "artist" => "lain",
- "length" => 180_000
+ title: "lain radio episode 1",
+ album: "lain radio",
+ artist: "lain",
+ length: 180_000
})
object = Object.normalize(activity)
@@ -859,11 +859,11 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} =
CommonAPI.listen(user, %{
- "title" => "lain radio episode 1",
- "album" => "lain radio",
- "artist" => "lain",
- "length" => 180_000,
- "visibility" => "private"
+ title: "lain radio episode 1",
+ album: "lain radio",
+ artist: "lain",
+ length: 180_000,
+ visibility: "private"
})
object = Object.normalize(activity)
--
cgit v1.2.3
From eb5f4285651c923aa3d776a2bc317c2a902031cc Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 20 May 2020 13:38:47 +0200
Subject: CommonAPI: Change public->private implicit addressing.
This will not add the OP to the `to` field anymore when going from
public to private.
---
test/web/common_api/common_api_test.exs | 26 ++++++++++++++++++++++++++
test/web/common_api/common_api_utils_test.exs | 12 ++++++++++--
2 files changed, 36 insertions(+), 2 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 52e95397c..6014ffdac 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -335,6 +335,32 @@ defmodule Pleroma.Web.CommonAPITest do
end)
end
+ test "replying with a direct message will NOT auto-add the author of the reply to the recipient list" do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{status: "I'm stupid"})
+
+ {:ok, open_answer} =
+ CommonAPI.post(other_user, %{status: "No ur smart", in_reply_to_status_id: post.id})
+
+ # The OP is implicitly added
+ assert user.ap_id in open_answer.recipients
+
+ {:ok, secret_answer} =
+ CommonAPI.post(other_user, %{
+ status: "lol, that guy really is stupid, right, @#{third_user.nickname}?",
+ in_reply_to_status_id: post.id,
+ visibility: "direct"
+ })
+
+ assert third_user.ap_id in secret_answer.recipients
+
+ # The OP is not added
+ refute user.ap_id in secret_answer.recipients
+ end
+
test "it allows to address a list" do
user = insert(:user)
{:ok, list} = Pleroma.List.create("foo", user)
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 5708db6a4..d7d2d10d5 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -297,11 +297,10 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
- assert length(to) == 3
+ assert length(to) == 2
assert Enum.empty?(cc)
assert mentioned_user.ap_id in to
- assert third_user.ap_id in to
assert user.follower_address in to
end
@@ -327,6 +326,15 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
+ assert length(to) == 1
+ assert Enum.empty?(cc)
+
+ assert mentioned_user.ap_id in to
+
+ {:ok, direct_activity} = CommonAPI.post(third_user, %{status: "uguu", visibility: "direct"})
+
+ {to, cc} = Utils.get_to_and_cc(user, mentions, direct_activity, "direct", nil)
+
assert length(to) == 2
assert Enum.empty?(cc)
--
cgit v1.2.3
From e42bc5f55732d42bf40ed9129ec737e654a911b8 Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 20 May 2020 15:44:37 +0200
Subject: Announcements: Handle through common pipeline.
---
test/web/common_api/common_api_test.exs | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 52e95397c..e68a6a7d2 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -416,7 +416,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
- {:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
+ {:ok, %Activity{} = announce_activity} = CommonAPI.repeat(activity.id, user)
+ assert Visibility.is_public?(announce_activity)
end
test "can't repeat a repeat" do
@@ -424,9 +425,9 @@ defmodule Pleroma.Web.CommonAPITest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
- {:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
+ {:ok, %Activity{} = announce} = CommonAPI.repeat(activity.id, other_user)
- refute match?({:ok, %Activity{}, _}, CommonAPI.repeat(announce.id, user))
+ refute match?({:ok, %Activity{}}, CommonAPI.repeat(announce.id, user))
end
test "repeating a status privately" do
@@ -435,7 +436,7 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
- {:ok, %Activity{} = announce_activity, _} =
+ {:ok, %Activity{} = announce_activity} =
CommonAPI.repeat(activity.id, user, %{visibility: "private"})
assert Visibility.is_private?(announce_activity)
@@ -458,8 +459,8 @@ defmodule Pleroma.Web.CommonAPITest do
other_user = insert(:user)
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
- {:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
- {:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
+ {:ok, %Activity{} = announce} = CommonAPI.repeat(activity.id, user)
+ {:ok, ^announce} = CommonAPI.repeat(activity.id, user)
end
test "favoriting a status twice returns ok, but without the like activity" do
--
cgit v1.2.3
From 23e248694df988d50e8a07b704a7ac56b8e9b19c Mon Sep 17 00:00:00 2001
From: lain
Date: Thu, 21 May 2020 13:16:21 +0200
Subject: Announcements: Fix all tests.
---
test/web/common_api/common_api_test.exs | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index e68a6a7d2..d849fd8f0 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -41,6 +41,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
+ clear_config([:instance, :federating], true)
+
Object.normalize(post, false)
|> Object.prune()
@@ -59,6 +61,8 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, post} = CommonAPI.post(user, %{status: "namu amida butsu"})
+ clear_config([:instance, :federating], true)
+
with_mock Pleroma.Web.Federator,
publish: fn _ -> nil end do
assert {:ok, delete} = CommonAPI.delete(post.id, user)
@@ -440,6 +444,7 @@ defmodule Pleroma.Web.CommonAPITest do
CommonAPI.repeat(activity.id, user, %{visibility: "private"})
assert Visibility.is_private?(announce_activity)
+ refute Visibility.visible_for_user?(announce_activity, nil)
end
test "favoriting a status" do
--
cgit v1.2.3
From cc82229ba70e054acfdea07a195c1b11961ea1bc Mon Sep 17 00:00:00 2001
From: Roman Chvanikov
Date: Fri, 22 May 2020 18:19:25 +0300
Subject: Add filename_display_max_length config
---
test/web/common_api/common_api_utils_test.exs | 41 +++++++++++++++++++++------
1 file changed, 32 insertions(+), 9 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index d7d2d10d5..e67c10b93 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -14,18 +14,41 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
@public_address "https://www.w3.org/ns/activitystreams#Public"
- test "it adds attachment links to a given text and attachment set" do
- name =
- "Sakura%20Mana%20%E2%80%93%20Turned%20on%20by%20a%20Senior%20OL%20with%20a%20Temptating%20Tight%20Skirt-s%20Full%20Hipline%20and%20Panty%20Shot-%20Beautiful%20Thick%20Thighs-%20and%20Erotic%20Ass-%20-2015-%20--%20Oppaitime%208-28-2017%206-50-33%20PM.png"
+ describe "add_attachments/2" do
+ setup do
+ name =
+ "Sakura Mana – Turned on by a Senior OL with a Temptating Tight Skirt-s Full Hipline and Panty Shot- Beautiful Thick Thighs- and Erotic Ass- -2015- -- Oppaitime 8-28-2017 6-50-33 PM.png"
- attachment = %{
- "url" => [%{"href" => name}]
- }
+ attachment = %{
+ "url" => [%{"href" => URI.encode(name)}]
+ }
- res = Utils.add_attachments("", [attachment])
+ %{name: name, attachment: attachment}
+ end
+
+ test "it adds attachment links to a given text and attachment set", %{
+ name: name,
+ attachment: attachment
+ } do
+ len = 10
+ clear_config([Pleroma.Upload, :filename_display_max_length], len)
- assert res ==
- "
Sakura Mana – Turned on by a Se…"
+ expected =
+ "
#{String.slice(name, 0..len)}…"
+
+ assert Utils.add_attachments("", [attachment]) == expected
+ end
+
+ test "doesn't truncate file name if config for truncate is set to 0", %{
+ name: name,
+ attachment: attachment
+ } do
+ clear_config([Pleroma.Upload, :filename_display_max_length], 0)
+
+ expected = "
#{name}"
+
+ assert Utils.add_attachments("", [attachment]) == expected
+ end
end
describe "it confirms the password given is the current users password" do
--
cgit v1.2.3
From 8bdf18d7c10f0e740b2f5e0fa5063c522b8b3872 Mon Sep 17 00:00:00 2001
From: lain
Date: Sat, 30 May 2020 12:30:31 +0200
Subject: CommonAPI: Linkify chat messages.
---
test/web/common_api/common_api_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 9e129e5a7..41c6909de 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -50,6 +50,29 @@ defmodule Pleroma.Web.CommonAPITest do
assert activity
end
+ test "it linkifies" do
+ author = insert(:user)
+ recipient = insert(:user)
+
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ "https://example.org is the site of @#{other_user.nickname} #2hu"
+ )
+
+ assert other_user.ap_id not in activity.recipients
+
+ object = Object.normalize(activity, false)
+
+ assert object.data["content"] ==
+ "https://example.org is the site of @#{other_user.nickname} #2hu"
+ end
+
test "it posts a chat message" do
author = insert(:user)
recipient = insert(:user)
--
cgit v1.2.3
From af9090238e1f71e6b081fbd09c09a5975d2ed99e Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 1 Jun 2020 15:14:22 +0200
Subject: CommonAPI: Newlines -> br for chat messages.
---
test/web/common_api/common_api_test.exs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 41c6909de..611a9ae66 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -50,6 +50,26 @@ defmodule Pleroma.Web.CommonAPITest do
assert activity
end
+ test "it adds html newlines" do
+ author = insert(:user)
+ recipient = insert(:user)
+
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ "uguu\nuguuu"
+ )
+
+ assert other_user.ap_id not in activity.recipients
+
+ object = Object.normalize(activity, false)
+
+ assert object.data["content"] == "uguu
uguuu"
+ end
+
test "it linkifies" do
author = insert(:user)
recipient = insert(:user)
--
cgit v1.2.3
From 115d08a7542b92c5e1d889da41c0ee6837a1235e Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 5 Jun 2020 16:47:02 +0200
Subject: Pipeline: Add a side effects step after the transaction finishes
This is to run things like streaming notifications out, which will
sometimes need data that is created by the transaction, but is
streamed out asynchronously.
---
test/web/common_api/common_api_test.exs | 45 ++++++++++++++++++++++++++-------
1 file changed, 36 insertions(+), 9 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 611a9ae66..63b59820e 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.Activity
alias Pleroma.Chat
alias Pleroma.Conversation.Participation
+ alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -39,15 +40,41 @@ defmodule Pleroma.Web.CommonAPITest do
{:ok, upload} = ActivityPub.upload(file, actor: author.ap_id)
- {:ok, activity} =
- CommonAPI.post_chat_message(
- author,
- recipient,
- nil,
- media_id: upload.id
- )
-
- assert activity
+ with_mocks([
+ {
+ Pleroma.Web.Streamer,
+ [],
+ [
+ stream: fn _, _ ->
+ nil
+ end
+ ]
+ },
+ {
+ Pleroma.Web.Push,
+ [],
+ [
+ send: fn _ -> nil end
+ ]
+ }
+ ]) do
+ {:ok, activity} =
+ CommonAPI.post_chat_message(
+ author,
+ recipient,
+ nil,
+ media_id: upload.id
+ )
+
+ notification =
+ Notification.for_user_and_activity(recipient, activity)
+ |> Repo.preload(:activity)
+
+ assert called(Pleroma.Web.Push.send(notification))
+ assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification))
+
+ assert activity
+ end
end
test "it adds html newlines" do
--
cgit v1.2.3
From 2cdaac433035d8df3890eae098b55380b9e1c9fc Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 7 Jun 2020 14:52:56 +0200
Subject: SideEffects: Move streaming of chats to after the transaction.
---
test/web/common_api/common_api_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 63b59820e..6bd26050e 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -72,6 +72,7 @@ defmodule Pleroma.Web.CommonAPITest do
assert called(Pleroma.Web.Push.send(notification))
assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification))
+ assert called(Pleroma.Web.Streamer.stream(["user", "user:pleroma_chat"], :_))
assert activity
end
--
cgit v1.2.3
From 84f9ca19568777861ff9520cbef09a0259efd536 Mon Sep 17 00:00:00 2001
From: lain
Date: Thu, 25 Jun 2020 12:03:14 +0200
Subject: Blocking: Don't federate if the options is set.
---
test/web/common_api/common_api_test.exs | 46 +++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 6bd26050e..fc3bb845d 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -25,6 +25,52 @@ defmodule Pleroma.Web.CommonAPITest do
setup do: clear_config([:instance, :limit])
setup do: clear_config([:instance, :max_pinned_statuses])
+ describe "blocking" do
+ setup do
+ blocker = insert(:user)
+ blocked = insert(:user)
+ User.follow(blocker, blocked)
+ User.follow(blocked, blocker)
+ %{blocker: blocker, blocked: blocked}
+ end
+
+ test "it blocks and federates", %{blocker: blocker, blocked: blocked} do
+ clear_config([:instance, :federating], true)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ assert {:ok, block} = CommonAPI.block(blocker, blocked)
+
+ assert block.local
+ assert User.blocks?(blocker, blocked)
+ refute User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+
+ assert called(Pleroma.Web.Federator.publish(block))
+ end
+ end
+
+ test "it blocks and does not federate if outgoing blocks are disabled", %{
+ blocker: blocker,
+ blocked: blocked
+ } do
+ clear_config([:instance, :federating], true)
+ clear_config([:activitypub, :outgoing_blocks], false)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ assert {:ok, block} = CommonAPI.block(blocker, blocked)
+
+ assert block.local
+ assert User.blocks?(blocker, blocked)
+ refute User.following?(blocker, blocked)
+ refute User.following?(blocked, blocker)
+
+ refute called(Pleroma.Web.Federator.publish(block))
+ end
+ end
+ end
+
describe "posting chat messages" do
setup do: clear_config([:instance, :chat_limit])
--
cgit v1.2.3
From 27c33f216ad250b60d44fe0662c3be3c4cee987e Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Fri, 26 Jun 2020 05:39:35 +0200
Subject: activity_draft: Add source field
---
test/web/common_api/common_api_test.exs | 2 ++
1 file changed, 2 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 6bd26050e..cbdd994a9 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -445,6 +445,7 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity)
assert object.data["content"] == "2hu
alert('xss')"
+ assert object.data["source"] == post
end
test "it filters out obviously bad tags when accepting a post as Markdown" do
@@ -461,6 +462,7 @@ defmodule Pleroma.Web.CommonAPITest do
object = Object.normalize(activity)
assert object.data["content"] == "2hu
alert('xss')"
+ assert object.data["source"] == post
end
test "it does not allow replies to direct messages that are not direct messages themselves" do
--
cgit v1.2.3
From 00e54f8fe7af098ba829f7f7cd5511569dcd1c0a Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 8 Jul 2020 17:07:24 +0200
Subject: ActivityPub: Remove `follow` and fix issues.
---
test/web/common_api/common_api_test.exs | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 908ee5484..7e11fede3 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -934,6 +934,15 @@ defmodule Pleroma.Web.CommonAPITest do
end
end
+ describe "follow/2" do
+ test "directly follows a non-locked local user" do
+ [follower, followed] = insert_pair(:user)
+ {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
+
+ assert User.following?(follower, followed)
+ end
+ end
+
describe "unfollow/2" do
test "also unsubscribes a user" do
[follower, followed] = insert_pair(:user)
@@ -998,9 +1007,9 @@ defmodule Pleroma.Web.CommonAPITest do
follower = insert(:user)
follower_two = insert(:user)
- {:ok, follow_activity} = ActivityPub.follow(follower, user)
- {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
- {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
+ {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
+ {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user)
+ {:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user)
assert follow_activity.data["state"] == "pending"
assert follow_activity_two.data["state"] == "pending"
@@ -1018,9 +1027,9 @@ defmodule Pleroma.Web.CommonAPITest do
follower = insert(:user)
follower_two = insert(:user)
- {:ok, follow_activity} = ActivityPub.follow(follower, user)
- {:ok, follow_activity_two} = ActivityPub.follow(follower, user)
- {:ok, follow_activity_three} = ActivityPub.follow(follower_two, user)
+ {:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
+ {:ok, _, _, follow_activity_two} = CommonAPI.follow(follower, user)
+ {:ok, _, _, follow_activity_three} = CommonAPI.follow(follower_two, user)
assert follow_activity.data["state"] == "pending"
assert follow_activity_two.data["state"] == "pending"
--
cgit v1.2.3
From 1dd6de03ee655f5247ac62fee488307c934d7378 Mon Sep 17 00:00:00 2001
From: Lain Soykaf
Date: Fri, 24 Jul 2020 14:54:13 +0200
Subject: CommonAPI Tests: Check that undoing objects federates them as embeds.
---
test/web/common_api/common_api_test.exs | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 7e11fede3..313dda21b 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -624,14 +624,27 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
other_user = insert(:user)
- {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
- {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+ clear_config([:instance, :federating], true)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
+ {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
+
+ {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
- {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
+ assert unreaction.data["type"] == "Undo"
+ assert unreaction.data["object"] == reaction.data["id"]
+ assert unreaction.local
- assert unreaction.data["type"] == "Undo"
- assert unreaction.data["object"] == reaction.data["id"]
- assert unreaction.local
+ # On federation, it contains the undone (and deleted) object
+ unreaction_with_object = %{
+ unreaction
+ | data: Map.put(unreaction.data, "object", reaction.data)
+ }
+
+ assert called(Pleroma.Web.Federator.publish(unreaction_with_object))
+ end
end
test "repeating a status" do
--
cgit v1.2.3
From e92c040ad3d0cc568ea0dc4b79f207a392c7c90f Mon Sep 17 00:00:00 2001
From: lain
Date: Tue, 4 Aug 2020 14:08:12 +0200
Subject: CommonAPITest: Add test that deactivated users can't post.
---
test/web/common_api/common_api_test.exs | 5 +++++
1 file changed, 5 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 313dda21b..4ba6232dc 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -458,6 +458,11 @@ defmodule Pleroma.Web.CommonAPITest do
end
describe "posting" do
+ test "deactivated users can't post" do
+ user = insert(:user, deactivated: true)
+ assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
+ end
+
test "it supports explicit addressing" do
user = insert(:user)
user_two = insert(:user)
--
cgit v1.2.3