Merge branch 'develop' into issue/1276
This commit is contained in:
commit
dfd2c74184
259 changed files with 4072 additions and 2048 deletions
|
|
@ -8,6 +8,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Delivery
|
||||
alias Pleroma.Instances
|
||||
alias Pleroma.Object
|
||||
|
|
@ -25,12 +26,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating],
|
||||
do: Pleroma.Config.put([:instance, :federating], true)
|
||||
)
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
describe "/relay" do
|
||||
clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
|
||||
test "with the relay active, it returns the relay user", %{conn: conn} do
|
||||
res =
|
||||
|
|
@ -42,12 +41,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "with the relay disabled, it returns 404", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :allow_relay], false)
|
||||
Config.put([:instance, :allow_relay], false)
|
||||
|
||||
conn
|
||||
|> get(activity_pub_path(conn, :relay))
|
||||
|> json_response(404)
|
||||
|> assert
|
||||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get(activity_pub_path(conn, :relay))
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -60,6 +68,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert res["id"] =~ "/fetch"
|
||||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get(activity_pub_path(conn, :internal_fetch))
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname" do
|
||||
|
|
@ -123,9 +141,34 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "it returns error when user is not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
put_req_header(
|
||||
conn,
|
||||
"accept",
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
)
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}.json", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/object/:uuid" do
|
||||
describe "/objects/:uuid" do
|
||||
test "it returns a json representation of the object with accept application/json", %{
|
||||
conn: conn
|
||||
} do
|
||||
|
|
@ -236,6 +279,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
note = insert(:note)
|
||||
uuid = String.split(note.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/objects/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/activities/:uuid" do
|
||||
|
|
@ -307,6 +362,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
assert "Not found" == json_response(conn2, :not_found)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
activity = insert(:note_activity)
|
||||
uuid = String.split(activity.data["id"], "/") |> List.last()
|
||||
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/activities/#{uuid}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/inbox" do
|
||||
|
|
@ -341,6 +408,72 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert "ok" == json_response(conn, 200)
|
||||
assert Instances.reachable?(sender_url)
|
||||
end
|
||||
|
||||
test "accept follow activity", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
relay = Relay.get_actor()
|
||||
|
||||
assert {:ok, %Activity{} = activity} = Relay.follow("https://relay.mastodon.host/actor")
|
||||
|
||||
followed_relay = Pleroma.User.get_by_ap_id("https://relay.mastodon.host/actor")
|
||||
relay = refresh_record(relay)
|
||||
|
||||
accept =
|
||||
File.read!("test/fixtures/relay/accept-follow.json")
|
||||
|> String.replace("{{ap_id}}", relay.ap_id)
|
||||
|> String.replace("{{activity_id}}", activity.data["id"])
|
||||
|
||||
assert "ok" ==
|
||||
conn
|
||||
|> assign(:valid_signature, true)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/inbox", accept)
|
||||
|> json_response(200)
|
||||
|
||||
ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
|
||||
|
||||
assert Pleroma.FollowingRelationship.following?(
|
||||
relay,
|
||||
followed_relay
|
||||
)
|
||||
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
end)
|
||||
|
||||
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
|
||||
assert_receive {:mix_shell, :info, ["relay.mastodon.host"]}
|
||||
end
|
||||
|
||||
test "without valid signature, " <>
|
||||
"it only accepts Create activities and requires enabled federation",
|
||||
%{conn: conn} do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
non_create_data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!()
|
||||
|
||||
conn = put_req_header(conn, "content-type", "application/activity+json")
|
||||
|
||||
Config.put([:instance, :federating], false)
|
||||
|
||||
conn
|
||||
|> post("/inbox", data)
|
||||
|> json_response(403)
|
||||
|
||||
conn
|
||||
|> post("/inbox", non_create_data)
|
||||
|> json_response(403)
|
||||
|
||||
Config.put([:instance, :federating], true)
|
||||
|
||||
ret_conn = post(conn, "/inbox", data)
|
||||
assert "ok" == json_response(ret_conn, 200)
|
||||
|
||||
conn
|
||||
|> post("/inbox", non_create_data)
|
||||
|> json_response(400)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname/inbox" do
|
||||
|
|
@ -479,22 +612,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
test "it rejects reads from other users", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
otheruser = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, otheruser)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/inbox")
|
||||
|
||||
assert json_response(conn, 403)
|
||||
end
|
||||
|
||||
test "it doesn't crash without an authenticated user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/inbox")
|
||||
|
||||
|
|
@ -575,14 +697,30 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
refute recipient.follower_address in activity.data["cc"]
|
||||
refute recipient.follower_address in activity.data["to"]
|
||||
end
|
||||
|
||||
test "it requires authentication", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ret_conn = get(conn, "/users/#{user.nickname}/inbox")
|
||||
assert json_response(ret_conn, 403)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user.nickname}/inbox")
|
||||
|
||||
assert json_response(ret_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname/outbox" do
|
||||
test "it will not bomb when there is no activity", %{conn: conn} do
|
||||
describe "GET /users/:nickname/outbox" do
|
||||
test "it returns 200 even if there're no activities", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox")
|
||||
|
||||
|
|
@ -597,6 +735,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox?page=true")
|
||||
|
||||
|
|
@ -609,24 +748,38 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}/outbox?page=true")
|
||||
|
||||
assert response(conn, 200) =~ announce_activity.data["object"]
|
||||
end
|
||||
|
||||
test "it rejects posts from other users", %{conn: conn} do
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "application/activity+json")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}/outbox", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox" do
|
||||
test "it rejects posts from other users / unauuthenticated users", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
user = insert(:user)
|
||||
otheruser = insert(:user)
|
||||
other_user = insert(:user)
|
||||
conn = put_req_header(conn, "content-type", "application/activity+json")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, otheruser)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
conn
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> json_response(403)
|
||||
|
||||
assert json_response(conn, 403)
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "it inserts an incoming create activity into the database", %{conn: conn} do
|
||||
|
|
@ -741,24 +894,42 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:relay, true)
|
||||
|> get("/relay/followers")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == [user.ap_id]
|
||||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/relay/followers")
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/relay/following" do
|
||||
test "it returns relay following", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> assign(:relay, true)
|
||||
|> get("/relay/following")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == []
|
||||
end
|
||||
|
||||
test "on non-federating instance, it returns 404", %{conn: conn} do
|
||||
Config.put([:instance, :federating], false)
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/relay/following")
|
||||
|> json_response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname/followers" do
|
||||
|
|
@ -769,32 +940,36 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user_two)
|
||||
|> get("/users/#{user_two.nickname}/followers")
|
||||
|> json_response(200)
|
||||
|
||||
assert result["first"]["orderedItems"] == [user.ap_id]
|
||||
end
|
||||
|
||||
test "it returns returns a uri if the user has 'hide_followers' set", %{conn: conn} do
|
||||
test "it returns a uri if the user has 'hide_followers' set", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, hide_followers: true)
|
||||
User.follow(user, user_two)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user_two.nickname}/followers")
|
||||
|> json_response(200)
|
||||
|
||||
assert is_binary(result["first"])
|
||||
end
|
||||
|
||||
test "it returns a 403 error on pages, if the user has 'hide_followers' set and the request is not authenticated",
|
||||
test "it returns a 403 error on pages, if the user has 'hide_followers' set and the request is from another user",
|
||||
%{conn: conn} do
|
||||
user = insert(:user, hide_followers: true)
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, hide_followers: true)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/followers?page=1")
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{other_user.nickname}/followers?page=1")
|
||||
|
||||
assert result.status == 403
|
||||
assert result.resp_body == ""
|
||||
|
|
@ -826,6 +1001,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user.nickname}/followers")
|
||||
|> json_response(200)
|
||||
|
||||
|
|
@ -835,12 +1011,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user.nickname}/followers?page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result["orderedItems"]) == 5
|
||||
assert result["totalItems"] == 15
|
||||
end
|
||||
|
||||
test "returns 403 if requester is not logged in", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/followers")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "/users/:nickname/following" do
|
||||
|
|
@ -851,6 +1036,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user.nickname}/following")
|
||||
|> json_response(200)
|
||||
|
||||
|
|
@ -858,25 +1044,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
|
||||
test "it returns a uri if the user has 'hide_follows' set", %{conn: conn} do
|
||||
user = insert(:user, hide_follows: true)
|
||||
user_two = insert(:user)
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, hide_follows: true)
|
||||
User.follow(user, user_two)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/following")
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user_two.nickname}/following")
|
||||
|> json_response(200)
|
||||
|
||||
assert is_binary(result["first"])
|
||||
end
|
||||
|
||||
test "it returns a 403 error on pages, if the user has 'hide_follows' set and the request is not authenticated",
|
||||
test "it returns a 403 error on pages, if the user has 'hide_follows' set and the request is from another user",
|
||||
%{conn: conn} do
|
||||
user = insert(:user, hide_follows: true)
|
||||
user = insert(:user)
|
||||
user_two = insert(:user, hide_follows: true)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/following?page=1")
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user_two.nickname}/following?page=1")
|
||||
|
||||
assert result.status == 403
|
||||
assert result.resp_body == ""
|
||||
|
|
@ -909,6 +1098,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user.nickname}/following")
|
||||
|> json_response(200)
|
||||
|
||||
|
|
@ -918,12 +1108,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/users/#{user.nickname}/following?page=2")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result["orderedItems"]) == 5
|
||||
assert result["totalItems"] == 15
|
||||
end
|
||||
|
||||
test "returns 403 if requester is not logged in", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn
|
||||
|> get("/users/#{user.nickname}/following")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "delivery tracking" do
|
||||
|
|
@ -1008,8 +1207,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Additionnal ActivityPub C2S endpoints" do
|
||||
test "/api/ap/whoami", %{conn: conn} do
|
||||
describe "Additional ActivityPub C2S endpoints" do
|
||||
test "GET /api/ap/whoami", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
|
|
@ -1020,12 +1219,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert UserView.render("user.json", %{user: user}) == json_response(conn, 200)
|
||||
|
||||
conn
|
||||
|> get("/api/ap/whoami")
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
clear_config([:media_proxy])
|
||||
clear_config([Pleroma.Upload])
|
||||
setup do: clear_config([:media_proxy])
|
||||
setup do: clear_config([Pleroma.Upload])
|
||||
|
||||
test "uploadMedia", %{conn: conn} do
|
||||
test "POST /api/ap/upload_media", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
desc = "Description of the image"
|
||||
|
|
@ -1045,6 +1248,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
assert object["name"] == desc
|
||||
assert object["type"] == "Document"
|
||||
assert object["actor"] == user.ap_id
|
||||
|
||||
conn
|
||||
|> post("/api/ap/upload_media", %{"file" => image, "description" => desc})
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :federating])
|
||||
|
||||
describe "streaming out participations" do
|
||||
test "it streams them out" do
|
||||
|
|
@ -1396,7 +1396,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
describe "deletion" do
|
||||
clear_config([:instance, :rewrite_policy])
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
|
||||
test "it reverts deletion on error" do
|
||||
note = insert(:note_activity)
|
||||
|
|
@ -1425,6 +1425,12 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert Repo.get(Object, object.id).data["type"] == "Tombstone"
|
||||
end
|
||||
|
||||
test "it doesn't fail when an activity was already deleted" do
|
||||
{:ok, delete} = insert(:note_activity) |> Object.normalize() |> ActivityPub.delete()
|
||||
|
||||
assert {:ok, ^delete} = delete |> Object.normalize() |> ActivityPub.delete()
|
||||
end
|
||||
|
||||
test "decrements user note count only for public activities" do
|
||||
user = insert(:user, note_count: 10)
|
||||
|
||||
|
|
@ -1580,7 +1586,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
|
||||
describe "update" do
|
||||
clear_config([:instance, :max_pinned_statuses])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
test "it creates an update activity with the new user data" do
|
||||
user = insert(:user)
|
||||
|
|
@ -1955,11 +1961,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
activity = %Activity{activity | object: nil}
|
||||
|
||||
assert [%Notification{activity: ^activity}] =
|
||||
Notification.for_user(follower, %{with_move: true})
|
||||
assert [%Notification{activity: ^activity}] = Notification.for_user(follower)
|
||||
|
||||
assert [%Notification{activity: ^activity}] =
|
||||
Notification.for_user(follower_move_opted_out, %{with_move: true})
|
||||
assert [%Notification{activity: ^activity}] = Notification.for_user(follower_move_opted_out)
|
||||
end
|
||||
|
||||
test "old user must be in the new user's `also_known_as` list" do
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do
|
|||
[user: user, message: message]
|
||||
end
|
||||
|
||||
clear_config(:mrf_hellthread)
|
||||
setup do: clear_config(:mrf_hellthread)
|
||||
|
||||
describe "reject" do
|
||||
test "rejects the message if the recipient count is above reject_threshold", %{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF.KeywordPolicy
|
||||
|
||||
clear_config(:mrf_keyword)
|
||||
setup do: clear_config(:mrf_keyword)
|
||||
|
||||
setup do
|
||||
Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF.MentionPolicy
|
||||
|
||||
clear_config(:mrf_mention)
|
||||
setup do: clear_config(:mrf_mention)
|
||||
|
||||
test "pass filter if allow list is empty" do
|
||||
Pleroma.Config.delete([:mrf_mention])
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
|
|||
end
|
||||
|
||||
describe "describe/0" do
|
||||
clear_config([:instance, :rewrite_policy])
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
|
||||
test "it works as expected with noop policy" do
|
||||
expected = %{
|
||||
|
|
|
|||
|
|
@ -9,12 +9,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
alias Pleroma.Web.ActivityPub.MRF.ObjectAgePolicy
|
||||
alias Pleroma.Web.ActivityPub.Visibility
|
||||
|
||||
clear_config([:mrf_object_age]) do
|
||||
Config.put(:mrf_object_age,
|
||||
threshold: 172_800,
|
||||
actions: [:delist, :strip_followers]
|
||||
)
|
||||
end
|
||||
setup do:
|
||||
clear_config(:mrf_object_age,
|
||||
threshold: 172_800,
|
||||
actions: [:delist, :strip_followers]
|
||||
)
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
|
||||
|
||||
clear_config([:mrf_rejectnonpublic])
|
||||
setup do: clear_config([:mrf_rejectnonpublic])
|
||||
|
||||
describe "public message" do
|
||||
test "it's allowed when address is public" do
|
||||
|
|
|
|||
|
|
@ -8,18 +8,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||
|
||||
clear_config([:mrf_simple]) do
|
||||
Config.put(:mrf_simple,
|
||||
media_removal: [],
|
||||
media_nsfw: [],
|
||||
federated_timeline_removal: [],
|
||||
report_removal: [],
|
||||
reject: [],
|
||||
accept: [],
|
||||
avatar_removal: [],
|
||||
banner_removal: []
|
||||
)
|
||||
end
|
||||
setup do:
|
||||
clear_config(:mrf_simple,
|
||||
media_removal: [],
|
||||
media_nsfw: [],
|
||||
federated_timeline_removal: [],
|
||||
report_removal: [],
|
||||
reject: [],
|
||||
accept: [],
|
||||
avatar_removal: [],
|
||||
banner_removal: []
|
||||
)
|
||||
|
||||
describe "when :media_removal" do
|
||||
test "is empty" do
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
|
|||
"type" => "Create",
|
||||
"object" => %{"content" => "hi"}
|
||||
}
|
||||
|
||||
clear_config([:mrf_subchain, :match_actor])
|
||||
setup do: clear_config([:mrf_subchain, :match_actor])
|
||||
|
||||
test "it matches and processes subchains when the actor matches a configured target" do
|
||||
Pleroma.Config.put([:mrf_subchain, :match_actor], %{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
|
|||
|
||||
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
|
||||
|
||||
clear_config([:mrf_user_allowlist, :localhost])
|
||||
setup do: clear_config([:mrf_user_allowlist, :localhost])
|
||||
|
||||
test "pass filter if allow list is empty" do
|
||||
actor = insert(:user)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
|
||||
|
||||
describe "accept" do
|
||||
clear_config([:mrf_vocabulary, :accept])
|
||||
setup do: clear_config([:mrf_vocabulary, :accept])
|
||||
|
||||
test "it accepts based on parent activity type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
|
||||
|
|
@ -65,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
|
|||
end
|
||||
|
||||
describe "reject" do
|
||||
clear_config([:mrf_vocabulary, :reject])
|
||||
setup do: clear_config([:mrf_vocabulary, :reject])
|
||||
|
||||
test "it rejects based on parent activity type" do
|
||||
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
|
||||
describe "gather_webfinger_links/1" do
|
||||
test "it returns links" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.RelayTest do
|
|||
end
|
||||
|
||||
describe "publish/1" do
|
||||
clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :federating])
|
||||
|
||||
test "returns error when activity not `Create` type" do
|
||||
activity = insert(:like_activity)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
end
|
||||
|
||||
describe "handle_incoming" do
|
||||
clear_config([:user, :deny_follow_blocked])
|
||||
setup do: clear_config([:user, :deny_follow_blocked])
|
||||
|
||||
test "it works for osada follow request" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance, :max_remote_account_fields])
|
||||
setup do: clear_config([:instance, :max_remote_account_fields])
|
||||
|
||||
describe "handle_incoming" do
|
||||
test "it ignores an incoming notice if we already have it" do
|
||||
|
|
@ -1351,11 +1351,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end
|
||||
|
||||
describe "`handle_incoming/2`, Mastodon format `replies` handling" do
|
||||
clear_config([:activitypub, :note_replies_output_limit]) do
|
||||
Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
|
||||
end
|
||||
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
|
||||
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
||||
setup do
|
||||
data =
|
||||
|
|
@ -1394,11 +1391,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end
|
||||
|
||||
describe "`handle_incoming/2`, Pleroma format `replies` handling" do
|
||||
clear_config([:activitypub, :note_replies_output_limit]) do
|
||||
Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
|
||||
end
|
||||
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
|
||||
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -1882,7 +1876,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end
|
||||
|
||||
describe "fix_in_reply_to/2" do
|
||||
clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
setup do: clear_config([:instance, :federation_incoming_replies_max_depth])
|
||||
|
||||
setup do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
|
|
@ -2145,9 +2139,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end
|
||||
|
||||
describe "set_replies/1" do
|
||||
clear_config([:activitypub, :note_replies_output_limit]) do
|
||||
Pleroma.Config.put([:activitypub, :note_replies_output_limit], 2)
|
||||
end
|
||||
setup do: clear_config([:activitypub, :note_replies_output_limit], 2)
|
||||
|
||||
test "returns unmodified object if activity doesn't have self-replies" do
|
||||
data = Poison.decode!(File.read!("test/fixtures/mastodon-post-activity.json"))
|
||||
|
|
|
|||
|
|
@ -177,71 +177,6 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "fetch_ordered_collection" do
|
||||
import Tesla.Mock
|
||||
|
||||
test "fetches the first OrderedCollectionPage when an OrderedCollection is encountered" do
|
||||
mock(fn
|
||||
%{method: :get, url: "http://mastodon.com/outbox"} ->
|
||||
json(%{"type" => "OrderedCollection", "first" => "http://mastodon.com/outbox?page=true"})
|
||||
|
||||
%{method: :get, url: "http://mastodon.com/outbox?page=true"} ->
|
||||
json(%{"type" => "OrderedCollectionPage", "orderedItems" => ["ok"]})
|
||||
end)
|
||||
|
||||
assert Utils.fetch_ordered_collection("http://mastodon.com/outbox", 1) == ["ok"]
|
||||
end
|
||||
|
||||
test "fetches several pages in the right order one after another, but only the specified amount" do
|
||||
mock(fn
|
||||
%{method: :get, url: "http://example.com/outbox"} ->
|
||||
json(%{
|
||||
"type" => "OrderedCollectionPage",
|
||||
"orderedItems" => [0],
|
||||
"next" => "http://example.com/outbox?page=1"
|
||||
})
|
||||
|
||||
%{method: :get, url: "http://example.com/outbox?page=1"} ->
|
||||
json(%{
|
||||
"type" => "OrderedCollectionPage",
|
||||
"orderedItems" => [1],
|
||||
"next" => "http://example.com/outbox?page=2"
|
||||
})
|
||||
|
||||
%{method: :get, url: "http://example.com/outbox?page=2"} ->
|
||||
json(%{"type" => "OrderedCollectionPage", "orderedItems" => [2]})
|
||||
end)
|
||||
|
||||
assert Utils.fetch_ordered_collection("http://example.com/outbox", 0) == [0]
|
||||
assert Utils.fetch_ordered_collection("http://example.com/outbox", 1) == [0, 1]
|
||||
end
|
||||
|
||||
test "returns an error if the url doesn't have an OrderedCollection/Page" do
|
||||
mock(fn
|
||||
%{method: :get, url: "http://example.com/not-an-outbox"} ->
|
||||
json(%{"type" => "NotAnOutbox"})
|
||||
end)
|
||||
|
||||
assert {:error, _} = Utils.fetch_ordered_collection("http://example.com/not-an-outbox", 1)
|
||||
end
|
||||
|
||||
test "returns the what was collected if there are less pages than specified" do
|
||||
mock(fn
|
||||
%{method: :get, url: "http://example.com/outbox"} ->
|
||||
json(%{
|
||||
"type" => "OrderedCollectionPage",
|
||||
"orderedItems" => [0],
|
||||
"next" => "http://example.com/outbox?page=1"
|
||||
})
|
||||
|
||||
%{method: :get, url: "http://example.com/outbox?page=1"} ->
|
||||
json(%{"type" => "OrderedCollectionPage", "orderedItems" => [1]})
|
||||
end)
|
||||
|
||||
assert Utils.fetch_ordered_collection("http://example.com/outbox", 5) == [0, 1]
|
||||
end
|
||||
end
|
||||
|
||||
test "make_json_ld_header/0" do
|
||||
assert Utils.make_json_ld_header() == %{
|
||||
"@context" => [
|
||||
|
|
|
|||
|
|
@ -37,9 +37,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectViewTest do
|
|||
end
|
||||
|
||||
describe "note activity's `replies` collection rendering" do
|
||||
clear_config([:activitypub, :note_replies_output_limit]) do
|
||||
Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
|
||||
end
|
||||
setup do: clear_config([:activitypub, :note_replies_output_limit], 5)
|
||||
|
||||
test "renders `replies` collection for a note activity" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -43,9 +43,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "with [:auth, :enforce_oauth_admin_scope_usage]," do
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
|
||||
Config.put([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
end
|
||||
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], true)
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope",
|
||||
%{admin: admin} do
|
||||
|
|
@ -93,9 +91,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
|
||||
Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
end
|
||||
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
|
||||
test "GET /api/pleroma/admin/users/:nickname requires " <>
|
||||
"read:accounts or admin:read:accounts or broader scope",
|
||||
|
|
@ -581,13 +577,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/email_invite, with valid config" do
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
|
||||
clear_config([:instance, :invites_enabled]) do
|
||||
Config.put([:instance, :invites_enabled], true)
|
||||
end
|
||||
setup do: clear_config([:instance, :registrations_open], false)
|
||||
setup do: clear_config([:instance, :invites_enabled], true)
|
||||
|
||||
test "sends invitation and returns 204", %{admin: admin, conn: conn} do
|
||||
recipient_email = "foo@bar.com"
|
||||
|
|
@ -638,8 +629,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/users/email_invite, with invalid config" do
|
||||
clear_config([:instance, :registrations_open])
|
||||
clear_config([:instance, :invites_enabled])
|
||||
setup do: clear_config([:instance, :registrations_open])
|
||||
setup do: clear_config([:instance, :invites_enabled])
|
||||
|
||||
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
|
|
@ -1888,9 +1879,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/config" do
|
||||
clear_config(:configurable_from_database) do
|
||||
Config.put(:configurable_from_database, true)
|
||||
end
|
||||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
test "when configuration from database is off", %{conn: conn} do
|
||||
Config.put(:configurable_from_database, false)
|
||||
|
|
@ -2041,9 +2030,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
clear_config(:configurable_from_database) do
|
||||
Config.put(:configurable_from_database, true)
|
||||
end
|
||||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
@tag capture_log: true
|
||||
test "create new config setting in db", %{conn: conn} do
|
||||
|
|
@ -3052,9 +3039,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/restart" do
|
||||
clear_config(:configurable_from_database) do
|
||||
Config.put(:configurable_from_database, true)
|
||||
end
|
||||
setup do: clear_config(:configurable_from_database, true)
|
||||
|
||||
test "pleroma restarts", %{conn: conn} do
|
||||
capture_log(fn ->
|
||||
|
|
@ -3066,7 +3051,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/statuses" do
|
||||
test "returns all public, unlisted, and direct statuses", %{conn: conn, admin: admin} do
|
||||
test "returns all public and unlisted statuses", %{conn: conn, admin: admin} do
|
||||
blocked = insert(:user)
|
||||
user = insert(:user)
|
||||
User.block(admin, blocked)
|
||||
|
|
@ -3085,7 +3070,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> json_response(200)
|
||||
|
||||
refute "private" in Enum.map(response, & &1["visibility"])
|
||||
assert length(response) == 4
|
||||
assert length(response) == 3
|
||||
end
|
||||
|
||||
test "returns only local statuses with local_only on", %{conn: conn} do
|
||||
|
|
@ -3102,12 +3087,16 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert length(response) == 1
|
||||
end
|
||||
|
||||
test "returns private statuses with godmode on", %{conn: conn} do
|
||||
test "returns private and direct statuses with godmode on", %{conn: conn, admin: admin} do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user, %{"status" => "@#{admin.nickname}", "visibility" => "direct"})
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "private"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
|
||||
conn = get(conn, "/api/pleroma/admin/statuses?godmode=true")
|
||||
assert json_response(conn, 200) |> length() == 2
|
||||
assert json_response(conn, 200) |> length() == 3
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -3385,6 +3374,75 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /users/:nickname/credentials" do
|
||||
test "gets the user credentials", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials")
|
||||
|
||||
response = assert json_response(conn, 200)
|
||||
assert response["email"] == user.email
|
||||
end
|
||||
|
||||
test "returns 403 if requested by a non-admin" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/api/pleroma/admin/users/#{user.nickname}/credentials")
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /users/:nickname/credentials" do
|
||||
test "changes password and email", %{conn: conn, admin: admin} do
|
||||
user = insert(:user)
|
||||
assert user.password_reset_pending == false
|
||||
|
||||
conn =
|
||||
patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
||||
"password" => "new_password",
|
||||
"email" => "new_email@example.com",
|
||||
"name" => "new_name"
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
updated_user = User.get_by_id(user.id)
|
||||
|
||||
assert updated_user.email == "new_email@example.com"
|
||||
assert updated_user.name == "new_name"
|
||||
assert updated_user.password_hash != user.password_hash
|
||||
assert updated_user.password_reset_pending == true
|
||||
|
||||
[log_entry2, log_entry1] = ModerationLog |> Repo.all() |> Enum.sort()
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry1) ==
|
||||
"@#{admin.nickname} updated users: @#{user.nickname}"
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry2) ==
|
||||
"@#{admin.nickname} forced password reset for users: @#{user.nickname}"
|
||||
end
|
||||
|
||||
test "returns 403 if requested by a non-admin" do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/pleroma/admin/users/#{user.nickname}/credentials", %{
|
||||
"password" => "new_password",
|
||||
"email" => "new_email@example.com",
|
||||
"name" => "new_name"
|
||||
})
|
||||
|
||||
assert json_response(conn, :forbidden)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /users/:nickname/force_password_reset" do
|
||||
test "sets password_reset_pending to true", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ defmodule Pleroma.Web.ChatChannelTest do
|
|||
end
|
||||
|
||||
describe "message lengths" do
|
||||
clear_config([:instance, :chat_limit])
|
||||
setup do: clear_config([:instance, :chat_limit])
|
||||
|
||||
test "it ignores messages of length zero", %{socket: socket} do
|
||||
push(socket, "new_msg", %{"text" => ""})
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
require Pleroma.Constants
|
||||
|
||||
clear_config([:instance, :safe_dm_mentions])
|
||||
clear_config([:instance, :limit])
|
||||
clear_config([:instance, :max_pinned_statuses])
|
||||
setup do: clear_config([:instance, :safe_dm_mentions])
|
||||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
||||
user = insert(:user)
|
||||
|
|
@ -202,13 +202,15 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
CommonAPI.post(user, %{"status" => ""})
|
||||
end
|
||||
|
||||
test "it returns error when character limit is exceeded" do
|
||||
test "it validates character limits are correctly enforced" do
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "The status is over the character limit"} =
|
||||
CommonAPI.post(user, %{"status" => "foobar"})
|
||||
|
||||
assert {:ok, activity} = CommonAPI.post(user, %{"status" => "12345"})
|
||||
end
|
||||
|
||||
test "it can handle activities that expire" do
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
assert output == expected
|
||||
|
||||
text = "<p>hello world!</p>\n\n<p>second paragraph</p>"
|
||||
expected = "<p>hello world!</p>\n\n<p>second paragraph</p>"
|
||||
text = "<p>hello world!</p><br/>\n<p>second paragraph</p>"
|
||||
expected = "<p>hello world!</p><br/>\n<p>second paragraph</p>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/html")
|
||||
|
||||
|
|
@ -99,14 +99,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
test "works for bare text/markdown" do
|
||||
text = "**hello world**"
|
||||
expected = "<p><strong>hello world</strong></p>\n"
|
||||
expected = "<p><strong>hello world</strong></p>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
assert output == expected
|
||||
|
||||
text = "**hello world**\n\n*another paragraph*"
|
||||
expected = "<p><strong>hello world</strong></p>\n<p><em>another paragraph</em></p>\n"
|
||||
expected = "<p><strong>hello world</strong></p><p><em>another paragraph</em></p>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
|
|
@ -118,7 +118,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
by someone
|
||||
"""
|
||||
|
||||
expected = "<blockquote><p>cool quote</p>\n</blockquote>\n<p>by someone</p>\n"
|
||||
expected = "<blockquote><p>cool quote</p></blockquote><p>by someone</p>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
assert output == expected
|
||||
|
||||
text = "[b]hello world![/b]\n\nsecond paragraph!"
|
||||
expected = "<strong>hello world!</strong><br>\n<br>\nsecond paragraph!"
|
||||
expected = "<strong>hello world!</strong><br><br>second paragraph!"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/bbcode")
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
text = "[b]hello world![/b]\n\n<strong>second paragraph!</strong>"
|
||||
|
||||
expected =
|
||||
"<strong>hello world!</strong><br>\n<br>\n<strong>second paragraph!</strong>"
|
||||
"<strong>hello world!</strong><br><br><strong>second paragraph!</strong>"
|
||||
|
||||
{output, [], []} = Utils.format_input(text, "text/bbcode")
|
||||
|
||||
|
|
@ -156,16 +156,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
|
||||
|
||||
expected =
|
||||
~s(<p><strong>hello world</strong></p>\n<p><em>another <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>\n)
|
||||
|
||||
{output, _, _} = Utils.format_input(text, "text/markdown")
|
||||
|
||||
assert output == expected
|
||||
assert output ==
|
||||
~s(<p><strong>hello world</strong></p><p><em>another <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> and <span class="h-card"><a data-user="#{
|
||||
user.id
|
||||
}" class="u-url mention" href="http://foo.com/user__test" rel="ugc">@<span>user__test</span></a></span> <a href="http://google.com" rel="ugc">google.com</a> paragraph</em></p>)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,13 +21,10 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
|
||||
clear_config([:instance, :allow_relay])
|
||||
clear_config([:instance, :rewrite_policy])
|
||||
clear_config([:mrf_keyword])
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:instance, :rewrite_policy])
|
||||
setup do: clear_config([:mrf_keyword])
|
||||
|
||||
describe "Publish an activity" do
|
||||
setup do
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
import Pleroma.Factory
|
||||
import SweetXml
|
||||
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.Feed.FeedView
|
||||
|
||||
clear_config([:feed])
|
||||
setup do: clear_config([:feed])
|
||||
|
||||
test "gets a feed (ATOM)", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
|
|
@ -19,9 +21,9 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
|
||||
{:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
|
||||
|
||||
object = Pleroma.Object.normalize(activity1)
|
||||
object = Object.normalize(activity1)
|
||||
|
||||
object_data =
|
||||
Map.put(object.data, "attachment", [
|
||||
|
|
@ -41,14 +43,13 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
{:ok, _activity2} =
|
||||
Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
|
||||
{:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
|
||||
|
||||
{:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})
|
||||
{:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart.atom"))
|
||||
|> response(200)
|
||||
|
||||
|
|
@ -63,6 +64,21 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
|
||||
assert xpath(xml, ~x"//feed/entry/author/name/text()"ls) == [user.nickname, user.nickname]
|
||||
assert xpath(xml, ~x"//feed/entry/author/id/text()"ls) == [user.ap_id, user.ap_id]
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get("/tags/pleromaart.atom", %{"max_id" => activity2.id})
|
||||
|
||||
assert get_resp_header(conn, "content-type") == ["application/atom+xml; charset=utf-8"]
|
||||
resp = response(conn, 200)
|
||||
xml = parse(resp)
|
||||
|
||||
assert xpath(xml, ~x"//feed/title/text()") == '#pleromaart'
|
||||
|
||||
assert xpath(xml, ~x"//feed/entry/title/text()"l) == [
|
||||
'yeah #PleromaArt'
|
||||
]
|
||||
end
|
||||
|
||||
test "gets a feed (RSS)", %{conn: conn} do
|
||||
|
|
@ -72,9 +88,9 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
)
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, activity1} = Pleroma.Web.CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
|
||||
{:ok, activity1} = CommonAPI.post(user, %{"status" => "yeah #PleromaArt"})
|
||||
|
||||
object = Pleroma.Object.normalize(activity1)
|
||||
object = Object.normalize(activity1)
|
||||
|
||||
object_data =
|
||||
Map.put(object.data, "attachment", [
|
||||
|
|
@ -94,14 +110,13 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
{:ok, activity2} =
|
||||
Pleroma.Web.CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
|
||||
{:ok, activity2} = CommonAPI.post(user, %{"status" => "42 This is :moominmamma #PleromaArt"})
|
||||
|
||||
{:ok, _activity3} = Pleroma.Web.CommonAPI.post(user, %{"status" => "This is :moominmamma"})
|
||||
{:ok, _activity3} = CommonAPI.post(user, %{"status" => "This is :moominmamma"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/rss+xml")
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart.rss"))
|
||||
|> response(200)
|
||||
|
||||
|
|
@ -131,8 +146,8 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4"
|
||||
]
|
||||
|
||||
obj1 = Pleroma.Object.normalize(activity1)
|
||||
obj2 = Pleroma.Object.normalize(activity2)
|
||||
obj1 = Object.normalize(activity1)
|
||||
obj2 = Object.normalize(activity2)
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
|
||||
HtmlEntities.decode(FeedView.activity_content(obj2)),
|
||||
|
|
@ -141,7 +156,7 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get(tag_feed_path(conn, :feed, "pleromaart"))
|
||||
|> response(200)
|
||||
|
||||
|
|
@ -150,5 +165,20 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
|
||||
assert xpath(xml, ~x"//channel/description/text()"s) ==
|
||||
"These are public toots tagged with #pleromaart. You can interact with them if you have an account anywhere in the fediverse."
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get("/tags/pleromaart.rss", %{"max_id" => activity2.id})
|
||||
|
||||
assert get_resp_header(conn, "content-type") == ["application/rss+xml; charset=utf-8"]
|
||||
resp = response(conn, 200)
|
||||
xml = parse(resp)
|
||||
|
||||
assert xpath(xml, ~x"//channel/title/text()") == '#pleromaart'
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/title/text()"l) == [
|
||||
'yeah #PleromaArt'
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,222 +8,160 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
import Pleroma.Factory
|
||||
import SweetXml
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
|
||||
clear_config([:feed])
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
test "gets a feed", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 10, omission: "..."}
|
||||
)
|
||||
describe "feed" do
|
||||
setup do: clear_config([:feed])
|
||||
|
||||
activity = insert(:note_activity)
|
||||
|
||||
note =
|
||||
insert(:note,
|
||||
data: %{
|
||||
"content" => "This is :moominmamma: note ",
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}]
|
||||
}
|
||||
],
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
test "gets a feed", %{conn: conn} do
|
||||
Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 10, omission: "..."}
|
||||
)
|
||||
|
||||
note_activity = insert(:note_activity, note: note)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
activity = insert(:note_activity)
|
||||
|
||||
note2 =
|
||||
insert(:note,
|
||||
user: user,
|
||||
data: %{"content" => "42 This is :moominmamma: note ", "inReplyTo" => activity.data["id"]}
|
||||
note =
|
||||
insert(:note,
|
||||
data: %{
|
||||
"content" => "This is :moominmamma: note ",
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
|
||||
]
|
||||
}
|
||||
],
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
||||
note_activity = insert(:note_activity, note: note)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
note2 =
|
||||
insert(:note,
|
||||
user: user,
|
||||
data: %{
|
||||
"content" => "42 This is :moominmamma: note ",
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
||||
note_activity2 = insert(:note_activity, note: note2)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||
|> response(200)
|
||||
|
||||
activity_titles =
|
||||
resp
|
||||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//entry/title/text()"l)
|
||||
|
||||
assert activity_titles == ['42 This...', 'This is...']
|
||||
assert resp =~ object.data["content"]
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get("/users/#{user.nickname}/feed", %{"max_id" => note_activity2.id})
|
||||
|> response(200)
|
||||
|
||||
activity_titles =
|
||||
resp
|
||||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//entry/title/text()"l)
|
||||
|
||||
assert activity_titles == ['This is...']
|
||||
end
|
||||
|
||||
test "gets a rss feed", %{conn: conn} do
|
||||
Pleroma.Config.put(
|
||||
[:feed, :post_title],
|
||||
%{max_length: 10, omission: "..."}
|
||||
)
|
||||
|
||||
_note_activity2 = insert(:note_activity, note: note2)
|
||||
object = Object.normalize(note_activity)
|
||||
activity = insert(:note_activity)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||
|> response(200)
|
||||
note =
|
||||
insert(:note,
|
||||
data: %{
|
||||
"content" => "This is :moominmamma: note ",
|
||||
"attachment" => [
|
||||
%{
|
||||
"url" => [
|
||||
%{"mediaType" => "image/png", "href" => "https://pleroma.gov/image.png"}
|
||||
]
|
||||
}
|
||||
],
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
||||
activity_titles =
|
||||
resp
|
||||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//entry/title/text()"l)
|
||||
note_activity = insert(:note_activity, note: note)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
assert activity_titles == ['42 This...', 'This is...']
|
||||
assert resp =~ object.data["content"]
|
||||
end
|
||||
|
||||
test "returns 404 for a missing feed", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/atom+xml")
|
||||
|> get(user_feed_path(conn, :feed, "nonexisting"))
|
||||
|
||||
assert response(conn, 404)
|
||||
note2 =
|
||||
insert(:note,
|
||||
user: user,
|
||||
data: %{
|
||||
"content" => "42 This is :moominmamma: note ",
|
||||
"inReplyTo" => activity.data["id"]
|
||||
}
|
||||
)
|
||||
|
||||
note_activity2 = insert(:note_activity, note: note2)
|
||||
object = Object.normalize(note_activity)
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get("/users/#{user.nickname}/feed.rss")
|
||||
|> response(200)
|
||||
|
||||
activity_titles =
|
||||
resp
|
||||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//item/title/text()"l)
|
||||
|
||||
assert activity_titles == ['42 This...', 'This is...']
|
||||
assert resp =~ object.data["content"]
|
||||
|
||||
resp =
|
||||
conn
|
||||
|> put_req_header("accept", "application/rss+xml")
|
||||
|> get("/users/#{user.nickname}/feed.rss", %{"max_id" => note_activity2.id})
|
||||
|> response(200)
|
||||
|
||||
activity_titles =
|
||||
resp
|
||||
|> SweetXml.parse()
|
||||
|> SweetXml.xpath(~x"//item/title/text()"l)
|
||||
|
||||
assert activity_titles == ['This is...']
|
||||
end
|
||||
|
||||
test "returns 404 for a missing feed", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(user_feed_path(conn, :feed, "nonexisting"))
|
||||
|
||||
assert response(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
# Note: see ActivityPubControllerTest for JSON format tests
|
||||
describe "feed_redirect" do
|
||||
test "undefined format. it redirects to feed", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> response(302)
|
||||
|
||||
assert response ==
|
||||
"<html><body>You are being <a href=\"#{Pleroma.Web.base_url()}/users/#{
|
||||
user.nickname
|
||||
}/feed.atom\">redirected</a>.</body></html>"
|
||||
end
|
||||
|
||||
test "undefined format. it returns error when user not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get(user_feed_path(conn, :feed, "jimm"))
|
||||
|> response(404)
|
||||
|
||||
assert response == ~S({"error":"Not found"})
|
||||
end
|
||||
|
||||
test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> json_response(200)
|
||||
|
||||
assert response["endpoints"] == %{
|
||||
"oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
|
||||
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
|
||||
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
|
||||
"sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
|
||||
"uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
|
||||
}
|
||||
|
||||
assert response["@context"] == [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
%{"@language" => "und"}
|
||||
]
|
||||
|
||||
assert Map.take(response, [
|
||||
"followers",
|
||||
"following",
|
||||
"id",
|
||||
"inbox",
|
||||
"manuallyApprovesFollowers",
|
||||
"name",
|
||||
"outbox",
|
||||
"preferredUsername",
|
||||
"summary",
|
||||
"tag",
|
||||
"type",
|
||||
"url"
|
||||
]) == %{
|
||||
"followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
|
||||
"following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
|
||||
"id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
|
||||
"inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
|
||||
"manuallyApprovesFollowers" => false,
|
||||
"name" => user.name,
|
||||
"outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
|
||||
"preferredUsername" => user.nickname,
|
||||
"summary" => user.bio,
|
||||
"tag" => [],
|
||||
"type" => "Person",
|
||||
"url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
|
||||
}
|
||||
end
|
||||
|
||||
test "activity+json format. it returns error whe use not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "json format. it redirects on actual feed of user", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|> json_response(200)
|
||||
|
||||
assert response["endpoints"] == %{
|
||||
"oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
|
||||
"oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
|
||||
"oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
|
||||
"sharedInbox" => "#{Pleroma.Web.base_url()}/inbox",
|
||||
"uploadMedia" => "#{Pleroma.Web.base_url()}/api/ap/upload_media"
|
||||
}
|
||||
|
||||
assert response["@context"] == [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"http://localhost:4001/schemas/litepub-0.1.jsonld",
|
||||
%{"@language" => "und"}
|
||||
]
|
||||
|
||||
assert Map.take(response, [
|
||||
"followers",
|
||||
"following",
|
||||
"id",
|
||||
"inbox",
|
||||
"manuallyApprovesFollowers",
|
||||
"name",
|
||||
"outbox",
|
||||
"preferredUsername",
|
||||
"summary",
|
||||
"tag",
|
||||
"type",
|
||||
"url"
|
||||
]) == %{
|
||||
"followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
|
||||
"following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
|
||||
"id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
|
||||
"inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
|
||||
"manuallyApprovesFollowers" => false,
|
||||
"name" => user.name,
|
||||
"outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
|
||||
"preferredUsername" => user.nickname,
|
||||
"summary" => user.bio,
|
||||
"tag" => [],
|
||||
"type" => "Person",
|
||||
"url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
|
||||
}
|
||||
end
|
||||
|
||||
test "json format. it returns error whe use not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/users/jimm")
|
||||
|> json_response(404)
|
||||
|
||||
assert response == "Not found"
|
||||
end
|
||||
|
||||
test "html format. it redirects on actual feed of user", %{conn: conn} do
|
||||
test "with html format, it redirects to user feed", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
|
|
@ -239,7 +177,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
).resp_body
|
||||
end
|
||||
|
||||
test "html format. it returns error when user not found", %{conn: conn} do
|
||||
test "with html format, it returns error when user is not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/users/jimm")
|
||||
|
|
@ -247,5 +185,30 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|
||||
assert response == %{"error" => "Not found"}
|
||||
end
|
||||
|
||||
test "with non-html / non-json format, it redirects to user feed in atom format", %{
|
||||
conn: conn
|
||||
} do
|
||||
note_activity = insert(:note_activity)
|
||||
user = User.get_cached_by_ap_id(note_activity.data["actor"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|
||||
assert conn.status == 302
|
||||
assert redirected_to(conn) == "#{Pleroma.Web.base_url()}/users/#{user.nickname}/feed.atom"
|
||||
end
|
||||
|
||||
test "with non-html / non-json format, it returns error when user is not found", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get(user_feed_path(conn, :feed, "jimm"))
|
||||
|> response(404)
|
||||
|
||||
assert response == ~S({"error":"Not found"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ defmodule Pleroma.Instances.InstanceTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config_all([:instance, :federation_reachability_timeout_days]) do
|
||||
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
|
||||
end
|
||||
setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
|
||||
|
||||
describe "set_reachable/1" do
|
||||
test "clears `unreachable_since` of existing matching Instance record having non-nil `unreachable_since`" do
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ defmodule Pleroma.InstancesTest do
|
|||
|
||||
use Pleroma.DataCase
|
||||
|
||||
clear_config_all([:instance, :federation_reachability_timeout_days]) do
|
||||
Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
|
||||
end
|
||||
setup_all do: clear_config([:instance, :federation_reachability_timeout_days], 1)
|
||||
|
||||
describe "reachable?/1" do
|
||||
test "returns `true` for host / url with unknown reachability status" do
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEController do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:instance, :public])
|
||||
setup do: clear_config([:instance, :public])
|
||||
|
||||
test "put settings", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
clear_config([:instance, :max_account_fields])
|
||||
|
||||
setup do: clear_config([:instance, :max_account_fields])
|
||||
|
||||
describe "updating credentials" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
|
|
@ -75,7 +76,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"note" => "I drink #cofe with @#{user2.nickname}"
|
||||
"note" => "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
||||
})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
|
|
@ -83,7 +84,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user_data["note"] ==
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a data-user="#{
|
||||
user2.id
|
||||
}" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span>)
|
||||
}" class="u-url mention" href="#{user2.ap_id}" rel="ugc">@<span>#{user2.nickname}</span></a></span><br/><br/>suya..)
|
||||
end
|
||||
|
||||
test "updates the user's locking status", %{conn: conn} do
|
||||
|
|
@ -117,6 +118,18 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user_data["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
test "updates the user's discoverable status", %{conn: conn} do
|
||||
assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
|
||||
|> json_response(:ok)
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
||||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -15,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
describe "account fetching" do
|
||||
clear_config([:instance, :limit_to_local_content])
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
test "works by id" do
|
||||
user = insert(:user)
|
||||
|
|
@ -46,7 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "works by nickname for remote users" do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], false)
|
||||
Config.put([:instance, :limit_to_local_content], false)
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
conn =
|
||||
|
|
@ -58,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :all for remote user nicknames" do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :all)
|
||||
Config.put([:instance, :limit_to_local_content], :all)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
|
|
@ -70,7 +71,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
|
||||
Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
reading_user = insert(:user)
|
||||
|
|
@ -140,6 +141,98 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_users do
|
||||
local = insert(:user)
|
||||
remote = insert(:user, local: false)
|
||||
{:ok, local: local, remote: remote}
|
||||
end
|
||||
|
||||
describe "user fetching with restrict unauthenticated profiles for local and remote" do
|
||||
setup do: local_and_remote_users()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user fetching with restrict unauthenticated profiles for local" do
|
||||
setup do: local_and_remote_users()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user fetching with restrict unauthenticated profiles for remote" do
|
||||
setup do: local_and_remote_users()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "user timelines" do
|
||||
setup do: oauth_access(["read:statuses"])
|
||||
|
||||
|
|
@ -293,6 +386,102 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_activities(%{local: local, remote: remote}) do
|
||||
insert(:note_activity, user: local)
|
||||
insert(:note_activity, user: remote, local: false)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "statuses with restrict unauthenticated profiles for local and remote" do
|
||||
setup do: local_and_remote_users()
|
||||
setup :local_and_remote_activities
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "statuses with restrict unauthenticated profiles for local" do
|
||||
setup do: local_and_remote_users()
|
||||
setup :local_and_remote_activities
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "statuses with restrict unauthenticated profiles for remote" do
|
||||
setup do: local_and_remote_users()
|
||||
setup :local_and_remote_activities
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Can't find user"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{local.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{remote.id}/statuses")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "followers" do
|
||||
setup do: oauth_access(["read:accounts"])
|
||||
|
||||
|
|
@ -601,6 +790,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
[valid_params: valid_params]
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "Account registration via Application", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/v1/apps", %{
|
||||
|
|
@ -685,7 +876,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert json_response(res, 200)
|
||||
|
||||
[{127, 0, 0, 1}, {127, 0, 0, 2}, {127, 0, 0, 3}, {127, 0, 0, 4}]
|
||||
|> Stream.zip(valid_params)
|
||||
|> Stream.zip(Map.delete(valid_params, :email))
|
||||
|> Enum.each(fn {ip, {attr, _}} ->
|
||||
res =
|
||||
conn
|
||||
|
|
@ -697,6 +888,54 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "returns bad_request if missing email params when :account_activation_required is enabled",
|
||||
%{conn: conn, valid_params: valid_params} do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 5})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response(res, 400) == %{"error" => "Missing parameters"}
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 6})
|
||||
|> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
|
||||
|
||||
assert json_response(res, 400) == %{"error" => "{\"email\":[\"can't be blank\"]}"}
|
||||
end
|
||||
|
||||
test "allow registration without an email", %{conn: conn, valid_params: valid_params} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 7})
|
||||
|> post("/api/v1/accounts", Map.delete(valid_params, :email))
|
||||
|
||||
assert json_response(res, 200)
|
||||
end
|
||||
|
||||
test "allow registration with an empty email", %{conn: conn, valid_params: valid_params} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> app_token.token)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> Map.put(:remote_ip, {127, 0, 0, 8})
|
||||
|> post("/api/v1/accounts", Map.put(valid_params, :email, ""))
|
||||
|
||||
assert json_response(res, 200)
|
||||
end
|
||||
|
||||
test "returns forbidden if token is invalid", %{conn: conn, valid_params: valid_params} do
|
||||
conn = put_req_header(conn, "authorization", "Bearer " <> "invalid-token")
|
||||
|
||||
|
|
@ -706,13 +945,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
describe "create account by app / rate limit" do
|
||||
clear_config([Pleroma.Plugs.RemoteIp, :enabled]) do
|
||||
Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], true)
|
||||
end
|
||||
|
||||
clear_config([:rate_limit, :app_account_creation]) do
|
||||
Pleroma.Config.put([:rate_limit, :app_account_creation], {10_000, 2})
|
||||
end
|
||||
setup do: clear_config([:rate_limit, :app_account_creation], {10_000, 2})
|
||||
|
||||
test "respects rate limit setting", %{conn: conn} do
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
[image: image]
|
||||
end
|
||||
|
||||
clear_config([:media_proxy])
|
||||
clear_config([Pleroma.Upload])
|
||||
setup do: clear_config([:media_proxy])
|
||||
setup do: clear_config([Pleroma.Upload])
|
||||
|
||||
test "returns uploaded image", %{conn: conn, image: image} do
|
||||
desc = "Description of the image"
|
||||
|
|
|
|||
|
|
@ -304,6 +304,51 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
end
|
||||
|
||||
test "filters notifications using include_types" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
|
||||
{:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
|
||||
{:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
|
||||
|
||||
mention_notification_id = get_notification_id_by_activity(mention_activity)
|
||||
favorite_notification_id = get_notification_id_by_activity(favorite_activity)
|
||||
reblog_notification_id = get_notification_id_by_activity(reblog_activity)
|
||||
follow_notification_id = get_notification_id_by_activity(follow_activity)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["follow"]})
|
||||
|
||||
assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["mention"]})
|
||||
|
||||
assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["favourite"]})
|
||||
|
||||
assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications", %{include_types: ["reblog"]})
|
||||
|
||||
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
|
||||
|
||||
result = conn |> get("/api/v1/notifications") |> json_response(200)
|
||||
|
||||
assert length(result) == 4
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/notifications", %{
|
||||
include_types: ["follow", "mention", "favourite", "reblog"]
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert length(result) == 4
|
||||
end
|
||||
|
||||
test "destroy multiple" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
|
@ -407,7 +452,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
||||
test "see move notifications with `with_move` parameter" do
|
||||
test "see move notifications" do
|
||||
old_user = insert(:user)
|
||||
new_user = insert(:user, also_known_as: [old_user.ap_id])
|
||||
%{user: follower, conn: conn} = oauth_access(["read:notifications"])
|
||||
|
|
@ -416,11 +461,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
|
||||
Pleroma.Tests.ObanHelpers.perform_all()
|
||||
|
||||
ret_conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert json_response(ret_conn, 200) == []
|
||||
|
||||
conn = get(conn, "/api/v1/notifications", %{"with_move" => "true"})
|
||||
conn = get(conn, "/api/v1/notifications")
|
||||
|
||||
assert length(json_response(conn, 200)) == 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
import Pleroma.Factory
|
||||
import Ecto.Query
|
||||
|
||||
clear_config([ScheduledActivity, :enabled])
|
||||
setup do: clear_config([ScheduledActivity, :enabled])
|
||||
|
||||
test "shows scheduled activities" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
clear_config([:instance, :allow_relay])
|
||||
clear_config([:rich_media, :enabled])
|
||||
setup do: clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :allow_relay])
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
|
||||
describe "posting statuses" do
|
||||
setup do: oauth_access(["write:statuses"])
|
||||
|
|
@ -476,6 +476,95 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
defp local_and_remote_activities do
|
||||
local = insert(:note_activity)
|
||||
remote = insert(:note_activity, local: false)
|
||||
{:ok, local: local, remote: remote}
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for local and remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for local" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "status with restrict unauthenticated activities for remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
|
||||
assert json_response(res_conn, :not_found) == %{
|
||||
"error" => "Record not found"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
res_conn = get(conn, "/api/v1/statuses/#{local.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses/#{remote.id}")
|
||||
assert %{"id" => _} = json_response(res_conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
test "getting a status that doesn't exist returns 404" do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -514,6 +603,70 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert [%{"id" => ^id1}, %{"id" => ^id2}] = Enum.sort_by(json_response(conn, :ok), & &1["id"])
|
||||
end
|
||||
|
||||
describe "getting statuses by ids with restricted unauthenticated for local and remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert json_response(res_conn, 200) == []
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting statuses by ids with restricted unauthenticated for local" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
remote_id = remote.id
|
||||
assert [%{"id" => ^remote_id}] = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting statuses by ids with restricted unauthenticated for remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :activities, :remote], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn, local: local, remote: remote} do
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
local_id = local.id
|
||||
assert [%{"id" => ^local_id}] = json_response(res_conn, 200)
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{local: local, remote: remote} do
|
||||
%{conn: conn} = oauth_access(["read"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/statuses", %{ids: [local.id, remote.id]})
|
||||
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "deleting a status" do
|
||||
test "when you created it" do
|
||||
%{user: author, conn: conn} = oauth_access(["write:statuses"])
|
||||
|
|
@ -739,9 +892,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
%{activity: activity}
|
||||
end
|
||||
|
||||
clear_config([:instance, :max_pinned_statuses]) do
|
||||
Config.put([:instance, :max_pinned_statuses], 1)
|
||||
end
|
||||
setup do: clear_config([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
test "pin status", %{conn: conn, user: user, activity: activity} do
|
||||
id_str = to_string(activity.id)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
clear_config([:instance, :public])
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
|
|
@ -23,9 +21,12 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
setup do: oauth_access(["read:statuses"])
|
||||
|
||||
test "the home timeline", %{user: user, conn: conn} do
|
||||
following = insert(:user)
|
||||
following = insert(:user, nickname: "followed")
|
||||
third_user = insert(:user, nickname: "repeated")
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "post"})
|
||||
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})
|
||||
{:ok, _, _} = CommonAPI.repeat(activity.id, following)
|
||||
|
||||
ret_conn = get(conn, "/api/v1/timelines/home")
|
||||
|
||||
|
|
@ -33,9 +34,54 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
|
||||
{:ok, _user} = User.follow(user, following)
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/home")
|
||||
ret_conn = get(conn, "/api/v1/timelines/home")
|
||||
|
||||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
assert [
|
||||
%{
|
||||
"reblog" => %{
|
||||
"content" => "repeated post",
|
||||
"account" => %{
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"following" => false, "followed_by" => false}
|
||||
}
|
||||
}
|
||||
},
|
||||
"account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
|
||||
},
|
||||
%{
|
||||
"content" => "post",
|
||||
"account" => %{
|
||||
"acct" => "followed",
|
||||
"pleroma" => %{"relationship" => %{"following" => true}}
|
||||
}
|
||||
}
|
||||
] = json_response(ret_conn, :ok)
|
||||
|
||||
{:ok, _user} = User.follow(third_user, user)
|
||||
|
||||
ret_conn = get(conn, "/api/v1/timelines/home")
|
||||
|
||||
assert [
|
||||
%{
|
||||
"reblog" => %{
|
||||
"content" => "repeated post",
|
||||
"account" => %{
|
||||
"acct" => "repeated",
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"following" => false, "followed_by" => true}
|
||||
}
|
||||
}
|
||||
},
|
||||
"account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
|
||||
},
|
||||
%{
|
||||
"content" => "post",
|
||||
"account" => %{
|
||||
"acct" => "followed",
|
||||
"pleroma" => %{"relationship" => %{"following" => true}}
|
||||
}
|
||||
}
|
||||
] = json_response(ret_conn, :ok)
|
||||
end
|
||||
|
||||
test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
|
||||
|
|
@ -80,15 +126,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
assert [%{"content" => "test"}] = json_response(conn, :ok)
|
||||
end
|
||||
|
||||
test "the public timeline when public is set to false", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
|
||||
assert %{"error" => "This resource requires authentication."} ==
|
||||
conn
|
||||
|> get("/api/v1/timelines/public", %{"local" => "False"})
|
||||
|> json_response(:forbidden)
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
|
|
@ -102,6 +139,98 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
defp local_and_remote_activities do
|
||||
insert(:note_activity)
|
||||
insert(:note_activity, local: false)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "public with restrict unauthenticated timeline for local and federated timelines" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn} do
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated" do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "public with restrict unauthenticated timeline for local" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn} do
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{conn: _conn} do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "public with restrict unauthenticated timeline for remote" do
|
||||
setup do: local_and_remote_activities()
|
||||
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
test "if user is unauthenticated", %{conn: conn} do
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == %{
|
||||
"error" => "authorization required for timeline view"
|
||||
}
|
||||
end
|
||||
|
||||
test "if user is authenticated", %{conn: _conn} do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "true"})
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "/api/v1/timelines/public", %{"local" => "false"})
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "direct" do
|
||||
test "direct timeline", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
||||
|
|
@ -32,7 +35,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
background: background_image,
|
||||
nickname: "shp@shitposter.club",
|
||||
name: ":karjalanpiirakka: shp",
|
||||
bio: "<script src=\"invalid-html\"></script><span>valid html</span>",
|
||||
bio:
|
||||
"<script src=\"invalid-html\"></script><span>valid html</span>. a<br>b<br/>c<br >d<br />f",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
})
|
||||
|
||||
|
|
@ -46,7 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
followers_count: 3,
|
||||
following_count: 0,
|
||||
statuses_count: 5,
|
||||
note: "<span>valid html</span>",
|
||||
note: "<span>valid html</span>. a<br/>b<br/>c<br/>d<br/>f",
|
||||
url: user.ap_id,
|
||||
avatar: "http://localhost:4001/images/avi.png",
|
||||
avatar_static: "http://localhost:4001/images/avi.png",
|
||||
|
|
@ -63,7 +67,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
fields: [],
|
||||
bot: false,
|
||||
source: %{
|
||||
note: "valid html",
|
||||
note: "valid html. a\nb\nc\nd\nf",
|
||||
sensitive: false,
|
||||
pleroma: %{
|
||||
actor_type: "Person",
|
||||
|
|
@ -181,6 +185,29 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
describe "relationship" do
|
||||
defp test_relationship_rendering(user, other_user, expected_result) do
|
||||
opts = %{user: user, target: other_user, relationships: nil}
|
||||
assert expected_result == AccountView.render("relationship.json", opts)
|
||||
|
||||
relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
|
||||
opts = Map.put(opts, :relationships, relationships_opt)
|
||||
assert expected_result == AccountView.render("relationship.json", opts)
|
||||
end
|
||||
|
||||
@blank_response %{
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: false,
|
||||
blocked_by: false,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
|
||||
test "represent a relationship for the following and followed user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -191,23 +218,21 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
{:ok, _user_relationships} = User.mute(user, other_user, true)
|
||||
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
|
||||
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: true,
|
||||
followed_by: true,
|
||||
blocking: false,
|
||||
blocked_by: false,
|
||||
muting: true,
|
||||
muting_notifications: true,
|
||||
subscribing: true,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: false,
|
||||
endorsed: false
|
||||
}
|
||||
expected =
|
||||
Map.merge(
|
||||
@blank_response,
|
||||
%{
|
||||
following: true,
|
||||
followed_by: true,
|
||||
muting: true,
|
||||
muting_notifications: true,
|
||||
subscribing: true,
|
||||
showing_reblogs: false,
|
||||
id: to_string(other_user.id)
|
||||
}
|
||||
)
|
||||
|
||||
assert expected ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
test_relationship_rendering(user, other_user, expected)
|
||||
end
|
||||
|
||||
test "represent a relationship for the blocking and blocked user" do
|
||||
|
|
@ -219,23 +244,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
{:ok, _user_relationship} = User.block(user, other_user)
|
||||
{:ok, _user_relationship} = User.block(other_user, user)
|
||||
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: true,
|
||||
blocked_by: true,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
expected =
|
||||
Map.merge(
|
||||
@blank_response,
|
||||
%{following: false, blocking: true, blocked_by: true, id: to_string(other_user.id)}
|
||||
)
|
||||
|
||||
assert expected ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
test_relationship_rendering(user, other_user, expected)
|
||||
end
|
||||
|
||||
test "represent a relationship for the user blocking a domain" do
|
||||
|
|
@ -244,8 +259,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
{:ok, user} = User.block_domain(user, "bad.site")
|
||||
|
||||
assert %{domain_blocking: true, blocking: false} =
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
expected =
|
||||
Map.merge(
|
||||
@blank_response,
|
||||
%{domain_blocking: true, blocking: false, id: to_string(other_user.id)}
|
||||
)
|
||||
|
||||
test_relationship_rendering(user, other_user, expected)
|
||||
end
|
||||
|
||||
test "represent a relationship for the user with a pending follow request" do
|
||||
|
|
@ -256,23 +276,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: false,
|
||||
blocked_by: false,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
requested: true,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
expected =
|
||||
Map.merge(
|
||||
@blank_response,
|
||||
%{requested: true, following: false, id: to_string(other_user.id)}
|
||||
)
|
||||
|
||||
assert expected ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
test_relationship_rendering(user, other_user, expected)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,21 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
import Pleroma.Factory
|
||||
|
||||
defp test_notifications_rendering(notifications, user, expected_result) do
|
||||
result = NotificationView.render("index.json", %{notifications: notifications, for: user})
|
||||
|
||||
assert expected_result == result
|
||||
|
||||
result =
|
||||
NotificationView.render("index.json", %{
|
||||
notifications: notifications,
|
||||
for: user,
|
||||
relationships: nil
|
||||
})
|
||||
|
||||
assert expected_result == result
|
||||
end
|
||||
|
||||
test "Mention notification" do
|
||||
user = insert(:user)
|
||||
mentioned_user = insert(:user)
|
||||
|
|
@ -32,10 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
result =
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: mentioned_user})
|
||||
|
||||
assert [expected] == result
|
||||
test_notifications_rendering([notification], mentioned_user, [expected])
|
||||
end
|
||||
|
||||
test "Favourite notification" do
|
||||
|
|
@ -55,9 +67,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
result = NotificationView.render("index.json", %{notifications: [notification], for: user})
|
||||
|
||||
assert [expected] == result
|
||||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Reblog notification" do
|
||||
|
|
@ -77,9 +87,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
result = NotificationView.render("index.json", %{notifications: [notification], for: user})
|
||||
|
||||
assert [expected] == result
|
||||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
|
||||
test "Follow notification" do
|
||||
|
|
@ -96,16 +104,12 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
result =
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: followed})
|
||||
|
||||
assert [expected] == result
|
||||
test_notifications_rendering([notification], followed, [expected])
|
||||
|
||||
User.perform(:delete, follower)
|
||||
notification = Notification |> Repo.one() |> Repo.preload(:activity)
|
||||
|
||||
assert [] ==
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: followed})
|
||||
test_notifications_rendering([notification], followed, [])
|
||||
end
|
||||
|
||||
test "Move notification" do
|
||||
|
|
@ -120,7 +124,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
old_user = refresh_record(old_user)
|
||||
new_user = refresh_record(new_user)
|
||||
|
||||
[notification] = Notification.for_user(follower, %{with_move: true})
|
||||
[notification] = Notification.for_user(follower)
|
||||
|
||||
expected = %{
|
||||
id: to_string(notification.id),
|
||||
|
|
@ -131,8 +135,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
assert [expected] ==
|
||||
NotificationView.render("index.json", %{notifications: [notification], for: follower})
|
||||
test_notifications_rendering([notification], follower, [expected])
|
||||
end
|
||||
|
||||
test "EmojiReact notification" do
|
||||
|
|
@ -158,7 +161,6 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
||||
assert expected ==
|
||||
NotificationView.render("show.json", %{notification: notification, for: user})
|
||||
test_notifications_rendering([notification], user, [expected])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,10 +12,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
|
|
@ -212,12 +214,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
{:ok, _user_relationships} = User.mute(user, other_user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
|
||||
status = StatusView.render("show.json", %{activity: activity})
|
||||
|
||||
relationships_opt = UserRelationship.view_relationships_option(user, [other_user])
|
||||
|
||||
opts = %{activity: activity}
|
||||
status = StatusView.render("show.json", opts)
|
||||
assert status.muted == false
|
||||
|
||||
status = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
status = StatusView.render("show.json", Map.put(opts, :relationships, relationships_opt))
|
||||
assert status.muted == false
|
||||
|
||||
for_opts = %{activity: activity, for: user}
|
||||
status = StatusView.render("show.json", for_opts)
|
||||
assert status.muted == true
|
||||
|
||||
status = StatusView.render("show.json", Map.put(for_opts, :relationships, relationships_opt))
|
||||
assert status.muted == true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
import Mock
|
||||
alias Pleroma.Config
|
||||
|
||||
clear_config(:media_proxy)
|
||||
clear_config([Pleroma.Web.Endpoint, :secret_key_base])
|
||||
setup do: clear_config(:media_proxy)
|
||||
setup do: clear_config([Pleroma.Web.Endpoint, :secret_key_base])
|
||||
|
||||
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
|
|
@ -52,9 +52,8 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
|
||||
invalid_url = String.replace(url, "test.png", "test-file.png")
|
||||
response = get(conn, invalid_url)
|
||||
html = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
|
||||
assert response.status == 302
|
||||
assert response.resp_body == html
|
||||
assert redirected_to(response) == url
|
||||
end
|
||||
|
||||
test "it performs ReverseProxy.call when signature valid", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ defmodule Pleroma.Web.MediaProxyTest do
|
|||
import Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.MediaProxy.MediaProxyController
|
||||
|
||||
clear_config([:media_proxy, :enabled])
|
||||
clear_config(Pleroma.Upload)
|
||||
setup do: clear_config([:media_proxy, :enabled])
|
||||
setup do: clear_config(Pleroma.Upload)
|
||||
|
||||
describe "when enabled" do
|
||||
setup do
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do
|
|||
import Pleroma.Factory
|
||||
alias Pleroma.Web.Metadata.Providers.OpenGraph
|
||||
|
||||
clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||
|
||||
test "it renders all supported types of attachments and skips unknown types" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
|
|||
alias Pleroma.Web.Metadata.Utils
|
||||
alias Pleroma.Web.Router
|
||||
|
||||
clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
|
||||
|
||||
test "it renders twitter card for user info" do
|
||||
user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config([:mrf_simple])
|
||||
clear_config(:instance)
|
||||
setup do: clear_config([:mrf_simple])
|
||||
setup do: clear_config(:instance)
|
||||
|
||||
test "GET /.well-known/nodeinfo", %{conn: conn} do
|
||||
links =
|
||||
|
|
@ -105,7 +105,7 @@ defmodule Pleroma.Web.NodeInfoTest do
|
|||
end
|
||||
|
||||
describe "`metadata/federation/enabled`" do
|
||||
clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :federating])
|
||||
|
||||
test "it shows if federation is enabled/disabled", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
|
|
|
|||
|
|
@ -12,13 +12,9 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
|
|||
|
||||
@skip if !Code.ensure_loaded?(:eldap), do: :skip
|
||||
|
||||
clear_config_all([:ldap, :enabled]) do
|
||||
Pleroma.Config.put([:ldap, :enabled], true)
|
||||
end
|
||||
setup_all do: clear_config([:ldap, :enabled], true)
|
||||
|
||||
clear_config_all(Pleroma.Web.Auth.Authenticator) do
|
||||
Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
|
||||
end
|
||||
setup_all do: clear_config(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
|
||||
|
||||
@tag @skip
|
||||
test "authorizes the existing user using LDAP credentials" do
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
|
||||
clear_config([:instance, :account_activation_required])
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
describe "in OAuth consumer mode, " do
|
||||
setup do
|
||||
|
|
@ -31,12 +30,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
]
|
||||
end
|
||||
|
||||
clear_config([:auth, :oauth_consumer_strategies]) do
|
||||
Pleroma.Config.put(
|
||||
[:auth, :oauth_consumer_strategies],
|
||||
~w(twitter facebook)
|
||||
)
|
||||
end
|
||||
setup do: clear_config([:auth, :oauth_consumer_strategies], ~w(twitter facebook))
|
||||
|
||||
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
|
||||
app: app,
|
||||
|
|
@ -944,7 +938,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
end
|
||||
|
||||
describe "POST /oauth/token - refresh token" do
|
||||
clear_config([:oauth2, :issue_new_refresh_token])
|
||||
setup do: clear_config([:oauth2, :issue_new_refresh_token])
|
||||
|
||||
test "issues a new access token with keep fresh token" do
|
||||
Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -16,22 +17,22 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
# Note: see ActivityPubControllerTest for JSON format tests
|
||||
describe "GET /objects/:uuid (text/html)" do
|
||||
setup %{conn: conn} do
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
%{conn: conn}
|
||||
end
|
||||
|
||||
describe "GET object/2" do
|
||||
test "redirects to /notice/id for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
|
||||
url = "/objects/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get(url)
|
||||
|
||||
conn = get(conn, url)
|
||||
assert redirected_to(conn) == "/notice/#{note_activity.id}"
|
||||
end
|
||||
|
||||
|
|
@ -45,23 +46,25 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> response(404)
|
||||
end
|
||||
|
||||
test "404s on nonexisting objects", %{conn: conn} do
|
||||
test "404s on non-existing objects", %{conn: conn} do
|
||||
conn
|
||||
|> get("/objects/123")
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET activity/2" do
|
||||
# Note: see ActivityPubControllerTest for JSON format tests
|
||||
describe "GET /activities/:uuid (text/html)" do
|
||||
setup %{conn: conn} do
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
%{conn: conn}
|
||||
end
|
||||
|
||||
test "redirects to /notice/id for html format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/activities/#{uuid}")
|
||||
|
||||
conn = get(conn, "/activities/#{uuid}")
|
||||
assert redirected_to(conn) == "/notice/#{note_activity.id}"
|
||||
end
|
||||
|
||||
|
|
@ -79,19 +82,6 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> get("/activities/123")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "gets an activity in AS2 format", %{conn: conn} do
|
||||
note_activity = insert(:note_activity)
|
||||
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
|
||||
url = "/activities/#{uuid}"
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/activity+json")
|
||||
|> get(url)
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET notice/2" do
|
||||
|
|
@ -170,7 +160,7 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "404s a nonexisting notice", %{conn: conn} do
|
||||
test "404s a non-existing notice", %{conn: conn} do
|
||||
url = "/notice/123"
|
||||
|
||||
conn =
|
||||
|
|
@ -179,10 +169,21 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|
||||
assert response(conn, 404)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
note_activity = insert(:note_activity)
|
||||
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /notice/:id/embed_player" do
|
||||
test "render embed player", %{conn: conn} do
|
||||
setup do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Pleroma.Object.normalize(note_activity)
|
||||
|
||||
|
|
@ -204,9 +205,11 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
%{note_activity: note_activity}
|
||||
end
|
||||
|
||||
test "renders embed player", %{conn: conn, note_activity: note_activity} do
|
||||
conn = get(conn, "/notice/#{note_activity.id}/embed_player")
|
||||
|
||||
assert Plug.Conn.get_resp_header(conn, "x-frame-options") == ["ALLOW"]
|
||||
|
||||
|
|
@ -272,9 +275,19 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
|
|||
|> Ecto.Changeset.change(data: object_data)
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
assert conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(404)
|
||||
conn
|
||||
|> get("/notice/#{note_activity.id}/embed_player")
|
||||
|> response(404)
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{
|
||||
conn: conn,
|
||||
note_activity: note_activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
conn = put_req_header(conn, "accept", "text/html")
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{note_activity.id}/embed_player", user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -27,9 +27,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
[user: user]
|
||||
end
|
||||
|
||||
clear_config([:instance, :account_activation_required]) do
|
||||
Config.put([:instance, :account_activation_required], true)
|
||||
end
|
||||
setup do: clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
test "resend account confirmation email", %{conn: conn, user: user} do
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiAPIControllerTest do
|
|||
Pleroma.Config.get!([:instance, :static_dir]),
|
||||
"emoji"
|
||||
)
|
||||
|
||||
clear_config([:auth, :enforce_oauth_admin_scope_usage]) do
|
||||
Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
end
|
||||
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
|
||||
test "shared & non-shared pack information in list_packs is ok" do
|
||||
conn = build_conn()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
defmodule Pleroma.Web.FederatingPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
clear_config([:instance, :federating])
|
||||
setup do: clear_config([:instance, :federating])
|
||||
|
||||
test "returns and halt the conn when federating is disabled" do
|
||||
Pleroma.Config.put([:instance, :federating], false)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:rich_media, :enabled])
|
||||
setup do: clear_config([:rich_media, :enabled])
|
||||
|
||||
test "refuses to crawl incomplete URLs" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -1,56 +1,41 @@
|
|||
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
clear_config_all([:static_fe, :enabled]) do
|
||||
Pleroma.Config.put([:static_fe, :enabled], true)
|
||||
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")
|
||||
user = insert(:user)
|
||||
|
||||
%{conn: conn, user: user}
|
||||
end
|
||||
|
||||
describe "user profile page" do
|
||||
test "just the profile as HTML", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/users/#{user.nickname}")
|
||||
describe "user profile html" do
|
||||
test "just the profile as HTML", %{conn: conn, user: user} do
|
||||
conn = get(conn, "/users/#{user.nickname}")
|
||||
|
||||
assert html_response(conn, 200) =~ user.nickname
|
||||
end
|
||||
|
||||
test "renders json unless there's an html accept header", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|> get("/users/#{user.nickname}")
|
||||
|
||||
assert json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "404 when user not found", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/users/limpopo")
|
||||
conn = get(conn, "/users/limpopo")
|
||||
|
||||
assert html_response(conn, 404) =~ "not found"
|
||||
end
|
||||
|
||||
test "profile does not include private messages", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
test "profile does not include private messages", %{conn: conn, user: user} do
|
||||
CommonAPI.post(user, %{"status" => "public"})
|
||||
CommonAPI.post(user, %{"status" => "private", "visibility" => "private"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/users/#{user.nickname}")
|
||||
conn = get(conn, "/users/#{user.nickname}")
|
||||
|
||||
html = html_response(conn, 200)
|
||||
|
||||
|
|
@ -58,14 +43,10 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
refute html =~ ">private<"
|
||||
end
|
||||
|
||||
test "pagination", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
test "pagination", %{conn: conn, user: user} do
|
||||
Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/users/#{user.nickname}")
|
||||
conn = get(conn, "/users/#{user.nickname}")
|
||||
|
||||
html = html_response(conn, 200)
|
||||
|
||||
|
|
@ -75,15 +56,11 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
refute html =~ ">test1<"
|
||||
end
|
||||
|
||||
test "pagination, page 2", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
test "pagination, page 2", %{conn: conn, user: user} do
|
||||
activities = Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
|
||||
{:ok, a11} = Enum.at(activities, 11)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/users/#{user.nickname}?max_id=#{a11.id}")
|
||||
conn = get(conn, "/users/#{user.nickname}?max_id=#{a11.id}")
|
||||
|
||||
html = html_response(conn, 200)
|
||||
|
||||
|
|
@ -92,17 +69,17 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
refute html =~ ">test20<"
|
||||
refute html =~ ">test29<"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
||||
ensure_federating_or_authenticated(conn, "/users/#{user.nickname}", user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "notice rendering" do
|
||||
test "single notice page", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
describe "notice html" do
|
||||
test "single notice page", %{conn: conn, user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{activity.id}")
|
||||
conn = get(conn, "/notice/#{activity.id}")
|
||||
|
||||
html = html_response(conn, 200)
|
||||
assert html =~ "<header>"
|
||||
|
|
@ -110,79 +87,68 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
assert html =~ "testing a thing!"
|
||||
end
|
||||
|
||||
test "shows the whole thread", %{conn: conn} do
|
||||
test "filters HTML tags", %{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
|
||||
})
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "<script>alert('xss')</script>"})
|
||||
|
||||
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
|
||||
|
||||
test "shows the whole thread", %{conn: conn, user: user} do
|
||||
{: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 = get(conn, "/notice/#{activity.id}")
|
||||
|
||||
html = html_response(conn, 200)
|
||||
assert html =~ "the final frontier"
|
||||
assert html =~ "voyages"
|
||||
end
|
||||
|
||||
test "redirect by AP object ID", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
test "redirect by AP object ID", %{conn: conn, user: user} do
|
||||
{: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)
|
||||
conn = get(conn, URI.parse(object_url).path)
|
||||
|
||||
assert html_response(conn, 302) =~ "redirected"
|
||||
end
|
||||
|
||||
test "redirect by activity ID", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
test "redirect by activity ID", %{conn: conn, user: user} do
|
||||
{: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)
|
||||
conn = get(conn, URI.parse(id).path)
|
||||
|
||||
assert html_response(conn, 302) =~ "redirected"
|
||||
end
|
||||
|
||||
test "404 when notice not found", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/88c9c317")
|
||||
conn = get(conn, "/notice/88c9c317")
|
||||
|
||||
assert html_response(conn, 404) =~ "not found"
|
||||
end
|
||||
|
||||
test "404 for private status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
test "404 for private status", %{conn: conn, user: user} do
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "don't show me!", "visibility" => "private"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{activity.id}")
|
||||
conn = get(conn, "/notice/#{activity.id}")
|
||||
|
||||
assert html_response(conn, 404) =~ "not found"
|
||||
end
|
||||
|
||||
test "302 for remote cached status", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
test "302 for remote cached status", %{conn: conn, user: user} do
|
||||
message = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => user.follower_address,
|
||||
|
|
@ -199,12 +165,15 @@ defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
|
|||
|
||||
assert {:ok, activity} = Transmogrifier.handle_incoming(message)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "text/html")
|
||||
|> get("/notice/#{activity.id}")
|
||||
conn = get(conn, "/notice/#{activity.id}")
|
||||
|
||||
assert html_response(conn, 302) =~ "redirected"
|
||||
end
|
||||
|
||||
test "it requires authentication if instance is NOT federating", %{conn: conn, user: user} do
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})
|
||||
|
||||
ensure_federating_or_authenticated(conn, "/notice/#{activity.id}", user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,8 +19,7 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
|
||||
@streamer_timeout 150
|
||||
@streamer_start_wait 10
|
||||
|
||||
clear_config([:instance, :skip_thread_containment])
|
||||
setup do: clear_config([:instance, :skip_thread_containment])
|
||||
|
||||
describe "user streams" do
|
||||
setup do
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -15,9 +17,10 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance])
|
||||
clear_config([:frontend_configurations, :pleroma_fe])
|
||||
clear_config([:user, :deny_follow_blocked])
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
setup do: clear_config([:instance])
|
||||
setup do: clear_config([:frontend_configurations, :pleroma_fe])
|
||||
setup do: clear_config([:user, :deny_follow_blocked])
|
||||
|
||||
describe "GET /ostatus_subscribe - remote_follow/2" do
|
||||
test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -117,9 +117,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
describe "register with one time token" do
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
setup do: clear_config([:instance, :registrations_open], false)
|
||||
|
||||
test "returns user on success" do
|
||||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
|
@ -184,9 +182,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
describe "registers with date limited token" do
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
setup do: clear_config([:instance, :registrations_open], false)
|
||||
|
||||
setup do
|
||||
data = %{
|
||||
|
|
@ -246,9 +242,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
describe "registers with reusable token" do
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
setup do: clear_config([:instance, :registrations_open], false)
|
||||
|
||||
test "returns user on success, after him registration fails" do
|
||||
{:ok, invite} = UserInviteToken.create_invite(%{max_use: 100})
|
||||
|
|
@ -292,9 +286,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
describe "registers with reusable date limited token" do
|
||||
clear_config([:instance, :registrations_open]) do
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
end
|
||||
setup do: clear_config([:instance, :registrations_open], false)
|
||||
|
||||
test "returns user on success" do
|
||||
{:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
|
||||
|
|
@ -17,8 +18,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config([:instance])
|
||||
clear_config([:frontend_configurations, :pleroma_fe])
|
||||
setup do: clear_config([:instance])
|
||||
setup do: clear_config([:frontend_configurations, :pleroma_fe])
|
||||
|
||||
describe "POST /api/pleroma/follow_import" do
|
||||
setup do: oauth_access(["follow"])
|
||||
|
|
@ -178,7 +179,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
describe "GET /api/statusnet/config" do
|
||||
test "it returns config in xml format", %{conn: conn} do
|
||||
instance = Pleroma.Config.get(:instance)
|
||||
instance = Config.get(:instance)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -195,12 +196,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "it returns config in json format", %{conn: conn} do
|
||||
instance = Pleroma.Config.get(:instance)
|
||||
Pleroma.Config.put([:instance, :managed_config], true)
|
||||
Pleroma.Config.put([:instance, :registrations_open], false)
|
||||
Pleroma.Config.put([:instance, :invites_enabled], true)
|
||||
Pleroma.Config.put([:instance, :public], false)
|
||||
Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
|
||||
instance = Config.get(:instance)
|
||||
Config.put([:instance, :managed_config], true)
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
Config.put([:instance, :invites_enabled], true)
|
||||
Config.put([:instance, :public], false)
|
||||
Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -234,7 +235,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
|
||||
Config.put([:instance, :safe_dm_mentions], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -243,7 +244,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
assert response["site"]["safeDMMentionsEnabled"] == "1"
|
||||
|
||||
Pleroma.Config.put([:instance, :safe_dm_mentions], false)
|
||||
Config.put([:instance, :safe_dm_mentions], false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -254,8 +255,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "it returns the managed config", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :managed_config], false)
|
||||
Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
|
||||
Config.put([:instance, :managed_config], false)
|
||||
Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -264,7 +265,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
|
||||
refute response["site"]["pleromafe"]
|
||||
|
||||
Pleroma.Config.put([:instance, :managed_config], true)
|
||||
Config.put([:instance, :managed_config], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -287,7 +288,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
}
|
||||
]
|
||||
|
||||
Pleroma.Config.put(:frontend_configurations, config)
|
||||
Config.put(:frontend_configurations, config)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -317,10 +318,10 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
describe "GET /api/pleroma/healthcheck" do
|
||||
clear_config([:instance, :healthcheck])
|
||||
setup do: clear_config([:instance, :healthcheck])
|
||||
|
||||
test "returns 503 when healthcheck disabled", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :healthcheck], false)
|
||||
Config.put([:instance, :healthcheck], false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|
|
@ -331,7 +332,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "returns 200 when healthcheck enabled and all ok", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :healthcheck], true)
|
||||
Config.put([:instance, :healthcheck], true)
|
||||
|
||||
with_mock Pleroma.Healthcheck,
|
||||
system_info: fn -> %Pleroma.Healthcheck{healthy: true} end do
|
||||
|
|
@ -351,7 +352,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
test "returns 503 when healthcheck enabled and health is false", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :healthcheck], true)
|
||||
Config.put([:instance, :healthcheck], true)
|
||||
|
||||
with_mock Pleroma.Healthcheck,
|
||||
system_info: fn -> %Pleroma.Healthcheck{healthy: false} end do
|
||||
|
|
@ -426,6 +427,8 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
|
||||
describe "POST /main/ostatus - remote_subscribe/2" do
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
test "renders subscribe form", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
clear_config_all([:instance, :federating]) do
|
||||
Pleroma.Config.put([:instance, :federating], true)
|
||||
end
|
||||
setup_all do: clear_config([:instance, :federating], true)
|
||||
|
||||
test "GET host-meta" do
|
||||
response =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue