logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

domain_block_controller_test.exs (2684B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
  5. use Pleroma.Web.ConnCase
  6. alias Pleroma.User
  7. import Pleroma.Factory
  8. test "blocking / unblocking a domain" do
  9. %{user: user, conn: conn} = oauth_access(["write:blocks"])
  10. other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
  11. ret_conn =
  12. conn
  13. |> put_req_header("content-type", "application/json")
  14. |> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
  15. assert %{} == json_response_and_validate_schema(ret_conn, 200)
  16. user = User.get_cached_by_ap_id(user.ap_id)
  17. assert User.blocks?(user, other_user)
  18. ret_conn =
  19. conn
  20. |> put_req_header("content-type", "application/json")
  21. |> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
  22. assert %{} == json_response_and_validate_schema(ret_conn, 200)
  23. user = User.get_cached_by_ap_id(user.ap_id)
  24. refute User.blocks?(user, other_user)
  25. end
  26. test "blocking a domain via query params" do
  27. %{user: user, conn: conn} = oauth_access(["write:blocks"])
  28. other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
  29. ret_conn =
  30. conn
  31. |> put_req_header("content-type", "application/json")
  32. |> post("/api/v1/domain_blocks?domain=dogwhistle.zone")
  33. assert %{} == json_response_and_validate_schema(ret_conn, 200)
  34. user = User.get_cached_by_ap_id(user.ap_id)
  35. assert User.blocks?(user, other_user)
  36. end
  37. test "unblocking a domain via query params" do
  38. %{user: user, conn: conn} = oauth_access(["write:blocks"])
  39. other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
  40. User.block_domain(user, "dogwhistle.zone")
  41. user = refresh_record(user)
  42. assert User.blocks?(user, other_user)
  43. ret_conn =
  44. conn
  45. |> put_req_header("content-type", "application/json")
  46. |> delete("/api/v1/domain_blocks?domain=dogwhistle.zone")
  47. assert %{} == json_response_and_validate_schema(ret_conn, 200)
  48. user = User.get_cached_by_ap_id(user.ap_id)
  49. refute User.blocks?(user, other_user)
  50. end
  51. test "getting a list of domain blocks" do
  52. %{user: user, conn: conn} = oauth_access(["read:blocks"])
  53. {:ok, user} = User.block_domain(user, "bad.site")
  54. {:ok, user} = User.block_domain(user, "even.worse.site")
  55. assert ["even.worse.site", "bad.site"] ==
  56. conn
  57. |> assign(:user, user)
  58. |> get("/api/v1/domain_blocks")
  59. |> json_response_and_validate_schema(200)
  60. end
  61. end