Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

102 rindas
2.8KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Object.ContainmentTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.Object.Containment
  7. alias Pleroma.User
  8. import Pleroma.Factory
  9. import ExUnit.CaptureLog
  10. setup_all do
  11. Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
  12. :ok
  13. end
  14. describe "general origin containment" do
  15. test "contain_origin_from_id() catches obvious spoofing attempts" do
  16. data = %{
  17. "id" => "http://example.com/~alyssa/activities/1234.json"
  18. }
  19. :error =
  20. Containment.contain_origin_from_id(
  21. "http://example.org/~alyssa/activities/1234.json",
  22. data
  23. )
  24. end
  25. test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
  26. data = %{
  27. "id" => "http://example.com/~alyssa/activities/1234.json"
  28. }
  29. :ok =
  30. Containment.contain_origin_from_id(
  31. "http://example.com/~alyssa/activities/1234",
  32. data
  33. )
  34. end
  35. test "contain_origin_from_id() allows matching IDs" do
  36. data = %{
  37. "id" => "http://example.com/~alyssa/activities/1234.json"
  38. }
  39. :ok =
  40. Containment.contain_origin_from_id(
  41. "http://example.com/~alyssa/activities/1234.json",
  42. data
  43. )
  44. end
  45. test "users cannot be collided through fake direction spoofing attempts" do
  46. _user =
  47. insert(:user, %{
  48. nickname: "rye@niu.moe",
  49. local: false,
  50. ap_id: "https://niu.moe/users/rye",
  51. follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
  52. })
  53. assert capture_log(fn ->
  54. {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
  55. end) =~
  56. "[error] Could not decode user at fetch https://n1u.moe/users/rye, {:error, :error}"
  57. end
  58. end
  59. describe "containment of children" do
  60. test "contain_child() catches spoofing attempts" do
  61. data = %{
  62. "id" => "http://example.com/whatever",
  63. "type" => "Create",
  64. "object" => %{
  65. "id" => "http://example.net/~alyssa/activities/1234",
  66. "attributedTo" => "http://example.org/~alyssa"
  67. },
  68. "actor" => "http://example.com/~bob"
  69. }
  70. :error = Containment.contain_child(data)
  71. end
  72. test "contain_child() allows correct origins" do
  73. data = %{
  74. "id" => "http://example.org/~alyssa/activities/5678",
  75. "type" => "Create",
  76. "object" => %{
  77. "id" => "http://example.org/~alyssa/activities/1234",
  78. "attributedTo" => "http://example.org/~alyssa"
  79. },
  80. "actor" => "http://example.org/~alyssa"
  81. }
  82. :ok = Containment.contain_child(data)
  83. end
  84. end
  85. end