Merge remote-tracking branch 'upstream/develop' into registration-workflow
This commit is contained in:
commit
9546c1444c
236 changed files with 5448 additions and 2802 deletions
|
|
@ -156,21 +156,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
put_req_header(
|
||||
conn,
|
||||
"accept",
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
)
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}.json", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "mastodon compatibility routes" do
|
||||
|
|
@ -338,18 +323,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/objects/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/activities/:uuid" do
|
||||
|
|
@ -421,18 +394,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/activities/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/inbox" do
|
||||
|
|
@ -893,15 +854,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert response(conn, 200) =~ announce_activity.data["object"]
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}/outbox", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox (C2S)" do
|
||||
|
|
@ -1487,9 +1439,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
desc = "Description of the image"
|
||||
|
||||
image = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "bad/content-type",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
filename: "an_image.png"
|
||||
}
|
||||
|
||||
object =
|
||||
|
|
@ -1504,6 +1456,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert [%{"href" => object_href, "mediaType" => object_mediatype}] = object["url"]
|
||||
assert is_binary(object_href)
|
||||
assert object_mediatype == "image/jpeg"
|
||||
assert String.ends_with?(object_href, ".jpg")
|
||||
|
||||
activity_request = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
|
|
|
|||
|
|
@ -505,22 +505,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
# public
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "public"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 1
|
||||
|
||||
# unlisted
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "unlisted"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
|
||||
# private
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "private"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
|
||||
# direct
|
||||
{:ok, _} = CommonAPI.post(user2, Map.put(reply_data, :visibility, "direct"))
|
||||
assert %{data: data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert %{data: _data, object: object} = Activity.get_by_ap_id_with_object(ap_id)
|
||||
assert object.data["repliesCount"] == 2
|
||||
end
|
||||
end
|
||||
|
|
@ -752,6 +752,22 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
refute repeat_activity in activities
|
||||
end
|
||||
|
||||
test "returns your own posts regardless of mute" do
|
||||
user = insert(:user)
|
||||
muted = insert(:user)
|
||||
|
||||
{:ok, muted_post} = CommonAPI.post(muted, %{status: "Im stupid"})
|
||||
|
||||
{:ok, reply} =
|
||||
CommonAPI.post(user, %{status: "I'm muting you", in_reply_to_status_id: muted_post.id})
|
||||
|
||||
{:ok, _} = User.mute(user, muted)
|
||||
|
||||
[activity] = ActivityPub.fetch_activities([], %{muting_user: user, skip_preload: true})
|
||||
|
||||
assert activity.id == reply.id
|
||||
end
|
||||
|
||||
test "doesn't return muted activities" do
|
||||
activity_one = insert(:note_activity)
|
||||
activity_two = insert(:note_activity)
|
||||
|
|
@ -1029,7 +1045,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
describe "uploading files" do
|
||||
setup do
|
||||
test_file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -1120,7 +1136,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
test "creates an undo activity for a pending follow request" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{locked: true})
|
||||
followed = insert(:user, %{is_locked: true})
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
{:ok, activity} = ActivityPub.unfollow(follower, followed)
|
||||
|
|
@ -1410,19 +1426,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
mock(fn env ->
|
||||
case env.url do
|
||||
"http://localhost:4001/users/masto_hidden_counters/following" ->
|
||||
json(%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/followers"
|
||||
})
|
||||
json(
|
||||
%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/followers"
|
||||
},
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
)
|
||||
|
||||
"http://localhost:4001/users/masto_hidden_counters/following?page=1" ->
|
||||
%Tesla.Env{status: 403, body: ""}
|
||||
|
||||
"http://localhost:4001/users/masto_hidden_counters/followers" ->
|
||||
json(%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/following"
|
||||
})
|
||||
json(
|
||||
%{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"id" => "http://localhost:4001/users/masto_hidden_counters/following"
|
||||
},
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
)
|
||||
|
||||
"http://localhost:4001/users/masto_hidden_counters/followers?page=1" ->
|
||||
%Tesla.Env{status: 403, body: ""}
|
||||
|
|
@ -2257,4 +2279,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert length(activities) == 2
|
||||
end
|
||||
end
|
||||
|
||||
test "allow fetching of accounts with an empty string name field" do
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get, url: "https://princess.cat/users/mewmew"} ->
|
||||
file = File.read!("test/fixtures/mewmew_no_name.json")
|
||||
%Tesla.Env{status: 200, body: file, headers: HttpRequestMock.activitypub_object_headers()}
|
||||
end)
|
||||
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id("https://princess.cat/users/mewmew")
|
||||
assert user.name == " "
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
test "it's allowed when cc address contain public address" do
|
||||
|
|
@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
"type" => "Create"
|
||||
}
|
||||
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_followersonly], true)
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
test "it's rejected when addrer of message in the follower addresses of user and it disabled in config" do
|
||||
|
|
@ -80,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
}
|
||||
|
||||
Pleroma.Config.put([:mrf_rejectnonpublic, :allow_direct], true)
|
||||
assert {:ok, message} = RejectNonPublic.filter(message)
|
||||
assert {:ok, _message} = RejectNonPublic.filter(message)
|
||||
end
|
||||
|
||||
test "it's reject when direct messages aren't allow" do
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do
|
|||
actor = insert(:user, tags: ["mrf_tag:disable-remote-subscription"])
|
||||
follower = insert(:user, tags: ["mrf_tag:disable-remote-subscription"], local: true)
|
||||
message = %{"object" => actor.ap_id, "type" => "Follow", "actor" => follower.ap_id}
|
||||
assert {:ok, message} = TagPolicy.filter(message)
|
||||
assert {:ok, _message} = TagPolicy.filter(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -87,4 +87,20 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
{:ok, ^expected} = MRF.describe()
|
||||
end
|
||||
end
|
||||
|
||||
test "config_descriptions/0" do
|
||||
descriptions = MRF.config_descriptions()
|
||||
|
||||
good_mrf = Enum.find(descriptions, fn %{key: key} -> key == :good_mrf end)
|
||||
|
||||
assert good_mrf == %{
|
||||
key: :good_mrf,
|
||||
related_policy: "Fixtures.Modules.GoodMRF",
|
||||
label: "Good MRF",
|
||||
description: "Some description",
|
||||
group: :pleroma,
|
||||
tab: :mrf,
|
||||
type: :group
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
"http://mastodon.example.org/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg",
|
||||
"type" => "Document",
|
||||
"name" => nil,
|
||||
"mediaType" => "image/jpeg"
|
||||
"mediaType" => "image/jpeg",
|
||||
"blurhash" => "UD9jJz~VSbR#xT$~%KtQX9R,WAs9RjWBs:of"
|
||||
}
|
||||
|
||||
{:ok, attachment} =
|
||||
|
|
@ -50,13 +51,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do
|
|||
] = attachment.url
|
||||
|
||||
assert attachment.mediaType == "image/jpeg"
|
||||
assert attachment.blurhash == "UD9jJz~VSbR#xT$~%KtQX9R,WAs9RjWBs:of"
|
||||
end
|
||||
|
||||
test "it handles our own uploads" do
|
||||
user = insert(:user)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
user: user
|
||||
} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
user: user
|
||||
} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -119,7 +119,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ChatValidationTest do
|
|||
user: user
|
||||
} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
|||
|
||||
test "it works for incoming accepts which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
|||
|
||||
test "it fails for incoming accepts which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|
|
|
|||
|
|
@ -60,7 +60,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :get} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/mastodon-note-object.json")}
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/mastodon-note-object.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
_user = insert(:user, local: false, ap_id: data["actor"])
|
||||
|
|
@ -144,7 +148,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnnounceHandlingTest do
|
|||
|
||||
_user = insert(:user, local: false, ap_id: data["actor"])
|
||||
|
||||
assert {:error, e} = Transmogrifier.handle_incoming(data)
|
||||
assert {:error, _e} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it does not clobber the addressing on announce activities" do
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
|||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
assert object.data["repliesCount"] == nil
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|
|
@ -41,7 +42,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
|||
assert answer_object.data["inReplyTo"] == object.data["id"]
|
||||
|
||||
new_object = Object.get_by_ap_id(object.data["id"])
|
||||
assert new_object.data["replies_count"] == object.data["replies_count"]
|
||||
assert new_object.data["repliesCount"] == nil
|
||||
|
||||
assert Enum.any?(
|
||||
new_object.data["oneOf"],
|
||||
|
|
|
|||
|
|
@ -13,7 +13,11 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
|||
|
||||
test "Pterotype (Wordpress Plugin) Article" do
|
||||
Tesla.Mock.mock(fn %{url: "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")}
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
data =
|
||||
|
|
@ -36,13 +40,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
|||
%{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
@ -61,7 +67,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
|
|||
Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
%{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
@ -69,6 +70,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|||
"mediaType" => "audio/ogg",
|
||||
"type" => "Link",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
|
|||
|
|
@ -13,13 +13,15 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.EventHandlingTest do
|
|||
%{url: "https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-event.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
|
||||
%{url: "https://mobilizon.org/@tcit"} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json")
|
||||
body: File.read!("test/fixtures/tesla_mock/mobilizon.org-user.json"),
|
||||
headers: HttpRequestMock.activitypub_object_headers()
|
||||
}
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
end
|
||||
|
||||
test "with locked accounts, it does create a Follow, but not an Accept" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|
|
@ -188,7 +188,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
|
||||
test "it works for incoming follows to locked account" do
|
||||
pending_follower = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
|
|||
|
||||
test "it fails for incoming rejects which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|
|
@ -33,7 +33,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
|
|||
|
||||
test "it works for incoming rejects which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
|
|
|||
|
|
@ -154,6 +154,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UserUpdateHandlingTest do
|
|||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.locked == true
|
||||
assert user.is_locked == true
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
@ -76,6 +77,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
|
|||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"name" => nil,
|
||||
"blurhash" => nil,
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
returned_object = Object.normalize(returned_activity, false)
|
||||
|
||||
assert activity =
|
||||
assert %Activity{} =
|
||||
Activity.get_create_by_object_ap_id(
|
||||
"https://mstdn.io/users/mayuutann/statuses/99568293732299394"
|
||||
)
|
||||
|
|
@ -206,6 +206,16 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert user.note_count == 1
|
||||
end
|
||||
|
||||
test "it works for incoming notices without the sensitive property but an nsfw hashtag" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity-nsfw.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object_data = Object.normalize(data["object"], false).data
|
||||
|
||||
assert object_data["sensitive"] == true
|
||||
end
|
||||
|
||||
test "it works for incoming notices with hashtags" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
|
||||
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
describe "update_follow_state_for_all/2" do
|
||||
test "updates the state of all Follow activities with the same actor and object" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
|
||||
|
|
@ -217,7 +217,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
describe "update_follow_state/2" do
|
||||
test "updates the state of the given follow activity" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, user)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -9,7 +9,6 @@ defmodule Pleroma.Web.AdminAPI.ChatControllerTest do
|
|||
|
||||
alias Pleroma.Chat
|
||||
alias Pleroma.Chat.MessageReference
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.AdminAPI.InstanceDocumentControllerTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Config
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
@default_instance_panel ~s(<p>Welcome to <a href="https://pleroma.social" target="_blank">Pleroma!</a></p>)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.OAuthAppControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web
|
||||
|
||||
setup do
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.AdminAPI.RelayControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ReportNote
|
||||
|
|
@ -38,12 +37,21 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
status_ids: [activity.id]
|
||||
})
|
||||
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/reports/#{report_id}/notes", %{
|
||||
content: "this is an admin note"
|
||||
})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports/#{report_id}")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert response["id"] == report_id
|
||||
|
||||
[notes] = response["notes"]
|
||||
assert notes["content"] == "this is an admin note"
|
||||
end
|
||||
|
||||
test "returns 404 when report id is invalid", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.AdminAPI.StatusControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
|
|
|||
970
test/pleroma/web/admin_api/controllers/user_controller_test.exs
Normal file
970
test/pleroma/web/admin_api/controllers/user_controller_test.exs
Normal file
|
|
@ -0,0 +1,970 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.AdminAPI.UserControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MediaProxy
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, token)
|
||||
|
||||
{:ok, %{admin: admin, token: token, conn: conn}}
|
||||
end
|
||||
|
||||
test "with valid `admin_token` query parameter, skips OAuth scopes check" do
|
||||
clear_config([:admin_token], "password123")
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
conn = get(build_conn(), "/api/pleroma/admin/users/#{user.nickname}?admin_token=password123")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
|
||||
describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
|
||||
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
|
||||
%{admin: admin} do
|
||||
user = insert(:user)
|
||||
url = "/api/pleroma/admin/users/#{user.nickname}"
|
||||
|
||||
good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
|
||||
good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
|
||||
good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
|
||||
|
||||
bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
|
||||
bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
|
||||
bad_token3 = nil
|
||||
|
||||
for good_token <- [good_token1, good_token2, good_token3] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, good_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
|
||||
for good_token <- [good_token1, good_token2, good_token3] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, nil)
|
||||
|> assign(:token, good_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
|
||||
for bad_token <- [bad_token1, bad_token2, bad_token3] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, bad_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
|
||||
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires " <>
|
||||
"read:accounts or admin:read:accounts or broader scope",
|
||||
%{admin: admin} do
|
||||
user = insert(:user)
|
||||
url = "/api/pleroma/admin/users/#{user.nickname}"
|
||||
|
||||
good_token1 = insert(:oauth_token, user: admin, scopes: ["admin"])
|
||||
good_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read"])
|
||||
good_token3 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts"])
|
||||
good_token4 = insert(:oauth_token, user: admin, scopes: ["read:accounts"])
|
||||
good_token5 = insert(:oauth_token, user: admin, scopes: ["read"])
|
||||
|
||||
good_tokens = [good_token1, good_token2, good_token3, good_token4, good_token5]
|
||||
|
||||
bad_token1 = insert(:oauth_token, user: admin, scopes: ["read:accounts:partial"])
|
||||
bad_token2 = insert(:oauth_token, user: admin, scopes: ["admin:read:accounts:partial"])
|
||||
bad_token3 = nil
|
||||
|
||||
for good_token <- good_tokens do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, good_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
|
||||
for good_token <- good_tokens do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, nil)
|
||||
|> assign(:token, good_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
|
||||
for bad_token <- [bad_token1, bad_token2, bad_token3] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, bad_token)
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /api/pleroma/admin/users" do
|
||||
test "single user", %{admin: admin, conn: conn} do
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
avatar: %{"url" => [%{"href" => "https://someurl"}]},
|
||||
banner: %{"url" => [%{"href" => "https://somebanner"}]},
|
||||
bio: "Hello world!",
|
||||
name: "A guy"
|
||||
)
|
||||
|
||||
# Create some activities to check they got deleted later
|
||||
follower = insert(:user)
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, follower)
|
||||
{:ok, _, _, _} = CommonAPI.follow(follower, user)
|
||||
user = Repo.get(User, user.id)
|
||||
assert user.note_count == 1
|
||||
assert user.follower_count == 1
|
||||
assert user.following_count == 1
|
||||
refute user.deactivated
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end,
|
||||
perform: fn _, _ -> nil end do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> delete("/api/pleroma/admin/users?nickname=#{user.nickname}")
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert User.get_by_nickname(user.nickname).deactivated
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted users: @#{user.nickname}"
|
||||
|
||||
assert json_response(conn, 200) == [user.nickname]
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
assert user.deactivated
|
||||
|
||||
assert user.avatar == %{}
|
||||
assert user.banner == %{}
|
||||
assert user.note_count == 0
|
||||
assert user.follower_count == 0
|
||||
assert user.following_count == 0
|
||||
assert user.bio == ""
|
||||
assert user.name == nil
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(:_))
|
||||
end
|
||||
end
|
||||
|
||||
test "multiple users", %{admin: admin, conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> delete("/api/pleroma/admin/users", %{
|
||||
nicknames: [user_one.nickname, user_two.nickname]
|
||||
})
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
|
||||
response = json_response(conn, 200)
|
||||
assert response -- [user_one.nickname, user_two.nickname] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/users" do
|
||||
test "Create", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@example.org",
|
||||
"password" => "test"
|
||||
},
|
||||
%{
|
||||
"nickname" => "lain2",
|
||||
"email" => "lain2@example.org",
|
||||
"password" => "test"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
response = json_response(conn, 200) |> Enum.map(&Map.get(&1, "type"))
|
||||
assert response == ["success", "success"]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ["lain", "lain2"] -- Enum.map(log_entry.data["subjects"], & &1["nickname"]) == []
|
||||
end
|
||||
|
||||
test "Cannot create user with existing email", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
"nickname" => "lain",
|
||||
"email" => user.email,
|
||||
"password" => "test"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 409) == [
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
"email" => user.email,
|
||||
"nickname" => "lain"
|
||||
},
|
||||
"error" => "email has already been taken",
|
||||
"type" => "error"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "Cannot create user with existing nickname", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
"nickname" => user.nickname,
|
||||
"email" => "someuser@plerama.social",
|
||||
"password" => "test"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 409) == [
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
"email" => "someuser@plerama.social",
|
||||
"nickname" => user.nickname
|
||||
},
|
||||
"error" => "nickname has already been taken",
|
||||
"type" => "error"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "Multiple user creation works in transaction", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"users" => [
|
||||
%{
|
||||
"nickname" => "newuser",
|
||||
"email" => "newuser@pleroma.social",
|
||||
"password" => "test"
|
||||
},
|
||||
%{
|
||||
"nickname" => "lain",
|
||||
"email" => user.email,
|
||||
"password" => "test"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 409) == [
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
"email" => user.email,
|
||||
"nickname" => "lain"
|
||||
},
|
||||
"error" => "email has already been taken",
|
||||
"type" => "error"
|
||||
},
|
||||
%{
|
||||
"code" => 409,
|
||||
"data" => %{
|
||||
"email" => "newuser@pleroma.social",
|
||||
"nickname" => "newuser"
|
||||
},
|
||||
"error" => "",
|
||||
"type" => "error"
|
||||
}
|
||||
]
|
||||
|
||||
assert User.get_by_nickname("newuser") === nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/users/:nickname" do
|
||||
test "Show", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
|
||||
|
||||
assert user_response(user) == json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "when the user doesn't exist", %{conn: conn} do
|
||||
user = build(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}")
|
||||
|
||||
assert %{"error" => "Not found"} == json_response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/users/follow" do
|
||||
test "allows to force-follow another user", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users/follow", %{
|
||||
"follower" => follower.nickname,
|
||||
"followed" => user.nickname
|
||||
})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, user)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} made @#{follower.nickname} follow @#{user.nickname}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/users/unfollow" do
|
||||
test "allows to force-unfollow another user", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
User.follow(follower, user)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users/unfollow", %{
|
||||
"follower" => follower.nickname,
|
||||
"followed" => user.nickname
|
||||
})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
refute User.following?(follower, user)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} made @#{follower.nickname} unfollow @#{user.nickname}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users" do
|
||||
test "renders users array for the first page", %{conn: conn, admin: admin} do
|
||||
user = insert(:user, local: false, tags: ["foo", "bar"])
|
||||
user2 = insert(:user, approval_pending: true, registration_reason: "I'm a chill dude")
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?page=1")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(
|
||||
admin,
|
||||
%{"roles" => %{"admin" => true, "moderator" => false}}
|
||||
),
|
||||
user_response(user, %{"local" => false, "tags" => ["foo", "bar"]}),
|
||||
user_response(
|
||||
user2,
|
||||
%{
|
||||
"local" => true,
|
||||
"approval_pending" => true,
|
||||
"registration_reason" => "I'm a chill dude",
|
||||
"actor_type" => "Person"
|
||||
}
|
||||
)
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 3,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
end
|
||||
|
||||
test "pagination works correctly with service users", %{conn: conn} do
|
||||
service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido")
|
||||
|
||||
insert_list(25, :user)
|
||||
|
||||
assert %{"count" => 26, "page_size" => 10, "users" => users1} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?page=1&filters=", %{page_size: "10"})
|
||||
|> json_response(200)
|
||||
|
||||
assert Enum.count(users1) == 10
|
||||
assert service1 not in users1
|
||||
|
||||
assert %{"count" => 26, "page_size" => 10, "users" => users2} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?page=2&filters=", %{page_size: "10"})
|
||||
|> json_response(200)
|
||||
|
||||
assert Enum.count(users2) == 10
|
||||
assert service1 not in users2
|
||||
|
||||
assert %{"count" => 26, "page_size" => 10, "users" => users3} =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?page=3&filters=", %{page_size: "10"})
|
||||
|> json_response(200)
|
||||
|
||||
assert Enum.count(users3) == 6
|
||||
assert service1 not in users3
|
||||
end
|
||||
|
||||
test "renders empty array for the second page", %{conn: conn} do
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?page=2")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => []
|
||||
}
|
||||
end
|
||||
|
||||
test "regular search", %{conn: conn} do
|
||||
user = insert(:user, nickname: "bob")
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?query=bo")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user, %{"local" => true})]
|
||||
}
|
||||
end
|
||||
|
||||
test "search by domain", %{conn: conn} do
|
||||
user = insert(:user, nickname: "nickname@domain.com")
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?query=domain.com")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
test "search by full nickname", %{conn: conn} do
|
||||
user = insert(:user, nickname: "nickname@domain.com")
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?query=nickname@domain.com")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
test "search by display name", %{conn: conn} do
|
||||
user = insert(:user, name: "Display name")
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?name=display")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
test "search by email", %{conn: conn} do
|
||||
user = insert(:user, email: "email@example.com")
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?email=email@example.com")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
test "regular search with page size", %{conn: conn} do
|
||||
user = insert(:user, nickname: "aalice")
|
||||
user2 = insert(:user, nickname: "alice")
|
||||
|
||||
conn1 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=1")
|
||||
|
||||
assert json_response(conn1, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 1,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
|
||||
conn2 = get(conn, "/api/pleroma/admin/users?query=a&page_size=1&page=2")
|
||||
|
||||
assert json_response(conn2, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 1,
|
||||
"users" => [user_response(user2)]
|
||||
}
|
||||
end
|
||||
|
||||
test "only local users" do
|
||||
admin = insert(:user, is_admin: true, nickname: "john")
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
user = insert(:user, nickname: "bob")
|
||||
|
||||
insert(:user, nickname: "bobb", local: false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, token)
|
||||
|> get("/api/pleroma/admin/users?query=bo&filters=local")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
test "only local users with no query", %{conn: conn, admin: old_admin} do
|
||||
admin = insert(:user, is_admin: true, nickname: "john")
|
||||
user = insert(:user, nickname: "bob")
|
||||
|
||||
insert(:user, nickname: "bobb", local: false)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=local")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(user),
|
||||
user_response(admin, %{
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
}),
|
||||
user_response(old_admin, %{
|
||||
"deactivated" => false,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 3,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
end
|
||||
|
||||
test "only unconfirmed users", %{conn: conn} do
|
||||
sad_user = insert(:user, nickname: "sadboy", confirmation_pending: true)
|
||||
old_user = insert(:user, nickname: "oldboy", confirmation_pending: true)
|
||||
|
||||
insert(:user, nickname: "happyboy", approval_pending: false)
|
||||
insert(:user, confirmation_pending: false)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/users?filters=unconfirmed")
|
||||
|> json_response(200)
|
||||
|
||||
users =
|
||||
Enum.map([old_user, sad_user], fn user ->
|
||||
user_response(user, %{
|
||||
"confirmation_pending" => true,
|
||||
"approval_pending" => false
|
||||
})
|
||||
end)
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert result == %{"count" => 2, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
||||
test "only unapproved users", %{conn: conn} do
|
||||
user =
|
||||
insert(:user,
|
||||
nickname: "sadboy",
|
||||
approval_pending: true,
|
||||
registration_reason: "Plz let me in!"
|
||||
)
|
||||
|
||||
insert(:user, nickname: "happyboy", approval_pending: false)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
|
||||
|
||||
users = [
|
||||
user_response(
|
||||
user,
|
||||
%{"approval_pending" => true, "registration_reason" => "Plz let me in!"}
|
||||
)
|
||||
]
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
end
|
||||
|
||||
test "load only admins", %{conn: conn, admin: admin} do
|
||||
second_admin = insert(:user, is_admin: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=is_admin")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(admin, %{
|
||||
"deactivated" => false,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
}),
|
||||
user_response(second_admin, %{
|
||||
"deactivated" => false,
|
||||
"roles" => %{"admin" => true, "moderator" => false}
|
||||
})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
end
|
||||
|
||||
test "load only moderators", %{conn: conn} do
|
||||
moderator = insert(:user, is_moderator: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=is_moderator")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
user_response(moderator, %{
|
||||
"deactivated" => false,
|
||||
"roles" => %{"admin" => false, "moderator" => true}
|
||||
})
|
||||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "load users with actor_type is Person", %{admin: admin, conn: conn} do
|
||||
insert(:user, actor_type: "Service")
|
||||
insert(:user, actor_type: "Application")
|
||||
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get(user_path(conn, :list), %{actor_types: ["Person"]})
|
||||
|> json_response(200)
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
|
||||
user_response(user1),
|
||||
user_response(user2)
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert response == %{"count" => 3, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
||||
test "load users with actor_type is Person and Service", %{admin: admin, conn: conn} do
|
||||
user_service = insert(:user, actor_type: "Service")
|
||||
insert(:user, actor_type: "Application")
|
||||
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get(user_path(conn, :list), %{actor_types: ["Person", "Service"]})
|
||||
|> json_response(200)
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}}),
|
||||
user_response(user1),
|
||||
user_response(user2),
|
||||
user_response(user_service, %{"actor_type" => "Service"})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert response == %{"count" => 4, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
||||
test "load users with actor_type is Service", %{conn: conn} do
|
||||
user_service = insert(:user, actor_type: "Service")
|
||||
insert(:user, actor_type: "Application")
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get(user_path(conn, :list), %{actor_types: ["Service"]})
|
||||
|> json_response(200)
|
||||
|
||||
users = [user_response(user_service, %{"actor_type" => "Service"})]
|
||||
|
||||
assert response == %{"count" => 1, "page_size" => 50, "users" => users}
|
||||
end
|
||||
|
||||
test "load users with tags list", %{conn: conn} do
|
||||
user1 = insert(:user, tags: ["first"])
|
||||
user2 = insert(:user, tags: ["second"])
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?tags[]=first&tags[]=second")
|
||||
|
||||
users =
|
||||
[
|
||||
user_response(user1, %{"tags" => ["first"]}),
|
||||
user_response(user2, %{"tags" => ["second"]})
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
end
|
||||
|
||||
test "`active` filters out users pending approval", %{token: token} do
|
||||
insert(:user, approval_pending: true)
|
||||
%{id: user_id} = insert(:user, approval_pending: false)
|
||||
%{id: admin_id} = token.user
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, token.user)
|
||||
|> assign(:token, token)
|
||||
|> get("/api/pleroma/admin/users?filters=active")
|
||||
|
||||
assert %{
|
||||
"count" => 2,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{"id" => ^admin_id},
|
||||
%{"id" => ^user_id}
|
||||
]
|
||||
} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "it works with multiple filters" do
|
||||
admin = insert(:user, nickname: "john", is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
user = insert(:user, nickname: "bob", local: false, deactivated: true)
|
||||
|
||||
insert(:user, nickname: "ken", local: true, deactivated: true)
|
||||
insert(:user, nickname: "bobb", local: false, deactivated: false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> assign(:token, token)
|
||||
|> get("/api/pleroma/admin/users?filters=deactivated,external")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [user_response(user)]
|
||||
}
|
||||
end
|
||||
|
||||
test "it omits relay user", %{admin: admin, conn: conn} do
|
||||
assert %User{} = Relay.get_actor()
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
user_response(admin, %{"roles" => %{"admin" => true, "moderator" => false}})
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/activate", %{admin: admin, conn: conn} do
|
||||
user_one = insert(:user, deactivated: true)
|
||||
user_two = insert(:user, deactivated: true)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
"/api/pleroma/admin/users/activate",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["deactivated"]) == [false, false]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} activated users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/deactivate", %{admin: admin, conn: conn} do
|
||||
user_one = insert(:user, deactivated: false)
|
||||
user_two = insert(:user, deactivated: false)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
"/api/pleroma/admin/users/deactivate",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["deactivated"]) == [true, true]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
|
||||
user_one = insert(:user, approval_pending: true)
|
||||
user_two = insert(:user, approval_pending: true)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
"/api/pleroma/admin/users/approve",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["approval_pending"]) == [false, false]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = patch(conn, "/api/pleroma/admin/users/#{user.nickname}/toggle_activation")
|
||||
|
||||
assert json_response(conn, 200) ==
|
||||
user_response(
|
||||
user,
|
||||
%{"deactivated" => !user.deactivated}
|
||||
)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deactivated users: @#{user.nickname}"
|
||||
end
|
||||
|
||||
defp user_response(user, attrs \\ %{}) do
|
||||
%{
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
"local" => user.local,
|
||||
"tags" => [],
|
||||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil,
|
||||
"actor_type" => "Person"
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
end
|
||||
|
|
@ -143,6 +143,20 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
assert user2 in users
|
||||
end
|
||||
|
||||
test "it returns users by actor_types" do
|
||||
user_service = insert(:user, actor_type: "Service")
|
||||
user_application = insert(:user, actor_type: "Application")
|
||||
user1 = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
||||
{:ok, [^user_service], 1} = Search.user(%{actor_types: ["Service"]})
|
||||
{:ok, [^user_application], 1} = Search.user(%{actor_types: ["Application"]})
|
||||
{:ok, [^user1, ^user2], 2} = Search.user(%{actor_types: ["Person"]})
|
||||
|
||||
{:ok, [^user_service, ^user1, ^user2], 3} =
|
||||
Search.user(%{actor_types: ["Person", "Service"]})
|
||||
end
|
||||
|
||||
test "it returns user by display name" do
|
||||
user = insert(:user, name: "Display name")
|
||||
insert(:user)
|
||||
|
|
@ -178,9 +192,20 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
assert count == 1
|
||||
end
|
||||
|
||||
test "it returns unconfirmed user" do
|
||||
unconfirmed = insert(:user, confirmation_pending: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
{:ok, _results, total} = Search.user()
|
||||
{:ok, [^unconfirmed], count} = Search.user(%{unconfirmed: true})
|
||||
assert total == 3
|
||||
assert count == 1
|
||||
end
|
||||
|
||||
test "it returns non-discoverable users" do
|
||||
insert(:user)
|
||||
insert(:user, discoverable: false)
|
||||
insert(:user, is_discoverable: false)
|
||||
|
||||
{:ok, _results, total} = Search.user()
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.CommonAPITest do
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Chat
|
||||
|
|
@ -95,12 +95,26 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
describe "posting chat messages" do
|
||||
setup do: clear_config([:instance, :chat_limit])
|
||||
|
||||
test "it posts a self-chat" do
|
||||
author = insert(:user)
|
||||
recipient = author
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post_chat_message(
|
||||
author,
|
||||
recipient,
|
||||
"remember to buy milk when milk truk arive"
|
||||
)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
end
|
||||
|
||||
test "it posts a chat message without content but with an attachment" do
|
||||
author = insert(:user)
|
||||
recipient = insert(:user)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -622,7 +636,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:error, "The status is over the character limit"} =
|
||||
CommonAPI.post(user, %{status: "foobar"})
|
||||
|
||||
assert {:ok, activity} = CommonAPI.post(user, %{status: "12345"})
|
||||
assert {:ok, _activity} = CommonAPI.post(user, %{status: "12345"})
|
||||
end
|
||||
|
||||
test "it can handle activities that expire" do
|
||||
|
|
@ -908,12 +922,34 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert CommonAPI.thread_muted?(user, activity)
|
||||
end
|
||||
|
||||
test "add expiring mute", %{user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.add_mute(user, activity, %{expires_in: 60})
|
||||
assert CommonAPI.thread_muted?(user, activity)
|
||||
|
||||
worker = Pleroma.Workers.MuteExpireWorker
|
||||
args = %{"op" => "unmute_conversation", "user_id" => user.id, "activity_id" => activity.id}
|
||||
|
||||
assert_enqueued(
|
||||
worker: worker,
|
||||
args: args
|
||||
)
|
||||
|
||||
assert :ok = perform_job(worker, args)
|
||||
refute CommonAPI.thread_muted?(user, activity)
|
||||
end
|
||||
|
||||
test "remove mute", %{user: user, activity: activity} do
|
||||
CommonAPI.add_mute(user, activity)
|
||||
{:ok, _} = CommonAPI.remove_mute(user, activity)
|
||||
refute CommonAPI.thread_muted?(user, activity)
|
||||
end
|
||||
|
||||
test "remove mute by ids", %{user: user, activity: activity} do
|
||||
CommonAPI.add_mute(user, activity)
|
||||
{:ok, _} = CommonAPI.remove_mute(user.id, activity.id)
|
||||
refute CommonAPI.thread_muted?(user, activity)
|
||||
end
|
||||
|
||||
test "check that mutes can't be duplicate", %{user: user, activity: activity} do
|
||||
CommonAPI.add_mute(user, activity)
|
||||
{:error, _} = CommonAPI.add_mute(user, activity)
|
||||
|
|
@ -1071,7 +1107,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
test "cancels a pending follow for a local user" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
followed = insert(:user, is_locked: true)
|
||||
|
||||
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
|
||||
CommonAPI.follow(follower, followed)
|
||||
|
|
@ -1093,7 +1129,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
test "cancels a pending follow for a remote user" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true, local: false, ap_enabled: true)
|
||||
followed = insert(:user, is_locked: true, local: false, ap_enabled: true)
|
||||
|
||||
assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} =
|
||||
CommonAPI.follow(follower, followed)
|
||||
|
|
@ -1116,7 +1152,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
describe "accept_follow_request/2" do
|
||||
test "after acceptance, it sets all existing pending follow request states to 'accept'" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
follower = insert(:user)
|
||||
follower_two = insert(:user)
|
||||
|
||||
|
|
@ -1136,7 +1172,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "after rejection, it sets all existing pending follow request states to 'reject'" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
follower = insert(:user)
|
||||
follower_two = insert(:user)
|
||||
|
||||
|
|
@ -1156,7 +1192,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "doesn't create a following relationship if the corresponding follow request doesn't exist" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
not_follower = insert(:user)
|
||||
CommonAPI.accept_follow_request(not_follower, user)
|
||||
|
||||
|
|
|
|||
68
test/pleroma/web/endpoint/metrics_exporter_test.exs
Normal file
68
test/pleroma/web/endpoint/metrics_exporter_test.exs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Endpoint.MetricsExporterTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Web.Endpoint.MetricsExporter
|
||||
|
||||
defp config do
|
||||
Application.get_env(:prometheus, MetricsExporter)
|
||||
end
|
||||
|
||||
describe "with default config" do
|
||||
test "does NOT expose app metrics", %{conn: conn} do
|
||||
conn
|
||||
|> get(config()[:path])
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when enabled" do
|
||||
setup do
|
||||
initial_config = config()
|
||||
on_exit(fn -> Application.put_env(:prometheus, MetricsExporter, initial_config) end)
|
||||
|
||||
Application.put_env(
|
||||
:prometheus,
|
||||
MetricsExporter,
|
||||
Keyword.put(initial_config, :enabled, true)
|
||||
)
|
||||
end
|
||||
|
||||
test "serves app metrics", %{conn: conn} do
|
||||
conn = get(conn, config()[:path])
|
||||
assert response = response(conn, 200)
|
||||
|
||||
for metric <- [
|
||||
"http_requests_total",
|
||||
"http_request_duration_microseconds",
|
||||
"phoenix_controller_call_duration",
|
||||
"telemetry_scrape_duration",
|
||||
"erlang_vm_memory_atom_bytes_total"
|
||||
] do
|
||||
assert response =~ ~r/#{metric}/
|
||||
end
|
||||
end
|
||||
|
||||
test "when IP whitelist configured, " <>
|
||||
"serves app metrics only if client IP is whitelisted",
|
||||
%{conn: conn} do
|
||||
Application.put_env(
|
||||
:prometheus,
|
||||
MetricsExporter,
|
||||
Keyword.put(config(), :ip_whitelist, ["127.127.127.127", {1, 1, 1, 1}, '255.255.255.255'])
|
||||
)
|
||||
|
||||
conn
|
||||
|> get(config()[:path])
|
||||
|> json_response(404)
|
||||
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 127, 127, 127})
|
||||
|> get(config()[:path])
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -20,15 +20,26 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "GET /*path adds a title", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
|
||||
assert conn
|
||||
|> get("/")
|
||||
|> html_response(200) =~ "<title>a cool title</title>"
|
||||
end
|
||||
|
||||
describe "preloaded data and metadata attached to" do
|
||||
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
|
||||
user = insert(:user)
|
||||
user_missing = get(conn, "/foo")
|
||||
user_present = get(conn, "/#{user.nickname}")
|
||||
|
||||
assert(html_response(user_missing, 200) =~ "<!--server-generated-meta-->")
|
||||
assert html_response(user_missing, 200) =~ "<!--server-generated-meta-->"
|
||||
refute html_response(user_present, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(user_present, 200) =~ "initial-results"
|
||||
assert html_response(user_present, 200) =~ "<title>a cool title</title>"
|
||||
end
|
||||
|
||||
test "GET /*path", %{conn: conn} do
|
||||
|
|
@ -44,10 +55,13 @@ defmodule Pleroma.Web.FallbackTest do
|
|||
|
||||
describe "preloaded data is attached to" do
|
||||
test "GET /main/public", %{conn: conn} do
|
||||
clear_config([:instance, :name], "a cool title")
|
||||
|
||||
public_page = get(conn, "/main/public")
|
||||
|
||||
refute html_response(public_page, 200) =~ "<!--server-generated-meta-->"
|
||||
assert html_response(public_page, 200) =~ "initial-results"
|
||||
assert html_response(public_page, 200) =~ "<title>a cool title</title>"
|
||||
end
|
||||
|
||||
test "GET /main/all", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ defmodule Pleroma.Web.FedSockets.FedRegistryTest do
|
|||
end
|
||||
|
||||
test "will be ignored" do
|
||||
assert {:ok, %SocketInfo{origin: origin, pid: pid_one}} =
|
||||
assert {:ok, %SocketInfo{origin: origin, pid: _pid_one}} =
|
||||
FedRegistry.get_fed_socket(@good_domain_origin)
|
||||
|
||||
assert origin == "good.domain:80"
|
||||
|
|
@ -63,7 +63,7 @@ defmodule Pleroma.Web.FedSockets.FedRegistryTest do
|
|||
test "the newer process will be closed" do
|
||||
pid_two = build_test_socket(@good_domain)
|
||||
|
||||
assert {:ok, %SocketInfo{origin: origin, pid: pid_one}} =
|
||||
assert {:ok, %SocketInfo{origin: origin, pid: _pid_one}} =
|
||||
FedRegistry.get_fed_socket(@good_domain_origin)
|
||||
|
||||
assert origin == "good.domain:80"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
import Pleroma.Factory
|
||||
import SweetXml
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Feed.FeedView
|
||||
|
|
@ -15,7 +16,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
setup do: clear_config([:feed])
|
||||
|
||||
test "gets a feed (ATOM)", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 25, omission: "..."}
|
||||
)
|
||||
|
|
@ -82,7 +83,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
end
|
||||
|
||||
test "gets a feed (RSS)", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 25, omission: "..."}
|
||||
)
|
||||
|
|
@ -157,7 +158,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||
|> response(200)
|
||||
|
||||
xml = parse(response)
|
||||
|
|
@ -183,14 +184,12 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
end
|
||||
|
||||
describe "private instance" do
|
||||
setup do: clear_config([:instance, :public])
|
||||
setup do: clear_config([:instance, :public], false)
|
||||
|
||||
test "returns 404 for tags feed", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,16 +12,17 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Feed.FeedView
|
||||
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:static_fe, :enabled], false)
|
||||
|
||||
describe "feed" do
|
||||
setup do: clear_config([:feed])
|
||||
|
||||
test "gets an atom feed", %{conn: conn} do
|
||||
setup do
|
||||
Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 10, omission: "..."}
|
||||
%{max_length: 15, omission: "..."}
|
||||
)
|
||||
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -29,7 +30,8 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
note =
|
||||
insert(:note,
|
||||
data: %{
|
||||
"content" => "This is :moominmamma: note ",
|
||||
"content" => "This & this is :moominmamma: note ",
|
||||
"source" => "This & this is :moominmamma: note ",
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
|
|
@ -37,7 +39,9 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
]
|
||||
}
|
||||
],
|
||||
"inReplyTo" => activity.data["id"]
|
||||
"inReplyTo" => activity.data["id"],
|
||||
"context" => "2hu & as",
|
||||
"summary" => "2hu & as"
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -48,7 +52,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
insert(:note,
|
||||
user: user,
|
||||
data: %{
|
||||
"content" => "42 This is :moominmamma: note ",
|
||||
"content" => "42 & This is :moominmamma: note ",
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
|
@ -56,6 +60,10 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
note_activity2 = insert(:note_activity, note: note2)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
[user: user, object: object, max_id: note_activity2.id]
|
||||
end
|
||||
|
||||
test "gets an atom feed", %{conn: conn, user: user, object: object, max_id: max_id} do
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|
|
@ -67,13 +75,15 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//entry/title/text()"l)
|
||||
|
||||
assert activity_titles == ['42 This...', 'This is...']
|
||||
assert resp =~ object.data["content"]
|
||||
assert activity_titles == ['42 & Thi...', 'This & t...']
|
||||
assert resp =~ FeedView.escape(object.data["content"])
|
||||
assert resp =~ FeedView.escape(object.data["summary"])
|
||||
assert resp =~ FeedView.escape(object.data["context"])
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
|
||||
|> get("/users/#{user.nickname}/feed", %{"max_id" => max_id})
|
||||
|> response(200)
|
||||
|
||||
activity_titles =
|
||||
|
|
@ -81,47 +91,10 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//entry/title/text()"l)
|
||||
|
||||
assert activity_titles == ['This is...']
|
||||
assert activity_titles == ['This & t...']
|
||||
end
|
||||
|
||||
test "gets a rss feed", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 10, omission: "..."}
|
||||
)
|
||||
|
||||
activity = insert(:note_activity)
|
||||
|
||||
note =
|
||||
insert(:note,
|
||||
data: %{
|
||||
"content" => "This is :moominmamma: note ",
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
|
||||
]
|
||||
}
|
||||
],
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
||||
note_activity = insert(:note_activity, note: note)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
note2 =
|
||||
insert(:note,
|
||||
user: user,
|
||||
data: %{
|
||||
"content" => "42 This is :moominmamma: note ",
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
||||
note_activity2 = insert(:note_activity, note: note2)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
test "gets a rss feed", %{conn: conn, user: user, object: object, max_id: max_id} do
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|
|
@ -133,13 +106,15 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//item/title/text()"l)
|
||||
|
||||
assert activity_titles == ['42 This...', 'This is...']
|
||||
assert resp =~ object.data["content"]
|
||||
assert activity_titles == ['42 & Thi...', 'This & t...']
|
||||
assert resp =~ FeedView.escape(object.data["content"])
|
||||
assert resp =~ FeedView.escape(object.data["summary"])
|
||||
assert resp =~ FeedView.escape(object.data["context"])
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
|
||||
|> get("/users/#{user.nickname}/feed.rss", %{"max_id" => max_id})
|
||||
|> response(200)
|
||||
|
||||
activity_titles =
|
||||
|
|
@ -147,7 +122,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//item/title/text()"l)
|
||||
|
||||
assert activity_titles == ['This is...']
|
||||
assert activity_titles == ['This & t...']
|
||||
end
|
||||
|
||||
test "returns 404 for a missing feed", %{conn: conn} do
|
||||
|
|
@ -192,6 +167,16 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "does not require authentication on non-federating instances", %{conn: conn} do
|
||||
clear_config([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get("/users/#{user.nickname}/feed.rss")
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
|
||||
# Note: see ActivityPubControllerTest for JSON format tests
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
test "works by nickname" do
|
||||
user = insert(:user)
|
||||
|
||||
assert %{"id" => user_id} =
|
||||
assert %{"id" => _user_id} =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
|
@ -43,7 +43,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
assert %{"id" => user_id} =
|
||||
assert %{"id" => _user_id} =
|
||||
build_conn()
|
||||
|> get("/api/v1/accounts/#{user.nickname}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
|
@ -380,7 +380,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -706,7 +706,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "cancelling follow request", %{conn: conn} do
|
||||
%{id: other_user_id} = insert(:user, %{locked: true})
|
||||
%{id: other_user_id} = insert(:user, %{is_locked: true})
|
||||
|
||||
assert %{"id" => ^other_user_id, "following" => false, "requested" => true} =
|
||||
conn
|
||||
|
|
@ -1429,10 +1429,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
test "returns lists to which the account belongs" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:lists"])
|
||||
other_user = insert(:user)
|
||||
assert {:ok, %Pleroma.List{id: list_id} = list} = Pleroma.List.create("Test List", user)
|
||||
assert {:ok, %Pleroma.List{id: _list_id} = list} = Pleroma.List.create("Test List", user)
|
||||
{:ok, %{following: _following}} = Pleroma.List.follow(list, other_user)
|
||||
|
||||
assert [%{"id" => list_id, "title" => "Test List"}] =
|
||||
assert [%{"id" => _list_id, "title" => "Test List"}] =
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{other_user.id}/lists")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
|
@ -1509,28 +1509,103 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
test "getting a list of mutes" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:mutes"])
|
||||
other_user = insert(:user)
|
||||
%{id: id1} = other_user1 = insert(:user)
|
||||
%{id: id2} = other_user2 = insert(:user)
|
||||
%{id: id3} = other_user3 = insert(:user)
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, other_user)
|
||||
{:ok, _user_relationships} = User.mute(user, other_user1)
|
||||
{:ok, _user_relationships} = User.mute(user, other_user2)
|
||||
{:ok, _user_relationships} = User.mute(user, other_user3)
|
||||
|
||||
conn = get(conn, "/api/v1/mutes")
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response_and_validate_schema(conn, 200)
|
||||
assert [id1, id2, id3] == Enum.map(result, & &1["id"])
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id1}] = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}&max_id=#{id3}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes?since_id=#{id1}&limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
|
||||
test "getting a list of blocks" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
||||
other_user = insert(:user)
|
||||
%{id: id1} = other_user1 = insert(:user)
|
||||
%{id: id2} = other_user2 = insert(:user)
|
||||
%{id: id3} = other_user3 = insert(:user)
|
||||
|
||||
{:ok, _user_relationship} = User.block(user, other_user)
|
||||
{:ok, _user_relationship} = User.block(user, other_user1)
|
||||
{:ok, _user_relationship} = User.block(user, other_user3)
|
||||
{:ok, _user_relationship} = User.block(user, other_user2)
|
||||
|
||||
conn =
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response_and_validate_schema(conn, 200)
|
||||
assert [id1, id2, id3] == Enum.map(result, & &1["id"])
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks?limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id1}] = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks?since_id=#{id1}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}, %{"id" => ^id3}] = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks?since_id=#{id1}&max_id=#{id3}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks?since_id=#{id1}&limit=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^id2}] = result
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -28,10 +29,10 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
user_three: user_three,
|
||||
conn: conn
|
||||
} do
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
{:ok, direct} = create_direct_message(user_one, [user_two, user_three])
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(user_two) == 1
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
|
|
@ -54,12 +55,33 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|
||||
account_ids = Enum.map(res_accounts, & &1["id"])
|
||||
assert length(res_accounts) == 2
|
||||
assert user_one.id not in account_ids
|
||||
assert user_two.id in account_ids
|
||||
assert user_three.id in account_ids
|
||||
assert is_binary(res_id)
|
||||
assert unread == false
|
||||
assert res_last_status["id"] == direct.id
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
assert res_last_status["account"]["id"] == user_one.id
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
end
|
||||
|
||||
test "includes the user if the user is the only participant", %{
|
||||
user: user_one,
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, _direct} = create_direct_message(user_one, [])
|
||||
|
||||
res_conn = get(conn, "/api/v1/conversations")
|
||||
|
||||
assert response = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"accounts" => [account]
|
||||
}
|
||||
] = response
|
||||
|
||||
assert user_one.id == account["id"]
|
||||
end
|
||||
|
||||
test "observes limit params", %{
|
||||
|
|
@ -134,8 +156,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
user_two = insert(:user)
|
||||
{:ok, direct} = create_direct_message(user_one, [user_two])
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
assert Participation.unread_count(user_two) == 1
|
||||
|
||||
user_two_conn =
|
||||
build_conn()
|
||||
|
|
@ -155,8 +177,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|> post("/api/v1/conversations/#{direct_conversation_id}/read")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
|
||||
# The conversation is marked as unread on reply
|
||||
{:ok, _} =
|
||||
|
|
@ -171,8 +193,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|> get("/api/v1/conversations")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 1
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
|
||||
# A reply doesn't increment the user's unread_conversation_count if the conversation is unread
|
||||
{:ok, _} =
|
||||
|
|
@ -182,8 +204,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
in_reply_to_status_id: direct.id
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(user_one) == 1
|
||||
assert Participation.unread_count(user_two) == 0
|
||||
end
|
||||
|
||||
test "(vanilla) Mastodon frontend behaviour", %{user: user_one, conn: conn} do
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
|
||||
describe "locked accounts" do
|
||||
setup do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
%{conn: conn} = oauth_access(["follow"], user: user)
|
||||
%{user: user, conn: conn}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
|
||||
setup do
|
||||
image = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
|
||||
setup %{user: actor} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
|
||||
setup %{user: actor} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,34 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [_] = result
|
||||
end
|
||||
|
||||
test "by default, does not contain pleroma:report" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
|
||||
user
|
||||
|> User.admin_api_update(%{is_moderator: true})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{status: "hey"})
|
||||
|
||||
{:ok, _report} =
|
||||
CommonAPI.report(third_user, %{account_id: other_user.id, status_ids: [activity.id]})
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [] == result
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications?include_types[]=pleroma:report")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [_] = result
|
||||
end
|
||||
|
||||
test "getting a single notification" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
|
@ -502,7 +530,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
assert length(json_response_and_validate_schema(ret_conn, 200)) == 1
|
||||
|
||||
{:ok, _user_relationships} = User.mute(user, user2, false)
|
||||
{:ok, _user_relationships} = User.mute(user, user2, %{notifications: false})
|
||||
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
test "posting an undefined status with an attachment", %{user: user, conn: conn} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -408,7 +408,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> Kernel.<>("Z")
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -937,7 +937,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> get("/api/v1/statuses/#{reblog_activity1.id}")
|
||||
|
||||
assert %{
|
||||
"reblog" => %{"id" => id, "reblogged" => false, "reblogs_count" => 2},
|
||||
"reblog" => %{"id" => _id, "reblogged" => false, "reblogs_count" => 2},
|
||||
"reblogged" => false,
|
||||
"favourited" => false,
|
||||
"bookmarked" => false
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
|
|
@ -148,6 +147,18 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
activities = json_response_and_validate_schema(res_conn, 200)
|
||||
[%{"id" => ^activity_id}] = activities
|
||||
end
|
||||
|
||||
test "can be filtered by instance", %{conn: conn} do
|
||||
user = insert(:user, ap_id: "https://lain.com/users/lain")
|
||||
insert(:note_activity, local: false)
|
||||
insert(:note_activity, local: false)
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/public?instance=lain.com")
|
||||
|
||||
assert length(json_response_and_validate_schema(conn, :ok)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_activities do
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|
||||
test "updates the user's avatar", %{user: user, conn: conn} do
|
||||
new_avatar = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|
||||
test "updates the user's banner", %{user: user, conn: conn} do
|
||||
new_header = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -265,7 +265,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
|
|||
|
||||
test "updates the user's background", %{conn: conn, user: user} do
|
||||
new_header = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -277,7 +277,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
{:ok, user} = User.follow(user, other_user)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
{:ok, _subscription} = User.subscribe(user, other_user)
|
||||
{:ok, _user_relationships} = User.mute(user, other_user, true)
|
||||
{:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true})
|
||||
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
|
||||
|
||||
expected =
|
||||
|
|
@ -332,7 +332,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
test "represent a relationship for the user with a pending follow request" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, locked: true)
|
||||
other_user = insert(:user, is_locked: true)
|
||||
|
||||
{:ok, user, other_user, _} = CommonAPI.follow(user, other_user)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
|
@ -481,7 +481,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "shows non-zero when follow requests are pending" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
|
|
@ -493,7 +493,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "decreases when accepting a follow request" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
|
|
@ -510,7 +510,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "decreases when rejecting a follow request" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
|
|
@ -527,14 +527,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "shows non-zero when historical unapproved requests are present" do
|
||||
user = insert(:user, locked: true)
|
||||
user = insert(:user, is_locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
{:ok, user} = User.update_and_set_cache(user, %{locked: false})
|
||||
{:ok, user} = User.update_and_set_cache(user, %{is_locked: false})
|
||||
|
||||
assert %{locked: false, follow_requests_count: 1} =
|
||||
AccountView.render("show.json", %{user: user, for: user})
|
||||
|
|
|
|||
|
|
@ -36,9 +36,11 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
|
|||
|
||||
assert conversation.id == participation.id |> to_string()
|
||||
assert conversation.last_status.id == activity.id
|
||||
assert conversation.last_status.account.id == user.id
|
||||
|
||||
assert [account] = conversation.accounts
|
||||
assert account.id == other_user.id
|
||||
|
||||
assert conversation.last_status.pleroma.direct_conversation_id == participation.id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.AdminAPI.Report
|
||||
alias Pleroma.Web.AdminAPI.ReportView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
|
@ -207,6 +209,26 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Report notification" do
|
||||
reporting_user = insert(:user)
|
||||
reported_user = insert(:user)
|
||||
{:ok, moderator_user} = insert(:user) |> User.admin_api_update(%{is_moderator: true})
|
||||
|
||||
{:ok, activity} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false, is_muted: false},
|
||||
type: "pleroma:report",
|
||||
account: AccountView.render("show.json", %{user: reporting_user, for: moderator_user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at),
|
||||
report: ReportView.render("show.json", Report.extract_report_info(activity))
|
||||
}
|
||||
|
||||
test_notifications_rendering([notification], moderator_user, [expected])
|
||||
end
|
||||
|
||||
test "muted notification" do
|
||||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
|||
],
|
||||
voted: false,
|
||||
votes_count: 0,
|
||||
voters_count: nil
|
||||
voters_count: 0
|
||||
}
|
||||
|
||||
result = PollView.render("show.json", %{object: object})
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
|
|||
|> NaiveDateTime.to_iso8601()
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -420,6 +420,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
"href" => "someurl"
|
||||
}
|
||||
],
|
||||
"blurhash" => "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn",
|
||||
"uuid" => 6
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +432,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
preview_url: "someurl",
|
||||
text_url: "someurl",
|
||||
description: nil,
|
||||
pleroma: %{mime_type: "image/png"}
|
||||
pleroma: %{mime_type: "image/png"},
|
||||
blurhash: "UJJ8X[xYW,%Jtq%NNFbXB5j]IVM|9GV=WHRn"
|
||||
}
|
||||
|
||||
api_spec = Pleroma.Web.ApiSpec.spec()
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ defmodule Pleroma.Web.Metadata.Providers.RestrictIndexingTest do
|
|||
|
||||
test "for local user" do
|
||||
assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
|
||||
user: %Pleroma.User{local: true, discoverable: true}
|
||||
user: %Pleroma.User{local: true, is_discoverable: true}
|
||||
}) == []
|
||||
end
|
||||
|
||||
test "for local user when discoverable is false" do
|
||||
assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
|
||||
user: %Pleroma.User{local: true, discoverable: false}
|
||||
user: %Pleroma.User{local: true, is_discoverable: false}
|
||||
}) == [{:meta, [name: "robots", content: "noindex, noarchive"], []}]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ defmodule Pleroma.Web.MetadataTest do
|
|||
end
|
||||
|
||||
test "for local user" do
|
||||
user = insert(:user, discoverable: false)
|
||||
user = insert(:user, is_discoverable: false)
|
||||
|
||||
assert Pleroma.Web.Metadata.build_tags(%{user: user}) =~
|
||||
"<meta content=\"noindex, noarchive\" name=\"robots\">"
|
||||
end
|
||||
|
||||
test "for local user set to discoverable" do
|
||||
user = insert(:user, discoverable: true)
|
||||
user = insert(:user, is_discoverable: true)
|
||||
|
||||
refute Pleroma.Web.Metadata.build_tags(%{user: user}) =~
|
||||
"<meta content=\"noindex, noarchive\" name=\"robots\">"
|
||||
|
|
@ -33,14 +33,14 @@ defmodule Pleroma.Web.MetadataTest do
|
|||
describe "no metadata for private instances" do
|
||||
test "for local user set to discoverable" do
|
||||
clear_config([:instance, :public], false)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio", discoverable: true)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio", is_discoverable: true)
|
||||
|
||||
assert "" = Pleroma.Web.Metadata.build_tags(%{user: user})
|
||||
end
|
||||
|
||||
test "search exclusion metadata is included" do
|
||||
clear_config([:instance, :public], false)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio", discoverable: false)
|
||||
user = insert(:user, bio: "This is my secret fedi account bio", is_discoverable: false)
|
||||
|
||||
assert ~s(<meta content="noindex, noarchive" name="robots">) ==
|
||||
Pleroma.Web.Metadata.build_tags(%{user: user})
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 302)
|
||||
assert html_response(conn, 302)
|
||||
|
||||
redirect_query = URI.parse(redirected_to(conn)).query
|
||||
assert %{"state" => state_param} = URI.decode_query(redirect_query)
|
||||
|
|
@ -119,7 +119,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 302)
|
||||
assert html_response(conn, 302)
|
||||
assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
|
||||
end
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 302)
|
||||
assert html_response(conn, 302)
|
||||
assert redirected_to(conn) == app.redirect_uris
|
||||
assert get_flash(conn, :error) == "Failed to authenticate: (error description)."
|
||||
end
|
||||
|
|
@ -238,7 +238,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 302)
|
||||
assert html_response(conn, 302)
|
||||
assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
|
||||
end
|
||||
|
||||
|
|
@ -268,7 +268,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 401)
|
||||
assert html_response(conn, 401)
|
||||
end
|
||||
|
||||
test "with invalid params, POST /oauth/register?op=register renders registration_details page",
|
||||
|
|
@ -336,7 +336,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 302)
|
||||
assert html_response(conn, 302)
|
||||
assert redirected_to(conn) =~ ~r/#{redirect_uri}\?code=.+/
|
||||
end
|
||||
|
||||
|
|
@ -367,7 +367,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
)
|
||||
|
||||
assert response = html_response(conn, 401)
|
||||
assert html_response(conn, 401)
|
||||
end
|
||||
|
||||
test "with invalid params, POST /oauth/register?op=connect renders registration_details page",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -21,7 +20,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:static_fe, :enabled], false)
|
||||
|
||||
describe "Mastodon compatibility routes" do
|
||||
setup %{conn: conn} do
|
||||
|
|
@ -215,15 +214,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
clear_config([:instance, :federating], false)
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user)
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{note_activity.id}")
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -325,14 +325,16 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> response(404)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn,
|
||||
note_activity: note_activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user)
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.User.Backup
|
||||
alias Pleroma.Web.PleromaAPI.BackupView
|
||||
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
clear_config([Backup, :limit_days])
|
||||
oauth_access(["read:accounts"])
|
||||
end
|
||||
|
||||
test "GET /api/v1/pleroma/backups", %{user: user, conn: conn} do
|
||||
assert {:ok, %Oban.Job{args: %{"backup_id" => backup_id}}} = Backup.create(user)
|
||||
|
||||
backup = Backup.get(backup_id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/backups")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"content_type" => "application/zip",
|
||||
"url" => url,
|
||||
"file_size" => 0,
|
||||
"processed" => false,
|
||||
"inserted_at" => _
|
||||
}
|
||||
] = response
|
||||
|
||||
assert url == BackupView.download_url(backup)
|
||||
|
||||
Pleroma.Tests.ObanHelpers.perform_all()
|
||||
|
||||
assert [
|
||||
%{
|
||||
"url" => ^url,
|
||||
"processed" => true
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/backups")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "POST /api/v1/pleroma/backups", %{user: _user, conn: conn} do
|
||||
assert [
|
||||
%{
|
||||
"content_type" => "application/zip",
|
||||
"url" => url,
|
||||
"file_size" => 0,
|
||||
"processed" => false,
|
||||
"inserted_at" => _
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> post("/api/v1/pleroma/backups")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
Pleroma.Tests.ObanHelpers.perform_all()
|
||||
|
||||
assert [
|
||||
%{
|
||||
"url" => ^url,
|
||||
"processed" => true
|
||||
}
|
||||
] =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/backups")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
days = Pleroma.Config.get([Backup, :limit_days])
|
||||
|
||||
assert %{"error" => "Last export was less than #{days} days ago"} ==
|
||||
conn
|
||||
|> post("/api/v1/pleroma/backups")
|
||||
|> json_response_and_validate_schema(400)
|
||||
end
|
||||
end
|
||||
|
|
@ -82,11 +82,13 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
result =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> put_req_header("idempotency-key", "123")
|
||||
|> post("/api/v1/pleroma/chats/#{chat.id}/messages", %{"content" => "Hallo!!"})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert result["content"] == "Hallo!!"
|
||||
assert result["chat_id"] == chat.id |> to_string()
|
||||
assert result["idempotency_key"] == "123"
|
||||
end
|
||||
|
||||
test "it fails if there is no content", %{conn: conn, user: user} do
|
||||
|
|
@ -105,7 +107,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
|
||||
test "it works with an attachment", %{conn: conn, user: user} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -341,6 +343,35 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
assert length(result) == 0
|
||||
end
|
||||
|
||||
test "it does not return chats with users you muted", %{conn: conn, user: user} do
|
||||
recipient = insert(:user)
|
||||
|
||||
{:ok, _} = Chat.get_or_create(user.id, recipient.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/chats")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 1
|
||||
|
||||
User.mute(user, recipient)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/chats")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 0
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/chats?with_muted=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(result) == 1
|
||||
end
|
||||
|
||||
test "it returns all chats", %{conn: conn, user: user} do
|
||||
Enum.each(1..30, fn _ ->
|
||||
recipient = insert(:user)
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation2, participation1] = Participation.for_user(other_user)
|
||||
assert Participation.get(participation2.id).read == false
|
||||
assert Participation.get(participation1.id).read == false
|
||||
assert User.get_cached_by_id(other_user.id).unread_conversation_count == 2
|
||||
assert Participation.unread_count(other_user) == 2
|
||||
|
||||
[%{"unread" => false}, %{"unread" => false}] =
|
||||
conn
|
||||
|
|
@ -131,6 +131,6 @@ defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do
|
|||
[participation2, participation1] = Participation.for_user(other_user)
|
||||
assert Participation.get(participation2.id).read == true
|
||||
assert Participation.get(participation1.id).read == true
|
||||
assert User.get_cached_by_id(other_user.id).unread_conversation_count == 0
|
||||
assert Participation.unread_count(other_user) == 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -569,7 +569,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
|
||||
test "for pack name with special chars", %{conn: conn} do
|
||||
assert %{
|
||||
"files" => files,
|
||||
"files" => _files,
|
||||
"files_count" => 1,
|
||||
"pack" => %{
|
||||
"can-download" => true,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaApi.InstancesControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Instances
|
||||
|
||||
setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
|
||||
|
||||
setup do
|
||||
constant = "http://consistently-unreachable.name/"
|
||||
eventual = "http://eventually-unreachable.com/path"
|
||||
|
||||
{:ok, %Pleroma.Instances.Instance{unreachable_since: constant_unreachable}} =
|
||||
Instances.set_consistently_unreachable(constant)
|
||||
|
||||
_eventual_unrechable = Instances.set_unreachable(eventual)
|
||||
|
||||
%{constant_unreachable: constant_unreachable, constant: constant}
|
||||
end
|
||||
|
||||
test "GET /api/v1/pleroma/federation_status", %{
|
||||
conn: conn,
|
||||
constant_unreachable: constant_unreachable,
|
||||
constant: constant
|
||||
} do
|
||||
constant_host = URI.parse(constant).host
|
||||
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> get("/api/v1/pleroma/federation_status")
|
||||
|> json_response_and_validate_schema(200) == %{
|
||||
"unreachable" => %{constant_host => to_string(constant_unreachable)}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -24,7 +24,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
assert json_response_and_validate_schema(ret_conn, 415)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put("/api/v1/pleroma/mascot", %{"file" => file})
|
||||
|
||||
assert %{"id" => _, "type" => image} = json_response_and_validate_schema(conn, 200)
|
||||
assert %{"id" => _, "type" => _image} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "mascot retrieving" do
|
||||
|
|
@ -48,7 +48,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
|
||||
# When a user sets their mascot, we should get that back
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.PleromaAPI.UserImportControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
|
|||
|
|
@ -19,13 +19,15 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
|||
recipient = insert(:user)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
{:ok, activity} = CommonAPI.post_chat_message(user, recipient, "kippis :firefox:")
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post_chat_message(user, recipient, "kippis :firefox:", idempotency_key: "123")
|
||||
|
||||
chat = Chat.get(user.id, recipient.ap_id)
|
||||
|
||||
|
|
@ -42,6 +44,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
|
|||
assert chat_message[:created_at]
|
||||
assert chat_message[:unread] == false
|
||||
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
||||
assert chat_message[:idempotency_key] == "123"
|
||||
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
import Mock
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
|
||||
|
|
@ -53,4 +54,24 @@ defmodule Pleroma.Web.Plugs.FrontendStaticPlugTest do
|
|||
index = get(conn, "/pleroma/admin/")
|
||||
assert html_response(index, 200) == "from frontend plug"
|
||||
end
|
||||
|
||||
test "exclude invalid path", %{conn: conn} do
|
||||
name = "pleroma-fe"
|
||||
ref = "dist"
|
||||
clear_config([:media_proxy, :enabled], true)
|
||||
clear_config([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
|
||||
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||
|
||||
File.mkdir_p!("#{path}/proxy/rr/ss")
|
||||
File.write!("#{path}/proxy/rr/ss/Ek7w8WPVcAApOvN.jpg:large", "FB image")
|
||||
|
||||
url =
|
||||
Pleroma.Web.MediaProxy.encode_url("https://pbs.twimg.com/media/Ek7w8WPVcAApOvN.jpg:large")
|
||||
|
||||
with_mock Pleroma.ReverseProxy,
|
||||
call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do
|
||||
assert %Plug.Conn{status: :success} = get(conn, url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Plug.Conn
|
||||
|
||||
describe "http security enabled" do
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do
|
|||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image_tmp.jpg"),
|
||||
filename: "nice_tf.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
recipient = insert(:user)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do: clear_config([:static_fe, :enabled], true)
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
setup %{conn: conn} do
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
|
|
@ -74,8 +72,27 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
refute html =~ ">test29<"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn,
|
||||
user: user
|
||||
} do
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
conn = get(conn, "/users/#{user.nickname}")
|
||||
|
||||
assert html_response(conn, 200) =~ user.nickname
|
||||
end
|
||||
|
||||
test "returns 404 for local user with `restrict_unauthenticated/profiles/local` setting", %{
|
||||
conn: conn
|
||||
} do
|
||||
clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
local_user = insert(:user, local: true)
|
||||
|
||||
conn
|
||||
|> get("/users/#{local_user.nickname}")
|
||||
|> html_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -187,10 +204,28 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
assert html_response(conn, 302) =~ "redirected"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
||||
test "does not require authentication on non-federating instances", %{
|
||||
conn: conn,
|
||||
user: user
|
||||
} do
|
||||
clear_config([:instance, :federating], false)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
|
||||
conn = get(conn, "/notice/#{activity.id}")
|
||||
|
||||
assert html_response(conn, 200) =~ "testing a thing!"
|
||||
end
|
||||
|
||||
test "returns 404 for local public activity with `restrict_unauthenticated/activities/local` setting",
|
||||
%{conn: conn, user: user} do
|
||||
clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
||||
|
||||
conn
|
||||
|> get("/notice/#{activity.id}")
|
||||
|> html_response(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,6 +29,14 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
assert {:ok, "public:local:media"} = Streamer.get_topic("public:local:media", nil, nil)
|
||||
end
|
||||
|
||||
test "allows instance streams" do
|
||||
assert {:ok, "public:remote:lain.com"} =
|
||||
Streamer.get_topic("public:remote", nil, nil, %{"instance" => "lain.com"})
|
||||
|
||||
assert {:ok, "public:remote:media:lain.com"} =
|
||||
Streamer.get_topic("public:remote:media", nil, nil, %{"instance" => "lain.com"})
|
||||
end
|
||||
|
||||
test "allows hashtag streams" do
|
||||
assert {:ok, "hashtag:cofe"} = Streamer.get_topic("hashtag", nil, nil, %{"tag" => "cofe"})
|
||||
end
|
||||
|
|
@ -255,7 +263,9 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
} do
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno")
|
||||
{:ok, create_activity} =
|
||||
CommonAPI.post_chat_message(other_user, user, "hey cirno", idempotency_key: "123")
|
||||
|
||||
object = Object.normalize(create_activity, false)
|
||||
chat = Chat.get(user.id, other_user.ap_id)
|
||||
cm_ref = MessageReference.for_chat_and_object(chat, object)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.MFA
|
||||
alias Pleroma.MFA.TOTP
|
||||
alias Pleroma.User
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue