2019-09-27 09:28:05 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
2019-09-30 09:28:37 +02:00
|
|
|
use Pleroma.Web.ConnCase
|
2019-09-27 09:28:05 +02:00
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "blocking / unblocking a domain" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
2019-09-27 09:28:05 +02:00
|
|
|
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
ret_conn = post(conn, "/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
2019-09-27 09:28:05 +02:00
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
assert %{} = json_response(ret_conn, 200)
|
2019-09-27 09:28:05 +02:00
|
|
|
user = User.get_cached_by_ap_id(user.ap_id)
|
|
|
|
assert User.blocks?(user, other_user)
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
ret_conn = delete(conn, "/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
2019-09-27 09:28:05 +02:00
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
assert %{} = json_response(ret_conn, 200)
|
2019-09-27 09:28:05 +02:00
|
|
|
user = User.get_cached_by_ap_id(user.ap_id)
|
|
|
|
refute User.blocks?(user, other_user)
|
|
|
|
end
|
|
|
|
|
2019-12-19 15:23:27 +01:00
|
|
|
test "getting a list of domain blocks" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
2019-09-27 09:28:05 +02:00
|
|
|
|
|
|
|
{:ok, user} = User.block_domain(user, "bad.site")
|
|
|
|
{:ok, user} = User.block_domain(user, "even.worse.site")
|
|
|
|
|
|
|
|
conn =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/v1/domain_blocks")
|
|
|
|
|
|
|
|
domain_blocks = json_response(conn, 200)
|
|
|
|
|
|
|
|
assert "bad.site" in domain_blocks
|
|
|
|
assert "even.worse.site" in domain_blocks
|
|
|
|
end
|
|
|
|
end
|