aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/rel_me_anchor_nofollow.html14
-rw-r--r--test/fixtures/rel_me_null.html1
-rw-r--r--test/integration/mastodon_websocket_test.exs2
-rw-r--r--test/jobs_test.exs2
-rw-r--r--test/notification_test.exs6
-rw-r--r--test/object_test.exs2
-rw-r--r--test/support/builders/user_builder.ex2
-rw-r--r--test/support/captcha_mock.ex2
-rw-r--r--test/support/factory.ex35
-rw-r--r--test/support/web_push_http_client_mock.ex23
-rw-r--r--test/tasks/relay_test.exs4
-rw-r--r--test/upload_test.exs7
-rw-r--r--test/user_test.exs2
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs8
-rw-r--r--test/web/activity_pub/activity_pub_test.exs31
-rw-r--r--test/web/activity_pub/mrf/anti_followbot_policy_test.exs15
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs8
-rw-r--r--test/web/activity_pub/utils_test.exs115
-rw-r--r--test/web/activity_pub/views/object_view_test.exs2
-rw-r--r--test/web/activity_pub/visibilty_test.exs2
-rw-r--r--test/web/admin_api/admin_api_controller_test.exs94
-rw-r--r--test/web/common_api/common_api_test.exs4
-rw-r--r--test/web/common_api/common_api_utils_test.exs2
-rw-r--r--test/web/federator_test.exs2
-rw-r--r--test/web/instances/instance_test.exs2
-rw-r--r--test/web/instances/instances_test.exs3
-rw-r--r--test/web/mastodon_api/account_view_test.exs2
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs199
-rw-r--r--test/web/mastodon_api/push_subscription_view_test.exs23
-rw-r--r--test/web/mastodon_api/status_view_test.exs13
-rw-r--r--test/web/mastodon_api/subscription_controller_test.exs192
-rw-r--r--test/web/node_info_test.exs6
-rw-r--r--test/web/oauth/authorization_test.exs2
-rw-r--r--test/web/oauth/token_test.exs2
-rw-r--r--test/web/ostatus/activity_representer_test.exs4
-rw-r--r--test/web/ostatus/feed_representer_test.exs2
-rw-r--r--test/web/ostatus/incoming_documents/delete_handling_test.exs2
-rw-r--r--test/web/ostatus/ostatus_controller_test.exs4
-rw-r--r--test/web/ostatus/ostatus_test.exs8
-rw-r--r--test/web/push/impl_test.exs145
-rw-r--r--test/web/rel_me_test.exs12
-rw-r--r--test/web/rich_media/helpers_test.exs62
-rw-r--r--test/web/salmon/salmon_test.exs2
-rw-r--r--test/web/streamer_test.exs12
-rw-r--r--test/web/twitter_api/representers/activity_representer_test.exs14
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs49
-rw-r--r--test/web/twitter_api/twitter_api_test.exs7
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs10
-rw-r--r--test/web/twitter_api/views/notification_view_test.exs10
-rw-r--r--test/web/twitter_api/views/user_view_test.exs2
-rw-r--r--test/web/websub/websub_controller_test.exs2
-rw-r--r--test/web/websub/websub_test.exs6
52 files changed, 1040 insertions, 142 deletions
diff --git a/test/fixtures/rel_me_anchor_nofollow.html b/test/fixtures/rel_me_anchor_nofollow.html
new file mode 100644
index 000000000..c856f0091
--- /dev/null
+++ b/test/fixtures/rel_me_anchor_nofollow.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <title>Blog</title>
+ </head>
+ <body>
+ <article>
+ <h1>Lorem ipsum</h1>
+ <p>Lorem ipsum dolor sit ameph, …</p>
+ <a rel="me nofollow" href="https://social.example.org/users/lain">lain’s account</a>
+ </article>
+ </body>
+</html>
diff --git a/test/fixtures/rel_me_null.html b/test/fixtures/rel_me_null.html
index 57d424b80..5ab5f10c1 100644
--- a/test/fixtures/rel_me_null.html
+++ b/test/fixtures/rel_me_null.html
@@ -8,6 +8,7 @@
<article>
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit ameph, …</p>
+ <a rel="nofollow" href="https://social.example.org/users/lain">lain’s account</a>
</article>
</body>
</html>
diff --git a/test/integration/mastodon_websocket_test.exs b/test/integration/mastodon_websocket_test.exs
index 0c513b6e7..b42c9ef07 100644
--- a/test/integration/mastodon_websocket_test.exs
+++ b/test/integration/mastodon_websocket_test.exs
@@ -7,9 +7,9 @@ defmodule Pleroma.Integration.MastodonWebsocketTest do
import Pleroma.Factory
+ alias Pleroma.Integration.WebsocketClient
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth
- alias Pleroma.Integration.WebsocketClient
alias Pleroma.Web.Streamer
@path Pleroma.Web.Endpoint.url()
diff --git a/test/jobs_test.exs b/test/jobs_test.exs
index ccb518dec..d55c86ccc 100644
--- a/test/jobs_test.exs
+++ b/test/jobs_test.exs
@@ -5,8 +5,8 @@
defmodule Pleroma.JobsTest do
use ExUnit.Case, async: true
- alias Pleroma.Jobs
alias Jobs.WorkerMock
+ alias Pleroma.Jobs
setup do
state = %{
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 755874a3d..12b4292aa 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -4,11 +4,11 @@
defmodule Pleroma.NotificationTest do
use Pleroma.DataCase
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.CommonAPI
- alias Pleroma.User
alias Pleroma.Notification
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
import Pleroma.Factory
describe "create_notifications" do
diff --git a/test/object_test.exs b/test/object_test.exs
index a820a34ee..911757d57 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -5,8 +5,8 @@
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.Repo
alias Pleroma.Object
+ alias Pleroma.Repo
test "returns an object by it's AP id" do
object = insert(:note)
diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex
index 611a5be18..f58e1b0ad 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -1,6 +1,6 @@
defmodule Pleroma.Builders.UserBuilder do
- alias Pleroma.User
alias Pleroma.Repo
+ alias Pleroma.User
def build(data \\ %{}) do
user = %User{
diff --git a/test/support/captcha_mock.ex b/test/support/captcha_mock.ex
index 9061f2b45..ef4e68bc5 100644
--- a/test/support/captcha_mock.ex
+++ b/test/support/captcha_mock.ex
@@ -7,7 +7,7 @@ defmodule Pleroma.Captcha.Mock do
@behaviour Service
@impl Service
- def new(), do: %{type: :mock}
+ def new, do: %{type: :mock}
@impl Service
def validate(_token, _captcha, _data), do: :ok
diff --git a/test/support/factory.ex b/test/support/factory.ex
index d1956d1cd..18f77f01a 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -23,7 +23,7 @@ defmodule Pleroma.Factory do
}
end
- def note_factory do
+ def note_factory(attrs \\ %{}) do
text = sequence(:text, &"This is :moominmamma: note #{&1}")
user = insert(:user)
@@ -46,7 +46,7 @@ defmodule Pleroma.Factory do
}
%Pleroma.Object{
- data: data
+ data: merge_attributes(data, Map.get(attrs, :data, %{}))
}
end
@@ -95,8 +95,8 @@ defmodule Pleroma.Factory do
}
end
- def note_activity_factory do
- note = insert(:note)
+ def note_activity_factory(attrs \\ %{}) do
+ note = attrs[:note] || insert(:note)
data = %{
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
@@ -135,9 +135,9 @@ defmodule Pleroma.Factory do
}
end
- def announce_activity_factory do
- note_activity = insert(:note_activity)
- user = insert(:user)
+ def announce_activity_factory(attrs \\ %{}) do
+ note_activity = attrs[:note_activity] || insert(:note_activity)
+ user = attrs[:user] || insert(:user)
data = %{
"type" => "Announce",
@@ -229,15 +229,32 @@ defmodule Pleroma.Factory do
end
def oauth_token_factory do
- user = insert(:user)
oauth_app = insert(:oauth_app)
%Pleroma.Web.OAuth.Token{
token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
refresh_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64(),
- user_id: user.id,
+ user: build(:user),
app_id: oauth_app.id,
valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
}
end
+
+ def push_subscription_factory do
+ %Pleroma.Web.Push.Subscription{
+ user: build(:user),
+ token: build(:oauth_token),
+ endpoint: "https://example.com/example/1234",
+ key_auth: "8eDyX_uCN0XRhSbY5hs7Hg==",
+ key_p256dh:
+ "BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA=",
+ data: %{}
+ }
+ end
+
+ def notification_factory do
+ %Pleroma.Notification{
+ user: build(:user)
+ }
+ end
end
diff --git a/test/support/web_push_http_client_mock.ex b/test/support/web_push_http_client_mock.ex
new file mode 100644
index 000000000..d8accd21c
--- /dev/null
+++ b/test/support/web_push_http_client_mock.ex
@@ -0,0 +1,23 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.WebPushHttpClientMock do
+ def get(url, headers \\ [], options \\ []) do
+ {
+ res,
+ %Tesla.Env{status: status}
+ } = Pleroma.HTTP.request(:get, url, "", headers, options)
+
+ {res, %{status_code: status}}
+ end
+
+ def post(url, body, headers \\ [], options \\ []) do
+ {
+ res,
+ %Tesla.Env{status: status}
+ } = Pleroma.HTTP.request(:post, url, body, headers, options)
+
+ {res, %{status_code: status}}
+ end
+end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 64ff07753..c9d90fa2e 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -4,10 +4,10 @@
defmodule Mix.Tasks.Pleroma.RelayTest do
alias Pleroma.Activity
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Relay
- alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.Utils
use Pleroma.DataCase
setup_all do
diff --git a/test/upload_test.exs b/test/upload_test.exs
index b2d9eca38..bdda01b3f 100644
--- a/test/upload_test.exs
+++ b/test/upload_test.exs
@@ -153,19 +153,20 @@ defmodule Pleroma.UploadTest do
assert Path.basename(attachment_url["href"]) == "an%E2%80%A6%20image.jpg"
end
- test "replaces : (colon) and ? (question-mark) to %3A and %3F (respectively)" do
+ test "escapes reserved uri characters" do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
file = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image_tmp.jpg"),
- filename: "is:an?image.jpg"
+ filename: ":?#[]@!$&\\'()*+,;=.jpg"
}
{:ok, data} = Upload.store(file)
[attachment_url | _] = data["url"]
- assert Path.basename(attachment_url["href"]) == "is%3Aan%3Fimage.jpg"
+ assert Path.basename(attachment_url["href"]) ==
+ "%3A%3F%23%5B%5D%40%21%24%26%5C%27%28%29%2A%2B%2C%3B%3D.jpg"
end
end
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 3a5f3c240..c57eb2c06 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -3,8 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.UserTest do
- alias Pleroma.Builders.UserBuilder
alias Pleroma.Activity
+ alias Pleroma.Builders.UserBuilder
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 6bd4493f5..a1e83b380 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -5,13 +5,13 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.Web.ActivityPub.UserView
- alias Pleroma.Web.ActivityPub.ObjectView
+ alias Pleroma.Activity
+ alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.Repo
- alias Pleroma.Activity
alias Pleroma.User
- alias Pleroma.Instances
+ alias Pleroma.Web.ActivityPub.ObjectView
+ alias Pleroma.Web.ActivityPub.UserView
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f4029896c..2b83bfb1d 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -4,14 +4,14 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
use Pleroma.DataCase
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Web.ActivityPub.Utils
- alias Pleroma.Web.CommonAPI
alias Pleroma.Activity
+ alias Pleroma.Builders.ActivityBuilder
+ alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.User
- alias Pleroma.Instances
- alias Pleroma.Builders.ActivityBuilder
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.CommonAPI
import Pleroma.Factory
import Tesla.Mock
@@ -691,6 +691,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
user = Repo.get(User, user.id)
assert user.info.note_count == 10
end
+
+ test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do
+ user = insert(:user)
+ note = insert(:note_activity)
+
+ {:ok, object} =
+ Object.get_by_ap_id(note.data["object"]["id"])
+ |> Object.change(%{
+ data: %{
+ "actor" => note.data["object"]["actor"],
+ "id" => note.data["object"]["id"],
+ "to" => [user.ap_id],
+ "type" => "Note"
+ }
+ })
+ |> Object.update_and_set_cache()
+
+ {:ok, delete} = ActivityPub.delete(object)
+
+ assert user.ap_id in delete.data["to"]
+ end
end
describe "timeline post-processing" do
diff --git a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs
index 2ea4f9d3f..37a7bfcf7 100644
--- a/test/web/activity_pub/mrf/anti_followbot_policy_test.exs
+++ b/test/web/activity_pub/mrf/anti_followbot_policy_test.exs
@@ -54,4 +54,19 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do
{:ok, _} = AntiFollowbotPolicy.filter(message)
end
+
+ test "it gracefully handles nil display names" do
+ actor = insert(:user, %{name: nil})
+ target = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "type" => "Follow",
+ "actor" => actor.ap_id,
+ "object" => target.ap_id,
+ "id" => "https://example.com/activities/1234"
+ }
+
+ {:ok, _} = AntiFollowbotPolicy.filter(message)
+ end
end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 86c66deff..8184dbbae 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -4,13 +4,13 @@
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils
- alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
- alias Pleroma.Activity
- alias Pleroma.User
- alias Pleroma.Repo
alias Pleroma.Web.Websub.WebsubClientSubscription
import Pleroma.Factory
diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs
index aeed0564c..2bd3ddf93 100644
--- a/test/web/activity_pub/utils_test.exs
+++ b/test/web/activity_pub/utils_test.exs
@@ -1,6 +1,9 @@
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
describe "determine_explicit_mentions()" do
test "works with an object that has mentions" do
@@ -54,4 +57,116 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
assert Utils.determine_explicit_mentions(object) == []
end
end
+
+ describe "make_like_data" do
+ setup do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+ [user: user, other_user: other_user, third_user: third_user]
+ end
+
+ test "addresses actor's follower address if the activity is public", %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user
+ } do
+ expected_to = Enum.sort([user.ap_id, other_user.follower_address])
+ expected_cc = Enum.sort(["https://www.w3.org/ns/activitystreams#Public", third_user.ap_id])
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" =>
+ "hey @#{other_user.nickname}, @#{third_user.nickname} how about beering together this weekend?"
+ })
+
+ %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
+ assert Enum.sort(to) == expected_to
+ assert Enum.sort(cc) == expected_cc
+ end
+
+ test "does not adress actor's follower address if the activity is not public", %{
+ user: user,
+ other_user: other_user,
+ third_user: third_user
+ } do
+ expected_to = Enum.sort([user.ap_id])
+ expected_cc = [third_user.ap_id]
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "@#{other_user.nickname} @#{third_user.nickname} bought a new swimsuit!",
+ "visibility" => "private"
+ })
+
+ %{"to" => to, "cc" => cc} = Utils.make_like_data(other_user, activity, nil)
+ assert Enum.sort(to) == expected_to
+ assert Enum.sort(cc) == expected_cc
+ end
+ end
+
+ describe "fetch_ordered_collection" do
+ import Tesla.Mock
+
+ test "fetches the first OrderedCollectionPage when an OrderedCollection is encountered" do
+ mock(fn
+ %{method: :get, url: "http://mastodon.com/outbox"} ->
+ json(%{"type" => "OrderedCollection", "first" => "http://mastodon.com/outbox?page=true"})
+
+ %{method: :get, url: "http://mastodon.com/outbox?page=true"} ->
+ json(%{"type" => "OrderedCollectionPage", "orderedItems" => ["ok"]})
+ end)
+
+ assert Utils.fetch_ordered_collection("http://mastodon.com/outbox", 1) == ["ok"]
+ end
+
+ test "fetches several pages in the right order one after another, but only the specified amount" do
+ mock(fn
+ %{method: :get, url: "http://example.com/outbox"} ->
+ json(%{
+ "type" => "OrderedCollectionPage",
+ "orderedItems" => [0],
+ "next" => "http://example.com/outbox?page=1"
+ })
+
+ %{method: :get, url: "http://example.com/outbox?page=1"} ->
+ json(%{
+ "type" => "OrderedCollectionPage",
+ "orderedItems" => [1],
+ "next" => "http://example.com/outbox?page=2"
+ })
+
+ %{method: :get, url: "http://example.com/outbox?page=2"} ->
+ json(%{"type" => "OrderedCollectionPage", "orderedItems" => [2]})
+ end)
+
+ assert Utils.fetch_ordered_collection("http://example.com/outbox", 0) == [0]
+ assert Utils.fetch_ordered_collection("http://example.com/outbox", 1) == [0, 1]
+ end
+
+ test "returns an error if the url doesn't have an OrderedCollection/Page" do
+ mock(fn
+ %{method: :get, url: "http://example.com/not-an-outbox"} ->
+ json(%{"type" => "NotAnOutbox"})
+ end)
+
+ assert {:error, _} = Utils.fetch_ordered_collection("http://example.com/not-an-outbox", 1)
+ end
+
+ test "returns the what was collected if there are less pages than specified" do
+ mock(fn
+ %{method: :get, url: "http://example.com/outbox"} ->
+ json(%{
+ "type" => "OrderedCollectionPage",
+ "orderedItems" => [0],
+ "next" => "http://example.com/outbox?page=1"
+ })
+
+ %{method: :get, url: "http://example.com/outbox?page=1"} ->
+ json(%{"type" => "OrderedCollectionPage", "orderedItems" => [1]})
+ end)
+
+ assert Utils.fetch_ordered_collection("http://example.com/outbox", 5) == [0, 1]
+ end
+ end
end
diff --git a/test/web/activity_pub/views/object_view_test.exs b/test/web/activity_pub/views/object_view_test.exs
index d144a77fc..d939fc5a7 100644
--- a/test/web/activity_pub/views/object_view_test.exs
+++ b/test/web/activity_pub/views/object_view_test.exs
@@ -2,8 +2,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.ObjectView
+ alias Pleroma.Web.CommonAPI
test "renders a note object" do
note = insert(:note)
diff --git a/test/web/activity_pub/visibilty_test.exs b/test/web/activity_pub/visibilty_test.exs
index 1172b7455..24b96c4aa 100644
--- a/test/web/activity_pub/visibilty_test.exs
+++ b/test/web/activity_pub/visibilty_test.exs
@@ -1,8 +1,8 @@
defmodule Pleroma.Web.ActivityPub.VisibilityTest do
use Pleroma.DataCase
- alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.Visibility
+ alias Pleroma.Web.CommonAPI
import Pleroma.Factory
setup do
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 42e0daf8e..0470a439b 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -348,12 +348,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{
"deactivated" => admin.info.deactivated,
"id" => admin.id,
- "nickname" => admin.nickname
+ "nickname" => admin.nickname,
+ "roles" => %{"admin" => true, "moderator" => false}
},
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
- "nickname" => user.nickname
+ "nickname" => user.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
}
]
}
@@ -374,26 +376,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"users" => []
}
end
- end
-
- test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
- admin = insert(:user, info: %{is_admin: true})
- user = insert(:user)
- conn =
- build_conn()
- |> assign(:user, admin)
- |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
-
- assert json_response(conn, 200) ==
- %{
- "deactivated" => !user.info.deactivated,
- "id" => user.id,
- "nickname" => user.nickname
- }
- end
-
- describe "GET /api/pleroma/admin/users/search" do
test "regular search" do
admin = insert(:user, info: %{is_admin: true})
user = insert(:user, nickname: "bob")
@@ -401,7 +384,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo")
+ |> get("/api/pleroma/admin/users?query=bo")
assert json_response(conn, 200) == %{
"count" => 1,
@@ -410,7 +393,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
- "nickname" => user.nickname
+ "nickname" => user.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
}
]
}
@@ -424,7 +408,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo&page_size=1&page=1")
+ |> get("/api/pleroma/admin/users?query=bo&page_size=1&page=1")
assert json_response(conn, 200) == %{
"count" => 2,
@@ -433,7 +417,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
- "nickname" => user.nickname
+ "nickname" => user.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
}
]
}
@@ -441,7 +426,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo&page_size=1&page=2")
+ |> get("/api/pleroma/admin/users?query=bo&page_size=1&page=2")
assert json_response(conn, 200) == %{
"count" => 2,
@@ -450,7 +435,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{
"deactivated" => user2.info.deactivated,
"id" => user2.id,
- "nickname" => user2.nickname
+ "nickname" => user2.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
}
]
}
@@ -465,7 +451,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
conn =
build_conn()
|> assign(:user, admin)
- |> get("/api/pleroma/admin/users/search?query=bo&local=true")
+ |> get("/api/pleroma/admin/users?query=bo&local_only=true")
assert json_response(conn, 200) == %{
"count" => 1,
@@ -474,10 +460,60 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
%{
"deactivated" => user.info.deactivated,
"id" => user.id,
- "nickname" => user.nickname
+ "nickname" => user.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
+ }
+ ]
+ }
+ end
+
+ test "only local users with no query" do
+ admin = insert(:user, info: %{is_admin: true}, nickname: "john")
+ user = insert(:user, nickname: "bob")
+
+ insert(:user, nickname: "bobb", local: false)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/users?local_only=true")
+
+ assert json_response(conn, 200) == %{
+ "count" => 2,
+ "page_size" => 50,
+ "users" => [
+ %{
+ "deactivated" => admin.info.deactivated,
+ "id" => admin.id,
+ "nickname" => admin.nickname,
+ "roles" => %{"admin" => true, "moderator" => false}
+ },
+ %{
+ "deactivated" => user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
}
]
}
end
end
+
+ test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation" do
+ admin = insert(:user, info: %{is_admin: true})
+ user = insert(:user)
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> patch("/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
+
+ assert json_response(conn, 200) ==
+ %{
+ "deactivated" => !user.info.deactivated,
+ "id" => user.id,
+ "nickname" => user.nickname,
+ "roles" => %{"admin" => false, "moderator" => false}
+ }
+ end
end
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 9ba320f59..181813c76 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -4,9 +4,9 @@
defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
- alias Pleroma.Web.CommonAPI
- alias Pleroma.User
alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
import Pleroma.Factory
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 684f2a23f..4c97b0d62 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -3,9 +3,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.UtilsTest do
+ alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
- alias Pleroma.Builders.UserBuilder
use Pleroma.DataCase
test "it adds attachment links to a given text and attachment set" do
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 08279f230..52729eb50 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -3,9 +3,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
+ alias Pleroma.Instances
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
- alias Pleroma.Instances
use Pleroma.DataCase
import Pleroma.Factory
import Mock
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
index a158c0a42..d28730994 100644
--- a/test/web/instances/instance_test.exs
+++ b/test/web/instances/instance_test.exs
@@ -3,8 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Instances.InstanceTest do
- alias Pleroma.Repo
alias Pleroma.Instances.Instance
+ alias Pleroma.Repo
use Pleroma.DataCase
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index 2530c09fe..f0d84edea 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -102,7 +102,8 @@ defmodule Pleroma.InstancesTest do
end
end
- # Note: implementation-specific (e.g. Instance) details of set_unreachable/1 should be tested in implementation-specific tests
+ # Note: implementation-specific (e.g. Instance) details of set_unreachable/1
+ # should be tested in implementation-specific tests
describe "set_unreachable/1" do
test "returns error status on non-binary input" do
assert {:error, _} = Instances.set_unreachable(nil)
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index 6be66ef63..c2ffc21da 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -5,8 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.User
+ alias Pleroma.Web.MastodonAPI.AccountView
test "Represent a user account" do
source_data = %{
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index f7f10662a..059d5237d 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -5,17 +5,17 @@
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Repo
- alias Pleroma.User
- alias Pleroma.Object
+ alias Ecto.Changeset
alias Pleroma.Activity
alias Pleroma.Notification
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.CommonAPI
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.FilterView
- alias Ecto.Changeset
+ alias Pleroma.Web.OStatus
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
import Pleroma.Factory
import ExUnit.CaptureLog
import Tesla.Mock
@@ -248,6 +248,33 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert status["url"] != direct.data["id"]
end
+ test "doesn't include DMs from blocked users", %{conn: conn} do
+ blocker = insert(:user)
+ blocked = insert(:user)
+ user = insert(:user)
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ {:ok, _blocked_direct} =
+ CommonAPI.post(blocked, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, direct} =
+ CommonAPI.post(user, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("api/v1/timelines/direct")
+
+ [status] = json_response(res_conn, 200)
+ assert status["id"] == direct.id
+ end
+
test "replying to a status", %{conn: conn} do
user = insert(:user)
@@ -344,6 +371,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert Repo.get(Activity, activity.id) == activity
end
+
+ test "when you're an admin or moderator", %{conn: conn} do
+ activity1 = insert(:note_activity)
+ activity2 = insert(:note_activity)
+ admin = insert(:user, info: %{is_admin: true})
+ moderator = insert(:user, info: %{is_moderator: true})
+
+ res_conn =
+ conn
+ |> assign(:user, admin)
+ |> delete("/api/v1/statuses/#{activity1.id}")
+
+ assert %{} = json_response(res_conn, 200)
+
+ res_conn =
+ conn
+ |> assign(:user, moderator)
+ |> delete("/api/v1/statuses/#{activity2.id}")
+
+ assert %{} = json_response(res_conn, 200)
+
+ refute Repo.get(Activity, activity1.id)
+ refute Repo.get(Activity, activity2.id)
+ end
end
describe "filters" do
@@ -1013,6 +1064,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"error" => "Can't find user"} = json_response(conn, 404)
end
+ test "account fetching also works nickname", %{conn: conn} do
+ user = insert(:user)
+
+ conn =
+ conn
+ |> get("/api/v1/accounts/#{user.nickname}")
+
+ assert %{"id" => id} = json_response(conn, 200)
+ assert id == user.id
+ end
+
test "media upload", %{conn: conn} do
file = %Plug.Upload{
content_type: "image/jpg",
@@ -1133,6 +1195,47 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
refute [] == json_response(conn, 200)
end
+ test "getting followers, pagination", %{conn: conn} do
+ user = insert(:user)
+ follower1 = insert(:user)
+ follower2 = insert(:user)
+ follower3 = insert(:user)
+ {:ok, _} = User.follow(follower1, user)
+ {:ok, _} = User.follow(follower2, user)
+ {:ok, _} = User.follow(follower3, user)
+
+ conn =
+ conn
+ |> assign(:user, user)
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?since_id=#{follower1.id}")
+
+ assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
+ assert id3 == follower3.id
+ assert id2 == follower2.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3.id}")
+
+ assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
+ assert id2 == follower2.id
+ assert id1 == follower1.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3.id}")
+
+ assert [%{"id" => id2}] = json_response(res_conn, 200)
+ assert id2 == follower2.id
+
+ assert [link_header] = get_resp_header(res_conn, "link")
+ assert link_header =~ ~r/since_id=#{follower2.id}/
+ assert link_header =~ ~r/max_id=#{follower2.id}/
+ end
+
test "getting following", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1171,6 +1274,47 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
refute [] == json_response(conn, 200)
end
+ test "getting following, pagination", %{conn: conn} do
+ user = insert(:user)
+ following1 = insert(:user)
+ following2 = insert(:user)
+ following3 = insert(:user)
+ {:ok, _} = User.follow(user, following1)
+ {:ok, _} = User.follow(user, following2)
+ {:ok, _} = User.follow(user, following3)
+
+ conn =
+ conn
+ |> assign(:user, user)
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
+
+ assert [%{"id" => id3}, %{"id" => id2}] = json_response(res_conn, 200)
+ assert id3 == following3.id
+ assert id2 == following2.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following?max_id=#{following3.id}")
+
+ assert [%{"id" => id2}, %{"id" => id1}] = json_response(res_conn, 200)
+ assert id2 == following2.id
+ assert id1 == following1.id
+
+ res_conn =
+ conn
+ |> get("/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
+
+ assert [%{"id" => id2}] = json_response(res_conn, 200)
+ assert id2 == following2.id
+
+ assert [link_header] = get_resp_header(res_conn, "link")
+ assert link_header =~ ~r/since_id=#{following2.id}/
+ assert link_header =~ ~r/max_id=#{following2.id}/
+ end
+
test "following / unfollowing a user", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -1488,9 +1632,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert user = json_response(conn, 200)
assert user["note"] ==
- "I drink <a class=\"hashtag\" data-tag=\"cofe\" href=\"http://localhost:4001/tag/cofe\">#cofe</a> with <span class=\"h-card\"><a data-user=\"#{
- user2.id
- }\" class=\"u-url mention\" href=\"#{user2.ap_id}\">@<span>#{user2.nickname}</span></a></span>"
+ ~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a data-user=") <>
+ user2.id <>
+ ~s(" class="u-url mention" href=") <>
+ user2.ap_id <> ~s(">@<span>) <> user2.nickname <> ~s(</span></a></span>)
end
test "updates the user's locking status", %{conn: conn} do
@@ -1899,7 +2044,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(200)
end
- test "accound_id is required", %{
+ test "account_id is required", %{
conn: conn,
reporter: reporter,
activity: activity
@@ -1928,4 +2073,36 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(400)
end
end
+
+ describe "link headers" do
+ test "preserves parameters in link headers", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity1} =
+ CommonAPI.post(other_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "public"
+ })
+
+ {:ok, activity2} =
+ CommonAPI.post(other_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "public"
+ })
+
+ notification1 = Repo.get_by(Notification, activity_id: activity1.id)
+ notification2 = Repo.get_by(Notification, activity_id: activity2.id)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications", %{media_only: true})
+
+ assert [link_header] = get_resp_header(conn, "link")
+ assert link_header =~ ~r/media_only=true/
+ assert link_header =~ ~r/since_id=#{notification2.id}/
+ assert link_header =~ ~r/max_id=#{notification1.id}/
+ end
+ end
end
diff --git a/test/web/mastodon_api/push_subscription_view_test.exs b/test/web/mastodon_api/push_subscription_view_test.exs
new file mode 100644
index 000000000..dc935fc82
--- /dev/null
+++ b/test/web/mastodon_api/push_subscription_view_test.exs
@@ -0,0 +1,23 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+ alias Pleroma.Web.MastodonAPI.PushSubscriptionView, as: View
+ alias Pleroma.Web.Push
+
+ test "Represent a subscription" do
+ subscription = insert(:push_subscription, data: %{"alerts" => %{"mention" => true}})
+
+ expected = %{
+ alerts: %{"mention" => true},
+ endpoint: subscription.endpoint,
+ id: to_string(subscription.id),
+ server_key: Keyword.get(Push.vapid_config(), :public_key)
+ }
+
+ assert expected == View.render("push_subscription.json", %{subscription: subscription})
+ end
+end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 351dbf673..3eec2cb5b 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -5,13 +5,13 @@
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
- alias Pleroma.User
alias Pleroma.Web.OStatus
- alias Pleroma.Web.CommonAPI
- alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Activity
import Pleroma.Factory
import Tesla.Mock
@@ -120,7 +120,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
static_url: "corndog.png",
visible_in_picker: false
}
- ]
+ ],
+ pleroma: %{
+ local: true
+ }
}
assert status == expected
diff --git a/test/web/mastodon_api/subscription_controller_test.exs b/test/web/mastodon_api/subscription_controller_test.exs
new file mode 100644
index 000000000..7dfb02f63
--- /dev/null
+++ b/test/web/mastodon_api/subscription_controller_test.exs
@@ -0,0 +1,192 @@
+# 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.SubscriptionControllerTest do
+ use Pleroma.Web.ConnCase
+
+ import Pleroma.Factory
+ alias Pleroma.Web.Push
+ alias Pleroma.Web.Push.Subscription
+
+ @sub %{
+ "endpoint" => "https://example.com/example/1234",
+ "keys" => %{
+ "auth" => "8eDyX_uCN0XRhSbY5hs7Hg==",
+ "p256dh" =>
+ "BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA="
+ }
+ }
+ @server_key Keyword.get(Push.vapid_config(), :public_key)
+
+ setup do
+ user = insert(:user)
+ token = insert(:oauth_token, user: user, scopes: ["push"])
+
+ conn =
+ build_conn()
+ |> assign(:user, user)
+ |> assign(:token, token)
+
+ %{conn: conn, user: user, token: token}
+ end
+
+ defmacro assert_error_when_disable_push(do: yield) do
+ quote do
+ vapid_details = Application.get_env(:web_push_encryption, :vapid_details, [])
+ Application.put_env(:web_push_encryption, :vapid_details, [])
+ assert "Something went wrong" == unquote(yield)
+ Application.put_env(:web_push_encryption, :vapid_details, vapid_details)
+ end
+ end
+
+ describe "creates push subscription" do
+ test "returns error when push disabled ", %{conn: conn} do
+ assert_error_when_disable_push do
+ conn
+ |> post("/api/v1/push/subscription", %{})
+ |> json_response(500)
+ end
+ end
+
+ test "successful creation", %{conn: conn} do
+ result =
+ conn
+ |> post("/api/v1/push/subscription", %{
+ "data" => %{"alerts" => %{"mention" => true, "test" => true}},
+ "subscription" => @sub
+ })
+ |> json_response(200)
+
+ [subscription] = Pleroma.Repo.all(Subscription)
+
+ assert %{
+ "alerts" => %{"mention" => true},
+ "endpoint" => subscription.endpoint,
+ "id" => to_string(subscription.id),
+ "server_key" => @server_key
+ } == result
+ end
+ end
+
+ describe "gets a user subscription" do
+ test "returns error when push disabled ", %{conn: conn} do
+ assert_error_when_disable_push do
+ conn
+ |> get("/api/v1/push/subscription", %{})
+ |> json_response(500)
+ end
+ end
+
+ test "returns error when user hasn't subscription", %{conn: conn} do
+ res =
+ conn
+ |> get("/api/v1/push/subscription", %{})
+ |> json_response(404)
+
+ assert "Not found" == res
+ end
+
+ test "returns a user subsciption", %{conn: conn, user: user, token: token} do
+ subscription =
+ insert(:push_subscription,
+ user: user,
+ token: token,
+ data: %{"alerts" => %{"mention" => true}}
+ )
+
+ res =
+ conn
+ |> get("/api/v1/push/subscription", %{})
+ |> json_response(200)
+
+ expect = %{
+ "alerts" => %{"mention" => true},
+ "endpoint" => "https://example.com/example/1234",
+ "id" => to_string(subscription.id),
+ "server_key" => @server_key
+ }
+
+ assert expect == res
+ end
+ end
+
+ describe "updates a user subsciption" do
+ setup %{conn: conn, user: user, token: token} do
+ subscription =
+ insert(:push_subscription,
+ user: user,
+ token: token,
+ data: %{"alerts" => %{"mention" => true}}
+ )
+
+ %{conn: conn, user: user, token: token, subscription: subscription}
+ end
+
+ test "returns error when push disabled ", %{conn: conn} do
+ assert_error_when_disable_push do
+ conn
+ |> put("/api/v1/push/subscription", %{data: %{"alerts" => %{"mention" => false}}})
+ |> json_response(500)
+ end
+ end
+
+ test "returns updated subsciption", %{conn: conn, subscription: subscription} do
+ res =
+ conn
+ |> put("/api/v1/push/subscription", %{
+ data: %{"alerts" => %{"mention" => false, "follow" => true}}
+ })
+ |> json_response(200)
+
+ expect = %{
+ "alerts" => %{"follow" => true, "mention" => false},
+ "endpoint" => "https://example.com/example/1234",
+ "id" => to_string(subscription.id),
+ "server_key" => @server_key
+ }
+
+ assert expect == res
+ end
+ end
+
+ describe "deletes the user subscription" do
+ test "returns error when push disabled ", %{conn: conn} do
+ assert_error_when_disable_push do
+ conn
+ |> delete("/api/v1/push/subscription", %{})
+ |> json_response(500)
+ end
+ end
+
+ test "returns error when user hasn't subscription", %{conn: conn} do
+ res =
+ conn
+ |> delete("/api/v1/push/subscription", %{})
+ |> json_response(404)
+
+ assert "Not found" == res
+ end
+
+ test "returns empty result and delete user subsciption", %{
+ conn: conn,
+ user: user,
+ token: token
+ } do
+ subscription =
+ insert(:push_subscription,
+ user: user,
+ token: token,
+ data: %{"alerts" => %{"mention" => true}}
+ )
+
+ res =
+ conn
+ |> delete("/api/v1/push/subscription", %{})
+ |> json_response(200)
+
+ assert %{} == res
+ refute Pleroma.Repo.get(Subscription, subscription.id)
+ end
+ end
+end
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index 763549bd1..038feecc1 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -8,7 +8,8 @@ defmodule Pleroma.Web.NodeInfoTest do
import Pleroma.Factory
test "nodeinfo shows staff accounts", %{conn: conn} do
- user = insert(:user, %{local: true, info: %{is_moderator: true}})
+ moderator = insert(:user, %{local: true, info: %{is_moderator: true}})
+ admin = insert(:user, %{local: true, info: %{is_admin: true}})
conn =
conn
@@ -16,7 +17,8 @@ defmodule Pleroma.Web.NodeInfoTest do
assert result = json_response(conn, 200)
- assert user.ap_id in result["metadata"]["staffAccounts"]
+ assert moderator.ap_id in result["metadata"]["staffAccounts"]
+ assert admin.ap_id in result["metadata"]["staffAccounts"]
end
test "nodeinfo shows restricted nicknames", %{conn: conn} do
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 306db2e62..d8b008437 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -4,8 +4,8 @@
defmodule Pleroma.Web.OAuth.AuthorizationTest do
use Pleroma.DataCase
- alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.App
+ alias Pleroma.Web.OAuth.Authorization
import Pleroma.Factory
setup do
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index 62444a0fa..ad2a49f09 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -4,10 +4,10 @@
defmodule Pleroma.Web.OAuth.TokenTest do
use Pleroma.DataCase
+ alias Pleroma.Repo
alias Pleroma.Web.OAuth.App
alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Token
- alias Pleroma.Repo
import Pleroma.Factory
diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs
index eebc5c040..5cb135b4c 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -5,12 +5,12 @@
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase
- alias Pleroma.Web.OStatus.ActivityRepresenter
alias Pleroma.Activity
- alias Pleroma.User
alias Pleroma.Object
+ alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
+ alias Pleroma.Web.OStatus.ActivityRepresenter
import Pleroma.Factory
import Tesla.Mock
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index efd4e7217..3c7b126e7 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -6,10 +6,10 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.User
+ alias Pleroma.Web.OStatus
alias Pleroma.Web.OStatus.ActivityRepresenter
alias Pleroma.Web.OStatus.FeedRepresenter
alias Pleroma.Web.OStatus.UserRepresenter
- alias Pleroma.Web.OStatus
test "returns a feed of the last 20 items of the user" do
note_activity = insert(:note_activity)
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index d295cc539..412d894fd 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -4,9 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
import Pleroma.Factory
import Tesla.Mock
- alias Pleroma.Repo
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.Repo
alias Pleroma.Web.OStatus
setup do
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index da9c72be8..2950f11c0 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -5,9 +5,9 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.User
- alias Pleroma.Repo
alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index b4b19ab05..76b90e186 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -4,13 +4,13 @@
defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
- alias Pleroma.Web.OStatus
- alias Pleroma.Web.XML
+ alias Pleroma.Activity
+ alias Pleroma.Instances
alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
- alias Pleroma.Activity
- alias Pleroma.Instances
+ alias Pleroma.Web.OStatus
+ alias Pleroma.Web.XML
import Pleroma.Factory
import ExUnit.CaptureLog
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
new file mode 100644
index 000000000..3f9f3d809
--- /dev/null
+++ b/test/web/push/impl_test.exs
@@ -0,0 +1,145 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Push.ImplTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.Push.Impl
+ alias Pleroma.Web.Push.Subscription
+
+ import Pleroma.Factory
+
+ setup_all do
+ Tesla.Mock.mock_global(fn
+ %{method: :post, url: "https://example.com/example/1234"} ->
+ %Tesla.Env{status: 200}
+
+ %{method: :post, url: "https://example.com/example/not_found"} ->
+ %Tesla.Env{status: 400}
+
+ %{method: :post, url: "https://example.com/example/bad"} ->
+ %Tesla.Env{status: 100}
+ end)
+
+ :ok
+ end
+
+ @sub %{
+ endpoint: "https://example.com/example/1234",
+ keys: %{
+ auth: "8eDyX_uCN0XRhSbY5hs7Hg==",
+ p256dh:
+ "BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA="
+ }
+ }
+ @api_key "BASgACIHpN1GYgzSRp"
+ @message "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+
+ test "performs sending notifications" do
+ user = insert(:user)
+ user2 = insert(:user)
+ insert(:push_subscription, user: user, data: %{alerts: %{"mention" => true}})
+ insert(:push_subscription, user: user2, data: %{alerts: %{"mention" => true}})
+
+ insert(:push_subscription,
+ user: user,
+ data: %{alerts: %{"follow" => true, "mention" => true}}
+ )
+
+ insert(:push_subscription,
+ user: user,
+ data: %{alerts: %{"follow" => true, "mention" => false}}
+ )
+
+ notif =
+ insert(:notification,
+ user: user,
+ activity: %Pleroma.Activity{
+ data: %{
+ "type" => "Create",
+ "actor" => user.ap_id,
+ "object" => %{"content" => "<Lorem ipsum dolor sit amet."}
+ }
+ }
+ )
+
+ assert Impl.perform_send(notif) == [:ok, :ok]
+ end
+
+ test "returns error if notif does not match " do
+ assert Impl.perform_send(%{}) == :error
+ end
+
+ test "successful message sending" do
+ assert Impl.push_message(@message, @sub, @api_key, %Subscription{}) == :ok
+ end
+
+ test "fail message sending" do
+ assert Impl.push_message(
+ @message,
+ Map.merge(@sub, %{endpoint: "https://example.com/example/bad"}),
+ @api_key,
+ %Subscription{}
+ ) == :error
+ end
+
+ test "delete subsciption if restult send message between 400..500" do
+ subscription = insert(:push_subscription)
+
+ assert Impl.push_message(
+ @message,
+ Map.merge(@sub, %{endpoint: "https://example.com/example/not_found"}),
+ @api_key,
+ subscription
+ ) == :ok
+
+ refute Pleroma.Repo.get(Subscription, subscription.id)
+ end
+
+ test "renders body for create activity" do
+ assert Impl.format_body(
+ %{
+ activity: %{
+ data: %{
+ "type" => "Create",
+ "object" => %{
+ "content" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ }
+ }
+ }
+ },
+ %{nickname: "Bob"}
+ ) ==
+ "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+ end
+
+ test "renders body for follow activity" do
+ assert Impl.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
+ "@Bob has followed you"
+ end
+
+ test "renders body for announce activity" do
+ user = insert(:user)
+
+ note =
+ insert(:note, %{
+ data: %{
+ "content" =>
+ "<span>Lorem ipsum dolor sit amet</span>, consectetur :bear: adipiscing elit. Fusce sagittis finibus turpis."
+ }
+ })
+
+ note_activity = insert(:note_activity, %{note: note})
+ announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
+
+ assert Impl.format_body(%{activity: announce_activity}, user) ==
+ "@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
+ end
+
+ test "renders body for like activity" do
+ assert Impl.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
+ "@Bob has favorited your post"
+ end
+end
diff --git a/test/web/rel_me_test.exs b/test/web/rel_me_test.exs
index ba8038e69..5188f4de1 100644
--- a/test/web/rel_me_test.exs
+++ b/test/web/rel_me_test.exs
@@ -11,6 +11,12 @@ defmodule Pleroma.Web.RelMeTest do
%{
method: :get,
+ url: "http://example.com/rel_me/anchor_nofollow"
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}
+
+ %{
+ method: :get,
url: "http://example.com/rel_me/link"
} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
@@ -33,6 +39,7 @@ defmodule Pleroma.Web.RelMeTest do
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
+ assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor_nofollow") == {:ok, hrefs}
end
test "maybe_put_rel_me/2" do
@@ -49,6 +56,11 @@ defmodule Pleroma.Web.RelMeTest do
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
attr
+ assert Pleroma.Web.RelMe.maybe_put_rel_me(
+ "http://example.com/rel_me/anchor_nofollow",
+ profile_urls
+ ) == attr
+
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/link", profile_urls) ==
attr
end
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
new file mode 100644
index 000000000..60d93768f
--- /dev/null
+++ b/test/web/rich_media/helpers_test.exs
@@ -0,0 +1,62 @@
+defmodule Pleroma.Web.RichMedia.HelpersTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+ import Tesla.Mock
+
+ setup do
+ mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+ :ok
+ end
+
+ test "refuses to crawl incomplete URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](example.com/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+
+ test "refuses to crawl malformed URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](example.com[]/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{} == Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+
+ test "crawls valid, complete URLs" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "[test](http://example.com/ogp)",
+ "content_type" => "text/markdown"
+ })
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{page_url: "http://example.com/ogp", rich_media: _} =
+ Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
+end
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index 9e583ba40..265e1abbd 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -4,10 +4,10 @@
defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase
- alias Pleroma.Web.Salmon
alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.User
+ alias Pleroma.Web.Salmon
import Pleroma.Factory
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index 16d7b9c24..0a2e91298 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -5,10 +5,10 @@
defmodule Pleroma.Web.StreamerTest do
use Pleroma.DataCase
- alias Pleroma.Web.Streamer
alias Pleroma.List
alias Pleroma.User
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Streamer
import Pleroma.Factory
test "it sends to public" do
@@ -39,7 +39,15 @@ defmodule Pleroma.Web.StreamerTest do
task =
Task.async(fn ->
- assert_receive {:text, _}, 4_000
+ expected_event =
+ %{
+ "event" => "delete",
+ "payload" => activity.id
+ }
+ |> Jason.encode!()
+
+ assert_receive {:text, received_event}, 4_000
+ assert received_event == expected_event
end)
fake_socket = %{
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index 0e554623c..d154385a0 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -4,12 +4,12 @@
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use Pleroma.DataCase
- alias Pleroma.User
alias Pleroma.Activity
alias Pleroma.Object
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
- alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
@@ -101,10 +101,14 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
recipients: to
}
+ corndog_emojo = ~s(<img height="32px" width="32px" alt="2hu" title="2hu" src="corndog.png" />)
+
expected_html =
- "<p>2hu <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /></p>alert('YAY')Some <img height=\"32px\" width=\"32px\" alt=\"2hu\" title=\"2hu\" src=\"corndog.png\" /> content mentioning <a href=\"#{
- mentioned_user.ap_id
- }\">@shp</a>"
+ ~s(<p>2hu ) <>
+ corndog_emojo <>
+ ~s(</p>alert\('YAY'\)Some ) <>
+ corndog_emojo <>
+ ~s( content mentioning <a href=") <> mentioned_user.ap_id <> ~s(">@shp</a>)
expected_status = %{
"id" => activity.id,
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index d18b65876..1b810c9a0 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -4,23 +4,23 @@
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
+ alias Comeonin.Pbkdf2
+ alias Ecto.Changeset
+ alias Pleroma.Activity
alias Pleroma.Builders.ActivityBuilder
alias Pleroma.Builders.UserBuilder
+ alias Pleroma.Notification
+ alias Pleroma.Object
alias Pleroma.Repo
- alias Pleroma.Activity
alias Pleroma.User
- alias Pleroma.Object
- alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.TwitterAPI.Controller
- alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
- alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Comeonin.Pbkdf2
- alias Ecto.Changeset
+ alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
import Mock
@@ -415,6 +415,33 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert status["id"] == direct_two.id
assert status_two["id"] == direct.id
end
+
+ test "doesn't include DMs from blocked users", %{conn: conn} do
+ blocker = insert(:user)
+ blocked = insert(:user)
+ user = insert(:user)
+ {:ok, blocker} = User.block(blocker, blocked)
+
+ {:ok, _blocked_direct} =
+ CommonAPI.post(blocked, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ {:ok, direct} =
+ CommonAPI.post(user, %{
+ "status" => "Hi @#{blocker.nickname}!",
+ "visibility" => "direct"
+ })
+
+ res_conn =
+ conn
+ |> assign(:user, blocker)
+ |> get("/api/statuses/dm_timeline.json")
+
+ [status] = json_response(res_conn, 200)
+ assert status["id"] == direct.id
+ end
end
describe "GET /statuses/mentions.json" do
@@ -463,7 +490,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
response = json_response(conn, 200)
- assert length(response) == 0
+ assert Enum.empty?(response)
end
end
@@ -1762,8 +1789,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/pleroma/friendships/approve", %{"user_id" => other_user.id})
- user = Repo.get(User, user.id)
-
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == true
@@ -1787,8 +1812,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> assign(:user, user)
|> post("/api/pleroma/friendships/deny", %{"user_id" => other_user.id})
- user = Repo.get(User, user.id)
-
assert relationship = json_response(conn, 200)
assert other_user.id == relationship["id"]
assert relationship["follows_you"] == false
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index aa2a4d650..c8dd3fd7a 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -4,15 +4,15 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
- alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Activity
- alias Pleroma.User
alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
@@ -472,6 +472,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
# Also fetches the feed.
# assert Activity.get_create_by_object_ap_id("tag:mastodon.social,2017-04-05:objectId=1641750:objectType=Status")
+ # credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
end
end
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 0a5384f34..6f0786b1c 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -5,15 +5,15 @@
defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.TwitterAPI.ActivityView
- alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.Repo
- alias Pleroma.Activity
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
import Tesla.Mock
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
index 3a67f7292..6baeeaf63 100644
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -5,14 +5,14 @@
defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
use Pleroma.DataCase
- alias Pleroma.User
alias Pleroma.Notification
- alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.CommonAPI.Utils
+ alias Pleroma.Web.TwitterAPI.ActivityView
alias Pleroma.Web.TwitterAPI.NotificationView
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.UserView
- alias Pleroma.Web.TwitterAPI.ActivityView
- alias Pleroma.Web.CommonAPI.Utils
- alias Pleroma.Web.ActivityPub.ActivityPub
import Pleroma.Factory
diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs
index 114f24a1c..4e7f94795 100644
--- a/test/web/twitter_api/views/user_view_test.exs
+++ b/test/web/twitter_api/views/user_view_test.exs
@@ -6,8 +6,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do
use Pleroma.DataCase
alias Pleroma.User
- alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.CommonAPI.Utils
+ alias Pleroma.Web.TwitterAPI.UserView
import Pleroma.Factory
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 87b01d89b..1e69ed01a 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -5,10 +5,10 @@
defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.Activity
alias Pleroma.Repo
alias Pleroma.Web.Websub
+ alias Pleroma.Web.Websub.WebsubClientSubscription
test "websub subscription request", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 9a9b9df02..74386d7db 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -4,11 +4,13 @@
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
+
+ alias Pleroma.Web.Router.Helpers
alias Pleroma.Web.Websub
- alias Pleroma.Web.Websub.WebsubServerSubscription
alias Pleroma.Web.Websub.WebsubClientSubscription
+ alias Pleroma.Web.Websub.WebsubServerSubscription
+
import Pleroma.Factory
- alias Pleroma.Web.Router.Helpers
import Tesla.Mock
setup do