1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Feed.UserControllerTest do
6 use Pleroma.Web.ConnCase
14 alias Pleroma.Web.CommonAPI
16 setup do: clear_config([:instance, :federating], true)
19 setup do: clear_config([:feed])
21 test "gets an atom feed", %{conn: conn} do
24 %{max_length: 10, omission: "..."}
27 activity = insert(:note_activity)
32 "content" => "This is :moominmamma: note ",
36 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
40 "inReplyTo" => activity.data["id"]
44 note_activity = insert(:note_activity, note: note)
45 user = User.get_cached_by_ap_id(note_activity.data["actor"])
51 "content" => "42 This is :moominmamma: note ",
52 "inReplyTo" => activity.data["id"]
56 note_activity2 = insert(:note_activity, note: note2)
57 object = Object.normalize(note_activity)
61 |> put_req_header("accept", "application/atom+xml")
62 |> get(user_feed_path(conn, :feed, user.nickname))
68 |> SweetXml.xpath(~x"//entry/title/text()"l)
70 assert activity_titles == ['42 This...', 'This is...']
71 assert resp =~ object.data["content"]
75 |> put_req_header("accept", "application/atom+xml")
76 |> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
82 |> SweetXml.xpath(~x"//entry/title/text()"l)
84 assert activity_titles == ['This is...']
87 test "gets a rss feed", %{conn: conn} do
90 %{max_length: 10, omission: "..."}
93 activity = insert(:note_activity)
98 "content" => "This is :moominmamma: note ",
102 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
106 "inReplyTo" => activity.data["id"]
110 note_activity = insert(:note_activity, note: note)
111 user = User.get_cached_by_ap_id(note_activity.data["actor"])
117 "content" => "42 This is :moominmamma: note ",
118 "inReplyTo" => activity.data["id"]
122 note_activity2 = insert(:note_activity, note: note2)
123 object = Object.normalize(note_activity)
127 |> put_req_header("accept", "application/rss+xml")
128 |> get("/users/#{user.nickname}/feed.rss")
134 |> SweetXml.xpath(~x"//item/title/text()"l)
136 assert activity_titles == ['42 This...', 'This is...']
137 assert resp =~ object.data["content"]
141 |> put_req_header("accept", "application/rss+xml")
142 |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
148 |> SweetXml.xpath(~x"//item/title/text()"l)
150 assert activity_titles == ['This is...']
153 test "returns 404 for a missing feed", %{conn: conn} do
156 |> put_req_header("accept", "application/atom+xml")
157 |> get(user_feed_path(conn, :feed, "nonexisting"))
159 assert response(conn, 404)
162 test "returns feed with public and unlisted activities", %{conn: conn} do
165 {:ok, _} = CommonAPI.post(user, %{status: "public", visibility: "public"})
166 {:ok, _} = CommonAPI.post(user, %{status: "direct", visibility: "direct"})
167 {:ok, _} = CommonAPI.post(user, %{status: "unlisted", visibility: "unlisted"})
168 {:ok, _} = CommonAPI.post(user, %{status: "private", visibility: "private"})
172 |> put_req_header("accept", "application/atom+xml")
173 |> get(user_feed_path(conn, :feed, user.nickname))
179 |> SweetXml.xpath(~x"//entry/title/text()"l)
182 assert activity_titles == ['public', 'unlisted']
185 test "returns 404 when the user is remote", %{conn: conn} do
186 user = insert(:user, local: false)
188 {:ok, _} = CommonAPI.post(user, %{status: "test"})
191 |> put_req_header("accept", "application/atom+xml")
192 |> get(user_feed_path(conn, :feed, user.nickname))
197 # Note: see ActivityPubControllerTest for JSON format tests
198 describe "feed_redirect" do
199 test "with html format, it redirects to user feed", %{conn: conn} do
200 note_activity = insert(:note_activity)
201 user = User.get_cached_by_ap_id(note_activity.data["actor"])
205 |> get("/users/#{user.nickname}")
209 Fallback.RedirectController.redirector_with_meta(
215 test "with html format, it returns error when user is not found", %{conn: conn} do
218 |> get("/users/jimm")
219 |> json_response(404)
221 assert response == %{"error" => "Not found"}
224 test "with non-html / non-json format, it redirects to user feed in atom format", %{
227 note_activity = insert(:note_activity)
228 user = User.get_cached_by_ap_id(note_activity.data["actor"])
232 |> put_req_header("accept", "application/xml")
233 |> get("/users/#{user.nickname}")
235 assert conn.status == 302
236 assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
239 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
242 |> put_req_header("accept", "application/xml")
243 |> get(user_feed_path(conn, :feed, "jimm"))
246 assert response == ~S({"error":"Not found"})
250 describe "private instance" do
251 setup do: clear_config([:instance, :public])
253 test "returns 404 for user feed", %{conn: conn} do
254 Config.put([:instance, :public], false)
257 {:ok, _} = CommonAPI.post(user, %{status: "test"})
260 |> put_req_header("accept", "application/atom+xml")
261 |> get(user_feed_path(conn, :feed, user.nickname))