summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-08-22 20:59:58 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-08-22 20:59:58 +0300
commit256ff09aa8068166a9f83e3159f060fd4598af76 (patch)
treea5e5efa83241f28d8d241b9d2d95ca4ceaefd286 /test
parent8778c16dac1789eeb6dd51524573163216200b5d (diff)
parent73884441f31092bdb2f509950daf9bd3889a9a8b (diff)
downloadpleroma-256ff09aa8068166a9f83e3159f060fd4598af76.tar.gz
pleroma-256ff09aa8068166a9f83e3159f060fd4598af76.zip
[#1149] Merge remote-tracking branch 'remotes/upstream/develop' into 1149-oban-job-queue
# Conflicts: # lib/pleroma/application.ex # lib/pleroma/scheduled_activity_worker.ex # lib/pleroma/web/federator/retry_queue.ex # lib/pleroma/web/oauth/token/clean_worker.ex # test/user_test.exs # test/web/federator_test.exs
Diffstat (limited to 'test')
-rw-r--r--test/config/transfer_task_test.exs12
-rw-r--r--test/conversation/participation_test.exs63
-rw-r--r--test/conversation_test.exs10
-rw-r--r--test/emails/mailer_test.exs6
-rw-r--r--test/fixtures/mastodon-update.json36
-rw-r--r--test/fixtures/tesla_mock/admin@mastdon.example.org.json55
-rw-r--r--test/http/request_builder_test.exs8
-rw-r--r--test/object/fetcher_test.exs8
-rw-r--r--test/plugs/ensure_public_or_authenticated_plug_test.exs17
-rw-r--r--test/plugs/http_security_plug_test.exs17
-rw-r--r--test/plugs/instance_static_test.exs10
-rw-r--r--test/reverse_proxy_test.exs4
-rw-r--r--test/support/helpers.ex53
-rw-r--r--test/tasks/config_test.exs9
-rw-r--r--test/tasks/database_test.exs47
-rw-r--r--test/tasks/digest_test.exs (renamed from test/mix/tasks/pleroma.digest_test.exs)2
-rw-r--r--test/tasks/relay_test.exs23
-rw-r--r--test/tasks/robots_txt_test.exs8
-rw-r--r--test/upload/filter/anonymize_filename_test.exs8
-rw-r--r--test/upload/filter/mogrify_test.exs8
-rw-r--r--test/upload/filter_test.exs8
-rw-r--r--test/upload_test.exs6
-rw-r--r--test/uploaders/s3_test.exs10
-rw-r--r--test/user_test.exs131
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs15
-rw-r--r--test/web/activity_pub/activity_pub_test.exs23
-rw-r--r--test/web/activity_pub/mrf/mrf_test.exs6
-rw-r--r--test/web/activity_pub/mrf/reject_non_public_test.exs7
-rw-r--r--test/web/activity_pub/mrf/simple_policy_test.exs8
-rw-r--r--test/web/activity_pub/mrf/user_allowlist_policy_test.exs7
-rw-r--r--test/web/activity_pub/mrf/vocabulary_policy_test.exs25
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs54
-rw-r--r--test/web/activity_pub/views/user_view_test.exs15
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs56
-rw-r--r--test/web/common_api/common_api_test.exs54
-rw-r--r--test/web/common_api/common_api_utils_test.exs16
-rw-r--r--test/web/digest_email_worker_test.exs35
-rw-r--r--test/web/federator_test.exs27
-rw-r--r--test/web/instances/instance_test.exs10
-rw-r--r--test/web/instances/instances_test.exs10
-rw-r--r--test/web/mastodon_api/account_view_test.exs9
-rw-r--r--test/web/mastodon_api/conversation_view_test.exs34
-rw-r--r--test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs64
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs53
-rw-r--r--test/web/mastodon_api/status_view_test.exs18
-rw-r--r--test/web/media_proxy/media_proxy_test.exs7
-rw-r--r--test/web/oauth/ldap_authorization_test.exs17
-rw-r--r--test/web/oauth/oauth_controller_test.exs36
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs11
-rw-r--r--test/web/pleroma_api/pleroma_api_controller_test.exs94
-rw-r--r--test/web/plugs/federating_plug_test.exs10
-rw-r--r--test/web/rich_media/aws_signed_url_test.exs3
-rw-r--r--test/web/rich_media/helpers_test.exs4
-rw-r--r--test/web/streamer_test.exs30
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs21
-rw-r--r--test/web/twitter_api/util_controller_test.exs28
-rw-r--r--test/web/web_finger/web_finger_controller_test.exs10
-rw-r--r--test/web/websub/websub_controller_test.exs10
58 files changed, 927 insertions, 459 deletions
diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs
index dbeadbe87..9074f3b97 100644
--- a/test/config/transfer_task_test.exs
+++ b/test/config/transfer_task_test.exs
@@ -5,14 +5,8 @@
defmodule Pleroma.Config.TransferTaskTest do
use Pleroma.DataCase
- setup do
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
-
+ clear_config([:instance, :dynamic_configuration]) do
Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
- end)
end
test "transfer config values from db to env" do
@@ -31,7 +25,7 @@ defmodule Pleroma.Config.TransferTaskTest do
value: [live: 15, com: 35]
})
- Pleroma.Config.TransferTask.start_link()
+ Pleroma.Config.TransferTask.start_link([])
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
@@ -50,7 +44,7 @@ defmodule Pleroma.Config.TransferTaskTest do
})
assert ExUnit.CaptureLog.capture_log(fn ->
- Pleroma.Config.TransferTask.start_link()
+ Pleroma.Config.TransferTask.start_link([])
end) =~
"updating env causes error, key: \"undefined_atom_key\", error: %ArgumentError{message: \"argument error\"}"
end
diff --git a/test/conversation/participation_test.exs b/test/conversation/participation_test.exs
index 2a03e5d67..a27167d42 100644
--- a/test/conversation/participation_test.exs
+++ b/test/conversation/participation_test.exs
@@ -8,6 +8,50 @@ defmodule Pleroma.Conversation.ParticipationTest do
alias Pleroma.Conversation.Participation
alias Pleroma.Web.CommonAPI
+ test "getting a participation will also preload things" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Participation.get(participation.id, preload: [:conversation])
+
+ assert %Pleroma.Conversation{} = participation.conversation
+ end
+
+ test "for a new conversation, it sets the recipents of the participation" do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+ participation = Pleroma.Repo.preload(participation, :recipients)
+
+ assert length(participation.recipients) == 2
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+
+ # Mentioning another user in the same conversation will not add a new recipients.
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{
+ "in_reply_to_status_id" => activity.id,
+ "status" => "Hey @#{third_user.nickname}.",
+ "visibility" => "direct"
+ })
+
+ [participation] = Participation.for_user(user)
+ participation = Pleroma.Repo.preload(participation, :recipients)
+
+ assert length(participation.recipients) == 2
+ end
+
test "it creates a participation for a conversation and a user" do
user = insert(:user)
conversation = insert(:conversation)
@@ -102,4 +146,23 @@ defmodule Pleroma.Conversation.ParticipationTest do
[] = Participation.for_user_with_last_activity_id(user)
end
+
+ test "it sets recipients, always keeping the owner of the participation even when not explicitly set" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+ [participation] = Participation.for_user_with_last_activity_id(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert participation.recipients |> length() == 1
+ assert user in participation.recipients
+
+ {:ok, participation} = Participation.set_recipients(participation, [other_user.id])
+
+ assert participation.recipients |> length() == 2
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+ end
end
diff --git a/test/conversation_test.exs b/test/conversation_test.exs
index f917aa691..693427d80 100644
--- a/test/conversation_test.exs
+++ b/test/conversation_test.exs
@@ -11,14 +11,8 @@ defmodule Pleroma.ConversationTest do
import Pleroma.Factory
- setup_all do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
end
test "it goes through old direct conversations" do
diff --git a/test/emails/mailer_test.exs b/test/emails/mailer_test.exs
index 450bb09c7..ae5effb7a 100644
--- a/test/emails/mailer_test.exs
+++ b/test/emails/mailer_test.exs
@@ -15,11 +15,7 @@ defmodule Pleroma.Emails.MailerTest do
to: [{"Test User", "user1@example.com"}]
}
- setup do
- value = Pleroma.Config.get([Pleroma.Emails.Mailer, :enabled])
- on_exit(fn -> Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], value) end)
- :ok
- end
+ clear_config([Pleroma.Emails.Mailer, :enabled])
test "not send email when mailer is disabled" do
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
diff --git a/test/fixtures/mastodon-update.json b/test/fixtures/mastodon-update.json
index f6713fea5..dbf8b6dff 100644
--- a/test/fixtures/mastodon-update.json
+++ b/test/fixtures/mastodon-update.json
@@ -1,10 +1,10 @@
-{
- "type": "Update",
- "object": {
- "url": "http://mastodon.example.org/@gargron",
- "type": "Person",
- "summary": "<p>Some bio</p>",
- "publicKey": {
+{
+ "type": "Update",
+ "object": {
+ "url": "http://mastodon.example.org/@gargron",
+ "type": "Person",
+ "summary": "<p>Some bio</p>",
+ "publicKey": {
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0gs3VnQf6am3R+CeBV4H\nlfI1HZTNRIBHgvFszRZkCERbRgEWMu+P+I6/7GJC5H5jhVQ60z4MmXcyHOGmYMK/\n5XyuHQz7V2Ssu1AxLfRN5Biq1ayb0+DT/E7QxNXDJPqSTnstZ6C7zKH/uAETqg3l\nBonjCQWyds+IYbQYxf5Sp3yhvQ80lMwHML3DaNCMlXWLoOnrOX5/yK5+dedesg2\n/HIvGk+HEt36vm6hoH7bwPuEkgA++ACqwjXRe5Mta7i3eilHxFaF8XIrJFARV0t\nqOu4GID/jG6oA+swIWndGrtR2QRJIt9QIBFfK3HG5M0koZbY1eTqwNFRHFL3xaD\nUQIDAQAB\n-----END PUBLIC KEY-----\n",
"owner": "http://mastodon.example.org/users/gargron",
"id": "http://mastodon.example.org/users/gargron#main-key"
@@ -20,7 +20,27 @@
"endpoints": {
"sharedInbox": "http://mastodon.example.org/inbox"
},
- "icon":{"type":"Image","mediaType":"image/jpeg","url":"https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"},"image":{"type":"Image","mediaType":"image/png","url":"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}
+ "attachment": [{
+ "type": "PropertyValue",
+ "name": "foo",
+ "value": "updated"
+ },
+ {
+ "type": "PropertyValue",
+ "name": "foo1",
+ "value": "updated"
+ }
+ ],
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/jpeg",
+ "url": "https://cd.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
+ },
+ "image": {
+ "type": "Image",
+ "mediaType": "image/png",
+ "url": "https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
+ }
},
"id": "http://mastodon.example.org/users/gargron#updates/1519563538",
"actor": "http://mastodon.example.org/users/gargron",
diff --git a/test/fixtures/tesla_mock/admin@mastdon.example.org.json b/test/fixtures/tesla_mock/admin@mastdon.example.org.json
index c297e4349..8159dc20a 100644
--- a/test/fixtures/tesla_mock/admin@mastdon.example.org.json
+++ b/test/fixtures/tesla_mock/admin@mastdon.example.org.json
@@ -1 +1,54 @@
-{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":"as:movedTo","Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji"}],"id":"http://mastodon.example.org/users/admin","type":"Person","following":"http://mastodon.example.org/users/admin/following","followers":"http://mastodon.example.org/users/admin/followers","inbox":"http://mastodon.example.org/users/admin/inbox","outbox":"http://mastodon.example.org/users/admin/outbox","preferredUsername":"admin","name":null,"summary":"\u003cp\u003e\u003c/p\u003e","url":"http://mastodon.example.org/@admin","manuallyApprovesFollowers":false,"publicKey":{"id":"http://mastodon.example.org/users/admin#main-key","owner":"http://mastodon.example.org/users/admin","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n"},"endpoints":{"sharedInbox":"http://mastodon.example.org/inbox"},"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"},"image":{"type":"Image","mediaType":"image/png","url":"https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"}}
+{
+ "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", {
+ "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+ "sensitive": "as:sensitive",
+ "movedTo": "as:movedTo",
+ "Hashtag": "as:Hashtag",
+ "ostatus": "http://ostatus.org#",
+ "atomUri": "ostatus:atomUri",
+ "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+ "conversation": "ostatus:conversation",
+ "toot": "http://joinmastodon.org/ns#",
+ "Emoji": "toot:Emoji"
+ }],
+ "id": "http://mastodon.example.org/users/admin",
+ "type": "Person",
+ "following": "http://mastodon.example.org/users/admin/following",
+ "followers": "http://mastodon.example.org/users/admin/followers",
+ "inbox": "http://mastodon.example.org/users/admin/inbox",
+ "outbox": "http://mastodon.example.org/users/admin/outbox",
+ "preferredUsername": "admin",
+ "name": null,
+ "summary": "\u003cp\u003e\u003c/p\u003e",
+ "url": "http://mastodon.example.org/@admin",
+ "manuallyApprovesFollowers": false,
+ "publicKey": {
+ "id": "http://mastodon.example.org/users/admin#main-key",
+ "owner": "http://mastodon.example.org/users/admin",
+ "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n"
+ },
+ "attachment": [{
+ "type": "PropertyValue",
+ "name": "foo",
+ "value": "bar"
+ },
+ {
+ "type": "PropertyValue",
+ "name": "foo1",
+ "value": "bar1"
+ }
+ ],
+ "endpoints": {
+ "sharedInbox": "http://mastodon.example.org/inbox"
+ },
+ "icon": {
+ "type": "Image",
+ "mediaType": "image/jpeg",
+ "url": "https://cdn.niu.moe/accounts/avatars/000/033/323/original/fd7f8ae0b3ffedc9.jpeg"
+ },
+ "image": {
+ "type": "Image",
+ "mediaType": "image/png",
+ "url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
+ }
+}
diff --git a/test/http/request_builder_test.exs b/test/http/request_builder_test.exs
index 7febe84c5..170ca916f 100644
--- a/test/http/request_builder_test.exs
+++ b/test/http/request_builder_test.exs
@@ -4,21 +4,19 @@
defmodule Pleroma.HTTP.RequestBuilderTest do
use ExUnit.Case, async: true
+ use Pleroma.Tests.Helpers
alias Pleroma.HTTP.RequestBuilder
describe "headers/2" do
+ clear_config([:http, :send_user_agent])
+
test "don't send pleroma user agent" do
assert RequestBuilder.headers(%{}, []) == %{headers: []}
end
test "send pleroma user agent" do
- send = Pleroma.Config.get([:http, :send_user_agent])
Pleroma.Config.put([:http, :send_user_agent], true)
- on_exit(fn ->
- Pleroma.Config.put([:http, :send_user_agent], send)
- end)
-
assert RequestBuilder.headers(%{}, []) == %{
headers: [{"User-Agent", Pleroma.Application.user_agent()}]
}
diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs
index 0ca87f035..895a73d2c 100644
--- a/test/object/fetcher_test.exs
+++ b/test/object/fetcher_test.exs
@@ -159,32 +159,28 @@ defmodule Pleroma.Object.FetcherTest do
end
describe "signed fetches" do
+ clear_config([:activitypub, :sign_object_fetches])
+
test_with_mock "it signs fetches when configured to do so",
Pleroma.Signature,
[:passthrough],
[] do
- option = Pleroma.Config.get([:activitypub, :sign_object_fetches])
Pleroma.Config.put([:activitypub, :sign_object_fetches], true)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
assert called(Pleroma.Signature.sign(:_, :_))
-
- Pleroma.Config.put([:activitypub, :sign_object_fetches], option)
end
test_with_mock "it doesn't sign fetches when not configured to do so",
Pleroma.Signature,
[:passthrough],
[] do
- option = Pleroma.Config.get([:activitypub, :sign_object_fetches])
Pleroma.Config.put([:activitypub, :sign_object_fetches], false)
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
refute called(Pleroma.Signature.sign(:_, :_))
-
- Pleroma.Config.put([:activitypub, :sign_object_fetches], option)
end
end
end
diff --git a/test/plugs/ensure_public_or_authenticated_plug_test.exs b/test/plugs/ensure_public_or_authenticated_plug_test.exs
index ce5d77ff7..d45662a2a 100644
--- a/test/plugs/ensure_public_or_authenticated_plug_test.exs
+++ b/test/plugs/ensure_public_or_authenticated_plug_test.exs
@@ -9,8 +9,10 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
alias Pleroma.User
+ clear_config([:instance, :public])
+
test "it halts if not public and no user is assigned", %{conn: conn} do
- set_public_to(false)
+ Config.put([:instance, :public], false)
conn =
conn
@@ -21,7 +23,7 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
end
test "it continues if public", %{conn: conn} do
- set_public_to(true)
+ Config.put([:instance, :public], true)
ret_conn =
conn
@@ -31,7 +33,7 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
end
test "it continues if a user is assigned, even if not public", %{conn: conn} do
- set_public_to(false)
+ Config.put([:instance, :public], false)
conn =
conn
@@ -43,13 +45,4 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
assert ret_conn == conn
end
-
- defp set_public_to(value) do
- orig = Config.get!([:instance, :public])
- Config.put([:instance, :public], value)
-
- on_exit(fn ->
- Config.put([:instance, :public], orig)
- end)
- end
end
diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs
index 7dfd50c1f..7a2835e3d 100644
--- a/test/plugs/http_security_plug_test.exs
+++ b/test/plugs/http_security_plug_test.exs
@@ -7,17 +7,12 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
alias Pleroma.Config
alias Plug.Conn
+ clear_config([:http_securiy, :enabled])
+ clear_config([:http_security, :sts])
+
describe "http security enabled" do
setup do
- enabled = Config.get([:http_securiy, :enabled])
-
Config.put([:http_security, :enabled], true)
-
- on_exit(fn ->
- Config.put([:http_security, :enabled], enabled)
- end)
-
- :ok
end
test "it sends CSP headers when enabled", %{conn: conn} do
@@ -81,14 +76,8 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
end
test "it does not send CSP headers when disabled", %{conn: conn} do
- enabled = Config.get([:http_securiy, :enabled])
-
Config.put([:http_security, :enabled], false)
- on_exit(fn ->
- Config.put([:http_security, :enabled], enabled)
- end)
-
conn = get(conn, "/api/v1/instance")
assert Conn.get_resp_header(conn, "x-xss-protection") == []
diff --git a/test/plugs/instance_static_test.exs b/test/plugs/instance_static_test.exs
index e2dcfa3d8..6aabc45a4 100644
--- a/test/plugs/instance_static_test.exs
+++ b/test/plugs/instance_static_test.exs
@@ -8,14 +8,12 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do
@dir "test/tmp/instance_static"
setup do
- static_dir = Pleroma.Config.get([:instance, :static_dir])
- Pleroma.Config.put([:instance, :static_dir], @dir)
File.mkdir_p!(@dir)
+ on_exit(fn -> File.rm_rf(@dir) end)
+ end
- on_exit(fn ->
- Pleroma.Config.put([:instance, :static_dir], static_dir)
- File.rm_rf(@dir)
- end)
+ clear_config([:instance, :static_dir]) do
+ Pleroma.Config.put([:instance, :static_dir], @dir)
end
test "overrides index" do
diff --git a/test/reverse_proxy_test.exs b/test/reverse_proxy_test.exs
index f4b7d6add..3a83c4c48 100644
--- a/test/reverse_proxy_test.exs
+++ b/test/reverse_proxy_test.exs
@@ -108,11 +108,11 @@ defmodule Pleroma.ReverseProxyTest do
end
end
- test "max_body_size returns error if streaming body more than that option", %{conn: conn} do
+ test "max_body_length returns error if streaming body more than that option", %{conn: conn} do
stream_mock(3, true)
assert capture_log(fn ->
- ReverseProxy.call(conn, "/stream-bytes/50", max_body_size: 30)
+ ReverseProxy.call(conn, "/stream-bytes/50", max_body_length: 30)
end) =~
"[warn] Elixir.Pleroma.ReverseProxy request to /stream-bytes/50 failed while reading/chunking: :body_too_large"
end
diff --git a/test/support/helpers.ex b/test/support/helpers.ex
index 1a92be065..a601b3ec8 100644
--- a/test/support/helpers.ex
+++ b/test/support/helpers.ex
@@ -7,8 +7,52 @@ defmodule Pleroma.Tests.Helpers do
Helpers for use in tests.
"""
+ defmacro clear_config(config_path) do
+ quote do
+ clear_config(unquote(config_path)) do
+ end
+ end
+ end
+
+ defmacro clear_config(config_path, do: yield) do
+ quote do
+ setup do
+ initial_setting = Pleroma.Config.get(unquote(config_path))
+ unquote(yield)
+ on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
+ :ok
+ end
+ end
+ end
+
+ defmacro clear_config_all(config_path) do
+ quote do
+ clear_config_all(unquote(config_path)) do
+ end
+ end
+ end
+
+ defmacro clear_config_all(config_path, do: yield) do
+ quote do
+ setup_all do
+ initial_setting = Pleroma.Config.get(unquote(config_path))
+ unquote(yield)
+ on_exit(fn -> Pleroma.Config.put(unquote(config_path), initial_setting) end)
+ :ok
+ end
+ end
+ end
+
defmacro __using__(_opts) do
quote do
+ import Pleroma.Tests.Helpers,
+ only: [
+ clear_config: 1,
+ clear_config: 2,
+ clear_config_all: 1,
+ clear_config_all: 2
+ ]
+
def collect_ids(collection) do
collection
|> Enum.map(& &1.id)
@@ -30,6 +74,15 @@ defmodule Pleroma.Tests.Helpers do
|> Poison.encode!()
|> Poison.decode!()
end
+
+ defmacro guards_config(config_path) do
+ quote do
+ initial_setting = Pleroma.Config.get(config_path)
+
+ Pleroma.Config.put(config_path, true)
+ on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
+ end
+ end
end
end
end
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
index a9b79eb5b..9cd47380c 100644
--- a/test/tasks/config_test.exs
+++ b/test/tasks/config_test.exs
@@ -11,21 +11,20 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
Mix.shell(Mix.Shell.Process)
temp_file = "config/temp.exported_from_db.secret.exs"
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
-
- Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
on_exit(fn ->
Mix.shell(Mix.Shell.IO)
Application.delete_env(:pleroma, :first_setting)
Application.delete_env(:pleroma, :second_setting)
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
:ok = File.rm(temp_file)
end)
{:ok, temp_file: temp_file}
end
+ clear_config_all([:instance, :dynamic_configuration]) do
+ Pleroma.Config.put([:instance, :dynamic_configuration], true)
+ end
+
test "settings are migrated to db" do
assert Repo.all(Config) == []
diff --git a/test/tasks/database_test.exs b/test/tasks/database_test.exs
index a8f25f500..a9925c361 100644
--- a/test/tasks/database_test.exs
+++ b/test/tasks/database_test.exs
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.DatabaseTest do
+ alias Pleroma.Activity
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
@@ -22,6 +23,52 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
:ok
end
+ describe "running remove_embedded_objects" do
+ test "it replaces objects with references" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ new_data = Map.put(activity.data, "object", activity.object.data)
+
+ {:ok, activity} =
+ activity
+ |> Activity.change(%{data: new_data})
+ |> Repo.update()
+
+ assert is_map(activity.data["object"])
+
+ Mix.Tasks.Pleroma.Database.run(["remove_embedded_objects"])
+
+ activity = Activity.get_by_id_with_object(activity.id)
+ assert is_binary(activity.data["object"])
+ end
+ end
+
+ describe "prune_objects" do
+ test "it prunes old objects from the database" do
+ insert(:note)
+ deadline = Pleroma.Config.get([:instance, :remote_post_retention_days]) + 1
+
+ date =
+ Timex.now()
+ |> Timex.shift(days: -deadline)
+ |> Timex.to_naive_datetime()
+ |> NaiveDateTime.truncate(:second)
+
+ %{id: id} =
+ :note
+ |> insert()
+ |> Ecto.Changeset.change(%{inserted_at: date})
+ |> Repo.update!()
+
+ assert length(Repo.all(Object)) == 2
+
+ Mix.Tasks.Pleroma.Database.run(["prune_objects"])
+
+ assert length(Repo.all(Object)) == 1
+ refute Object.get_by_id(id)
+ end
+ end
+
describe "running update_users_following_followers_counts" do
test "following and followers count are updated" do
[user, user2] = insert_pair(:user)
diff --git a/test/mix/tasks/pleroma.digest_test.exs b/test/tasks/digest_test.exs
index 5fbeac0d6..96d762685 100644
--- a/test/mix/tasks/pleroma.digest_test.exs
+++ b/test/tasks/digest_test.exs
@@ -47,7 +47,7 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
assert_email_sent(
to: {user2.name, user2.email},
- html_body: ~r/new mentions:/i
+ html_body: ~r/here is what you've missed!/i
)
end
end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 9d260da3e..0d341c8d6 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -69,4 +69,27 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
assert undo_activity.data["object"] == cancelled_activity.data
end
end
+
+ describe "mix pleroma.relay list" do
+ test "Prints relay subscription list" do
+ :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
+
+ refute_receive {:mix_shell, :info, _}
+
+ Pleroma.Web.ActivityPub.Relay.get_actor()
+ |> Ecto.Changeset.change(
+ following: [
+ "http://test-app.com/user/test1",
+ "http://test-app.com/user/test1",
+ "http://test-app-42.com/user/test1"
+ ]
+ )
+ |> Pleroma.User.update_and_set_cache()
+
+ :ok = Mix.Tasks.Pleroma.Relay.run(["list"])
+
+ assert_receive {:mix_shell, :info, ["test-app.com"]}
+ assert_receive {:mix_shell, :info, ["test-app-42.com"]}
+ end
+ end
end
diff --git a/test/tasks/robots_txt_test.exs b/test/tasks/robots_txt_test.exs
index 78a3f17b4..917df2675 100644
--- a/test/tasks/robots_txt_test.exs
+++ b/test/tasks/robots_txt_test.exs
@@ -4,17 +4,17 @@
defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
use ExUnit.Case
+ use Pleroma.Tests.Helpers
alias Mix.Tasks.Pleroma.RobotsTxt
+ clear_config([:instance, :static_dir])
+
test "creates new dir" do
path = "test/fixtures/new_dir/"
file_path = path <> "robots.txt"
-
- static_dir = Pleroma.Config.get([:instance, :static_dir])
Pleroma.Config.put([:instance, :static_dir], path)
on_exit(fn ->
- Pleroma.Config.put([:instance, :static_dir], static_dir)
{:ok, ["test/fixtures/new_dir/", "test/fixtures/new_dir/robots.txt"]} = File.rm_rf(path)
end)
@@ -29,11 +29,9 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
test "to existance folder" do
path = "test/fixtures/"
file_path = path <> "robots.txt"
- static_dir = Pleroma.Config.get([:instance, :static_dir])
Pleroma.Config.put([:instance, :static_dir], path)
on_exit(fn ->
- Pleroma.Config.put([:instance, :static_dir], static_dir)
:ok = File.rm(file_path)
end)
diff --git a/test/upload/filter/anonymize_filename_test.exs b/test/upload/filter/anonymize_filename_test.exs
index a31b38ab1..6b33e7395 100644
--- a/test/upload/filter/anonymize_filename_test.exs
+++ b/test/upload/filter/anonymize_filename_test.exs
@@ -9,12 +9,6 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
alias Pleroma.Upload
setup do
- custom_filename = Config.get([Upload.Filter.AnonymizeFilename, :text])
-
- on_exit(fn ->
- Config.put([Upload.Filter.AnonymizeFilename, :text], custom_filename)
- end)
-
upload_file = %Upload{
name: "an… image.jpg",
content_type: "image/jpg",
@@ -24,6 +18,8 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
%{upload_file: upload_file}
end
+ clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
+
test "it replaces filename on pre-defined text", %{upload_file: upload_file} do
Config.put([Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
{:ok, %Upload{name: name}} = Upload.Filter.AnonymizeFilename.filter(upload_file)
diff --git a/test/upload/filter/mogrify_test.exs b/test/upload/filter/mogrify_test.exs
index c301440fd..210320d30 100644
--- a/test/upload/filter/mogrify_test.exs
+++ b/test/upload/filter/mogrify_test.exs
@@ -10,13 +10,7 @@ defmodule Pleroma.Upload.Filter.MogrifyTest do
alias Pleroma.Upload
alias Pleroma.Upload.Filter
- setup do
- filter = Config.get([Filter.Mogrify, :args])
-
- on_exit(fn ->
- Config.put([Filter.Mogrify, :args], filter)
- end)
- end
+ clear_config([Filter.Mogrify, :args])
test "apply mogrify filter" do
Config.put([Filter.Mogrify, :args], [{"tint", "40"}])
diff --git a/test/upload/filter_test.exs b/test/upload/filter_test.exs
index 640cd7107..03887c06a 100644
--- a/test/upload/filter_test.exs
+++ b/test/upload/filter_test.exs
@@ -8,13 +8,7 @@ defmodule Pleroma.Upload.FilterTest do
alias Pleroma.Config
alias Pleroma.Upload.Filter
- setup do
- custom_filename = Config.get([Pleroma.Upload.Filter.AnonymizeFilename, :text])
-
- on_exit(fn ->
- Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], custom_filename)
- end)
- end
+ clear_config([Pleroma.Upload.Filter.AnonymizeFilename, :text])
test "applies filters" do
Config.put([Pleroma.Upload.Filter.AnonymizeFilename, :text], "custom-file.png")
diff --git a/test/upload_test.exs b/test/upload_test.exs
index 95b16078b..6721fe82e 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -250,12 +250,8 @@ defmodule Pleroma.UploadTest do
end
describe "Setting a custom base_url for uploaded media" do
- setup do
+ clear_config([Pleroma.Upload, :base_url]) do
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://cache.pleroma.social")
-
- on_exit(fn ->
- Pleroma.Config.put([Pleroma.Upload, :base_url], nil)
- end)
end
test "returns a media url with configured base_url" do
diff --git a/test/uploaders/s3_test.exs b/test/uploaders/s3_test.exs
index a0a1cfdf0..171316340 100644
--- a/test/uploaders/s3_test.exs
+++ b/test/uploaders/s3_test.exs
@@ -11,19 +11,11 @@ defmodule Pleroma.Uploaders.S3Test do
import Mock
import ExUnit.CaptureLog
- setup do
- config = Config.get([Pleroma.Uploaders.S3])
-
+ clear_config([Pleroma.Uploaders.S3]) do
Config.put([Pleroma.Uploaders.S3],
bucket: "test_bucket",
public_endpoint: "https://s3.amazonaws.com"
)
-
- on_exit(fn ->
- Config.put([Pleroma.Uploaders.S3], config)
- end)
-
- :ok
end
describe "get_file/1" do
diff --git a/test/user_test.exs b/test/user_test.exs
index 2b955ced0..3185cc1fb 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -15,6 +15,7 @@ defmodule Pleroma.UserTest do
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
+ import Mock
import Pleroma.Factory
setup_all do
@@ -22,6 +23,8 @@ defmodule Pleroma.UserTest do
:ok
end
+ clear_config([:instance, :account_activation_required])
+
describe "when tags are nil" do
test "tagging a user" do
user = insert(:user, %{tags: nil})
@@ -91,6 +94,17 @@ defmodule Pleroma.UserTest do
assert activity
end
+ test "clears follow requests when requester is blocked" do
+ followed = insert(:user, %{info: %{locked: true}})
+ follower = insert(:user)
+
+ CommonAPI.follow(follower, followed)
+ assert {:ok, [_activity]} = User.get_follow_requests(followed)
+
+ {:ok, _follower} = User.block(followed, follower)
+ assert {:ok, []} = User.get_follow_requests(followed)
+ end
+
test "follow_all follows mutliple users" do
user = insert(:user)
followed_zero = insert(:user)
@@ -193,24 +207,64 @@ defmodule Pleroma.UserTest do
# assert websub
# end
- test "unfollow takes a user and another user" do
- followed = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(followed)]})
+ describe "unfollow/2" do
+ setup do
+ setting = Pleroma.Config.get([:instance, :external_user_synchronization])
- {:ok, user, _activity} = User.unfollow(user, followed)
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :external_user_synchronization], setting)
+ end)
- user = User.get_cached_by_id(user.id)
+ :ok
+ end
- assert user.following == []
- end
+ test "unfollow with syncronizes external user" do
+ Pleroma.Config.put([:instance, :external_user_synchronization], true)
- test "unfollow doesn't unfollow yourself" do
- user = insert(:user)
+ followed =
+ insert(:user,
+ nickname: "fuser1",
+ follower_address: "http://localhost:4001/users/fuser1/followers",
+ following_address: "http://localhost:4001/users/fuser1/following",
+ ap_id: "http://localhost:4001/users/fuser1"
+ )
+
+ user =
+ insert(:user, %{
+ local: false,
+ nickname: "fuser2",
+ ap_id: "http://localhost:4001/users/fuser2",
+ follower_address: "http://localhost:4001/users/fuser2/followers",
+ following_address: "http://localhost:4001/users/fuser2/following",
+ following: [User.ap_followers(followed)]
+ })
- {:error, _} = User.unfollow(user, user)
+ {:ok, user, _activity} = User.unfollow(user, followed)
- user = User.get_cached_by_id(user.id)
- assert user.following == [user.ap_id]
+ user = User.get_cached_by_id(user.id)
+
+ assert user.following == []
+ end
+
+ test "unfollow takes a user and another user" do
+ followed = insert(:user)
+ user = insert(:user, %{following: [User.ap_followers(followed)]})
+
+ {:ok, user, _activity} = User.unfollow(user, followed)
+
+ user = User.get_cached_by_id(user.id)
+
+ assert user.following == []
+ end
+
+ test "unfollow doesn't unfollow yourself" do
+ user = insert(:user)
+
+ {:error, _} = User.unfollow(user, user)
+
+ user = User.get_cached_by_id(user.id)
+ assert user.following == [user.ap_id]
+ end
end
test "test if a user is following another user" do
@@ -237,6 +291,9 @@ defmodule Pleroma.UserTest do
password_confirmation: "test",
email: "email@example.com"
}
+ clear_config([:instance, :autofollowed_nicknames])
+ clear_config([:instance, :welcome_message])
+ clear_config([:instance, :welcome_user_nickname])
test "it autofollows accounts that are set for it" do
user = insert(:user)
@@ -253,8 +310,6 @@ defmodule Pleroma.UserTest do
assert User.following?(registered_user, user)
refute User.following?(registered_user, remote_user)
-
- Pleroma.Config.put([:instance, :autofollowed_nicknames], [])
end
test "it sends a welcome message if it is set" do
@@ -270,9 +325,6 @@ defmodule Pleroma.UserTest do
assert registered_user.ap_id in activity.recipients
assert Object.normalize(activity).data["content"] =~ "cool site"
assert activity.actor == welcome_user.ap_id
-
- Pleroma.Config.put([:instance, :welcome_user_nickname], nil)
- Pleroma.Config.put([:instance, :welcome_message], nil)
end
test "it requires an email, name, nickname and password, bio is optional" do
@@ -338,15 +390,8 @@ defmodule Pleroma.UserTest do
email: "email@example.com"
}
- setup do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
-
- :ok
+ clear_config([:instance, :account_activation_required]) do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
end
test "it creates unconfirmed user" do
@@ -997,6 +1042,8 @@ defmodule Pleroma.UserTest do
[user: user]
end
+ clear_config([:instance, :federating])
+
test ".delete_user_activities deletes all create activities", %{user: user} do
{:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
@@ -1006,6 +1053,15 @@ defmodule Pleroma.UserTest do
refute Activity.get_by_id(activity.id)
end
+ test "it deletes deactivated user" do
+ {:ok, user} = insert(:user, info: %{deactivated: true}) |> User.set_cache()
+
+ {:ok, job} = User.delete(user)
+ {:ok, _user} = ObanHelpers.perform(job)
+
+ refute User.get_by_id(user.id)
+ end
+
test "it deletes a user, all follow relationships and all activities", %{user: user} do
follower = insert(:user)
{:ok, follower} = User.follow(follower, user)
@@ -1043,10 +1099,12 @@ defmodule Pleroma.UserTest do
refute Activity.get_by_id(repeat.id)
end
- test "it sends out User Delete activity", %{user: user} do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
- Pleroma.Config.put(config_path, true)
+ test_with_mock "it sends out User Delete activity",
+ %{user: user},
+ Pleroma.Web.ActivityPub.Publisher,
+ [:passthrough],
+ [] do
+ Pleroma.Config.put([:instance, :federating], true)
{:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
{:ok, _} = User.follow(follower, user)
@@ -1064,8 +1122,6 @@ defmodule Pleroma.UserTest do
},
all_enqueued(worker: Pleroma.Workers.Publisher)
)
-
- Pleroma.Config.put(config_path, initial_setting)
end
end
@@ -1132,8 +1188,6 @@ defmodule Pleroma.UserTest do
refute User.auth_active?(local_user)
assert User.auth_active?(confirmed_user)
assert User.auth_active?(remote_user)
-
- Pleroma.Config.put([:instance, :account_activation_required], false)
end
describe "superuser?/1" do
@@ -1178,8 +1232,6 @@ defmodule Pleroma.UserTest do
other_user = insert(:user, local: true)
refute User.visible_for?(user, other_user)
-
- Pleroma.Config.put([:instance, :account_activation_required], false)
end
test "returns true when the account is unauthenticated and auth is not required" do
@@ -1196,8 +1248,6 @@ defmodule Pleroma.UserTest do
other_user = insert(:user, local: true, info: %{is_admin: true})
assert User.visible_for?(user, other_user)
-
- Pleroma.Config.put([:instance, :account_activation_required], false)
end
end
@@ -1510,10 +1560,7 @@ defmodule Pleroma.UserTest do
end
describe "following/followers synchronization" do
- setup do
- sync = Pleroma.Config.get([:instance, :external_user_synchronization])
- on_exit(fn -> Pleroma.Config.put([:instance, :external_user_synchronization], sync) end)
- end
+ clear_config([:instance, :external_user_synchronization])
test "updates the counters normally on following/getting a follow when disabled" do
Pleroma.Config.put([:instance, :external_user_synchronization], false)
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index f46353fdd..a214f57a6 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -20,17 +20,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ clear_config_all([:instance, :federating],
+ do: Pleroma.Config.put([:instance, :federating], true)
+ )
+
describe "/relay" do
+ clear_config([:instance, :allow_relay])
+
test "with the relay active, it returns the relay user", %{conn: conn} do
res =
conn
@@ -47,8 +46,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> get(activity_pub_path(conn, :relay))
|> json_response(404)
|> assert
-
- Pleroma.Config.put([:instance, :allow_relay], true)
end
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d723f331f..1515f4eb6 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -538,6 +538,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_one)
end
+ test "doesn't return thread muted activities" do
+ user = insert(:user)
+ _activity_one = insert(:note_activity)
+ note_two = insert(:note, data: %{"context" => "suya.."})
+ activity_two = insert(:note_activity, note: note_two)
+
+ {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
+
+ assert [_activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
+ end
+
+ test "returns thread muted activities when with_muted is set" do
+ user = insert(:user)
+ _activity_one = insert(:note_activity)
+ note_two = insert(:note, data: %{"context" => "suya.."})
+ activity_two = insert(:note_activity, note: note_two)
+
+ {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
+
+ assert [_activity_two, _activity_one] =
+ ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
+ end
+
test "does include announces on request" do
activity_three = insert(:note_activity)
user = insert(:user)
diff --git a/test/web/activity_pub/mrf/mrf_test.exs b/test/web/activity_pub/mrf/mrf_test.exs
index 19e172939..04709df17 100644
--- a/test/web/activity_pub/mrf/mrf_test.exs
+++ b/test/web/activity_pub/mrf/mrf_test.exs
@@ -1,5 +1,6 @@
defmodule Pleroma.Web.ActivityPub.MRFTest do
use ExUnit.Case, async: true
+ use Pleroma.Tests.Helpers
alias Pleroma.Web.ActivityPub.MRF
test "subdomains_regex/1" do
@@ -59,6 +60,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
describe "describe/0" do
+ clear_config([:instance, :rewrite_policy])
+
test "it works as expected with noop policy" do
expected = %{
mrf_policies: ["NoOpPolicy"],
@@ -69,7 +72,6 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
test "it works as expected with mock policy" do
- config = Pleroma.Config.get([:instance, :rewrite_policy])
Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
expected = %{
@@ -79,8 +81,6 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
}
{:ok, ^expected} = MRF.describe()
-
- Pleroma.Config.put([:instance, :rewrite_policy], config)
end
end
end
diff --git a/test/web/activity_pub/mrf/reject_non_public_test.exs b/test/web/activity_pub/mrf/reject_non_public_test.exs
index fdf6b245e..fc1d190bb 100644
--- a/test/web/activity_pub/mrf/reject_non_public_test.exs
+++ b/test/web/activity_pub/mrf/reject_non_public_test.exs
@@ -8,12 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
- setup do
- policy = Pleroma.Config.get([:mrf_rejectnonpublic])
- on_exit(fn -> Pleroma.Config.put([:mrf_rejectnonpublic], policy) end)
-
- :ok
- end
+ clear_config([:mrf_rejectnonpublic])
describe "public message" do
test "it's allowed when address is public" do
diff --git a/test/web/activity_pub/mrf/simple_policy_test.exs b/test/web/activity_pub/mrf/simple_policy_test.exs
index 8e86d2219..7203b27da 100644
--- a/test/web/activity_pub/mrf/simple_policy_test.exs
+++ b/test/web/activity_pub/mrf/simple_policy_test.exs
@@ -8,9 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
alias Pleroma.Config
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
- setup do
- orig = Config.get!(:mrf_simple)
-
+ clear_config([:mrf_simple]) do
Config.put(:mrf_simple,
media_removal: [],
media_nsfw: [],
@@ -21,10 +19,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
avatar_removal: [],
banner_removal: []
)
-
- on_exit(fn ->
- Config.put(:mrf_simple, orig)
- end)
end
describe "when :media_removal" do
diff --git a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
index 6519e2398..72084c0fd 100644
--- a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
+++ b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
@@ -7,12 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
- setup do
- policy = Pleroma.Config.get([:mrf_user_allowlist]) || []
- on_exit(fn -> Pleroma.Config.put([:mrf_user_allowlist], policy) end)
-
- :ok
- end
+ clear_config([:mrf_user_allowlist, :localhost])
test "pass filter if allow list is empty" do
actor = insert(:user)
diff --git a/test/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
index c3b11d7a1..38309f9f1 100644
--- a/test/web/activity_pub/mrf/vocabulary_policy_test.exs
+++ b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
@@ -8,8 +8,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
describe "accept" do
+ clear_config([:mrf_vocabulary, :accept])
+
test "it accepts based on parent activity type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
message = %{
@@ -18,12 +19,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:ok, ^message} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
test "it accepts based on child object type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
@@ -35,12 +33,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:ok, ^message} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
test "it does not accept disallowed child objects" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
@@ -52,12 +47,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
test "it does not accept disallowed parent types" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
message = %{
@@ -69,14 +61,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
end
describe "reject" do
+ clear_config([:mrf_vocabulary, :reject])
+
test "it rejects based on parent activity type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :reject])
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
message = %{
@@ -85,12 +76,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :reject], config)
end
test "it rejects based on child object type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :reject])
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
message = %{
@@ -102,12 +90,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :reject], config)
end
test "it passes through objects that aren't disallowed" do
- config = Pleroma.Config.get([:mrf_vocabulary, :reject])
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
message = %{
@@ -116,8 +101,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:ok, ^message} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :reject], config)
end
end
end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index e80263328..86605c336 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -510,6 +510,60 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.bio == "<p>Some bio</p>"
end
+ test "it works with custom profile fields" do
+ {:ok, activity} =
+ "test/fixtures/mastodon-post-activity.json"
+ |> File.read!()
+ |> Poison.decode!()
+ |> Transmogrifier.handle_incoming()
+
+ user = User.get_cached_by_ap_id(activity.actor)
+
+ assert User.Info.fields(user.info) == [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "foo1", "value" => "bar1"}
+ ]
+
+ update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
+
+ object =
+ update_data["object"]
+ |> Map.put("actor", user.ap_id)
+ |> Map.put("id", user.ap_id)
+
+ update_data =
+ update_data
+ |> Map.put("actor", user.ap_id)
+ |> Map.put("object", object)
+
+ {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert User.Info.fields(user.info) == [
+ %{"name" => "foo", "value" => "updated"},
+ %{"name" => "foo1", "value" => "updated"}
+ ]
+
+ Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
+
+ update_data =
+ put_in(update_data, ["object", "attachment"], [
+ %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
+ %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
+ %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
+ ])
+
+ {:ok, _} = Transmogrifier.handle_incoming(update_data)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert User.Info.fields(user.info) == [
+ %{"name" => "foo", "value" => "updated"},
+ %{"name" => "foo1", "value" => "updated"}
+ ]
+ end
+
test "it works for incoming update activities which lock the account" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 86254117f..fb7fd9e79 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -22,6 +22,21 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
+ test "Renders profile fields" do
+ fields = [
+ %{"name" => "foo", "value" => "bar"}
+ ]
+
+ {:ok, user} =
+ insert(:user)
+ |> User.upgrade_changeset(%{info: %{fields: fields}})
+ |> User.update_and_set_cache()
+
+ assert %{
+ "attachment" => [%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"}]
+ } = UserView.render("user.json", %{user: user})
+ end
+
test "Does not add an avatar image if the user hasn't set one" do
user = insert(:user)
{:ok, user} = User.ensure_keys_present(user)
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index bcbc18639..844cd0732 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -294,18 +294,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "POST /api/pleroma/admin/email_invite, with valid config" do
setup do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
- Pleroma.Config.put([:instance, :registrations_open], false)
- Pleroma.Config.put([:instance, :invites_enabled], true)
+ [user: insert(:user, info: %{is_admin: true})]
+ end
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
+ clear_config([:instance, :registrations_open]) do
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ end
- [user: insert(:user, info: %{is_admin: true})]
+ clear_config([:instance, :invites_enabled]) do
+ Pleroma.Config.put([:instance, :invites_enabled], true)
end
test "sends invitation and returns 204", %{conn: conn, user: user} do
@@ -360,18 +357,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
[user: insert(:user, info: %{is_admin: true})]
end
+ clear_config([:instance, :registrations_open])
+ clear_config([:instance, :invites_enabled])
+
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
Pleroma.Config.put([:instance, :registrations_open], false)
Pleroma.Config.put([:instance, :invites_enabled], false)
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
conn =
conn
|> assign(:user, user)
@@ -381,17 +373,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
Pleroma.Config.put([:instance, :registrations_open], true)
Pleroma.Config.put([:instance, :invites_enabled], true)
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
conn =
conn
|> assign(:user, user)
@@ -1402,15 +1386,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
:ok = File.rm(temp_file)
end)
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
+ %{conn: assign(conn, :user, admin)}
+ end
+ clear_config([:instance, :dynamic_configuration]) do
Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
- end)
-
- %{conn: assign(conn, :user, admin)}
end
test "create new config setting in db", %{conn: conn} do
@@ -1961,15 +1941,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
:ok = File.rm(temp_file)
end)
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
+ %{conn: assign(conn, :user, admin), admin: admin}
+ end
+ clear_config([:instance, :dynamic_configuration]) do
Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
- end)
-
- %{conn: assign(conn, :user, admin), admin: admin}
end
test "transfer settings to DB and to file", %{conn: conn, admin: admin} do
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 16b3f121d..bcbaad665 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -5,18 +5,66 @@
defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Conversation.Participation
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ clear_config([:instance, :safe_dm_mentions])
+ clear_config([:instance, :limit])
+ 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)
+ {: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})
+
+ assert Visibility.is_direct?(convo_reply)
+
+ assert activity.data["context"] == convo_reply.data["context"]
+ end
+
+ test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
+ har = insert(:user)
+ jafnhar = insert(:user)
+ tridi = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(har, %{
+ "status" => "@#{jafnhar.nickname} hey",
+ "visibility" => "direct"
+ })
+
+ assert har.ap_id in activity.recipients
+ assert jafnhar.ap_id in activity.recipients
+
+ [participation] = Participation.for_user(har)
+
+ {: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
+ })
+
+ assert har.ap_id in activity.recipients
+ assert jafnhar.ap_id in activity.recipients
+ refute tridi.ap_id in activity.recipients
+ end
+
test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
har = insert(:user)
jafnhar = insert(:user)
tridi = insert(:user)
- option = Pleroma.Config.get([:instance, :safe_dm_mentions])
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
{:ok, activity} =
@@ -27,7 +75,6 @@ defmodule Pleroma.Web.CommonAPITest do
refute tridi.ap_id in activity.recipients
assert jafnhar.ap_id in activity.recipients
- Pleroma.Config.put([:instance, :safe_dm_mentions], option)
end
test "it de-duplicates tags" do
@@ -150,15 +197,12 @@ defmodule Pleroma.Web.CommonAPITest do
end
test "it returns error when character limit is exceeded" do
- limit = Pleroma.Config.get([:instance, :limit])
Pleroma.Config.put([:instance, :limit], 5)
user = insert(:user)
assert {:error, "The status is over the character limit"} =
CommonAPI.post(user, %{"status" => "foobar"})
-
- Pleroma.Config.put([:instance, :limit], limit)
end
end
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 5989d7d29..c281dd1f1 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -239,7 +239,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public", nil)
assert length(to) == 2
assert length(cc) == 1
@@ -256,7 +256,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
assert length(to) == 3
assert length(cc) == 1
@@ -272,7 +272,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted", nil)
assert length(to) == 2
assert length(cc) == 1
@@ -289,7 +289,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
assert length(to) == 3
assert length(cc) == 1
@@ -305,7 +305,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private", nil)
assert length(to) == 2
assert length(cc) == 0
@@ -320,7 +320,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
assert length(to) == 3
assert length(cc) == 0
@@ -335,7 +335,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct", nil)
assert length(to) == 1
assert length(cc) == 0
@@ -350,7 +350,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
assert length(to) == 2
assert length(cc) == 0
diff --git a/test/web/digest_email_worker_test.exs b/test/web/digest_email_worker_test.exs
new file mode 100644
index 000000000..5dfd920fa
--- /dev/null
+++ b/test/web/digest_email_worker_test.exs
@@ -0,0 +1,35 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.DigestEmailWorkerTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.DigestEmailWorker
+ alias Pleroma.Tests.ObanHelpers
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ test "it sends digest emails" do
+ user = insert(:user)
+
+ date =
+ Timex.now()
+ |> Timex.shift(days: -10)
+ |> Timex.to_naive_datetime()
+
+ user2 = insert(:user, last_digest_emailed_at: date)
+ User.switch_email_notifications(user2, "digest", true)
+ CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
+
+ DigestEmailWorker.perform()
+ ObanHelpers.perform_all()
+ # Performing job(s) enqueued at previous step
+ ObanHelpers.perform_all()
+
+ assert_received {:email, email}
+ assert email.to == [{user2.name, user2.email}]
+ assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
+ end
+end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 9ca341b6d..5724672fd 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -18,15 +18,17 @@ defmodule Pleroma.Web.FederatorTest do
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
+ clear_config([:instance, :allow_relay])
+ clear_config([:instance, :rewrite_policy])
+ clear_config([:mrf_keyword])
+
describe "Publish an activity" do
setup do
user = insert(:user)
@@ -65,8 +67,6 @@ defmodule Pleroma.Web.FederatorTest do
end
refute_received :relay_publish
-
- Pleroma.Config.put([:instance, :allow_relay], true)
end
end
@@ -240,10 +240,12 @@ defmodule Pleroma.Web.FederatorTest do
end
test "it does not crash if MRF rejects the post" do
- policies = Pleroma.Config.get([:instance, :rewrite_policy])
- mrf_keyword_policy = Pleroma.Config.get(:mrf_keyword)
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
- Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.KeywordPolicy)
+
+ Pleroma.Config.put(
+ [:instance, :rewrite_policy],
+ Pleroma.Web.ActivityPub.MRF.KeywordPolicy
+ )
params =
File.read!("test/fixtures/mastodon-post-activity.json")
@@ -251,9 +253,6 @@ defmodule Pleroma.Web.FederatorTest do
assert {:ok, job} = Federator.incoming_ap_doc(params)
assert :error = ObanHelpers.perform(job)
-
- Pleroma.Config.put([:instance, :rewrite_policy], policies)
- Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
end
end
end
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
index a1bdd45d3..0b53bc6cd 100644
--- a/test/web/instances/instance_test.exs
+++ b/test/web/instances/instance_test.exs
@@ -10,14 +10,8 @@ defmodule Pleroma.Instances.InstanceTest do
import Pleroma.Factory
- setup_all do
- config_path = [:instance, :federation_reachability_timeout_days]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, 1)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federation_reachability_timeout_days]) do
+ Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
end
describe "set_reachable/1" do
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index f0d84edea..dea8e2aea 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -7,14 +7,8 @@ defmodule Pleroma.InstancesTest do
use Pleroma.DataCase
- setup_all do
- config_path = [:instance, :federation_reachability_timeout_days]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, 1)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federation_reachability_timeout_days]) do
+ Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
end
describe "reachable?/1" do
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index a26f514a5..1d8b28339 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -67,7 +67,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: "valid html",
sensitive: false,
- pleroma: %{}
+ pleroma: %{},
+ fields: []
},
pleroma: %{
background_image: "https://example.com/images/asuka_hospital.png",
@@ -134,7 +135,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: user.bio,
sensitive: false,
- pleroma: %{}
+ pleroma: %{},
+ fields: []
},
pleroma: %{
background_image: nil,
@@ -304,7 +306,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: user.bio,
sensitive: false,
- pleroma: %{}
+ pleroma: %{},
+ fields: []
},
pleroma: %{
background_image: nil,
diff --git a/test/web/mastodon_api/conversation_view_test.exs b/test/web/mastodon_api/conversation_view_test.exs
new file mode 100644
index 000000000..a2a880705
--- /dev/null
+++ b/test/web/mastodon_api/conversation_view_test.exs
@@ -0,0 +1,34 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.MastodonAPI.ConversationView
+
+ import Pleroma.Factory
+
+ test "represents a Mastodon Conversation entity" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}", "visibility" => "direct"})
+
+ [participation] = Participation.for_user_with_last_activity_id(user)
+
+ assert participation
+
+ conversation =
+ ConversationView.render("participation.json", %{participation: participation, for: user})
+
+ assert conversation.id == participation.id |> to_string()
+ assert conversation.last_status.id == activity.id
+
+ assert [account] = conversation.accounts
+ assert account.id == other_user.id
+ end
+end
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index 71d0c8af8..dd443495b 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -300,5 +300,69 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert user["display_name"] == name
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
end
+
+ test "update fields", %{conn: conn} do
+ user = insert(:user)
+
+ fields = [
+ %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "<script>bar</script>"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ account =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(200)
+
+ assert account["fields"] == [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "link", "value" => "<a href=\"http://cofe.io\">cofe.io</a>"}
+ ]
+
+ assert account["source"]["fields"] == [
+ %{
+ "name" => "<a href=\"http://google.com\">foo</a>",
+ "value" => "<script>bar</script>"
+ },
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
+ value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
+
+ long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
+
+ fields = [%{"name" => "<b>foo<b>", "value" => long_value}]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+
+ long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
+
+ fields = [%{"name" => long_name, "value" => "bar"}]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+
+ Pleroma.Config.put([:instance, :max_account_fields], 1)
+
+ fields = [
+ %{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+ end
end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f18b58a1b..0f40146fb 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -34,6 +34,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
:ok
end
+ clear_config([:instance, :public])
+ clear_config([:rich_media, :enabled])
+
test "the home timeline", %{conn: conn} do
user = insert(:user)
following = insert(:user)
@@ -87,13 +90,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "the public timeline when public is set to false", %{conn: conn} do
- public = Config.get([:instance, :public])
Config.put([:instance, :public], false)
- on_exit(fn ->
- Config.put([:instance, :public], public)
- end)
-
assert conn
|> get("/api/v1/timelines/public", %{"local" => "False"})
|> json_response(403) == %{"error" => "This resource requires authentication."}
@@ -262,7 +260,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
assert Activity.get_by_id(id)
- Config.put([:rich_media, :enabled], false)
end
test "posting a direct status", %{conn: conn} do
@@ -1635,14 +1632,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "media upload" do
setup do
- upload_config = Config.get([Pleroma.Upload])
- proxy_config = Config.get([:media_proxy])
-
- on_exit(fn ->
- Config.put([Pleroma.Upload], upload_config)
- Config.put([:media_proxy], proxy_config)
- end)
-
user = insert(:user)
conn =
@@ -1658,6 +1647,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[conn: conn, image: image]
end
+ clear_config([:media_proxy])
+ clear_config([Pleroma.Upload])
+
test "returns uploaded image", %{conn: conn, image: image} do
desc = "Description of the image"
@@ -2625,7 +2617,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> Changeset.put_embed(:info, info_change)
|> User.update_and_set_cache()
- Pleroma.Stats.update_stats()
+ Pleroma.Stats.force_update()
conn = get(conn, "/api/v1/instance")
@@ -2643,7 +2635,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
- Pleroma.Stats.update_stats()
+ Pleroma.Stats.force_update()
conn = get(conn, "/api/v1/instance/peers")
@@ -2668,14 +2660,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "pinned statuses" do
setup do
- Config.put([:instance, :max_pinned_statuses], 1)
-
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
[user: user, activity: activity]
end
+ clear_config([:instance, :max_pinned_statuses]) do
+ Config.put([:instance, :max_pinned_statuses], 1)
+ end
+
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.pin(activity.id, user)
@@ -2770,10 +2764,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
setup do
Config.put([:rich_media, :enabled], true)
- on_exit(fn ->
- Config.put([:rich_media, :enabled], false)
- end)
-
user = insert(:user)
%{user: user}
end
@@ -3128,15 +3118,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn: conn,
path: path
} do
- is_public = Config.get([:instance, :public])
Config.put([:instance, :public], false)
conn = get(conn, path)
assert conn.status == 302
assert redirected_to(conn) == "/web/login"
-
- Config.put([:instance, :public], is_public)
end
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
@@ -3912,13 +3899,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
setup do
- setting = Config.get([:instance, :account_activation_required])
-
- unless setting do
- Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Config.put([:instance, :account_activation_required], setting) end)
- end
-
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
@@ -3933,6 +3913,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[user: user]
end
+ clear_config([:instance, :account_activation_required]) do
+ Config.put([:instance, :account_activation_required], true)
+ end
+
test "resend account confirmation email", %{conn: conn, user: user} do
conn
|> assign(:user, user)
@@ -3957,9 +3941,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
setup do
user = insert(:user)
other_user = insert(:user)
- config = Config.get(:suggestions)
- on_exit(fn -> Config.put(:suggestions, config) end)
-
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
url500 = "http://test500?#{host}&#{user.nickname}"
url200 = "http://test200?#{host}&#{user.nickname}"
@@ -3981,6 +3962,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[user: user, other_user: other_user]
end
+ clear_config(:suggestions)
+
test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
Config.put([:suggestions, :enabled], false)
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 0b167f839..c983b494f 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -23,6 +23,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
:ok
end
+ test "returns the direct conversation id when given the `with_conversation_id` option" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+
+ status =
+ StatusView.render("status.json",
+ activity: activity,
+ with_direct_conversation_id: true,
+ for: user
+ )
+
+ assert status[:pleroma][:direct_conversation_id]
+ end
+
test "returns a temporary ap_id based user for activities missing db users" do
user = insert(:user)
@@ -133,7 +148,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
conversation_id: convo_id,
in_reply_to_account_acct: nil,
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
- spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])}
+ spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
+ direct_conversation_id: nil
}
}
diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index 0c94755df..79699cac5 100644
--- a/test/web/media_proxy/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -4,14 +4,11 @@
defmodule Pleroma.Web.MediaProxyTest do
use ExUnit.Case
+ use Pleroma.Tests.Helpers
import Pleroma.Web.MediaProxy
alias Pleroma.Web.MediaProxy.MediaProxyController
- setup do
- enabled = Pleroma.Config.get([:media_proxy, :enabled])
- on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
- :ok
- end
+ clear_config([:media_proxy, :enabled])
describe "when enabled" do
setup do
diff --git a/test/web/oauth/ldap_authorization_test.exs b/test/web/oauth/ldap_authorization_test.exs
index 0eb191c76..1cbe133b7 100644
--- a/test/web/oauth/ldap_authorization_test.exs
+++ b/test/web/oauth/ldap_authorization_test.exs
@@ -12,21 +12,12 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
@skip if !Code.ensure_loaded?(:eldap), do: :skip
- setup_all do
- ldap_authenticator =
- Pleroma.Config.get(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator)
-
- ldap_enabled = Pleroma.Config.get([:ldap, :enabled])
-
- on_exit(fn ->
- Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, ldap_authenticator)
- Pleroma.Config.put([:ldap, :enabled], ldap_enabled)
- end)
-
- Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
+ clear_config_all([:ldap, :enabled]) do
Pleroma.Config.put([:ldap, :enabled], true)
+ end
- :ok
+ clear_config_all(Pleroma.Web.Auth.Authenticator) do
+ Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
end
@tag @skip
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 92e156347..b492c7794 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -11,23 +11,15 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
alias Pleroma.Web.OAuth.OAuthController
alias Pleroma.Web.OAuth.Token
- @oauth_config_path [:oauth2, :issue_new_refresh_token]
@session_opts [
store: :cookie,
key: "_test",
signing_salt: "cooldude"
]
+ clear_config_all([:instance, :account_activation_required])
describe "in OAuth consumer mode, " do
setup do
- oauth_consumer_strategies_path = [:auth, :oauth_consumer_strategies]
- oauth_consumer_strategies = Pleroma.Config.get(oauth_consumer_strategies_path)
- Pleroma.Config.put(oauth_consumer_strategies_path, ~w(twitter facebook))
-
- on_exit(fn ->
- Pleroma.Config.put(oauth_consumer_strategies_path, oauth_consumer_strategies)
- end)
-
[
app: insert(:oauth_app),
conn:
@@ -37,6 +29,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
]
end
+ clear_config([:auth, :oauth_consumer_strategies]) do
+ Pleroma.Config.put(
+ [:auth, :oauth_consumer_strategies],
+ ~w(twitter facebook)
+ )
+ end
+
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
app: app,
conn: conn
@@ -775,12 +774,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
+ Pleroma.Config.put([:instance, :account_activation_required], true)
password = "testpassword"
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
@@ -857,16 +851,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
describe "POST /oauth/token - refresh token" do
- setup do
- oauth_token_config = Pleroma.Config.get(@oauth_config_path)
-
- on_exit(fn ->
- Pleroma.Config.get(@oauth_config_path, oauth_token_config)
- end)
- end
+ clear_config([:oauth2, :issue_new_refresh_token])
test "issues a new access token with keep fresh token" do
- Pleroma.Config.put(@oauth_config_path, true)
+ Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
@@ -906,7 +894,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "issues a new access token with new fresh token" do
- Pleroma.Config.put(@oauth_config_path, false)
+ Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 9f756effb..095ae7041 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -15,16 +15,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
describe "salmon_incoming" do
test "decodes a salmon", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
new file mode 100644
index 000000000..ed6b79727
--- /dev/null
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -0,0 +1,94 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}")
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string()
+ end
+
+ test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ {:ok, activity_two} =
+ CommonAPI.post(other_user, %{
+ "status" => "Hi!",
+ "in_reply_to_status_id" => activity.id,
+ "in_reply_to_conversation_id" => participation.id
+ })
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
+ |> json_response(200)
+
+ assert length(result) == 2
+
+ id_one = activity.id
+ id_two = activity_two.id
+ assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
+ end
+
+ test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert [user] == participation.recipients
+ assert other_user not in participation.recipients
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
+ "recipients" => [user.id, other_user.id]
+ })
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string
+
+ [participation] = Participation.for_user(user)
+ participation = Repo.preload(participation, :recipients)
+
+ assert user in participation.recipients
+ assert other_user in participation.recipients
+ end
+end
diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs
index c01e01124..bb2e1687a 100644
--- a/test/web/plugs/federating_plug_test.exs
+++ b/test/web/plugs/federating_plug_test.exs
@@ -4,15 +4,7 @@
defmodule Pleroma.Web.FederatingPlugTest do
use Pleroma.Web.ConnCase
-
- setup_all do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
- end
+ clear_config_all([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
Pleroma.Config.put([:instance, :federating], false)
diff --git a/test/web/rich_media/aws_signed_url_test.exs b/test/web/rich_media/aws_signed_url_test.exs
index 122787bc2..a3a50cbb1 100644
--- a/test/web/rich_media/aws_signed_url_test.exs
+++ b/test/web/rich_media/aws_signed_url_test.exs
@@ -60,7 +60,8 @@ defmodule Pleroma.Web.RichMedia.TTL.AwsSignedUrlTest do
{:ok, cache_ttl} = Cachex.ttl(:rich_media_cache, url)
# as there is delay in setting and pulling the data from cache we ignore 1 second
- assert_in_delta(valid_till * 1000, cache_ttl, 1000)
+ # make it 2 seconds for flakyness
+ assert_in_delta(valid_till * 1000, cache_ttl, 2000)
end
defp construct_s3_url(timestamp, valid_till) do
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
index 92198f3d9..48884319d 100644
--- a/test/web/rich_media/helpers_test.exs
+++ b/test/web/rich_media/helpers_test.exs
@@ -15,12 +15,12 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- rich_media = Config.get([:rich_media, :enabled])
- on_exit(fn -> Config.put([:rich_media, :enabled], rich_media) end)
:ok
end
+ clear_config([:rich_media, :enabled])
+
test "refuses to crawl incomplete URLs" do
user = insert(:user)
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index d47b37efb..96fa7645f 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -11,15 +11,7 @@ defmodule Pleroma.Web.StreamerTest do
alias Pleroma.Web.Streamer
import Pleroma.Factory
- setup do
- skip_thread_containment = Pleroma.Config.get([:instance, :skip_thread_containment])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :skip_thread_containment], skip_thread_containment)
- end)
-
- :ok
- end
+ clear_config_all([:instance, :skip_thread_containment])
describe "user streams" do
setup do
@@ -414,6 +406,26 @@ defmodule Pleroma.Web.StreamerTest do
Task.await(task)
end
+ test "it doesn't send posts from muted threads" do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+
+ {:ok, activity} = CommonAPI.add_mute(user2, activity)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user2}}
+ )
+
+ Streamer.stream("user", activity)
+ Task.await(task)
+ end
+
describe "direct streams" do
setup do
GenServer.start(Streamer, %{}, name: Streamer)
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 9ac4ff929..598833893 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -152,6 +152,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /statuses/public_timeline.json" do
setup [:valid_user]
+ clear_config([:instance, :public])
test "returns statuses", %{conn: conn} do
user = insert(:user)
@@ -174,8 +175,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(403)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
@@ -186,8 +185,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
@@ -221,6 +218,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /statuses/public_and_external_timeline.json" do
setup [:valid_user]
+ clear_config([:instance, :public])
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
Pleroma.Config.put([:instance, :public], false)
@@ -228,8 +226,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(403)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
@@ -240,8 +236,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
@@ -1178,13 +1172,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/account/resend_confirmation_email" do
setup do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
-
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
@@ -1199,6 +1186,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
[user: user]
end
+ clear_config([:instance, :account_activation_required]) do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ end
+
test "it returns 204 No Content", %{conn: conn, user: user} do
conn
|> assign(:user, user)
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index e3f129f72..349122c05 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -16,20 +16,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
setup do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- instance_config = Pleroma.Config.get([:instance])
- pleroma_fe = Pleroma.Config.get([:frontend_configurations, :pleroma_fe])
- deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance], instance_config)
- Pleroma.Config.put([:frontend_configurations, :pleroma_fe], pleroma_fe)
- Pleroma.Config.put([:user, :deny_follow_blocked], deny_follow_blocked)
- end)
-
:ok
end
+ clear_config([:instance])
+ clear_config([:frontend_configurations, :pleroma_fe])
+ clear_config([:user, :deny_follow_blocked])
+
describe "POST /api/pleroma/follow_import" do
test "it returns HTTP 200", %{conn: conn} do
user1 = insert(:user)
@@ -262,7 +255,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
- option = Pleroma.Config.get([:instance, :safe_dm_mentions])
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
response =
@@ -280,8 +272,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|> json_response(:ok)
assert response["site"]["safeDMMentionsEnabled"] == "0"
-
- Pleroma.Config.put([:instance, :safe_dm_mentions], option)
end
test "it returns the managed config", %{conn: conn} do
@@ -536,15 +526,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
describe "GET /api/pleroma/healthcheck" do
- setup do
- config_healthcheck = Pleroma.Config.get([:instance, :healthcheck])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :healthcheck], config_healthcheck)
- end)
-
- :ok
- end
+ clear_config([:instance, :healthcheck])
test "returns 503 when healthcheck disabled", %{conn: conn} do
Pleroma.Config.put([:instance, :healthcheck], false)
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index 7d861cbf5..e23086b2a 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -10,15 +10,13 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
test "GET host-meta" do
response =
build_conn()
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index aa7262beb..59cacbe68 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -9,14 +9,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.WebsubClientSubscription
- setup_all do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
end
test "websub subscription request", %{conn: conn} do