1 defmodule Pleroma.Web.OStatus.OStatusControllerTest do
2 use Pleroma.Web.ConnCase
4 alias Pleroma.{User, Repo}
5 alias Pleroma.Web.CommonAPI
6 alias Pleroma.Web.OStatus.ActivityRepresenter
9 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
13 test "decodes a salmon", %{conn: conn} do
15 salmon = File.read!("test/fixtures/salmon.xml")
19 |> put_req_header("content-type", "application/atom+xml")
20 |> post("/users/#{user.nickname}/salmon", salmon)
22 assert response(conn, 200)
25 test "decodes a salmon with a changed magic key", %{conn: conn} do
27 salmon = File.read!("test/fixtures/salmon.xml")
31 |> put_req_header("content-type", "application/atom+xml")
32 |> post("/users/#{user.nickname}/salmon", salmon)
34 assert response(conn, 200)
36 # Set a wrong magic-key for a user so it has to refetch
37 salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
40 User.Info.remote_user_creation(salmon_user.info, %{
42 "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
46 |> Ecto.Changeset.change()
47 |> Ecto.Changeset.put_embed(:info, info_cng)
52 |> put_req_header("content-type", "application/atom+xml")
53 |> post("/users/#{user.nickname}/salmon", salmon)
55 assert response(conn, 200)
58 test "gets a feed", %{conn: conn} do
59 note_activity = insert(:note_activity)
60 user = User.get_cached_by_ap_id(note_activity.data["actor"])
64 |> put_req_header("content-type", "application/atom+xml")
65 |> get("/users/#{user.nickname}/feed.atom")
67 assert response(conn, 200) =~ note_activity.data["object"]["content"]
70 test "returns 404 for a missing feed", %{conn: conn} do
73 |> put_req_header("content-type", "application/atom+xml")
74 |> get("/users/nonexisting/feed.atom")
76 assert response(conn, 404)
79 test "gets an object", %{conn: conn} do
80 note_activity = insert(:note_activity)
81 user = User.get_by_ap_id(note_activity.data["actor"])
82 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
83 url = "/objects/#{uuid}"
90 ActivityRepresenter.to_simple_form(note_activity, user, true)
91 |> ActivityRepresenter.wrap_with_entry()
92 |> :xmerl.export_simple(:xmerl_xml)
95 assert response(conn, 200) == expected
98 test "404s on private objects", %{conn: conn} do
99 note_activity = insert(:direct_note_activity)
100 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
103 |> get("/objects/#{uuid}")
107 test "404s on nonexisting objects", %{conn: conn} do
109 |> get("/objects/123")
113 test "gets an activity", %{conn: conn} do
114 note_activity = insert(:note_activity)
115 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
118 |> get("/activities/#{uuid}")
122 test "404s on private activities", %{conn: conn} do
123 note_activity = insert(:direct_note_activity)
124 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
127 |> get("/activities/#{uuid}")
131 test "404s on nonexistent activities", %{conn: conn} do
133 |> get("/activities/123")
137 test "gets a notice", %{conn: conn} do
138 note_activity = insert(:note_activity)
141 |> get("/notice/#{note_activity.id}")
145 test "gets a notice in AS2 format", %{conn: conn} do
146 note_activity = insert(:note_activity)
149 |> put_req_header("accept", "application/activity+json")
150 |> get("/notice/#{note_activity.id}")
151 |> json_response(200)
154 test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
155 note_activity = insert(:note_activity)
156 url = "/notice/#{note_activity.id}"
160 |> put_req_header("accept", "application/activity+json")
163 assert json_response(conn, 200)
167 {:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
168 url = "/notice/#{like_activity.id}"
170 assert like_activity.data["type"] == "Like"
174 |> put_req_header("accept", "application/activity+json")
177 assert response(conn, 404)
180 test "gets an activity in AS2 format", %{conn: conn} do
181 note_activity = insert(:note_activity)
182 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
183 url = "/activities/#{uuid}"
187 |> put_req_header("accept", "application/activity+json")
190 assert json_response(conn, 200)
193 test "404s a private notice", %{conn: conn} do
194 note_activity = insert(:direct_note_activity)
195 url = "/notice/#{note_activity.id}"
201 assert response(conn, 404)
204 test "404s a nonexisting notice", %{conn: conn} do
211 assert response(conn, 404)