X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fostatus%2Fostatus_test.exs;h=e577a6bee50e1cadc01a3f5e33e656c837683926;hb=f672555ad347861617c9b9b2c323b5044e840649;hp=e40fae78cc3a1d22f5386ab7cc6a998b236f0db5;hpb=c7fdd1b7ff6e7a08389395d555862eaec9721b08;p=akkoma
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index e40fae78c..e577a6bee 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -4,6 +4,12 @@ defmodule Pleroma.Web.OStatusTest do
alias Pleroma.Web.XML
alias Pleroma.{Object, Repo, User, Activity}
import Pleroma.Factory
+ import ExUnit.CaptureLog
+
+ 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")
@@ -15,12 +21,22 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ user = User.get_by_ap_id(activity.data["actor"])
+ assert user.info.note_count == 1
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
+
+ assert activity.data["object"]["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 activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
+ assert activity.data["object"]["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 activity.data["object"]["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
assert activity.local == false
end
@@ -34,6 +50,7 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"]["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
@@ -44,6 +61,8 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
assert activity.data["object"]["attachment"] |> length == 2
+ assert activity.data["object"]["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
@@ -51,15 +70,18 @@ defmodule Pleroma.Web.OStatusTest do
{:ok, [activity]} = OStatus.handle_incoming(incoming)
assert activity.data["object"]["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"
- }})
+ 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)
@@ -67,6 +89,7 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["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
@@ -76,14 +99,24 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
- assert String.contains?(activity.data["object"]["content"], "technologic")
+ assert activity.data["object"]["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)
+ 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 activity.data["object"]["to"]
+ assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["object"]["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)
+ {:ok, [[_activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
- assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.")
+ assert retweeted_activity.data["object"]["summary"] == "Hey."
end
test "handle incoming notes - GS, subscription, reply" do
@@ -93,8 +126,14 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"]["content"] == "@shpbot why not indeed."
- assert activity.data["object"]["inReplyTo"] == "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
+
+ assert activity.data["object"]["content"] ==
+ "@shpbot why not indeed."
+
+ assert activity.data["object"]["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
@@ -120,9 +159,11 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/share-gs-local.xml")
note_activity = insert(:note_activity)
user = User.get_cached_by_ap_id(note_activity.data["actor"])
- incoming = incoming
- |> String.replace("LOCAL_ID", note_activity.data["object"]["id"])
- |> String.replace("LOCAL_USER", user.ap_id)
+
+ incoming =
+ incoming
+ |> String.replace("LOCAL_ID", note_activity.data["object"]["id"])
+ |> String.replace("LOCAL_USER", user.ap_id)
{:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
@@ -147,7 +188,9 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://mastodon.social/users/lambadalambda"
assert activity.data["object"] == retweeted_activity.data["object"]["id"]
- assert activity.data["id"] == "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
+
+ assert activity.data["id"] ==
+ "tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
refute activity.local
assert retweeted_activity.data["type"] == "Create"
@@ -157,26 +200,42 @@ defmodule Pleroma.Web.OStatusTest do
end
test "handle incoming favorites - GS, websub" do
- incoming = File.read!("test/fixtures/favorite.xml")
- {:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
+ 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"]["id"]
- assert activity.data["id"] == "tag:social.heldscal.la,2017-05-05:fave:23211:comment:2061643:2017-05-05T09:12:50+00:00"
+ assert activity.data["type"] == "Like"
+ assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
+ assert activity.data["object"] == favorited_activity.data["object"]["id"]
- refute activity.local
- assert favorited_activity.data["type"] == "Create"
- assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
- assert favorited_activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
- refute favorited_activity.local
+ 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"]["id"] ==
+ "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)
- incoming = File.read!("test/fixtures/favorite_with_local_note.xml")
- |> String.replace("localid", note_activity.data["object"]["id"])
+ incoming =
+ File.read!("test/fixtures/favorite_with_local_note.xml")
+ |> String.replace("localid", note_activity.data["object"]["id"])
{:ok, [[activity, favorited_activity]]} = OStatus.handle_incoming(incoming)
@@ -194,16 +253,26 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
+
+ assert activity.data["object"]["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 activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
+
+ assert activity.data["object"]["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"]
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["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
@@ -214,6 +283,30 @@ defmodule Pleroma.Web.OStatusTest do
assert User.following?(follower, followed)
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"
+ assert is_map(activity.data["object"])
+ assert activity.data["object"]["type"] == "Follow"
+ assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino"
+ refute activity.local
+
+ follower = User.get_by_ap_id(activity.data["actor"])
+ followed = User.get_by_ap_id(activity.data["object"]["object"])
+
+ refute User.following?(follower, followed)
+ end
+
describe "new remote user creation" do
test "returns local users" do
local_user = insert(:user)
@@ -231,7 +324,7 @@ defmodule Pleroma.Web.OStatusTest do
assert user.name == "Constance Variable"
assert user.nickname == "lambadalambda@social.heldscal.la"
assert user.local == false
- assert user.info["uri"] == uri
+ assert user.info.uri == uri
assert user.ap_id == uri
assert user.bio == "Call me Deacon Blues."
assert user.avatar["type"] == "Image"
@@ -241,6 +334,38 @@ defmodule Pleroma.Web.OStatusTest do
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 ==
+ %Pleroma.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_user takes an author element and returns an updated user" do
uri = "https://social.heldscal.la/user/23211"
@@ -273,7 +398,8 @@ defmodule Pleroma.Web.OStatusTest do
expected = %{
"hub" => "https://social.heldscal.la/main/push/hub",
- "magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
+ "magic_key" =>
+ "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
"name" => "shp",
"nickname" => "shp",
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
@@ -283,8 +409,20 @@ defmodule Pleroma.Web.OStatusTest do
"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"}]}
+ "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
@@ -296,7 +434,8 @@ defmodule Pleroma.Web.OStatusTest do
expected = %{
"hub" => "https://social.heldscal.la/main/push/hub",
- "magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
+ "magic_key" =>
+ "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
"name" => "shp",
"nickname" => "shp",
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
@@ -306,19 +445,76 @@ defmodule Pleroma.Web.OStatusTest do
"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"}]}
+ "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
- url = "https://shitposter.club/notice/2827873"
- {:ok, [activity] } = OStatus.fetch_activity_from_html_url(url)
+ 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"]["id"] ==
+ "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"]["id"] == 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.data["object"])
+
+ note_data =
+ note_object.data
+ |> Map.put("type", "Article")
+
+ cs = Object.change(note_object, %{data: note_data})
+ {:ok, _article_object} = Repo.update(cs)
- assert activity.data["actor"] == "https://shitposter.club/user/1"
- assert activity.data["object"]["id"] == "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+ # the underlying object is now an Article instead of a note, so this should fail
+ refute OStatus.is_representable?(note_activity)
end
end
end