Merge remote-tracking branch 'remotes/origin/develop' into 1560-non-federating-instan...
[akkoma] / test / web / static_fe / static_fe_controller_test.exs
1 defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
2 use Pleroma.Web.ConnCase
3
4 alias Pleroma.Activity
5 alias Pleroma.Config
6 alias Pleroma.Web.ActivityPub.Transmogrifier
7 alias Pleroma.Web.CommonAPI
8
9 import Pleroma.Factory
10
11 clear_config_all([:static_fe, :enabled]) do
12 Config.put([:static_fe, :enabled], true)
13 end
14
15 clear_config([:instance, :federating]) do
16 Config.put([:instance, :federating], true)
17 end
18
19 setup %{conn: conn} do
20 conn = put_req_header(conn, "accept", "text/html")
21 user = insert(:user)
22
23 %{conn: conn, user: user}
24 end
25
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}")
29
30 assert html_response(conn, 200) =~ user.nickname
31 end
32
33 test "404 when user not found", %{conn: conn} do
34 conn = get(conn, "/users/limpopo")
35
36 assert html_response(conn, 404) =~ "not found"
37 end
38
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"})
42
43 conn = get(conn, "/users/#{user.nickname}")
44
45 html = html_response(conn, 200)
46
47 assert html =~ ">public<"
48 refute html =~ ">private<"
49 end
50
51 test "pagination", %{conn: conn, user: user} do
52 Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
53
54 conn = get(conn, "/users/#{user.nickname}")
55
56 html = html_response(conn, 200)
57
58 assert html =~ ">test30<"
59 assert html =~ ">test11<"
60 refute html =~ ">test10<"
61 refute html =~ ">test1<"
62 end
63
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)
67
68 conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
69
70 html = html_response(conn, 200)
71
72 assert html =~ ">test1<"
73 assert html =~ ">test10<"
74 refute html =~ ">test20<"
75 refute html =~ ">test29<"
76 end
77
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)
80 end
81 end
82
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!"})
86
87 conn = get(conn, "/notice/#{activity.id}")
88
89 html = html_response(conn, 200)
90 assert html =~ "<header>"
91 assert html =~ user.nickname
92 assert html =~ "testing a thing!"
93 end
94
95 test "shows the whole thread", %{conn: conn, user: user} do
96 {:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
97
98 CommonAPI.post(user, %{
99 "status" => "these are the voyages or something",
100 "in_reply_to_status_id" => activity.id
101 })
102
103 conn = get(conn, "/notice/#{activity.id}")
104
105 html = html_response(conn, 200)
106 assert html =~ "the final frontier"
107 assert html =~ "voyages"
108 end
109
110 test "redirect by AP object ID", %{conn: conn, user: user} do
111 {:ok, %Activity{data: %{"object" => object_url}}} =
112 CommonAPI.post(user, %{"status" => "beam me up"})
113
114 conn = get(conn, URI.parse(object_url).path)
115
116 assert html_response(conn, 302) =~ "redirected"
117 end
118
119 test "redirect by activity ID", %{conn: conn, user: user} do
120 {:ok, %Activity{data: %{"id" => id}}} =
121 CommonAPI.post(user, %{"status" => "I'm a doctor, not a devops!"})
122
123 conn = get(conn, URI.parse(id).path)
124
125 assert html_response(conn, 302) =~ "redirected"
126 end
127
128 test "404 when notice not found", %{conn: conn} do
129 conn = get(conn, "/notice/88c9c317")
130
131 assert html_response(conn, 404) =~ "not found"
132 end
133
134 test "404 for private status", %{conn: conn, user: user} do
135 {:ok, activity} =
136 CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
137
138 conn = get(conn, "/notice/#{activity.id}")
139
140 assert html_response(conn, 404) =~ "not found"
141 end
142
143 test "302 for remote cached status", %{conn: conn, user: user} do
144 message = %{
145 "@context" => "https://www.w3.org/ns/activitystreams",
146 "to" => user.follower_address,
147 "cc" => "https://www.w3.org/ns/activitystreams#Public",
148 "type" => "Create",
149 "object" => %{
150 "content" => "blah blah blah",
151 "type" => "Note",
152 "attributedTo" => user.ap_id,
153 "inReplyTo" => nil
154 },
155 "actor" => user.ap_id
156 }
157
158 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
159
160 conn = get(conn, "/notice/#{activity.id}")
161
162 assert html_response(conn, 302) =~ "redirected"
163 end
164
165 test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
166 {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
167
168 ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
169 end
170 end
171 end