2018-12-23 13:11:29 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2019-09-18 15:20:54 -06:00
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 13:11:29 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-04-24 10:46:34 -06:00
|
|
|
defmodule Pleroma.Web.OStatusTest do
|
|
|
|
use Pleroma.DataCase
|
2019-03-04 19:52:23 -07:00
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Instances
|
2019-02-10 14:57:38 -07:00
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Repo
|
|
|
|
alias Pleroma.User
|
2017-04-24 10:46:34 -06:00
|
|
|
alias Pleroma.Web.OStatus
|
2017-05-02 09:13:41 -06:00
|
|
|
alias Pleroma.Web.XML
|
2019-06-29 11:04:50 -06:00
|
|
|
|
2018-02-12 02:13:54 -07:00
|
|
|
import ExUnit.CaptureLog
|
2019-06-29 11:04:50 -06:00
|
|
|
import Mock
|
|
|
|
import Pleroma.Factory
|
2017-04-24 10:46:34 -06:00
|
|
|
|
2018-12-04 04:01:39 -07:00
|
|
|
setup_all do
|
|
|
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
2018-12-02 12:05:28 -07:00
|
|
|
:ok
|
|
|
|
end
|
2017-04-24 10:46:34 -06:00
|
|
|
|
2017-04-30 04:36:47 -06:00
|
|
|
test "don't insert create notes twice" do
|
|
|
|
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
2017-05-08 10:19:45 -06:00
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
assert {:ok, [activity]} == OStatus.handle_incoming(incoming)
|
2017-04-30 04:36:47 -06:00
|
|
|
end
|
|
|
|
|
2017-04-29 13:13:21 -06:00
|
|
|
test "handle incoming note - GS, Salmon" do
|
2017-04-24 10:46:34 -06:00
|
|
|
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
2017-04-29 13:13:21 -06:00
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2017-04-24 10:46:34 -06:00
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
user = User.get_cached_by_ap_id(activity.data["actor"])
|
2018-11-27 10:37:46 -07:00
|
|
|
assert user.info.note_count == 1
|
2017-04-24 10:46:34 -06:00
|
|
|
assert activity.data["type"] == "Create"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["type"] == "Note"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2018-11-25 15:49:39 -07:00
|
|
|
assert object.data["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-24 10:46:34 -06:00
|
|
|
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["published"] == "2017-04-23T14:51:03+00:00"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert activity.data["context"] ==
|
|
|
|
"tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
|
|
|
|
|
2017-04-25 10:03:14 -06:00
|
|
|
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
|
2017-05-02 02:47:04 -06:00
|
|
|
assert activity.local == false
|
2017-04-24 10:46:34 -06:00
|
|
|
end
|
|
|
|
|
2017-04-29 13:13:21 -06:00
|
|
|
test "handle incoming notes - GS, subscription" do
|
|
|
|
incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2017-04-29 13:13:21 -06:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["type"] == "Note"
|
|
|
|
assert object.data["actor"] == "https://social.heldscal.la/user/23211"
|
|
|
|
assert object.data["content"] == "Will it blend?"
|
2017-05-06 06:23:39 -06:00
|
|
|
user = User.get_cached_by_ap_id(activity.data["actor"])
|
|
|
|
assert User.ap_followers(user) in activity.data["to"]
|
2017-06-30 08:08:59 -06:00
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
2017-04-29 13:13:21 -06:00
|
|
|
end
|
|
|
|
|
2017-05-18 07:58:18 -06:00
|
|
|
test "handle incoming notes with tags" do
|
|
|
|
incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2017-05-18 07:58:18 -06:00
|
|
|
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["tag"] == ["nsfw"]
|
2017-06-30 08:08:59 -06:00
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
2017-05-18 07:58:18 -06:00
|
|
|
end
|
|
|
|
|
2017-05-02 13:31:01 -06:00
|
|
|
test "handle incoming notes - Mastodon, salmon, reply" do
|
|
|
|
# It uses the context of the replied to object
|
|
|
|
Repo.insert!(%Object{
|
2018-03-30 07:01:53 -06:00
|
|
|
data: %{
|
|
|
|
"id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
|
|
|
|
"context" => "2hu"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-05-02 13:31:01 -06:00
|
|
|
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2017-05-02 13:31:01 -06:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["type"] == "Note"
|
|
|
|
assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
2017-05-02 13:31:01 -06:00
|
|
|
assert activity.data["context"] == "2hu"
|
2017-06-30 08:08:59 -06:00
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
2017-05-02 13:31:01 -06:00
|
|
|
end
|
|
|
|
|
2017-05-10 10:46:23 -06:00
|
|
|
test "handle incoming notes - Mastodon, with CW" do
|
|
|
|
incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2017-05-10 10:46:23 -06:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["type"] == "Note"
|
|
|
|
assert object.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
|
|
|
assert object.data["summary"] == "technologic"
|
2017-06-30 08:08:59 -06:00
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
2017-05-10 10:46:23 -06:00
|
|
|
end
|
|
|
|
|
2018-03-07 07:45:13 -07:00
|
|
|
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)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2018-11-25 15:31:07 -07:00
|
|
|
|
2018-03-07 07:45:13 -07:00
|
|
|
refute "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["cc"]
|
2018-11-25 15:31:07 -07:00
|
|
|
refute "https://www.w3.org/ns/activitystreams#Public" in object.data["to"]
|
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in object.data["cc"]
|
2018-03-07 07:45:13 -07:00
|
|
|
end
|
|
|
|
|
2017-05-11 09:59:11 -06:00
|
|
|
test "handle incoming retweets - Mastodon, with CW" do
|
|
|
|
incoming = File.read!("test/fixtures/cw_retweet.xml")
|
2018-02-12 02:13:54 -07:00
|
|
|
{:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
retweeted_object = Object.normalize(retweeted_activity)
|
2017-05-11 09:59:11 -06:00
|
|
|
|
2018-11-25 15:31:07 -07:00
|
|
|
assert retweeted_object.data["summary"] == "Hey."
|
2017-05-11 09:59:11 -06:00
|
|
|
end
|
|
|
|
|
2017-04-30 03:39:27 -06:00
|
|
|
test "handle incoming notes - GS, subscription, reply" do
|
|
|
|
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(activity)
|
2017-04-30 03:39:27 -06:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["type"] == "Note"
|
|
|
|
assert object.data["actor"] == "https://social.heldscal.la/user/23211"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["content"] ==
|
2018-03-30 07:01:53 -06:00
|
|
|
"@<a href=\"https://gs.archae.me/user/4687\" class=\"h-card u-url p-nickname mention\" title=\"shpbot\">shpbot</a> why not indeed."
|
|
|
|
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["inReplyTo"] ==
|
2018-03-30 07:01:53 -06:00
|
|
|
"tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
|
|
|
|
|
2017-06-30 08:08:59 -06:00
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
2017-04-30 03:39:27 -06:00
|
|
|
end
|
|
|
|
|
2017-05-04 10:42:29 -06:00
|
|
|
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"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert activity.data["object"] == retweeted_activity.data["object"]
|
2017-05-08 10:19:45 -06:00
|
|
|
assert "https://pleroma.soykaf.com/users/lain" in activity.data["to"]
|
2017-05-04 10:42:29 -06:00
|
|
|
refute activity.local
|
2017-05-08 10:19:45 -06:00
|
|
|
|
2019-04-02 04:08:03 -06:00
|
|
|
retweeted_activity = Activity.get_by_id(retweeted_activity.id)
|
2019-07-08 10:53:02 -06:00
|
|
|
retweeted_object = Object.normalize(retweeted_activity)
|
2017-05-04 10:42:29 -06:00
|
|
|
assert retweeted_activity.data["type"] == "Create"
|
|
|
|
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
|
|
|
|
refute retweeted_activity.local
|
2018-11-25 15:31:07 -07:00
|
|
|
assert retweeted_object.data["announcement_count"] == 1
|
|
|
|
assert String.contains?(retweeted_object.data["content"], "mastodon")
|
|
|
|
refute String.contains?(retweeted_object.data["content"], "Test account")
|
2017-05-08 10:19:45 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "handle incoming retweets - GS, subscription - local message" do
|
|
|
|
incoming = File.read!("test/fixtures/share-gs-local.xml")
|
|
|
|
note_activity = insert(:note_activity)
|
2019-07-08 10:53:02 -06:00
|
|
|
object = Object.normalize(note_activity)
|
2017-05-08 10:19:45 -06:00
|
|
|
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
incoming =
|
|
|
|
incoming
|
2019-07-08 10:53:02 -06:00
|
|
|
|> String.replace("LOCAL_ID", object.data["id"])
|
2018-03-30 07:01:53 -06:00
|
|
|
|> String.replace("LOCAL_USER", user.ap_id)
|
2017-05-08 10:19:45 -06:00
|
|
|
|
|
|
|
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
|
|
|
|
|
|
|
assert activity.data["type"] == "Announce"
|
|
|
|
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
2019-07-08 10:53:02 -06:00
|
|
|
assert activity.data["object"] == object.data["id"]
|
2017-05-08 10:19:45 -06:00
|
|
|
assert user.ap_id in activity.data["to"]
|
|
|
|
refute activity.local
|
|
|
|
|
2019-04-02 04:08:03 -06:00
|
|
|
retweeted_activity = Activity.get_by_id(retweeted_activity.id)
|
2017-05-08 10:19:45 -06:00
|
|
|
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
|
2019-08-06 15:58:48 -06:00
|
|
|
assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
|
2017-05-04 10:42:29 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "handle incoming retweets - Mastodon, salmon" do
|
|
|
|
incoming = File.read!("test/fixtures/share.xml")
|
|
|
|
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
|
2019-07-08 10:53:02 -06:00
|
|
|
retweeted_object = Object.normalize(retweeted_activity)
|
2017-05-04 10:42:29 -06:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Announce"
|
|
|
|
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert activity.data["object"] == retweeted_activity.data["object"]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert activity.data["id"] ==
|
|
|
|
"tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
|
2017-05-07 12:05:03 -06:00
|
|
|
|
2017-05-04 10:42:29 -06:00
|
|
|
refute activity.local
|
|
|
|
assert retweeted_activity.data["type"] == "Create"
|
|
|
|
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
|
|
|
|
refute retweeted_activity.local
|
2018-11-25 15:31:07 -07:00
|
|
|
refute String.contains?(retweeted_object.data["content"], "Test account")
|
2017-05-04 10:42:29 -06:00
|
|
|
end
|
|
|
|
|
2017-09-04 03:03:51 -06:00
|
|
|
test "handle conversation references" do
|
|
|
|
incoming = File.read!("test/fixtures/mastodon_conversation.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
assert activity.data["context"] ==
|
|
|
|
"tag:mastodon.social,2017-08-28:objectId=7876885:objectType=Conversation"
|
2017-09-04 03:03:51 -06:00
|
|
|
end
|
|
|
|
|
2019-06-29 11:04:50 -06:00
|
|
|
test_with_mock "handle incoming replies, fetching replied-to activities if we don't have them",
|
|
|
|
OStatus,
|
|
|
|
[:passthrough],
|
|
|
|
[] do
|
2017-04-26 02:22:51 -06:00
|
|
|
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
|
2017-04-29 13:13:21 -06:00
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-09 12:46:16 -06:00
|
|
|
object = Object.normalize(activity, false)
|
2017-04-26 02:22:51 -06:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["type"] == "Note"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2018-11-25 15:31:07 -07:00
|
|
|
assert object.data["inReplyTo"] ==
|
2018-03-30 07:01:53 -06:00
|
|
|
"http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
|
|
|
|
|
2017-04-26 02:22:51 -06:00
|
|
|
assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2018-11-25 15:49:39 -07:00
|
|
|
assert object.data["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-06-30 08:08:59 -06:00
|
|
|
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
|
2019-06-29 11:04:50 -06:00
|
|
|
|
|
|
|
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,
|
2019-06-30 06:58:50 -06:00
|
|
|
allowed_incoming_reply_depth?: fn _ -> false end do
|
2019-06-29 11:04:50 -06:00
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2019-07-09 12:46:16 -06:00
|
|
|
object = Object.normalize(activity, false)
|
2019-06-29 11:04:50 -06:00
|
|
|
|
|
|
|
refute called(OStatus.fetch_activity_from_url(object.data["inReplyTo"], :_))
|
|
|
|
end
|
2017-04-26 02:22:51 -06:00
|
|
|
end
|
|
|
|
|
2017-05-10 10:46:23 -06:00
|
|
|
test "handle incoming follows" do
|
|
|
|
incoming = File.read!("test/fixtures/follow.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
assert activity.data["type"] == "Follow"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
|
|
|
assert activity.data["id"] ==
|
|
|
|
"tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
|
|
|
|
|
2017-05-10 10:46:23 -06:00
|
|
|
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
|
|
|
|
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
|
|
|
|
refute activity.local
|
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
follower = User.get_cached_by_ap_id(activity.data["actor"])
|
|
|
|
followed = User.get_cached_by_ap_id(activity.data["object"])
|
2017-05-10 10:46:23 -06:00
|
|
|
|
|
|
|
assert User.following?(follower, followed)
|
|
|
|
end
|
|
|
|
|
2019-07-31 13:05:12 -06:00
|
|
|
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
|
|
|
|
|
2018-05-21 03:11:13 -06:00
|
|
|
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"
|
2019-07-08 10:53:02 -06:00
|
|
|
embedded_object = activity.data["object"]
|
|
|
|
assert is_map(embedded_object)
|
|
|
|
assert embedded_object["type"] == "Follow"
|
|
|
|
assert embedded_object["object"] == "https://pawoo.net/users/pekorino"
|
2018-05-21 03:11:13 -06:00
|
|
|
refute activity.local
|
|
|
|
|
2019-04-22 01:20:43 -06:00
|
|
|
follower = User.get_cached_by_ap_id(activity.data["actor"])
|
2019-07-08 10:53:02 -06:00
|
|
|
followed = User.get_cached_by_ap_id(embedded_object["object"])
|
2018-05-21 03:11:13 -06:00
|
|
|
|
|
|
|
refute User.following?(follower, followed)
|
|
|
|
end
|
|
|
|
|
2019-01-29 03:12:28 -07:00
|
|
|
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
|
|
|
|
|
2017-04-24 10:46:34 -06:00
|
|
|
describe "new remote user creation" do
|
2017-05-07 04:45:37 -06:00
|
|
|
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
|
|
|
|
|
2017-04-24 10:46:34 -06:00
|
|
|
test "tries to use the information in poco fields" do
|
2017-04-29 11:06:01 -06:00
|
|
|
uri = "https://social.heldscal.la/user/23211"
|
2017-04-24 10:46:34 -06:00
|
|
|
|
2017-04-29 11:06:01 -06:00
|
|
|
{:ok, user} = OStatus.find_or_make_user(uri)
|
2017-04-24 10:46:34 -06:00
|
|
|
|
2019-05-17 01:25:20 -06:00
|
|
|
user = User.get_cached_by_id(user.id)
|
2017-04-24 10:46:34 -06:00
|
|
|
assert user.name == "Constance Variable"
|
2017-04-29 12:08:45 -06:00
|
|
|
assert user.nickname == "lambadalambda@social.heldscal.la"
|
2017-04-24 10:46:34 -06:00
|
|
|
assert user.local == false
|
2018-11-27 10:37:46 -07:00
|
|
|
assert user.info.uri == uri
|
2017-04-29 11:06:01 -06:00
|
|
|
assert user.ap_id == uri
|
2017-05-24 09:34:38 -06:00
|
|
|
assert user.bio == "Call me Deacon Blues."
|
2017-04-30 04:53:49 -06:00
|
|
|
assert user.avatar["type"] == "Image"
|
2017-04-24 10:46:34 -06:00
|
|
|
|
2017-04-29 11:06:01 -06:00
|
|
|
{:ok, user_again} = OStatus.find_or_make_user(uri)
|
2017-04-24 10:46:34 -06:00
|
|
|
|
|
|
|
assert user == user_again
|
|
|
|
end
|
2017-05-02 09:13:41 -06:00
|
|
|
|
2018-12-01 04:46:08 -07:00
|
|
|
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 ==
|
2019-05-17 01:25:20 -06:00
|
|
|
%User.Info{
|
2018-12-01 04:46:08 -07:00
|
|
|
id: user.info.id,
|
|
|
|
ap_enabled: false,
|
2018-12-02 03:20:38 -07:00
|
|
|
background: %{},
|
2018-12-01 04:46:08 -07:00
|
|
|
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
|
|
|
|
|
2019-07-31 11:23:16 -06:00
|
|
|
test "find_make_or_update_actor takes an author element and returns an updated user" do
|
2017-05-02 09:13:41 -06:00
|
|
|
uri = "https://social.heldscal.la/user/23211"
|
|
|
|
|
|
|
|
{:ok, user} = OStatus.find_or_make_user(uri)
|
2017-05-24 09:34:38 -06:00
|
|
|
old_name = user.name
|
|
|
|
old_bio = user.bio
|
2019-05-17 03:49:13 -06:00
|
|
|
change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, name: nil})
|
2017-05-02 09:13:41 -06:00
|
|
|
|
|
|
|
{: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)
|
2019-07-31 11:23:16 -06:00
|
|
|
{:ok, user} = OStatus.find_make_or_update_actor(author)
|
2017-05-02 09:13:41 -06:00
|
|
|
assert user.avatar["type"] == "Image"
|
2017-05-24 09:34:38 -06:00
|
|
|
assert user.name == old_name
|
|
|
|
assert user.bio == old_bio
|
2017-05-02 09:13:41 -06:00
|
|
|
|
2019-07-31 11:23:16 -06:00
|
|
|
{:ok, user_again} = OStatus.find_make_or_update_actor(author)
|
2017-05-02 09:13:41 -06:00
|
|
|
assert user_again == user
|
|
|
|
end
|
2019-07-31 11:23:16 -06:00
|
|
|
|
|
|
|
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
|
2017-04-24 10:46:34 -06:00
|
|
|
end
|
2017-04-29 09:51:59 -06:00
|
|
|
|
|
|
|
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 = %{
|
2017-05-03 06:26:49 -06:00
|
|
|
"hub" => "https://social.heldscal.la/main/push/hub",
|
2018-03-30 07:01:53 -06:00
|
|
|
"magic_key" =>
|
|
|
|
"RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
|
2017-05-03 06:26:49 -06:00
|
|
|
"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,
|
2017-05-24 09:34:38 -06:00
|
|
|
"bio" => "cofe",
|
2018-03-30 07:01:53 -06:00
|
|
|
"avatar" => %{
|
|
|
|
"type" => "Image",
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
|
|
|
|
"mediaType" => "image/jpeg",
|
|
|
|
"type" => "Link"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-02-24 05:06:53 -07:00
|
|
|
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
|
|
|
|
"ap_id" => nil
|
2017-04-29 09:51:59 -06:00
|
|
|
}
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-29 09:51:59 -06:00
|
|
|
assert data == expected
|
|
|
|
end
|
2017-04-29 11:06:01 -06:00
|
|
|
|
|
|
|
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 = %{
|
2017-05-03 06:26:49 -06:00
|
|
|
"hub" => "https://social.heldscal.la/main/push/hub",
|
2018-03-30 07:01:53 -06:00
|
|
|
"magic_key" =>
|
|
|
|
"RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
|
2017-05-03 06:26:49 -06:00
|
|
|
"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,
|
2017-05-24 09:34:38 -06:00
|
|
|
"bio" => "cofe",
|
2018-03-30 07:01:53 -06:00
|
|
|
"avatar" => %{
|
|
|
|
"type" => "Image",
|
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg",
|
|
|
|
"mediaType" => "image/jpeg",
|
|
|
|
"type" => "Link"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
2018-02-24 05:06:53 -07:00
|
|
|
"subscribe_address" => "https://social.heldscal.la/main/ostatussub?profile={uri}",
|
|
|
|
"ap_id" => nil
|
2017-04-29 11:06:01 -06:00
|
|
|
}
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2017-04-29 11:06:01 -06:00
|
|
|
assert data == expected
|
|
|
|
end
|
2017-04-29 09:51:59 -06:00
|
|
|
end
|
2017-05-05 08:07:44 -06:00
|
|
|
|
|
|
|
describe "fetching a status by it's HTML url" do
|
|
|
|
test "it builds a missing status from an html url" do
|
2018-03-30 07:01:53 -06:00
|
|
|
capture_log(fn ->
|
2018-02-12 02:13:54 -07:00
|
|
|
url = "https://shitposter.club/notice/2827873"
|
2018-03-30 07:01:53 -06:00
|
|
|
{:ok, [activity]} = OStatus.fetch_activity_from_url(url)
|
2017-05-05 08:07:44 -06:00
|
|
|
|
2018-02-12 02:13:54 -07:00
|
|
|
assert activity.data["actor"] == "https://shitposter.club/user/1"
|
2018-03-30 07:01:53 -06:00
|
|
|
|
2018-11-25 15:31:07 -07:00
|
|
|
assert activity.data["object"] ==
|
2018-03-30 07:01:53 -06:00
|
|
|
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
|
|
|
|
end)
|
2017-05-10 10:46:23 -06:00
|
|
|
end
|
2017-08-04 08:57:38 -06:00
|
|
|
|
|
|
|
test "it works for atom notes, too" do
|
|
|
|
url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
|
2018-03-30 07:01:53 -06:00
|
|
|
{:ok, [activity]} = OStatus.fetch_activity_from_url(url)
|
2017-08-04 08:57:38 -06:00
|
|
|
assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
|
2018-11-25 15:31:07 -07:00
|
|
|
assert activity.data["object"] == url
|
2017-08-04 08:57:38 -06:00
|
|
|
end
|
2017-05-05 08:07:44 -06:00
|
|
|
end
|
2017-06-24 05:09:46 -06:00
|
|
|
|
2018-11-30 09:08:02 -07:00
|
|
|
test "it doesn't add nil in the to field" do
|
2017-08-24 04:54:01 -06:00
|
|
|
incoming = File.read!("test/fixtures/nil_mention_entry.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
assert activity.data["to"] == [
|
|
|
|
"http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers",
|
|
|
|
"https://www.w3.org/ns/activitystreams#Public"
|
|
|
|
]
|
2017-08-24 04:54:01 -06:00
|
|
|
end
|
2018-11-10 03:39:42 -07:00
|
|
|
|
|
|
|
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)
|
2019-07-08 10:53:02 -06:00
|
|
|
note_object = Object.normalize(note_activity)
|
2018-11-10 03:39:42 -07:00
|
|
|
|
|
|
|
note_data =
|
|
|
|
note_object.data
|
|
|
|
|> Map.put("type", "Article")
|
|
|
|
|
2019-02-03 10:54:39 -07:00
|
|
|
Cachex.clear(:object_cache)
|
|
|
|
|
2018-11-10 03:39:42 -07:00
|
|
|
cs = Object.change(note_object, %{data: note_data})
|
2018-12-11 05:31:52 -07:00
|
|
|
{:ok, _article_object} = Repo.update(cs)
|
2018-11-10 03:39:42 -07:00
|
|
|
|
|
|
|
# the underlying object is now an Article instead of a note, so this should fail
|
|
|
|
refute OStatus.is_representable?(note_activity)
|
|
|
|
end
|
|
|
|
end
|
2019-09-12 00:59:34 -06:00
|
|
|
|
|
|
|
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
|
2017-04-24 10:46:34 -06:00
|
|
|
end
|