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 "filters HTML tags", %{conn: conn} do
92 {:ok, activity} = CommonAPI.post(user, %{status: "<script>alert('xss')</script>"})
96 |> put_req_header("accept", "text/html")
97 |> get("/notice/#{activity.id}")
99 html = html_response(conn, 200)
100 assert html =~ ~s[<script>alert('xss')</script>]
103 test "shows the whole thread", %{conn: conn, user: user} do
104 {:ok, activity} = CommonAPI.post(user, %{status: "space: the final frontier"})
106 CommonAPI.post(user, %{
107 status: "these are the voyages or something",
108 in_reply_to_status_id: activity.id
111 conn = get(conn, "/notice/#{activity.id}")
113 html = html_response(conn, 200)
114 assert html =~ "the final frontier"
115 assert html =~ "voyages"
118 test "redirect by AP object ID", %{conn: conn, user: user} do
119 {:ok, %Activity{data: %{"object" => object_url}}} =
120 CommonAPI.post(user, %{status: "beam me up"})
122 conn = get(conn, URI.parse(object_url).path)
124 assert html_response(conn, 302) =~ "redirected"
127 test "redirect by activity ID", %{conn: conn, user: user} do
128 {:ok, %Activity{data: %{"id" => id}}} =
129 CommonAPI.post(user, %{status: "I'm a doctor, not a devops!"})
131 conn = get(conn, URI.parse(id).path)
133 assert html_response(conn, 302) =~ "redirected"
136 test "404 when notice not found", %{conn: conn} do
137 conn = get(conn, "/notice/88c9c317")
139 assert html_response(conn, 404) =~ "not found"
142 test "404 for private status", %{conn: conn, user: user} do
143 {:ok, activity} = CommonAPI.post(user, %{status: "don't show me!", visibility: "private"})
145 conn = get(conn, "/notice/#{activity.id}")
147 assert html_response(conn, 404) =~ "not found"
150 test "302 for remote cached status", %{conn: conn, user: user} do
152 "@context" => "https://www.w3.org/ns/activitystreams",
153 "to" => user.follower_address,
154 "cc" => "https://www.w3.org/ns/activitystreams#Public",
157 "content" => "blah blah blah",
159 "attributedTo" => user.ap_id,
162 "actor" => user.ap_id
165 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
167 conn = get(conn, "/notice/#{activity.id}")
169 assert html_response(conn, 302) =~ "redirected"
172 test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
173 {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
175 ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)