1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
6 alias Pleroma.Web.ActivityPub.Transmogrifier
7 alias Pleroma.Web.CommonAPI
11 setup_all do: clear_config([:static_fe, :enabled], true)
12 setup do: clear_config([:instance, :federating], true)
14 setup %{conn: conn} do
15 conn = put_req_header(conn, "accept", "text/html")
18 %{conn: conn, user: user}
21 describe "user profile html" do
22 test "just the profile as HTML", %{conn: conn, user: user} do
23 conn = get(conn, "/users/#{user.nickname}")
25 assert html_response(conn, 200) =~ user.nickname
28 test "404 when user not found", %{conn: conn} do
29 conn = get(conn, "/users/limpopo")
31 assert html_response(conn, 404) =~ "not found"
34 test "profile does not include private messages", %{conn: conn, user: user} do
35 CommonAPI.post(user, %{status: "public"})
36 CommonAPI.post(user, %{status: "private", visibility: "private"})
38 conn = get(conn, "/users/#{user.nickname}")
40 html = html_response(conn, 200)
42 assert html =~ ">public<"
43 refute html =~ ">private<"
46 test "pagination", %{conn: conn, user: user} do
47 Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end)
49 conn = get(conn, "/users/#{user.nickname}")
51 html = html_response(conn, 200)
53 assert html =~ ">test30<"
54 assert html =~ ">test11<"
55 refute html =~ ">test10<"
56 refute html =~ ">test1<"
59 test "pagination, page 2", %{conn: conn, user: user} do
60 activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end)
61 {:ok, a11} = Enum.at(activities, 11)
63 conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
65 html = html_response(conn, 200)
67 assert html =~ ">test1<"
68 assert html =~ ">test10<"
69 refute html =~ ">test20<"
70 refute html =~ ">test29<"
73 test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
74 ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
78 describe "notice html" do
79 test "single notice page", %{conn: conn, user: user} do
80 {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
82 conn = get(conn, "/notice/#{activity.id}")
84 html = html_response(conn, 200)
85 assert html =~ "<header>"
86 assert html =~ user.nickname
87 assert html =~ "testing a thing!"
90 test "redirects to json if requested", %{conn: conn, user: user} do
91 {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
97 "Accept: application/activity+json, application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\", text/html"
99 |> get("/notice/#{activity.id}")
101 assert redirected_to(conn, 302) =~ activity.data["object"]
104 test "filters HTML tags", %{conn: conn} do
106 {:ok, activity} = CommonAPI.post(user, %{status: "<script>alert('xss')</script>"})
110 |> put_req_header("accept", "text/html")
111 |> get("/notice/#{activity.id}")
113 html = html_response(conn, 200)
114 assert html =~ ~s[<script>alert('xss')</script>]
117 test "shows the whole thread", %{conn: conn, user: user} do
118 {:ok, activity} = CommonAPI.post(user, %{status: "space: the final frontier"})
120 CommonAPI.post(user, %{
121 status: "these are the voyages or something",
122 in_reply_to_status_id: activity.id
125 conn = get(conn, "/notice/#{activity.id}")
127 html = html_response(conn, 200)
128 assert html =~ "the final frontier"
129 assert html =~ "voyages"
132 test "redirect by AP object ID", %{conn: conn, user: user} do
133 {:ok, %Activity{data: %{"object" => object_url}}} =
134 CommonAPI.post(user, %{status: "beam me up"})
136 conn = get(conn, URI.parse(object_url).path)
138 assert html_response(conn, 302) =~ "redirected"
141 test "redirect by activity ID", %{conn: conn, user: user} do
142 {:ok, %Activity{data: %{"id" => id}}} =
143 CommonAPI.post(user, %{status: "I'm a doctor, not a devops!"})
145 conn = get(conn, URI.parse(id).path)
147 assert html_response(conn, 302) =~ "redirected"
150 test "404 when notice not found", %{conn: conn} do
151 conn = get(conn, "/notice/88c9c317")
153 assert html_response(conn, 404) =~ "not found"
156 test "404 for private status", %{conn: conn, user: user} do
157 {:ok, activity} = CommonAPI.post(user, %{status: "don't show me!", visibility: "private"})
159 conn = get(conn, "/notice/#{activity.id}")
161 assert html_response(conn, 404) =~ "not found"
164 test "302 for remote cached status", %{conn: conn, user: user} do
166 "@context" => "https://www.w3.org/ns/activitystreams",
167 "to" => user.follower_address,
168 "cc" => "https://www.w3.org/ns/activitystreams#Public",
171 "content" => "blah blah blah",
173 "attributedTo" => user.ap_id,
176 "actor" => user.ap_id
179 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
181 conn = get(conn, "/notice/#{activity.id}")
183 assert html_response(conn, 302) =~ "redirected"
186 test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
187 {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
189 ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)