1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
6 alias Pleroma.Web.ActivityPub.Transmogrifier
7 alias Pleroma.Web.CommonAPI
11 clear_config_all([:static_fe, :enabled]) do
12 Config.put([:static_fe, :enabled], true)
15 clear_config([:instance, :federating]) do
16 Config.put([:instance, :federating], true)
19 setup %{conn: conn} do
20 conn = put_req_header(conn, "accept", "text/html")
23 %{conn: conn, user: user}
26 describe "user profile html" do
27 test "just the profile as HTML", %{conn: conn, user: user} do
28 conn = get(conn, "/users/#{user.nickname}")
30 assert html_response(conn, 200) =~ user.nickname
33 test "404 when user not found", %{conn: conn} do
34 conn = get(conn, "/users/limpopo")
36 assert html_response(conn, 404) =~ "not found"
39 test "profile does not include private messages", %{conn: conn, user: user} do
40 CommonAPI.post(user, %{"status" => "public"})
41 CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
43 conn = get(conn, "/users/#{user.nickname}")
45 html = html_response(conn, 200)
47 assert html =~ ">public<"
48 refute html =~ ">private<"
51 test "pagination", %{conn: conn, user: user} do
52 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
54 conn = get(conn, "/users/#{user.nickname}")
56 html = html_response(conn, 200)
58 assert html =~ ">test30<"
59 assert html =~ ">test11<"
60 refute html =~ ">test10<"
61 refute html =~ ">test1<"
64 test "pagination, page 2", %{conn: conn, user: user} do
65 activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
66 {:ok, a11} = Enum.at(activities, 11)
68 conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
70 html = html_response(conn, 200)
72 assert html =~ ">test1<"
73 assert html =~ ">test10<"
74 refute html =~ ">test20<"
75 refute html =~ ">test29<"
78 test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
79 ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
83 describe "notice html" do
84 test "single notice page", %{conn: conn, user: user} do
85 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
87 conn = get(conn, "/notice/#{activity.id}")
89 html = html_response(conn, 200)
90 assert html =~ "<header>"
91 assert html =~ user.nickname
92 assert html =~ "testing a thing!"
95 test "filters HTML tags", %{conn: conn} do
97 {:ok, activity} = CommonAPI.post(user, %{"status" => "<script>alert('xss')</script>"})
101 |> put_req_header("accept", "text/html")
102 |> get("/notice/#{activity.id}")
104 html = html_response(conn, 200)
105 assert html =~ ~s[<script>alert('xss')</script>]
108 test "shows the whole thread", %{conn: conn, user: user} do
109 {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
111 CommonAPI.post(user, %{
112 "status" => "these are the voyages or something",
113 "in_reply_to_status_id" => activity.id
116 conn = get(conn, "/notice/#{activity.id}")
118 html = html_response(conn, 200)
119 assert html =~ "the final frontier"
120 assert html =~ "voyages"
123 test "redirect by AP object ID", %{conn: conn, user: user} do
124 {:ok, %Activity{data: %{"object" => object_url}}} =
125 CommonAPI.post(user, %{"status" => "beam me up"})
127 conn = get(conn, URI.parse(object_url).path)
129 assert html_response(conn, 302) =~ "redirected"
132 test "redirect by activity ID", %{conn: conn, user: user} do
133 {:ok, %Activity{data: %{"id" => id}}} =
134 CommonAPI.post(user, %{"status" => "I'm a doctor, not a devops!"})
136 conn = get(conn, URI.parse(id).path)
138 assert html_response(conn, 302) =~ "redirected"
141 test "404 when notice not found", %{conn: conn} do
142 conn = get(conn, "/notice/88c9c317")
144 assert html_response(conn, 404) =~ "not found"
147 test "404 for private status", %{conn: conn, user: user} do
149 CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
151 conn = get(conn, "/notice/#{activity.id}")
153 assert html_response(conn, 404) =~ "not found"
156 test "302 for remote cached status", %{conn: conn, user: user} do
158 "@context" => "https://www.w3.org/ns/activitystreams",
159 "to" => user.follower_address,
160 "cc" => "https://www.w3.org/ns/activitystreams#Public",
163 "content" => "blah blah blah",
165 "attributedTo" => user.ap_id,
168 "actor" => user.ap_id
171 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
173 conn = get(conn, "/notice/#{activity.id}")
175 assert html_response(conn, 302) =~ "redirected"
178 test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
179 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
181 ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)