Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.5KB

  1. defmodule Pleroma.Object.ContainmentTest do
  2. use Pleroma.DataCase
  3. alias Pleroma.Object.Containment
  4. alias Pleroma.User
  5. import Pleroma.Factory
  6. describe "general origin containment" do
  7. test "contain_origin_from_id() catches obvious spoofing attempts" do
  8. data = %{
  9. "id" => "http://example.com/~alyssa/activities/1234.json"
  10. }
  11. :error =
  12. Containment.contain_origin_from_id(
  13. "http://example.org/~alyssa/activities/1234.json",
  14. data
  15. )
  16. end
  17. test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
  18. data = %{
  19. "id" => "http://example.com/~alyssa/activities/1234.json"
  20. }
  21. :ok =
  22. Containment.contain_origin_from_id(
  23. "http://example.com/~alyssa/activities/1234",
  24. data
  25. )
  26. end
  27. test "contain_origin_from_id() allows matching IDs" do
  28. data = %{
  29. "id" => "http://example.com/~alyssa/activities/1234.json"
  30. }
  31. :ok =
  32. Containment.contain_origin_from_id(
  33. "http://example.com/~alyssa/activities/1234.json",
  34. data
  35. )
  36. end
  37. test "users cannot be collided through fake direction spoofing attempts" do
  38. _user =
  39. insert(:user, %{
  40. nickname: "rye@niu.moe",
  41. local: false,
  42. ap_id: "https://niu.moe/users/rye",
  43. follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
  44. })
  45. {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
  46. end
  47. end
  48. end