1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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
13 alias Pleroma.Web.CommonAPI
14 alias Pleroma.Web.Feed.FeedView
16 setup do: clear_config([:static_fe, :enabled], false)
19 setup do: clear_config([:feed])
24 %{max_length: 15, omission: "..."}
27 activity = insert(:note_activity)
32 "content" => "This & this is :moominmamma: note ",
33 "source" => "This & this is :moominmamma: note ",
37 %{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
41 "inReplyTo" => activity.data["id"],
42 "context" => "2hu & as",
43 "summary" => "2hu & as"
47 note_activity = insert(:note_activity, note: note)
48 user = User.get_cached_by_ap_id(note_activity.data["actor"])
54 "content" => "42 & This is :moominmamma: note ",
55 "inReplyTo" => activity.data["id"]
59 note_activity2 = insert(:note_activity, note: note2)
60 object = Object.normalize(note_activity, fetch: false)
62 [user: user, object: object, max_id: note_activity2.id]
65 test "gets an atom feed", %{conn: conn, user: user, object: object, max_id: max_id} do
68 |> put_req_header("accept", "application/atom+xml")
69 |> get(user_feed_path(conn, :feed, user.nickname))
75 |> SweetXml.xpath(~x"//entry/title/text()"l)
77 assert activity_titles == ['42 & Thi...', 'This & t...']
78 assert resp =~ FeedView.escape(object.data["content"])
79 assert resp =~ FeedView.escape(object.data["summary"])
80 assert resp =~ FeedView.escape(object.data["context"])
84 |> put_req_header("accept", "application/atom+xml")
85 |> get("/users/#{user.nickname}/feed", %{"max_id" => max_id})
91 |> SweetXml.xpath(~x"//entry/title/text()"l)
93 assert activity_titles == ['This & t...']
96 test "gets a rss feed", %{conn: conn, user: user, object: object, max_id: max_id} do
99 |> put_req_header("accept", "application/rss+xml")
100 |> get("/users/#{user.nickname}/feed.rss")
106 |> SweetXml.xpath(~x"//item/title/text()"l)
108 assert activity_titles == ['42 & Thi...', 'This & t...']
109 assert resp =~ FeedView.escape(object.data["content"])
110 assert resp =~ FeedView.escape(object.data["summary"])
111 assert resp =~ FeedView.escape(object.data["context"])
115 |> put_req_header("accept", "application/rss+xml")
116 |> get("/users/#{user.nickname}/feed.rss", %{"max_id" => max_id})
122 |> SweetXml.xpath(~x"//item/title/text()"l)
124 assert activity_titles == ['This & t...']
127 test "returns 404 for a missing feed", %{conn: conn} do
130 |> put_req_header("accept", "application/atom+xml")
131 |> get(user_feed_path(conn, :feed, "nonexisting"))
133 assert response(conn, 404)
136 test "returns feed with public and unlisted activities", %{conn: conn} do
139 {:ok, _} = CommonAPI.post(user, %{status: "public", visibility: "public"})
140 {:ok, _} = CommonAPI.post(user, %{status: "direct", visibility: "direct"})
141 {:ok, _} = CommonAPI.post(user, %{status: "unlisted", visibility: "unlisted"})
142 {:ok, _} = CommonAPI.post(user, %{status: "private", visibility: "private"})
146 |> put_req_header("accept", "application/atom+xml")
147 |> get(user_feed_path(conn, :feed, user.nickname))
153 |> SweetXml.xpath(~x"//entry/title/text()"l)
156 assert activity_titles == ['public', 'unlisted']
159 test "returns 404 when the user is remote", %{conn: conn} do
160 user = insert(:user, local: false)
162 {:ok, _} = CommonAPI.post(user, %{status: "test"})
165 |> put_req_header("accept", "application/atom+xml")
166 |> get(user_feed_path(conn, :feed, user.nickname))
170 test "does not require authentication on non-federating instances", %{conn: conn} do
171 clear_config([:instance, :federating], false)
175 |> put_req_header("accept", "application/rss+xml")
176 |> get("/users/#{user.nickname}/feed.rss")
181 # Note: see ActivityPubControllerTest for JSON format tests
182 describe "feed_redirect" do
183 test "with html format, it redirects to user feed", %{conn: conn} do
184 note_activity = insert(:note_activity)
185 user = User.get_cached_by_ap_id(note_activity.data["actor"])
189 |> get("/users/#{user.nickname}")
193 Pleroma.Web.Fallback.RedirectController.redirector_with_meta(
199 test "with html format, it falls back to frontend when user is remote", %{conn: conn} do
200 user = insert(:user, local: false)
202 {:ok, _} = CommonAPI.post(user, %{status: "test"})
206 |> get("/users/#{user.nickname}")
209 assert response =~ "</html>"
212 test "with html format, it falls back to frontend when user is not found", %{conn: conn} do
215 |> get("/users/jimm")
218 assert response =~ "</html>"
221 test "with non-html / non-json format, it redirects to user feed in atom format", %{
224 note_activity = insert(:note_activity)
225 user = User.get_cached_by_ap_id(note_activity.data["actor"])
229 |> put_req_header("accept", "application/xml")
230 |> get("/users/#{user.nickname}")
232 assert conn.status == 302
234 assert redirected_to(conn) ==
235 "#{Pleroma.Web.Endpoint.url()}/users/#{user.nickname}/feed.atom"
238 test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
241 |> put_req_header("accept", "application/xml")
242 |> get(user_feed_path(conn, :feed, "jimm"))
245 assert response == ~S({"error":"Not found"})
249 describe "private instance" do
250 setup do: clear_config([:instance, :public])
252 test "returns 404 for user feed", %{conn: conn} do
253 clear_config([:instance, :public], false)
256 {:ok, _} = CommonAPI.post(user, %{status: "test"})
259 |> put_req_header("accept", "application/atom+xml")
260 |> get(user_feed_path(conn, :feed, user.nickname))