1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Object.ContainmentTest do
8 alias Pleroma.Object.Containment
11 import Pleroma.Factory
12 import ExUnit.CaptureLog
15 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
19 describe "general origin containment" do
20 test "works for completely actorless posts" do
22 Containment.contain_origin("https://glaceon.social/users/monorail", %{
23 "deleted" => "2019-10-30T05:48:50.249606Z",
24 "formerType" => "Note",
25 "id" => "https://glaceon.social/users/monorail/statuses/103049757364029187",
30 test "contain_origin_from_id() catches obvious spoofing attempts" do
32 "id" => "http://example.com/~alyssa/activities/1234.json"
36 Containment.contain_origin_from_id(
37 "http://example.org/~alyssa/activities/1234.json",
42 test "contain_origin_from_id() allows alternate IDs within the same origin domain" do
44 "id" => "http://example.com/~alyssa/activities/1234.json"
48 Containment.contain_origin_from_id(
49 "http://example.com/~alyssa/activities/1234",
54 test "contain_origin_from_id() allows matching IDs" do
56 "id" => "http://example.com/~alyssa/activities/1234.json"
60 Containment.contain_origin_from_id(
61 "http://example.com/~alyssa/activities/1234.json",
66 test "users cannot be collided through fake direction spoofing attempts" do
69 nickname: "rye@niu.moe",
71 ap_id: "https://niu.moe/users/rye",
72 follower_address: User.ap_followers(%User{nickname: "rye@niu.moe"})
75 assert capture_log(fn ->
76 {:error, _} = User.get_or_fetch_by_ap_id("https://n1u.moe/users/rye")
78 "[error] Could not decode user at fetch https://n1u.moe/users/rye"
81 test "contain_origin_from_id() gracefully handles cases where no ID is present" do
85 "id" => "http://example.net/~alyssa/activities/1234",
86 "attributedTo" => "http://example.org/~alyssa"
88 "actor" => "http://example.com/~bob"
92 Containment.contain_origin_from_id("http://example.net/~alyssa/activities/1234", data)
96 describe "containment of children" do
97 test "contain_child() catches spoofing attempts" do
99 "id" => "http://example.com/whatever",
102 "id" => "http://example.net/~alyssa/activities/1234",
103 "attributedTo" => "http://example.org/~alyssa"
105 "actor" => "http://example.com/~bob"
108 :error = Containment.contain_child(data)
111 test "contain_child() allows correct origins" do
113 "id" => "http://example.org/~alyssa/activities/5678",
116 "id" => "http://example.org/~alyssa/activities/1234",
117 "attributedTo" => "http://example.org/~alyssa"
119 "actor" => "http://example.org/~alyssa"
122 :ok = Containment.contain_child(data)