aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/object/containment_test.exs59
-rw-r--r--test/object/fetcher_test.exs85
-rw-r--r--test/object_test.exs22
-rw-r--r--test/web/activity_pub/activity_pub_test.exs31
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs57
-rw-r--r--test/web/common_api/common_api_test.exs15
-rw-r--r--test/web/mastodon_api/status_view_test.exs12
-rw-r--r--test/web/ostatus/ostatus_test.exs89
-rw-r--r--test/web/twitter_api/twitter_api_test.exs24
-rw-r--r--test/web/twitter_api/views/activity_view_test.exs17
10 files changed, 301 insertions, 110 deletions
diff --git a/test/object/containment_test.exs b/test/object/containment_test.exs
new file mode 100644
index 000000000..268675c86
--- /dev/null
+++ b/test/object/containment_test.exs
@@ -0,0 +1,59 @@
+defmodule Pleroma.Object.ContainmentTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.User
+ alias Pleroma.Object.Containment
+ alias Pleroma.Web.ActivityPub.ActivityPub
+
+ import Pleroma.Factory
+
+ describe "general origin containment" do
+ test "contain_origin_from_id() catches obvious spoofing attempts" do
+ data = %{
+ "id" => "http://example.com/~alyssa/activities/1234.json"
+ }
+
+ :error =
+ Containment.contain_origin_from_id(
+ "http://example.org/~alyssa/activities/1234.json",
+ data
+ )
+ end
+
+ test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
+ data = %{
+ "id" => "http://example.com/~alyssa/activities/1234.json"
+ }
+
+ :ok =
+ Containment.contain_origin_from_id(
+ "http://example.com/~alyssa/activities/1234",
+ data
+ )
+ end
+
+ test "contain_origin_from_id() allows matching IDs" do
+ data = %{
+ "id" => "http://example.com/~alyssa/activities/1234.json"
+ }
+
+ :ok =
+ Containment.contain_origin_from_id(
+ "http://example.com/~alyssa/activities/1234.json",
+ data
+ )
+ end
+
+ test "users cannot be collided through fake direction spoofing attempts" do
+ user =
+ insert(:user, %{
+ nickname: "rye@niu.moe",
+ local: false,
+ ap_id: "https://niu.moe/users/rye",
+ follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
+ })
+
+ {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
+ end
+ end
+end
diff --git a/test/object/fetcher_test.exs b/test/object/fetcher_test.exs
new file mode 100644
index 000000000..3bbade9d1
--- /dev/null
+++ b/test/object/fetcher_test.exs
@@ -0,0 +1,85 @@
+defmodule Pleroma.Object.FetcherTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.{Activity, Object}
+ alias Pleroma.Object.Fetcher
+
+ import Pleroma.Factory
+
+ describe "actor origin containment" do
+ test "it rejects objects with a bogus origin" do
+ {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity.json")
+ end
+
+ test "it rejects objects when attributedTo is wrong (variant 1)" do
+ {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity2.json")
+ end
+
+ test "it rejects objects when attributedTo is wrong (variant 2)" do
+ {:error, _} = Fetcher.fetch_object_from_id("https://info.pleroma.site/activity3.json")
+ end
+ end
+
+ describe "fetching an object" do
+ test "it fetches an object" do
+ {:ok, object} =
+ Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} =
+ Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert [attachment] = object.data["attachment"]
+ assert is_list(attachment["url"])
+
+ assert object == object_again
+ end
+
+ test "it works with objects only available via Ostatus" do
+ {:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
+ assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
+ assert activity.data["id"]
+
+ {:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
+
+ assert object == object_again
+ end
+
+ test "it correctly stitches up conversations between ostatus and ap" do
+ last = "https://mstdn.io/users/mayuutann/statuses/99568293732299394"
+ {:ok, object} = Fetcher.fetch_object_from_id(last)
+
+ object = Object.get_by_ap_id(object.data["inReplyTo"])
+ assert object
+ end
+ end
+
+ describe "implementation quirks" do
+ test "it can fetch plume articles" do
+ {:ok, object} =
+ Fetcher.fetch_object_from_id(
+ "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
+ )
+
+ assert object
+ end
+
+ test "it can fetch peertube videos" do
+ {:ok, object} =
+ Fetcher.fetch_object_from_id(
+ "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
+ )
+
+ assert object
+ end
+
+ test "all objects with fake directions are rejected by the object fetcher" do
+ {:error, _} =
+ Fetcher.fetch_and_contain_remote_object_from_id(
+ "https://info.pleroma.site/activity4.json"
+ )
+ end
+ end
+end
diff --git a/test/object_test.exs b/test/object_test.exs
index 911757d57..a30efd48c 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -58,4 +58,26 @@ defmodule Pleroma.ObjectTest do
assert cached_object.data["type"] == "Tombstone"
end
end
+
+ describe "normalizer" do
+ test "fetches unknown objects by default" do
+ %Object{} =
+ object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367")
+
+ assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
+ end
+
+ test "fetches unknown objects when fetch_remote is explicitly true" do
+ %Object{} =
+ object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true)
+
+ assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367"
+ end
+
+ test "does not fetch unknown objects when fetch_remote is false" do
+ assert is_nil(
+ Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false)
+ )
+ end
+ end
end
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 17fec05b1..68bfb3858 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -192,8 +192,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
}
{:ok, %Activity{} = activity} = ActivityPub.insert(data)
- assert is_binary(activity.data["object"]["id"])
- assert %Object{} = Object.get_by_ap_id(activity.data["object"]["id"])
+ object = Object.normalize(activity.data["object"])
+
+ assert is_binary(object.data["id"])
+ assert %Object{} = Object.get_by_ap_id(activity.data["object"])
end
end
@@ -206,7 +208,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
to: ["user1", "user1", "user2"],
actor: user,
context: "",
- object: %{}
+ object: %{
+ "to" => ["user1", "user1", "user2"],
+ "type" => "Note",
+ "content" => "testing"
+ }
})
assert activity.data["to"] == ["user1", "user2"]
@@ -635,6 +641,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
+ describe "fetch the latest Follow" do
+ test "fetches the latest Follow activity" do
+ %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
+ follower = Repo.get_by(User, ap_id: activity.data["actor"])
+ followed = Repo.get_by(User, ap_id: activity.data["object"])
+
+ assert activity == Utils.fetch_latest_follow(follower, followed)
+ end
+ end
+
describe "fetching an object" do
test "it fetches an object" do
{:ok, object} =
@@ -871,15 +887,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
end
end
- test "it can fetch plume articles" do
- {:ok, object} =
- ActivityPub.fetch_object_from_id(
- "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
- )
-
- assert object
- end
-
describe "update" do
test "it creates an update activity with the new user data" do
user = insert(:user)
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index c857a7ec1..5559cdf87 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -50,14 +50,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|> Map.put("object", object)
{:ok, returned_activity} = Transmogrifier.handle_incoming(data)
+ returned_object = Object.normalize(returned_activity.data["object"])
assert activity =
Activity.get_create_by_object_ap_id(
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
)
- assert returned_activity.data["object"]["inReplyToAtomUri"] ==
- "https://shitposter.club/notice/2827873"
+ assert returned_object.data["inReplyToAtomUri"] == "https://shitposter.club/notice/2827873"
end
test "it works for incoming notices" do
@@ -80,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["actor"] == "http://mastodon.example.org/users/admin"
- object = data["object"]
+ object = Object.normalize(data["object"]).data
assert object["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822"
assert object["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
@@ -107,7 +107,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
- assert Enum.at(data["object"]["tag"], 2) == "moo"
+ object = Object.normalize(data["object"])
+
+ assert Enum.at(object.data["tag"], 2) == "moo"
end
test "it works for incoming notices with contentMap" do
@@ -115,8 +117,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["content"] ==
+ assert object.data["content"] ==
"<p><span class=\"h-card\"><a href=\"http://localtesting.pleroma.lol/users/lain\" class=\"u-url mention\">@<span>lain</span></a></span></p>"
end
@@ -124,8 +127,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = File.read!("test/fixtures/kroeg-post-activity.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["content"] ==
+ assert object.data["content"] ==
"<p>henlo from my Psion netBook</p><p>message sent from my Psion netBook</p>"
end
@@ -141,24 +145,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["emoji"] == %{
+ assert object.data["emoji"] == %{
"icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png"
}
data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert "test" in data["object"]["tag"]
+ assert "test" in object.data["tag"]
end
test "it works for incoming notices with url not being a string (prismo)" do
data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!()
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
+ object = Object.normalize(data["object"])
- assert data["object"]["url"] == "https://prismo.news/posts/83"
+ assert object.data["url"] == "https://prismo.news/posts/83"
end
test "it cleans up incoming notices which are not really DMs" do
@@ -231,14 +238,14 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-like.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
assert data["actor"] == "http://mastodon.example.org/users/admin"
assert data["type"] == "Like"
assert data["id"] == "http://mastodon.example.org/users/admin#likes/2"
- assert data["object"] == activity.data["object"]["id"]
+ assert data["object"] == activity.data["object"]
end
test "it returns an error for incoming unlikes wihout a like activity" do
@@ -248,7 +255,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-undo-like.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
assert Transmogrifier.handle_incoming(data) == :error
end
@@ -260,7 +267,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
like_data =
File.read!("test/fixtures/mastodon-like.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: like_data, local: false}} = Transmogrifier.handle_incoming(like_data)
@@ -302,7 +309,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
data =
File.read!("test/fixtures/mastodon-announce.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
@@ -312,7 +319,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["id"] ==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
- assert data["object"] == activity.data["object"]["id"]
+ assert data["object"] == activity.data["object"]
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
end
@@ -450,7 +457,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
object =
data["object"]
- |> Map.put("id", activity.data["object"]["id"])
+ |> Map.put("id", activity.data["object"])
data =
data
@@ -471,7 +478,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
object =
data["object"]
- |> Map.put("id", activity.data["object"]["id"])
+ |> Map.put("id", activity.data["object"])
data =
data
@@ -489,7 +496,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
announce_data =
File.read!("test/fixtures/mastodon-announce.json")
|> Poison.decode!()
- |> Map.put("object", activity.data["object"]["id"])
+ |> Map.put("object", activity.data["object"])
{:ok, %Activity{data: announce_data, local: false}} =
Transmogrifier.handle_incoming(announce_data)
@@ -504,7 +511,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert data["type"] == "Undo"
assert data["object"]["type"] == "Announce"
- assert data["object"]["object"] == activity.data["object"]["id"]
+ assert data["object"]["object"] == activity.data["object"]
assert data["object"]["id"] ==
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
@@ -1088,10 +1095,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
end
describe "actor origin containment" do
- test "it rejects objects with a bogus origin" do
- {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity.json")
- end
-
test "it rejects activities which reference objects with bogus origins" do
data = %{
"@context" => "https://www.w3.org/ns/activitystreams",
@@ -1105,10 +1108,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(data)
end
- test "it rejects objects when attributedTo is wrong (variant 1)" do
- {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity2.json")
- end
-
test "it rejects activities which reference objects that have an incorrect attribution (variant 1)" do
data = %{
"@context" => "https://www.w3.org/ns/activitystreams",
@@ -1122,10 +1121,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:error = Transmogrifier.handle_incoming(data)
end
- test "it rejects objects when attributedTo is wrong (variant 2)" do
- {:error, _} = ActivityPub.fetch_object_from_id("https://info.pleroma.site/activity3.json")
- end
-
test "it rejects activities which reference objects that have an incorrect attribution (variant 2)" do
data = %{
"@context" => "https://www.w3.org/ns/activitystreams",
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 34aa5bf18..b9ed088e4 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Activity
alias Pleroma.User
+ alias Pleroma.Object
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -32,7 +33,9 @@ defmodule Pleroma.Web.CommonAPITest do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
- assert activity.data["object"]["tag"] == ["2hu"]
+ object = Object.normalize(activity.data["object"])
+
+ assert object.data["tag"] == ["2hu"]
end
test "it adds emoji in the object" do
@@ -64,8 +67,9 @@ defmodule Pleroma.Web.CommonAPITest do
"content_type" => "text/html"
})
- content = activity.data["object"]["content"]
- assert content == "<p><b>2hu</b></p>alert('xss')"
+ object = Object.normalize(activity.data["object"])
+
+ 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
@@ -79,8 +83,9 @@ defmodule Pleroma.Web.CommonAPITest do
"content_type" => "text/markdown"
})
- content = activity.data["object"]["content"]
- assert content == "<p><b>2hu</b></p>alert('xss')"
+ object = Object.normalize(activity.data["object"])
+
+ assert object.data["content"] == "<p><b>2hu</b></p>alert('xss')"
end
end
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index db2fdc2f6..4ea50c7c6 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -7,6 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
alias Pleroma.Activity
alias Pleroma.User
+ alias Pleroma.Repo
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
@@ -53,14 +55,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
test "a note with null content" do
note = insert(:note_activity)
+ note_object = Object.normalize(note.data["object"])
data =
- note.data
- |> put_in(["object", "content"], nil)
+ note_object.data
+ |> Map.put("content", nil)
- note =
- note
- |> Map.put(:data, data)
+ Object.change(note_object, %{data: data})
+ |> Repo.update()
User.get_cached_by_ap_id(note.data["actor"])
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 9fd100f63..50467c71f 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -28,34 +28,35 @@ defmodule Pleroma.Web.OStatusTest do
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.data["object"])
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 object.data["type"] == "Note"
- assert activity.data["object"]["id"] ==
- "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=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 activity.data["object"]["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 activity.data["object"]["emoji"] == %{"marko" => "marko.png", "reimu" => "reimu.png"}
+ 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.data["object"])
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"] == "Will it blend?"
+ 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"]
@@ -64,20 +65,22 @@ defmodule Pleroma.Web.OStatusTest do
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.data["object"])
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"]["attachment"] |> length == 2
- assert activity.data["object"]["external_url"] == "https://social.heldscal.la/notice/2020923"
+ 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.data["object"])
- assert activity.data["object"]["tag"] == ["nsfw"]
+ assert object.data["tag"] == ["nsfw"]
assert "https://www.w3.org/ns/activitystreams#Public" in activity.data["to"]
end
@@ -92,10 +95,11 @@ defmodule Pleroma.Web.OStatusTest do
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
+ 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
@@ -103,42 +107,47 @@ defmodule Pleroma.Web.OStatusTest do
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.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
- assert activity.data["object"]["summary"] == "technologic"
+ 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.data["object"])
+
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"]
+ 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.data["object"])
- assert retweeted_activity.data["object"]["summary"] == "Hey."
+ 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.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
- assert activity.data["object"]["actor"] == "https://social.heldscal.la/user/23211"
+ assert object.data["type"] == "Note"
+ assert object.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"]["content"] ==
+ 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 activity.data["object"]["inReplyTo"] ==
+ 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"]
@@ -150,17 +159,18 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["type"] == "Announce"
assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
- assert activity.data["object"] == retweeted_activity.data["object"]["id"]
+ 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.data["object"])
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
refute retweeted_activity.local
- assert retweeted_activity.data["object"]["announcement_count"] == 1
- assert String.contains?(retweeted_activity.data["object"]["content"], "mastodon")
- refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
+ 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
@@ -192,10 +202,11 @@ defmodule Pleroma.Web.OStatusTest do
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.data["object"])
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["object"] == retweeted_activity.data["object"]
assert activity.data["id"] ==
"tag:mastodon.social,2017-05-03:objectId=4934452:objectType=Status"
@@ -204,7 +215,7 @@ defmodule Pleroma.Web.OStatusTest do
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_activity.data["object"]["content"], "Test account")
+ refute String.contains?(retweeted_object.data["content"], "Test account")
end
test "handle incoming favorites - GS, websub" do
@@ -214,7 +225,7 @@ defmodule Pleroma.Web.OStatusTest do
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["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"
@@ -223,7 +234,7 @@ defmodule Pleroma.Web.OStatusTest do
assert favorited_activity.data["type"] == "Create"
assert favorited_activity.data["actor"] == "https://shitposter.club/user/1"
- assert favorited_activity.data["object"]["id"] ==
+ assert favorited_activity.data["object"] ==
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
refute favorited_activity.local
@@ -258,17 +269,17 @@ defmodule Pleroma.Web.OStatusTest do
test "handle incoming replies" do
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
{:ok, [activity]} = OStatus.handle_incoming(incoming)
+ object = Object.normalize(activity.data["object"])
assert activity.data["type"] == "Create"
- assert activity.data["object"]["type"] == "Note"
+ assert object.data["type"] == "Note"
- assert activity.data["object"]["inReplyTo"] ==
+ 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 activity.data["object"]["id"] ==
- "tag:gs.example.org:4040,2017-04-25:noticeId=55:objectType=note"
+ 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"]
end
@@ -495,7 +506,7 @@ defmodule Pleroma.Web.OStatusTest do
assert activity.data["actor"] == "https://shitposter.club/user/1"
- assert activity.data["object"]["id"] ==
+ assert activity.data["object"] ==
"tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
end)
end
@@ -504,7 +515,7 @@ defmodule Pleroma.Web.OStatusTest 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
+ assert activity.data["object"] == url
end
end
diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs
index 4c9ae2da8..5bea1037a 100644
--- a/test/web/twitter_api/twitter_api_test.exs
+++ b/test/web/twitter_api/twitter_api_test.exs
@@ -46,13 +46,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+ object = Object.normalize(activity.data["object"])
expected_text =
"Hello again, <span class='h-card'><a data-user='#{mentioned_user.id}' class='u-url mention' href='shp'>@<span>shp</span></a></span>.&lt;script&gt;&lt;/script&gt;<br>This is on another :moominmamma: line. <a class='hashtag' data-tag='2hu' href='http://localhost:4001/tag/2hu' rel='tag'>#2hu</a> <a class='hashtag' data-tag='epic' href='http://localhost:4001/tag/epic' rel='tag'>#epic</a> <a class='hashtag' data-tag='phantasmagoric' href='http://localhost:4001/tag/phantasmagoric' rel='tag'>#phantasmagoric</a><br><a href=\"http://example.org/image.jpg\" class='attachment'>image.jpg</a>"
- assert get_in(activity.data, ["object", "content"]) == expected_text
- assert get_in(activity.data, ["object", "type"]) == "Note"
- assert get_in(activity.data, ["object", "actor"]) == user.ap_id
+ assert get_in(object.data, ["content"]) == expected_text
+ assert get_in(object.data, ["type"]) == "Note"
+ assert get_in(object.data, ["actor"]) == user.ap_id
assert get_in(activity.data, ["actor"]) == user.ap_id
assert Enum.member?(get_in(activity.data, ["cc"]), User.ap_followers(user))
@@ -65,18 +66,18 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
assert activity.local == true
assert %{"moominmamma" => "http://localhost:4001/finmoji/128px/moominmamma-128.png"} =
- activity.data["object"]["emoji"]
+ object.data["emoji"]
# hashtags
- assert activity.data["object"]["tag"] == ["2hu", "epic", "phantasmagoric"]
+ assert object.data["tag"] == ["2hu", "epic", "phantasmagoric"]
# Add a context
assert is_binary(get_in(activity.data, ["context"]))
- assert is_binary(get_in(activity.data, ["object", "context"]))
+ assert is_binary(get_in(object.data, ["context"]))
- assert is_list(activity.data["object"]["attachment"])
+ assert is_list(object.data["attachment"])
- assert activity.data["object"] == Object.get_by_ap_id(activity.data["object"]["id"]).data
+ assert activity.data["object"] == object.data["id"]
user = User.get_by_ap_id(user.ap_id)
@@ -91,6 +92,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, activity = %Activity{}} = TwitterAPI.create_status(user, input)
+ object = Object.normalize(activity.data["object"])
input = %{
"status" => "Here's your (you).",
@@ -98,13 +100,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
}
{:ok, reply = %Activity{}} = TwitterAPI.create_status(user, input)
+ reply_object = Object.normalize(reply.data["object"])
assert get_in(reply.data, ["context"]) == get_in(activity.data, ["context"])
- assert get_in(reply.data, ["object", "context"]) ==
- get_in(activity.data, ["object", "context"])
+ assert get_in(reply_object.data, ["context"]) == get_in(object.data, ["context"])
- assert get_in(reply.data, ["object", "inReplyTo"]) == get_in(activity.data, ["object", "id"])
+ assert get_in(reply_object.data, ["inReplyTo"]) == get_in(activity.data, ["object"])
assert Activity.get_in_reply_to_activity(reply).id == activity.id
end
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index ee9a0c834..7ef0270cc 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -125,10 +126,11 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+ object = Object.normalize(activity.data["object"])
result = ActivityView.render("activity.json", activity: activity)
- convo_id = Utils.context_to_conversation_id(activity.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object.data["context"])
expected = %{
"activity_type" => "post",
@@ -136,8 +138,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"attentions" => [
UserView.render("show.json", %{user: other_user})
],
- "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
- "external_url" => activity.data["object"]["id"],
+ "created_at" => object.data["published"] |> Utils.date_to_asctime(),
+ "external_url" => object.data["id"],
"fave_num" => 0,
"favorited" => false,
"id" => activity.id,
@@ -161,7 +163,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
}\">@<span>shp</span></a></span>!",
"tags" => [],
"text" => "Hey @shp!",
- "uri" => activity.data["object"]["id"],
+ "uri" => object.data["id"],
"user" => UserView.render("show.json", %{user: user}),
"visibility" => "direct",
"card" => nil,
@@ -175,8 +177,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
user = insert(:user)
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+ object = Object.normalize(activity.data["object"])
- convo_id = Utils.context_to_conversation_id(activity.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object.data["context"])
mocks = [
{
@@ -277,9 +280,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
other_user = insert(:user, %{nickname: "shp"})
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
- {:ok, announce, _object} = CommonAPI.repeat(activity.id, other_user)
+ {:ok, announce, object} = CommonAPI.repeat(activity.id, other_user)
- convo_id = Utils.context_to_conversation_id(activity.data["object"]["context"])
+ convo_id = Utils.context_to_conversation_id(object.data["context"])
activity = Activity.get_by_id(activity.id)