pleroma/test/web/ostatus/ostatus_test.exs

100 lines
3.8 KiB
Elixir
Raw Normal View History

defmodule Pleroma.Web.OStatusTest do
use Pleroma.DataCase
alias Pleroma.Web.OStatus
2017-04-29 19:13:21 +00:00
test "handle incoming note - GS, Salmon" do
incoming = File.read!("test/fixtures/incoming_note_activity.xml")
2017-04-29 19:13:21 +00:00
{:ok, [activity]} = OStatus.handle_incoming(incoming)
assert activity.data["type"] == "Create"
assert activity.data["object"]["type"] == "Note"
assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
2017-04-25 15:45:34 +00:00
assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
2017-04-25 16:03:14 +00:00
assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
end
2017-04-29 19:13:21 +00: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-04-26 08:22:51 +00:00
test "handle incoming replies" do
incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
2017-04-29 19:13:21 +00:00
{:ok, [activity]} = OStatus.handle_incoming(incoming)
2017-04-26 08:22:51 +00: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
describe "new remote user creation" do
test "tries to use the information in poco fields" do
2017-04-29 17:06:01 +00:00
# TODO make test local
uri = "https://social.heldscal.la/user/23211"
2017-04-29 17:06:01 +00:00
{:ok, user} = OStatus.find_or_make_user(uri)
2017-04-29 17:06:01 +00:00
user = Repo.get(Pleroma.User, user.id)
assert user.name == "Constance Variable"
assert user.nickname == "lambadalambda@social.heldscal.la"
assert user.local == false
2017-04-29 17:06:01 +00:00
assert user.info["uri"] == uri
assert user.ap_id == uri
2017-04-29 17:06:01 +00:00
{:ok, user_again} = OStatus.find_or_make_user(uri)
assert user == user_again
end
end
2017-04-29 15:51:59 +00: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 = %{
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",
2017-04-29 15:51:59 +00:00
fqn: user
}
assert data == expected
end
2017-04-29 17:06:01 +00: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 = %{
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",
2017-04-29 17:06:01 +00:00
fqn: user
}
assert data == expected
end
2017-04-29 15:51:59 +00:00
end
end