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
8 test "decodes a salmon", %{conn: conn} do
10 salmon = File.read!("test/fixtures/salmon.xml")
14 |> put_req_header("content-type", "application/atom+xml")
15 |> post("/users/#{user.nickname}/salmon", salmon)
17 assert response(conn, 200)
20 test "decodes a salmon with a changed magic key", %{conn: conn} do
22 salmon = File.read!("test/fixtures/salmon.xml")
26 |> put_req_header("content-type", "application/atom+xml")
27 |> post("/users/#{user.nickname}/salmon", salmon)
29 assert response(conn, 200)
31 # Set a wrong magic-key for a user so it has to refetch
32 salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
38 "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwrong1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB"
41 Repo.update(User.info_changeset(salmon_user, %{info: info}))
45 |> put_req_header("content-type", "application/atom+xml")
46 |> post("/users/#{user.nickname}/salmon", salmon)
48 assert response(conn, 200)
51 test "gets a feed", %{conn: conn} do
52 note_activity = insert(:note_activity)
53 user = User.get_cached_by_ap_id(note_activity.data["actor"])
57 |> put_req_header("content-type", "application/atom+xml")
58 |> get("/users/#{user.nickname}/feed.atom")
60 assert response(conn, 200) =~ note_activity.data["object"]["content"]
63 test "returns 404 for a missing feed", %{conn: conn} do
66 |> put_req_header("content-type", "application/atom+xml")
67 |> get("/users/nonexisting/feed.atom")
69 assert response(conn, 404)
72 test "gets an object", %{conn: conn} do
73 note_activity = insert(:note_activity)
74 user = User.get_by_ap_id(note_activity.data["actor"])
75 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
76 url = "/objects/#{uuid}"
83 ActivityRepresenter.to_simple_form(note_activity, user, true)
84 |> ActivityRepresenter.wrap_with_entry()
85 |> :xmerl.export_simple(:xmerl_xml)
88 assert response(conn, 200) == expected
91 test "404s on private objects", %{conn: conn} do
92 note_activity = insert(:direct_note_activity)
93 user = User.get_by_ap_id(note_activity.data["actor"])
94 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
95 url = "/objects/#{uuid}"
101 assert response(conn, 404)
104 test "404s on nonexisting objects", %{conn: conn} do
111 assert response(conn, 404)
114 test "gets an activity", %{conn: conn} do
115 note_activity = insert(:note_activity)
116 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
117 url = "/activities/#{uuid}"
123 assert response(conn, 200)
126 test "404s on private activities", %{conn: conn} do
127 note_activity = insert(:direct_note_activity)
128 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
129 url = "/activities/#{uuid}"
135 assert response(conn, 404)
138 test "404s on nonexistent activities", %{conn: conn} do
139 url = "/activities/123"
145 assert response(conn, 404)
148 test "gets a notice", %{conn: conn} do
149 note_activity = insert(:note_activity)
150 url = "/notice/#{note_activity.id}"
156 assert response(conn, 200)
159 test "gets a notice in AS2 format", %{conn: conn} do
160 note_activity = insert(:note_activity)
161 url = "/notice/#{note_activity.id}"
165 |> put_req_header("accept", "application/activity+json")
168 assert json_response(conn, 200)
171 test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
172 note_activity = insert(:note_activity)
173 url = "/notice/#{note_activity.id}"
177 |> put_req_header("accept", "application/activity+json")
180 assert json_response(conn, 200)
184 {:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
185 url = "/notice/#{like_activity.id}"
187 assert like_activity.data["type"] == "Like"
191 |> put_req_header("accept", "application/activity+json")
194 assert response(conn, 404)
197 test "gets an activity in AS2 format", %{conn: conn} do
198 note_activity = insert(:note_activity)
199 [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
200 url = "/activities/#{uuid}"
204 |> put_req_header("accept", "application/activity+json")
207 assert json_response(conn, 200)
210 test "404s a private notice", %{conn: conn} do
211 note_activity = insert(:direct_note_activity)
212 url = "/notice/#{note_activity.id}"
218 assert response(conn, 404)
221 test "404s a nonexisting notice", %{conn: conn} do
228 assert response(conn, 404)