2019-11-08 06:29:46 +00:00
|
|
|
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
2019-11-13 01:19:46 +00:00
|
|
|
alias Pleroma.Activity
|
2019-11-08 16:55:32 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
2019-11-09 17:50:45 +00:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-11-08 16:55:32 +00:00
|
|
|
|
2019-11-08 06:29:46 +00:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
clear_config_all([:static_fe, :enabled]) do
|
|
|
|
Pleroma.Config.put([:static_fe, :enabled], true)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "user profile page" do
|
|
|
|
test "just the profile as HTML", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
2019-11-08 16:55:32 +00:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/users/#{user.nickname}")
|
2019-11-08 06:29:46 +00:00
|
|
|
|
|
|
|
assert html_response(conn, 200) =~ user.nickname
|
|
|
|
end
|
|
|
|
|
|
|
|
test "renders json unless there's an html accept header", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
2019-11-08 16:55:32 +00:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "application/json")
|
|
|
|
|> get("/users/#{user.nickname}")
|
2019-11-08 06:29:46 +00:00
|
|
|
|
|
|
|
assert json_response(conn, 200)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "404 when user not found", %{conn: conn} do
|
2019-11-08 16:55:32 +00:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/users/limpopo")
|
2019-11-08 06:29:46 +00:00
|
|
|
|
|
|
|
assert html_response(conn, 404) =~ "not found"
|
|
|
|
end
|
|
|
|
|
2019-11-08 16:55:32 +00:00
|
|
|
test "profile does not include private messages", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
CommonAPI.post(user, %{"status" => "public"})
|
|
|
|
CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/users/#{user.nickname}")
|
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
|
|
|
|
assert html =~ ">public<"
|
|
|
|
refute html =~ ">private<"
|
|
|
|
end
|
|
|
|
|
2019-11-08 06:29:46 +00:00
|
|
|
test "pagination", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
2019-11-08 16:55:32 +00:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/users/#{user.nickname}")
|
|
|
|
|
2019-11-08 06:29:46 +00:00
|
|
|
html = html_response(conn, 200)
|
|
|
|
|
|
|
|
assert html =~ ">test30<"
|
|
|
|
assert html =~ ">test11<"
|
|
|
|
refute html =~ ">test10<"
|
|
|
|
refute html =~ ">test1<"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "pagination, page 2", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
2019-11-08 16:55:32 +00:00
|
|
|
activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
2019-11-08 06:29:46 +00:00
|
|
|
{:ok, a11} = Enum.at(activities, 11)
|
2019-11-08 16:55:32 +00:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/users/#{user.nickname}?max_id=#{a11.id}")
|
|
|
|
|
2019-11-08 06:29:46 +00:00
|
|
|
html = html_response(conn, 200)
|
|
|
|
|
|
|
|
assert html =~ ">test1<"
|
|
|
|
assert html =~ ">test10<"
|
|
|
|
refute html =~ ">test20<"
|
|
|
|
refute html =~ ">test29<"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "notice rendering" do
|
|
|
|
test "single notice page", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
|
|
|
|
|
2019-11-08 16:55:32 +00:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/notice/#{activity.id}")
|
2019-11-08 06:29:46 +00:00
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
assert html =~ "<header>"
|
|
|
|
assert html =~ user.nickname
|
|
|
|
assert html =~ "testing a thing!"
|
|
|
|
end
|
|
|
|
|
2019-11-08 16:55:32 +00:00
|
|
|
test "shows the whole thread", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "space: the final frontier"})
|
|
|
|
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
"status" => "these are the voyages or something",
|
|
|
|
"in_reply_to_status_id" => activity.id
|
|
|
|
})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/notice/#{activity.id}")
|
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
assert html =~ "the final frontier"
|
|
|
|
assert html =~ "voyages"
|
|
|
|
end
|
|
|
|
|
2019-11-13 01:19:46 +00:00
|
|
|
test "redirect by AP object ID", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: %{"object" => object_url}}} =
|
|
|
|
CommonAPI.post(user, %{"status" => "beam me up"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get(URI.parse(object_url).path)
|
|
|
|
|
|
|
|
assert html_response(conn, 302) =~ "redirected"
|
|
|
|
end
|
|
|
|
|
2019-11-13 01:33:54 +00:00
|
|
|
test "redirect by activity ID", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, %Activity{data: %{"id" => id}}} =
|
|
|
|
CommonAPI.post(user, %{"status" => "I'm a doctor, not a devops!"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get(URI.parse(id).path)
|
|
|
|
|
|
|
|
assert html_response(conn, 302) =~ "redirected"
|
|
|
|
end
|
|
|
|
|
2019-11-08 06:29:46 +00:00
|
|
|
test "404 when notice not found", %{conn: conn} do
|
2019-11-08 16:55:32 +00:00
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/notice/88c9c317")
|
|
|
|
|
|
|
|
assert html_response(conn, 404) =~ "not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "404 for private status", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/notice/#{activity.id}")
|
|
|
|
|
|
|
|
assert html_response(conn, 404) =~ "not found"
|
|
|
|
end
|
|
|
|
|
2019-11-12 01:16:44 +00:00
|
|
|
test "302 for remote cached status", %{conn: conn} do
|
2019-11-08 16:55:32 +00:00
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
message = %{
|
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
|
|
|
"to" => user.follower_address,
|
|
|
|
"cc" => "https://www.w3.org/ns/activitystreams#Public",
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"content" => "blah blah blah",
|
|
|
|
"type" => "Note",
|
|
|
|
"attributedTo" => user.ap_id,
|
|
|
|
"inReplyTo" => nil
|
|
|
|
},
|
|
|
|
"actor" => user.ap_id
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/notice/#{activity.id}")
|
2019-11-08 06:29:46 +00:00
|
|
|
|
2019-11-12 01:16:44 +00:00
|
|
|
assert html_response(conn, 302) =~ "redirected"
|
2019-11-08 06:29:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|