2017-04-24 09:46:34 -07:00
|
|
|
defmodule Pleroma.Web.OStatusTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
alias Pleroma.Web.OStatus
|
2017-05-02 08:13:41 -07:00
|
|
|
alias Pleroma.Web.XML
|
2017-05-02 12:31:01 -07:00
|
|
|
alias Pleroma.{Object, Repo}
|
2017-04-24 09:46:34 -07:00
|
|
|
|
2017-04-30 03:36:47 -07:00
|
|
|
test "don't insert create notes twice" do
|
|
|
|
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
|
|
|
{:ok, [_activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
assert {:ok, [{:error, "duplicate activity"}]} == OStatus.handle_incoming(incoming)
|
|
|
|
end
|
|
|
|
|
2017-04-29 12:13:21 -07:00
|
|
|
test "handle incoming note - GS, Salmon" do
|
2017-04-24 09:46:34 -07:00
|
|
|
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
|
2017-04-29 12:13:21 -07:00
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2017-04-24 09:46:34 -07:00
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
|
|
|
assert activity.data["object"]["type"] == "Note"
|
2017-04-30 02:55:19 -07:00
|
|
|
assert activity.data["object"]["id"] == "tag:gs.example.org:4040,2017-04-23:noticeId=29:objectType=note"
|
2017-04-24 09:46:34 -07:00
|
|
|
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
|
2017-04-25 08:45:34 -07:00
|
|
|
assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
|
2017-04-25 09:03:14 -07:00
|
|
|
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
|
2017-05-02 01:47:04 -07:00
|
|
|
assert activity.local == false
|
2017-04-24 09:46:34 -07:00
|
|
|
end
|
|
|
|
|
2017-04-29 12:13:21 -07:00
|
|
|
test "handle incoming notes - GS, subscription" do
|
|
|
|
incoming = File.read!("test/fixtures/ostatus_incoming_post.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
|
|
|
|
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?"
|
|
|
|
end
|
|
|
|
|
2017-05-03 05:26:49 -07:00
|
|
|
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)
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2017-05-02 12:31:01 -07:00
|
|
|
test "handle incoming notes - Mastodon, salmon, reply" do
|
|
|
|
# It uses the context of the replied to object
|
|
|
|
Repo.insert!(%Object{
|
|
|
|
data: %{
|
|
|
|
"id" => "https://pleroma.soykaf.com/objects/c237d966-ac75-4fe3-a87a-d89d71a3a7a4",
|
|
|
|
"context" => "2hu"
|
|
|
|
}})
|
|
|
|
incoming = File.read!("test/fixtures/incoming_reply_mastodon.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
|
|
|
|
assert activity.data["type"] == "Create"
|
|
|
|
assert activity.data["object"]["type"] == "Note"
|
|
|
|
assert activity.data["object"]["actor"] == "https://mastodon.social/users/lambadalambda"
|
|
|
|
assert activity.data["context"] == "2hu"
|
|
|
|
end
|
|
|
|
|
2017-04-30 02:39:27 -07:00
|
|
|
test "handle incoming notes - GS, subscription, reply" do
|
|
|
|
incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
|
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
|
|
|
|
|
|
|
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"] == "@<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"] == "tag:gs.archae.me,2017-04-30:noticeId=778260:objectType=note"
|
|
|
|
end
|
|
|
|
|
2017-04-26 01:22:51 -07:00
|
|
|
test "handle incoming replies" do
|
|
|
|
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
|
2017-04-29 12:13:21 -07:00
|
|
|
{:ok, [activity]} = OStatus.handle_incoming(incoming)
|
2017-04-26 01:22:51 -07:00
|
|
|
|
|
|
|
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 "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
|
|
|
|
end
|
|
|
|
|
2017-04-24 09:46:34 -07:00
|
|
|
describe "new remote user creation" do
|
|
|
|
test "tries to use the information in poco fields" do
|
2017-04-29 10:06:01 -07:00
|
|
|
# TODO make test local
|
|
|
|
uri = "https://social.heldscal.la/user/23211"
|
2017-04-24 09:46:34 -07:00
|
|
|
|
2017-04-29 10:06:01 -07:00
|
|
|
{:ok, user} = OStatus.find_or_make_user(uri)
|
2017-04-24 09:46:34 -07:00
|
|
|
|
2017-04-29 10:06:01 -07:00
|
|
|
user = Repo.get(Pleroma.User, user.id)
|
2017-04-24 09:46:34 -07:00
|
|
|
assert user.name == "Constance Variable"
|
2017-04-29 11:08:45 -07:00
|
|
|
assert user.nickname == "lambadalambda@social.heldscal.la"
|
2017-04-24 09:46:34 -07:00
|
|
|
assert user.local == false
|
2017-04-29 10:06:01 -07:00
|
|
|
assert user.info["uri"] == uri
|
|
|
|
assert user.ap_id == uri
|
2017-04-30 03:53:49 -07:00
|
|
|
assert user.avatar["type"] == "Image"
|
2017-04-24 09:46:34 -07:00
|
|
|
|
2017-04-29 10:06:01 -07:00
|
|
|
{:ok, user_again} = OStatus.find_or_make_user(uri)
|
2017-04-24 09:46:34 -07:00
|
|
|
|
|
|
|
assert user == user_again
|
|
|
|
end
|
2017-05-02 08:13:41 -07:00
|
|
|
|
|
|
|
test "find_make_or_update_user takes an author element and returns an updated user" do
|
|
|
|
# TODO make test local
|
|
|
|
uri = "https://social.heldscal.la/user/23211"
|
|
|
|
|
|
|
|
{:ok, user} = OStatus.find_or_make_user(uri)
|
|
|
|
change = Ecto.Changeset.change(user, %{avatar: nil})
|
|
|
|
|
|
|
|
{:ok, user} = Repo.update(change)
|
|
|
|
refute user.avatar
|
|
|
|
|
|
|
|
doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
|
|
|
|
[author] = :xmerl_xpath.string('//author[1]', doc)
|
|
|
|
{:ok, user} = OStatus.find_make_or_update_user(author)
|
|
|
|
assert user.avatar["type"] == "Image"
|
|
|
|
|
|
|
|
{:ok, user_again} = OStatus.find_make_or_update_user(author)
|
|
|
|
assert user_again == user
|
|
|
|
end
|
2017-04-24 09:46:34 -07:00
|
|
|
end
|
2017-04-29 08:51:59 -07: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 05:26:49 -07:00
|
|
|
"hub" => "https://social.heldscal.la/main/push/hub",
|
|
|
|
"magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
|
|
|
|
"name" => "shp",
|
|
|
|
"nickname" => "shp",
|
|
|
|
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
|
|
|
|
"subject" => "acct:shp@social.heldscal.la",
|
|
|
|
"topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
|
|
|
|
"uri" => "https://social.heldscal.la/user/29191",
|
|
|
|
"host" => "social.heldscal.la",
|
|
|
|
"fqn" => user,
|
|
|
|
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}
|
2017-04-29 08:51:59 -07:00
|
|
|
}
|
|
|
|
assert data == expected
|
|
|
|
end
|
2017-04-29 10:06:01 -07: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 05:26:49 -07:00
|
|
|
"hub" => "https://social.heldscal.la/main/push/hub",
|
|
|
|
"magic_key" => "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
|
|
|
|
"name" => "shp",
|
|
|
|
"nickname" => "shp",
|
|
|
|
"salmon" => "https://social.heldscal.la/main/salmon/user/29191",
|
|
|
|
"subject" => "https://social.heldscal.la/user/29191",
|
|
|
|
"topic" => "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
|
|
|
|
"uri" => "https://social.heldscal.la/user/29191",
|
|
|
|
"host" => "social.heldscal.la",
|
|
|
|
"fqn" => user,
|
|
|
|
"avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}
|
2017-04-29 10:06:01 -07:00
|
|
|
}
|
|
|
|
assert data == expected
|
|
|
|
end
|
2017-04-29 08:51:59 -07:00
|
|
|
end
|
2017-04-24 09:46:34 -07:00
|
|
|
end
|