Merge remote-tracking branch 'origin/develop' into reactions
This commit is contained in:
commit
b923842e96
341 changed files with 12526 additions and 7168 deletions
|
|
@ -1,19 +1,24 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Delivery
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ObjectView
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
alias Pleroma.Web.ActivityPub.UserView
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Workers.ReceiverWorker
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -365,7 +370,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
:timer.sleep(500)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
|
|
@ -407,7 +413,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/users/#{user.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
:timer.sleep(500)
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
|
|
@ -436,7 +442,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/users/#{recipient.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
:timer.sleep(500)
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
|
|
@ -473,7 +479,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/inbox")
|
||||
|> get("/users/#{user.nickname}/inbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ note_object.data["content"]
|
||||
end
|
||||
|
|
@ -526,6 +532,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/users/#{recipient.nickname}/inbox", data)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
|
||||
activity = Activity.get_by_ap_id(data["id"])
|
||||
|
||||
assert activity.id
|
||||
|
|
@ -559,7 +567,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox")
|
||||
|> get("/users/#{user.nickname}/outbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ note_object.data["content"]
|
||||
end
|
||||
|
|
@ -571,7 +579,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox")
|
||||
|> get("/users/#{user.nickname}/outbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ announce_activity.data["object"]
|
||||
end
|
||||
|
|
@ -601,6 +609,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|
||||
result = json_response(conn, 201)
|
||||
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
end
|
||||
|
||||
|
|
@ -885,4 +894,86 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert result["totalItems"] == 15
|
||||
end
|
||||
end
|
||||
|
||||
describe "delivery tracking" do
|
||||
test "it tracks a signed object fetch", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
end
|
||||
|
||||
test "it tracks a signed activity fetch", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
end
|
||||
|
||||
test "it tracks a signed object fetch when the json is cached", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
other_user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, other_user)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
assert Delivery.get(object.id, other_user.id)
|
||||
end
|
||||
|
||||
test "it tracks a signed activity fetch when the json is cached", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
other_user = insert(:user, local: false)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, user)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, other_user)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
assert Delivery.get(object.id, user.id)
|
||||
assert Delivery.get(object.id, other_user.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,9 +38,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
stream: fn _, _ -> nil end do
|
||||
ActivityPub.stream_out_participations(conversation.participations)
|
||||
|
||||
Enum.each(participations, fn participation ->
|
||||
assert called(Pleroma.Web.Streamer.stream("participation", participation))
|
||||
end)
|
||||
assert called(Pleroma.Web.Streamer.stream("participation", participations))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -259,6 +257,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "listen activities" do
|
||||
test "does not increase user note count" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
ActivityPub.listen(%{
|
||||
to: ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
actor: user,
|
||||
context: "",
|
||||
object: %{
|
||||
"actor" => user.ap_id,
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"artist" => "lain",
|
||||
"title" => "lain radio episode 1",
|
||||
"length" => 180_000,
|
||||
"type" => "Audio"
|
||||
}
|
||||
})
|
||||
|
||||
assert activity.actor == user.ap_id
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.note_count == 0
|
||||
end
|
||||
|
||||
test "can be fetched into a timeline" do
|
||||
_listen_activity_1 = insert(:listen)
|
||||
_listen_activity_2 = insert(:listen)
|
||||
_listen_activity_3 = insert(:listen)
|
||||
|
||||
timeline = ActivityPub.fetch_activities([], %{"type" => ["Listen"]})
|
||||
|
||||
assert length(timeline) == 3
|
||||
end
|
||||
end
|
||||
|
||||
describe "create activities" do
|
||||
test "removes doubled 'to' recipients" do
|
||||
user = insert(:user)
|
||||
|
|
@ -649,6 +683,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert last == last_expected
|
||||
end
|
||||
|
||||
test "paginates via offset/limit" do
|
||||
_first_activities = ActivityBuilder.insert_list(10)
|
||||
activities = ActivityBuilder.insert_list(10)
|
||||
_later_activities = ActivityBuilder.insert_list(10)
|
||||
first_expected = List.first(activities)
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_public_activities(%{"page" => "2", "page_size" => "20"}, :offset)
|
||||
|
||||
first = List.first(activities)
|
||||
|
||||
assert length(activities) == 20
|
||||
assert first == first_expected
|
||||
end
|
||||
|
||||
test "doesn't return reblogs for users for whom reblogs have been muted" do
|
||||
activity = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
|
|
@ -708,7 +757,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object_activity)
|
||||
assert called(Pleroma.Web.Federator.publish(like_activity, 5))
|
||||
assert called(Pleroma.Web.Federator.publish(like_activity))
|
||||
end
|
||||
|
||||
test "returns exist activity if object already liked" do
|
||||
|
|
@ -769,7 +818,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(unlike_activity, 5))
|
||||
assert called(Pleroma.Web.Federator.publish(unlike_activity))
|
||||
end
|
||||
|
||||
test "unliking a previously liked object" do
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
|||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.HTTP
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
|
||||
|
||||
import Mock
|
||||
|
|
@ -24,6 +25,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicyTest do
|
|||
test "it prefetches media proxy URIs" do
|
||||
with_mock HTTP, get: fn _, _, _ -> {:ok, []} end do
|
||||
MediaProxyWarmingPolicy.filter(@message)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
# Performing jobs which has been just enqueued
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert called(HTTP.get(:_, :_, :_))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,15 +3,18 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
||||
use Pleroma.DataCase
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
import Mock
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Publisher
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
@as_public "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
||||
|
|
@ -188,7 +191,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
actor = insert(:user)
|
||||
inbox = "http://connrefused.site/users/nick1/inbox"
|
||||
|
||||
assert {:error, _} = Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
|
||||
assert capture_log(fn ->
|
||||
assert {:error, _} =
|
||||
Publisher.publish_one(%{inbox: inbox, json: "{}", actor: actor, id: 1})
|
||||
end) =~ "connrefused"
|
||||
|
||||
assert called(Instances.set_unreachable(inbox))
|
||||
end
|
||||
|
|
@ -212,14 +218,16 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
actor = insert(:user)
|
||||
inbox = "http://connrefused.site/users/nick1/inbox"
|
||||
|
||||
assert {:error, _} =
|
||||
Publisher.publish_one(%{
|
||||
inbox: inbox,
|
||||
json: "{}",
|
||||
actor: actor,
|
||||
id: 1,
|
||||
unreachable_since: NaiveDateTime.utc_now()
|
||||
})
|
||||
assert capture_log(fn ->
|
||||
assert {:error, _} =
|
||||
Publisher.publish_one(%{
|
||||
inbox: inbox,
|
||||
json: "{}",
|
||||
actor: actor,
|
||||
id: 1,
|
||||
unreachable_since: NaiveDateTime.utc_now()
|
||||
})
|
||||
end) =~ "connrefused"
|
||||
|
||||
refute called(Instances.set_unreachable(inbox))
|
||||
end
|
||||
|
|
@ -257,10 +265,74 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor: actor,
|
||||
actor_id: actor.id,
|
||||
id: note_activity.data["id"]
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "publishes a delete activity to peers who signed fetch requests to the create acitvity/object.",
|
||||
Pleroma.Web.Federator.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
|
||||
}
|
||||
)
|
||||
|
||||
another_fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"}
|
||||
}
|
||||
)
|
||||
|
||||
actor = insert(:user)
|
||||
|
||||
note_activity = insert(:note_activity, user: actor)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url())
|
||||
object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, fetcher)
|
||||
|> get(object_path)
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> assign(:user, another_fetcher)
|
||||
|> get(activity_path)
|
||||
|> json_response(200)
|
||||
|
||||
{:ok, delete} = CommonAPI.delete(note_activity.id, actor)
|
||||
|
||||
res = Publisher.publish(actor, delete)
|
||||
assert res == :ok
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
})
|
||||
)
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{
|
||||
inbox: "https://domain2.com/users/nick1/inbox",
|
||||
actor_id: actor.id,
|
||||
id: delete.data["id"]
|
||||
})
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.RelayTest do
|
||||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
|
|
@ -20,7 +21,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
|
||||
describe "follow/1" do
|
||||
test "returns errors when user not found" do
|
||||
assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
assert capture_log(fn ->
|
||||
assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
end) =~ "Could not fetch by AP id"
|
||||
end
|
||||
|
||||
test "returns activity" do
|
||||
|
|
@ -37,7 +40,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
|
||||
describe "unfollow/1" do
|
||||
test "returns errors when user not found" do
|
||||
assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
assert capture_log(fn ->
|
||||
assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
end) =~ "Could not fetch by AP id"
|
||||
end
|
||||
|
||||
test "returns activity" do
|
||||
|
|
@ -78,7 +83,9 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert Relay.publish(activity) == {:error, nil}
|
||||
assert capture_log(fn ->
|
||||
assert Relay.publish(activity) == {:error, nil}
|
||||
end) =~ "[error] error: nil"
|
||||
end
|
||||
|
||||
test_with_mock "returns announce activity and publish to federate",
|
||||
|
|
@ -92,7 +99,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["object"] == obj.data["id"]
|
||||
assert called(Pleroma.Web.Federator.publish(activity, 5))
|
||||
assert called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
|
||||
test_with_mock "returns announce activity and not publish to federate",
|
||||
|
|
@ -106,7 +113,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["object"] == obj.data["id"]
|
||||
refute called(Pleroma.Web.Federator.publish(activity, 5))
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Object.Fetcher
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
|
@ -176,6 +177,35 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "it works for incoming listens" do
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"type" => "Listen",
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
|
||||
"actor" => "http://mastodon.example.org/users/admin",
|
||||
"object" => %{
|
||||
"type" => "Audio",
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio",
|
||||
"length" => 180_000
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
assert object.data["artist"] == "lain"
|
||||
assert object.data["album"] == "lain radio"
|
||||
assert object.data["length"] == 180_000
|
||||
end
|
||||
|
||||
test "it rewrites Note votes to Answers and increments vote counters on question activities" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -680,6 +710,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|> Poison.decode!()
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(data)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
refute User.get_cached_by_ap_id(ap_id)
|
||||
end
|
||||
|
|
@ -1220,6 +1251,20 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert is_nil(modified["bcc"])
|
||||
end
|
||||
|
||||
test "it can handle Listen activities" do
|
||||
listen_activity = insert(:listen)
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(listen_activity.data)
|
||||
|
||||
assert modified["type"] == "Listen"
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.listen(user, %{"title" => "lain radio episode 1"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user upgrade" do
|
||||
|
|
@ -1242,6 +1287,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert user.info.note_count == 1
|
||||
|
||||
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert user.info.ap_enabled
|
||||
assert user.info.note_count == 1
|
||||
assert user.follower_address == "https://niu.moe/users/rye/followers"
|
||||
|
|
@ -1483,4 +1530,271 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute recipient.follower_address in fixed_object["to"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_summary/1" do
|
||||
test "returns fixed object" do
|
||||
assert Transmogrifier.fix_summary(%{"summary" => nil}) == %{"summary" => ""}
|
||||
assert Transmogrifier.fix_summary(%{"summary" => "ok"}) == %{"summary" => "ok"}
|
||||
assert Transmogrifier.fix_summary(%{}) == %{"summary" => ""}
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_in_reply_to/2" do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
||||
setup do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
[data: data]
|
||||
end
|
||||
|
||||
test "returns not modified object when hasn't containts inReplyTo field", %{data: data} do
|
||||
assert Transmogrifier.fix_in_reply_to(data) == data
|
||||
end
|
||||
|
||||
test "returns object with inReplyToAtomUri when denied incoming reply", %{data: data} do
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 0)
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", "https://shitposter.club/notice/2827873")
|
||||
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == "https://shitposter.club/notice/2827873"
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", %{"id" => "https://shitposter.club/notice/2827873"})
|
||||
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == %{"id" => "https://shitposter.club/notice/2827873"}
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
object_with_reply =
|
||||
Map.put(data["object"], "inReplyTo", ["https://shitposter.club/notice/2827873"])
|
||||
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == ["https://shitposter.club/notice/2827873"]
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
object_with_reply = Map.put(data["object"], "inReplyTo", [])
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
assert modified_object["inReplyTo"] == []
|
||||
assert modified_object["inReplyToAtomUri"] == ""
|
||||
end
|
||||
|
||||
test "returns modified object when allowed incoming reply", %{data: data} do
|
||||
object_with_reply =
|
||||
Map.put(
|
||||
data["object"],
|
||||
"inReplyTo",
|
||||
"https://shitposter.club/notice/2827873"
|
||||
)
|
||||
|
||||
Pleroma.Config.put([:instance, :federation_incoming_replies_max_depth], 5)
|
||||
modified_object = Transmogrifier.fix_in_reply_to(object_with_reply)
|
||||
|
||||
assert modified_object["inReplyTo"] ==
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
|
||||
assert modified_object["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
|
||||
|
||||
assert modified_object["conversation"] ==
|
||||
"tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
|
||||
|
||||
assert modified_object["context"] ==
|
||||
"tag:shitposter.club,2017-05-05:objectType=thread:nonce=3c16e9c2681f6d26"
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_url/1" do
|
||||
test "fixes data for object when url is map" do
|
||||
object = %{
|
||||
"url" => %{
|
||||
"type" => "Link",
|
||||
"mimeType" => "video/mp4",
|
||||
"href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
}
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(object) == %{
|
||||
"url" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
}
|
||||
end
|
||||
|
||||
test "fixes data for video object" do
|
||||
object = %{
|
||||
"type" => "Video",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "video/mp4",
|
||||
"href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "video/mp4",
|
||||
"href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d1630e3"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d16377-42"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(object) == %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mimeType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
],
|
||||
"type" => "Video",
|
||||
"url" => "https://peertube.-2d4c2d1630e3"
|
||||
}
|
||||
end
|
||||
|
||||
test "fixes url for not Video object" do
|
||||
object = %{
|
||||
"type" => "Text",
|
||||
"url" => [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d1630e3"
|
||||
},
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mimeType" => "text/html",
|
||||
"href" => "https://peertube.-2d4c2d16377-42"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(object) == %{
|
||||
"type" => "Text",
|
||||
"url" => "https://peertube.-2d4c2d1630e3"
|
||||
}
|
||||
|
||||
assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{
|
||||
"type" => "Text",
|
||||
"url" => ""
|
||||
}
|
||||
end
|
||||
|
||||
test "retunrs not modified object" do
|
||||
assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_obj_helper/2" do
|
||||
test "returns nil when cannot normalize object" do
|
||||
refute Transmogrifier.get_obj_helper("test-obj-id")
|
||||
end
|
||||
|
||||
test "returns {:ok, %Object{}} for success case" do
|
||||
assert {:ok, %Object{}} =
|
||||
Transmogrifier.get_obj_helper("https://shitposter.club/notice/2827873")
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_attachments/1" do
|
||||
test "returns not modified object" do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
assert Transmogrifier.fix_attachments(data) == data
|
||||
end
|
||||
|
||||
test "returns modified object when attachment is map" do
|
||||
assert Transmogrifier.fix_attachments(%{
|
||||
"attachment" => %{
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => "https://peertube.moe/stat-480.mp4"
|
||||
}
|
||||
}) == %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://peertube.moe/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "returns modified object when attachment is list" do
|
||||
assert Transmogrifier.fix_attachments(%{
|
||||
"attachment" => [
|
||||
%{"mediaType" => "video/mp4", "url" => "https://pe.er/stat-480.mp4"},
|
||||
%{"mimeType" => "video/mp4", "href" => "https://pe.er/stat-480.mp4"}
|
||||
]
|
||||
}) == %{
|
||||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"mimeType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "fix_emoji/1" do
|
||||
test "returns not modified object when object not contains tags" do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
assert Transmogrifier.fix_emoji(data) == data
|
||||
end
|
||||
|
||||
test "returns object with emoji when object contains list tags" do
|
||||
assert Transmogrifier.fix_emoji(%{
|
||||
"tag" => [
|
||||
%{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}},
|
||||
%{"type" => "Hashtag"}
|
||||
]
|
||||
}) == %{
|
||||
"emoji" => %{"bib" => "/test"},
|
||||
"tag" => [
|
||||
%{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"},
|
||||
%{"type" => "Hashtag"}
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "returns object with emoji when object contains map tag" do
|
||||
assert Transmogrifier.fix_emoji(%{
|
||||
"tag" => %{"type" => "Emoji", "name" => ":bib:", "icon" => %{"url" => "/test"}}
|
||||
}) == %{
|
||||
"emoji" => %{"bib" => "/test"},
|
||||
"tag" => %{"icon" => %{"url" => "/test"}, "name" => ":bib:", "type" => "Emoji"}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -87,6 +87,18 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
assert Utils.determine_explicit_mentions(object) == []
|
||||
end
|
||||
|
||||
test "works with an object has tags as map" do
|
||||
object = %{
|
||||
"tag" => %{
|
||||
"type" => "Mention",
|
||||
"href" => "https://example.com/~alyssa",
|
||||
"name" => "Alyssa P. Hacker"
|
||||
}
|
||||
}
|
||||
|
||||
assert Utils.determine_explicit_mentions(object) == ["https://example.com/~alyssa"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_unlike_data/3" do
|
||||
|
|
@ -300,8 +312,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
{:ok, follow_activity_two} =
|
||||
Utils.update_follow_state_for_all(follow_activity_two, "accept")
|
||||
|
||||
assert Repo.get(Activity, follow_activity.id).data["state"] == "accept"
|
||||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "accept"
|
||||
assert refresh_record(follow_activity).data["state"] == "accept"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "accept"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -323,8 +335,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
{:ok, follow_activity_two} = Utils.update_follow_state(follow_activity_two, "reject")
|
||||
|
||||
assert Repo.get(Activity, follow_activity.id).data["state"] == "pending"
|
||||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
|
||||
assert refresh_record(follow_activity).data["state"] == "pending"
|
||||
assert refresh_record(follow_activity_two).data["state"] == "reject"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -401,4 +413,216 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert ^like_activity = Utils.get_existing_like(user.ap_id, object)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_get_existing_announce/2" do
|
||||
test "returns nil if announce not found" do
|
||||
actor = insert(:user)
|
||||
refute Utils.get_existing_announce(actor.ap_id, %{data: %{"id" => "test"}})
|
||||
end
|
||||
|
||||
test "fetches existing announce" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object = Object.normalize(note_activity)
|
||||
actor = insert(:user)
|
||||
|
||||
{:ok, announce, _object} = ActivityPub.announce(actor, object)
|
||||
assert Utils.get_existing_announce(actor.ap_id, object) == announce
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetch_latest_block/2" do
|
||||
test "fetches last block activities" do
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = _} = ActivityPub.block(user1, user2)
|
||||
assert {:ok, %Activity{} = activity} = ActivityPub.block(user1, user2)
|
||||
|
||||
assert Utils.fetch_latest_block(user1, user2) == activity
|
||||
end
|
||||
end
|
||||
|
||||
describe "recipient_in_message/3" do
|
||||
test "returns true when recipient in `to`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"to" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"to" => [recipient.ap_id], "cc" => ""}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when recipient in `cc`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"cc" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"cc" => [recipient.ap_id], "to" => ""}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when recipient in `bto`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"bto" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"bcc" => "", "bto" => [recipient.ap_id]}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when recipient in `bcc`" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"bcc" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"bto" => "", "bcc" => [recipient.ap_id]}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns true when message without addresses fields" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
assert Utils.recipient_in_message(recipient, actor, %{"bccc" => recipient.ap_id})
|
||||
|
||||
assert Utils.recipient_in_message(
|
||||
recipient,
|
||||
actor,
|
||||
%{"btod" => "", "bccc" => [recipient.ap_id]}
|
||||
)
|
||||
end
|
||||
|
||||
test "returns false" do
|
||||
recipient = insert(:user)
|
||||
actor = insert(:user)
|
||||
refute Utils.recipient_in_message(recipient, actor, %{"to" => "ap_id"})
|
||||
end
|
||||
end
|
||||
|
||||
describe "lazy_put_activity_defaults/2" do
|
||||
test "returns map with id and published data" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
res = Utils.lazy_put_activity_defaults(%{"context" => object.data["id"]})
|
||||
assert res["context"] == object.data["id"]
|
||||
assert res["context_id"] == object.id
|
||||
assert res["id"]
|
||||
assert res["published"]
|
||||
end
|
||||
|
||||
test "returns map with fake id and published data" do
|
||||
assert %{
|
||||
"context" => "pleroma:fakecontext",
|
||||
"context_id" => -1,
|
||||
"id" => "pleroma:fakeid",
|
||||
"published" => _
|
||||
} = Utils.lazy_put_activity_defaults(%{}, true)
|
||||
end
|
||||
|
||||
test "returns activity data with object" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
res =
|
||||
Utils.lazy_put_activity_defaults(%{
|
||||
"context" => object.data["id"],
|
||||
"object" => %{}
|
||||
})
|
||||
|
||||
assert res["context"] == object.data["id"]
|
||||
assert res["context_id"] == object.id
|
||||
assert res["id"]
|
||||
assert res["published"]
|
||||
assert res["object"]["id"]
|
||||
assert res["object"]["published"]
|
||||
assert res["object"]["context"] == object.data["id"]
|
||||
assert res["object"]["context_id"] == object.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_flag_data" do
|
||||
test "returns empty map when params is invalid" do
|
||||
assert Utils.make_flag_data(%{}, %{}) == %{}
|
||||
end
|
||||
|
||||
test "returns map with Flag object" do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"})
|
||||
context = Utils.generate_context_id()
|
||||
content = "foobar"
|
||||
|
||||
target_ap_id = target_account.ap_id
|
||||
activity_ap_id = activity.data["id"]
|
||||
|
||||
res =
|
||||
Utils.make_flag_data(
|
||||
%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [%{"id" => activity.data["id"]}],
|
||||
content: content
|
||||
},
|
||||
%{}
|
||||
)
|
||||
|
||||
assert %{
|
||||
"type" => "Flag",
|
||||
"content" => ^content,
|
||||
"context" => ^context,
|
||||
"object" => [^target_ap_id, ^activity_ap_id],
|
||||
"state" => "open"
|
||||
} = res
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_announce_to_object/2" do
|
||||
test "adds actor to announcement" do
|
||||
user = insert(:user)
|
||||
object = insert(:note)
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
data: %{
|
||||
"actor" => user.ap_id,
|
||||
"cc" => [Pleroma.Constants.as_public()]
|
||||
}
|
||||
)
|
||||
|
||||
assert {:ok, updated_object} = Utils.add_announce_to_object(activity, object)
|
||||
assert updated_object.data["announcements"] == [user.ap_id]
|
||||
assert updated_object.data["announcement_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_announce_from_object/2" do
|
||||
test "removes actor from announcements" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
object =
|
||||
insert(:note,
|
||||
data: %{"announcements" => [user.ap_id, user2.ap_id], "announcement_count" => 2}
|
||||
)
|
||||
|
||||
activity = insert(:note_activity, data: %{"actor" => user.ap_id})
|
||||
|
||||
assert {:ok, updated_object} = Utils.remove_announce_from_object(activity, object)
|
||||
assert updated_object.data["announcements"] == [user2.ap_id]
|
||||
assert updated_object.data["announcement_count"] == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -37,6 +37,22 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
test "Renders with emoji tags" do
|
||||
user = insert(:user, %{info: %{emoji: [%{"bib" => "/test"}]}})
|
||||
|
||||
assert %{
|
||||
"tag" => [
|
||||
%{
|
||||
"icon" => %{"type" => "Image", "url" => "/test"},
|
||||
"id" => "/test",
|
||||
"name" => ":bib:",
|
||||
"type" => "Emoji",
|
||||
"updated" => "1970-01-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
} = UserView.render("user.json", %{user: user})
|
||||
end
|
||||
|
||||
test "Does not add an avatar image if the user hasn't set one" do
|
||||
user = insert(:user)
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
|
|
@ -105,10 +121,20 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
info = Map.put(user.info, :hide_followers, true)
|
||||
info = Map.merge(user.info, %{hide_followers_count: true, hide_followers: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
|
||||
end
|
||||
|
||||
test "sets correct totalItems when followers are hidden but the follower counter is not" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_followers_count: false, hide_followers: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "following" do
|
||||
|
|
@ -117,9 +143,50 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
info = Map.put(user.info, :hide_follows, true)
|
||||
info = Map.merge(user.info, %{hide_follows_count: true, hide_follows: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
|
||||
test "sets correct totalItems when follows are hidden but the follow counter is not" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_follows_count: false, hide_follows: true})
|
||||
user = Map.put(user, :info, info)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
test "activity collection page aginates correctly" do
|
||||
user = insert(:user)
|
||||
|
||||
posts =
|
||||
for i <- 0..25 do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "post #{i}"})
|
||||
activity
|
||||
end
|
||||
|
||||
# outbox sorts chronologically, newest first, with ten per page
|
||||
posts = Enum.reverse(posts)
|
||||
|
||||
%{"next" => next_url} =
|
||||
UserView.render("activity_collection_page.json", %{
|
||||
iri: "#{user.ap_id}/outbox",
|
||||
activities: Enum.take(posts, 10)
|
||||
})
|
||||
|
||||
next_id = Enum.at(posts, 9).id
|
||||
assert next_url =~ next_id
|
||||
|
||||
%{"next" => next_url} =
|
||||
UserView.render("activity_collection_page.json", %{
|
||||
iri: "#{user.ap_id}/outbox",
|
||||
activities: Enum.take(Enum.drop(posts, 10), 10)
|
||||
})
|
||||
|
||||
next_id = Enum.at(posts, 19).id
|
||||
assert next_url =~ next_id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -574,18 +576,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "/api/pleroma/admin/users/invite_token" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/pleroma/admin/users/invite_token")
|
||||
|
||||
assert conn.status == 200
|
||||
end
|
||||
|
||||
test "/api/pleroma/admin/users/:nickname/password_reset" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
|
@ -596,7 +586,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> put_req_header("accept", "application/json")
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/password_reset")
|
||||
|
||||
assert conn.status == 200
|
||||
resp = json_response(conn, 200)
|
||||
|
||||
assert Regex.match?(~r/(http:\/\/|https:\/\/)/, resp["link"])
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users" do
|
||||
|
|
@ -1064,7 +1056,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{admin.nickname} deactivated user @#{user.nickname}"
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/invite_token" do
|
||||
describe "POST /api/pleroma/admin/users/invite_token" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
|
|
@ -1076,10 +1068,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "without options", %{conn: conn} do
|
||||
conn = get(conn, "/api/pleroma/admin/users/invite_token")
|
||||
conn = post(conn, "/api/pleroma/admin/users/invite_token")
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
refute invite.used
|
||||
refute invite.expires_at
|
||||
refute invite.max_use
|
||||
|
|
@ -1088,12 +1080,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
test "with expires_at", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"expires_at" => Date.to_string(Date.utc_today())}
|
||||
post(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"expires_at" => Date.to_string(Date.utc_today())
|
||||
})
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
|
||||
refute invite.used
|
||||
assert invite.expires_at == Date.utc_today()
|
||||
|
|
@ -1102,13 +1094,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "with max_use", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"max_use" => 150}
|
||||
})
|
||||
conn = post(conn, "/api/pleroma/admin/users/invite_token", %{"max_use" => 150})
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
refute invite.used
|
||||
refute invite.expires_at
|
||||
assert invite.max_use == 150
|
||||
|
|
@ -1117,12 +1106,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
test "with max use and expires_at", %{conn: conn} do
|
||||
conn =
|
||||
get(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"invite" => %{"max_use" => 150, "expires_at" => Date.to_string(Date.utc_today())}
|
||||
post(conn, "/api/pleroma/admin/users/invite_token", %{
|
||||
"max_use" => 150,
|
||||
"expires_at" => Date.to_string(Date.utc_today())
|
||||
})
|
||||
|
||||
token = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(token)
|
||||
invite_json = json_response(conn, 200)
|
||||
invite = UserInviteToken.find_by_token!(invite_json["token"])
|
||||
refute invite.used
|
||||
assert invite.expires_at == Date.utc_today()
|
||||
assert invite.max_use == 150
|
||||
|
|
@ -1309,6 +1299,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert Enum.empty?(response["reports"])
|
||||
assert response["total"] == 0
|
||||
end
|
||||
|
||||
test "returns reports", %{conn: conn} do
|
||||
|
|
@ -1331,6 +1322,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert length(response["reports"]) == 1
|
||||
assert report["id"] == report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
end
|
||||
|
||||
test "returns reports with specified state", %{conn: conn} do
|
||||
|
|
@ -1364,6 +1357,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert length(response["reports"]) == 1
|
||||
assert open_report["id"] == first_report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports", %{
|
||||
|
|
@ -1376,6 +1371,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert length(response["reports"]) == 1
|
||||
assert closed_report["id"] == second_report_id
|
||||
|
||||
assert response["total"] == 1
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports", %{
|
||||
|
|
@ -1384,6 +1381,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert Enum.empty?(response["reports"])
|
||||
assert response["total"] == 0
|
||||
end
|
||||
|
||||
test "returns 403 when requested by a non-admin" do
|
||||
|
|
@ -2096,7 +2094,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
post(conn, "/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
"group" => "pleroma_job_queue",
|
||||
"group" => "oban",
|
||||
"key" => ":queues",
|
||||
"value" => [
|
||||
%{"tuple" => [":federator_incoming", 50]},
|
||||
|
|
@ -2114,7 +2112,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert json_response(conn, 200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"group" => "pleroma_job_queue",
|
||||
"group" => "oban",
|
||||
"key" => ":queues",
|
||||
"value" => [
|
||||
%{"tuple" => [":federator_incoming", 50]},
|
||||
|
|
@ -2259,8 +2257,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
describe "GET /api/pleroma/admin/moderation_log" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
moderator = insert(:user, info: %{is_moderator: true})
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
%{conn: assign(conn, :user, admin), admin: admin, moderator: moderator}
|
||||
end
|
||||
|
||||
test "returns the log", %{conn: conn, admin: admin} do
|
||||
|
|
@ -2293,9 +2292,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
conn = get(conn, "/api/pleroma/admin/moderation_log")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
[first_entry, second_entry] = response
|
||||
[first_entry, second_entry] = response["items"]
|
||||
|
||||
assert response |> length() == 2
|
||||
assert response["total"] == 2
|
||||
assert first_entry["data"]["action"] == "relay_unfollow"
|
||||
|
||||
assert first_entry["message"] ==
|
||||
|
|
@ -2337,9 +2336,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
conn1 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=1")
|
||||
|
||||
response1 = json_response(conn1, 200)
|
||||
[first_entry] = response1
|
||||
[first_entry] = response1["items"]
|
||||
|
||||
assert response1 |> length() == 1
|
||||
assert response1["total"] == 2
|
||||
assert response1["items"] |> length() == 1
|
||||
assert first_entry["data"]["action"] == "relay_unfollow"
|
||||
|
||||
assert first_entry["message"] ==
|
||||
|
|
@ -2348,14 +2348,143 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
conn2 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=2")
|
||||
|
||||
response2 = json_response(conn2, 200)
|
||||
[second_entry] = response2
|
||||
[second_entry] = response2["items"]
|
||||
|
||||
assert response2 |> length() == 1
|
||||
assert response2["total"] == 2
|
||||
assert response2["items"] |> length() == 1
|
||||
assert second_entry["data"]["action"] == "relay_follow"
|
||||
|
||||
assert second_entry["message"] ==
|
||||
"@#{admin.nickname} followed relay: https://example.org/relay"
|
||||
end
|
||||
|
||||
test "filters log by date", %{conn: conn, admin: admin} do
|
||||
first_date = "2017-08-15T15:47:06Z"
|
||||
second_date = "2017-08-20T15:47:06Z"
|
||||
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_follow",
|
||||
target: "https://example.org/relay"
|
||||
},
|
||||
inserted_at: NaiveDateTime.from_iso8601!(first_date)
|
||||
})
|
||||
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_unfollow",
|
||||
target: "https://example.org/relay"
|
||||
},
|
||||
inserted_at: NaiveDateTime.from_iso8601!(second_date)
|
||||
})
|
||||
|
||||
conn1 =
|
||||
get(
|
||||
conn,
|
||||
"/api/pleroma/admin/moderation_log?start_date=#{second_date}"
|
||||
)
|
||||
|
||||
response1 = json_response(conn1, 200)
|
||||
[first_entry] = response1["items"]
|
||||
|
||||
assert response1["total"] == 1
|
||||
assert first_entry["data"]["action"] == "relay_unfollow"
|
||||
|
||||
assert first_entry["message"] ==
|
||||
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
|
||||
end
|
||||
|
||||
test "returns log filtered by user", %{conn: conn, admin: admin, moderator: moderator} do
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_follow",
|
||||
target: "https://example.org/relay"
|
||||
}
|
||||
})
|
||||
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => moderator.id,
|
||||
"nickname" => moderator.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_unfollow",
|
||||
target: "https://example.org/relay"
|
||||
}
|
||||
})
|
||||
|
||||
conn1 = get(conn, "/api/pleroma/admin/moderation_log?user_id=#{moderator.id}")
|
||||
|
||||
response1 = json_response(conn1, 200)
|
||||
[first_entry] = response1["items"]
|
||||
|
||||
assert response1["total"] == 1
|
||||
assert get_in(first_entry, ["data", "actor", "id"]) == moderator.id
|
||||
end
|
||||
|
||||
test "returns log filtered by search", %{conn: conn, moderator: moderator} do
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "relay_follow",
|
||||
target: "https://example.org/relay"
|
||||
})
|
||||
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "relay_unfollow",
|
||||
target: "https://example.org/relay"
|
||||
})
|
||||
|
||||
conn1 = get(conn, "/api/pleroma/admin/moderation_log?search=unfo")
|
||||
|
||||
response1 = json_response(conn1, 200)
|
||||
[first_entry] = response1["items"]
|
||||
|
||||
assert response1["total"] == 1
|
||||
|
||||
assert get_in(first_entry, ["data", "message"]) ==
|
||||
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /users/:nickname/force_password_reset" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin, user: user}
|
||||
end
|
||||
|
||||
test "sets password_reset_pending to true", %{admin: admin, user: user} do
|
||||
assert user.info.password_reset_pending == false
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> patch("/api/pleroma/admin/users/#{user.nickname}/force_password_reset")
|
||||
|
||||
assert json_response(conn, 204) == ""
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert User.get_by_id(user.id).info.password_reset_pending == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.SearchTest do
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.AdminAPI.Report
|
||||
alias Pleroma.Web.AdminAPI.ReportView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
|
@ -34,7 +35,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
}
|
||||
|
||||
result =
|
||||
ReportView.render("show.json", %{report: activity})
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
|> Map.delete(:created_at)
|
||||
|
||||
assert result == expected
|
||||
|
|
@ -60,13 +61,13 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
AccountView.render("account.json", %{user: other_user}),
|
||||
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
),
|
||||
statuses: [StatusView.render("status.json", %{activity: activity})],
|
||||
statuses: [StatusView.render("show.json", %{activity: activity})],
|
||||
state: "open",
|
||||
id: report_activity.id
|
||||
}
|
||||
|
||||
result =
|
||||
ReportView.render("show.json", %{report: report_activity})
|
||||
ReportView.render("show.json", Report.extract_report_info(report_activity))
|
||||
|> Map.delete(:created_at)
|
||||
|
||||
assert result == expected
|
||||
|
|
@ -78,7 +79,9 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
|
||||
{:ok, activity} = CommonAPI.report(user, %{"account_id" => other_user.id})
|
||||
{:ok, activity} = CommonAPI.update_report_state(activity.id, "closed")
|
||||
assert %{state: "closed"} = ReportView.render("show.json", %{report: activity})
|
||||
|
||||
assert %{state: "closed"} =
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
end
|
||||
|
||||
test "renders report description" do
|
||||
|
|
@ -92,7 +95,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
})
|
||||
|
||||
assert %{content: "posts are too good for this instance"} =
|
||||
ReportView.render("show.json", %{report: activity})
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
end
|
||||
|
||||
test "sanitizes report description" do
|
||||
|
|
@ -109,7 +112,7 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
activity = Map.put(activity, :data, data)
|
||||
|
||||
refute "<script> alert('hecked :D:D:D:D:D:D:D') </script>" ==
|
||||
ReportView.render("show.json", %{report: activity})[:content]
|
||||
ReportView.render("show.json", Report.extract_report_info(activity))[:content]
|
||||
end
|
||||
|
||||
test "doesn't error out when the user doesn't exists" do
|
||||
|
|
@ -125,6 +128,6 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
Pleroma.User.delete(other_user)
|
||||
Pleroma.User.invalidate_cache(other_user)
|
||||
|
||||
assert %{} = ReportView.render("show.json", %{report: activity})
|
||||
assert %{} = ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -524,4 +524,43 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
|
||||
end
|
||||
end
|
||||
|
||||
describe "listen/2" do
|
||||
test "returns a valid activity" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 1",
|
||||
"album" => "lain radio",
|
||||
"artist" => "lain",
|
||||
"length" => 180_000
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
|
||||
assert Visibility.get_visibility(activity) == "public"
|
||||
end
|
||||
|
||||
test "respects visibility=private" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 1",
|
||||
"album" => "lain radio",
|
||||
"artist" => "lain",
|
||||
"length" => 180_000,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
|
||||
assert Visibility.get_visibility(activity) == "private"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
||||
|
|
@ -157,11 +157,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
|
||||
|
||||
expected =
|
||||
"<p><strong>hello world</strong></p>\n<p><em>another <span class=\"h-card\"><a data-user=\"#{
|
||||
~s(<p><strong>hello world</strong></p>\n<p><em>another <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> and <span class=\"h-card\"><a data-user=\"#{
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n"
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>\n)
|
||||
|
||||
{output, _, _} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.DigestEmailWorkerTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.DigestEmailWorker
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
test "it sends digest emails" do
|
||||
user = insert(:user)
|
||||
|
||||
date =
|
||||
Timex.now()
|
||||
|> Timex.shift(days: -10)
|
||||
|> Timex.to_naive_datetime()
|
||||
|
||||
user2 = insert(:user, last_digest_emailed_at: date)
|
||||
User.switch_email_notifications(user2, "digest", true)
|
||||
CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
|
||||
|
||||
DigestEmailWorker.perform()
|
||||
|
||||
assert_received {:email, email}
|
||||
assert email.to == [{user2.name, user2.email}]
|
||||
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
|
||||
end
|
||||
end
|
||||
|
|
@ -1,12 +1,17 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.FederatorTest do
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Federator
|
||||
alias Pleroma.Workers.PublisherWorker
|
||||
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
|
|
@ -24,15 +29,6 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
clear_config([:instance, :rewrite_policy])
|
||||
clear_config([:mrf_keyword])
|
||||
|
||||
describe "Publisher.perform" do
|
||||
test "call `perform` with unknown task" do
|
||||
assert {
|
||||
:error,
|
||||
"Don't know what to do with this"
|
||||
} = Pleroma.Web.Federator.Publisher.perform("test", :ok, :ok)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Publish an activity" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -53,6 +49,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
} do
|
||||
with_mocks([relay_mock]) do
|
||||
Federator.publish(activity)
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
end
|
||||
|
||||
assert_received :relay_publish
|
||||
|
|
@ -66,6 +63,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
with_mocks([relay_mock]) do
|
||||
Federator.publish(activity)
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
end
|
||||
|
||||
refute_received :relay_publish
|
||||
|
|
@ -73,10 +71,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
end
|
||||
|
||||
describe "Targets reachability filtering in `publish`" do
|
||||
test_with_mock "it federates only to reachable instances via AP",
|
||||
Pleroma.Web.ActivityPub.Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "it federates only to reachable instances via AP" do
|
||||
user = insert(:user)
|
||||
|
||||
{inbox1, inbox2} =
|
||||
|
|
@ -104,20 +99,20 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.ActivityPub.Publisher.publish_one(%{
|
||||
inbox: inbox1,
|
||||
unreachable_since: dt
|
||||
})
|
||||
)
|
||||
expected_dt = NaiveDateTime.to_iso8601(dt)
|
||||
|
||||
refute called(Pleroma.Web.ActivityPub.Publisher.publish_one(%{inbox: inbox2}))
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "publish_one",
|
||||
"params" => %{"inbox" => inbox1, "unreachable_since" => expected_dt}
|
||||
},
|
||||
all_enqueued(worker: PublisherWorker)
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "it federates only to reachable instances via Websub",
|
||||
Pleroma.Web.Websub,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "it federates only to reachable instances via Websub" do
|
||||
user = insert(:user)
|
||||
websub_topic = Pleroma.Web.OStatus.feed_path(user)
|
||||
|
||||
|
|
@ -142,23 +137,27 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Websub.publish_one(%{
|
||||
callback: sub2.callback,
|
||||
unreachable_since: dt
|
||||
})
|
||||
)
|
||||
expected_callback = sub2.callback
|
||||
expected_dt = NaiveDateTime.to_iso8601(dt)
|
||||
|
||||
refute called(Pleroma.Web.Websub.publish_one(%{callback: sub1.callback}))
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "publish_one",
|
||||
"params" => %{
|
||||
"callback" => expected_callback,
|
||||
"unreachable_since" => expected_dt
|
||||
}
|
||||
},
|
||||
all_enqueued(worker: PublisherWorker)
|
||||
)
|
||||
end
|
||||
|
||||
test_with_mock "it federates only to reachable instances via Salmon",
|
||||
Pleroma.Web.Salmon,
|
||||
[:passthrough],
|
||||
[] do
|
||||
test "it federates only to reachable instances via Salmon" do
|
||||
user = insert(:user)
|
||||
|
||||
remote_user1 =
|
||||
_remote_user1 =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "nick1@domain.com",
|
||||
|
|
@ -174,6 +173,8 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
info: %{salmon: "https://domain2.com/salmon"}
|
||||
})
|
||||
|
||||
remote_user2_id = remote_user2.id
|
||||
|
||||
dt = NaiveDateTime.utc_now()
|
||||
Instances.set_unreachable(remote_user2.ap_id, dt)
|
||||
|
||||
|
|
@ -182,14 +183,20 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
||||
|
||||
assert called(
|
||||
Pleroma.Web.Salmon.publish_one(%{
|
||||
recipient: remote_user2,
|
||||
unreachable_since: dt
|
||||
})
|
||||
)
|
||||
expected_dt = NaiveDateTime.to_iso8601(dt)
|
||||
|
||||
refute called(Pleroma.Web.Salmon.publish_one(%{recipient: remote_user1}))
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "publish_one",
|
||||
"params" => %{
|
||||
"recipient_id" => remote_user2_id,
|
||||
"unreachable_since" => expected_dt
|
||||
}
|
||||
},
|
||||
all_enqueued(worker: PublisherWorker)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -209,7 +216,8 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
||||
{:ok, _activity} = Federator.incoming_ap_doc(params)
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert {:ok, _activity} = ObanHelpers.perform(job)
|
||||
end
|
||||
|
||||
test "rejects incoming AP docs with incorrect origin" do
|
||||
|
|
@ -227,7 +235,8 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
"to" => ["https://www.w3.org/ns/activitystreams#Public"]
|
||||
}
|
||||
|
||||
:error = Federator.incoming_ap_doc(params)
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert :error = ObanHelpers.perform(job)
|
||||
end
|
||||
|
||||
test "it does not crash if MRF rejects the post" do
|
||||
|
|
@ -242,7 +251,8 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
assert Federator.incoming_ap_doc(params) == :error
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert :error = ObanHelpers.perform(job)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Instances.InstanceTest do
|
||||
|
|
@ -16,7 +16,8 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
|
||||
describe "set_reachable/1" do
|
||||
test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
|
||||
instance = insert(:instance, unreachable_since: NaiveDateTime.utc_now())
|
||||
unreachable_since = NaiveDateTime.to_iso8601(NaiveDateTime.utc_now())
|
||||
instance = insert(:instance, unreachable_since: unreachable_since)
|
||||
|
||||
assert {:ok, instance} = Instance.set_reachable(instance.host)
|
||||
refute instance.unreachable_since
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.InstancesTest do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,75 @@
|
|||
# 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.ConversationControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "Conversations", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|
||||
assert response = json_response(res_conn, 200)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"id" => res_id,
|
||||
"accounts" => res_accounts,
|
||||
"last_status" => res_last_status,
|
||||
"unread" => unread
|
||||
}
|
||||
] = response
|
||||
|
||||
account_ids = Enum.map(res_accounts, & &1["id"])
|
||||
assert length(res_accounts) == 2
|
||||
assert user_two.id in account_ids
|
||||
assert user_three.id in account_ids
|
||||
assert is_binary(res_id)
|
||||
assert unread == true
|
||||
assert res_last_status["id"] == direct.id
|
||||
|
||||
# Apparently undocumented API endpoint
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> post("/api/v1/conversations/#{res_id}/read")
|
||||
|
||||
assert response = json_response(res_conn, 200)
|
||||
assert length(response["accounts"]) == 2
|
||||
assert response["last_status"]["id"] == direct.id
|
||||
assert response["unread"] == false
|
||||
|
||||
# (vanilla) Mastodon frontend behaviour
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/statuses/#{res_last_status["id"]}/context")
|
||||
|
||||
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
# 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.DomainBlockControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.User
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "blocking / unblocking a domain", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert User.blocks?(user, other_user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
refute User.blocks?(user, other_user)
|
||||
end
|
||||
|
||||
test "getting a list of domain blocks", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, user} = User.block_domain(user, "bad.site")
|
||||
{:ok, user} = User.block_domain(user, "even.worse.site")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/domain_blocks")
|
||||
|
||||
domain_blocks = json_response(conn, 200)
|
||||
|
||||
assert "bad.site" in domain_blocks
|
||||
assert "even.worse.site" in domain_blocks
|
||||
end
|
||||
end
|
||||
137
test/web/mastodon_api/controllers/filter_controller_test.exs
Normal file
137
test/web/mastodon_api/controllers/filter_controller_test.exs
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
# 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.FilterControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.MastodonAPI.FilterView
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "creating a filter", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
filter = %Pleroma.Filter{
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/filters", %{"phrase" => filter.phrase, context: filter.context})
|
||||
|
||||
assert response = json_response(conn, 200)
|
||||
assert response["phrase"] == filter.phrase
|
||||
assert response["context"] == filter.context
|
||||
assert response["irreversible"] == false
|
||||
assert response["id"] != nil
|
||||
assert response["id"] != ""
|
||||
end
|
||||
|
||||
test "fetching a list of filters", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
query_one = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 1,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
query_two = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "who",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, filter_one} = Pleroma.Filter.create(query_one)
|
||||
{:ok, filter_two} = Pleroma.Filter.create(query_two)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/filters")
|
||||
|> json_response(200)
|
||||
|
||||
assert response ==
|
||||
render_json(
|
||||
FilterView,
|
||||
"filters.json",
|
||||
filters: [filter_two, filter_one]
|
||||
)
|
||||
end
|
||||
|
||||
test "get a filter", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, filter} = Pleroma.Filter.create(query)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/filters/#{filter.filter_id}")
|
||||
|
||||
assert _response = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "update a filter", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, _filter} = Pleroma.Filter.create(query)
|
||||
|
||||
new = %Pleroma.Filter{
|
||||
phrase: "nii",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/v1/filters/#{query.filter_id}", %{
|
||||
phrase: new.phrase,
|
||||
context: new.context
|
||||
})
|
||||
|
||||
assert response = json_response(conn, 200)
|
||||
assert response["phrase"] == new.phrase
|
||||
assert response["context"] == new.context
|
||||
end
|
||||
|
||||
test "delete a filter", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, filter} = Pleroma.Filter.create(query)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/filters/#{filter.filter_id}")
|
||||
|
||||
assert response = json_response(conn, 200)
|
||||
assert response == %{}
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
# 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.FollowRequestControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "locked accounts" do
|
||||
test "/api/v1/follow_requests works" do
|
||||
user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
||||
assert User.following?(other_user, user) == false
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/follow_requests")
|
||||
|
||||
assert [relationship] = json_response(conn, 200)
|
||||
assert to_string(other_user.id) == relationship["id"]
|
||||
end
|
||||
|
||||
test "/api/v1/follow_requests/:id/authorize works" do
|
||||
user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
||||
assert User.following?(other_user, user) == false
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/follow_requests/#{other_user.id}/authorize")
|
||||
|
||||
assert relationship = json_response(conn, 200)
|
||||
assert to_string(other_user.id) == relationship["id"]
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
||||
assert User.following?(other_user, user) == true
|
||||
end
|
||||
|
||||
test "/api/v1/follow_requests/:id/reject works" do
|
||||
user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/follow_requests/#{other_user.id}/reject")
|
||||
|
||||
assert relationship = json_response(conn, 200)
|
||||
assert to_string(other_user.id) == relationship["id"]
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
||||
assert User.following?(other_user, user) == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -86,10 +86,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user = json_response(conn, 200)
|
||||
|
||||
assert user["note"] ==
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe" rel="tag">#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>)
|
||||
~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
|
||||
}" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span>)
|
||||
end
|
||||
|
||||
test "updates the user's locking status", %{conn: conn} do
|
||||
|
|
@ -128,6 +127,22 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
hide_followers_count: "true",
|
||||
hide_follows_count: "true"
|
||||
})
|
||||
|
||||
assert user = json_response(conn, 200)
|
||||
assert user["pleroma"]["hide_followers_count"] == true
|
||||
assert user["pleroma"]["hide_follows_count"] == true
|
||||
end
|
||||
|
||||
test "updates the user's skip_thread_containment option", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -318,7 +333,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "link", "value" => "<a href=\"http://cofe.io\">cofe.io</a>"}
|
||||
%{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)}
|
||||
]
|
||||
|
||||
assert account["source"]["fields"] == [
|
||||
|
|
|
|||
|
|
@ -0,0 +1,299 @@
|
|||
# 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.NotificationControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "list of notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{
|
||||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "getting a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications/#{notification.id}")
|
||||
|
||||
expected_response =
|
||||
"hi <span class=\"h-card\"><a data-user=\"#{user.id}\" class=\"u-url mention\" href=\"#{
|
||||
user.ap_id
|
||||
}\" rel=\"ugc\">@<span>#{user.nickname}</span></a></span>"
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert response == expected_response
|
||||
end
|
||||
|
||||
test "dismissing a single notification", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/dismiss", %{"id" => notification.id})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "clearing all notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/notifications/clear")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/notifications")
|
||||
|
||||
assert all = json_response(conn, 200)
|
||||
assert all == []
|
||||
end
|
||||
|
||||
test "paginates notifications using min_id, since_id, max_id, and limit", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity3} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity4} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
notification1_id = get_notification_id_by_activity(activity1)
|
||||
notification2_id = get_notification_id_by_activity(activity2)
|
||||
notification3_id = get_notification_id_by_activity(activity3)
|
||||
notification4_id = get_notification_id_by_activity(activity4)
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
# min_id
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&min_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
|
||||
# since_id
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&since_id=#{notification1_id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
# max_id
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?limit=2&max_id=#{notification4_id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
||||
test "filters notifications using exclude_types", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
|
||||
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
mention_notification_id = get_notification_id_by_activity(mention_activity)
|
||||
favorite_notification_id = get_notification_id_by_activity(favorite_activity)
|
||||
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
|
||||
follow_notification_id = get_notification_id_by_activity(follow_activity)
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["mention", "favourite", "reblog"]})
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["favourite", "reblog", "follow"]})
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["reblog", "follow", "mention"]})
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{exclude_types: ["follow", "mention", "favourite"]})
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
end
|
||||
|
||||
test "destroy multiple", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity2} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity3} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||
{:ok, activity4} = CommonAPI.post(user, %{"status" => "hi @#{other_user.nickname}"})
|
||||
|
||||
notification1_id = get_notification_id_by_activity(activity1)
|
||||
notification2_id = get_notification_id_by_activity(activity2)
|
||||
notification3_id = get_notification_id_by_activity(activity3)
|
||||
notification4_id = get_notification_id_by_activity(activity4)
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification2_id}, %{"id" => ^notification1_id}] = result
|
||||
|
||||
conn2 =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|
||||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
conn_destroy =
|
||||
conn
|
||||
|> delete("/api/v1/notifications/destroy_multiple", %{
|
||||
"ids" => [notification1_id, notification2_id]
|
||||
})
|
||||
|
||||
assert json_response(conn_destroy, 200) == %{}
|
||||
|
||||
result =
|
||||
conn2
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
end
|
||||
|
||||
test "doesn't see notifications after muting user with notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
end
|
||||
|
||||
test "see notifications after muting user without notifications", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2, false)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see notifications after muting user with notifications and with_muted parameter", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, user2)
|
||||
{:ok, _} = CommonAPI.post(user2, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
|
||||
{:ok, user} = User.mute(user, user2)
|
||||
|
||||
conn = assign(build_conn(), :user, user)
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_muted" => "true"})
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
defp get_notification_id_by_activity(%{id: id}) do
|
||||
Notification
|
||||
|> Repo.get_by(activity_id: id)
|
||||
|> Map.get(:id)
|
||||
|> to_string()
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
# 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.ScheduledActivityControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "shows scheduled activities", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
scheduled_activity_id1 = insert(:scheduled_activity, user: user).id |> to_string()
|
||||
scheduled_activity_id2 = insert(:scheduled_activity, user: user).id |> to_string()
|
||||
scheduled_activity_id3 = insert(:scheduled_activity, user: user).id |> to_string()
|
||||
scheduled_activity_id4 = insert(:scheduled_activity, user: user).id |> to_string()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|
||||
# min_id
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/scheduled_statuses?limit=2&min_id=#{scheduled_activity_id1}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
|
||||
|
||||
# since_id
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/scheduled_statuses?limit=2&since_id=#{scheduled_activity_id1}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^scheduled_activity_id4}, %{"id" => ^scheduled_activity_id3}] = result
|
||||
|
||||
# max_id
|
||||
conn_res =
|
||||
conn
|
||||
|> get("/api/v1/scheduled_statuses?limit=2&max_id=#{scheduled_activity_id4}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^scheduled_activity_id3}, %{"id" => ^scheduled_activity_id2}] = result
|
||||
end
|
||||
|
||||
test "shows a scheduled activity", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
scheduled_activity = insert(:scheduled_activity, user: user)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
|
||||
|
||||
assert %{"id" => scheduled_activity_id} = json_response(res_conn, 200)
|
||||
assert scheduled_activity_id == scheduled_activity.id |> to_string()
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/scheduled_statuses/404")
|
||||
|
||||
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
|
||||
end
|
||||
|
||||
test "updates a scheduled activity", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
scheduled_activity = insert(:scheduled_activity, user: user)
|
||||
|
||||
new_scheduled_at =
|
||||
NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/v1/scheduled_statuses/#{scheduled_activity.id}", %{
|
||||
scheduled_at: new_scheduled_at
|
||||
})
|
||||
|
||||
assert %{"scheduled_at" => expected_scheduled_at} = json_response(res_conn, 200)
|
||||
assert expected_scheduled_at == Pleroma.Web.CommonAPI.Utils.to_masto_date(new_scheduled_at)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/v1/scheduled_statuses/404", %{scheduled_at: new_scheduled_at})
|
||||
|
||||
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
|
||||
end
|
||||
|
||||
test "deletes a scheduled activity", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
scheduled_activity = insert(:scheduled_activity, user: user)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
|
||||
|
||||
assert %{} = json_response(res_conn, 200)
|
||||
assert nil == Repo.get(ScheduledActivity, scheduled_activity.id)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/scheduled_statuses/#{scheduled_activity.id}")
|
||||
|
||||
assert %{"error" => "Record not found"} = json_response(res_conn, 404)
|
||||
end
|
||||
end
|
||||
1210
test/web/mastodon_api/controllers/status_controller_test.exs
Normal file
1210
test/web/mastodon_api/controllers/status_controller_test.exs
Normal file
File diff suppressed because it is too large
Load diff
291
test/web/mastodon_api/controllers/timeline_controller_test.exs
Normal file
291
test/web/mastodon_api/controllers/timeline_controller_test.exs
Normal file
|
|
@ -0,0 +1,291 @@
|
|||
# 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.TimelineControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
|
||||
clear_config([:instance, :public])
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "the home timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
following = insert(:user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home")
|
||||
|
||||
assert Enum.empty?(json_response(conn, :ok))
|
||||
|
||||
{:ok, user} = User.follow(user, following)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home")
|
||||
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
describe "public" do
|
||||
@tag capture_log: true
|
||||
test "the public timeline", %{conn: conn} do
|
||||
following = insert(:user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
|
||||
{:ok, [_activity]} =
|
||||
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/public", %{"local" => "False"})
|
||||
|
||||
assert length(json_response(conn, :ok)) == 2
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public", %{"local" => "True"})
|
||||
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public", %{"local" => "1"})
|
||||
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
test "the public timeline when public is set to false", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
assert %{"error" => "This resource requires authentication."} ==
|
||||
conn
|
||||
|> get("/api/v1/timelines/public", %{"local" => "False"})
|
||||
|> json_response(:forbidden)
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "private"})
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "unlisted"})
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "direct" do
|
||||
test "direct timeline", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
# Only direct should be visible here
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("api/v1/timelines/direct")
|
||||
|
||||
[status] = json_response(res_conn, :ok)
|
||||
|
||||
assert %{"visibility" => "direct"} = status
|
||||
assert status["url"] != direct.data["id"]
|
||||
|
||||
# User should be able to see their own direct message
|
||||
res_conn =
|
||||
build_conn()
|
||||
|> assign(:user, user_one)
|
||||
|> get("api/v1/timelines/direct")
|
||||
|
||||
[status] = json_response(res_conn, :ok)
|
||||
|
||||
assert %{"visibility" => "direct"} = status
|
||||
|
||||
# Both should be visible here
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("api/v1/timelines/home")
|
||||
|
||||
[_s1, _s2] = json_response(res_conn, :ok)
|
||||
|
||||
# Test pagination
|
||||
Enum.each(1..20, fn _ ->
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
end)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("api/v1/timelines/direct")
|
||||
|
||||
statuses = json_response(res_conn, :ok)
|
||||
assert length(statuses) == 20
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("api/v1/timelines/direct", %{max_id: List.last(statuses)["id"]})
|
||||
|
||||
[status] = json_response(res_conn, :ok)
|
||||
|
||||
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, :ok)
|
||||
assert status["id"] == direct.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "list" do
|
||||
test "list timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
|
||||
{:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/list/#{list.id}")
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, :ok)
|
||||
|
||||
assert id == to_string(activity_two.id)
|
||||
end
|
||||
|
||||
test "list timeline does not leak non-public statuses for unfollowed users", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
|
||||
|
||||
{:ok, _activity_two} =
|
||||
CommonAPI.post(other_user, %{
|
||||
"status" => "Marisa is cute.",
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/list/#{list.id}")
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, :ok)
|
||||
|
||||
assert id == to_string(activity_one.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "hashtag" do
|
||||
@tag capture_log: true
|
||||
test "hashtag timeline", %{conn: conn} do
|
||||
following = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
|
||||
|
||||
{:ok, [_activity]} =
|
||||
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
|
||||
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2hu")
|
||||
|
||||
assert [%{"id" => id}] = json_response(nconn, :ok)
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
|
||||
# works for different capitalization too
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2HU")
|
||||
|
||||
assert [%{"id" => id}] = json_response(nconn, :ok)
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "multi-hashtag timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity_test} = CommonAPI.post(user, %{"status" => "#test"})
|
||||
{:ok, activity_test1} = CommonAPI.post(user, %{"status" => "#test #test1"})
|
||||
{:ok, activity_none} = CommonAPI.post(user, %{"status" => "#test #none"})
|
||||
|
||||
any_test = get(conn, "/api/v1/timelines/tag/test", %{"any" => ["test1"]})
|
||||
|
||||
[status_none, status_test1, status_test] = json_response(any_test, :ok)
|
||||
|
||||
assert to_string(activity_test.id) == status_test["id"]
|
||||
assert to_string(activity_test1.id) == status_test1["id"]
|
||||
assert to_string(activity_none.id) == status_none["id"]
|
||||
|
||||
restricted_test =
|
||||
get(conn, "/api/v1/timelines/tag/test", %{"all" => ["test1"], "none" => ["none"]})
|
||||
|
||||
assert [status_test1] == json_response(restricted_test, :ok)
|
||||
|
||||
all_test = get(conn, "/api/v1/timelines/tag/test", %{"all" => ["none"]})
|
||||
|
||||
assert [status_none] == json_response(all_test, :ok)
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
|
|
@ -67,7 +67,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: "valid html",
|
||||
sensitive: false,
|
||||
pleroma: %{},
|
||||
pleroma: %{
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
|
|
@ -79,6 +81,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false
|
||||
}
|
||||
|
|
@ -135,7 +139,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{},
|
||||
pleroma: %{
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
|
|
@ -147,6 +153,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{},
|
||||
skip_thread_containment: false
|
||||
}
|
||||
|
|
@ -306,7 +314,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{},
|
||||
pleroma: %{
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
|
|
@ -318,6 +328,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{
|
||||
id: to_string(user.id),
|
||||
following: false,
|
||||
|
|
@ -361,8 +373,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
describe "hiding follows/following" do
|
||||
test "shows when follows/following are hidden and sets follower/following count to 0" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
test "shows when follows/followers stats are hidden and sets follow/follower count to 0" do
|
||||
info = %{
|
||||
hide_followers: true,
|
||||
hide_followers_count: true,
|
||||
hide_follows: true,
|
||||
hide_follows_count: true
|
||||
}
|
||||
|
||||
user = insert(:user, info: info)
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
|
@ -370,6 +390,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert %{
|
||||
followers_count: 0,
|
||||
following_count: 0,
|
||||
pleroma: %{hide_follows_count: true, hide_followers_count: true}
|
||||
} = AccountView.render("account.json", %{user: user})
|
||||
end
|
||||
|
||||
test "shows when follows/followers are hidden" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{
|
||||
followers_count: 1,
|
||||
following_count: 1,
|
||||
pleroma: %{hide_follows: true, hide_followers: true}
|
||||
} = AccountView.render("account.json", %{user: user})
|
||||
end
|
||||
|
|
@ -386,4 +419,79 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
} = AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow requests counter" do
|
||||
test "shows zero when no follow requests are pending" do
|
||||
user = insert(:user)
|
||||
|
||||
assert %{follow_requests_count: 0} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{follow_requests_count: 0} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "shows non-zero when follow requests are pending" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
|
||||
assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{locked: true, follow_requests_count: 1} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "decreases when accepting a follow request" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
|
||||
assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{locked: true, follow_requests_count: 1} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
{:ok, _other_user} = CommonAPI.accept_follow_request(other_user, user)
|
||||
|
||||
assert %{locked: true, follow_requests_count: 0} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "decreases when rejecting a follow request" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
|
||||
assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
assert %{locked: true, follow_requests_count: 1} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
{:ok, _other_user} = CommonAPI.reject_follow_request(other_user, user)
|
||||
|
||||
assert %{locked: true, follow_requests_count: 0} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "shows non-zero when historical unapproved requests are present" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
|
||||
assert %{locked: true} = AccountView.render("account.json", %{user: user, for: user})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
{:ok, user} = User.update_info(user, &User.Info.user_upgrade(&1, %{locked: false}))
|
||||
|
||||
assert %{locked: false, follow_requests_count: 1} =
|
||||
AccountView.render("account.json", %{user: user, for: user})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ListViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
||||
|
|
@ -28,7 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
pleroma: %{is_seen: false},
|
||||
type: "mention",
|
||||
account: AccountView.render("account.json", %{user: user, for: mentioned_user}),
|
||||
status: StatusView.render("status.json", %{activity: activity, for: mentioned_user}),
|
||||
status: StatusView.render("show.json", %{activity: activity, for: mentioned_user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
pleroma: %{is_seen: false},
|
||||
type: "favourite",
|
||||
account: AccountView.render("account.json", %{user: another_user, for: user}),
|
||||
status: StatusView.render("status.json", %{activity: create_activity, for: user}),
|
||||
status: StatusView.render("show.json", %{activity: create_activity, for: user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
pleroma: %{is_seen: false},
|
||||
type: "reblog",
|
||||
account: AccountView.render("account.json", %{user: another_user, for: user}),
|
||||
status: StatusView.render("status.json", %{activity: reblog_activity, for: user}),
|
||||
status: StatusView.render("show.json", %{activity: reblog_activity, for: user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
|
||||
status =
|
||||
StatusView.render("status.json",
|
||||
StatusView.render("show.json",
|
||||
activity: activity,
|
||||
with_direct_conversation_id: true,
|
||||
for: user
|
||||
|
|
@ -46,7 +46,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
Repo.delete(user)
|
||||
Cachex.clear(:user_cache)
|
||||
|
||||
%{account: ms_user} = StatusView.render("status.json", activity: activity)
|
||||
%{account: ms_user} = StatusView.render("show.json", activity: activity)
|
||||
|
||||
assert ms_user.acct == "erroruser@example.com"
|
||||
end
|
||||
|
|
@ -63,7 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
Cachex.clear(:user_cache)
|
||||
|
||||
result = StatusView.render("status.json", activity: activity)
|
||||
result = StatusView.render("show.json", activity: activity)
|
||||
|
||||
assert result[:account][:id] == to_string(user.id)
|
||||
end
|
||||
|
|
@ -81,7 +81,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
User.get_cached_by_ap_id(note.data["actor"])
|
||||
|
||||
status = StatusView.render("status.json", %{activity: note})
|
||||
status = StatusView.render("show.json", %{activity: note})
|
||||
|
||||
assert status.content == ""
|
||||
end
|
||||
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
convo_id = Utils.context_to_conversation_id(object_data["context"])
|
||||
|
||||
status = StatusView.render("status.json", %{activity: note})
|
||||
status = StatusView.render("show.json", %{activity: note})
|
||||
|
||||
created_at =
|
||||
(object_data["published"] || "")
|
||||
|
|
@ -165,11 +165,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
{:ok, user} = User.mute(user, other_user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.muted == false
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.muted == true
|
||||
end
|
||||
|
|
@ -181,13 +181,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
{:ok, user} = User.mute(user, other_user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.pleroma.thread_muted == false
|
||||
|
||||
{:ok, activity} = CommonAPI.add_mute(user, activity)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.pleroma.thread_muted == true
|
||||
end
|
||||
|
|
@ -196,11 +196,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Cute girls doing cute things"})
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.bookmarked == false
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.bookmarked == false
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
activity = Activity.get_by_id_with_object(activity.id)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert status.bookmarked == true
|
||||
end
|
||||
|
|
@ -220,7 +220,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id})
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.in_reply_to_id == to_string(note.id)
|
||||
|
||||
|
|
@ -237,7 +237,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.mentions ==
|
||||
Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
|
||||
|
|
@ -263,7 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
assert length(activity.recipients) == 3
|
||||
|
||||
%{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
|
||||
%{mentions: [mention] = mentions} = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert length(mentions) == 1
|
||||
assert mention.url == recipient_ap_id
|
||||
|
|
@ -300,7 +300,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
assert length(activity.recipients) == 3
|
||||
|
||||
%{mentions: [mention] = mentions} = StatusView.render("status.json", %{activity: activity})
|
||||
%{mentions: [mention] = mentions} = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert length(mentions) == 1
|
||||
assert mention.url == recipient.ap_id
|
||||
|
|
@ -340,7 +340,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810"
|
||||
[activity] = Activity.search(nil, id)
|
||||
|
||||
status = StatusView.render("status.json", %{activity: activity})
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.uri == id
|
||||
assert status.url == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
|
||||
|
|
@ -352,7 +352,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
{:ok, reblog, _} = CommonAPI.repeat(activity.id, user)
|
||||
|
||||
represented = StatusView.render("status.json", %{for: user, activity: reblog})
|
||||
represented = StatusView.render("show.json", %{for: user, activity: reblog})
|
||||
|
||||
assert represented[:id] == to_string(reblog.id)
|
||||
assert represented[:reblog][:id] == to_string(activity.id)
|
||||
|
|
@ -369,7 +369,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
%Activity{} = activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||
|
||||
represented = StatusView.render("status.json", %{for: user, activity: activity})
|
||||
represented = StatusView.render("show.json", %{for: user, activity: activity})
|
||||
|
||||
assert represented[:id] == to_string(activity.id)
|
||||
assert length(represented[:media_attachments]) == 1
|
||||
|
|
@ -570,7 +570,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
"status" => "drink more water"
|
||||
})
|
||||
|
||||
result = StatusView.render("status.json", %{activity: activity, for: other_user})
|
||||
result = StatusView.render("show.json", %{activity: activity, for: other_user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: other_user, target: user})
|
||||
|
|
@ -587,7 +587,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
{:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
result = StatusView.render("status.json", %{activity: activity, for: user})
|
||||
result = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
|
|
@ -604,8 +604,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
|
||||
|
||||
status = StatusView.render("status.json", activity: activity)
|
||||
status = StatusView.render("show.json", activity: activity)
|
||||
|
||||
assert status.visibility == "list"
|
||||
end
|
||||
|
||||
test "successfully renders a Listen activity (pleroma extension)" do
|
||||
listen_activity = insert(:listen)
|
||||
|
||||
status = StatusView.render("listen.json", activity: listen_activity)
|
||||
|
||||
assert status.length == listen_activity.data["object"]["length"]
|
||||
assert status.title == listen_activity.data["object"]["title"]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MediaProxyTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.NodeInfoTest do
|
||||
|
|
|
|||
33
test/web/oauth/app_test.exs
Normal file
33
test/web/oauth/app_test.exs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.AppTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.OAuth.App
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "get_or_make/2" do
|
||||
test "gets exist app" do
|
||||
attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
|
||||
app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
|
||||
{:ok, %App{} = exist_app} = App.get_or_make(attrs, [])
|
||||
assert exist_app == app
|
||||
end
|
||||
|
||||
test "make app" do
|
||||
attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
|
||||
{:ok, %App{} = app} = App.get_or_make(attrs, ["write"])
|
||||
assert app.scopes == ["write"]
|
||||
end
|
||||
|
||||
test "gets exist app and updates scopes" do
|
||||
attrs = %{client_name: "Mastodon-Local", redirect_uris: "."}
|
||||
app = insert(:oauth_app, Map.merge(attrs, %{scopes: ["read", "write"]}))
|
||||
{:ok, %App{} = exist_app} = App.get_or_make(attrs, ["read", "write", "follow", "push"])
|
||||
assert exist_app.id == app.id
|
||||
assert exist_app.scopes == ["read", "write", "follow", "push"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.AuthorizationTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
||||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.Authorization
|
||||
alias Pleroma.Web.OAuth.OAuthController
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
|
|
@ -775,15 +776,11 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|
||||
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
password = "testpassword"
|
||||
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
info_change = Pleroma.User.Info.confirmation_changeset(user.info, need_confirmation: true)
|
||||
|
||||
{:ok, user} =
|
||||
user
|
||||
|> Ecto.Changeset.change()
|
||||
|> Ecto.Changeset.put_embed(:info, info_change)
|
||||
insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|
||||
refute Pleroma.User.auth_active?(user)
|
||||
|
|
@ -831,6 +828,33 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
refute Map.has_key?(resp, "access_token")
|
||||
end
|
||||
|
||||
test "rejects token exchange for user with password_reset_pending set to true" do
|
||||
password = "testpassword"
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
|
||||
info: %{password_reset_pending: true}
|
||||
)
|
||||
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "password",
|
||||
"username" => user.nickname,
|
||||
"password" => password,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|
||||
assert resp = json_response(conn, 403)
|
||||
|
||||
assert resp["error"] == "Password reset is required"
|
||||
refute Map.has_key?(resp, "access_token")
|
||||
end
|
||||
|
||||
test "rejects an invalid authorization code" do
|
||||
app = insert(:oauth_app)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.Token.UtilsTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OAuth.TokenTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
||||
|
|
@ -50,20 +50,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 200)
|
||||
end) =~ "[error]"
|
||||
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
|
||||
|
||||
# Wrong key
|
||||
info_cng =
|
||||
User.Info.remote_user_creation(salmon_user.info, %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
})
|
||||
info = %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
}
|
||||
|
||||
salmon_user
|
||||
|> Ecto.Changeset.change()
|
||||
|> Ecto.Changeset.put_embed(:info, info_cng)
|
||||
|> User.update_and_set_cache()
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
"http://gs.example.org:4040/index.php/user/1"
|
||||
|> User.get_cached_by_ap_id()
|
||||
|> User.update_info(&User.Info.remote_user_creation(&1, info))
|
||||
|
||||
assert capture_log(fn ->
|
||||
conn =
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatusTest do
|
||||
|
|
@ -628,4 +628,18 @@ defmodule Pleroma.Web.OStatusTest do
|
|||
refute OStatus.is_representable?(note_activity)
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_user/2" do
|
||||
test "creates new user" do
|
||||
{:ok, user} = OStatus.make_user("https://social.heldscal.la/user/23211")
|
||||
|
||||
created_user =
|
||||
User
|
||||
|> Repo.get_by(ap_id: "https://social.heldscal.la/user/23211")
|
||||
|> Map.put(:last_digest_emailed_at, nil)
|
||||
|
||||
assert user.info
|
||||
assert user == created_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "POST /api/v1/pleroma/scrobble" do
|
||||
test "works correctly", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/pleroma/scrobble", %{
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio",
|
||||
"length" => "180000"
|
||||
})
|
||||
|
||||
assert %{"title" => "lain radio episode 1"} = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/pleroma/accounts/:id/scrobbles" do
|
||||
test "works correctly", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 2",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 3",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio"
|
||||
})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/scrobbles")
|
||||
|
||||
result = json_response(conn, 200)
|
||||
|
||||
assert length(result) == 3
|
||||
end
|
||||
end
|
||||
end
|
||||
459
test/web/pleroma_api/emoji_api_controller_test.exs
Normal file
459
test/web/pleroma_api/emoji_api_controller_test.exs
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Tesla.Mock
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
@emoji_dir_path Path.join(
|
||||
Pleroma.Config.get!([:instance, :static_dir]),
|
||||
"emoji"
|
||||
)
|
||||
|
||||
test "shared & non-shared pack information in list_packs is ok" do
|
||||
conn = build_conn()
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
assert Map.has_key?(resp, "test_pack")
|
||||
|
||||
pack = resp["test_pack"]
|
||||
|
||||
assert Map.has_key?(pack["pack"], "download-sha256")
|
||||
assert pack["pack"]["can-download"]
|
||||
|
||||
assert pack["files"] == %{"blank" => "blank.png"}
|
||||
|
||||
# Non-shared pack
|
||||
|
||||
assert Map.has_key?(resp, "test_pack_nonshared")
|
||||
|
||||
pack = resp["test_pack_nonshared"]
|
||||
|
||||
refute pack["pack"]["shared"]
|
||||
refute pack["pack"]["can-download"]
|
||||
end
|
||||
|
||||
test "listing remote packs" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
mock(fn
|
||||
%{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
|
||||
json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
|
||||
|
||||
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
|
||||
|
||||
%{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
|
||||
json(resp)
|
||||
end)
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :list_from), %{instance_address: "https://example.com"})
|
||||
|> json_response(200) == resp
|
||||
end
|
||||
|
||||
test "downloading a shared pack from download_shared" do
|
||||
conn = build_conn()
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> get(emoji_api_path(conn, :download_shared, "test_pack"))
|
||||
|> response(200)
|
||||
|
||||
{:ok, arch} = :zip.unzip(resp, [:memory])
|
||||
|
||||
assert Enum.find(arch, fn {n, _} -> n == 'pack.json' end)
|
||||
assert Enum.find(arch, fn {n, _} -> n == 'blank.png' end)
|
||||
end
|
||||
|
||||
test "downloading shared & unshared packs from another instance via download_from, deleting them" do
|
||||
on_exit(fn ->
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack2")
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack_nonshared2")
|
||||
end)
|
||||
|
||||
mock(fn
|
||||
%{method: :get, url: "https://old-instance/.well-known/nodeinfo"} ->
|
||||
json(%{links: [%{href: "https://old-instance/nodeinfo/2.1.json"}]})
|
||||
|
||||
%{method: :get, url: "https://old-instance/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: []}})
|
||||
|
||||
%{method: :get, url: "https://example.com/.well-known/nodeinfo"} ->
|
||||
json(%{links: [%{href: "https://example.com/nodeinfo/2.1.json"}]})
|
||||
|
||||
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://example.com/api/pleroma/emoji/packs/list"
|
||||
} ->
|
||||
conn = build_conn()
|
||||
|
||||
conn
|
||||
|> get(emoji_api_path(conn, :list_packs))
|
||||
|> json_response(200)
|
||||
|> json()
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://example.com/api/pleroma/emoji/packs/download_shared/test_pack"
|
||||
} ->
|
||||
conn = build_conn()
|
||||
|
||||
conn
|
||||
|> get(emoji_api_path(conn, :download_shared, "test_pack"))
|
||||
|> response(200)
|
||||
|> text()
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://nonshared-pack"
|
||||
} ->
|
||||
text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
assert (conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:download_from
|
||||
),
|
||||
%{
|
||||
instance_address: "https://old-instance",
|
||||
pack_name: "test_pack",
|
||||
as: "test_pack2"
|
||||
}
|
||||
|> Jason.encode!()
|
||||
)
|
||||
|> json_response(500))["error"] =~ "does not support"
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:download_from
|
||||
),
|
||||
%{
|
||||
instance_address: "https://example.com",
|
||||
pack_name: "test_pack",
|
||||
as: "test_pack2"
|
||||
}
|
||||
|> Jason.encode!()
|
||||
)
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack2/pack.json")
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack2/blank.png")
|
||||
|
||||
assert conn
|
||||
|> delete(emoji_api_path(conn, :delete, "test_pack2"))
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack2")
|
||||
|
||||
# non-shared, downloaded from the fallback URL
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:download_from
|
||||
),
|
||||
%{
|
||||
instance_address: "https://example.com",
|
||||
pack_name: "test_pack_nonshared",
|
||||
as: "test_pack_nonshared2"
|
||||
}
|
||||
|> Jason.encode!()
|
||||
)
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/pack.json")
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack_nonshared2/blank.png")
|
||||
|
||||
assert conn
|
||||
|> delete(emoji_api_path(conn, :delete, "test_pack_nonshared2"))
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack_nonshared2")
|
||||
end
|
||||
|
||||
describe "updating pack metadata" do
|
||||
setup do
|
||||
pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
|
||||
original_content = File.read!(pack_file)
|
||||
|
||||
on_exit(fn ->
|
||||
File.write!(pack_file, original_content)
|
||||
end)
|
||||
|
||||
{:ok,
|
||||
admin: insert(:user, info: %{is_admin: true}),
|
||||
pack_file: pack_file,
|
||||
new_data: %{
|
||||
"license" => "Test license changed",
|
||||
"homepage" => "https://pleroma.social",
|
||||
"description" => "Test description",
|
||||
"share-files" => false
|
||||
}}
|
||||
end
|
||||
|
||||
test "for a pack without a fallback source", ctx do
|
||||
conn = build_conn()
|
||||
|
||||
assert conn
|
||||
|> assign(:user, ctx[:admin])
|
||||
|> post(
|
||||
emoji_api_path(conn, :update_metadata, "test_pack"),
|
||||
%{
|
||||
"new_data" => ctx[:new_data]
|
||||
}
|
||||
)
|
||||
|> json_response(200) == ctx[:new_data]
|
||||
|
||||
assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == ctx[:new_data]
|
||||
end
|
||||
|
||||
test "for a pack with a fallback source", ctx do
|
||||
mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://nonshared-pack"
|
||||
} ->
|
||||
text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
|
||||
end)
|
||||
|
||||
new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
|
||||
|
||||
new_data_with_sha =
|
||||
Map.put(
|
||||
new_data,
|
||||
"fallback-src-sha256",
|
||||
"74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF"
|
||||
)
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
assert conn
|
||||
|> assign(:user, ctx[:admin])
|
||||
|> post(
|
||||
emoji_api_path(conn, :update_metadata, "test_pack"),
|
||||
%{
|
||||
"new_data" => new_data
|
||||
}
|
||||
)
|
||||
|> json_response(200) == new_data_with_sha
|
||||
|
||||
assert Jason.decode!(File.read!(ctx[:pack_file]))["pack"] == new_data_with_sha
|
||||
end
|
||||
|
||||
test "when the fallback source doesn't have all the files", ctx do
|
||||
mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://nonshared-pack"
|
||||
} ->
|
||||
{:ok, {'empty.zip', empty_arch}} = :zip.zip('empty.zip', [], [:memory])
|
||||
text(empty_arch)
|
||||
end)
|
||||
|
||||
new_data = Map.put(ctx[:new_data], "fallback-src", "https://nonshared-pack")
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
assert (conn
|
||||
|> assign(:user, ctx[:admin])
|
||||
|> post(
|
||||
emoji_api_path(conn, :update_metadata, "test_pack"),
|
||||
%{
|
||||
"new_data" => new_data
|
||||
}
|
||||
)
|
||||
|> json_response(:bad_request))["error"] =~ "does not have all"
|
||||
end
|
||||
end
|
||||
|
||||
test "updating pack files" do
|
||||
pack_file = "#{@emoji_dir_path}/test_pack/pack.json"
|
||||
original_content = File.read!(pack_file)
|
||||
|
||||
on_exit(fn ->
|
||||
File.write!(pack_file, original_content)
|
||||
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack/blank_url.png")
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir")
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
same_name = %{
|
||||
"action" => "add",
|
||||
"shortcode" => "blank",
|
||||
"filename" => "dir/blank.png",
|
||||
"file" => %Plug.Upload{
|
||||
filename: "blank.png",
|
||||
path: "#{@emoji_dir_path}/test_pack/blank.png"
|
||||
}
|
||||
}
|
||||
|
||||
different_name = %{same_name | "shortcode" => "blank_2"}
|
||||
|
||||
conn = conn |> assign(:user, admin)
|
||||
|
||||
assert (conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), same_name)
|
||||
|> json_response(:conflict))["error"] =~ "already exists"
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), different_name)
|
||||
|> json_response(200) == %{"blank" => "blank.png", "blank_2" => "dir/blank.png"}
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack/dir/blank.png")
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), %{
|
||||
"action" => "update",
|
||||
"shortcode" => "blank_2",
|
||||
"new_shortcode" => "blank_3",
|
||||
"new_filename" => "dir_2/blank_3.png"
|
||||
})
|
||||
|> json_response(200) == %{"blank" => "blank.png", "blank_3" => "dir_2/blank_3.png"}
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack/dir/")
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack/dir_2/blank_3.png")
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), %{
|
||||
"action" => "remove",
|
||||
"shortcode" => "blank_3"
|
||||
})
|
||||
|> json_response(200) == %{"blank" => "blank.png"}
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack/dir_2/")
|
||||
|
||||
mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "https://test-blank/blank_url.png"
|
||||
} ->
|
||||
text(File.read!("#{@emoji_dir_path}/test_pack/blank.png"))
|
||||
end)
|
||||
|
||||
# The name should be inferred from the URL ending
|
||||
from_url = %{
|
||||
"action" => "add",
|
||||
"shortcode" => "blank_url",
|
||||
"file" => "https://test-blank/blank_url.png"
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), from_url)
|
||||
|> json_response(200) == %{
|
||||
"blank" => "blank.png",
|
||||
"blank_url" => "blank_url.png"
|
||||
}
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
|
||||
|
||||
assert conn
|
||||
|> post(emoji_api_path(conn, :update_file, "test_pack"), %{
|
||||
"action" => "remove",
|
||||
"shortcode" => "blank_url"
|
||||
})
|
||||
|> json_response(200) == %{"blank" => "blank.png"}
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack/blank_url.png")
|
||||
end
|
||||
|
||||
test "creating and deleting a pack" do
|
||||
on_exit(fn ->
|
||||
File.rm_rf!("#{@emoji_dir_path}/test_created")
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> put(
|
||||
emoji_api_path(
|
||||
conn,
|
||||
:create,
|
||||
"test_created"
|
||||
)
|
||||
)
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
assert File.exists?("#{@emoji_dir_path}/test_created/pack.json")
|
||||
|
||||
assert Jason.decode!(File.read!("#{@emoji_dir_path}/test_created/pack.json")) == %{
|
||||
"pack" => %{},
|
||||
"files" => %{}
|
||||
}
|
||||
|
||||
assert conn
|
||||
|> delete(emoji_api_path(conn, :delete, "test_created"))
|
||||
|> json_response(200) == "ok"
|
||||
|
||||
refute File.exists?("#{@emoji_dir_path}/test_created/pack.json")
|
||||
end
|
||||
|
||||
test "filesystem import" do
|
||||
on_exit(fn ->
|
||||
File.rm!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt")
|
||||
File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
|
||||
end)
|
||||
|
||||
conn = build_conn()
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
refute Map.has_key?(resp, "test_pack_for_import")
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
assert conn
|
||||
|> assign(:user, admin)
|
||||
|> post(emoji_api_path(conn, :import_from_fs))
|
||||
|> json_response(200) == ["test_pack_for_import"]
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
|
||||
|
||||
File.rm!("#{@emoji_dir_path}/test_pack_for_import/pack.json")
|
||||
refute File.exists?("#{@emoji_dir_path}/test_pack_for_import/pack.json")
|
||||
|
||||
emoji_txt_content = "blank, blank.png, Fun\n\nblank2, blank.png"
|
||||
|
||||
File.write!("#{@emoji_dir_path}/test_pack_for_import/emoji.txt", emoji_txt_content)
|
||||
|
||||
assert conn
|
||||
|> assign(:user, admin)
|
||||
|> post(emoji_api_path(conn, :import_from_fs))
|
||||
|> json_response(200) == ["test_pack_for_import"]
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
||||
assert resp["test_pack_for_import"]["files"] == %{
|
||||
"blank" => "blank.png",
|
||||
"blank2" => "blank.png"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.FederatingPlugTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Push.ImplTest do
|
||||
|
|
|
|||
|
|
@ -1,48 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule MockActivityPub do
|
||||
def publish_one({ret, waiter}) do
|
||||
send(waiter, :complete)
|
||||
{ret, "success"}
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Pleroma.Web.Federator.RetryQueueTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.Federator.RetryQueue
|
||||
|
||||
@small_retry_count 0
|
||||
@hopeless_retry_count 10
|
||||
|
||||
setup do
|
||||
RetryQueue.reset_stats()
|
||||
end
|
||||
|
||||
test "RetryQueue responds to stats request" do
|
||||
assert %{delivered: 0, dropped: 0} == RetryQueue.get_stats()
|
||||
end
|
||||
|
||||
test "failed posts are retried" do
|
||||
{:retry, _timeout} = RetryQueue.get_retry_params(@small_retry_count)
|
||||
|
||||
wait_task =
|
||||
Task.async(fn ->
|
||||
receive do
|
||||
:complete -> :ok
|
||||
end
|
||||
end)
|
||||
|
||||
RetryQueue.enqueue({:ok, wait_task.pid}, MockActivityPub, @small_retry_count)
|
||||
Task.await(wait_task)
|
||||
assert %{delivered: 1, dropped: 0} == RetryQueue.get_stats()
|
||||
end
|
||||
|
||||
test "posts that have been tried too many times are dropped" do
|
||||
{:drop, _timeout} = RetryQueue.get_retry_params(@hopeless_retry_count)
|
||||
|
||||
RetryQueue.enqueue({:ok, nil}, MockActivityPub, @hopeless_retry_count)
|
||||
assert %{delivered: 0, dropped: 1} == RetryQueue.get_stats()
|
||||
end
|
||||
end
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||
|
|
@ -96,6 +96,6 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
|
|||
|
||||
Salmon.publish(user, activity)
|
||||
|
||||
assert called(Publisher.enqueue_one(Salmon, %{recipient: mentioned_user}))
|
||||
assert called(Publisher.enqueue_one(Salmon, %{recipient_id: mentioned_user.id}))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
36
test/web/streamer/ping_test.exs
Normal file
36
test/web/streamer/ping_test.exs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.Streamer
|
||||
|
||||
setup do
|
||||
start_supervised({Streamer.supervisor(), [ping_interval: 30]})
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "sockets" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, %{user: user}}
|
||||
end
|
||||
|
||||
test "it sends pings", %{user: user} do
|
||||
task =
|
||||
Task.async(fn ->
|
||||
assert_receive {:text, received_event}, 40
|
||||
assert_receive {:text, received_event}, 40
|
||||
assert_receive {:text, received_event}, 40
|
||||
end)
|
||||
|
||||
Streamer.add_socket("public", %{transport_pid: task.pid, assigns: %{user: user}})
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
end
|
||||
end
|
||||
54
test/web/streamer/state_test.exs
Normal file
54
test/web/streamer/state_test.exs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.StateTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.Streamer
|
||||
alias Pleroma.Web.Streamer.StreamerSocket
|
||||
|
||||
@moduletag needs_streamer: true
|
||||
|
||||
describe "sockets" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
{:ok, %{user: user, user2: user2}}
|
||||
end
|
||||
|
||||
test "it can add a socket", %{user: user} do
|
||||
Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
|
||||
|
||||
assert(%{"public" => [%StreamerSocket{transport_pid: 1}]} = Streamer.get_sockets())
|
||||
end
|
||||
|
||||
test "it can add multiple sockets per user", %{user: user} do
|
||||
Streamer.add_socket("public", %{transport_pid: 1, assigns: %{user: user}})
|
||||
Streamer.add_socket("public", %{transport_pid: 2, assigns: %{user: user}})
|
||||
|
||||
assert(
|
||||
%{
|
||||
"public" => [
|
||||
%StreamerSocket{transport_pid: 2},
|
||||
%StreamerSocket{transport_pid: 1}
|
||||
]
|
||||
} = Streamer.get_sockets()
|
||||
)
|
||||
end
|
||||
|
||||
test "it will not add a duplicate socket", %{user: user} do
|
||||
Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
|
||||
Streamer.add_socket("activity", %{transport_pid: 1, assigns: %{user: user}})
|
||||
|
||||
assert(
|
||||
%{
|
||||
"activity" => [
|
||||
%StreamerSocket{transport_pid: 1}
|
||||
]
|
||||
} = Streamer.get_sockets()
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,28 +1,24 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.StreamerTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.List
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Streamer
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.Streamer.StreamerSocket
|
||||
alias Pleroma.Web.Streamer.Worker
|
||||
|
||||
@moduletag needs_streamer: true
|
||||
clear_config_all([:instance, :skip_thread_containment])
|
||||
|
||||
describe "user streams" do
|
||||
setup do
|
||||
GenServer.start(Streamer, %{}, name: Streamer)
|
||||
|
||||
on_exit(fn ->
|
||||
if pid = Process.whereis(Streamer) do
|
||||
Process.exit(pid, :kill)
|
||||
end
|
||||
end)
|
||||
|
||||
user = insert(:user)
|
||||
notify = insert(:notification, user: user, activity: build(:note_activity))
|
||||
{:ok, %{user: user, notify: notify}}
|
||||
|
|
@ -125,11 +121,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
assert_receive {:text, _}, 4_000
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user
|
||||
}
|
||||
user: user
|
||||
}
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "Test"})
|
||||
|
|
@ -138,7 +132,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"public" => [fake_socket]
|
||||
}
|
||||
|
||||
Streamer.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
|
||||
|
|
@ -155,11 +149,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
assert received_event == expected_event
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user
|
||||
}
|
||||
user: user
|
||||
}
|
||||
|
||||
{:ok, activity} = CommonAPI.delete(activity.id, other_user)
|
||||
|
|
@ -168,7 +160,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"public" => [fake_socket]
|
||||
}
|
||||
|
||||
Streamer.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -189,9 +181,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
)
|
||||
|
||||
task = Task.async(fn -> refute_receive {:text, _}, 1_000 end)
|
||||
fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
|
||||
fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
|
||||
topics = %{"public" => [fake_socket]}
|
||||
Streamer.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -211,9 +203,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
)
|
||||
|
||||
task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
|
||||
fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
|
||||
fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
|
||||
topics = %{"public" => [fake_socket]}
|
||||
Streamer.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -233,9 +225,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
)
|
||||
|
||||
task = Task.async(fn -> assert_receive {:text, _}, 1_000 end)
|
||||
fake_socket = %{transport_pid: task.pid, assigns: %{user: user}}
|
||||
fake_socket = %StreamerSocket{transport_pid: task.pid, user: user}
|
||||
topics = %{"public" => [fake_socket]}
|
||||
Streamer.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -251,11 +243,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user
|
||||
}
|
||||
user: user
|
||||
}
|
||||
|
||||
{:ok, activity} = CommonAPI.post(blocked_user, %{"status" => "Test"})
|
||||
|
|
@ -264,7 +254,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"public" => [fake_socket]
|
||||
}
|
||||
|
||||
Streamer.push_to_socket(topics, "public", activity)
|
||||
Worker.push_to_socket(topics, "public", activity)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -284,11 +274,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user_a
|
||||
}
|
||||
user: user_a
|
||||
}
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -301,7 +289,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"list:#{list.id}" => [fake_socket]
|
||||
}
|
||||
|
||||
Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
|
||||
Worker.handle_call({:stream, "list", activity}, self(), topics)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -318,11 +306,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user_a
|
||||
}
|
||||
user: user_a
|
||||
}
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -335,12 +321,12 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"list:#{list.id}" => [fake_socket]
|
||||
}
|
||||
|
||||
Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
|
||||
Worker.handle_call({:stream, "list", activity}, self(), topics)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it send wanted private posts to list" do
|
||||
test "it sends wanted private posts to list" do
|
||||
user_a = insert(:user)
|
||||
user_b = insert(:user)
|
||||
|
||||
|
|
@ -354,11 +340,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
assert_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user_a
|
||||
}
|
||||
user: user_a
|
||||
}
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -367,11 +351,12 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"visibility" => "private"
|
||||
})
|
||||
|
||||
topics = %{
|
||||
"list:#{list.id}" => [fake_socket]
|
||||
}
|
||||
Streamer.add_socket(
|
||||
"list:#{list.id}",
|
||||
fake_socket
|
||||
)
|
||||
|
||||
Streamer.handle_cast(%{action: :stream, topic: "list", item: activity}, topics)
|
||||
Worker.handle_call({:stream, "list", activity}, self(), %{})
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -387,11 +372,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
refute_receive {:text, _}, 1_000
|
||||
end)
|
||||
|
||||
fake_socket = %{
|
||||
fake_socket = %StreamerSocket{
|
||||
transport_pid: task.pid,
|
||||
assigns: %{
|
||||
user: user1
|
||||
}
|
||||
user: user1
|
||||
}
|
||||
|
||||
{:ok, create_activity} = CommonAPI.post(user3, %{"status" => "I'm kawen"})
|
||||
|
|
@ -401,7 +384,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
"public" => [fake_socket]
|
||||
}
|
||||
|
||||
Streamer.push_to_socket(topics, "public", announce_activity)
|
||||
Worker.push_to_socket(topics, "public", announce_activity)
|
||||
|
||||
Task.await(task)
|
||||
end
|
||||
|
|
@ -417,6 +400,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
|
||||
|
||||
Process.sleep(4000)
|
||||
|
||||
Streamer.add_socket(
|
||||
"user",
|
||||
%{transport_pid: task.pid, assigns: %{user: user2}}
|
||||
|
|
@ -428,14 +413,6 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
describe "direct streams" do
|
||||
setup do
|
||||
GenServer.start(Streamer, %{}, name: Streamer)
|
||||
|
||||
on_exit(fn ->
|
||||
if pid = Process.whereis(Streamer) do
|
||||
Process.exit(pid, :kill)
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
@ -480,6 +457,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
refute_receive {:text, _}, 4_000
|
||||
end)
|
||||
|
||||
Process.sleep(1000)
|
||||
|
||||
Streamer.add_socket(
|
||||
"direct",
|
||||
%{transport_pid: task.pid, assigns: %{user: user}}
|
||||
|
|
@ -521,6 +500,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
assert last_status["id"] == to_string(create_activity.id)
|
||||
end)
|
||||
|
||||
Process.sleep(1000)
|
||||
|
||||
Streamer.add_socket(
|
||||
"direct",
|
||||
%{transport_pid: task.pid, assigns: %{user: user}}
|
||||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.PasswordResetToken
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -56,5 +57,25 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
|
||||
assert length(Token.get_user_tokens(user)) == 0
|
||||
end
|
||||
|
||||
test "it sets password_reset_pending to false", %{conn: conn} do
|
||||
user = insert(:user, info: %{password_reset_pending: true})
|
||||
|
||||
{:ok, token} = PasswordResetToken.create_token(user)
|
||||
{:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
|
||||
|
||||
params = %{
|
||||
"password" => "test",
|
||||
password_confirmation: "test",
|
||||
token: token.token
|
||||
}
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/pleroma/password_reset", %{data: params})
|
||||
|> html_response(:ok)
|
||||
|
||||
assert User.get_by_id(user.id).info.password_reset_pending == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
|
@ -68,6 +69,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert user.info.confirmation_pending
|
||||
|
||||
|
|
@ -107,7 +109,9 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user2} = TwitterAPI.register_user(data2)
|
||||
|
||||
expected_text =
|
||||
"<span class='h-card'><a data-user='#{user1.id}' class='u-url mention' href='#{user1.ap_id}'>@<span>john</span></a></span> test"
|
||||
~s(<span class="h-card"><a data-user="#{user1.id}" class="u-url mention" href="#{
|
||||
user1.ap_id
|
||||
}" rel="ugc">@<span>john</span></a></span> test)
|
||||
|
||||
assert user2.bio == expected_text
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
|
|
@ -42,8 +45,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
{File, [],
|
||||
read!: fn "follow_list.txt" ->
|
||||
"Account address,Show boosts\n#{user2.ap_id},true"
|
||||
end},
|
||||
{PleromaJobQueue, [:passthrough], []}
|
||||
end}
|
||||
]) do
|
||||
response =
|
||||
conn
|
||||
|
|
@ -51,15 +53,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> post("/api/pleroma/follow_import", %{"list" => %Plug.Upload{path: "follow_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert called(
|
||||
PleromaJobQueue.enqueue(
|
||||
:background,
|
||||
User,
|
||||
[:follow_import, user1, [user2.ap_id]]
|
||||
)
|
||||
)
|
||||
|
||||
assert response == "job started"
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "follow_import",
|
||||
"follower_id" => user1.id,
|
||||
"followed_identifiers" => [user2.ap_id]
|
||||
},
|
||||
all_enqueued(worker: Pleroma.Workers.BackgroundWorker)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -118,8 +121,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
user3 = insert(:user)
|
||||
|
||||
with_mocks([
|
||||
{File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end},
|
||||
{PleromaJobQueue, [:passthrough], []}
|
||||
{File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end}
|
||||
]) do
|
||||
response =
|
||||
conn
|
||||
|
|
@ -127,15 +129,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> post("/api/pleroma/blocks_import", %{"list" => %Plug.Upload{path: "blocks_list.txt"}})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert called(
|
||||
PleromaJobQueue.enqueue(
|
||||
:background,
|
||||
User,
|
||||
[:blocks_import, user1, [user2.ap_id, user3.ap_id]]
|
||||
)
|
||||
)
|
||||
|
||||
assert response == "job started"
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "blocks_import",
|
||||
"blocker_id" => user1.id,
|
||||
"blocked_identifiers" => [user2.ap_id, user3.ap_id]
|
||||
},
|
||||
all_enqueued(worker: Pleroma.Workers.BackgroundWorker)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -338,12 +341,14 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
|
||||
assert capture_log(fn ->
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
|
||||
|
||||
assert html_response(response, 200) =~ "Error fetching user"
|
||||
assert html_response(response, 200) =~ "Error fetching user"
|
||||
end) =~ "Object has been deleted"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -557,6 +562,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> json_response(:ok)
|
||||
|
||||
assert response == %{"status" => "success"}
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
|
|
@ -769,4 +775,109 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/change_password" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without credentials", %{conn: conn} do
|
||||
conn = post(conn, "/api/pleroma/change_password")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "hi",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and new password and confirmation not matching", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "notnewpass"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"error" => "New password does not match confirmation."
|
||||
}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and invalid new password", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "",
|
||||
"new_password_confirmation" => ""
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"error" => "New password can't be blank."
|
||||
}
|
||||
end
|
||||
|
||||
test "with credentials, valid password and matching new password and confirmation", %{
|
||||
conn: conn,
|
||||
user: current_user
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/change_password", %{
|
||||
"password" => "test",
|
||||
"new_password" => "newpass",
|
||||
"new_password_confirmation" => "newpass"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
fetched_user = User.get_cached_by_id(current_user.id)
|
||||
assert Comeonin.Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/delete_account" do
|
||||
setup [:valid_user]
|
||||
|
||||
test "without credentials", %{conn: conn} do
|
||||
conn = post(conn, "/api/pleroma/delete_account")
|
||||
assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
|
||||
end
|
||||
|
||||
test "with credentials and invalid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/delete_account", %{"password" => "hi"})
|
||||
|
||||
assert json_response(conn, 200) == %{"error" => "Invalid password."}
|
||||
end
|
||||
|
||||
test "with credentials and valid password", %{conn: conn, user: current_user} do
|
||||
conn =
|
||||
conn
|
||||
|> with_credentials(current_user.nickname, "test")
|
||||
|> post("/api/pleroma/delete_account", %{"password" => "test"})
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
# Wait a second for the started task to end
|
||||
:timer.sleep(1000)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.UploaderControllerTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ErrorViewTest do
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
|
|
@ -75,11 +76,13 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
test "Sends a 404 when invalid format" do
|
||||
user = insert(:user)
|
||||
|
||||
assert_raise Phoenix.NotAcceptableError, fn ->
|
||||
build_conn()
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
||||
end
|
||||
assert capture_log(fn ->
|
||||
assert_raise Phoenix.NotAcceptableError, fn ->
|
||||
build_conn()
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
|
||||
end
|
||||
end) =~ "no supported media type in accept header"
|
||||
end
|
||||
|
||||
test "Sends a 400 when resource param is missing" do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebFingerTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Websub.WebsubControllerTest do
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebsubTest do
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.Router.Helpers
|
||||
alias Pleroma.Web.Websub
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
alias Pleroma.Web.Websub.WebsubServerSubscription
|
||||
alias Pleroma.Workers.SubscriberWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
|
@ -224,6 +227,7 @@ defmodule Pleroma.Web.WebsubTest do
|
|||
})
|
||||
|
||||
_refresh = Websub.refresh_subscriptions()
|
||||
ObanHelpers.perform(all_enqueued(worker: SubscriberWorker))
|
||||
|
||||
assert still_good == Repo.get(WebsubClientSubscription, still_good.id)
|
||||
refute needs_refresh == Repo.get(WebsubClientSubscription, needs_refresh.id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue