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([:static_fe, :enabled], false)
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))
196 test "does not require authentication on non-federating instances", %{conn: conn} do
197 clear_config([:instance, :federating], false)
201 |> put_req_header("accept", "application/rss+xml")
202 |> get("/users/#{user.nickname}/feed.rss")
207 # Note: see ActivityPubControllerTest for JSON format tests
208 describe "feed_redirect" do
209 test "with html format, it redirects to user feed", %{conn: conn} do
210 note_activity = insert(:note_activity)
211 user = User.get_cached_by_ap_id(note_activity.data["actor"])
215 |> get("/users/#{user.nickname}")
219 Pleroma.Web.Fallback.RedirectController.redirector_with_meta(
225 test "with html format, it returns error when user is not found", %{conn: conn} do
228 |> get("/users/jimm")
229 |> json_response(404)
231 assert response == %{"error" => "Not found"}
234 test "with non-html / non-json format, it redirects to user feed in atom format", %{
237 note_activity = insert(:note_activity)
238 user = User.get_cached_by_ap_id(note_activity.data["actor"])
242 |> put_req_header("accept", "application/xml")
243 |> get("/users/#{user.nickname}")
245 assert conn.status == 302
246 assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
249 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
252 |> put_req_header("accept", "application/xml")
253 |> get(user_feed_path(conn, :feed, "jimm"))
256 assert response == ~S({"error":"Not found"})
260 describe "private instance" do
261 setup do: clear_config([:instance, :public])
263 test "returns 404 for user feed", %{conn: conn} do
264 Config.put([:instance, :public], false)
267 {:ok, _} = CommonAPI.post(user, %{status: "test"})
270 |> put_req_header("accept", "application/atom+xml")
271 |> get(user_feed_path(conn, :feed, user.nickname))