# 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.OStatus.OStatusControllerTest do
import Pleroma.Factory
- alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
:ok
end
- setup do: clear_config([:instance, :federating], true)
+ setup do: clear_config([:static_fe, :enabled], false)
describe "Mastodon compatibility routes" do
setup %{conn: conn} do
test "redirects to /notice/id for html format", %{conn: conn} do
note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
url = "/objects/#{uuid}"
test "404s on private objects", %{conn: conn} do
note_activity = insert(:direct_note_activity)
- object = Object.normalize(note_activity)
+ object = Object.normalize(note_activity, fetch: false)
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
conn
conn: conn
} do
note_activity = insert(:note_activity)
- expected_redirect_url = Object.normalize(note_activity).data["id"]
+ expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
redirect_url =
conn
assert redirect_url == expected_redirect_url
end
- test "returns a 404 on remote notice when json requested", %{conn: conn} do
+ test "redirects to a proper object URL when json requested and the object is remote", %{
+ conn: conn
+ } do
note_activity = insert(:note_activity, local: false)
+ expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"]
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/notice/#{note_activity.id}")
- |> response(404)
+ redirect_url =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/notice/#{note_activity.id}")
+ |> redirected_to()
+
+ assert redirect_url == expected_redirect_url
end
test "500s when actor not found", %{conn: conn} do
|> response(200)
assert resp =~
- "<meta content=\"#{Pleroma.Web.base_url()}/notice/#{note_activity.id}\" property=\"og:url\">"
+ "<meta content=\"#{Pleroma.Web.Endpoint.url()}/notice/#{note_activity.id}\" property=\"og:url\">"
user = insert(:user)
assert response(conn, 404)
end
- test "it requires authentication if instance is NOT federating", %{
+ test "does not require authentication on non-federating instances", %{
conn: conn
} do
- user = insert(:user)
+ clear_config([:instance, :federating], false)
note_activity = insert(:note_activity)
- conn = put_req_header(conn, "accept", "text/html")
-
- ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user)
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/notice/#{note_activity.id}")
+ |> response(200)
end
end
describe "GET /notice/:id/embed_player" do
setup do
note_activity = insert(:note_activity)
- object = Pleroma.Object.normalize(note_activity)
+ object = Pleroma.Object.normalize(note_activity, fetch: false)
object_data =
Map.put(object.data, "attachment", [
test "404s when attachment is empty", %{conn: conn} do
note_activity = insert(:note_activity)
- object = Pleroma.Object.normalize(note_activity)
+ object = Pleroma.Object.normalize(note_activity, fetch: false)
object_data = Map.put(object.data, "attachment", [])
object
test "404s when attachment isn't audio or video", %{conn: conn} do
note_activity = insert(:note_activity)
- object = Pleroma.Object.normalize(note_activity)
+ object = Pleroma.Object.normalize(note_activity, fetch: false)
object_data =
Map.put(object.data, "attachment", [
|> response(404)
end
- test "it requires authentication if instance is NOT federating", %{
+ test "does not require authentication on non-federating instances", %{
conn: conn,
note_activity: note_activity
} do
- user = insert(:user)
- conn = put_req_header(conn, "accept", "text/html")
+ clear_config([:instance, :federating], false)
- ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user)
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/notice/#{note_activity.id}/embed_player")
+ |> response(200)
end
end
end