Merge remote-tracking branch 'origin/develop' into reactions
This commit is contained in:
commit
b22ee9d966
238 changed files with 6405 additions and 6160 deletions
|
|
@ -354,6 +354,87 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
test "it accepts messages with to as string instead of array", %{conn: conn, data: data} do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
Map.put(data, "to", user.ap_id)
|
||||
|> Map.delete("cc")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
test "it accepts messages with cc as string instead of array", %{conn: conn, data: data} do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
Map.put(data, "cc", user.ap_id)
|
||||
|> Map.delete("to")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
%Activity{} = activity = Activity.get_by_ap_id(data["id"])
|
||||
assert user.ap_id in activity.recipients
|
||||
end
|
||||
|
||||
test "it accepts messages with bcc as string instead of array", %{conn: conn, data: data} do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
Map.put(data, "bcc", user.ap_id)
|
||||
|> Map.delete("to")
|
||||
|> Map.delete("cc")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
assert Activity.get_by_ap_id(data["id"])
|
||||
end
|
||||
|
||||
test "it accepts announces with to as string instead of array", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"actor" => "http://mastodon.example.org/users/admin",
|
||||
"id" => "http://mastodon.example.org/users/admin/statuses/19512778738411822/activity",
|
||||
"object" => "https://mastodon.social/users/emelie/statuses/101849165031453009",
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => [user.ap_id],
|
||||
"type" => "Announce"
|
||||
}
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/inbox", data)
|
||||
|
||||
assert "ok" == json_response(conn, 200)
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
%Activity{} = activity = Activity.get_by_ap_id(data["id"])
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.recipients
|
||||
end
|
||||
|
||||
test "it accepts messages from actors that are followed by the user", %{
|
||||
conn: conn,
|
||||
data: data
|
||||
|
|
@ -683,7 +764,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it returns returns a uri if the user has 'hide_followers' set", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{info: %{hide_followers: true}})
|
||||
user_two = insert(:user, hide_followers: true)
|
||||
User.follow(user, user_two)
|
||||
|
||||
result =
|
||||
|
|
@ -696,7 +777,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it returns a 403 error on pages, if the user has 'hide_followers' set and the request is not authenticated",
|
||||
%{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_followers: true}})
|
||||
user = insert(:user, hide_followers: true)
|
||||
|
||||
result =
|
||||
conn
|
||||
|
|
@ -708,7 +789,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it renders the page, if the user has 'hide_followers' set and the request is authenticated with the same user",
|
||||
%{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_followers: true}})
|
||||
user = insert(:user, hide_followers: true)
|
||||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
|
|
@ -764,7 +845,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "it returns a uri if the user has 'hide_follows' set", %{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_follows: true}})
|
||||
user = insert(:user, hide_follows: true)
|
||||
user_two = insert(:user)
|
||||
User.follow(user, user_two)
|
||||
|
||||
|
|
@ -778,7 +859,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it returns a 403 error on pages, if the user has 'hide_follows' set and the request is not authenticated",
|
||||
%{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_follows: true}})
|
||||
user = insert(:user, hide_follows: true)
|
||||
|
||||
result =
|
||||
conn
|
||||
|
|
@ -790,7 +871,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it renders the page, if the user has 'hide_follows' set and the request is authenticated with the same user",
|
||||
%{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_follows: true}})
|
||||
user = insert(:user, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -41,6 +42,27 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert called(Pleroma.Web.Streamer.stream("participation", participations))
|
||||
end
|
||||
end
|
||||
|
||||
test "streams them out on activity creation" do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
with_mock Pleroma.Web.Streamer,
|
||||
stream: fn _, _ -> nil end do
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "@#{user_two.nickname}",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
conversation =
|
||||
activity.data["context"]
|
||||
|> Pleroma.Conversation.get_for_ap_id()
|
||||
|> Repo.preload(participations: :user)
|
||||
|
||||
assert called(Pleroma.Web.Streamer.stream("participation", conversation.participations))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching restricted by visibility" do
|
||||
|
|
@ -87,17 +109,83 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "fetching excluded by visibility" do
|
||||
test "it excludes by the appropriate visibility" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
|
||||
|
||||
{:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
||||
{:ok, unlisted_activity} =
|
||||
CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
|
||||
|
||||
{:ok, private_activity} =
|
||||
CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
"exclude_visibilities" => "direct",
|
||||
"actor_id" => user.ap_id
|
||||
})
|
||||
|
||||
assert public_activity in activities
|
||||
assert unlisted_activity in activities
|
||||
assert private_activity in activities
|
||||
refute direct_activity in activities
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
"exclude_visibilities" => "unlisted",
|
||||
"actor_id" => user.ap_id
|
||||
})
|
||||
|
||||
assert public_activity in activities
|
||||
refute unlisted_activity in activities
|
||||
assert private_activity in activities
|
||||
assert direct_activity in activities
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
"exclude_visibilities" => "private",
|
||||
"actor_id" => user.ap_id
|
||||
})
|
||||
|
||||
assert public_activity in activities
|
||||
assert unlisted_activity in activities
|
||||
refute private_activity in activities
|
||||
assert direct_activity in activities
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
"exclude_visibilities" => "public",
|
||||
"actor_id" => user.ap_id
|
||||
})
|
||||
|
||||
refute public_activity in activities
|
||||
assert unlisted_activity in activities
|
||||
assert private_activity in activities
|
||||
assert direct_activity in activities
|
||||
end
|
||||
end
|
||||
|
||||
describe "building a user from his ap id" do
|
||||
test "it returns a user" do
|
||||
user_id = "http://mastodon.example.org/users/admin"
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||
assert user.ap_id == user_id
|
||||
assert user.nickname == "admin@mastodon.example.org"
|
||||
assert user.info.source_data
|
||||
assert user.info.ap_enabled
|
||||
assert user.source_data
|
||||
assert user.ap_enabled
|
||||
assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
|
||||
end
|
||||
|
||||
test "it returns a user that is invisible" do
|
||||
user_id = "http://mastodon.example.org/users/relay"
|
||||
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||
assert User.invisible?(user)
|
||||
end
|
||||
|
||||
test "it fetches the appropriate tag-restricted posts" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -279,7 +367,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert activity.actor == user.ap_id
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.note_count == 0
|
||||
assert user.note_count == 0
|
||||
end
|
||||
|
||||
test "can be fetched into a timeline" do
|
||||
|
|
@ -342,7 +430,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.note_count == 2
|
||||
assert user.note_count == 2
|
||||
end
|
||||
|
||||
test "increases replies count" do
|
||||
|
|
@ -606,7 +694,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
{:ok, announce, _object} = CommonAPI.repeat(activity_three.id, booster)
|
||||
|
||||
[announce_activity] = ActivityPub.fetch_activities([user.ap_id | user.following])
|
||||
[announce_activity] = ActivityPub.fetch_activities([user.ap_id | User.following(user)])
|
||||
|
||||
assert announce_activity.id == announce.id
|
||||
end
|
||||
|
|
@ -1081,7 +1169,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
test "decrements user note count only for public activities" do
|
||||
user = insert(:user, info: %{note_count: 10})
|
||||
user = insert(:user, note_count: 10)
|
||||
|
||||
{:ok, a1} =
|
||||
CommonAPI.post(User.get_cached_by_id(user.id), %{
|
||||
|
|
@ -1113,7 +1201,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, _} = Object.normalize(a4) |> ActivityPub.delete()
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.note_count == 10
|
||||
assert user.note_count == 10
|
||||
end
|
||||
|
||||
test "it creates a delete activity and checks that it is also sent to users mentioned by the deleted object" do
|
||||
|
|
@ -1204,7 +1292,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
})
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([user1.ap_id | user1.following])
|
||||
ActivityPub.fetch_activities([user1.ap_id | User.following(user1)])
|
||||
|> Enum.map(fn a -> a.id end)
|
||||
|
||||
private_activity_1 = Activity.get_by_ap_id_with_object(private_activity_1.data["id"])
|
||||
|
|
@ -1214,7 +1302,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert length(activities) == 3
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([user1.ap_id | user1.following], %{"user" => user1})
|
||||
ActivityPub.fetch_activities([user1.ap_id | User.following(user1)], %{"user" => user1})
|
||||
|> Enum.map(fn a -> a.id end)
|
||||
|
||||
assert [public_activity.id, private_activity_1.id] == activities
|
||||
|
|
@ -1266,35 +1354,99 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert 3 = length(activities)
|
||||
end
|
||||
|
||||
test "it can create a Flag activity" do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(target_account, %{"status" => "foobar"})
|
||||
context = Utils.generate_context_id()
|
||||
content = "foobar"
|
||||
describe "flag/1" do
|
||||
setup do
|
||||
reporter = insert(:user)
|
||||
target_account = insert(:user)
|
||||
content = "foobar"
|
||||
{:ok, activity} = CommonAPI.post(target_account, %{"status" => content})
|
||||
context = Utils.generate_context_id()
|
||||
|
||||
reporter_ap_id = reporter.ap_id
|
||||
target_ap_id = target_account.ap_id
|
||||
activity_ap_id = activity.data["id"]
|
||||
reporter_ap_id = reporter.ap_id
|
||||
target_ap_id = target_account.ap_id
|
||||
activity_ap_id = activity.data["id"]
|
||||
|
||||
assert {:ok, activity} =
|
||||
ActivityPub.flag(%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [activity],
|
||||
content: content
|
||||
})
|
||||
activity_with_object = Activity.get_by_ap_id_with_object(activity_ap_id)
|
||||
|
||||
assert %Activity{
|
||||
actor: ^reporter_ap_id,
|
||||
data: %{
|
||||
"type" => "Flag",
|
||||
"content" => ^content,
|
||||
"context" => ^context,
|
||||
"object" => [^target_ap_id, ^activity_ap_id]
|
||||
}
|
||||
} = activity
|
||||
{:ok,
|
||||
%{
|
||||
reporter: reporter,
|
||||
context: context,
|
||||
target_account: target_account,
|
||||
reported_activity: activity,
|
||||
content: content,
|
||||
activity_ap_id: activity_ap_id,
|
||||
activity_with_object: activity_with_object,
|
||||
reporter_ap_id: reporter_ap_id,
|
||||
target_ap_id: target_ap_id
|
||||
}}
|
||||
end
|
||||
|
||||
test "it can create a Flag activity",
|
||||
%{
|
||||
reporter: reporter,
|
||||
context: context,
|
||||
target_account: target_account,
|
||||
reported_activity: reported_activity,
|
||||
content: content,
|
||||
activity_ap_id: activity_ap_id,
|
||||
activity_with_object: activity_with_object,
|
||||
reporter_ap_id: reporter_ap_id,
|
||||
target_ap_id: target_ap_id
|
||||
} do
|
||||
assert {:ok, activity} =
|
||||
ActivityPub.flag(%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [reported_activity],
|
||||
content: content
|
||||
})
|
||||
|
||||
note_obj = %{
|
||||
"type" => "Note",
|
||||
"id" => activity_ap_id,
|
||||
"content" => content,
|
||||
"published" => activity_with_object.object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: target_account})
|
||||
}
|
||||
|
||||
assert %Activity{
|
||||
actor: ^reporter_ap_id,
|
||||
data: %{
|
||||
"type" => "Flag",
|
||||
"content" => ^content,
|
||||
"context" => ^context,
|
||||
"object" => [^target_ap_id, ^note_obj]
|
||||
}
|
||||
} = activity
|
||||
end
|
||||
|
||||
test_with_mock "strips status data from Flag, before federating it",
|
||||
%{
|
||||
reporter: reporter,
|
||||
context: context,
|
||||
target_account: target_account,
|
||||
reported_activity: reported_activity,
|
||||
content: content
|
||||
},
|
||||
Utils,
|
||||
[:passthrough],
|
||||
[] do
|
||||
{:ok, activity} =
|
||||
ActivityPub.flag(%{
|
||||
actor: reporter,
|
||||
context: context,
|
||||
account: target_account,
|
||||
statuses: [reported_activity],
|
||||
content: content
|
||||
})
|
||||
|
||||
new_data =
|
||||
put_in(activity.data, ["object"], [target_account.ap_id, reported_activity.data["id"]])
|
||||
|
||||
assert_called(Utils.maybe_federate(%{activity | data: new_data}))
|
||||
end
|
||||
end
|
||||
|
||||
test "fetch_activities/2 returns activities addressed to a list " do
|
||||
|
|
@ -1377,9 +1529,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
following_address: "http://localhost:4001/users/masto_closed/following"
|
||||
)
|
||||
|
||||
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert info.hide_followers == true
|
||||
assert info.hide_follows == false
|
||||
{:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert follow_info.hide_followers == true
|
||||
assert follow_info.hide_follows == false
|
||||
end
|
||||
|
||||
test "detects hidden follows" do
|
||||
|
|
@ -1400,9 +1552,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
following_address: "http://localhost:4001/users/masto_closed/following"
|
||||
)
|
||||
|
||||
{:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert info.hide_followers == false
|
||||
assert info.hide_follows == true
|
||||
{:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user)
|
||||
assert follow_info.hide_followers == false
|
||||
assert follow_info.hide_follows == true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
test "it allows posts without links" do
|
||||
user = insert(:user)
|
||||
|
||||
assert user.info.note_count == 0
|
||||
assert user.note_count == 0
|
||||
|
||||
message =
|
||||
@linkless_message
|
||||
|
|
@ -47,7 +47,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
test "it disallows posts with links" do
|
||||
user = insert(:user)
|
||||
|
||||
assert user.info.note_count == 0
|
||||
assert user.note_count == 0
|
||||
|
||||
message =
|
||||
@linkful_message
|
||||
|
|
@ -59,9 +59,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
|
||||
describe "with old user" do
|
||||
test "it allows posts without links" do
|
||||
user = insert(:user, info: %{note_count: 1})
|
||||
user = insert(:user, note_count: 1)
|
||||
|
||||
assert user.info.note_count == 1
|
||||
assert user.note_count == 1
|
||||
|
||||
message =
|
||||
@linkless_message
|
||||
|
|
@ -71,9 +71,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
end
|
||||
|
||||
test "it allows posts with links" do
|
||||
user = insert(:user, info: %{note_count: 1})
|
||||
user = insert(:user, note_count: 1)
|
||||
|
||||
assert user.info.note_count == 1
|
||||
assert user.note_count == 1
|
||||
|
||||
message =
|
||||
@linkful_message
|
||||
|
|
@ -85,9 +85,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
|
||||
describe "with followed new user" do
|
||||
test "it allows posts without links" do
|
||||
user = insert(:user, info: %{follower_count: 1})
|
||||
user = insert(:user, follower_count: 1)
|
||||
|
||||
assert user.info.follower_count == 1
|
||||
assert user.follower_count == 1
|
||||
|
||||
message =
|
||||
@linkless_message
|
||||
|
|
@ -97,9 +97,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
end
|
||||
|
||||
test "it allows posts with links" do
|
||||
user = insert(:user, info: %{follower_count: 1})
|
||||
user = insert(:user, follower_count: 1)
|
||||
|
||||
assert user.info.follower_count == 1
|
||||
assert user.follower_count == 1
|
||||
|
||||
message =
|
||||
@linkful_message
|
||||
|
|
@ -133,7 +133,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiLinkSpamPolicyTest do
|
|||
|
||||
describe "with contentless-objects" do
|
||||
test "it does not reject them or error out" do
|
||||
user = insert(:user, info: %{note_count: 1})
|
||||
user = insert(:user, note_count: 1)
|
||||
|
||||
message =
|
||||
@response_message
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do
|
|||
expected = """
|
||||
<b>this is in bold</b>
|
||||
<p>this is a paragraph</p>
|
||||
this is a linebreak<br />
|
||||
this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
|
||||
this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a>
|
||||
this is an image: <img src="http://example.com/image.jpg" /><br />
|
||||
alert('hacked')
|
||||
this is a linebreak<br/>
|
||||
this is a link with allowed "rel" attribute: <a href="http://example.com/" rel="tag">example.com</a>
|
||||
this is a link with not allowed "rel" attribute: <a href="http://example.com/">example.com</a>
|
||||
this is an image: <img src="http://example.com/image.jpg"/><br/>
|
||||
alert('hacked')
|
||||
"""
|
||||
|
||||
message = %{"type" => "Create", "object" => %{"content" => @html_sample}}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
test "it returns sharedInbox for messages involving as:Public in to" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
|
||||
activity = %Activity{
|
||||
|
|
@ -40,7 +40,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
test "it returns sharedInbox for messages involving as:Public in cc" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
|
||||
activity = %Activity{
|
||||
|
|
@ -53,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
test "it returns sharedInbox for messages involving multiple recipients in to" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
|
||||
user_two = insert(:user)
|
||||
|
|
@ -69,7 +69,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
test "it returns sharedInbox for messages involving multiple recipients in cc" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
|
||||
user_two = insert(:user)
|
||||
|
|
@ -84,14 +84,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
test "it returns sharedInbox for messages involving multiple recipients in total" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{
|
||||
source_data: %{
|
||||
"inbox" => "http://example.com/personal-inbox",
|
||||
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
|
||||
}
|
||||
insert(:user,
|
||||
source_data: %{
|
||||
"inbox" => "http://example.com/personal-inbox",
|
||||
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
user_two = insert(:user)
|
||||
|
||||
|
|
@ -104,14 +102,12 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
test "it returns inbox for messages involving single recipients in total" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{
|
||||
source_data: %{
|
||||
"inbox" => "http://example.com/personal-inbox",
|
||||
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
|
||||
}
|
||||
insert(:user,
|
||||
source_data: %{
|
||||
"inbox" => "http://example.com/personal-inbox",
|
||||
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
activity = %Activity{
|
||||
data: %{"to" => [user.ap_id], "cc" => []}
|
||||
|
|
@ -241,10 +237,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
follower =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
|
||||
}
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"},
|
||||
ap_enabled: true
|
||||
)
|
||||
|
||||
actor = insert(:user, follower_address: follower.ap_id)
|
||||
|
|
@ -278,19 +272,15 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"}
|
||||
}
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"},
|
||||
ap_enabled: true
|
||||
)
|
||||
|
||||
another_fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
info: %{
|
||||
ap_enabled: true,
|
||||
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"}
|
||||
}
|
||||
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"},
|
||||
ap_enabled: true
|
||||
)
|
||||
|
||||
actor = insert(:user)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
|
||||
|
|
@ -19,11 +20,16 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
assert user.ap_id == "#{Pleroma.Web.Endpoint.url()}/relay"
|
||||
end
|
||||
|
||||
test "relay actor is invisible" do
|
||||
user = Relay.get_actor()
|
||||
assert User.invisible?(user)
|
||||
end
|
||||
|
||||
describe "follow/1" do
|
||||
test "returns errors when user not found" do
|
||||
assert capture_log(fn ->
|
||||
assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
end) =~ "Could not fetch by AP id"
|
||||
{:error, _} = Relay.follow("test-ap-id")
|
||||
end) =~ "Could not decode user at fetch"
|
||||
end
|
||||
|
||||
test "returns activity" do
|
||||
|
|
@ -41,8 +47,8 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
describe "unfollow/1" do
|
||||
test "returns errors when user not found" do
|
||||
assert capture_log(fn ->
|
||||
assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
|
||||
end) =~ "Could not fetch by AP id"
|
||||
{:error, _} = Relay.unfollow("test-ap-id")
|
||||
end) =~ "Could not decode user at fetch"
|
||||
end
|
||||
|
||||
test "returns activity" do
|
||||
|
|
@ -50,14 +56,14 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
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 "#{user.ap_id}/followers" in User.following(service_actor)
|
||||
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
|
||||
refute "#{user.ap_id}/followers" in User.following(service_actor)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
end
|
||||
|
||||
test "with locked accounts, it does not create a follow or an accept" do
|
||||
user = insert(:user, info: %{locked: true})
|
||||
user = insert(:user, locked: true)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|
|
|
|||
|
|
@ -7,14 +7,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Object.Fetcher
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
|
@ -148,7 +146,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(object_data["actor"])
|
||||
|
||||
assert user.info.note_count == 1
|
||||
assert user.note_count == 1
|
||||
end
|
||||
|
||||
test "it works for incoming notices with hashtags" do
|
||||
|
|
@ -673,7 +671,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
}
|
||||
]
|
||||
|
||||
assert user.info.banner["url"] == [
|
||||
assert user.banner["url"] == [
|
||||
%{
|
||||
"href" =>
|
||||
"https://cd.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
|
|
@ -692,7 +690,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(activity.actor)
|
||||
|
||||
assert User.Info.fields(user.info) == [
|
||||
assert User.fields(user) == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "foo1", "value" => "bar1"}
|
||||
]
|
||||
|
|
@ -713,7 +711,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.Info.fields(user.info) == [
|
||||
assert User.fields(user) == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
|
@ -731,7 +729,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.Info.fields(user.info) == [
|
||||
assert User.fields(user) == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
|
@ -742,7 +740,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.Info.fields(user.info) == []
|
||||
assert User.fields(user) == []
|
||||
end
|
||||
|
||||
test "it works for incoming update activities which lock the account" do
|
||||
|
|
@ -765,11 +763,12 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.info.locked == true
|
||||
assert user.locked == true
|
||||
end
|
||||
|
||||
test "it works for incoming deletes" do
|
||||
activity = insert(:note_activity)
|
||||
deleting_user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-delete.json")
|
||||
|
|
@ -782,11 +781,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
data =
|
||||
data
|
||||
|> Map.put("object", object)
|
||||
|> Map.put("actor", activity.data["actor"])
|
||||
|> Map.put("actor", deleting_user.ap_id)
|
||||
|
||||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
||||
{:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
|
||||
Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert id == data["id"]
|
||||
refute Activity.get_by_id(activity.id)
|
||||
assert actor == deleting_user.ap_id
|
||||
end
|
||||
|
||||
test "it fails for incoming deletes with spoofed origin" do
|
||||
|
|
@ -807,7 +809,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert capture_log(fn ->
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end) =~
|
||||
"[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, {:error, :nxdomain}}"
|
||||
"[error] Could not decode user at fetch http://mastodon.example.org/users/gargron, {:error, :nxdomain}"
|
||||
|
||||
assert Activity.get_by_id(activity.id)
|
||||
end
|
||||
|
|
@ -833,7 +835,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|> Poison.decode!()
|
||||
|> Map.put("actor", ap_id)
|
||||
|
||||
assert :error == Transmogrifier.handle_incoming(data)
|
||||
assert capture_log(fn ->
|
||||
assert :error == Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
|
||||
assert User.get_cached_by_ap_id(ap_id)
|
||||
end
|
||||
|
||||
|
|
@ -891,6 +896,25 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Follow"
|
||||
assert data["object"] == user.ap_id
|
||||
assert data["state"] == "pending"
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
assert [^pending_follower] = User.get_follow_requests(user)
|
||||
end
|
||||
|
||||
test "it works for incoming blocks" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -993,6 +1017,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
assert activity.data["id"] == accept_data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
|
@ -1000,7 +1026,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
test "it works for incoming accepts which were orphaned" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %User.Info{locked: true}})
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
|
|
@ -1022,7 +1048,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
test "it works for incoming accepts which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %User.Info{locked: true}})
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
||||
|
|
@ -1042,7 +1068,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
test "it fails for incoming accepts which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %User.Info{locked: true}})
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|
|
@ -1061,7 +1087,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
test "it fails for incoming rejects which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %User.Info{locked: true}})
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|
|
@ -1080,7 +1106,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
test "it works for incoming rejects which are orphaned" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %User.Info{locked: true}})
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, _follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
|
@ -1097,6 +1123,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
|
||||
refute activity.local
|
||||
assert activity.data["id"] == reject_data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
|
|
@ -1105,7 +1132,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
test "it works for incoming rejects which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, %{info: %User.Info{locked: true}})
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, followed)
|
||||
|
|
@ -1174,10 +1201,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test post"})
|
||||
object = Object.normalize(activity)
|
||||
|
||||
note_obj = %{
|
||||
"type" => "Note",
|
||||
"id" => activity.data["id"],
|
||||
"content" => "test post",
|
||||
"published" => object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: user})
|
||||
}
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"cc" => [user.ap_id],
|
||||
"object" => [user.ap_id, object.data["id"]],
|
||||
"object" => [user.ap_id, activity.data["id"]],
|
||||
"type" => "Flag",
|
||||
"content" => "blocked AND reported!!!",
|
||||
"actor" => other_user.ap_id
|
||||
|
|
@ -1185,11 +1220,55 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
assert activity.data["object"] == [user.ap_id, object.data["id"]]
|
||||
assert activity.data["object"] == [user.ap_id, note_obj]
|
||||
assert activity.data["content"] == "blocked AND reported!!!"
|
||||
assert activity.data["actor"] == other_user.ap_id
|
||||
assert activity.data["cc"] == [user.ap_id]
|
||||
end
|
||||
|
||||
test "it correctly processes messages with non-array to field" do
|
||||
user = insert(:user)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "blah blah blah",
|
||||
"type" => "Note",
|
||||
"attributedTo" => user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["to"]
|
||||
end
|
||||
|
||||
test "it correctly processes messages with non-array cc field" do
|
||||
user = insert(:user)
|
||||
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => user.follower_address,
|
||||
"cc" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"content" => "blah blah blah",
|
||||
"type" => "Note",
|
||||
"attributedTo" => user.ap_id,
|
||||
"inReplyTo" => nil
|
||||
},
|
||||
"actor" => user.ap_id
|
||||
}
|
||||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]
|
||||
assert [user.follower_address] == activity.data["to"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "prepare outgoing" do
|
||||
|
|
@ -1262,32 +1341,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert modified["object"]["actor"] == modified["object"]["attributedTo"]
|
||||
end
|
||||
|
||||
test "it translates ostatus IDs to external URLs" do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
{:ok, [referent_activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity, _} = CommonAPI.favorite(referent_activity.id, user)
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"] == "http://gs.example.org:4040/index.php/notice/29"
|
||||
end
|
||||
|
||||
test "it translates ostatus reply_to IDs to external URLs" do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
{:ok, [referred_activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "HI!", "in_reply_to_status_id" => referred_activity.id})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert modified["object"]["inReplyTo"] == "http://gs.example.org:4040/index.php/notice/29"
|
||||
end
|
||||
|
||||
test "it strips internal hashtag data" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -1400,25 +1453,26 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
|
||||
})
|
||||
|
||||
user_two = insert(:user, %{following: [user.follower_address]})
|
||||
user_two = insert(:user)
|
||||
Pleroma.FollowingRelationship.follow(user_two, user, "accept")
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
{:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
|
||||
assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.note_count == 1
|
||||
assert user.note_count == 1
|
||||
|
||||
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert user.info.ap_enabled
|
||||
assert user.info.note_count == 1
|
||||
assert user.ap_enabled
|
||||
assert user.note_count == 1
|
||||
assert user.follower_address == "https://niu.moe/users/rye/followers"
|
||||
assert user.following_address == "https://niu.moe/users/rye/following"
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.note_count == 1
|
||||
assert user.note_count == 1
|
||||
|
||||
activity = Activity.get_by_id(activity.id)
|
||||
assert user.follower_address in activity.recipients
|
||||
|
|
@ -1439,7 +1493,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
|
||||
}
|
||||
]
|
||||
} = user.info.banner
|
||||
} = user.banner
|
||||
|
||||
refute "..." in activity.recipients
|
||||
|
||||
|
|
@ -1447,23 +1501,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute user.follower_address in unrelated_activity.recipients
|
||||
|
||||
user_two = User.get_cached_by_id(user_two.id)
|
||||
assert user.follower_address in user_two.following
|
||||
refute "..." in user_two.following
|
||||
end
|
||||
end
|
||||
|
||||
describe "maybe_retire_websub" do
|
||||
test "it deletes all websub client subscripitions with the user as topic" do
|
||||
subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/rye.atom"}
|
||||
{:ok, ws} = Repo.insert(subscription)
|
||||
|
||||
subscription = %WebsubClientSubscription{topic: "https://niu.moe/users/pasty.atom"}
|
||||
{:ok, ws2} = Repo.insert(subscription)
|
||||
|
||||
Transmogrifier.maybe_retire_websub("https://niu.moe/users/rye")
|
||||
|
||||
refute Repo.get(WebsubClientSubscription, ws.id)
|
||||
assert Repo.get(WebsubClientSubscription, ws2.id)
|
||||
assert User.following?(user_two, user)
|
||||
refute "..." in User.following(user_two)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1489,7 +1528,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"type" => "Announce"
|
||||
}
|
||||
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
assert capture_log(fn ->
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
end
|
||||
|
||||
test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
|
||||
|
|
@ -1502,7 +1543,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"type" => "Announce"
|
||||
}
|
||||
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
assert capture_log(fn ->
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
end
|
||||
|
||||
test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
|
||||
|
|
@ -1515,7 +1558,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"type" => "Announce"
|
||||
}
|
||||
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
assert capture_log(fn ->
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "Object containment failed"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1818,7 +1863,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
describe "get_obj_helper/2" do
|
||||
test "returns nil when cannot normalize object" do
|
||||
refute Transmogrifier.get_obj_helper("test-obj-id")
|
||||
assert capture_log(fn ->
|
||||
refute Transmogrifier.get_obj_helper("test-obj-id")
|
||||
end) =~ "Unsupported URI scheme"
|
||||
end
|
||||
|
||||
test "returns {:ok, %Object{}} for success case" do
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -297,7 +298,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, info: %{locked: true})
|
||||
user = insert(:user, locked: true)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, user)
|
||||
|
|
@ -321,7 +322,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, info: %{locked: true})
|
||||
user = insert(:user, locked: true)
|
||||
follower = insert(:user)
|
||||
|
||||
{:ok, follow_activity} = ActivityPub.follow(follower, user)
|
||||
|
|
@ -581,11 +582,19 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
%{}
|
||||
)
|
||||
|
||||
note_obj = %{
|
||||
"type" => "Note",
|
||||
"id" => activity_ap_id,
|
||||
"content" => content,
|
||||
"published" => activity.object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: target_account})
|
||||
}
|
||||
|
||||
assert %{
|
||||
"type" => "Flag",
|
||||
"content" => ^content,
|
||||
"context" => ^context,
|
||||
"object" => [^target_ap_id, ^activity_ap_id],
|
||||
"object" => [^target_ap_id, ^note_obj],
|
||||
"state" => "open"
|
||||
} = res
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
|
||||
{:ok, user} =
|
||||
insert(:user)
|
||||
|> User.upgrade_changeset(%{info: %{fields: fields}})
|
||||
|> User.upgrade_changeset(%{fields: fields})
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
assert %{
|
||||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
end
|
||||
|
||||
test "Renders with emoji tags" do
|
||||
user = insert(:user, %{info: %{emoji: [%{"bib" => "/test"}]}})
|
||||
user = insert(:user, emoji: [%{"bib" => "/test"}])
|
||||
|
||||
assert %{
|
||||
"tag" => [
|
||||
|
|
@ -64,9 +64,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
user =
|
||||
insert(:user,
|
||||
avatar: %{"url" => [%{"href" => "https://someurl"}]},
|
||||
info: %{
|
||||
banner: %{"url" => [%{"href" => "https://somebanner"}]}
|
||||
}
|
||||
banner: %{"url" => [%{"href" => "https://somebanner"}]}
|
||||
)
|
||||
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
|
|
@ -76,6 +74,12 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
assert result["image"]["url"] == "https://somebanner"
|
||||
end
|
||||
|
||||
test "renders an invisible user with the invisible property set to true" do
|
||||
user = insert(:user, invisible: true)
|
||||
|
||||
assert %{"invisible" => true} = UserView.render("service.json", %{user: user})
|
||||
end
|
||||
|
||||
describe "endpoints" do
|
||||
test "local users have a usable endpoints structure" do
|
||||
user = insert(:user)
|
||||
|
|
@ -121,8 +125,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_followers_count: true, hide_followers: true})
|
||||
user = Map.put(user, :info, info)
|
||||
user = Map.merge(user, %{hide_followers_count: true, hide_followers: true})
|
||||
assert %{"totalItems" => 0} = UserView.render("followers.json", %{user: user})
|
||||
end
|
||||
|
||||
|
|
@ -131,8 +134,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_followers_count: false, hide_followers: true})
|
||||
user = Map.put(user, :info, info)
|
||||
user = Map.merge(user, %{hide_followers_count: false, hide_followers: true})
|
||||
assert %{"totalItems" => 1} = UserView.render("followers.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
|
@ -143,8 +145,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_follows_count: true, hide_follows: true})
|
||||
user = Map.put(user, :info, info)
|
||||
user = Map.merge(user, %{hide_follows_count: true, hide_follows: true})
|
||||
assert %{"totalItems" => 0} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
|
||||
|
|
@ -153,8 +154,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
other_user = insert(:user)
|
||||
{:ok, user, _other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
info = Map.merge(user.info, %{hide_follows_count: false, hide_follows: true})
|
||||
user = Map.put(user, :info, info)
|
||||
user = Map.merge(user, %{hide_follows_count: false, hide_follows: true})
|
||||
assert %{"totalItems" => 1} = UserView.render("following.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -212,7 +212,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
|
||||
test "returns true if user following to author" do
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id])
|
||||
user = insert(:user)
|
||||
Pleroma.User.follow(user, author)
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
|
|||
|
|
@ -13,13 +13,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.ActivityPub.Relay
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MediaProxy
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "/api/pleroma/admin/users" do
|
||||
test "Delete" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "DELETE /api/pleroma/admin/users" do
|
||||
test "single user" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -30,17 +37,38 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
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}"
|
||||
"@#{admin.nickname} deleted users: @#{user.nickname}"
|
||||
|
||||
assert json_response(conn, 200) == user.nickname
|
||||
end
|
||||
|
||||
test "multiple users" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> 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" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -70,7 +98,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "Cannot create user with exisiting email" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -101,7 +129,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "Cannot create user with exisiting nickname" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -132,7 +160,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "Multiple user creation works in transaction" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -181,7 +209,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "/api/pleroma/admin/users/:nickname" do
|
||||
test "Show", %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -204,7 +232,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "when the user doesn't exist", %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = build(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -218,7 +246,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "/api/pleroma/admin/users/follow" do
|
||||
test "allows to force-follow another user" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
|
|
@ -244,7 +272,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "/api/pleroma/admin/users/unfollow" do
|
||||
test "allows to force-unfollow another user" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
follower = insert(:user)
|
||||
|
||||
|
|
@ -272,7 +300,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "PUT /api/pleroma/admin/users/tag" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user1 = insert(:user, %{tags: ["x"]})
|
||||
user2 = insert(:user, %{tags: ["y"]})
|
||||
user3 = insert(:user, %{tags: ["unchanged"]})
|
||||
|
|
@ -321,7 +349,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "DELETE /api/pleroma/admin/users/tag" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user1 = insert(:user, %{tags: ["x"]})
|
||||
user2 = insert(:user, %{tags: ["y", "z"]})
|
||||
user3 = insert(:user, %{tags: ["unchanged"]})
|
||||
|
|
@ -370,7 +398,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "/api/pleroma/admin/users/:nickname/permission_group" do
|
||||
test "GET is giving user_info" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -385,7 +413,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "/:right POST, can add to a permission group" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -404,9 +432,32 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{admin.nickname} made @#{user.nickname} admin"
|
||||
end
|
||||
|
||||
test "/:right POST, can add to a permission group (multiple)" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> post("/api/pleroma/admin/users/permission_group/admin", %{
|
||||
nicknames: [user_one.nickname, user_two.nickname]
|
||||
})
|
||||
|
||||
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_one.nickname}, @#{user_two.nickname} admin"
|
||||
end
|
||||
|
||||
test "/:right DELETE, can remove from a permission group" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
user = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -423,69 +474,36 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} revoked admin role from @#{user.nickname}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /api/pleroma/admin/users/:nickname/activation_status" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
test "/:right DELETE, can remove from a permission group (multiple)" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user_one = insert(:user, is_admin: true)
|
||||
user_two = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
conn
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> delete("/api/pleroma/admin/users/permission_group/admin", %{
|
||||
nicknames: [user_one.nickname, user_two.nickname]
|
||||
})
|
||||
|
||||
%{conn: conn, admin: admin}
|
||||
end
|
||||
|
||||
test "deactivates the user", %{conn: conn, admin: admin} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/users/#{user.nickname}/activation_status", %{status: false})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.info.deactivated == true
|
||||
assert json_response(conn, :no_content)
|
||||
assert json_response(conn, 200) == %{
|
||||
"is_admin" => false
|
||||
}
|
||||
|
||||
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, admin: admin} do
|
||||
user = insert(:user, info: %{deactivated: true})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put("/api/pleroma/admin/users/#{user.nickname}/activation_status", %{status: true})
|
||||
|
||||
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
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put("/api/pleroma/admin/users/#{user.nickname}/activation_status", %{status: false})
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
"@#{admin.nickname} revoked admin role from @#{user_one.nickname}, @#{
|
||||
user_two.nickname
|
||||
}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/email_invite, with valid config" do
|
||||
setup do
|
||||
[user: insert(:user, info: %{is_admin: true})]
|
||||
[user: insert(:user, is_admin: true)]
|
||||
end
|
||||
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
|
|
@ -545,7 +563,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "POST /api/pleroma/admin/users/email_invite, with invalid config" do
|
||||
setup do
|
||||
[user: insert(:user, info: %{is_admin: true})]
|
||||
[user: insert(:user, is_admin: true)]
|
||||
end
|
||||
|
||||
clear_config([:instance, :registrations_open])
|
||||
|
|
@ -577,7 +595,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "/api/pleroma/admin/users/:nickname/password_reset" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -593,7 +611,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/users" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -609,7 +627,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
users =
|
||||
[
|
||||
%{
|
||||
"deactivated" => admin.info.deactivated,
|
||||
"deactivated" => admin.deactivated,
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"roles" => %{"admin" => true, "moderator" => false},
|
||||
|
|
@ -619,7 +637,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"display_name" => HTML.strip_tags(admin.name || admin.nickname)
|
||||
},
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -660,7 +678,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -684,7 +702,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -708,7 +726,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -732,7 +750,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -756,7 +774,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -780,7 +798,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 1,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -799,7 +817,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 1,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user2.info.deactivated,
|
||||
"deactivated" => user2.deactivated,
|
||||
"id" => user2.id,
|
||||
"nickname" => user2.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -813,7 +831,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "only local users" do
|
||||
admin = insert(:user, info: %{is_admin: true}, nickname: "john")
|
||||
admin = insert(:user, is_admin: true, nickname: "john")
|
||||
user = insert(:user, nickname: "bob")
|
||||
|
||||
insert(:user, nickname: "bobb", local: false)
|
||||
|
|
@ -828,7 +846,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -842,7 +860,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "only local users with no query", %{admin: old_admin} do
|
||||
admin = insert(:user, info: %{is_admin: true}, nickname: "john")
|
||||
admin = insert(:user, is_admin: true, nickname: "john")
|
||||
user = insert(:user, nickname: "bob")
|
||||
|
||||
insert(:user, nickname: "bobb", local: false)
|
||||
|
|
@ -855,7 +873,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
users =
|
||||
[
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -865,7 +883,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"display_name" => HTML.strip_tags(user.name || user.nickname)
|
||||
},
|
||||
%{
|
||||
"deactivated" => admin.info.deactivated,
|
||||
"deactivated" => admin.deactivated,
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"roles" => %{"admin" => true, "moderator" => false},
|
||||
|
|
@ -895,7 +913,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "load only admins", %{conn: conn, admin: admin} do
|
||||
second_admin = insert(:user, info: %{is_admin: true})
|
||||
second_admin = insert(:user, is_admin: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
|
|
@ -934,7 +952,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "load only moderators", %{conn: conn} do
|
||||
moderator = insert(:user, info: %{is_moderator: true})
|
||||
moderator = insert(:user, is_moderator: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
|
|
@ -999,11 +1017,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "it works with multiple filters" do
|
||||
admin = insert(:user, nickname: "john", info: %{is_admin: true})
|
||||
user = insert(:user, nickname: "bob", local: false, info: %{deactivated: true})
|
||||
admin = insert(:user, nickname: "john", is_admin: true)
|
||||
user = insert(:user, nickname: "bob", local: false, deactivated: true)
|
||||
|
||||
insert(:user, nickname: "ken", local: true, info: %{deactivated: true})
|
||||
insert(:user, nickname: "bobb", local: false, info: %{deactivated: false})
|
||||
insert(:user, nickname: "ken", local: true, deactivated: true)
|
||||
insert(:user, nickname: "bobb", local: false, deactivated: false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -1015,7 +1033,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => user.info.deactivated,
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -1027,10 +1045,80 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "it omits relay user", %{admin: admin} do
|
||||
assert %User{} = Relay.get_actor()
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> get("/api/pleroma/admin/users")
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => [
|
||||
%{
|
||||
"deactivated" => admin.deactivated,
|
||||
"id" => admin.id,
|
||||
"nickname" => admin.nickname,
|
||||
"roles" => %{"admin" => true, "moderator" => false},
|
||||
"local" => true,
|
||||
"tags" => [],
|
||||
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(admin.name || admin.nickname)
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/activate" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user_one = insert(:user, deactivated: true)
|
||||
user_two = insert(:user, deactivated: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> patch(
|
||||
"/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" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
user_one = insert(:user, deactivated: false)
|
||||
user_two = insert(:user, deactivated: false)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> patch(
|
||||
"/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/:nickname/toggle_activation" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -1040,7 +1128,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert json_response(conn, 200) ==
|
||||
%{
|
||||
"deactivated" => !user.info.deactivated,
|
||||
"deactivated" => !user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
|
|
@ -1053,12 +1141,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} deactivated user @#{user.nickname}"
|
||||
"@#{admin.nickname} deactivated users: @#{user.nickname}"
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/users/invite_token" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -1122,7 +1210,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/users/invites" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -1160,7 +1248,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "POST /api/pleroma/admin/users/revoke_invite" do
|
||||
test "with token" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
||||
conn =
|
||||
|
|
@ -1180,7 +1268,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
test "with invalid token" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
@ -1193,7 +1281,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/reports/:id" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
%{conn: assign(conn, :user, admin)}
|
||||
end
|
||||
|
|
@ -1226,7 +1314,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "PUT /api/pleroma/admin/reports/:id" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
[reporter, target_user] = insert_pair(:user)
|
||||
activity = insert(:note_activity, user: target_user)
|
||||
|
||||
|
|
@ -1287,7 +1375,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/reports" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
%{conn: assign(conn, :user, admin)}
|
||||
end
|
||||
|
|
@ -1407,7 +1495,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
#
|
||||
describe "POST /api/pleroma/admin/reports/:id/respond" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
end
|
||||
|
|
@ -1462,7 +1550,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "PUT /api/pleroma/admin/statuses/:id" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
activity = insert(:note_activity)
|
||||
|
||||
%{conn: assign(conn, :user, admin), id: activity.id, admin: admin}
|
||||
|
|
@ -1528,7 +1616,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "DELETE /api/pleroma/admin/statuses/:id" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
activity = insert(:note_activity)
|
||||
|
||||
%{conn: assign(conn, :user, admin), id: activity.id, admin: admin}
|
||||
|
|
@ -1558,7 +1646,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/config" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
%{conn: assign(conn, :user, admin)}
|
||||
end
|
||||
|
|
@ -1595,7 +1683,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "POST /api/pleroma/admin/config" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
temp_file = "config/test.exported_from_db.secret.exs"
|
||||
|
||||
|
|
@ -2163,7 +2251,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "config mix tasks run" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
temp_file = "config/test.exported_from_db.secret.exs"
|
||||
|
||||
|
|
@ -2199,7 +2287,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/users/:nickname/statuses" do
|
||||
setup do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
date1 = (DateTime.to_unix(DateTime.utc_now()) + 2000) |> DateTime.from_unix!()
|
||||
|
|
@ -2256,8 +2344,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "GET /api/pleroma/admin/moderation_log" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
moderator = insert(:user, info: %{is_moderator: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
moderator = insert(:user, is_moderator: true)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin, moderator: moderator}
|
||||
end
|
||||
|
|
@ -2465,25 +2553,91 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "PATCH /users/:nickname/force_password_reset" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
user = insert(:user)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin, user: user}
|
||||
end
|
||||
|
||||
test "sets password_reset_pending to true", %{admin: admin, user: user} do
|
||||
assert user.info.password_reset_pending == false
|
||||
assert user.password_reset_pending == false
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> patch("/api/pleroma/admin/users/#{user.nickname}/force_password_reset")
|
||||
|> patch("/api/pleroma/admin/users/force_password_reset", %{nicknames: [user.nickname]})
|
||||
|
||||
assert json_response(conn, 204) == ""
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert User.get_by_id(user.id).info.password_reset_pending == true
|
||||
assert User.get_by_id(user.id).password_reset_pending == true
|
||||
end
|
||||
end
|
||||
|
||||
describe "relays" do
|
||||
setup %{conn: conn} do
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
%{conn: assign(conn, :user, admin), admin: admin}
|
||||
end
|
||||
|
||||
test "POST /relay", %{admin: admin} do
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> post("/api/pleroma/admin/relay", %{
|
||||
relay_url: "http://mastodon.example.org/users/admin"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == "http://mastodon.example.org/users/admin"
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
|
||||
end
|
||||
|
||||
test "GET /relay", %{admin: admin} do
|
||||
relay_user = Pleroma.Web.ActivityPub.Relay.get_actor()
|
||||
|
||||
["http://mastodon.example.org/users/admin", "https://mstdn.io/users/mayuutann"]
|
||||
|> Enum.each(fn ap_id ->
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id(ap_id)
|
||||
User.follow(relay_user, user)
|
||||
end)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> get("/api/pleroma/admin/relay")
|
||||
|
||||
assert json_response(conn, 200)["relays"] -- ["mastodon.example.org", "mstdn.io"] == []
|
||||
end
|
||||
|
||||
test "DELETE /relay", %{admin: admin} do
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> post("/api/pleroma/admin/relay", %{
|
||||
relay_url: "http://mastodon.example.org/users/admin"
|
||||
})
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, admin)
|
||||
|> delete("/api/pleroma/admin/relay", %{
|
||||
relay_url: "http://mastodon.example.org/users/admin"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == "http://mastodon.example.org/users/admin"
|
||||
|
||||
[log_entry_one, log_entry_two] = Repo.all(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry_one) ==
|
||||
"@#{admin.nickname} followed relay: http://mastodon.example.org/users/admin"
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry_two) ==
|
||||
"@#{admin.nickname} unfollowed relay: http://mastodon.example.org/users/admin"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
end
|
||||
|
||||
test "it returns active/deactivated users" do
|
||||
insert(:user, info: %{deactivated: true})
|
||||
insert(:user, info: %{deactivated: true})
|
||||
insert(:user, info: %{deactivated: false})
|
||||
insert(:user, deactivated: true)
|
||||
insert(:user, deactivated: true)
|
||||
insert(:user, deactivated: false)
|
||||
|
||||
{:ok, _results, active_count} =
|
||||
Search.user(%{
|
||||
|
|
@ -70,7 +70,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
test "it returns specific user" do
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
user = insert(:user, nickname: "bob", local: true, info: %{deactivated: false})
|
||||
user = insert(:user, nickname: "bob", local: true, deactivated: false)
|
||||
|
||||
{:ok, _results, total_count} = Search.user(%{query: ""})
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
end
|
||||
|
||||
test "it returns admin user" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
end
|
||||
|
||||
test "it returns moderator user" do
|
||||
moderator = insert(:user, info: %{is_moderator: true})
|
||||
moderator = insert(:user, is_moderator: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
{:ok, report_activity} =
|
||||
CommonAPI.report(user, %{"account_id" => other_user.id, "status_ids" => [activity.id]})
|
||||
|
||||
other_user = Pleroma.User.get_by_id(other_user.id)
|
||||
|
||||
expected = %{
|
||||
content: nil,
|
||||
actor:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -100,7 +101,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, activity} = CommonAPI.update(user)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
[firefox] = user.info.source_data["tag"]
|
||||
[firefox] = user.source_data["tag"]
|
||||
|
||||
assert firefox["name"] == ":firefox:"
|
||||
|
||||
|
|
@ -140,7 +141,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
end
|
||||
|
||||
test "it filters out obviously bad tags when accepting a post as Markdown" do
|
||||
|
|
@ -156,7 +157,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
|
||||
end
|
||||
|
||||
test "it does not allow replies to direct messages that are not direct messages themselves" do
|
||||
|
|
@ -318,7 +319,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
id = activity.id
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{info: %{pinned_activities: [^id]}} = user
|
||||
assert %User{pinned_activities: [^id]} = user
|
||||
end
|
||||
|
||||
test "unlisted statuses can be pinned", %{user: user} do
|
||||
|
|
@ -352,7 +353,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{info: %{pinned_activities: []}} = user
|
||||
assert %User{pinned_activities: []} = user
|
||||
end
|
||||
|
||||
test "should unpin when deleting a status", %{user: user, activity: activity} do
|
||||
|
|
@ -364,7 +365,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %User{info: %{pinned_activities: []}} = user
|
||||
assert %User{pinned_activities: []} = user
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -412,6 +413,14 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
"status_ids" => [activity.id]
|
||||
}
|
||||
|
||||
note_obj = %{
|
||||
"type" => "Note",
|
||||
"id" => activity_ap_id,
|
||||
"content" => "foobar",
|
||||
"published" => activity.object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: target_user})
|
||||
}
|
||||
|
||||
assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
|
||||
|
||||
assert %Activity{
|
||||
|
|
@ -419,7 +428,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
data: %{
|
||||
"type" => "Flag",
|
||||
"content" => ^comment,
|
||||
"object" => [^target_ap_id, ^activity_ap_id],
|
||||
"object" => [^target_ap_id, ^note_obj],
|
||||
"state" => "open"
|
||||
}
|
||||
} = flag_activity
|
||||
|
|
@ -439,6 +448,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, report} = CommonAPI.update_report_state(report_id, "resolved")
|
||||
|
||||
assert report.data["state"] == "resolved"
|
||||
|
||||
[reported_user, activity_id] = report.data["object"]
|
||||
|
||||
assert reported_user == target_user.ap_id
|
||||
assert activity_id == activity.data["id"]
|
||||
end
|
||||
|
||||
test "does not update report state when state is unsupported" do
|
||||
|
|
@ -495,7 +509,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, info: %{locked: true})
|
||||
user = insert(:user, locked: true)
|
||||
follower = insert(:user)
|
||||
follower_two = insert(:user)
|
||||
|
||||
|
|
@ -515,7 +529,7 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
test "after rejection, it sets all existing pending follow request states to 'reject'" do
|
||||
user = insert(:user, info: %{locked: true})
|
||||
user = insert(:user, locked: true)
|
||||
follower = insert(:user)
|
||||
follower_two = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -81,14 +81,16 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
local: false,
|
||||
nickname: "nick1@domain.com",
|
||||
ap_id: "https://domain.com/users/nick1",
|
||||
info: %{ap_enabled: true, source_data: %{"inbox" => inbox1}}
|
||||
source_data: %{"inbox" => inbox1},
|
||||
ap_enabled: true
|
||||
})
|
||||
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "nick2@domain2.com",
|
||||
ap_id: "https://domain2.com/users/nick2",
|
||||
info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
|
||||
source_data: %{"inbox" => inbox2},
|
||||
ap_enabled: true
|
||||
})
|
||||
|
||||
dt = NaiveDateTime.utc_now()
|
||||
|
|
@ -111,93 +113,6 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
all_enqueued(worker: PublisherWorker)
|
||||
)
|
||||
end
|
||||
|
||||
test "it federates only to reachable instances via Websub" do
|
||||
user = insert(:user)
|
||||
websub_topic = Pleroma.Web.OStatus.feed_path(user)
|
||||
|
||||
sub1 =
|
||||
insert(:websub_subscription, %{
|
||||
topic: websub_topic,
|
||||
state: "active",
|
||||
callback: "http://pleroma.soykaf.com/cb"
|
||||
})
|
||||
|
||||
sub2 =
|
||||
insert(:websub_subscription, %{
|
||||
topic: websub_topic,
|
||||
state: "active",
|
||||
callback: "https://pleroma2.soykaf.com/cb"
|
||||
})
|
||||
|
||||
dt = NaiveDateTime.utc_now()
|
||||
Instances.set_unreachable(sub2.callback, dt)
|
||||
|
||||
Instances.set_consistently_unreachable(sub1.callback)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
|
||||
|
||||
expected_callback = sub2.callback
|
||||
expected_dt = NaiveDateTime.to_iso8601(dt)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "publish_one",
|
||||
"params" => %{
|
||||
"callback" => expected_callback,
|
||||
"unreachable_since" => expected_dt
|
||||
}
|
||||
},
|
||||
all_enqueued(worker: PublisherWorker)
|
||||
)
|
||||
end
|
||||
|
||||
test "it federates only to reachable instances via Salmon" do
|
||||
user = insert(:user)
|
||||
|
||||
_remote_user1 =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "nick1@domain.com",
|
||||
ap_id: "https://domain.com/users/nick1",
|
||||
info: %{salmon: "https://domain.com/salmon"}
|
||||
})
|
||||
|
||||
remote_user2 =
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
nickname: "nick2@domain2.com",
|
||||
ap_id: "https://domain2.com/users/nick2",
|
||||
info: %{salmon: "https://domain2.com/salmon"}
|
||||
})
|
||||
|
||||
remote_user2_id = remote_user2.id
|
||||
|
||||
dt = NaiveDateTime.utc_now()
|
||||
Instances.set_unreachable(remote_user2.ap_id, dt)
|
||||
|
||||
Instances.set_consistently_unreachable("domain.com")
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
|
||||
|
||||
expected_dt = NaiveDateTime.to_iso8601(dt)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
|
||||
|
||||
assert ObanHelpers.member?(
|
||||
%{
|
||||
"op" => "publish_one",
|
||||
"params" => %{
|
||||
"recipient_id" => remote_user2_id,
|
||||
"unreachable_since" => expected_dt
|
||||
}
|
||||
},
|
||||
all_enqueued(worker: PublisherWorker)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Receive an activity" do
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEController do
|
|||
assert _result = json_response(conn, 200)
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert user.info.settings == %{"programming" => "socks"}
|
||||
assert user.settings == %{"programming" => "socks"}
|
||||
end
|
||||
|
||||
describe "index/2 redirections" do
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|> json_response(200)
|
||||
|
||||
assert response["pleroma"]["skip_thread_containment"] == true
|
||||
assert refresh_record(user).info.skip_thread_containment
|
||||
assert refresh_record(user).skip_thread_containment
|
||||
end
|
||||
|
||||
test "updates the user's hide_follows status", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -237,6 +237,20 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id == to_string(post.id)
|
||||
end
|
||||
|
||||
test "the user views their own timelines and excludes direct messages", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
|
||||
{:ok, _direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses", %{"exclude_visibilities" => ["direct"]})
|
||||
|
||||
assert [%{"id" => id}] = json_response(conn, 200)
|
||||
assert id == to_string(public_activity.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "followers" do
|
||||
|
|
@ -255,7 +269,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
test "getting followers, hide_followers", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{info: %{hide_followers: true}})
|
||||
other_user = insert(:user, hide_followers: true)
|
||||
{:ok, _user} = User.follow(user, other_user)
|
||||
|
||||
conn =
|
||||
|
|
@ -267,7 +281,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
test "getting followers, hide_followers, same user requesting", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{info: %{hide_followers: true}})
|
||||
other_user = insert(:user, hide_followers: true)
|
||||
{:ok, _user} = User.follow(user, other_user)
|
||||
|
||||
conn =
|
||||
|
|
@ -335,7 +349,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "getting following, hide_follows", %{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_follows: true}})
|
||||
user = insert(:user, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
{:ok, user} = User.follow(user, other_user)
|
||||
|
||||
|
|
@ -347,7 +361,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "getting following, hide_follows, same user requesting", %{conn: conn} do
|
||||
user = insert(:user, %{info: %{hide_follows: true}})
|
||||
user = insert(:user, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
{:ok, user} = User.follow(user, other_user)
|
||||
|
||||
|
|
@ -457,7 +471,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, follower)
|
||||
|> assign(:user, User.get_cached_by_id(follower.id))
|
||||
|> post("/api/v1/accounts/#{followed.id}/follow?reblogs=true")
|
||||
|
||||
assert %{"showing_reblogs" => true} = json_response(conn, 200)
|
||||
|
|
@ -669,7 +683,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
|
||||
assert token_from_db.user.info.confirmation_pending
|
||||
assert token_from_db.user.confirmation_pending
|
||||
end
|
||||
|
||||
test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
|
||||
|
|
@ -713,7 +727,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
|
||||
assert token_from_db.user.info.confirmation_pending
|
||||
assert token_from_db.user.confirmation_pending
|
||||
end
|
||||
|
||||
conn =
|
||||
|
|
@ -798,7 +812,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "verify_credentials default scope unlisted", %{conn: conn} do
|
||||
user = insert(:user, %{info: %User.Info{default_scope: "unlisted"}})
|
||||
user = insert(:user, default_scope: "unlisted")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -810,7 +824,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "locked accounts", %{conn: conn} do
|
||||
user = insert(:user, %{info: %User.Info{default_scope: "private"}})
|
||||
user = insert(:user, default_scope: "private")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 0
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 0
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(user_two.id).unread_conversation_count == 1
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
|
|
@ -54,9 +54,62 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
assert user_two.id in account_ids
|
||||
assert user_three.id in account_ids
|
||||
assert is_binary(res_id)
|
||||
assert unread == true
|
||||
assert unread == false
|
||||
assert res_last_status["id"] == direct.id
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
assert User.get_cached_by_id(user_one.id).unread_conversation_count == 0
|
||||
end
|
||||
|
||||
test "filters conversations by recipients", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
{:ok, direct1} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _direct2} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_three.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, direct3} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, _direct4} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "Hi @#{user_three.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, direct5} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "Hi @#{user_one.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
[conversation1, conversation2] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations", %{"recipients" => [user_two.id]})
|
||||
|> json_response(200)
|
||||
|
||||
assert conversation1["last_status"]["id"] == direct5.id
|
||||
assert conversation2["last_status"]["id"] == direct1.id
|
||||
|
||||
[conversation1] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations", %{"recipients" => [user_two.id, user_three.id]})
|
||||
|> json_response(200)
|
||||
|
||||
assert conversation1["last_status"]["id"] == direct3.id
|
||||
end
|
||||
|
||||
test "updates the last_status on reply", %{conn: conn} do
|
||||
|
|
@ -95,19 +148,23 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
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
|
||||
|
||||
[%{"id" => direct_conversation_id, "unread" => true}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> assign(:user, user_two)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
%{"unread" => false} =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> assign(:user, user_two)
|
||||
|> post("/api/v1/conversations/#{direct_conversation_id}/read")
|
||||
|> json_response(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 0
|
||||
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
|
||||
|
||||
# The conversation is marked as unread on reply
|
||||
{:ok, _} =
|
||||
|
|
@ -123,7 +180,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
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
|
||||
|
||||
# A reply doesn't increment the user's unread_conversation_count if the conversation is unread
|
||||
{:ok, _} =
|
||||
|
|
@ -133,7 +191,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
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
|
||||
end
|
||||
|
||||
test "(vanilla) Mastodon frontend behaviour", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -12,13 +12,11 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
|
||||
describe "locked accounts" do
|
||||
test "/api/v1/follow_requests works" do
|
||||
user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
user = insert(:user, locked: true)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
{:ok, other_user} = User.follow(other_user, user, "pending")
|
||||
|
||||
assert User.following?(other_user, user) == false
|
||||
|
||||
|
|
@ -32,10 +30,11 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
end
|
||||
|
||||
test "/api/v1/follow_requests/:id/authorize works" do
|
||||
user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
user = insert(:user, locked: true)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
{:ok, other_user} = User.follow(other_user, user, "pending")
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
|
@ -57,7 +56,7 @@ defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do
|
|||
end
|
||||
|
||||
test "/api/v1/follow_requests/:id/reject works" do
|
||||
user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
user = insert(:user, locked: true)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = ActivityPub.follow(other_user, user)
|
||||
|
|
|
|||
|
|
@ -41,20 +41,13 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
user = insert(:user, %{local: true})
|
||||
|
||||
user2 = insert(:user, %{local: true})
|
||||
{:ok, _user2} = User.deactivate(user2, !user2.info.deactivated)
|
||||
{:ok, _user2} = User.deactivate(user2, !user2.deactivated)
|
||||
|
||||
insert(:user, %{local: false, nickname: "u@peer1.com"})
|
||||
insert(:user, %{local: false, nickname: "u@peer2.com"})
|
||||
|
||||
{:ok, _} = Pleroma.Web.CommonAPI.post(user, %{"status" => "cofe"})
|
||||
|
||||
# Stats should count users with missing or nil `info.deactivated` value
|
||||
|
||||
{:ok, _user} =
|
||||
user.id
|
||||
|> User.get_cached_by_id()
|
||||
|> User.update_info(&Ecto.Changeset.change(&1, %{deactivated: nil}))
|
||||
|
||||
Pleroma.Stats.force_update()
|
||||
|
||||
conn = get(conn, "/api/v1/instance")
|
||||
|
|
|
|||
124
test/web/mastodon_api/controllers/marker_controller_test.exs
Normal file
124
test/web/mastodon_api/controllers/marker_controller_test.exs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
# 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.MarkerControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "GET /api/v1/markers" do
|
||||
test "gets markers with correct scopes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: ["read:statuses"])
|
||||
|
||||
{:ok, %{"notifications" => marker}} =
|
||||
Pleroma.Marker.upsert(
|
||||
user,
|
||||
%{"notifications" => %{"last_read_id" => "69420"}}
|
||||
)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> get("/api/v1/markers", %{timeline: ["notifications"]})
|
||||
|> json_response(200)
|
||||
|
||||
assert response == %{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69420",
|
||||
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
|
||||
"version" => 0
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "gets markers with missed scopes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: [])
|
||||
|
||||
Pleroma.Marker.upsert(user, %{"notifications" => %{"last_read_id" => "69420"}})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> get("/api/v1/markers", %{timeline: ["notifications"]})
|
||||
|> json_response(403)
|
||||
|
||||
assert response == %{"error" => "Insufficient permissions: read:statuses."}
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/v1/markers" do
|
||||
test "creates a marker with correct scopes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> post("/api/v1/markers", %{
|
||||
home: %{last_read_id: "777"},
|
||||
notifications: %{"last_read_id" => "69420"}
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69420",
|
||||
"updated_at" => _,
|
||||
"version" => 0
|
||||
}
|
||||
} = response
|
||||
end
|
||||
|
||||
test "updates exist marker", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: ["write:statuses"])
|
||||
|
||||
{:ok, %{"notifications" => marker}} =
|
||||
Pleroma.Marker.upsert(
|
||||
user,
|
||||
%{"notifications" => %{"last_read_id" => "69477"}}
|
||||
)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> post("/api/v1/markers", %{
|
||||
home: %{last_read_id: "777"},
|
||||
notifications: %{"last_read_id" => "69888"}
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert response == %{
|
||||
"notifications" => %{
|
||||
"last_read_id" => "69888",
|
||||
"updated_at" => NaiveDateTime.to_iso8601(marker.updated_at),
|
||||
"version" => 0
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
test "creates a marker with missed scopes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
token = insert(:oauth_token, user: user, scopes: [])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> post("/api/v1/markers", %{
|
||||
home: %{last_read_id: "777"},
|
||||
notifications: %{"last_read_id" => "69420"}
|
||||
})
|
||||
|> json_response(403)
|
||||
|
||||
assert response == %{"error" => "Insufficient permissions: write:statuses."}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -137,6 +137,57 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
||||
test "filters notifications using exclude_visibilities", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, public_activity} =
|
||||
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "public"})
|
||||
|
||||
{:ok, direct_activity} =
|
||||
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "direct"})
|
||||
|
||||
{:ok, unlisted_activity} =
|
||||
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "unlisted"})
|
||||
|
||||
{:ok, private_activity} =
|
||||
CommonAPI.post(other_user, %{"status" => "@#{user.nickname}", "visibility" => "private"})
|
||||
|
||||
conn = assign(conn, :user, user)
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "unlisted", "private"]
|
||||
})
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert id == direct_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "unlisted", "direct"]
|
||||
})
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert id == private_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["public", "private", "direct"]
|
||||
})
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert id == unlisted_activity.id
|
||||
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications", %{
|
||||
exclude_visibilities: ["unlisted", "private", "direct"]
|
||||
})
|
||||
|
||||
assert [%{"status" => %{"id" => id}}] = json_response(conn_res, 200)
|
||||
assert id == public_activity.id
|
||||
end
|
||||
|
||||
test "filters notifications using exclude_types", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
test "search", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu 天子"})
|
||||
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private"})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{
|
||||
|
|
@ -70,8 +70,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
get(conn, "/api/v2/search", %{"q" => "天子"})
|
||||
|> json_response(200)
|
||||
|
||||
[account] == results["accounts"]
|
||||
assert account["id"] == to_string(user_three.id)
|
||||
[status] = results["statuses"]
|
||||
assert status["id"] == to_string(activity.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -204,17 +204,17 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
|
|||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "true"})
|
||||
|> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "true"})
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
[account] = results["accounts"]
|
||||
assert account["acct"] == "shp@social.heldscal.la"
|
||||
assert account["acct"] == "mike@osada.macgirvin.com"
|
||||
end
|
||||
|
||||
test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> get("/api/v1/search", %{"q" => "shp@social.heldscal.la", "resolve" => "false"})
|
||||
|> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "false"})
|
||||
|
||||
assert results = json_response(conn, 200)
|
||||
assert [] == results["accounts"]
|
||||
|
|
|
|||
|
|
@ -12,12 +12,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
clear_config([:instance, :allow_relay])
|
||||
|
||||
describe "posting statuses" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -29,6 +33,34 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
[conn: conn]
|
||||
end
|
||||
|
||||
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
Pleroma.Config.get([:instance, :allow_relay], true)
|
||||
user = insert(:user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("api/v1/statuses", %{
|
||||
"content_type" => "text/plain",
|
||||
"source" => "Pleroma FE",
|
||||
"status" => "Hello world",
|
||||
"visibility" => "public"
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert response["reblogs_count"] == 0
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
response =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("api/v1/statuses/#{response["id"]}", %{})
|
||||
|> json_response(200)
|
||||
|
||||
assert response["reblogs_count"] == 0
|
||||
end
|
||||
|
||||
test "posting a status", %{conn: conn} do
|
||||
idempotency_key = "Pikachu rocks!"
|
||||
|
||||
|
|
@ -526,8 +558,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
test "when you're an admin or moderator", %{conn: conn} do
|
||||
activity1 = insert(:note_activity)
|
||||
activity2 = insert(:note_activity)
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
moderator = insert(:user, info: %{is_moderator: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
moderator = insert(:user, is_moderator: true)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus
|
||||
|
||||
clear_config([:instance, :public])
|
||||
|
||||
|
|
@ -20,27 +19,52 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "the home timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
following = insert(:user)
|
||||
describe "home" do
|
||||
test "the home timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
following = insert(:user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home")
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home")
|
||||
|
||||
assert Enum.empty?(json_response(conn, :ok))
|
||||
assert Enum.empty?(json_response(conn, :ok))
|
||||
|
||||
{:ok, user} = User.follow(user, following)
|
||||
{:ok, user} = User.follow(user, following)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home")
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home")
|
||||
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
test "the home timeline when the direct messages are excluded", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
{:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
|
||||
{:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
||||
{:ok, unlisted_activity} =
|
||||
CommonAPI.post(user, %{"status" => ".", "visibility" => "unlisted"})
|
||||
|
||||
{:ok, private_activity} =
|
||||
CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/timelines/home", %{"exclude_visibilities" => ["direct"]})
|
||||
|
||||
assert status_ids = json_response(conn, :ok) |> Enum.map(& &1["id"])
|
||||
assert public_activity.id in status_ids
|
||||
assert unlisted_activity.id in status_ids
|
||||
assert private_activity.id in status_ids
|
||||
refute direct_activity.id in status_ids
|
||||
end
|
||||
end
|
||||
|
||||
describe "public" do
|
||||
|
|
@ -50,8 +74,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
|
||||
{:ok, [_activity]} =
|
||||
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
|
||||
_activity = insert(:note_activity, local: false)
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/public", %{"local" => "False"})
|
||||
|
||||
|
|
@ -246,9 +269,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
|
||||
{:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
|
||||
|
||||
{:ok, [_activity]} =
|
||||
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
|
||||
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2hu")
|
||||
|
||||
assert [%{"id" => id}] = json_response(nconn, :ok)
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
import Pleroma.Factory
|
||||
|
||||
describe "follow/3" do
|
||||
test "returns error when user deactivated" do
|
||||
test "returns error when followed user is deactivated" do
|
||||
follower = insert(:user)
|
||||
user = insert(:user, local: true, info: %{deactivated: true})
|
||||
user = insert(:user, local: true, deactivated: true)
|
||||
{:error, error} = MastodonAPI.follow(follower, user)
|
||||
assert error == "Could not follow user: You are deactivated."
|
||||
assert error == "Could not follow user: #{user.nickname} is deactivated."
|
||||
end
|
||||
|
||||
test "following for user" do
|
||||
|
|
|
|||
|
|
@ -26,12 +26,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{
|
||||
note_count: 5,
|
||||
follower_count: 3,
|
||||
source_data: source_data,
|
||||
background: background_image
|
||||
},
|
||||
follower_count: 3,
|
||||
note_count: 5,
|
||||
source_data: source_data,
|
||||
background: background_image,
|
||||
nickname: "shp@shitposter.club",
|
||||
name: ":karjalanpiirakka: shp",
|
||||
bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
|
||||
|
|
@ -101,7 +99,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
"non_followers" => true
|
||||
}
|
||||
|
||||
privacy = user.info.default_scope
|
||||
privacy = user.default_scope
|
||||
|
||||
assert %{
|
||||
pleroma: %{notification_settings: ^notification_settings},
|
||||
|
|
@ -112,7 +110,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
test "Represent a Service(bot) account" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
|
||||
follower_count: 3,
|
||||
note_count: 5,
|
||||
source_data: %{"type" => "Service"},
|
||||
nickname: "shp@shitposter.club",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
})
|
||||
|
|
@ -164,8 +164,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "Represent a deactivated user for an admin" do
|
||||
admin = insert(:user, %{info: %{is_admin: true}})
|
||||
deactivated_user = insert(:user, %{info: %{deactivated: true}})
|
||||
admin = insert(:user, is_admin: true)
|
||||
deactivated_user = insert(:user, deactivated: true)
|
||||
represented = AccountView.render("show.json", %{user: deactivated_user, for: admin})
|
||||
assert represented[:pleroma][:deactivated] == true
|
||||
end
|
||||
|
|
@ -253,7 +253,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, %{info: %User.Info{locked: true}})
|
||||
other_user = insert(:user, locked: true)
|
||||
|
||||
{:ok, user, other_user, _} = CommonAPI.follow(user, other_user)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
|
@ -282,7 +282,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
test "represent an embedded relationship" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
|
||||
follower_count: 0,
|
||||
note_count: 5,
|
||||
source_data: %{"type" => "Service"},
|
||||
nickname: "shp@shitposter.club",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
})
|
||||
|
|
@ -352,7 +354,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
|
||||
user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
|
||||
user = insert(:user, pleroma_settings_store: %{fe: "test"})
|
||||
|
||||
result =
|
||||
AccountView.render("show.json", %{user: user, for: user, with_pleroma_settings: true})
|
||||
|
|
@ -374,14 +376,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
describe "hiding follows/following" do
|
||||
test "shows when follows/followers stats are hidden and sets follow/follower count to 0" do
|
||||
info = %{
|
||||
hide_followers: true,
|
||||
hide_followers_count: true,
|
||||
hide_follows: true,
|
||||
hide_follows_count: true
|
||||
}
|
||||
|
||||
user = insert(:user, info: info)
|
||||
user =
|
||||
insert(:user, %{
|
||||
hide_followers: true,
|
||||
hide_followers_count: true,
|
||||
hide_follows: true,
|
||||
hide_follows_count: true
|
||||
})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
|
|
@ -395,7 +396,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "shows when follows/followers are hidden" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
user = insert(:user, hide_followers: true, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
|
@ -408,7 +409,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "shows actual follower/following count to the account owner" do
|
||||
user = insert(:user, info: %{hide_followers: true, hide_follows: true})
|
||||
user = insert(:user, hide_followers: true, hide_follows: true)
|
||||
other_user = insert(:user)
|
||||
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
|
||||
{:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
|
||||
|
|
@ -424,8 +425,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "Hey @#{other_user.nickname}.",
|
||||
CommonAPI.post(other_user, %{
|
||||
"status" => "Hey @#{user.nickname}.",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
|
|
@ -456,7 +457,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "shows non-zero when follow requests are pending" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
user = insert(:user, locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
|
|
@ -468,7 +469,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "decreases when accepting a follow request" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
user = insert(:user, locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
|
|
@ -485,7 +486,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "decreases when rejecting a follow request" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
user = insert(:user, locked: true)
|
||||
|
||||
assert %{locked: true} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
|
|
@ -502,14 +503,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "shows non-zero when historical unapproved requests are present" do
|
||||
user = insert(:user, %{info: %{locked: true}})
|
||||
user = insert(:user, 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_info(user, &User.Info.user_upgrade(&1, %{locked: false}))
|
||||
{:ok, user} = User.update_and_set_cache(user, %{locked: false})
|
||||
|
||||
assert %{locked: false, follow_requests_count: 1} =
|
||||
AccountView.render("show.json", %{user: user, for: user})
|
||||
|
|
|
|||
|
|
@ -30,5 +30,6 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
|
|||
|
||||
assert [account] = conversation.accounts
|
||||
assert account.id == other_user.id
|
||||
assert conversation.last_status.pleroma.direct_conversation_id == participation.id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
27
test/web/mastodon_api/views/marker_view_test.exs
Normal file
27
test/web/mastodon_api/views/marker_view_test.exs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# 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.MarkerViewTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.MastodonAPI.MarkerView
|
||||
import Pleroma.Factory
|
||||
|
||||
test "returns markers" do
|
||||
marker1 = insert(:marker, timeline: "notifications", last_read_id: "17")
|
||||
marker2 = insert(:marker, timeline: "home", last_read_id: "42")
|
||||
|
||||
assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{
|
||||
"home" => %{
|
||||
last_read_id: "42",
|
||||
updated_at: NaiveDateTime.to_iso8601(marker2.updated_at),
|
||||
version: 0
|
||||
},
|
||||
"notifications" => %{
|
||||
last_read_id: "17",
|
||||
updated_at: NaiveDateTime.to_iso8601(marker1.updated_at),
|
||||
version: 0
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
@ -7,6 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Bookmark
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.HTML
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
|
|
@ -14,7 +16,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
alias Pleroma.Web.OStatus
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
|
|
@ -23,10 +24,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "returns the direct conversation id when given the `with_conversation_id` option" do
|
||||
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
[participation] = Participation.for_user(user)
|
||||
|
||||
status =
|
||||
StatusView.render("show.json",
|
||||
|
|
@ -35,7 +37,26 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
for: user
|
||||
)
|
||||
|
||||
assert status[:pleroma][:direct_conversation_id]
|
||||
assert status[:pleroma][:direct_conversation_id] == participation.id
|
||||
|
||||
status = StatusView.render("show.json", activity: activity, for: user)
|
||||
assert status[:pleroma][:direct_conversation_id] == nil
|
||||
end
|
||||
|
||||
test "returns the direct conversation id when given the `direct_conversation_id` option" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
|
||||
[participation] = Participation.for_user(user)
|
||||
|
||||
status =
|
||||
StatusView.render("show.json",
|
||||
activity: activity,
|
||||
direct_conversation_id: participation.id,
|
||||
for: user
|
||||
)
|
||||
|
||||
assert status[:pleroma][:direct_conversation_id] == participation.id
|
||||
end
|
||||
|
||||
test "returns a temporary ap_id based user for activities missing db users" do
|
||||
|
|
@ -108,7 +129,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
in_reply_to_account_id: nil,
|
||||
card: nil,
|
||||
reblog: nil,
|
||||
content: HtmlSanitizeEx.basic_html(object_data["content"]),
|
||||
content: HTML.filter_tags(object_data["content"]),
|
||||
created_at: created_at,
|
||||
reblogs_count: 0,
|
||||
replies_count: 0,
|
||||
|
|
@ -120,7 +141,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
pinned: false,
|
||||
sensitive: false,
|
||||
poll: nil,
|
||||
spoiler_text: HtmlSanitizeEx.basic_html(object_data["summary"]),
|
||||
spoiler_text: HTML.filter_tags(object_data["summary"]),
|
||||
visibility: "public",
|
||||
media_attachments: [],
|
||||
mentions: [],
|
||||
|
|
@ -147,8 +168,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
local: true,
|
||||
conversation_id: convo_id,
|
||||
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"])},
|
||||
content: %{"text/plain" => HTML.strip_tags(object_data["content"])},
|
||||
spoiler_text: %{"text/plain" => HTML.strip_tags(object_data["summary"])},
|
||||
expires_at: nil,
|
||||
direct_conversation_id: nil,
|
||||
thread_muted: false
|
||||
|
|
@ -230,17 +251,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
end
|
||||
|
||||
test "contains mentions" do
|
||||
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
||||
# a user with this ap id might be in the cache.
|
||||
recipient = "https://pleroma.soykaf.com/users/lain"
|
||||
user = insert(:user, %{ap_id: recipient})
|
||||
user = insert(:user)
|
||||
mentioned = insert(:user)
|
||||
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hi @#{mentioned.nickname}"})
|
||||
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
assert status.mentions ==
|
||||
Enum.map([user], fn u -> AccountView.render("mention.json", %{user: u}) end)
|
||||
Enum.map([mentioned], fn u -> AccountView.render("mention.json", %{user: u}) end)
|
||||
end
|
||||
|
||||
test "create mentions from the 'to' field" do
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
end
|
||||
|
||||
test "nodeinfo shows staff accounts", %{conn: conn} do
|
||||
moderator = insert(:user, %{local: true, info: %{is_moderator: true}})
|
||||
admin = insert(:user, %{local: true, info: %{is_admin: true}})
|
||||
moderator = insert(:user, local: true, is_moderator: true)
|
||||
admin = insert(:user, local: true, is_admin: true)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -780,8 +780,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
|
||||
{:ok, user} =
|
||||
insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|> User.confirmation_changeset(need_confirmation: true)
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
refute Pleroma.User.auth_active?(user)
|
||||
|
||||
|
|
@ -808,7 +808,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
user =
|
||||
insert(:user,
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
|
||||
info: %{deactivated: true}
|
||||
deactivated: true
|
||||
)
|
||||
|
||||
app = insert(:oauth_app)
|
||||
|
|
@ -834,7 +834,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
user =
|
||||
insert(:user,
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt(password),
|
||||
info: %{password_reset_pending: true}
|
||||
password_reset_pending: true
|
||||
)
|
||||
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
|
|
|||
|
|
@ -1,300 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.OStatus.ActivityRepresenter
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "an external note activity" do
|
||||
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(activity, user)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
assert String.contains?(
|
||||
res,
|
||||
~s{<link type="text/html" href="https://mastodon.social/users/lambadalambda/updates/2314748" rel="alternate"/>}
|
||||
)
|
||||
end
|
||||
|
||||
test "a note activity" do
|
||||
note_activity = insert(:note_activity)
|
||||
object_data = Object.normalize(note_activity).data
|
||||
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
expected = """
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<id>#{object_data["id"]}</id>
|
||||
<title>New note by #{user.nickname}</title>
|
||||
<content type="html">#{object_data["content"]}</content>
|
||||
<published>#{object_data["published"]}</published>
|
||||
<updated>#{object_data["published"]}</updated>
|
||||
<ostatus:conversation ref="#{note_activity.data["context"]}">#{note_activity.data["context"]}</ostatus:conversation>
|
||||
<link ref="#{note_activity.data["context"]}" rel="ostatus:conversation" />
|
||||
<summary>#{object_data["summary"]}</summary>
|
||||
<link type="application/atom+xml" href="#{object_data["id"]}" rel="self" />
|
||||
<link type="text/html" href="#{object_data["id"]}" rel="alternate" />
|
||||
<category term="2hu"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<link name="2hu" rel="emoji" href="corndog.png" />
|
||||
"""
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(note_activity, user)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
test "a reply note" do
|
||||
user = insert(:user)
|
||||
note_object = insert(:note)
|
||||
_note = insert(:note_activity, %{note: note_object})
|
||||
object = insert(:note, %{data: %{"inReplyTo" => note_object.data["id"]}})
|
||||
answer = insert(:note_activity, %{note: object})
|
||||
|
||||
Repo.update!(
|
||||
Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
|
||||
)
|
||||
|
||||
expected = """
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<id>#{object.data["id"]}</id>
|
||||
<title>New note by #{user.nickname}</title>
|
||||
<content type="html">#{object.data["content"]}</content>
|
||||
<published>#{object.data["published"]}</published>
|
||||
<updated>#{object.data["published"]}</updated>
|
||||
<ostatus:conversation ref="#{answer.data["context"]}">#{answer.data["context"]}</ostatus:conversation>
|
||||
<link ref="#{answer.data["context"]}" rel="ostatus:conversation" />
|
||||
<summary>2hu</summary>
|
||||
<link type="application/atom+xml" href="#{object.data["id"]}" rel="self" />
|
||||
<link type="text/html" href="#{object.data["id"]}" rel="alternate" />
|
||||
<category term="2hu"/>
|
||||
<thr:in-reply-to ref="#{note_object.data["id"]}" href="someurl" />
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
<link name="2hu" rel="emoji" href="corndog.png" />
|
||||
"""
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(answer, user)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
test "an announce activity" do
|
||||
note = insert(:note_activity)
|
||||
user = insert(:user)
|
||||
object = Object.normalize(note)
|
||||
|
||||
{:ok, announce, _object} = ActivityPub.announce(user, object)
|
||||
|
||||
announce = Activity.get_by_id(announce.id)
|
||||
|
||||
note_user = User.get_cached_by_ap_id(note.data["actor"])
|
||||
note = Activity.get_by_id(note.id)
|
||||
|
||||
note_xml =
|
||||
ActivityRepresenter.to_simple_form(note, note_user, true)
|
||||
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||
|> to_string
|
||||
|
||||
expected = """
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
|
||||
<id>#{announce.data["id"]}</id>
|
||||
<title>#{user.nickname} repeated a notice</title>
|
||||
<content type="html">RT #{object.data["content"]}</content>
|
||||
<published>#{announce.data["published"]}</published>
|
||||
<updated>#{announce.data["published"]}</updated>
|
||||
<ostatus:conversation ref="#{announce.data["context"]}">#{announce.data["context"]}</ostatus:conversation>
|
||||
<link ref="#{announce.data["context"]}" rel="ostatus:conversation" />
|
||||
<link rel="self" type="application/atom+xml" href="#{announce.data["id"]}"/>
|
||||
<activity:object>
|
||||
#{note_xml}
|
||||
</activity:object>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
|
||||
note.data["actor"]
|
||||
}"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
"""
|
||||
|
||||
announce_xml =
|
||||
ActivityRepresenter.to_simple_form(announce, user)
|
||||
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||
|> to_string
|
||||
|
||||
assert clean(expected) == clean(announce_xml)
|
||||
end
|
||||
|
||||
test "a like activity" do
|
||||
note = insert(:note)
|
||||
user = insert(:user)
|
||||
{:ok, like, _note} = ActivityPub.like(user, note)
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(like, user)
|
||||
refute is_nil(tuple)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
expected = """
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/favorite</activity:verb>
|
||||
<id>#{like.data["id"]}</id>
|
||||
<title>New favorite by #{user.nickname}</title>
|
||||
<content type="html">#{user.nickname} favorited something</content>
|
||||
<published>#{like.data["published"]}</published>
|
||||
<updated>#{like.data["published"]}</updated>
|
||||
<activity:object>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
|
||||
<id>#{note.data["id"]}</id>
|
||||
</activity:object>
|
||||
<ostatus:conversation ref="#{like.data["context"]}">#{like.data["context"]}</ostatus:conversation>
|
||||
<link ref="#{like.data["context"]}" rel="ostatus:conversation" />
|
||||
<link rel="self" type="application/atom+xml" href="#{like.data["id"]}"/>
|
||||
<thr:in-reply-to ref="#{note.data["id"]}" />
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
|
||||
note.data["actor"]
|
||||
}"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
|
||||
"""
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
test "a follow activity" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
ActivityPub.insert(%{
|
||||
"type" => "Follow",
|
||||
"actor" => follower.ap_id,
|
||||
"object" => followed.ap_id,
|
||||
"to" => [followed.ap_id]
|
||||
})
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(activity, follower)
|
||||
|
||||
refute is_nil(tuple)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
expected = """
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/follow</activity:verb>
|
||||
<id>#{activity.data["id"]}</id>
|
||||
<title>#{follower.nickname} started following #{activity.data["object"]}</title>
|
||||
<content type="html"> #{follower.nickname} started following #{activity.data["object"]}</content>
|
||||
<published>#{activity.data["published"]}</published>
|
||||
<updated>#{activity.data["published"]}</updated>
|
||||
<activity:object>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<id>#{activity.data["object"]}</id>
|
||||
<uri>#{activity.data["object"]}</uri>
|
||||
</activity:object>
|
||||
<link rel="self" type="application/atom+xml" href="#{activity.data["id"]}"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
|
||||
activity.data["object"]
|
||||
}"/>
|
||||
"""
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
test "an unfollow activity" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
{:ok, _activity} = ActivityPub.follow(follower, followed)
|
||||
{:ok, activity} = ActivityPub.unfollow(follower, followed)
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(activity, follower)
|
||||
|
||||
refute is_nil(tuple)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
expected = """
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/unfollow</activity:verb>
|
||||
<id>#{activity.data["id"]}</id>
|
||||
<title>#{follower.nickname} stopped following #{followed.ap_id}</title>
|
||||
<content type="html"> #{follower.nickname} stopped following #{followed.ap_id}</content>
|
||||
<published>#{activity.data["published"]}</published>
|
||||
<updated>#{activity.data["published"]}</updated>
|
||||
<activity:object>
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
|
||||
<id>#{followed.ap_id}</id>
|
||||
<uri>#{followed.ap_id}</uri>
|
||||
</activity:object>
|
||||
<link rel="self" type="application/atom+xml" href="#{activity.data["id"]}"/>
|
||||
<link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/person" href="#{
|
||||
followed.ap_id
|
||||
}"/>
|
||||
"""
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
test "a delete" do
|
||||
user = insert(:user)
|
||||
|
||||
activity = %Activity{
|
||||
data: %{
|
||||
"id" => "ap_id",
|
||||
"type" => "Delete",
|
||||
"actor" => user.ap_id,
|
||||
"object" => "some_id",
|
||||
"published" => "2017-06-18T12:00:18+00:00"
|
||||
}
|
||||
}
|
||||
|
||||
tuple = ActivityRepresenter.to_simple_form(activity, nil)
|
||||
|
||||
refute is_nil(tuple)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> IO.iodata_to_binary()
|
||||
|
||||
expected = """
|
||||
<activity:object-type>http://activitystrea.ms/schema/1.0/activity</activity:object-type>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/delete</activity:verb>
|
||||
<id>#{activity.data["object"]}</id>
|
||||
<title>An object was deleted</title>
|
||||
<content type="html">An object was deleted</content>
|
||||
<published>#{activity.data["published"]}</published>
|
||||
<updated>#{activity.data["published"]}</updated>
|
||||
"""
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
test "an unknown activity" do
|
||||
tuple = ActivityRepresenter.to_simple_form(%Activity{}, nil)
|
||||
assert is_nil(tuple)
|
||||
end
|
||||
|
||||
defp clean(string) do
|
||||
String.replace(string, ~r/\s/, "")
|
||||
end
|
||||
end
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.FeedRepresenterTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.OStatus.ActivityRepresenter
|
||||
alias Pleroma.Web.OStatus.FeedRepresenter
|
||||
alias Pleroma.Web.OStatus.UserRepresenter
|
||||
|
||||
test "returns a feed of the last 20 items of the user" do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
tuple = FeedRepresenter.to_simple_form(user, [note_activity], [user])
|
||||
|
||||
most_recent_update =
|
||||
note_activity.updated_at
|
||||
|> NaiveDateTime.to_iso8601()
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
|
||||
|
||||
user_xml =
|
||||
UserRepresenter.to_simple_form(user)
|
||||
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||
|
||||
entry_xml =
|
||||
ActivityRepresenter.to_simple_form(note_activity, user)
|
||||
|> :xmerl.export_simple_content(:xmerl_xml)
|
||||
|
||||
expected = """
|
||||
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:activity="http://activitystrea.ms/spec/1.0/" xmlns:poco="http://portablecontacts.net/spec/1.0" xmlns:ostatus="http://ostatus.org/schema/1.0">
|
||||
<id>#{OStatus.feed_path(user)}</id>
|
||||
<title>#{user.nickname}'s timeline</title>
|
||||
<updated>#{most_recent_update}</updated>
|
||||
<logo>#{User.avatar_url(user)}</logo>
|
||||
<link rel="hub" href="#{OStatus.pubsub_path(user)}" />
|
||||
<link rel="salmon" href="#{OStatus.salmon_path(user)}" />
|
||||
<link rel="self" href="#{OStatus.feed_path(user)}" type="application/atom+xml" />
|
||||
<author>
|
||||
#{user_xml}
|
||||
</author>
|
||||
<link rel="next" href="#{OStatus.feed_path(user)}?max_id=#{note_activity.id}" type="application/atom+xml" />
|
||||
<entry>
|
||||
#{entry_xml}
|
||||
</entry>
|
||||
</feed>
|
||||
"""
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
defp clean(string) do
|
||||
String.replace(string, ~r/\s/, "")
|
||||
end
|
||||
end
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.DeleteHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.OStatus
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "deletions" do
|
||||
test "it removes the mentioned activity" do
|
||||
note = insert(:note_activity)
|
||||
second_note = insert(:note_activity)
|
||||
object = Object.normalize(note)
|
||||
second_object = Object.normalize(second_note)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like, _object} = Pleroma.Web.ActivityPub.ActivityPub.like(user, object)
|
||||
|
||||
incoming =
|
||||
File.read!("test/fixtures/delete.xml")
|
||||
|> String.replace(
|
||||
"tag:mastodon.sdf.org,2017-06-10:objectId=310513:objectType=Status",
|
||||
object.data["id"]
|
||||
)
|
||||
|
||||
{:ok, [delete]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
refute Activity.get_by_id(note.id)
|
||||
refute Activity.get_by_id(like.id)
|
||||
assert Object.get_by_ap_id(object.data["id"]).data["type"] == "Tombstone"
|
||||
assert Activity.get_by_id(second_note.id)
|
||||
assert Object.get_by_ap_id(second_object.data["id"])
|
||||
|
||||
assert delete.data["type"] == "Delete"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -5,13 +5,11 @@
|
|||
defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.OStatus.ActivityRepresenter
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -22,78 +20,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
describe "salmon_incoming" do
|
||||
test "decodes a salmon", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
salmon = File.read!("test/fixtures/salmon.xml")
|
||||
|
||||
assert capture_log(fn ->
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/users/#{user.nickname}/salmon", salmon)
|
||||
|
||||
assert response(conn, 200)
|
||||
end) =~ "[error]"
|
||||
end
|
||||
|
||||
test "decodes a salmon with a changed magic key", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
salmon = File.read!("test/fixtures/salmon.xml")
|
||||
|
||||
assert capture_log(fn ->
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/users/#{user.nickname}/salmon", salmon)
|
||||
|
||||
assert response(conn, 200)
|
||||
end) =~ "[error]"
|
||||
|
||||
# Wrong key
|
||||
info = %{
|
||||
magic_key:
|
||||
"RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
}
|
||||
|
||||
# Set a wrong magic-key for a user so it has to refetch
|
||||
"http://gs.example.org:4040/index.php/user/1"
|
||||
|> User.get_cached_by_ap_id()
|
||||
|> User.update_info(&User.Info.remote_user_creation(&1, info))
|
||||
|
||||
assert capture_log(fn ->
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/users/#{user.nickname}/salmon", salmon)
|
||||
|
||||
assert response(conn, 200)
|
||||
end) =~ "[error]"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET object/2" do
|
||||
test "gets an object", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
url = "/objects/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get(url)
|
||||
|
||||
expected =
|
||||
ActivityRepresenter.to_simple_form(note_activity, user, true)
|
||||
|> ActivityRepresenter.wrap_with_entry()
|
||||
|> :xmerl.export_simple(:xmerl_xml)
|
||||
|> to_string
|
||||
|
||||
assert response(conn, 200) == expected
|
||||
end
|
||||
|
||||
test "redirects to /notice/id for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
|
|
@ -143,16 +70,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
end
|
||||
|
||||
describe "GET activity/2" do
|
||||
test "gets an activity in xml format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/activities/#{uuid}")
|
||||
|> response(200)
|
||||
end
|
||||
|
||||
test "redirects to /notice/id for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
|
@ -180,24 +97,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 500) == ~S({"error":"Something went wrong"})
|
||||
end
|
||||
|
||||
test "404s on deleted objects", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(200)
|
||||
|
||||
Object.delete(object)
|
||||
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/objects/#{uuid}")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on private activities", %{conn: conn} do
|
||||
note_activity = insert(:direct_note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
|
|
|||
|
|
@ -1,645 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatusTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.OStatus
|
||||
alias Pleroma.Web.XML
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "don't insert create notes twice" do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
assert {:ok, [activity]} == OStatus.handle_incoming(incoming)
|
||||
end
|
||||
|
||||
test "handle incoming note - GS, Salmon" do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
assert user.info.note_count == 1
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
|
||||
assert object.data["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
|
||||
|
||||
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
|
||||
assert object.data["published"] == "2017-04-23T14:51:03+00:00"
|
||||
|
||||
assert activity.data["context"] ==
|
||||
"tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
|
||||
|
||||
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
|
||||
assert object.data["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
|
||||
assert activity.local == false
|
||||
end
|
||||
|
||||
test "handle incoming notes - GS, subscription" do
|
||||
incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
assert object.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert object.data["content"] == "Will it blend?"
|
||||
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
assert User.ap_followers(user) in activity.data["to"]
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
test "handle incoming notes with attachments - GS, subscription" do
|
||||
incoming = File.read!("test/fixtures/incoming_websub_gnusocial_attachments.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
assert object.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert object.data["attachment"] |> length == 2
|
||||
assert object.data["external_url"] == "https://social.heldscal.la/notice/2020923"
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
test "handle incoming notes with tags" do
|
||||
incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["tag"] == ["nsfw"]
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
test "handle incoming notes - Mastodon, salmon, reply" do
|
||||
# It uses the context of the replied to object
|
||||
Repo.insert!(%Object{
|
||||
data: %{
|
||||
"id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
|
||||
"context" => "2hu"
|
||||
}
|
||||
})
|
||||
|
||||
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
||||
assert activity.data["context"] == "2hu"
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
test "handle incoming notes - Mastodon, with CW" do
|
||||
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
||||
assert object.data["summary"] == "technologic"
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
test "handle incoming unlisted messages, put public into cc" do
|
||||
incoming = File.read!("test/fixtures/mastodon-note-unlisted.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
|
||||
refute "https://www.w3.org/ns/activitystreams#Public" in object.data["to"]
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in object.data["cc"]
|
||||
end
|
||||
|
||||
test "handle incoming retweets - Mastodon, with CW" do
|
||||
incoming = File.read!("test/fixtures/cw_retweet.xml")
|
||||
{:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||
retweeted_object = Object.normalize(retweeted_activity)
|
||||
|
||||
assert retweeted_object.data["summary"] == "Hey."
|
||||
end
|
||||
|
||||
test "handle incoming notes - GS, subscription, reply" do
|
||||
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
assert object.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
|
||||
assert object.data["content"] ==
|
||||
"@<a href=\"https://gs.archae.me/user/4687\" class=\"h-card u-url p-nickname mention\" title=\"shpbot\">shpbot</a> why not indeed."
|
||||
|
||||
assert object.data["inReplyTo"] ==
|
||||
"tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
|
||||
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
end
|
||||
|
||||
test "handle incoming retweets - GS, subscription" do
|
||||
incoming = File.read!("test/fixtures/share-gs.xml")
|
||||
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == retweeted_activity.data["object"]
|
||||
assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"]
|
||||
refute activity.local
|
||||
|
||||
retweeted_activity = Activity.get_by_id(retweeted_activity.id)
|
||||
retweeted_object = Object.normalize(retweeted_activity)
|
||||
assert retweeted_activity.data["type"] == "Create"
|
||||
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
|
||||
refute retweeted_activity.local
|
||||
assert retweeted_object.data["announcement_count"] == 1
|
||||
assert String.contains?(retweeted_object.data["content"], "mastodon")
|
||||
refute String.contains?(retweeted_object.data["content"], "Test account")
|
||||
end
|
||||
|
||||
test "handle incoming retweets - GS, subscription - local message" do
|
||||
incoming = File.read!("test/fixtures/share-gs-local.xml")
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
incoming =
|
||||
incoming
|
||||
|> String.replace("LOCAL_ID", object.data["id"])
|
||||
|> String.replace("LOCAL_USER", user.ap_id)
|
||||
|
||||
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == object.data["id"]
|
||||
assert user.ap_id in activity.data["to"]
|
||||
refute activity.local
|
||||
|
||||
retweeted_activity = Activity.get_by_id(retweeted_activity.id)
|
||||
assert note_activity.id == retweeted_activity.id
|
||||
assert retweeted_activity.data["type"] == "Create"
|
||||
assert retweeted_activity.data["actor"] == user.ap_id
|
||||
assert retweeted_activity.local
|
||||
assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
|
||||
end
|
||||
|
||||
test "handle incoming retweets - Mastodon, salmon" do
|
||||
incoming = File.read!("test/fixtures/share.xml")
|
||||
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
||||
retweeted_object = Object.normalize(retweeted_activity)
|
||||
|
||||
assert activity.data["type"] == "Announce"
|
||||
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
||||
assert activity.data["object"] == retweeted_activity.data["object"]
|
||||
|
||||
assert activity.data["id"] ==
|
||||
"tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
|
||||
|
||||
refute activity.local
|
||||
assert retweeted_activity.data["type"] == "Create"
|
||||
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
|
||||
refute retweeted_activity.local
|
||||
refute String.contains?(retweeted_object.data["content"], "Test account")
|
||||
end
|
||||
|
||||
test "handle incoming favorites - GS, websub" do
|
||||
capture_log(fn ->
|
||||
incoming = File.read!("test/fixtures/favorite.xml")
|
||||
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Like"
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == favorited_activity.data["object"]
|
||||
|
||||
assert activity.data["id"] ==
|
||||
"tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
|
||||
|
||||
refute activity.local
|
||||
assert favorited_activity.data["type"] == "Create"
|
||||
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
|
||||
|
||||
assert favorited_activity.data["object"] ==
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
|
||||
refute favorited_activity.local
|
||||
end)
|
||||
end
|
||||
|
||||
test "handle conversation references" do
|
||||
incoming = File.read!("test/fixtures/mastodon_conversation.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["context"] ==
|
||||
"tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
|
||||
end
|
||||
|
||||
test "handle incoming favorites with locally available object - GS, websub" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
incoming =
|
||||
File.read!("test/fixtures/favorite_with_local_note.xml")
|
||||
|> String.replace("localid", object.data["id"])
|
||||
|
||||
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Like"
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == object.data["id"]
|
||||
refute activity.local
|
||||
assert note_activity.id == favorited_activity.id
|
||||
assert favorited_activity.local
|
||||
end
|
||||
|
||||
test_with_mock "handle incoming replies, fetching replied-to activities if we don't have them",
|
||||
OStatus,
|
||||
[:passthrough],
|
||||
[] do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity, false)
|
||||
|
||||
assert activity.data["type"] == "Create"
|
||||
assert object.data["type"] == "Note"
|
||||
|
||||
assert object.data["inReplyTo"] ==
|
||||
"http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
|
||||
|
||||
assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
|
||||
|
||||
assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
|
||||
|
||||
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
||||
|
||||
assert called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
|
||||
end
|
||||
|
||||
test_with_mock "handle incoming replies, not fetching replied-to activities beyond max_replies_depth",
|
||||
OStatus,
|
||||
[:passthrough],
|
||||
[] do
|
||||
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
allowed_incoming_reply_depth?: fn _ -> false end do
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
object = Object.normalize(activity, false)
|
||||
|
||||
refute called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
|
||||
end
|
||||
end
|
||||
|
||||
test "handle incoming follows" do
|
||||
incoming = File.read!("test/fixtures/follow.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
assert activity.data["type"] == "Follow"
|
||||
|
||||
assert activity.data["id"] ==
|
||||
"tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
|
||||
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
|
||||
refute activity.local
|
||||
|
||||
follower = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
followed = User.get_cached_by_ap_id(activity.data["object"])
|
||||
|
||||
assert User.following?(follower, followed)
|
||||
end
|
||||
|
||||
test "refuse following over OStatus if the followed's account is locked" do
|
||||
incoming = File.read!("test/fixtures/follow.xml")
|
||||
_user = insert(:user, info: %{locked: true}, ap_id: "https://pawoo.net/users/pekorino")
|
||||
|
||||
{:ok, [{:error, "It's not possible to follow locked accounts over OStatus"}]} =
|
||||
OStatus.handle_incoming(incoming)
|
||||
end
|
||||
|
||||
test "handle incoming unfollows with existing follow" do
|
||||
incoming_follow = File.read!("test/fixtures/follow.xml")
|
||||
{:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)
|
||||
|
||||
incoming = File.read!("test/fixtures/unfollow.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["type"] == "Undo"
|
||||
|
||||
assert activity.data["id"] ==
|
||||
"undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
|
||||
|
||||
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
||||
embedded_object = activity.data["object"]
|
||||
assert is_map(embedded_object)
|
||||
assert embedded_object["type"] == "Follow"
|
||||
assert embedded_object["object"] == "https://pawoo.net/users/pekorino"
|
||||
refute activity.local
|
||||
|
||||
follower = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
followed = User.get_cached_by_ap_id(embedded_object["object"])
|
||||
|
||||
refute User.following?(follower, followed)
|
||||
end
|
||||
|
||||
test "it clears `unreachable` federation status of the sender" do
|
||||
incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml")
|
||||
doc = XML.parse_document(incoming_reaction_xml)
|
||||
actor_uri = XML.string_from_xpath("//author/uri[1]", doc)
|
||||
reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc)
|
||||
|
||||
Instances.set_consistently_unreachable(actor_uri)
|
||||
Instances.set_consistently_unreachable(reacted_to_author_uri)
|
||||
refute Instances.reachable?(actor_uri)
|
||||
refute Instances.reachable?(reacted_to_author_uri)
|
||||
|
||||
{:ok, _} = OStatus.handle_incoming(incoming_reaction_xml)
|
||||
assert Instances.reachable?(actor_uri)
|
||||
refute Instances.reachable?(reacted_to_author_uri)
|
||||
end
|
||||
|
||||
describe "new remote user creation" do
|
||||
test "returns local users" do
|
||||
local_user = insert(:user)
|
||||
{:ok, user} = OStatus.find_or_make_user(local_user.ap_id)
|
||||
|
||||
assert user == local_user
|
||||
end
|
||||
|
||||
test "tries to use the information in poco fields" do
|
||||
uri = "https://social.heldscal.la/user/23211"
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(uri)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert user.name == "Constance Variable"
|
||||
assert user.nickname == "lambadalambda@social.heldscal.la"
|
||||
assert user.local == false
|
||||
assert user.info.uri == uri
|
||||
assert user.ap_id == uri
|
||||
assert user.bio == "Call me Deacon Blues."
|
||||
assert user.avatar["type"] == "Image"
|
||||
|
||||
{:ok, user_again} = OStatus.find_or_make_user(uri)
|
||||
|
||||
assert user == user_again
|
||||
end
|
||||
|
||||
test "find_or_make_user sets all the nessary input fields" do
|
||||
uri = "https://social.heldscal.la/user/23211"
|
||||
{:ok, user} = OStatus.find_or_make_user(uri)
|
||||
|
||||
assert user.info ==
|
||||
%User.Info{
|
||||
id: user.info.id,
|
||||
ap_enabled: false,
|
||||
background: %{},
|
||||
banner: %{},
|
||||
blocks: [],
|
||||
deactivated: false,
|
||||
default_scope: "public",
|
||||
domain_blocks: [],
|
||||
follower_count: 0,
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
keys: nil,
|
||||
locked: false,
|
||||
no_rich_text: false,
|
||||
note_count: 0,
|
||||
settings: nil,
|
||||
source_data: %{},
|
||||
hub: "https://social.heldscal.la/main/push/hub",
|
||||
magic_key:
|
||||
"RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB",
|
||||
salmon: "https://social.heldscal.la/main/salmon/user/23211",
|
||||
topic: "https://social.heldscal.la/api/statuses/user_timeline/23211.atom",
|
||||
uri: "https://social.heldscal.la/user/23211"
|
||||
}
|
||||
end
|
||||
|
||||
test "find_make_or_update_actor takes an author element and returns an updated user" do
|
||||
uri = "https://social.heldscal.la/user/23211"
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(uri)
|
||||
old_name = user.name
|
||||
old_bio = user.bio
|
||||
change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, name: nil})
|
||||
|
||||
{:ok, user} = Repo.update(change)
|
||||
refute user.avatar
|
||||
|
||||
doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
|
||||
[author] = :xmerl_xpath.string('//author[1]', doc)
|
||||
{:ok, user} = OStatus.find_make_or_update_actor(author)
|
||||
assert user.avatar["type"] == "Image"
|
||||
assert user.name == old_name
|
||||
assert user.bio == old_bio
|
||||
|
||||
{:ok, user_again} = OStatus.find_make_or_update_actor(author)
|
||||
assert user_again == user
|
||||
end
|
||||
|
||||
test "find_or_make_user disallows protocol downgrade" do
|
||||
user = insert(:user, %{local: true})
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
ap_id: "https://social.heldscal.la/user/23211",
|
||||
info: %{ap_enabled: true},
|
||||
local: false
|
||||
})
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
assert User.ap_enabled?(user)
|
||||
end
|
||||
|
||||
test "find_make_or_update_actor disallows protocol downgrade" do
|
||||
user = insert(:user, %{local: true})
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
user =
|
||||
insert(:user, %{
|
||||
ap_id: "https://social.heldscal.la/user/23211",
|
||||
info: %{ap_enabled: true},
|
||||
local: false
|
||||
})
|
||||
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
{:ok, user} = OStatus.find_or_make_user(user.ap_id)
|
||||
assert User.ap_enabled?(user)
|
||||
|
||||
doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
|
||||
[author] = :xmerl_xpath.string('//author[1]', doc)
|
||||
{:error, :invalid_protocol} = OStatus.find_make_or_update_actor(author)
|
||||
end
|
||||
end
|
||||
|
||||
describe "gathering user info from a user id" do
|
||||
test "it returns user info in a hash" do
|
||||
user = "shp@social.heldscal.la"
|
||||
|
||||
# TODO: make test local
|
||||
{:ok, data} = OStatus.gather_user_info(user)
|
||||
|
||||
expected = %{
|
||||
"hub" => "https://social.heldscal.la/main/push/hub",
|
||||
"magic_key" =>
|
||||
"RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
|
||||
"name" => "shp",
|
||||
"nickname" => "shp",
|
||||
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
|
||||
"subject" => "acct:shp@social.heldscal.la",
|
||||
"topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
|
||||
"uri" => "https://social.heldscal.la/user/29191",
|
||||
"host" => "social.heldscal.la",
|
||||
"fqn" => user,
|
||||
"bio" => "cofe",
|
||||
"avatar" => %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
|
||||
"mediaType" => "image/jpeg",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
},
|
||||
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
|
||||
"ap_id" => nil
|
||||
}
|
||||
|
||||
assert data == expected
|
||||
end
|
||||
|
||||
test "it works with the uri" do
|
||||
user = "https://social.heldscal.la/user/29191"
|
||||
|
||||
# TODO: make test local
|
||||
{:ok, data} = OStatus.gather_user_info(user)
|
||||
|
||||
expected = %{
|
||||
"hub" => "https://social.heldscal.la/main/push/hub",
|
||||
"magic_key" =>
|
||||
"RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
|
||||
"name" => "shp",
|
||||
"nickname" => "shp",
|
||||
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
|
||||
"subject" => "https://social.heldscal.la/user/29191",
|
||||
"topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
|
||||
"uri" => "https://social.heldscal.la/user/29191",
|
||||
"host" => "social.heldscal.la",
|
||||
"fqn" => user,
|
||||
"bio" => "cofe",
|
||||
"avatar" => %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
|
||||
"mediaType" => "image/jpeg",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
},
|
||||
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
|
||||
"ap_id" => nil
|
||||
}
|
||||
|
||||
assert data == expected
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching a status by it's HTML url" do
|
||||
test "it builds a missing status from an html url" do
|
||||
capture_log(fn ->
|
||||
url = "https://shitposter.club/notice/2827873"
|
||||
{:ok, [activity]} = OStatus.fetch_activity_from_url(url)
|
||||
|
||||
assert activity.data["actor"] == "https://shitposter.club/user/1"
|
||||
|
||||
assert activity.data["object"] ==
|
||||
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
||||
end)
|
||||
end
|
||||
|
||||
test "it works for atom notes, too" do
|
||||
url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
|
||||
{:ok, [activity]} = OStatus.fetch_activity_from_url(url)
|
||||
assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
|
||||
assert activity.data["object"] == url
|
||||
end
|
||||
end
|
||||
|
||||
test "it doesn't add nil in the to field" do
|
||||
incoming = File.read!("test/fixtures/nil_mention_entry.xml")
|
||||
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
||||
|
||||
assert activity.data["to"] == [
|
||||
"http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers",
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
]
|
||||
end
|
||||
|
||||
describe "is_representable?" do
|
||||
test "Note objects are representable" do
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
assert OStatus.is_representable?(note_activity)
|
||||
end
|
||||
|
||||
test "Article objects are not representable" do
|
||||
note_activity = insert(:note_activity)
|
||||
note_object = Object.normalize(note_activity)
|
||||
|
||||
note_data =
|
||||
note_object.data
|
||||
|> Map.put("type", "Article")
|
||||
|
||||
Cachex.clear(:object_cache)
|
||||
|
||||
cs = Object.change(note_object, %{data: note_data})
|
||||
{:ok, _article_object} = Repo.update(cs)
|
||||
|
||||
# the underlying object is now an Article instead of a note, so this should fail
|
||||
refute OStatus.is_representable?(note_activity)
|
||||
end
|
||||
end
|
||||
|
||||
describe "make_user/2" do
|
||||
test "creates new user" do
|
||||
{:ok, user} = OStatus.make_user("https://social.heldscal.la/user/23211")
|
||||
|
||||
created_user =
|
||||
User
|
||||
|> Repo.get_by(ap_id: "https://social.heldscal.la/user/23211")
|
||||
|> Map.put(:last_digest_emailed_at, nil)
|
||||
|
||||
assert user.info
|
||||
assert user == created_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.OStatus.UserRepresenterTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.OStatus.UserRepresenter
|
||||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.User
|
||||
|
||||
test "returns a user with id, uri, name and link" do
|
||||
user = insert(:user, %{nickname: "レイン"})
|
||||
tuple = UserRepresenter.to_simple_form(user)
|
||||
|
||||
res = :xmerl.export_simple_content(tuple, :xmerl_xml) |> to_string
|
||||
|
||||
expected = """
|
||||
<id>#{user.ap_id}</id>
|
||||
<activity:object>http://activitystrea.ms/schema/1.0/person</activity:object>
|
||||
<uri>#{user.ap_id}</uri>
|
||||
<poco:preferredUsername>#{user.nickname}</poco:preferredUsername>
|
||||
<poco:displayName>#{user.name}</poco:displayName>
|
||||
<poco:note>#{user.bio}</poco:note>
|
||||
<summary>#{user.bio}</summary>
|
||||
<name>#{user.nickname}</name>
|
||||
<link rel="avatar" href="#{User.avatar_url(user)}" />
|
||||
<link rel="header" href="#{User.banner_url(user)}" />
|
||||
<ap_enabled>true</ap_enabled>
|
||||
"""
|
||||
|
||||
assert clean(res) == clean(expected)
|
||||
end
|
||||
|
||||
defp clean(string) do
|
||||
String.replace(string, ~r/\s/, "")
|
||||
end
|
||||
end
|
||||
|
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -20,10 +19,10 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
setup do
|
||||
{:ok, user} =
|
||||
insert(:user)
|
||||
|> User.change_info(&User.Info.confirmation_changeset(&1, need_confirmation: true))
|
||||
|> Repo.update()
|
||||
|> User.confirmation_changeset(need_confirmation: true)
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
assert user.info.confirmation_pending
|
||||
assert user.confirmation_pending
|
||||
|
||||
[user: user]
|
||||
end
|
||||
|
|
@ -105,7 +104,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.banner["type"] == "Image"
|
||||
assert user.banner["type"] == "Image"
|
||||
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
end
|
||||
|
|
@ -119,7 +118,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.banner == %{}
|
||||
assert user.banner == %{}
|
||||
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
end
|
||||
|
|
@ -135,7 +134,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> patch("/api/v1/pleroma/accounts/update_background", %{"img" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.background["type"] == "Image"
|
||||
assert user.background["type"] == "Image"
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
end
|
||||
|
||||
|
|
@ -148,14 +147,14 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> patch("/api/v1/pleroma/accounts/update_background", %{"img" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.info.background == %{}
|
||||
assert user.background == %{}
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting favorites timeline of specified user" do
|
||||
setup do
|
||||
[current_user, user] = insert_pair(:user, %{info: %{hide_favorites: false}})
|
||||
[current_user, user] = insert_pair(:user, hide_favorites: false)
|
||||
[current_user: current_user, user: user]
|
||||
end
|
||||
|
||||
|
|
@ -319,7 +318,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
conn: conn,
|
||||
current_user: current_user
|
||||
} do
|
||||
user = insert(:user, %{info: %{hide_favorites: true}})
|
||||
user = insert(:user, hide_favorites: true)
|
||||
activity = insert(:note_activity)
|
||||
CommonAPI.favorite(activity.id, user)
|
||||
|
||||
|
|
@ -341,7 +340,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> assign(:user, current_user)
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|
||||
assert user.info.hide_favorites
|
||||
assert user.hide_favorites
|
||||
assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
end
|
||||
|
||||
test "listing remote packs" do
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
resp = conn |> get(emoji_api_path(conn, :list_packs)) |> json_response(200)
|
||||
|
|
@ -121,7 +121,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
text(File.read!("#{@emoji_dir_path}/test_pack_nonshared/nonshared.zip"))
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
end)
|
||||
|
||||
{:ok,
|
||||
admin: insert(:user, info: %{is_admin: true}),
|
||||
admin: insert(:user, is_admin: true),
|
||||
pack_file: pack_file,
|
||||
new_data: %{
|
||||
"license" => "Test license changed",
|
||||
|
|
@ -303,7 +303,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
File.rm_rf!("#{@emoji_dir_path}/test_pack/dir_2")
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn = build_conn()
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
File.rm_rf!("#{@emoji_dir_path}/test_created")
|
||||
end)
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn = build_conn() |> assign(:user, admin)
|
||||
|
||||
|
|
@ -431,7 +431,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
|
||||
refute Map.has_key?(resp, "test_pack_for_import")
|
||||
|
||||
admin = insert(:user, info: %{is_admin: true})
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
assert conn
|
||||
|> assign(:user, admin)
|
||||
|
|
|
|||
|
|
@ -155,6 +155,33 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
assert other_user in participation.recipients
|
||||
end
|
||||
|
||||
test "POST /api/v1/pleroma/conversations/read", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
|
||||
|
||||
[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
|
||||
|
||||
[%{"unread" => false}, %{"unread" => false}] =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> post("/api/v1/pleroma/conversations/read", %{})
|
||||
|> json_response(200)
|
||||
|
||||
[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
|
||||
end
|
||||
|
||||
describe "POST /api/v1/pleroma/notifications/read" do
|
||||
test "it marks a single notification as read", %{conn: conn} do
|
||||
user1 = insert(:user)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
) == :error
|
||||
end
|
||||
|
||||
test "delete subsciption if restult send message between 400..500" do
|
||||
test "delete subscription if result send message between 400..500" do
|
||||
subscription = insert(:push_subscription)
|
||||
|
||||
assert Impl.push_message(
|
||||
|
|
@ -97,7 +97,7 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
refute Pleroma.Repo.get(Subscription, subscription.id)
|
||||
end
|
||||
|
||||
test "renders body for create activity" do
|
||||
test "renders title and body for create activity" do
|
||||
user = insert(:user, nickname: "Bob")
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -116,18 +116,24 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
object
|
||||
) ==
|
||||
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
||||
|
||||
assert Impl.format_title(%{activity: activity}) ==
|
||||
"New Mention"
|
||||
end
|
||||
|
||||
test "renders body for follow activity" do
|
||||
test "renders title and body for follow activity" do
|
||||
user = insert(:user, nickname: "Bob")
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has followed you"
|
||||
|
||||
assert Impl.format_title(%{activity: activity}) ==
|
||||
"New Follower"
|
||||
end
|
||||
|
||||
test "renders body for announce activity" do
|
||||
test "renders title and body for announce activity" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -141,9 +147,12 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
|
||||
assert Impl.format_body(%{activity: announce_activity}, user, object) ==
|
||||
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
|
||||
|
||||
assert Impl.format_title(%{activity: announce_activity}) ==
|
||||
"New Repeat"
|
||||
end
|
||||
|
||||
test "renders body for like activity" do
|
||||
test "renders title and body for like activity" do
|
||||
user = insert(:user, nickname: "Bob")
|
||||
|
||||
{:ok, activity} =
|
||||
|
|
@ -156,5 +165,21 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
object = Object.normalize(activity)
|
||||
|
||||
assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
|
||||
|
||||
assert Impl.format_title(%{activity: activity}) ==
|
||||
"New Favorite"
|
||||
end
|
||||
|
||||
test "renders title for create activity with direct visibility" do
|
||||
user = insert(:user, nickname: "Bob")
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"visibility" => "direct",
|
||||
"status" => "This is just between you and me, pal"
|
||||
})
|
||||
|
||||
assert Impl.format_title(%{activity: activity}) ==
|
||||
"New Direct Message"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ defmodule Pleroma.Web.RelMeTest do
|
|||
hrefs = ["https://social.example.org/users/lain"]
|
||||
|
||||
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
|
||||
assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
|
||||
|
||||
assert {:ok, %Tesla.Env{status: 404}} =
|
||||
Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
|
||||
|
||||
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
|
||||
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
|
||||
|
|
|
|||
|
|
@ -1,101 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Salmon.SalmonTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Keys
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.Federator.Publisher
|
||||
alias Pleroma.Web.Salmon
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
@magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
|
||||
|
||||
@wrong_magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAA"
|
||||
|
||||
@magickey_friendica "RSA.AMwa8FUs2fWEjX0xN7yRQgegQffhBpuKNC6fa5VNSVorFjGZhRrlPMn7TQOeihlc9lBz2OsHlIedbYn2uJ7yCs0.AQAB"
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "decodes a salmon" do
|
||||
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
|
||||
{:ok, doc} = Salmon.decode_and_validate(@magickey, salmon)
|
||||
assert Regex.match?(~r/xml/, doc)
|
||||
end
|
||||
|
||||
test "errors on wrong magic key" do
|
||||
{:ok, salmon} = File.read("test/fixtures/salmon.xml")
|
||||
assert Salmon.decode_and_validate(@wrong_magickey, salmon) == :error
|
||||
end
|
||||
|
||||
test "it encodes a magic key from a public key" do
|
||||
key = Salmon.decode_key(@magickey)
|
||||
magic_key = Salmon.encode_key(key)
|
||||
|
||||
assert @magickey == magic_key
|
||||
end
|
||||
|
||||
test "it decodes a friendica public key" do
|
||||
_key = Salmon.decode_key(@magickey_friendica)
|
||||
end
|
||||
|
||||
test "encodes an xml payload with a private key" do
|
||||
doc = File.read!("test/fixtures/incoming_note_activity.xml")
|
||||
pem = File.read!("test/fixtures/private_key.pem")
|
||||
{:ok, private, public} = Keys.keys_from_pem(pem)
|
||||
|
||||
# Let's try a roundtrip.
|
||||
{:ok, salmon} = Salmon.encode(private, doc)
|
||||
{:ok, decoded_doc} = Salmon.decode_and_validate(Salmon.encode_key(public), salmon)
|
||||
|
||||
assert doc == decoded_doc
|
||||
end
|
||||
|
||||
test "it gets a magic key" do
|
||||
salmon = File.read!("test/fixtures/salmon2.xml")
|
||||
{:ok, key} = Salmon.fetch_magic_key(salmon)
|
||||
|
||||
assert key ==
|
||||
"RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB"
|
||||
end
|
||||
|
||||
test_with_mock "it pushes an activity to remote accounts it's addressed to",
|
||||
Publisher,
|
||||
[:passthrough],
|
||||
[] do
|
||||
user_data = %{
|
||||
info: %{
|
||||
salmon: "http://test-example.org/salmon"
|
||||
},
|
||||
local: false
|
||||
}
|
||||
|
||||
mentioned_user = insert(:user, user_data)
|
||||
note = insert(:note)
|
||||
|
||||
activity_data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Create",
|
||||
"actor" => note.data["actor"],
|
||||
"to" => note.data["to"] ++ [mentioned_user.ap_id],
|
||||
"object" => note.data,
|
||||
"published_at" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"context" => note.data["context"]
|
||||
}
|
||||
|
||||
{:ok, activity} = Repo.insert(%Activity{data: activity_data, recipients: activity_data["to"]})
|
||||
user = User.get_cached_by_ap_id(activity.data["actor"])
|
||||
{:ok, user} = User.ensure_keys_present(user)
|
||||
|
||||
Salmon.publish(user, activity)
|
||||
|
||||
assert called(Publisher.enqueue_one(Salmon, %{recipient_id: mentioned_user.id}))
|
||||
end
|
||||
end
|
||||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.List
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -110,6 +111,24 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
Streamer.stream("user:notification", notif)
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it sends follow activities to the 'user:notification' stream", %{
|
||||
user: user
|
||||
} do
|
||||
user2 = insert(:user)
|
||||
task = Task.async(fn -> assert_receive {:text, _}, 4_000 end)
|
||||
|
||||
Streamer.add_socket(
|
||||
"user:notification",
|
||||
%{transport_pid: task.pid, assigns: %{user: user}}
|
||||
)
|
||||
|
||||
{:ok, _follower, _followed, _activity} = CommonAPI.follow(user2, user)
|
||||
|
||||
# We don't directly pipe the notification to the streamer as it's already
|
||||
# generated as a side effect of CommonAPI.follow().
|
||||
Task.await(task)
|
||||
end
|
||||
end
|
||||
|
||||
test "it sends to public" do
|
||||
|
|
@ -169,7 +188,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
test "it doesn't send to user if recipients invalid and thread containment is enabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id])
|
||||
user = insert(:user)
|
||||
User.follow(user, author, "accept")
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
@ -191,7 +211,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
test "it sends message if recipients invalid and thread containment is disabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], true)
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id])
|
||||
user = insert(:user)
|
||||
User.follow(user, author, "accept")
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
@ -213,7 +234,8 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
|
||||
Pleroma.Config.put([:instance, :skip_thread_containment], false)
|
||||
author = insert(:user)
|
||||
user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true})
|
||||
user = insert(:user, skip_thread_containment: true)
|
||||
User.follow(user, author, "accept")
|
||||
|
||||
activity =
|
||||
insert(:note_activity,
|
||||
|
|
@ -460,7 +482,14 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
task =
|
||||
Task.async(fn ->
|
||||
assert_receive {:text, _received_event}, 4_000
|
||||
assert_receive {:text, received_event}, 4_000
|
||||
|
||||
assert %{"event" => "conversation", "payload" => received_payload} =
|
||||
Jason.decode!(received_event)
|
||||
|
||||
assert %{"last_status" => last_status} = Jason.decode!(received_payload)
|
||||
[participation] = Participation.for_user(user)
|
||||
assert last_status["pleroma"]["direct_conversation_id"] == participation.id
|
||||
end)
|
||||
|
||||
Streamer.add_socket(
|
||||
|
|
@ -477,7 +506,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it doesn't send conversation update to the 'direct' streamj when the last message in the conversation is deleted" do
|
||||
test "it doesn't send conversation update to the 'direct' stream when the last message in the conversation is deleted" do
|
||||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
end
|
||||
|
||||
test "it sets password_reset_pending to false", %{conn: conn} do
|
||||
user = insert(:user, info: %{password_reset_pending: true})
|
||||
user = insert(:user, password_reset_pending: true)
|
||||
|
||||
{:ok, token} = PasswordResetToken.create_token(user)
|
||||
{:ok, _access_token} = Token.create_token(insert(:oauth_app), user, %{})
|
||||
|
|
@ -75,7 +75,7 @@ defmodule Pleroma.Web.TwitterAPI.PasswordControllerTest do
|
|||
|> post("/api/pleroma/password_reset", %{data: params})
|
||||
|> html_response(:ok)
|
||||
|
||||
assert User.get_by_id(user.id).info.password_reset_pending == false
|
||||
assert User.get_by_id(user.id).password_reset_pending == false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert user.info.confirmation_pending
|
||||
assert user.confirmation_pending
|
||||
|
||||
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
"follows" => true,
|
||||
"non_follows" => true,
|
||||
"non_followers" => true
|
||||
} == user.info.notification_settings
|
||||
} == user.notification_settings
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -366,11 +366,11 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
assert user2.follower_address in refresh_record(user).following
|
||||
assert user2.follower_address in User.following(user)
|
||||
end
|
||||
|
||||
test "returns error when user is deactivated", %{conn: conn} do
|
||||
user = insert(:user, info: %{deactivated: true})
|
||||
user = insert(:user, deactivated: true)
|
||||
user2 = insert(:user)
|
||||
|
||||
response =
|
||||
|
|
@ -438,7 +438,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|> response(200)
|
||||
|
||||
assert response =~ "Account followed!"
|
||||
assert user2.follower_address in refresh_record(user).following
|
||||
assert user2.follower_address in User.following(user)
|
||||
end
|
||||
|
||||
test "returns error when followee not found", %{conn: conn} do
|
||||
|
|
@ -568,7 +568,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.info.deactivated == true
|
||||
assert user.deactivated == true
|
||||
end
|
||||
|
||||
test "it returns returns when password invalid", %{conn: conn} do
|
||||
|
|
@ -583,7 +583,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
assert response == %{"error" => "Invalid password."}
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
refute user.info.deactivated
|
||||
refute user.deactivated
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -45,19 +45,6 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
|
||||
end
|
||||
|
||||
test "returns the info for an OStatus user" do
|
||||
user = "shp@social.heldscal.la"
|
||||
|
||||
{:ok, data} = WebFinger.finger(user)
|
||||
|
||||
assert data["magic_key"] ==
|
||||
"RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB"
|
||||
|
||||
assert data["topic"] == "https://social.heldscal.la/api/statuses/user_timeline/29191.atom"
|
||||
assert data["subject"] == "acct:shp@social.heldscal.la"
|
||||
assert data["salmon"] == "https://social.heldscal.la/main/salmon/user/29191"
|
||||
end
|
||||
|
||||
test "returns the ActivityPub actor URI for an ActivityPub user" do
|
||||
user = "framasoft@framatube.org"
|
||||
|
||||
|
|
@ -72,20 +59,6 @@ defmodule Pleroma.Web.WebFingerTest do
|
|||
assert data["ap_id"] == "https://gerzilla.de/channel/kaniini"
|
||||
end
|
||||
|
||||
test "returns the correctly for json ostatus users" do
|
||||
user = "winterdienst@gnusocial.de"
|
||||
|
||||
{:ok, data} = WebFinger.finger(user)
|
||||
|
||||
assert data["magic_key"] ==
|
||||
"RSA.qfYaxztz7ZELrE4v5WpJrPM99SKI3iv9Y3Tw6nfLGk-4CRljNYqV8IYX2FXjeucC_DKhPNnlF6fXyASpcSmA_qupX9WC66eVhFhZ5OuyBOeLvJ1C4x7Hi7Di8MNBxY3VdQuQR0tTaS_YAZCwASKp7H6XEid3EJpGt0EQZoNzRd8=.AQAB"
|
||||
|
||||
assert data["topic"] == "https://gnusocial.de/api/statuses/user_timeline/249296.atom"
|
||||
assert data["subject"] == "acct:winterdienst@gnusocial.de"
|
||||
assert data["salmon"] == "https://gnusocial.de/main/salmon/user/249296"
|
||||
assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
|
||||
end
|
||||
|
||||
test "it work for AP-only user" do
|
||||
user = "kpherox@mstdn.jp"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,86 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Websub.WebsubControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.Websub
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
test "websub subscription request", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
path = Pleroma.Web.OStatus.pubsub_path(user)
|
||||
|
||||
data = %{
|
||||
"hub.callback": "http://example.org/sub",
|
||||
"hub.mode": "subscribe",
|
||||
"hub.topic": Pleroma.Web.OStatus.feed_path(user),
|
||||
"hub.secret": "a random secret",
|
||||
"hub.lease_seconds": "100"
|
||||
}
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> post(path, data)
|
||||
|
||||
assert response(conn, 202) == "Accepted"
|
||||
end
|
||||
|
||||
test "websub subscription confirmation", %{conn: conn} do
|
||||
websub = insert(:websub_client_subscription)
|
||||
|
||||
params = %{
|
||||
"hub.mode" => "subscribe",
|
||||
"hub.topic" => websub.topic,
|
||||
"hub.challenge" => "some challenge",
|
||||
"hub.lease_seconds" => "100"
|
||||
}
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/push/subscriptions/#{websub.id}", params)
|
||||
|
||||
websub = Repo.get(WebsubClientSubscription, websub.id)
|
||||
|
||||
assert response(conn, 200) == "some challenge"
|
||||
assert websub.state == "accepted"
|
||||
assert_in_delta NaiveDateTime.diff(websub.valid_until, NaiveDateTime.utc_now()), 100, 5
|
||||
end
|
||||
|
||||
describe "websub_incoming" do
|
||||
test "accepts incoming feed updates", %{conn: conn} do
|
||||
websub = insert(:websub_client_subscription)
|
||||
doc = "some stuff"
|
||||
signature = Websub.sign(websub.secret, doc)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("x-hub-signature", "sha1=" <> signature)
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/push/subscriptions/#{websub.id}", doc)
|
||||
|
||||
assert response(conn, 200) == "OK"
|
||||
end
|
||||
|
||||
test "rejects incoming feed updates with the wrong signature", %{conn: conn} do
|
||||
websub = insert(:websub_client_subscription)
|
||||
doc = "some stuff"
|
||||
signature = Websub.sign("wrong secret", doc)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("x-hub-signature", "sha1=" <> signature)
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> post("/push/subscriptions/#{websub.id}", doc)
|
||||
|
||||
assert response(conn, 500) == "Error"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,236 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.WebsubTest do
|
||||
use Pleroma.DataCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.Web.Router.Helpers
|
||||
alias Pleroma.Web.Websub
|
||||
alias Pleroma.Web.Websub.WebsubClientSubscription
|
||||
alias Pleroma.Web.Websub.WebsubServerSubscription
|
||||
alias Pleroma.Workers.SubscriberWorker
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "a verification of a request that is accepted" do
|
||||
sub = insert(:websub_subscription)
|
||||
topic = sub.topic
|
||||
|
||||
getter = fn _path, _headers, options ->
|
||||
%{
|
||||
"hub.challenge": challenge,
|
||||
"hub.lease_seconds": seconds,
|
||||
"hub.topic": ^topic,
|
||||
"hub.mode": "subscribe"
|
||||
} = Keyword.get(options, :params)
|
||||
|
||||
assert String.to_integer(seconds) > 0
|
||||
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: challenge
|
||||
}}
|
||||
end
|
||||
|
||||
{:ok, sub} = Websub.verify(sub, getter)
|
||||
assert sub.state == "active"
|
||||
end
|
||||
|
||||
test "a verification of a request that doesn't return 200" do
|
||||
sub = insert(:websub_subscription)
|
||||
|
||||
getter = fn _path, _headers, _options ->
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 500,
|
||||
body: ""
|
||||
}}
|
||||
end
|
||||
|
||||
{:error, sub} = Websub.verify(sub, getter)
|
||||
# Keep the current state.
|
||||
assert sub.state == "requested"
|
||||
end
|
||||
|
||||
test "an incoming subscription request" do
|
||||
user = insert(:user)
|
||||
|
||||
data = %{
|
||||
"hub.callback" => "http://example.org/sub",
|
||||
"hub.mode" => "subscribe",
|
||||
"hub.topic" => Pleroma.Web.OStatus.feed_path(user),
|
||||
"hub.secret" => "a random secret",
|
||||
"hub.lease_seconds" => "100"
|
||||
}
|
||||
|
||||
{:ok, subscription} = Websub.incoming_subscription_request(user, data)
|
||||
assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
|
||||
assert subscription.state == "requested"
|
||||
assert subscription.secret == "a random secret"
|
||||
assert subscription.callback == "http://example.org/sub"
|
||||
end
|
||||
|
||||
test "an incoming subscription request for an existing subscription" do
|
||||
user = insert(:user)
|
||||
|
||||
sub =
|
||||
insert(:websub_subscription, state: "accepted", topic: Pleroma.Web.OStatus.feed_path(user))
|
||||
|
||||
data = %{
|
||||
"hub.callback" => sub.callback,
|
||||
"hub.mode" => "subscribe",
|
||||
"hub.topic" => Pleroma.Web.OStatus.feed_path(user),
|
||||
"hub.secret" => "a random secret",
|
||||
"hub.lease_seconds" => "100"
|
||||
}
|
||||
|
||||
{:ok, subscription} = Websub.incoming_subscription_request(user, data)
|
||||
assert subscription.topic == Pleroma.Web.OStatus.feed_path(user)
|
||||
assert subscription.state == sub.state
|
||||
assert subscription.secret == "a random secret"
|
||||
assert subscription.callback == sub.callback
|
||||
assert length(Repo.all(WebsubServerSubscription)) == 1
|
||||
assert subscription.id == sub.id
|
||||
end
|
||||
|
||||
def accepting_verifier(subscription) do
|
||||
{:ok, %{subscription | state: "accepted"}}
|
||||
end
|
||||
|
||||
test "initiate a subscription for a given user and topic" do
|
||||
subscriber = insert(:user)
|
||||
user = insert(:user, %{info: %Pleroma.User.Info{topic: "some_topic", hub: "some_hub"}})
|
||||
|
||||
{:ok, websub} = Websub.subscribe(subscriber, user, &accepting_verifier/1)
|
||||
assert websub.subscribers == [subscriber.ap_id]
|
||||
assert websub.topic == "some_topic"
|
||||
assert websub.hub == "some_hub"
|
||||
assert is_binary(websub.secret)
|
||||
assert websub.user == user
|
||||
assert websub.state == "accepted"
|
||||
end
|
||||
|
||||
test "discovers the hub and canonical url" do
|
||||
topic = "https://mastodon.social/users/lambadalambda.atom"
|
||||
|
||||
{:ok, discovered} = Websub.gather_feed_data(topic)
|
||||
|
||||
expected = %{
|
||||
"hub" => "https://mastodon.social/api/push",
|
||||
"uri" => "https://mastodon.social/users/lambadalambda",
|
||||
"nickname" => "lambadalambda",
|
||||
"name" => "Critical Value",
|
||||
"host" => "mastodon.social",
|
||||
"bio" => "a cool dude.",
|
||||
"avatar" => %{
|
||||
"type" => "Image",
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://files.mastodon.social/accounts/avatars/000/000/264/original/1429214160519.gif?1492379244",
|
||||
"mediaType" => "image/gif",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
assert expected == discovered
|
||||
end
|
||||
|
||||
test "calls the hub, requests topic" do
|
||||
hub = "https://social.heldscal.la/main/push/hub"
|
||||
topic = "https://social.heldscal.la/api/statuses/user_timeline/23211.atom"
|
||||
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
|
||||
|
||||
poster = fn ^hub, {:form, data}, _headers ->
|
||||
assert Keyword.get(data, :"hub.mode") == "subscribe"
|
||||
|
||||
assert Keyword.get(data, :"hub.callback") ==
|
||||
Helpers.websub_url(
|
||||
Pleroma.Web.Endpoint,
|
||||
:websub_subscription_confirmation,
|
||||
websub.id
|
||||
)
|
||||
|
||||
{:ok, %{status: 202}}
|
||||
end
|
||||
|
||||
task = Task.async(fn -> Websub.request_subscription(websub, poster) end)
|
||||
|
||||
change = Ecto.Changeset.change(websub, %{state: "accepted"})
|
||||
{:ok, _} = Repo.update(change)
|
||||
|
||||
{:ok, websub} = Task.await(task)
|
||||
|
||||
assert websub.state == "accepted"
|
||||
end
|
||||
|
||||
test "rejects the subscription if it can't be accepted" do
|
||||
hub = "https://social.heldscal.la/main/push/hub"
|
||||
topic = "https://social.heldscal.la/api/statuses/user_timeline/23211.atom"
|
||||
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
|
||||
|
||||
poster = fn ^hub, {:form, _data}, _headers ->
|
||||
{:ok, %{status: 202}}
|
||||
end
|
||||
|
||||
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
|
||||
assert websub.state == "rejected"
|
||||
|
||||
websub = insert(:websub_client_subscription, %{hub: hub, topic: topic})
|
||||
|
||||
poster = fn ^hub, {:form, _data}, _headers ->
|
||||
{:ok, %{status: 400}}
|
||||
end
|
||||
|
||||
{:error, websub} = Websub.request_subscription(websub, poster, 1000)
|
||||
assert websub.state == "rejected"
|
||||
end
|
||||
|
||||
test "sign a text" do
|
||||
signed = Websub.sign("secret", "text")
|
||||
assert signed == "B8392C23690CCF871F37EC270BE1582DEC57A503" |> String.downcase()
|
||||
|
||||
_signed = Websub.sign("secret", [["て"], ['す']])
|
||||
end
|
||||
|
||||
describe "renewing subscriptions" do
|
||||
test "it renews subscriptions that have less than a day of time left" do
|
||||
day = 60 * 60 * 24
|
||||
now = NaiveDateTime.utc_now()
|
||||
|
||||
still_good =
|
||||
insert(:websub_client_subscription, %{
|
||||
valid_until: NaiveDateTime.add(now, 2 * day),
|
||||
topic: "http://example.org/still_good",
|
||||
hub: "http://example.org/still_good",
|
||||
state: "accepted"
|
||||
})
|
||||
|
||||
needs_refresh =
|
||||
insert(:websub_client_subscription, %{
|
||||
valid_until: NaiveDateTime.add(now, day - 100),
|
||||
topic: "http://example.org/needs_refresh",
|
||||
hub: "http://example.org/needs_refresh",
|
||||
state: "accepted"
|
||||
})
|
||||
|
||||
_refresh = Websub.refresh_subscriptions()
|
||||
ObanHelpers.perform(all_enqueued(worker: SubscriberWorker))
|
||||
|
||||
assert still_good == Repo.get(WebsubClientSubscription, still_good.id)
|
||||
refute needs_refresh == Repo.get(WebsubClientSubscription, needs_refresh.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue