Commit 4ca4c838 authored by kaniini's avatar kaniini

tests: fix most remaining failures

parent cf139e3e
......@@ -77,8 +77,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
......
......@@ -4,7 +4,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.OStatus
alias Pleroma.Activity
alias Pleroma.{Activity, Object}
alias Pleroma.User
alias Pleroma.Repo
alias Pleroma.Web.Websub.WebsubClientSubscription
......@@ -40,16 +40,16 @@ 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_activity_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"
assert returned_activity.data["object"]["inReplyToStatusId"] == activity.id
assert returned_object.data["inReplyToStatusId"] == activity.id
end
test "it works for incoming notices" do
......@@ -72,7 +72,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"]
......@@ -99,7 +99,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
......@@ -107,8 +109,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
......@@ -116,8 +119,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
......@@ -133,24 +137,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 works for incoming follow requests" do
......@@ -193,14 +200,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
......@@ -210,7 +217,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
......@@ -222,7 +229,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)
......@@ -264,7 +271,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)
......@@ -274,7 +281,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_activity_by_object_ap_id(data["object"]).id == activity.id
end
......@@ -349,7 +356,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
......@@ -370,7 +377,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
......@@ -388,7 +395,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)
......@@ -403,7 +410,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"
......
defmodule Pleroma.Web.CommonAPI.Test do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.User
alias Pleroma.{User, Object}
import Pleroma.Factory
......@@ -9,7 +9,9 @@ defmodule Pleroma.Web.CommonAPI.Test 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 when updating profiles" do
......@@ -34,8 +36,10 @@ defmodule Pleroma.Web.CommonAPI.Test 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
......@@ -49,8 +53,10 @@ defmodule Pleroma.Web.CommonAPI.Test 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
end
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment