# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Activity
- alias Pleroma.Config
+ alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Transmogrifier
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
setup_all do: clear_config([:static_fe, :enabled], true)
- setup do: clear_config([:instance, :federating], true)
setup %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
html = html_response(conn, 200)
- assert html =~ ">public<"
- refute html =~ ">private<"
+ assert html =~ "\npublic\n"
+ refute html =~ "\nprivate\n"
+ end
+
+ test "main page does not include replies", %{conn: conn, user: user} do
+ {:ok, op} = CommonAPI.post(user, %{status: "beep"})
+ CommonAPI.post(user, %{status: "boop", in_reply_to_id: op})
+
+ conn = get(conn, "/users/#{user.nickname}")
+
+ html = html_response(conn, 200)
+
+ assert html =~ "\nbeep\n"
+ refute html =~ "\nboop\n"
+ end
+
+ test "media page only includes posts with attachments", %{conn: conn, user: user} do
+ file = %Plug.Upload{
+ content_type: "image/jpeg",
+ path: Path.absname("test/fixtures/image.jpg"),
+ filename: "an_image.jpg"
+ }
+
+ {:ok, %{id: media_id}} = ActivityPub.upload(file, actor: user.ap_id)
+
+ CommonAPI.post(user, %{status: "virgin text post"})
+ CommonAPI.post(user, %{status: "chad post with attachment", media_ids: [media_id]})
+
+ conn = get(conn, "/users/#{user.nickname}/media")
+
+ html = html_response(conn, 200)
+
+ assert html =~ "\nchad post with attachment\n"
+ refute html =~ "\nvirgin text post\n"
+ end
+
+ test "show follower list", %{conn: conn, user: user} do
+ follower = insert(:user)
+ CommonAPI.follow(follower, user)
+
+ conn = get(conn, "/users/#{user.nickname}/followers")
+
+ html = html_response(conn, 200)
+
+ assert html =~ "user-card"
+ end
+
+ test "don't show followers if hidden", %{conn: conn, user: user} do
+ follower = insert(:user)
+ CommonAPI.follow(follower, user)
+
+ {:ok, user} =
+ user
+ |> User.update_changeset(%{hide_followers: true})
+ |> User.update_and_set_cache()
+
+ conn = get(conn, "/users/#{user.nickname}/followers")
+
+ html = html_response(conn, 200)
+
+ refute html =~ "user-card"
end
test "pagination", %{conn: conn, user: user} do
html = html_response(conn, 200)
- assert html =~ ">test30<"
- assert html =~ ">test11<"
- refute html =~ ">test10<"
- refute html =~ ">test1<"
+ assert html =~ "\ntest30\n"
+ assert html =~ "\ntest11\n"
+ refute html =~ "\ntest10\n"
+ refute html =~ "\ntest1\n"
end
test "pagination, page 2", %{conn: conn, user: user} do
html = html_response(conn, 200)
- assert html =~ ">test1<"
- assert html =~ ">test10<"
- refute html =~ ">test20<"
- refute html =~ ">test29<"
+ assert html =~ "\ntest1\n"
+ assert html =~ "\ntest10\n"
+ refute html =~ "\ntest20\n"
+ refute html =~ "\ntest29\n"
+ end
+
+ test "does not require authentication on non-federating instances", %{
+ conn: conn,
+ user: user
+ } do
+ clear_config([:instance, :federating], false)
+
+ conn = get(conn, "/users/#{user.nickname}")
+
+ assert html_response(conn, 200) =~ user.nickname
end
- test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
- ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
+ test "returns 404 for local user with `restrict_unauthenticated/profiles/local` setting", %{
+ conn: conn
+ } do
+ clear_config([:restrict_unauthenticated, :profiles, :local], true)
+
+ local_user = insert(:user, local: true)
+
+ conn
+ |> get("/users/#{local_user.nickname}")
+ |> html_response(404)
end
end
conn = get(conn, "/notice/#{activity.id}")
html = html_response(conn, 200)
- assert html =~ "<header>"
+ assert html =~ "<div class=\"panel conversation\">"
assert html =~ user.nickname
assert html =~ "testing a thing!"
end
test "302 for remote cached status", %{conn: conn, user: user} do
message = %{
"@context" => "https://www.w3.org/ns/activitystreams",
- "to" => user.follower_address,
- "cc" => "https://www.w3.org/ns/activitystreams#Public",
"type" => "Create",
+ "actor" => user.ap_id,
"object" => %{
+ "to" => user.follower_address,
+ "cc" => "https://www.w3.org/ns/activitystreams#Public",
+ "id" => Utils.generate_object_id(),
"content" => "blah blah blah",
"type" => "Note",
- "attributedTo" => user.ap_id,
- "inReplyTo" => nil
- },
- "actor" => user.ap_id
+ "attributedTo" => user.ap_id
+ }
}
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
assert html_response(conn, 302) =~ "redirected"
end
- test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
+ test "does not require authentication on non-federating instances", %{
+ conn: conn,
+ user: user
+ } do
+ clear_config([:instance, :federating], false)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
+
+ conn = get(conn, "/notice/#{activity.id}")
+
+ assert html_response(conn, 200) =~ "testing a thing!"
+ end
+
+ test "returns 404 for local public activity with `restrict_unauthenticated/activities/local` setting",
+ %{conn: conn, user: user} do
+ clear_config([:restrict_unauthenticated, :activities, :local], true)
+
{:ok, activity} = CommonAPI.post(user, %{status: "testing a thing!"})
- ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
+ conn
+ |> get("/notice/#{activity.id}")
+ |> html_response(404)
end
end
end