diff --git a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
index de2241ec9..32c458f0c 100644
--- a/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
+++ b/lib/pleroma/web/templates/o_auth/o_auth/show.html.eex
@@ -1,5 +1,9 @@
+<%= if get_flash(@conn, :info) do %>
<%= get_flash(@conn, :info) %>
+<% end %>
+<%= if get_flash(@conn, :error) do %>
<%= get_flash(@conn, :error) %>
+<% end %>
OAuth Authorization
<%= form_for @conn, o_auth_path(@conn, :authorize), [as: "authorization"], fn f -> %>
<%= label f, :name, "Name or email" %>
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index c2f0dc2a9..b815379fd 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -8,6 +8,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
alias Ecto.Changeset
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView, TokenView}
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.{Repo, Activity, Object, User, Notification}
+ alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
@@ -524,6 +528,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
def friends(%{assigns: %{user: for_user}} = conn, params) do
{:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1)
+ {:ok, export} = Ecto.Type.cast(:boolean, params["all"] || false)
+
+ page = if export, do: nil, else: page
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
{:ok, friends} <- User.get_friends(user, page) do
@@ -542,6 +549,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
end
+ def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do
+ with oauth_tokens <- Token.get_user_tokens(user) do
+ conn
+ |> put_view(TokenView)
+ |> render("index.json", %{tokens: oauth_tokens})
+ end
+ end
+
+ def revoke_token(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
+ Token.delete_user_token(user, id)
+
+ json_reply(conn, 201, "")
+ end
+
def blocks(%{assigns: %{user: user}} = conn, _params) do
with blocked_users <- User.blocked_users(user) do
conn
@@ -570,7 +591,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{:ok, _activity} <-
ActivityPub.accept(%{
to: [follower.ap_id],
- actor: followed.ap_id,
+ actor: followed,
object: follow_activity.data["id"],
type: "Accept"
}) do
@@ -590,7 +611,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{:ok, _activity} <-
ActivityPub.reject(%{
to: [follower.ap_id],
- actor: followed.ap_id,
+ actor: followed,
object: follow_activity.data["id"],
type: "Reject"
}) do
diff --git a/lib/pleroma/web/twitter_api/views/token_view.ex b/lib/pleroma/web/twitter_api/views/token_view.ex
new file mode 100644
index 000000000..3ff314913
--- /dev/null
+++ b/lib/pleroma/web/twitter_api/views/token_view.ex
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.TwitterAPI.TokenView do
+ use Pleroma.Web, :view
+
+ def render("index.json", %{tokens: tokens}) do
+ tokens
+ |> render_many(Pleroma.Web.TwitterAPI.TokenView, "show.json")
+ |> Enum.filter(&Enum.any?/1)
+ end
+
+ def render("show.json", %{token: token_entry}) do
+ %{
+ id: token_entry.id,
+ valid_until: token_entry.valid_until,
+ app_name: token_entry.app.client_name
+ }
+ end
+end
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index a09450df7..df7384476 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -113,10 +113,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"fields" => fields,
# Pleroma extension
- "pleroma" => %{
- "confirmation_pending" => user_info.confirmation_pending,
- "tags" => user.tags
- }
+ "pleroma" =>
+ %{
+ "confirmation_pending" => user_info.confirmation_pending,
+ "tags" => user.tags
+ }
+ |> maybe_with_follow_request_count(user, for_user)
}
data =
@@ -132,6 +134,14 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
end
end
+ defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{
+ id: id
+ }) do
+ Map.put(data, "follow_request_count", user.info.follow_request_count)
+ end
+
+ defp maybe_with_follow_request_count(data, _, _), do: data
+
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role})
end
diff --git a/lib/pleroma/web/websub/websub.ex b/lib/pleroma/web/websub/websub.ex
index a08d7993d..c00ec0858 100644
--- a/lib/pleroma/web/websub/websub.ex
+++ b/lib/pleroma/web/websub/websub.ex
@@ -13,6 +13,7 @@ defmodule Pleroma.Web.Websub do
alias Pleroma.Web.Endpoint
alias Pleroma.Web.OStatus
alias Pleroma.Web.Router.Helpers
+ alias Pleroma.Web.Federator
require Logger
import Ecto.Query
@@ -87,7 +88,7 @@ defmodule Pleroma.Web.Websub do
unreachable_since: reachable_callbacks_metadata[sub.callback]
}
- Pleroma.Web.Federator.enqueue(:publish_single_websub, data)
+ Federator.publish_single_websub(data)
end)
end
@@ -119,7 +120,7 @@ defmodule Pleroma.Web.Websub do
websub = Repo.update!(change)
- Pleroma.Web.Federator.enqueue(:verify_websub, websub)
+ Federator.verify_websub(websub)
{:ok, websub}
else
@@ -269,7 +270,7 @@ defmodule Pleroma.Web.Websub do
subs = Repo.all(query)
Enum.each(subs, fn sub ->
- Pleroma.Web.Federator.enqueue(:request_subscription, sub)
+ Federator.request_subscription(sub)
end)
end
diff --git a/lib/pleroma/web/websub/websub_controller.ex b/lib/pleroma/web/websub/websub_controller.ex
index 1ad18a8a4..ad40f1b94 100644
--- a/lib/pleroma/web/websub/websub_controller.ex
+++ b/lib/pleroma/web/websub/websub_controller.ex
@@ -84,7 +84,7 @@ defmodule Pleroma.Web.Websub.WebsubController do
%WebsubClientSubscription{} = websub <- Repo.get(WebsubClientSubscription, id),
{:ok, body, _conn} = read_body(conn),
^signature <- Websub.sign(websub.secret, body) do
- Federator.enqueue(:incoming_doc, body)
+ Federator.incoming_doc(body)
conn
|> send_resp(200, "OK")
diff --git a/mix.exs b/mix.exs
index d46998891..ee1c00bb9 100644
--- a/mix.exs
+++ b/mix.exs
@@ -21,7 +21,14 @@ defmodule Pleroma.Mixfile do
homepage_url: "https://pleroma.social/",
docs: [
logo: "priv/static/static/logo.png",
- extras: ["README.md", "docs/config.md", "docs/Pleroma-API.md", "docs/Admin-API.md"],
+ extras: [
+ "README.md",
+ "docs/config.md",
+ "docs/Pleroma-API.md",
+ "docs/Admin-API.md",
+ "docs/Clients.md",
+ "docs/Differences-in-MastodonAPI-Responses.md"
+ ],
main: "readme",
output: "priv/static/doc"
]
diff --git a/priv/static/schemas/litepub-0.1.jsonld b/priv/static/schemas/litepub-0.1.jsonld
index 15645646a..f36b231c5 100644
--- a/priv/static/schemas/litepub-0.1.jsonld
+++ b/priv/static/schemas/litepub-0.1.jsonld
@@ -19,7 +19,11 @@
"value": "schema:value",
"sensitive": "as:sensitive",
"litepub": "http://litepub.social/ns#",
- "directMessage": "litepub:directMessage"
+ "directMessage": "litepub:directMessage",
+ "oauthRegistrationEndpoint": {
+ "@id": "litepub:oauthRegistrationEndpoint",
+ "@type": "@id"
+ }
}
]
}
diff --git a/test/formatter_test.exs b/test/formatter_test.exs
index 2e717194b..f14077d25 100644
--- a/test/formatter_test.exs
+++ b/test/formatter_test.exs
@@ -197,7 +197,7 @@ defmodule Pleroma.FormatterTest do
{subs, text} = Formatter.add_user_links({[], text}, mentions)
- assert length(subs) == 0
+ assert Enum.empty?(subs)
Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end)
expected_text = "@a hi"
diff --git a/test/jobs_test.exs b/test/jobs_test.exs
new file mode 100644
index 000000000..ccb518dec
--- /dev/null
+++ b/test/jobs_test.exs
@@ -0,0 +1,83 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.JobsTest do
+ use ExUnit.Case, async: true
+
+ alias Pleroma.Jobs
+ alias Jobs.WorkerMock
+
+ setup do
+ state = %{
+ queues: Enum.into([Jobs.create_queue(:testing)], %{}),
+ refs: %{}
+ }
+
+ [state: state]
+ end
+
+ test "creates queue" do
+ queue = Jobs.create_queue(:foobar)
+
+ assert {:foobar, set} = queue
+ assert :set == elem(set, 0) |> elem(0)
+ end
+
+ test "enqueues an element according to priority" do
+ queue = [%{item: 1, priority: 2}]
+
+ new_queue = Jobs.enqueue_sorted(queue, 2, 1)
+ assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
+
+ new_queue = Jobs.enqueue_sorted(queue, 2, 3)
+ assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}]
+ end
+
+ test "pop first item" do
+ queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
+
+ assert {2, [%{item: 1, priority: 2}]} = Jobs.queue_pop(queue)
+ end
+
+ test "enqueue a job", %{state: state} do
+ assert {:noreply, new_state} =
+ Jobs.handle_cast({:enqueue, :testing, WorkerMock, [:test_job, :foo, :bar], 3}, state)
+
+ assert %{queues: %{testing: {running_jobs, []}}, refs: _} = new_state
+ assert :sets.size(running_jobs) == 1
+ assert [ref] = :sets.to_list(running_jobs)
+ assert %{refs: %{^ref => :testing}} = new_state
+ end
+
+ test "max jobs setting", %{state: state} do
+ max_jobs = Pleroma.Config.get([Jobs, :testing, :max_jobs])
+
+ {:noreply, state} =
+ Enum.reduce(1..(max_jobs + 1), {:noreply, state}, fn _, {:noreply, state} ->
+ Jobs.handle_cast({:enqueue, :testing, WorkerMock, [:test_job, :foo, :bar], 3}, state)
+ end)
+
+ assert %{
+ queues: %{
+ testing:
+ {running_jobs, [%{item: {WorkerMock, [:test_job, :foo, :bar]}, priority: 3}]}
+ }
+ } = state
+
+ assert :sets.size(running_jobs) == max_jobs
+ end
+
+ test "remove job after it finished", %{state: state} do
+ {:noreply, new_state} =
+ Jobs.handle_cast({:enqueue, :testing, WorkerMock, [:test_job, :foo, :bar], 3}, state)
+
+ %{queues: %{testing: {running_jobs, []}}} = new_state
+ [ref] = :sets.to_list(running_jobs)
+
+ assert {:noreply, %{queues: %{testing: {running_jobs, []}}, refs: %{}}} =
+ Jobs.handle_info({:DOWN, ref, :process, nil, nil}, new_state)
+
+ assert :sets.size(running_jobs) == 0
+ end
+end
diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs
index 05d927422..ddbadfbf5 100644
--- a/test/media_proxy_test.exs
+++ b/test/media_proxy_test.exs
@@ -140,6 +140,15 @@ defmodule Pleroma.MediaProxyTest do
assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url]))
end
+
+ # https://git.pleroma.social/pleroma/pleroma/issues/580
+ test "encoding S3 links (must preserve `%2F`)" do
+ url =
+ "https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request"
+
+ encoded = url(url)
+ assert decode_result(encoded) == url
+ end
end
describe "when disabled" do
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 94fb0ab15..755874a3d 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -6,7 +6,8 @@ defmodule Pleroma.NotificationTest do
use Pleroma.DataCase
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.CommonAPI
- alias Pleroma.{User, Notification}
+ alias Pleroma.User
+ alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.Transmogrifier
import Pleroma.Factory
@@ -299,7 +300,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
@@ -307,7 +308,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "liking an activity results in 1 notification, then 0 if the activity is unliked" do
@@ -316,7 +317,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
@@ -324,7 +325,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do
@@ -333,7 +334,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
@@ -341,7 +342,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do
@@ -350,7 +351,7 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
@@ -358,7 +359,7 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "liking an activity which is already deleted does not generate a notification" do
@@ -367,15 +368,15 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:error, _} = CommonAPI.favorite(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "repeating an activity which is already deleted does not generate a notification" do
@@ -384,15 +385,15 @@ defmodule Pleroma.NotificationTest do
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:ok, _deletion_activity} = CommonAPI.delete(activity.id, user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
{:error, _} = CommonAPI.repeat(activity.id, other_user)
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
test "replying to a deleted post without tagging does not generate a notification" do
@@ -408,7 +409,7 @@ defmodule Pleroma.NotificationTest do
"in_reply_to_status_id" => activity.id
})
- assert length(Notification.for_user(user)) == 0
+ assert Enum.empty?(Notification.for_user(user))
end
end
end
diff --git a/test/object_test.exs b/test/object_test.exs
index 72194975d..a820a34ee 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.ObjectTest do
use Pleroma.DataCase
import Pleroma.Factory
- alias Pleroma.{Repo, Object}
+ alias Pleroma.Repo
+ alias Pleroma.Object
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 7a1ca79b5..611a5be18 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -1,5 +1,6 @@
defmodule Pleroma.Builders.UserBuilder do
- alias Pleroma.{User, Repo}
+ alias Pleroma.User
+ alias Pleroma.Repo
def build(data \\ %{}) do
user = %User{
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 0c21093ce..7a91549f5 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -227,4 +227,17 @@ defmodule Pleroma.Factory do
unreachable_since: nil
}
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,
+ app_id: oauth_app.id,
+ valid_until: NaiveDateTime.add(NaiveDateTime.utc_now(), 60 * 10)
+ }
+ end
end
diff --git a/test/support/jobs_worker_mock.ex b/test/support/jobs_worker_mock.ex
new file mode 100644
index 000000000..0fb976d05
--- /dev/null
+++ b/test/support/jobs_worker_mock.ex
@@ -0,0 +1,19 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Jobs.WorkerMock do
+ require Logger
+
+ def perform(:test_job, arg, arg2) do
+ Logger.debug({:perform, :test_job, arg, arg2})
+ end
+
+ def perform(:test_job, payload) do
+ Logger.debug({:perform, :test_job, payload})
+ end
+
+ def test_job(payload) do
+ Pleroma.Jobs.enqueue(:testing, __MODULE__, [:test_job, payload])
+ end
+end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index 96fac4811..64ff07753 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -4,7 +4,9 @@
defmodule Mix.Tasks.Pleroma.RelayTest do
alias Pleroma.Activity
- alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils}
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Utils
+ alias Pleroma.Web.ActivityPub.Relay
alias Pleroma.User
use Pleroma.DataCase
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 44271898c..7b814d171 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -151,7 +151,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do
assert message =~ "Successfully unsubscribed"
user = User.get_by_nickname(user.nickname)
- assert length(user.following) == 0
+ assert Enum.empty?(user.following)
assert user.info.deactivated
end
diff --git a/test/user_test.exs b/test/user_test.exs
index 523ab1ea4..92991d063 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -4,7 +4,9 @@
defmodule Pleroma.UserTest do
alias Pleroma.Builders.UserBuilder
- alias Pleroma.{User, Repo, Activity}
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
use Pleroma.DataCase
@@ -55,18 +57,21 @@ defmodule Pleroma.UserTest do
followed_two = insert(:user)
blocked = insert(:user)
not_followed = insert(:user)
+ reverse_blocked = insert(:user)
{:ok, user} = User.block(user, blocked)
+ {:ok, reverse_blocked} = User.block(reverse_blocked, user)
{:ok, user} = User.follow(user, followed_zero)
- {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked])
+ {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
assert User.following?(user, followed_one)
assert User.following?(user, followed_two)
assert User.following?(user, followed_zero)
refute User.following?(user, not_followed)
refute User.following?(user, blocked)
+ refute User.following?(user, reverse_blocked)
end
test "follow_all follows mutliple users without duplicating" do
@@ -191,6 +196,26 @@ 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
+ welcome_user = insert(:user)
+
+ Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
+ Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
+
+ cng = User.register_changeset(%User{}, @full_user_data)
+ {:ok, registered_user} = User.register(cng)
+
+ activity = Repo.one(Pleroma.Activity)
+ assert registered_user.ap_id in activity.recipients
+ assert activity.data["object"]["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
@@ -873,6 +898,16 @@ defmodule Pleroma.UserTest do
assert [] == User.search(query)
end)
end
+
+ test "works with URIs" do
+ results = User.search("http://mastodon.example.org/users/admin", true)
+ result = results |> List.first()
+
+ user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
+
+ assert length(results) == 1
+ assert user == result |> Map.put(:search_rank, nil)
+ end
end
test "auth_active?/1 works correctly" do
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 570bee6b3..398bedf77 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -5,8 +5,13 @@
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.Web.ActivityPub.{UserView, ObjectView}
- alias Pleroma.{Object, Repo, Activity, User, Instances}
+ alias Pleroma.Web.ActivityPub.UserView
+ alias Pleroma.Web.ActivityPub.ObjectView
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Instances
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -397,7 +402,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(200)
assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 1
+ assert result["totalItems"] == 0
end
test "it works for more than 10 users", %{conn: conn} do
@@ -452,7 +457,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> json_response(200)
assert result["first"]["orderedItems"] == []
- assert result["totalItems"] == 1
+ assert result["totalItems"] == 0
end
test "it works for more than 10 users", %{conn: conn} do
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index a55961ac4..a6f8b822a 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -7,7 +7,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
- alias Pleroma.{Activity, Object, User, Instances}
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.User
+ alias Pleroma.Instances
alias Pleroma.Builders.ActivityBuilder
import Pleroma.Factory
diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs
new file mode 100644
index 000000000..eb6ee4d04
--- /dev/null
+++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs
@@ -0,0 +1,73 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy
+
+ setup do
+ user = insert(:user)
+
+ message = %{
+ "actor" => user.ap_id,
+ "cc" => [user.follower_address],
+ "type" => "Create",
+ "to" => [
+ "https://www.w3.org/ns/activitystreams#Public",
+ "https://instance.tld/users/user1",
+ "https://instance.tld/users/user2",
+ "https://instance.tld/users/user3"
+ ]
+ }
+
+ [user: user, message: message]
+ end
+
+ describe "reject" do
+ test "rejects the message if the recipient count is above reject_threshold", %{
+ message: message
+ } do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2})
+
+ {:reject, nil} = filter(message)
+ end
+
+ test "does not reject the message if the recipient count is below reject_threshold", %{
+ message: message
+ } do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+ assert {:ok, ^message} = filter(message)
+ end
+ end
+
+ describe "delist" do
+ test "delists the message if the recipient count is above delist_threshold", %{
+ user: user,
+ message: message
+ } do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0})
+
+ {:ok, message} = filter(message)
+ assert user.follower_address in message["to"]
+ assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"]
+ end
+
+ test "does not delist the message if the recipient count is below delist_threshold", %{
+ message: message
+ } do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 4, reject_threshold: 0})
+
+ assert {:ok, ^message} = filter(message)
+ end
+ end
+
+ test "excludes follower collection and public URI from threshold count", %{message: message} do
+ Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3})
+
+ assert {:ok, ^message} = filter(message)
+ end
+end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index e5e3c8d33..86c66deff 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1128,4 +1128,58 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
)
end
end
+
+ describe "reserialization" do
+ test "successfully reserializes a message with inReplyTo == nil" do
+ user = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Create",
+ "object" => %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Note",
+ "content" => "Hi",
+ "inReplyTo" => nil,
+ "attributedTo" => user.ap_id
+ },
+ "actor" => user.ap_id
+ }
+
+ {:ok, activity} = Transmogrifier.handle_incoming(message)
+
+ {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
+ end
+
+ test "successfully reserializes a message with AS2 objects in IR" do
+ user = insert(:user)
+
+ message = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Create",
+ "object" => %{
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Note",
+ "content" => "Hi",
+ "inReplyTo" => nil,
+ "attributedTo" => user.ap_id,
+ "tag" => [
+ %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"},
+ %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"}
+ ]
+ },
+ "actor" => user.ap_id
+ }
+
+ {:ok, activity} = Transmogrifier.handle_incoming(message)
+
+ {:ok, _} = Transmogrifier.prepare_outgoing(activity.data)
+ end
+ end
end
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 7fc870e96..0bc1d4728 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -15,4 +15,43 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
+
+ describe "endpoints" do
+ test "local users have a usable endpoints structure" do
+ user = insert(:user)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ assert result["id"] == user.ap_id
+
+ %{
+ "sharedInbox" => _,
+ "oauthAuthorizationEndpoint" => _,
+ "oauthRegistrationEndpoint" => _,
+ "oauthTokenEndpoint" => _
+ } = result["endpoints"]
+ end
+
+ test "remote users have an empty endpoints structure" do
+ user = insert(:user, local: false)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ assert result["id"] == user.ap_id
+ assert result["endpoints"] == %{}
+ end
+
+ test "instance users do not expose oAuth endpoints" do
+ user = insert(:user, nickname: nil, local: true)
+ {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
+
+ result = UserView.render("user.json", %{user: user})
+
+ refute result["endpoints"]["oauthAuthorizationEndpoint"]
+ refute result["endpoints"]["oauthRegistrationEndpoint"]
+ refute result["endpoints"]["oauthTokenEndpoint"]
+ end
+ end
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 42450a7b6..a27c26f95 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
use Pleroma.Web.ConnCase
- alias Pleroma.{Repo, User}
+ alias Pleroma.Repo
+ alias Pleroma.User
import Pleroma.Factory
describe "/api/pleroma/admin/user" do
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index d26b6e49c..870648fb5 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.CommonAPI.Test do
+defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.User
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 754bc7255..faed6b685 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
- alias Pleroma.Builders.{UserBuilder}
+ 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 05f813291..08279f230 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -3,7 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.FederatorTest do
- alias Pleroma.Web.{CommonAPI, Federator}
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Web.Federator
alias Pleroma.Instances
use Pleroma.DataCase
import Pleroma.Factory
@@ -14,22 +15,6 @@ defmodule Pleroma.Web.FederatorTest do
:ok
end
- test "enqueues an element according to priority" do
- queue = [%{item: 1, priority: 2}]
-
- new_queue = Federator.enqueue_sorted(queue, 2, 1)
- assert new_queue == [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
-
- new_queue = Federator.enqueue_sorted(queue, 2, 3)
- assert new_queue == [%{item: 1, priority: 2}, %{item: 2, priority: 3}]
- end
-
- test "pop first item" do
- queue = [%{item: 2, priority: 1}, %{item: 1, priority: 2}]
-
- assert {2, [%{item: 1, priority: 2}]} = Federator.queue_pop(queue)
- end
-
describe "Publish an activity" do
setup do
user = insert(:user)
@@ -49,7 +34,7 @@ defmodule Pleroma.Web.FederatorTest do
relay_mock: relay_mock
} do
with_mocks([relay_mock]) do
- Federator.handle(:publish, activity)
+ Federator.publish(activity)
end
assert_received :relay_publish
@@ -62,7 +47,7 @@ defmodule Pleroma.Web.FederatorTest do
Pleroma.Config.put([:instance, :allow_relay], false)
with_mocks([relay_mock]) do
- Federator.handle(:publish, activity)
+ Federator.publish(activity)
end
refute_received :relay_publish
@@ -103,11 +88,9 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} =
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
- assert called(
- Federator.enqueue(:publish_single_ap, %{inbox: inbox1, unreachable_since: dt})
- )
+ assert called(Federator.publish_single_ap(%{inbox: inbox1, unreachable_since: dt}))
- refute called(Federator.enqueue(:publish_single_ap, %{inbox: inbox2}))
+ refute called(Federator.publish_single_ap(%{inbox: inbox2}))
end
test_with_mock "it federates only to reachable instances via Websub",
@@ -139,13 +122,13 @@ defmodule Pleroma.Web.FederatorTest do
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
assert called(
- Federator.enqueue(:publish_single_websub, %{
+ Federator.publish_single_websub(%{
callback: sub2.callback,
unreachable_since: dt
})
)
- refute called(Federator.enqueue(:publish_single_websub, %{callback: sub1.callback}))
+ refute called(Federator.publish_single_websub(%{callback: sub1.callback}))
end
test_with_mock "it federates only to reachable instances via Salmon",
@@ -179,13 +162,13 @@ defmodule Pleroma.Web.FederatorTest do
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
assert called(
- Federator.enqueue(:publish_single_salmon, %{
+ Federator.publish_single_salmon(%{
recipient: remote_user2,
unreachable_since: dt
})
)
- refute called(Federator.enqueue(:publish_single_websub, %{recipient: remote_user1}))
+ refute called(Federator.publish_single_websub(%{recipient: remote_user1}))
end
end
@@ -205,7 +188,7 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- {:ok, _activity} = Federator.handle(:incoming_ap_doc, params)
+ {:ok, _activity} = Federator.incoming_ap_doc(params)
end
test "rejects incoming AP docs with incorrect origin" do
@@ -223,7 +206,7 @@ defmodule Pleroma.Web.FederatorTest do
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
}
- :error = Federator.handle(:incoming_ap_doc, params)
+ :error = Federator.incoming_ap_doc(params)
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 1a60ad8e6..e43bc4508 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -6,8 +6,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.TwitterAPI
- alias Pleroma.{Repo, User, Object, Activity, Notification}
- alias Pleroma.Web.{OStatus, CommonAPI}
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Activity
+ alias Pleroma.Notification
+ alias Pleroma.Web.OStatus
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.MastodonAPI.FilterView
alias Ecto.Changeset
@@ -31,7 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> assign(:user, user)
|> get("/api/v1/timelines/home")
- assert length(json_response(conn, 200)) == 0
+ assert Enum.empty?(json_response(conn, 200))
{:ok, user} = User.follow(user, following)
@@ -932,7 +937,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "/api/v1/follow_requests/:id/authorize works" do
- user = insert(:user, %{info: %Pleroma.User.Info{locked: true}})
+ user = insert(:user, %{info: %User.Info{locked: true}})
other_user = insert(:user)
{:ok, _activity} = ActivityPub.follow(other_user, user)
@@ -941,6 +946,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 1
conn =
build_conn()
@@ -954,6 +960,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == true
+ assert user.info.follow_request_count == 0
end
test "verify_credentials", %{conn: conn} do
@@ -974,6 +981,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
{:ok, _activity} = ActivityPub.follow(other_user, user)
+ user = Repo.get(User, user.id)
+ assert user.info.follow_request_count == 1
+
conn =
build_conn()
|> assign(:user, user)
@@ -986,6 +996,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 0
end
end
@@ -1781,4 +1792,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(200)
end
end
+
+ test "flavours switching (Pleroma Extension)", %{conn: conn} do
+ user = insert(:user)
+
+ get_old_flavour =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/pleroma/flavour")
+
+ assert "glitch" == json_response(get_old_flavour, 200)
+
+ set_flavour =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/flavour/vanilla")
+
+ assert "vanilla" == json_response(set_flavour, 200)
+
+ get_new_flavour =
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/flavour/vanilla")
+
+ assert json_response(set_flavour, 200) == json_response(get_new_flavour, 200)
+ end
end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 2106253f2..0dc9c538c 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
use Pleroma.DataCase
- alias Pleroma.Web.MastodonAPI.{StatusView, AccountView}
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.User
alias Pleroma.Web.OStatus
alias Pleroma.Web.CommonAPI
diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs
index 3b1ddada8..81618e935 100644
--- a/test/web/oauth/authorization_test.exs
+++ b/test/web/oauth/authorization_test.exs
@@ -4,7 +4,8 @@
defmodule Pleroma.Web.OAuth.AuthorizationTest do
use Pleroma.DataCase
- alias Pleroma.Web.OAuth.{Authorization, App}
+ alias Pleroma.Web.OAuth.Authorization
+ alias Pleroma.Web.OAuth.App
import Pleroma.Factory
test "create an authorization token for a valid app" do
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index e0d3cb55f..2315f9a34 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -7,7 +7,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
import Pleroma.Factory
alias Pleroma.Repo
- alias Pleroma.Web.OAuth.{Authorization, Token}
+ alias Pleroma.Web.OAuth.Authorization
+ alias Pleroma.Web.OAuth.Token
test "redirects with oauth authorization" do
user = insert(:user)
diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs
index 9a241d61a..4dab4a308 100644
--- a/test/web/oauth/token_test.exs
+++ b/test/web/oauth/token_test.exs
@@ -4,7 +4,9 @@
defmodule Pleroma.Web.OAuth.TokenTest do
use Pleroma.DataCase
- alias Pleroma.Web.OAuth.{App, Token, Authorization}
+ 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 0869f2fd5..eebc5c040 100644
--- a/test/web/ostatus/activity_representer_test.exs
+++ b/test/web/ostatus/activity_representer_test.exs
@@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus.ActivityRepresenter
- alias Pleroma.{User, Activity, Object}
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs
index 55717dec7..efd4e7217 100644
--- a/test/web/ostatus/feed_representer_test.exs
+++ b/test/web/ostatus/feed_representer_test.exs
@@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
use Pleroma.DataCase
import Pleroma.Factory
alias Pleroma.User
- alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter}
+ 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
diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs
index d97cd79f4..d295cc539 100644
--- a/test/web/ostatus/incoming_documents/delete_handling_test.exs
+++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs
@@ -4,7 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
import Pleroma.Factory
import Tesla.Mock
- alias Pleroma.{Repo, Activity, Object}
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.Object
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 3145ca9a1..da9c72be8 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -5,7 +5,9 @@
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
- alias Pleroma.{User, Repo, Object}
+ alias Pleroma.User
+ alias Pleroma.Repo
+ alias Pleroma.Object
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 dbe5de2e2..b4b19ab05 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -6,7 +6,11 @@ defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
alias Pleroma.Web.XML
- alias Pleroma.{Object, Repo, User, Activity, Instances}
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Activity
+ alias Pleroma.Instances
import Pleroma.Factory
import ExUnit.CaptureLog
diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs
index c539a28b2..9e583ba40 100644
--- a/test/web/salmon/salmon_test.exs
+++ b/test/web/salmon/salmon_test.exs
@@ -5,7 +5,9 @@
defmodule Pleroma.Web.Salmon.SalmonTest do
use Pleroma.DataCase
alias Pleroma.Web.Salmon
- alias Pleroma.{Repo, Activity, User}
+ alias Pleroma.Activity
+ alias Pleroma.Repo
+ alias Pleroma.User
import Pleroma.Factory
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs
index ea5813733..365c7f659 100644
--- a/test/web/twitter_api/representers/activity_representer_test.exs
+++ b/test/web/twitter_api/representers/activity_representer_test.exs
@@ -4,8 +4,11 @@
defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
use Pleroma.DataCase
- alias Pleroma.{User, Activity, Object}
- alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter}
+ alias Pleroma.User
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ 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
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 855ae1526..1571ab68e 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -5,9 +5,15 @@
defmodule Pleroma.Web.TwitterAPI.ControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter
- alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
- alias Pleroma.{Repo, Activity, User, Object, Notification}
+ alias Pleroma.Builders.ActivityBuilder
+ alias Pleroma.Builders.UserBuilder
+ alias Pleroma.Repo
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Notification
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.CommonAPI
@@ -635,6 +641,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert json_response(conn, 200) ==
UserView.render("show.json", %{user: followed, for: current_user})
end
+
+ test "for restricted account", %{conn: conn, user: current_user} do
+ followed = insert(:user, info: %User.Info{locked: true})
+
+ conn =
+ conn
+ |> with_credentials(current_user.nickname, "test")
+ |> post("/api/friendships/create.json", %{user_id: followed.id})
+
+ current_user = Repo.get(User, current_user.id)
+ followed = Repo.get(User, followed.id)
+
+ refute User.ap_followers(followed) in current_user.following
+ assert followed.info.follow_request_count == 1
+
+ assert json_response(conn, 200) ==
+ UserView.render("show.json", %{user: followed, for: current_user})
+ end
end
describe "POST /friendships/destroy.json" do
@@ -1213,7 +1237,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
assert Enum.sort(expected) == Enum.sort(result)
end
- test "it returns 20 friends per page", %{conn: conn} do
+ test "it returns 20 friends per page, except if 'export' is set to true", %{conn: conn} do
user = insert(:user)
followeds = insert_list(21, :user)
@@ -1237,6 +1261,14 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
result = json_response(res_conn, 200)
assert length(result) == 1
+
+ res_conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/statuses/friends", %{all: true})
+
+ result = json_response(res_conn, 200)
+ assert length(result) == 21
end
test "it returns a given user's friends with user_id", %{conn: conn} do
@@ -1671,15 +1703,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 1
conn =
build_conn()
|> 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
+ assert user.info.follow_request_count == 0
end
end
@@ -1694,15 +1730,19 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
other_user = Repo.get(User, other_user.id)
assert User.following?(other_user, user) == false
+ assert user.info.follow_request_count == 1
conn =
build_conn()
|> 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
+ assert user.info.follow_request_count == 0
end
end
@@ -1876,4 +1916,38 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
ActivityRepresenter.to_map(activity, %{user: user, for: user})
end
end
+
+ describe "GET /api/oauth_tokens" do
+ setup do
+ token = insert(:oauth_token) |> Repo.preload(:user)
+
+ %{token: token}
+ end
+
+ test "renders list", %{token: token} do
+ response =
+ build_conn()
+ |> assign(:user, token.user)
+ |> get("/api/oauth_tokens")
+
+ keys =
+ json_response(response, 200)
+ |> hd()
+ |> Map.keys()
+
+ assert keys -- ["id", "app_name", "valid_until"] == []
+ end
+
+ test "revoke token", %{token: token} do
+ response =
+ build_conn()
+ |> assign(:user, token.user)
+ |> delete("/api/oauth_tokens/#{token.id}")
+
+ tokens = Token.get_user_tokens(token.user)
+
+ assert tokens == []
+ assert response.status == 201
+ end
+ end
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 48ddbcf50..aa2a4d650 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -4,8 +4,13 @@
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
use Pleroma.DataCase
- alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView}
- alias Pleroma.{Activity, User, Object, Repo, UserInviteToken}
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Object
+ alias Pleroma.Repo
+ alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.TwitterAPI.ActivityView
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
index 8367fc6c7..3a67f7292 100644
--- a/test/web/twitter_api/views/notification_view_test.exs
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
use Pleroma.DataCase
- alias Pleroma.{User, Notification}
+ alias Pleroma.User
+ alias Pleroma.Notification
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.TwitterAPI.UserView
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index 6492df2a0..87b01d89b 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -6,7 +6,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Web.Websub.WebsubClientSubscription
- alias Pleroma.{Repo, Activity}
+ alias Pleroma.Activity
+ alias Pleroma.Repo
alias Pleroma.Web.Websub
test "websub subscription request", %{conn: conn} do
@@ -80,7 +81,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
assert response(conn, 500) == "Error"
- assert length(Repo.all(Activity)) == 0
+ assert Enum.empty?(Repo.all(Activity))
end
end
end
diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs
index 9751d161d..9a9b9df02 100644
--- a/test/web/websub/websub_test.exs
+++ b/test/web/websub/websub_test.exs
@@ -5,7 +5,8 @@
defmodule Pleroma.Web.WebsubTest do
use Pleroma.DataCase
alias Pleroma.Web.Websub
- alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription}
+ alias Pleroma.Web.Websub.WebsubServerSubscription
+ alias Pleroma.Web.Websub.WebsubClientSubscription
import Pleroma.Factory
alias Pleroma.Web.Router.Helpers
import Tesla.Mock