cc0975bb595a4a3d8883488474211b086919c5cf
[akkoma] / test / web / ostatus / ostatus_test.exs
1 defmodule Pleroma.Web.OStatusTest do
2 use Pleroma.DataCase
3 alias Pleroma.Web.OStatus
4 alias Pleroma.Web.XML
5
6 test "handle incoming notes" do
7 incoming = File.read!("test/fixtures/incoming_note_activity.xml")
8 {:ok, activity} = OStatus.handle_incoming(incoming)
9
10 assert activity.data["type"] == "Create"
11 assert activity.data["object"]["type"] == "Note"
12 assert activity.data["published"] == "2017-04-23T14:51:03+00:00"
13 assert activity.data["context"] == "tag:gs.example.org:4040,2017-04-23:objectType=thread:nonce=f09e22f58abd5c7b"
14 assert "http://pleroma.example.org:4000/users/lain3" in activity.data["to"]
15 end
16
17 test "handle incoming replies" do
18 incoming = File.read!("test/fixtures/incoming_note_activity_answer.xml")
19 {:ok, activity} = OStatus.handle_incoming(incoming)
20
21 assert activity.data["type"] == "Create"
22 assert activity.data["object"]["type"] == "Note"
23 assert activity.data["object"]["inReplyTo"] == "http://pleroma.example.org:4000/objects/55bce8fc-b423-46b1-af71-3759ab4670bc"
24 assert "http://pleroma.example.org:4000/users/lain5" in activity.data["to"]
25 end
26
27 describe "new remote user creation" do
28 test "tries to use the information in poco fields" do
29 # TODO make test local
30 uri = "https://social.heldscal.la/user/23211"
31
32 {:ok, user} = OStatus.find_or_make_user(uri)
33
34 user = Repo.get(Pleroma.User, user.id)
35 assert user.name == "Constance Variable"
36 assert user.nickname == "lambadalambda@social.heldscal.la"
37 assert user.local == false
38 assert user.info["uri"] == uri
39 assert user.ap_id == uri
40
41 {:ok, user_again} = OStatus.find_or_make_user(uri)
42
43 assert user == user_again
44 end
45 end
46
47 describe "gathering user info from a user id" do
48 test "it returns user info in a hash" do
49 user = "shp@social.heldscal.la"
50
51 # TODO: make test local
52 {:ok, data} = OStatus.gather_user_info(user)
53
54 expected = %{
55 hub: "https://social.heldscal.la/main/push/hub",
56 magic_key: "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
57 name: "shp",
58 nickname: "shp",
59 salmon: "https://social.heldscal.la/main/salmon/user/29191",
60 subject: "acct:shp@social.heldscal.la",
61 topic: "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
62 uri: "https://social.heldscal.la/user/29191",
63 host: "social.heldscal.la",
64 fqn: user
65 }
66 assert data == expected
67 end
68
69 test "it works with the uri" do
70 user = "https://social.heldscal.la/user/29191"
71
72 # TODO: make test local
73 {:ok, data} = OStatus.gather_user_info(user)
74
75 expected = %{
76 hub: "https://social.heldscal.la/main/push/hub",
77 magic_key: "RSA.wQ3i9UA0qmAxZ0WTIp4a-waZn_17Ez1pEEmqmqoooRsG1_BvpmOvLN0G2tEcWWxl2KOtdQMCiPptmQObeZeuj48mdsDZ4ArQinexY2hCCTcbV8Xpswpkb8K05RcKipdg07pnI7tAgQ0VWSZDImncL6YUGlG5YN8b5TjGOwk2VG8=.AQAB",
78 name: "shp",
79 nickname: "shp",
80 salmon: "https://social.heldscal.la/main/salmon/user/29191",
81 subject: "https://social.heldscal.la/user/29191",
82 topic: "https://social.heldscal.la/api/statuses/user_timeline/29191.atom",
83 uri: "https://social.heldscal.la/user/29191",
84 host: "social.heldscal.la",
85 fqn: user
86 }
87 assert data == expected
88 end
89 end
90 end