[#1149] Added Oban job for "activity_expiration". Merged remote-tracking branch 'remotes/upstream/develop' into 1149-oban-job-queue
# Conflicts: # config/config.exs
This commit is contained in:
commit
e890ea7e82
76 changed files with 2689 additions and 551 deletions
27
test/activity_expiration_test.exs
Normal file
27
test/activity_expiration_test.exs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ActivityExpirationTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.ActivityExpiration
|
||||
import Pleroma.Factory
|
||||
|
||||
test "finds activities due to be deleted only" do
|
||||
activity = insert(:note_activity)
|
||||
expiration_due = insert(:expiration_in_the_past, %{activity_id: activity.id})
|
||||
activity2 = insert(:note_activity)
|
||||
insert(:expiration_in_the_future, %{activity_id: activity2.id})
|
||||
|
||||
expirations = ActivityExpiration.due_expirations()
|
||||
|
||||
assert length(expirations) == 1
|
||||
assert hd(expirations) == expiration_due
|
||||
end
|
||||
|
||||
test "denies expirations that don't live long enough" do
|
||||
activity = insert(:note_activity)
|
||||
now = NaiveDateTime.utc_now()
|
||||
assert {:error, _} = ActivityExpiration.create(activity, now)
|
||||
end
|
||||
end
|
||||
17
test/activity_expiration_worker_test.exs
Normal file
17
test/activity_expiration_worker_test.exs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ActivityExpirationWorkerTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
import Pleroma.Factory
|
||||
|
||||
test "deletes an activity" do
|
||||
activity = insert(:note_activity)
|
||||
expiration = insert(:expiration_in_the_past, %{activity_id: activity.id})
|
||||
Pleroma.ActivityExpirationWorker.perform(:execute, expiration.id)
|
||||
|
||||
refute Repo.get(Activity, activity.id)
|
||||
end
|
||||
end
|
||||
|
|
@ -166,4 +166,13 @@ defmodule Pleroma.ActivityTest do
|
|||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
end
|
||||
end
|
||||
|
||||
test "add an activity with an expiration" do
|
||||
activity = insert(:note_activity)
|
||||
insert(:expiration_in_the_future, %{activity_id: activity.id})
|
||||
|
||||
Pleroma.ActivityExpiration
|
||||
|> where([a], a.activity_id == ^activity.id)
|
||||
|> Repo.one!()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
56
test/fixtures/osada-follow-activity.json
vendored
Normal file
56
test/fixtures/osada-follow-activity.json
vendored
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"@context":[
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
"https://apfed.club/apschema/v1.4"
|
||||
],
|
||||
"id":"https://apfed.club/follow/9",
|
||||
"type":"Follow",
|
||||
"actor":{
|
||||
"type":"Person",
|
||||
"id":"https://apfed.club/channel/indio",
|
||||
"preferredUsername":"indio",
|
||||
"name":"Indio",
|
||||
"updated":"2019-08-20T23:52:34Z",
|
||||
"icon":{
|
||||
"type":"Image",
|
||||
"mediaType":"image/jpeg",
|
||||
"updated":"2019-08-20T23:53:37Z",
|
||||
"url":"https://apfed.club/photo/profile/l/2",
|
||||
"height":300,
|
||||
"width":300
|
||||
},
|
||||
"url":"https://apfed.club/channel/indio",
|
||||
"inbox":"https://apfed.club/inbox/indio",
|
||||
"outbox":"https://apfed.club/outbox/indio",
|
||||
"followers":"https://apfed.club/followers/indio",
|
||||
"following":"https://apfed.club/following/indio",
|
||||
"endpoints":{
|
||||
"sharedInbox":"https://apfed.club/inbox"
|
||||
},
|
||||
"publicKey":{
|
||||
"id":"https://apfed.club/channel/indio",
|
||||
"owner":"https://apfed.club/channel/indio",
|
||||
"publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA77TIR1VuSYFnmDRFGHHb\n4vaGdx9ranzRX4bfOKAqa++Ch5L4EqJpPy08RuM+NrYCYiYl4QQFDSSDXAEgb5g9\nC1TgWTfI7q/E0UBX2Vr0mU6X4i1ztv0tuQvegRjcSJ7l1AvoBs8Ip4MEJ3OPEQhB\ngJqAACB3Gnps4zi2I0yavkxUfGVKr6zKT3BxWh5hTpKC7Do+ChIrVZC2EwxND9K6
|
||||
\nsAnQHThcb5EQuvuzUQZKeS7IEOsd0JpZDmJjbfMGrAWE81pLIfEeeA2joCJiBBTO\nglDsW+juvZ+lWqJpMr2hMWpvfrFjJeUawNJCIzsLdVIZR+aKj5yy6yqoS8hkN9Ha\n1MljZpsXl+EmwcwAIqim1YeLwERCEAQ/JWbSt8pQTQbzZ6ibwQ4mchCxacrRbIVR
|
||||
\nnL59fWMBassJcbY0VwrTugm2SBsYbDjESd55UZV03Rwr8qseGTyi+hH8O7w2SIaY\nzjN6AdZiPmsh00YflzlCk8MSLOHMol1vqIUzXxU8CdXn9+KsuQdZGrTz0YKN/db4\naVwUGJatz2Tsvf7R1tJBjJfeQWOWbbn3pycLVH86LjZ83qngp9ZVnAveUnUqz0yS
|
||||
\nhe+buZ6UMsfGzbIYon2bKNlz6gYTH0YPcr+cLe+29drtt0GZiXha1agbpo4RB8zE
|
||||
\naNL2fucF5YT0yNpbd/5WoV0CAwEAAQ==\n-----END PUBLIC KEY-----\n"
|
||||
}
|
||||
},
|
||||
"object":"https://pleroma.site/users/kaniini",
|
||||
"to":[
|
||||
"https://pleroma.site/users/kaniini"
|
||||
],
|
||||
"signature":{
|
||||
"@context":[
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1"
|
||||
],
|
||||
"type":"RsaSignature2017",
|
||||
"nonce":"52c035e0a9e81dce8b486159204e97c22637e91f75cdfad5378de91de68e9117",
|
||||
"creator":"https://apfed.club/channel/indio/public_key_pem",
|
||||
"created":"2019-08-22T03:38:02Z",
|
||||
"signatureValue":"oVliRCIqNIh6yUp851dYrF0y21aHp3Rz6VkIpW1pFMWfXuzExyWSfcELpyLseeRmsw5bUu9zJkH44B4G2LiJQKA9UoEQDjrDMZBmbeUpiQqq3DVUzkrBOI8bHZ7xyJ/CjSZcNHHh0MHhSKxswyxWMGi4zIqzkAZG3vRRgoPVHdjPm00sR3B8jBLw1cjoffv+KKeM/zEUpe13gqX9qHAWHHqZepxgSWmq+EKOkRvHUPBXiEJZfXzc5uW+vZ09F3WBYmaRoy8Y0e1P29fnRLqSy7EEINdrHaGclRqoUZyiawpkgy3lWWlynesV/HiLBR7EXT79eKstxf4wfTDaPKBCfTCsOWuMWHr7Genu37ew2/t7eiBGqCwwW12ylhml/OLHgNK3LOhmRABhtfpaFZSxfDVnlXfaLpY1xekVOj2oC0FpBtnoxVKLpIcyLw6dkfSil5ANd+hl59W/bpPA8KT90ii1fSNCo3+FcwQVx0YsPznJNA60XfFuVsme7zNcOst6393e1WriZxBanFpfB63zVQc9u1fjyfktx/yiUNxIlre+sz9OCc0AACn94iRhBYh4bbzdleUOTnM7lnD4Dj2FP+xeDIP8CA8wXUeq5+9kopSp2kAmlUEyFUdg4no7naIeu1SZnopfUg56PsVCp9JHiUK1SYAyWbdC+FbUECu5CvI="
|
||||
}
|
||||
}
|
||||
1
test/fixtures/tesla_mock/osada-user-indio.json
vendored
Normal file
1
test/fixtures/tesla_mock/osada-user-indio.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"Person","id":"https://apfed.club/channel/indio","preferredUsername":"indio","name":"Indio","updated":"2019-08-20T23:52:34Z","icon":{"type":"Image","mediaType":"image/jpeg","updated":"2019-08-20T23:53:37Z","url":"https://apfed.club/photo/profile/l/2","height":300,"width":300},"url":"https://apfed.club/channel/indio","inbox":"https://apfed.club/inbox/indio","outbox":"https://apfed.club/outbox/indio","followers":"https://apfed.club/followers/indio","following":"https://apfed.club/following/indio","endpoints":{"sharedInbox":"https://apfed.club/inbox"},"publicKey":{"id":"https://apfed.club/channel/indio","owner":"https://apfed.club/channel/indio","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA77TIR1VuSYFnmDRFGHHb\n4vaGdx9ranzRX4bfOKAqa++Ch5L4EqJpPy08RuM+NrYCYiYl4QQFDSSDXAEgb5g9\nC1TgWTfI7q/E0UBX2Vr0mU6X4i1ztv0tuQvegRjcSJ7l1AvoBs8Ip4MEJ3OPEQhB\ngJqAACB3Gnps4zi2I0yavkxUfGVKr6zKT3BxWh5hTpKC7Do+ChIrVZC2EwxND9K6\nsAnQHThcb5EQuvuzUQZKeS7IEOsd0JpZDmJjbfMGrAWE81pLIfEeeA2joCJiBBTO\nglDsW+juvZ+lWqJpMr2hMWpvfrFjJeUawNJCIzsLdVIZR+aKj5yy6yqoS8hkN9Ha\n1MljZpsXl+EmwcwAIqim1YeLwERCEAQ/JWbSt8pQTQbzZ6ibwQ4mchCxacrRbIVR\nnL59fWMBassJcbY0VwrTugm2SBsYbDjESd55UZV03Rwr8qseGTyi+hH8O7w2SIaY\nzjN6AdZiPmsh00YflzlCk8MSLOHMol1vqIUzXxU8CdXn9+KsuQdZGrTz0YKN/db4\naVwUGJatz2Tsvf7R1tJBjJfeQWOWbbn3pycLVH86LjZ83qngp9ZVnAveUnUqz0yS\nhe+buZ6UMsfGzbIYon2bKNlz6gYTH0YPcr+cLe+29drtt0GZiXha1agbpo4RB8zE\naNL2fucF5YT0yNpbd/5WoV0CAwEAAQ==\n-----END PUBLIC KEY-----\n"},"signature":{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],"type":"RsaSignature2017","nonce":"c672a408d2e88b322b36a61bf0c25f586be9245d30293c55b8d653dcc867aaf7","creator":"https://apfed.club/channel/indio/public_key_pem","created":"2019-08-26T07:24:03Z","signatureValue":"MyAv5gnedu6L/DYFaE1TUYvp4LjI9ZUU0axwGYOhgD7qsjivMgwbOrjX/iH32xlcfF8nWOMh/ogu3+Qwr5sqLHkS2AimWmw1+Ubf2KccE58b8vI8zWfyu8QJnMuE92jtBPv8UTQUHw8ZebbExk3L99oXaeyVihKiMBmd63NpVTpGXZTg6m+H+KfWchVajPoyNKZtKMd3nH99x5j54Cqkz0BN5CSTwCSG0wP95G0VtZHtmhX+tsAPM3oAj0d+gtCZSCd8Nu8fvFAwCyTg1oKSfRqKb27EKHlskqK9X57x0jURH77CTAIQSejgGcKJ5GGLtvofubJkafadjagqrtqz6Mz6BZ642ssJ2KGkRAn79Q4F08goI6cfU5lLk2Tooe5A55XERnmE3SkYGyTvLpacZplxJdU0sa+deX9D7+alSGFJZSziaxpCxzrO6lEApe4b9kHXAzn9VaZt9trijkHq/kkq0i3NRcP7n8JG9q+Vv8jY9ddY6HcH89RNCBIA6MKLtAqc+vSc5G24qeZlw2MzlQWBp0KGuVG8DQR00AL6cXLBzF1WY8JZeEg6zqm+DMznbuNzgiS34BP+AehBSHlQ4MZebwDnK3ZPPqGSwioIWMxIFfZDaVDX9Pp1pXAARQMw0c/y4sDcf9FMzsr8jteEa7ZQcoqq5kXQTSCP56TEHnI="}}
|
||||
|
|
@ -15,6 +15,13 @@ defmodule Pleroma.ListTest do
|
|||
assert title == "title"
|
||||
end
|
||||
|
||||
test "validates title" do
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, changeset} = Pleroma.List.create("", user)
|
||||
assert changeset.errors == [title: {"can't be blank", [validation: :required]}]
|
||||
end
|
||||
|
||||
test "getting a list not belonging to the user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
301
test/moderation_log_test.exs
Normal file
301
test/moderation_log_test.exs
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ModerationLogTest do
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.ModerationLog
|
||||
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "user moderation" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
moderator = insert(:user, info: %{is_moderator: true})
|
||||
subject1 = insert(:user)
|
||||
subject2 = insert(:user)
|
||||
|
||||
[admin: admin, moderator: moderator, subject1: subject1, subject2: subject2]
|
||||
end
|
||||
|
||||
test "logging user deletion by moderator", %{moderator: moderator, subject1: subject1} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
subject: subject1,
|
||||
action: "delete"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} deleted user @#{subject1.nickname}"
|
||||
end
|
||||
|
||||
test "logging user creation by moderator", %{
|
||||
moderator: moderator,
|
||||
subject1: subject1,
|
||||
subject2: subject2
|
||||
} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
subjects: [subject1, subject2],
|
||||
action: "create"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} created users: @#{subject1.nickname}, @#{subject2.nickname}"
|
||||
end
|
||||
|
||||
test "logging user follow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: admin,
|
||||
followed: subject1,
|
||||
follower: subject2,
|
||||
action: "follow"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{admin.nickname} made @#{subject2.nickname} follow @#{subject1.nickname}"
|
||||
end
|
||||
|
||||
test "logging user unfollow by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: admin,
|
||||
followed: subject1,
|
||||
follower: subject2,
|
||||
action: "unfollow"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{admin.nickname} made @#{subject2.nickname} unfollow @#{subject1.nickname}"
|
||||
end
|
||||
|
||||
test "logging user tagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: admin,
|
||||
nicknames: [subject1.nickname, subject2.nickname],
|
||||
tags: ["foo", "bar"],
|
||||
action: "tag"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
users =
|
||||
[subject1.nickname, subject2.nickname]
|
||||
|> Enum.map(&"@#{&1}")
|
||||
|> Enum.join(", ")
|
||||
|
||||
tags = ["foo", "bar"] |> Enum.join(", ")
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{admin.nickname} added tags: #{tags} to users: #{users}"
|
||||
end
|
||||
|
||||
test "logging user untagged by admin", %{admin: admin, subject1: subject1, subject2: subject2} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: admin,
|
||||
nicknames: [subject1.nickname, subject2.nickname],
|
||||
tags: ["foo", "bar"],
|
||||
action: "untag"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
users =
|
||||
[subject1.nickname, subject2.nickname]
|
||||
|> Enum.map(&"@#{&1}")
|
||||
|> Enum.join(", ")
|
||||
|
||||
tags = ["foo", "bar"] |> Enum.join(", ")
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
|
||||
end
|
||||
|
||||
test "logging user grant by moderator", %{moderator: moderator, subject1: subject1} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
subject: subject1,
|
||||
action: "grant",
|
||||
permission: "moderator"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} made @#{subject1.nickname} moderator"
|
||||
end
|
||||
|
||||
test "logging user revoke by moderator", %{moderator: moderator, subject1: subject1} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
subject: subject1,
|
||||
action: "revoke",
|
||||
permission: "moderator"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} revoked moderator role from @#{subject1.nickname}"
|
||||
end
|
||||
|
||||
test "logging relay follow", %{moderator: moderator} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "relay_follow",
|
||||
target: "https://example.org/relay"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} followed relay: https://example.org/relay"
|
||||
end
|
||||
|
||||
test "logging relay unfollow", %{moderator: moderator} do
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "relay_unfollow",
|
||||
target: "https://example.org/relay"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} unfollowed relay: https://example.org/relay"
|
||||
end
|
||||
|
||||
test "logging report update", %{moderator: moderator} do
|
||||
report = %Activity{
|
||||
id: "9m9I1F4p8ftrTP6QTI",
|
||||
data: %{
|
||||
"type" => "Flag",
|
||||
"state" => "resolved"
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "report_update",
|
||||
subject: report
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} updated report ##{report.id} with 'resolved' state"
|
||||
end
|
||||
|
||||
test "logging report response", %{moderator: moderator} do
|
||||
report = %Activity{
|
||||
id: "9m9I1F4p8ftrTP6QTI",
|
||||
data: %{
|
||||
"type" => "Note"
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "report_response",
|
||||
subject: report,
|
||||
text: "look at this"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} responded with 'look at this' to report ##{report.id}"
|
||||
end
|
||||
|
||||
test "logging status sensitivity update", %{moderator: moderator} do
|
||||
note = insert(:note_activity)
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "status_update",
|
||||
subject: note,
|
||||
sensitive: "true",
|
||||
visibility: nil
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true'"
|
||||
end
|
||||
|
||||
test "logging status visibility update", %{moderator: moderator} do
|
||||
note = insert(:note_activity)
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "status_update",
|
||||
subject: note,
|
||||
sensitive: nil,
|
||||
visibility: "private"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} updated status ##{note.id}, set visibility: 'private'"
|
||||
end
|
||||
|
||||
test "logging status sensitivity & visibility update", %{moderator: moderator} do
|
||||
note = insert(:note_activity)
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "status_update",
|
||||
subject: note,
|
||||
sensitive: "true",
|
||||
visibility: "private"
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} updated status ##{note.id}, set sensitive: 'true', visibility: 'private'"
|
||||
end
|
||||
|
||||
test "logging status deletion", %{moderator: moderator} do
|
||||
note = insert(:note_activity)
|
||||
|
||||
{:ok, _} =
|
||||
ModerationLog.insert_log(%{
|
||||
actor: moderator,
|
||||
action: "status_delete",
|
||||
subject_id: note.id
|
||||
})
|
||||
|
||||
log = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log) ==
|
||||
"@#{moderator.nickname} deleted status ##{note.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.SignatureTest do
|
|||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
import Mock
|
||||
|
||||
alias Pleroma.Signature
|
||||
|
||||
|
|
@ -114,4 +115,17 @@ defmodule Pleroma.SignatureTest do
|
|||
"https://example.com/users/1234"
|
||||
end
|
||||
end
|
||||
|
||||
describe "signed_date" do
|
||||
test "it returns formatted current date" do
|
||||
with_mock(NaiveDateTime, utc_now: fn -> ~N[2019-08-23 18:11:24.822233] end) do
|
||||
assert Signature.signed_date() == "Fri, 23 Aug 2019 18:11:24 GMT"
|
||||
end
|
||||
end
|
||||
|
||||
test "it returns formatted date" do
|
||||
assert Signature.signed_date(~N[2019-08-23 08:11:24.822233]) ==
|
||||
"Fri, 23 Aug 2019 08:11:24 GMT"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Factory do
|
||||
|
|
@ -143,6 +143,25 @@ defmodule Pleroma.Factory do
|
|||
|> Map.merge(attrs)
|
||||
end
|
||||
|
||||
defp expiration_offset_by_minutes(attrs, minutes) do
|
||||
scheduled_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(:timer.minutes(minutes), :millisecond)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
%Pleroma.ActivityExpiration{}
|
||||
|> Map.merge(attrs)
|
||||
|> Map.put(:scheduled_at, scheduled_at)
|
||||
end
|
||||
|
||||
def expiration_in_the_past_factory(attrs \\ %{}) do
|
||||
expiration_offset_by_minutes(attrs, -60)
|
||||
end
|
||||
|
||||
def expiration_in_the_future_factory(attrs \\ %{}) do
|
||||
expiration_offset_by_minutes(attrs, 61)
|
||||
end
|
||||
|
||||
def article_activity_factory do
|
||||
article = insert(:article)
|
||||
|
||||
|
|
@ -188,13 +207,15 @@ defmodule Pleroma.Factory do
|
|||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"actor" => user.ap_id,
|
||||
"type" => "Like",
|
||||
"object" => object.data["id"],
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601()
|
||||
}
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"actor" => user.ap_id,
|
||||
"type" => "Like",
|
||||
"object" => object.data["id"],
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601()
|
||||
}
|
||||
|> Map.merge(attrs[:data_attrs] || %{})
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data
|
||||
|
|
|
|||
|
|
@ -17,9 +17,12 @@ defmodule HttpRequestMock do
|
|||
with {:ok, res} <- apply(__MODULE__, method, [url, query, body, headers]) do
|
||||
res
|
||||
else
|
||||
{_, _r} = error ->
|
||||
# Logger.warn(r)
|
||||
error
|
||||
error ->
|
||||
with {:error, message} <- error do
|
||||
Logger.warn(message)
|
||||
end
|
||||
|
||||
{_, _r} = error
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -772,6 +775,11 @@ defmodule HttpRequestMock do
|
|||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/lambadalambda.json")}}
|
||||
end
|
||||
|
||||
def get("https://apfed.club/channel/indio", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/osada-user-indio.json")}}
|
||||
end
|
||||
|
||||
def get("https://social.heldscal.la/user/23211", _, _, Accept: "application/activity+json") do
|
||||
{:ok, Tesla.Mock.json(%{"id" => "https://social.heldscal.la/user/23211"}, status: 200)}
|
||||
end
|
||||
|
|
@ -968,9 +976,25 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://example.com/rel_me/anchor", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}}
|
||||
end
|
||||
|
||||
def get("http://example.com/rel_me/anchor_nofollow", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}}
|
||||
end
|
||||
|
||||
def get("http://example.com/rel_me/link", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}}
|
||||
end
|
||||
|
||||
def get("http://example.com/rel_me/null", _, _, _) do
|
||||
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}}
|
||||
end
|
||||
|
||||
def get(url, query, body, headers) do
|
||||
{:error,
|
||||
"Not implemented the mock response for get #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
"Mock response not implemented for GET #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
inspect(headers)
|
||||
}"}
|
||||
end
|
||||
|
|
@ -1032,7 +1056,10 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def post(url, _query, _body, _headers) do
|
||||
{:error, "Not implemented the mock response for post #{inspect(url)}"}
|
||||
def post(url, query, body, headers) do
|
||||
{:error,
|
||||
"Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
|
||||
inspect(headers)
|
||||
}"}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||
%User{ap_id: follower_id} = local_user = Relay.get_actor()
|
||||
target_user = User.get_cached_by_ap_id(target_instance)
|
||||
follow_activity = Utils.fetch_latest_follow(local_user, target_user)
|
||||
|
||||
User.follow(local_user, target_user)
|
||||
assert "#{target_instance}/followers" in refresh_record(local_user).following
|
||||
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
|
||||
|
||||
cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
|
||||
|
|
@ -67,6 +68,7 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||
assert undo_activity.data["type"] == "Undo"
|
||||
assert undo_activity.data["actor"] == local_user.ap_id
|
||||
assert undo_activity.data["object"] == cancelled_activity.data
|
||||
refute "#{target_instance}/followers" in refresh_record(local_user).following
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1269,18 +1269,18 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
|
||||
test "Adds rel=me on linkbacked urls" do
|
||||
user = insert(:user, ap_id: "http://social.example.org/users/lain")
|
||||
user = insert(:user, ap_id: "https://social.example.org/users/lain")
|
||||
|
||||
bio = "http://example.org/rel_me/null"
|
||||
bio = "http://example.com/rel_me/null"
|
||||
expected_text = "<a href=\"#{bio}\">#{bio}</a>"
|
||||
assert expected_text == User.parse_bio(bio, user)
|
||||
|
||||
bio = "http://example.org/rel_me/link"
|
||||
expected_text = "<a href=\"#{bio}\">#{bio}</a>"
|
||||
bio = "http://example.com/rel_me/link"
|
||||
expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
|
||||
assert expected_text == User.parse_bio(bio, user)
|
||||
|
||||
bio = "http://example.org/rel_me/anchor"
|
||||
expected_text = "<a href=\"#{bio}\">#{bio}</a>"
|
||||
bio = "http://example.com/rel_me/anchor"
|
||||
expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
|
||||
assert expected_text == User.parse_bio(bio, user)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ObjectView
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
alias Pleroma.Web.ActivityPub.UserView
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -601,6 +602,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "/relay/followers" do
|
||||
test "it returns relay followers", %{conn: conn} do
|
||||
relay_actor = Relay.get_actor()
|
||||
user = insert(:user)
|
||||
User.follow(user, relay_actor)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:relay, true)
|
||||
|> get("/relay/followers")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == [user.ap_id]
|
||||
end
|
||||
end
|
||||
|
||||
describe "/relay/following" do
|
||||
test "it returns relay following", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> assign(:relay, true)
|
||||
|> get("/relay/following")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname/followers" do
|
||||
test "it returns the followers in a collection", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
|
||||
describe "streaming out participations" do
|
||||
test "it streams them out" do
|
||||
user = insert(:user)
|
||||
|
|
@ -676,6 +678,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
describe "like an object" do
|
||||
test_with_mock "sends an activity to federation", Pleroma.Web.Federator, [:passthrough], [] do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
note_activity = insert(:note_activity)
|
||||
assert object_activity = Object.normalize(note_activity)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object_activity)
|
||||
assert called(Pleroma.Web.Federator.publish(like_activity))
|
||||
end
|
||||
|
||||
test "returns exist activity if object already liked" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object_activity = Object.normalize(note_activity)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object_activity)
|
||||
|
||||
{:ok, like_activity_exist, _object} = ActivityPub.like(user, object_activity)
|
||||
assert like_activity == like_activity_exist
|
||||
end
|
||||
|
||||
test "adds a like activity to the db" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object = Object.normalize(note_activity)
|
||||
|
|
@ -706,6 +731,25 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
describe "unliking" do
|
||||
test_with_mock "sends an activity to federation", Pleroma.Web.Federator, [:passthrough], [] do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
refute called(Pleroma.Web.Federator.publish())
|
||||
|
||||
{:ok, _like_activity, object} = ActivityPub.like(user, object)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(unlike_activity))
|
||||
end
|
||||
|
||||
test "unliking a previously liked object" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
test "gets an actor for the relay" do
|
||||
user = Relay.get_actor()
|
||||
|
|
@ -43,16 +44,21 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
user = insert(:user)
|
||||
service_actor = Relay.get_actor()
|
||||
ActivityPub.follow(service_actor, user)
|
||||
Pleroma.User.follow(service_actor, user)
|
||||
assert "#{user.ap_id}/followers" in refresh_record(service_actor).following
|
||||
assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
|
||||
assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
assert user.ap_id in activity.recipients
|
||||
assert activity.data["type"] == "Undo"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["to"] == [user.ap_id]
|
||||
refute "#{user.ap_id}/followers" in refresh_record(service_actor).following
|
||||
end
|
||||
end
|
||||
|
||||
describe "publish/1" do
|
||||
clear_config([:instance, :federating])
|
||||
|
||||
test "returns error when activity not `Create` type" do
|
||||
activity = insert(:like_activity)
|
||||
assert Relay.publish(activity) == {:error, "Not implemented"}
|
||||
|
|
@ -63,13 +69,44 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
assert Relay.publish(activity) == {:error, false}
|
||||
end
|
||||
|
||||
test "returns announce activity" do
|
||||
test "returns error when object is unknown" do
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
data: %{
|
||||
"type" => "Create",
|
||||
"object" => "http://mastodon.example.org/eee/99541947525187367"
|
||||
}
|
||||
)
|
||||
|
||||
assert Relay.publish(activity) == {:error, nil}
|
||||
end
|
||||
|
||||
test_with_mock "returns announce activity and publish to federate",
|
||||
Pleroma.Web.Federator,
|
||||
[:passthrough],
|
||||
[] do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
service_actor = Relay.get_actor()
|
||||
note = insert(:note_activity)
|
||||
assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["object"] == obj.data["id"]
|
||||
assert called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
|
||||
test_with_mock "returns announce activity and not publish to federate",
|
||||
Pleroma.Web.Federator,
|
||||
[:passthrough],
|
||||
[] do
|
||||
Pleroma.Config.put([:instance, :federating], false)
|
||||
service_actor = Relay.get_actor()
|
||||
note = insert(:note_activity)
|
||||
assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == service_actor.ap_id
|
||||
assert activity.data["object"] == obj.data["id"]
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
end
|
||||
|
||||
describe "handle_incoming" do
|
||||
test "it works for osada follow request" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/osada-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "https://apfed.club/channel/indio"
|
||||
assert data["type"] == "Follow"
|
||||
assert data["id"] == "https://apfed.club/follow/9"
|
||||
|
||||
activity = Repo.get(Activity, activity.id)
|
||||
assert activity.data["state"] == "accept"
|
||||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it works for incoming follow requests" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -564,6 +564,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
||||
update_data = put_in(update_data, ["object", "attachment"], [])
|
||||
|
||||
{:ok, _} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.Info.fields(user.info) == []
|
||||
end
|
||||
|
||||
test "it works for incoming update activities which lock the account" do
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
describe "fetch the latest Follow" do
|
||||
test "fetches the latest Follow activity" do
|
||||
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
|
||||
|
|
@ -87,6 +89,32 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "make_unlike_data/3" do
|
||||
test "returns data for unlike activity" do
|
||||
user = insert(:user)
|
||||
like_activity = insert(:like_activity, data_attrs: %{"context" => "test context"})
|
||||
|
||||
assert Utils.make_unlike_data(user, like_activity, nil) == %{
|
||||
"type" => "Undo",
|
||||
"actor" => user.ap_id,
|
||||
"object" => like_activity.data,
|
||||
"to" => [user.follower_address, like_activity.data["actor"]],
|
||||
"cc" => [Pleroma.Constants.as_public()],
|
||||
"context" => like_activity.data["context"]
|
||||
}
|
||||
|
||||
assert Utils.make_unlike_data(user, like_activity, "9mJEZK0tky1w2xD2vY") == %{
|
||||
"type" => "Undo",
|
||||
"actor" => user.ap_id,
|
||||
"object" => like_activity.data,
|
||||
"to" => [user.follower_address, like_activity.data["actor"]],
|
||||
"cc" => [Pleroma.Constants.as_public()],
|
||||
"context" => like_activity.data["context"],
|
||||
"id" => "9mJEZK0tky1w2xD2vY"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_like_data" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -299,4 +327,78 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
assert Repo.get(Activity, follow_activity_two.id).data["state"] == "reject"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update_element_in_object/3" do
|
||||
test "updates likes" do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert {:ok, updated_object} =
|
||||
Utils.update_element_in_object(
|
||||
"like",
|
||||
[user.ap_id],
|
||||
object
|
||||
)
|
||||
|
||||
assert updated_object.data["likes"] == [user.ap_id]
|
||||
assert updated_object.data["like_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_like_to_object/2" do
|
||||
test "add actor to likes" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
object = insert(:note)
|
||||
|
||||
assert {:ok, updated_object} =
|
||||
Utils.add_like_to_object(
|
||||
%Activity{data: %{"actor" => user.ap_id}},
|
||||
object
|
||||
)
|
||||
|
||||
assert updated_object.data["likes"] == [user.ap_id]
|
||||
assert updated_object.data["like_count"] == 1
|
||||
|
||||
assert {:ok, updated_object2} =
|
||||
Utils.add_like_to_object(
|
||||
%Activity{data: %{"actor" => user2.ap_id}},
|
||||
updated_object
|
||||
)
|
||||
|
||||
assert updated_object2.data["likes"] == [user2.ap_id, user.ap_id]
|
||||
assert updated_object2.data["like_count"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "remove_like_from_object/2" do
|
||||
test "removes ap_id from likes" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
object = insert(:note, data: %{"likes" => [user.ap_id, user2.ap_id], "like_count" => 2})
|
||||
|
||||
assert {:ok, updated_object} =
|
||||
Utils.remove_like_from_object(
|
||||
%Activity{data: %{"actor" => user.ap_id}},
|
||||
object
|
||||
)
|
||||
|
||||
assert updated_object.data["likes"] == [user2.ap_id]
|
||||
assert updated_object.data["like_count"] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_existing_like/2" do
|
||||
test "fetches existing like" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object = Object.normalize(note_activity)
|
||||
|
||||
user = insert(:user)
|
||||
refute Utils.get_existing_like(user.ap_id, object)
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object)
|
||||
|
||||
assert ^like_activity = Utils.get_existing_like(user.ap_id, object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.ModerationLog
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -24,6 +26,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> put_req_header("accept", "application/json")
|
||||
|> delete("/api/pleroma/admin/users?nickname=#{user.nickname}")
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert log_entry.data["subject"]["nickname"] == user.nickname
|
||||
assert log_entry.data["action"] == "delete"
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted user @#{user.nickname}"
|
||||
|
||||
assert json_response(conn, 200) == user.nickname
|
||||
end
|
||||
|
||||
|
|
@ -35,12 +45,135 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users", %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@example.org",
|
||||
"password" => "test"
|
||||
"users" => [
|
||||
%{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@example.org",
|
||||
"password" => "test"
|
||||
},
|
||||
%{
|
||||
"nickname" => "lain2",
|
||||
"email" => "lain2@example.org",
|
||||
"password" => "test"
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == "lain"
|
||||
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 exisiting email" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> 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 exisiting nickname" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> 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" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> 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
|
||||
|
||||
|
|
@ -99,6 +232,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
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
|
||||
|
||||
|
|
@ -122,6 +260,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
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
|
||||
|
||||
|
|
@ -142,17 +285,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
}&tags[]=foo&tags[]=bar"
|
||||
)
|
||||
|
||||
%{conn: conn, user1: user1, user2: user2, user3: user3}
|
||||
%{conn: conn, admin: admin, user1: user1, user2: user2, user3: user3}
|
||||
end
|
||||
|
||||
test "it appends specified tags to users with specified nicknames", %{
|
||||
conn: conn,
|
||||
admin: admin,
|
||||
user1: user1,
|
||||
user2: user2
|
||||
} do
|
||||
assert json_response(conn, :no_content)
|
||||
assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
|
||||
assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
users =
|
||||
[user1.nickname, user2.nickname]
|
||||
|> Enum.map(&"@#{&1}")
|
||||
|> Enum.join(", ")
|
||||
|
||||
tags = ["foo", "bar"] |> Enum.join(", ")
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} added tags: #{tags} to users: #{users}"
|
||||
end
|
||||
|
||||
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
|
||||
|
|
@ -178,17 +334,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
}&tags[]=x&tags[]=z"
|
||||
)
|
||||
|
||||
%{conn: conn, user1: user1, user2: user2, user3: user3}
|
||||
%{conn: conn, admin: admin, user1: user1, user2: user2, user3: user3}
|
||||
end
|
||||
|
||||
test "it removes specified tags from users with specified nicknames", %{
|
||||
conn: conn,
|
||||
admin: admin,
|
||||
user1: user1,
|
||||
user2: user2
|
||||
} do
|
||||
assert json_response(conn, :no_content)
|
||||
assert User.get_cached_by_id(user1.id).tags == []
|
||||
assert User.get_cached_by_id(user2.id).tags == ["y"]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
users =
|
||||
[user1.nickname, user2.nickname]
|
||||
|> Enum.map(&"@#{&1}")
|
||||
|> Enum.join(", ")
|
||||
|
||||
tags = ["x", "z"] |> Enum.join(", ")
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} removed tags: #{tags} from users: #{users}"
|
||||
end
|
||||
|
||||
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
|
||||
|
|
@ -226,6 +395,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert json_response(conn, 200) == %{
|
||||
"is_admin" => true
|
||||
}
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} made @#{user.nickname} admin"
|
||||
end
|
||||
|
||||
test "/:right DELETE, can remove from a permission group" do
|
||||
|
|
@ -241,6 +415,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert json_response(conn, 200) == %{
|
||||
"is_admin" => false
|
||||
}
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} revoked admin role from @#{user.nickname}"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -253,10 +432,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|
||||
%{conn: conn}
|
||||
%{conn: conn, admin: admin}
|
||||
end
|
||||
|
||||
test "deactivates the user", %{conn: conn} do
|
||||
test "deactivates the user", %{conn: conn, admin: admin} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -266,9 +445,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.deactivated == true
|
||||
assert json_response(conn, :no_content)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deactivated user @#{user.nickname}"
|
||||
end
|
||||
|
||||
test "activates the user", %{conn: conn} do
|
||||
test "activates the user", %{conn: conn, admin: admin} do
|
||||
user = insert(:user, info: %{deactivated: true})
|
||||
|
||||
conn =
|
||||
|
|
@ -278,6 +462,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.deactivated == false
|
||||
assert json_response(conn, :no_content)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} activated user @#{user.nickname}"
|
||||
end
|
||||
|
||||
test "returns 403 when requested by a non-admin", %{conn: conn} do
|
||||
|
|
@ -868,6 +1057,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname)
|
||||
}
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deactivated user @#{user.nickname}"
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/users/invite_token" do
|
||||
|
|
@ -1053,25 +1247,35 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"status_ids" => [activity.id]
|
||||
})
|
||||
|
||||
%{conn: assign(conn, :user, admin), id: report_id}
|
||||
%{conn: assign(conn, :user, admin), id: report_id, admin: admin}
|
||||
end
|
||||
|
||||
test "mark report as resolved", %{conn: conn, id: id} do
|
||||
test "mark report as resolved", %{conn: conn, id: id, admin: admin} do
|
||||
response =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/reports/#{id}", %{"state" => "resolved"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["state"] == "resolved"
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} updated report ##{id} with 'resolved' state"
|
||||
end
|
||||
|
||||
test "closes report", %{conn: conn, id: id} do
|
||||
test "closes report", %{conn: conn, id: id, admin: admin} do
|
||||
response =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/reports/#{id}", %{"state" => "closed"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["state"] == "closed"
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} updated report ##{id} with 'closed' state"
|
||||
end
|
||||
|
||||
test "returns 400 when state is unknown", %{conn: conn, id: id} do
|
||||
|
|
@ -1202,14 +1406,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
#
|
||||
describe "POST /api/pleroma/admin/reports/:id/respond" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
%{conn: assign(conn, :user, admin)}
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
end
|
||||
|
||||
test "returns created dm", %{conn: conn} do
|
||||
test "returns created dm", %{conn: conn, admin: admin} do
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
||||
|
|
@ -1232,6 +1437,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert reporter.nickname in recipients
|
||||
assert response["content"] == "I will check it out"
|
||||
assert response["visibility"] == "direct"
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} responded with 'I will check it out' to report ##{
|
||||
response["id"]
|
||||
}"
|
||||
end
|
||||
|
||||
test "returns 400 when status is missing", %{conn: conn} do
|
||||
|
|
@ -1255,10 +1467,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
admin = insert(:user, info: %{is_admin: true})
|
||||
activity = insert(:note_activity)
|
||||
|
||||
%{conn: assign(conn, :user, admin), id: activity.id}
|
||||
%{conn: assign(conn, :user, admin), id: activity.id, admin: admin}
|
||||
end
|
||||
|
||||
test "toggle sensitive flag", %{conn: conn, id: id} do
|
||||
test "toggle sensitive flag", %{conn: conn, id: id, admin: admin} do
|
||||
response =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/statuses/#{id}", %{"sensitive" => "true"})
|
||||
|
|
@ -1266,6 +1478,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert response["sensitive"]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} updated status ##{id}, set sensitive: 'true'"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/statuses/#{id}", %{"sensitive" => "false"})
|
||||
|
|
@ -1274,7 +1491,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
refute response["sensitive"]
|
||||
end
|
||||
|
||||
test "change visibility flag", %{conn: conn, id: id} do
|
||||
test "change visibility flag", %{conn: conn, id: id, admin: admin} do
|
||||
response =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/statuses/#{id}", %{"visibility" => "public"})
|
||||
|
|
@ -1282,6 +1499,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert response["visibility"] == "public"
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} updated status ##{id}, set visibility: 'public'"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/statuses/#{id}", %{"visibility" => "private"})
|
||||
|
|
@ -1311,15 +1533,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
admin = insert(:user, info: %{is_admin: true})
|
||||
activity = insert(:note_activity)
|
||||
|
||||
%{conn: assign(conn, :user, admin), id: activity.id}
|
||||
%{conn: assign(conn, :user, admin), id: activity.id, admin: admin}
|
||||
end
|
||||
|
||||
test "deletes status", %{conn: conn, id: id} do
|
||||
test "deletes status", %{conn: conn, id: id, admin: admin} do
|
||||
conn
|
||||
|> delete("/api/pleroma/admin/statuses/#{id}")
|
||||
|> json_response(:ok)
|
||||
|
||||
refute Activity.get_by_id(id)
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deleted status ##{id}"
|
||||
end
|
||||
|
||||
test "returns error when status is not exist", %{conn: conn} do
|
||||
|
|
@ -2020,6 +2247,108 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert json_response(conn, 200) |> length() == 5
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/moderation_log" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
end
|
||||
|
||||
test "returns the log", %{conn: conn, admin: admin} do
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_follow",
|
||||
target: "https://example.org/relay"
|
||||
},
|
||||
inserted_at: NaiveDateTime.truncate(~N[2017-08-15 15:47:06.597036], :second)
|
||||
})
|
||||
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_unfollow",
|
||||
target: "https://example.org/relay"
|
||||
},
|
||||
inserted_at: NaiveDateTime.truncate(~N[2017-08-16 15:47:06.597036], :second)
|
||||
})
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/moderation_log")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
[first_entry, second_entry] = response
|
||||
|
||||
assert response |> length() == 2
|
||||
assert first_entry["data"]["action"] == "relay_unfollow"
|
||||
|
||||
assert first_entry["message"] ==
|
||||
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
|
||||
|
||||
assert second_entry["data"]["action"] == "relay_follow"
|
||||
|
||||
assert second_entry["message"] ==
|
||||
"@#{admin.nickname} followed relay: https://example.org/relay"
|
||||
end
|
||||
|
||||
test "returns the log with pagination", %{conn: conn, admin: admin} do
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_follow",
|
||||
target: "https://example.org/relay"
|
||||
},
|
||||
inserted_at: NaiveDateTime.truncate(~N[2017-08-15 15:47:06.597036], :second)
|
||||
})
|
||||
|
||||
Repo.insert(%ModerationLog{
|
||||
data: %{
|
||||
actor: %{
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"type" => "user"
|
||||
},
|
||||
action: "relay_unfollow",
|
||||
target: "https://example.org/relay"
|
||||
},
|
||||
inserted_at: NaiveDateTime.truncate(~N[2017-08-16 15:47:06.597036], :second)
|
||||
})
|
||||
|
||||
conn1 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=1")
|
||||
|
||||
response1 = json_response(conn1, 200)
|
||||
[first_entry] = response1
|
||||
|
||||
assert response1 |> length() == 1
|
||||
assert first_entry["data"]["action"] == "relay_unfollow"
|
||||
|
||||
assert first_entry["message"] ==
|
||||
"@#{admin.nickname} unfollowed relay: https://example.org/relay"
|
||||
|
||||
conn2 = get(conn, "/api/pleroma/admin/moderation_log?page_size=1&page=2")
|
||||
|
||||
response2 = json_response(conn2, 200)
|
||||
[second_entry] = response2
|
||||
|
||||
assert response2 |> length() == 1
|
||||
assert second_entry["data"]["action"] == "relay_follow"
|
||||
|
||||
assert second_entry["message"] ==
|
||||
"@#{admin.nickname} followed relay: https://example.org/relay"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Needed for testing
|
||||
|
|
|
|||
|
|
@ -204,6 +204,21 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert {:error, "The status is over the character limit"} =
|
||||
CommonAPI.post(user, %{"status" => "foobar"})
|
||||
end
|
||||
|
||||
test "it can handle activities that expire" do
|
||||
user = insert(:user)
|
||||
|
||||
expires_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|> NaiveDateTime.add(1_000_000, :second)
|
||||
|
||||
assert {:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "chai", "expires_in" => 1_000_000})
|
||||
|
||||
assert expiration = Pleroma.ActivityExpiration.get_by_activity_id(activity.id)
|
||||
assert expiration.scheduled_at == expires_at
|
||||
end
|
||||
end
|
||||
|
||||
describe "reactions" do
|
||||
|
|
|
|||
166
test/web/mastodon_api/controllers/list_controller_test.exs
Normal file
166
test/web/mastodon_api/controllers/list_controller_test.exs
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.ListControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Repo
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "creating a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists", %{"title" => "cuties"})
|
||||
|
||||
assert %{"title" => title} = json_response(conn, 200)
|
||||
assert title == "cuties"
|
||||
end
|
||||
|
||||
test "renders error for invalid params", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists", %{"title" => nil})
|
||||
|
||||
assert %{"error" => "can't be blank"} == json_response(conn, :unprocessable_entity)
|
||||
end
|
||||
|
||||
test "listing a user's lists", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists", %{"title" => "cuties"})
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists", %{"title" => "cofe"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/lists")
|
||||
|
||||
assert [
|
||||
%{"id" => _, "title" => "cofe"},
|
||||
%{"id" => _, "title" => "cuties"}
|
||||
] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
test "adding users to a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|
||||
assert %{} == json_response(conn, 200)
|
||||
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||
assert following == [other_user.follower_address]
|
||||
end
|
||||
|
||||
test "removing users from a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, third_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|
||||
assert %{} == json_response(conn, 200)
|
||||
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||
assert following == [third_user.follower_address]
|
||||
end
|
||||
|
||||
test "listing users in a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "retrieving a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/lists/#{list.id}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == to_string(list.id)
|
||||
end
|
||||
|
||||
test "renders 404 if list is not found", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/lists/666")
|
||||
|
||||
assert %{"error" => "List not found"} = json_response(conn, :not_found)
|
||||
end
|
||||
|
||||
test "renaming a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/v1/lists/#{list.id}", %{"title" => "newname"})
|
||||
|
||||
assert %{"title" => name} = json_response(conn, 200)
|
||||
assert name == "newname"
|
||||
end
|
||||
|
||||
test "validates title when renaming a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/v1/lists/#{list.id}", %{"title" => " "})
|
||||
|
||||
assert %{"error" => "can't be blank"} == json_response(conn, :unprocessable_entity)
|
||||
end
|
||||
|
||||
test "deleting a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/lists/#{list.id}")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
assert is_nil(Repo.get(Pleroma.List, list.id))
|
||||
end
|
||||
end
|
||||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
alias Ecto.Changeset
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.ActivityExpiration
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
|
|
@ -151,6 +152,32 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert %{"id" => third_id} = json_response(conn_three, 200)
|
||||
refute id == third_id
|
||||
|
||||
# An activity that will expire:
|
||||
# 2 hours
|
||||
expires_in = 120 * 60
|
||||
|
||||
conn_four =
|
||||
conn
|
||||
|> post("api/v1/statuses", %{
|
||||
"status" => "oolong",
|
||||
"expires_in" => expires_in
|
||||
})
|
||||
|
||||
assert fourth_response = %{"id" => fourth_id} = json_response(conn_four, 200)
|
||||
assert activity = Activity.get_by_id(fourth_id)
|
||||
assert expiration = ActivityExpiration.get_by_activity_id(fourth_id)
|
||||
|
||||
estimated_expires_at =
|
||||
NaiveDateTime.utc_now()
|
||||
|> NaiveDateTime.add(expires_in)
|
||||
|> NaiveDateTime.truncate(:second)
|
||||
|
||||
# This assert will fail if the test takes longer than a minute. I sure hope it never does:
|
||||
assert abs(NaiveDateTime.diff(expiration.scheduled_at, estimated_expires_at, :second)) < 60
|
||||
|
||||
assert fourth_response["pleroma"]["expires_at"] ==
|
||||
NaiveDateTime.to_iso8601(expiration.scheduled_at)
|
||||
end
|
||||
|
||||
test "replying to a status", %{conn: conn} do
|
||||
|
|
@ -404,7 +431,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert %{"visibility" => "direct"} = status
|
||||
assert status["url"] != direct.data["id"]
|
||||
|
||||
# User should be able to see his own direct message
|
||||
# User should be able to see their own direct message
|
||||
res_conn =
|
||||
build_conn()
|
||||
|> assign(:user, user_one)
|
||||
|
|
@ -901,106 +928,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "lists" do
|
||||
test "creating a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists", %{"title" => "cuties"})
|
||||
|
||||
assert %{"title" => title} = json_response(conn, 200)
|
||||
assert title == "cuties"
|
||||
end
|
||||
|
||||
test "adding users to a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|
||||
assert %{} == json_response(conn, 200)
|
||||
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||
assert following == [other_user.follower_address]
|
||||
end
|
||||
|
||||
test "removing users from a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
third_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, third_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|
||||
assert %{} == json_response(conn, 200)
|
||||
%Pleroma.List{following: following} = Pleroma.List.get(list.id, user)
|
||||
assert following == [third_user.follower_address]
|
||||
end
|
||||
|
||||
test "listing users in a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/lists/#{list.id}/accounts", %{"account_ids" => [other_user.id]})
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id == to_string(other_user.id)
|
||||
end
|
||||
|
||||
test "retrieving a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/lists/#{list.id}")
|
||||
|
||||
assert %{"id" => id} = json_response(conn, 200)
|
||||
assert id == to_string(list.id)
|
||||
end
|
||||
|
||||
test "renaming a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/v1/lists/#{list.id}", %{"title" => "newname"})
|
||||
|
||||
assert %{"title" => name} = json_response(conn, 200)
|
||||
assert name == "newname"
|
||||
end
|
||||
|
||||
test "deleting a list", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> delete("/api/v1/lists/#{list.id}")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
assert is_nil(Repo.get(Pleroma.List, list.id))
|
||||
end
|
||||
|
||||
describe "list timelines" do
|
||||
test "list timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
|
|||
import Pleroma.Factory
|
||||
alias Pleroma.Web.MastodonAPI.ListView
|
||||
|
||||
test "Represent a list" do
|
||||
test "show" do
|
||||
user = insert(:user)
|
||||
title = "mortal enemies"
|
||||
{:ok, list} = Pleroma.List.create(title, user)
|
||||
|
|
@ -17,6 +17,16 @@ defmodule Pleroma.Web.MastodonAPI.ListViewTest do
|
|||
title: title
|
||||
}
|
||||
|
||||
assert expected == ListView.render("list.json", %{list: list})
|
||||
assert expected == ListView.render("show.json", %{list: list})
|
||||
end
|
||||
|
||||
test "index" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, list} = Pleroma.List.create("my list", user)
|
||||
{:ok, list2} = Pleroma.List.create("cofe", user)
|
||||
|
||||
assert [%{id: _, title: "my list"}, %{id: _, title: "cofe"}] =
|
||||
ListView.render("index.json", lists: [list, list2])
|
||||
end
|
||||
end
|
||||
|
|
@ -149,6 +149,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
in_reply_to_account_acct: nil,
|
||||
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
|
||||
spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
|
||||
expires_at: nil,
|
||||
direct_conversation_id: nil
|
||||
}
|
||||
}
|
||||
|
|
@ -5,33 +5,8 @@
|
|||
defmodule Pleroma.Web.RelMeTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
setup do
|
||||
Tesla.Mock.mock(fn
|
||||
%{
|
||||
method: :get,
|
||||
url: "http://example.com/rel_me/anchor"
|
||||
} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor.html")}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "http://example.com/rel_me/anchor_nofollow"
|
||||
} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_anchor_nofollow.html")}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "http://example.com/rel_me/link"
|
||||
} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_link.html")}
|
||||
|
||||
%{
|
||||
method: :get,
|
||||
url: "http://example.com/rel_me/null"
|
||||
} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rel_me_null.html")}
|
||||
end)
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue