2020-10-12 10:00:50 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-11-07 22:29:46 -08:00
|
|
|
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
2020-02-22 08:48:41 -08:00
|
|
|
|
2019-11-12 17:19:46 -08:00
|
|
|
alias Pleroma.Activity
|
2020-02-22 08:48:41 -08:00
|
|
|
alias Pleroma.Config
|
2019-11-08 08:55:32 -08:00
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
2019-11-09 09:50:45 -08:00
|
|
|
alias Pleroma.Web.CommonAPI
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2019-11-07 22:29:46 -08:00
|
|
|
import Pleroma.Factory
|
|
|
|
|
2020-03-20 08:33:00 -07:00
|
|
|
setup_all do: clear_config([:static_fe, :enabled], true)
|
|
|
|
setup do: clear_config([:instance, :federating], true)
|
2020-03-11 04:05:56 -07:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
setup %{conn: conn} do
|
|
|
|
conn = put_req_header(conn, "accept", "text/html")
|
|
|
|
user = insert(:user)
|
2019-11-07 22:29:46 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
%{conn: conn, user: user}
|
|
|
|
end
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
describe "user profile html" do
|
|
|
|
test "just the profile as HTML", %{conn: conn, user: user} do
|
|
|
|
conn = get(conn, "/users/#{user.nickname}")
|
2019-11-07 22:29:46 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
assert html_response(conn, 200) =~ user.nickname
|
2019-11-07 22:29:46 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
test "404 when user not found", %{conn: conn} do
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/users/limpopo")
|
2019-11-07 22:29:46 -08:00
|
|
|
|
|
|
|
assert html_response(conn, 404) =~ "not found"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "profile does not include private messages", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
CommonAPI.post(user, %{status: "public"})
|
|
|
|
CommonAPI.post(user, %{status: "private", visibility: "private"})
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/users/#{user.nickname}")
|
2019-11-08 08:55:32 -08:00
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
|
|
|
|
assert html =~ ">public<"
|
|
|
|
refute html =~ ">private<"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "pagination", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end)
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/users/#{user.nickname}")
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2019-11-07 22:29:46 -08:00
|
|
|
html = html_response(conn, 200)
|
|
|
|
|
|
|
|
assert html =~ ">test30<"
|
|
|
|
assert html =~ ">test11<"
|
|
|
|
refute html =~ ">test10<"
|
|
|
|
refute html =~ ">test1<"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "pagination, page 2", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{status: "test#{i}"}) end)
|
2019-11-07 22:29:46 -08:00
|
|
|
{:ok, a11} = Enum.at(activities, 11)
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2019-11-07 22:29:46 -08:00
|
|
|
html = html_response(conn, 200)
|
|
|
|
|
|
|
|
assert html =~ ">test1<"
|
|
|
|
assert html =~ ">test10<"
|
|
|
|
refute html =~ ">test20<"
|
|
|
|
refute html =~ ">test29<"
|
|
|
|
end
|
2020-03-11 04:05:56 -07:00
|
|
|
|
|
|
|
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
|
|
|
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
|
|
|
|
end
|
2019-11-07 22:29:46 -08:00
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
describe "notice html" do
|
|
|
|
test "single notice page", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
2019-11-07 22:29:46 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/notice/#{activity.id}")
|
2019-11-07 22:29:46 -08:00
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
assert html =~ "<header>"
|
|
|
|
assert html =~ user.nickname
|
|
|
|
assert html =~ "testing a thing!"
|
|
|
|
end
|
|
|
|
|
2020-06-26 07:27:39 -07:00
|
|
|
test "redirects to json if requested", %{conn: conn, user: user} do
|
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header(
|
|
|
|
"accept",
|
|
|
|
"Accept: application/activity+json, application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\", text/html"
|
|
|
|
)
|
|
|
|
|> get("/notice/#{activity.id}")
|
|
|
|
|
|
|
|
assert redirected_to(conn, 302) =~ activity.data["object"]
|
|
|
|
end
|
|
|
|
|
2020-03-15 07:45:57 -07:00
|
|
|
test "filters HTML tags", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "<script>alert('xss')</script>"})
|
2020-03-15 07:45:57 -07:00
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("accept", "text/html")
|
|
|
|
|> get("/notice/#{activity.id}")
|
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
assert html =~ ~s[<script>alert('xss')</script>]
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "shows the whole thread", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "space: the final frontier"})
|
2019-11-08 08:55:32 -08:00
|
|
|
|
|
|
|
CommonAPI.post(user, %{
|
2020-05-12 12:59:26 -07:00
|
|
|
status: "these are the voyages or something",
|
|
|
|
in_reply_to_status_id: activity.id
|
2019-11-08 08:55:32 -08:00
|
|
|
})
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/notice/#{activity.id}")
|
2019-11-08 08:55:32 -08:00
|
|
|
|
|
|
|
html = html_response(conn, 200)
|
|
|
|
assert html =~ "the final frontier"
|
|
|
|
assert html =~ "voyages"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "redirect by AP object ID", %{conn: conn, user: user} do
|
2019-11-12 17:19:46 -08:00
|
|
|
{:ok, %Activity{data: %{"object" => object_url}}} =
|
2020-05-12 12:59:26 -07:00
|
|
|
CommonAPI.post(user, %{status: "beam me up"})
|
2019-11-12 17:19:46 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, URI.parse(object_url).path)
|
2019-11-12 17:19:46 -08:00
|
|
|
|
|
|
|
assert html_response(conn, 302) =~ "redirected"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "redirect by activity ID", %{conn: conn, user: user} do
|
2019-11-12 17:33:54 -08:00
|
|
|
{:ok, %Activity{data: %{"id" => id}}} =
|
2020-05-12 12:59:26 -07:00
|
|
|
CommonAPI.post(user, %{status: "I'm a doctor, not a devops!"})
|
2019-11-12 17:33:54 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, URI.parse(id).path)
|
2019-11-12 17:33:54 -08:00
|
|
|
|
|
|
|
assert html_response(conn, 302) =~ "redirected"
|
|
|
|
end
|
|
|
|
|
2019-11-07 22:29:46 -08:00
|
|
|
test "404 when notice not found", %{conn: conn} do
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/notice/88c9c317")
|
2019-11-08 08:55:32 -08:00
|
|
|
|
|
|
|
assert html_response(conn, 404) =~ "not found"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "404 for private status", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "don't show me!", visibility: "private"})
|
2019-11-08 08:55:32 -08:00
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/notice/#{activity.id}")
|
2019-11-08 08:55:32 -08:00
|
|
|
|
|
|
|
assert html_response(conn, 404) =~ "not found"
|
|
|
|
end
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
test "302 for remote cached status", %{conn: conn, user: user} do
|
2019-11-08 08:55:32 -08:00
|
|
|
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)
|
|
|
|
|
2020-02-22 08:48:41 -08:00
|
|
|
conn = get(conn, "/notice/#{activity.id}")
|
2019-11-07 22:29:46 -08:00
|
|
|
|
2019-11-11 17:16:44 -08:00
|
|
|
assert html_response(conn, 302) =~ "redirected"
|
2019-11-07 22:29:46 -08:00
|
|
|
end
|
2020-03-11 04:05:56 -07:00
|
|
|
|
|
|
|
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
2020-05-12 12:59:26 -07:00
|
|
|
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
|
2020-03-11 04:05:56 -07:00
|
|
|
|
|
|
|
ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
|
|
|
|
end
|
2019-11-07 22:29:46 -08:00
|
|
|
end
|
|
|
|
end
|