2019-09-27 03:28:05 -04:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 00:08:45 -05:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-09-27 03:28:05 -04:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
2019-09-30 03:28:37 -04:00
|
|
|
use Pleroma.Web.ConnCase
|
2019-09-27 03:28:05 -04:00
|
|
|
|
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
2019-12-19 09:23:27 -05:00
|
|
|
test "blocking / unblocking a domain" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
2019-09-27 03:28:05 -04:00
|
|
|
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
|
|
|
|
2020-04-13 14:44:52 -04:00
|
|
|
ret_conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
2019-09-27 03:28:05 -04:00
|
|
|
|
2020-04-24 06:46:59 -04:00
|
|
|
assert %{} == json_response_and_validate_schema(ret_conn, 200)
|
2019-09-27 03:28:05 -04:00
|
|
|
user = User.get_cached_by_ap_id(user.ap_id)
|
|
|
|
assert User.blocks?(user, other_user)
|
|
|
|
|
2020-04-13 14:44:52 -04:00
|
|
|
ret_conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
2019-09-27 03:28:05 -04:00
|
|
|
|
2020-04-24 06:46:59 -04:00
|
|
|
assert %{} == json_response_and_validate_schema(ret_conn, 200)
|
2019-09-27 03:28:05 -04:00
|
|
|
user = User.get_cached_by_ap_id(user.ap_id)
|
|
|
|
refute User.blocks?(user, other_user)
|
|
|
|
end
|
|
|
|
|
2020-07-23 13:59:40 -04:00
|
|
|
test "blocking a domain via query params" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
|
|
|
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
|
|
|
|
|
|
|
ret_conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> post("/api/v1/domain_blocks?domain=dogwhistle.zone")
|
|
|
|
|
|
|
|
assert %{} == json_response_and_validate_schema(ret_conn, 200)
|
|
|
|
user = User.get_cached_by_ap_id(user.ap_id)
|
|
|
|
assert User.blocks?(user, other_user)
|
|
|
|
end
|
|
|
|
|
2020-07-21 08:06:46 -04:00
|
|
|
test "unblocking a domain via query params" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
|
|
|
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
|
|
|
|
|
|
|
User.block_domain(user, "dogwhistle.zone")
|
|
|
|
user = refresh_record(user)
|
|
|
|
assert User.blocks?(user, other_user)
|
|
|
|
|
|
|
|
ret_conn =
|
|
|
|
conn
|
|
|
|
|> put_req_header("content-type", "application/json")
|
|
|
|
|> delete("/api/v1/domain_blocks?domain=dogwhistle.zone")
|
|
|
|
|
|
|
|
assert %{} == json_response_and_validate_schema(ret_conn, 200)
|
|
|
|
user = User.get_cached_by_ap_id(user.ap_id)
|
|
|
|
refute User.blocks?(user, other_user)
|
|
|
|
end
|
|
|
|
|
2019-12-19 09:23:27 -05:00
|
|
|
test "getting a list of domain blocks" do
|
|
|
|
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
2019-09-27 03:28:05 -04:00
|
|
|
|
|
|
|
{:ok, user} = User.block_domain(user, "bad.site")
|
|
|
|
{:ok, user} = User.block_domain(user, "even.worse.site")
|
|
|
|
|
2020-04-24 06:46:59 -04:00
|
|
|
assert ["even.worse.site", "bad.site"] ==
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/v1/domain_blocks")
|
|
|
|
|> json_response_and_validate_schema(200)
|
2019-09-27 03:28:05 -04:00
|
|
|
end
|
|
|
|
end
|