Convert tests to all use clear_config instead of Pleroma.Config.put
[akkoma] / test / pleroma / web / activity_pub / activity_pub_controller_test.exs
index c9b42148911df86a99a657670337bdb6938add54..f7417de31dc3f46e5e258b98b4680d202dbe049e 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
@@ -7,7 +7,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
   use Oban.Testing, repo: Pleroma.Repo
 
   alias Pleroma.Activity
-  alias Pleroma.Config
   alias Pleroma.Delivery
   alias Pleroma.Instances
   alias Pleroma.Object
@@ -46,7 +45,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
 
     test "with the relay disabled, it returns 404", %{conn: conn} do
-      Config.put([:instance, :allow_relay], false)
+      clear_config([:instance, :allow_relay], false)
 
       conn
       |> get(activity_pub_path(conn, :relay))
@@ -54,7 +53,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
 
     test "on non-federating instance, it returns 404", %{conn: conn} do
-      Config.put([:instance, :federating], false)
+      clear_config([:instance, :federating], false)
       user = insert(:user)
 
       conn
@@ -75,7 +74,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
 
     test "on non-federating instance, it returns 404", %{conn: conn} do
-      Config.put([:instance, :federating], false)
+      clear_config([:instance, :federating], false)
       user = insert(:user)
 
       conn
@@ -219,7 +218,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
       assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post)
 
-      object = Object.normalize(post, false)
+      object = Object.normalize(post, fetch: false)
       uuid = String.split(object.data["id"], "/") |> List.last()
 
       conn =
@@ -493,7 +492,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
 
     test "accept follow activity", %{conn: conn} do
-      Pleroma.Config.put([:instance, :federating], true)
+      clear_config([:instance, :federating], true)
       relay = Relay.get_actor()
 
       assert {:ok, %Activity{} = activity} = Relay.follow("https://relay.mastodon.host/actor")
@@ -539,7 +538,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
       conn = put_req_header(conn, "content-type", "application/activity+json")
 
-      Config.put([:instance, :federating], false)
+      clear_config([:instance, :federating], false)
 
       conn
       |> post("/inbox", data)
@@ -549,7 +548,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       |> post("/inbox", non_create_data)
       |> json_response(403)
 
-      Config.put([:instance, :federating], true)
+      clear_config([:instance, :federating], true)
 
       ret_conn = post(conn, "/inbox", data)
       assert "ok" == json_response(ret_conn, 200)
@@ -675,7 +674,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       recipient = insert(:user)
       actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
 
-      {:ok, recipient} = User.follow(recipient, actor)
+      {:ok, recipient, actor} = User.follow(recipient, actor)
 
       object =
         data["object"]
@@ -712,7 +711,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
     test "it returns a note activity in a collection", %{conn: conn} do
       note_activity = insert(:direct_note_activity)
-      note_object = Object.normalize(note_activity)
+      note_object = Object.normalize(note_activity, fetch: false)
       user = User.get_cached_by_ap_id(hd(note_activity.data["to"]))
 
       conn =
@@ -999,7 +998,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
     test "it returns a note activity in a collection", %{conn: conn} do
       note_activity = insert(:note_activity)
-      note_object = Object.normalize(note_activity)
+      note_object = Object.normalize(note_activity, fetch: false)
       user = User.get_cached_by_ap_id(note_activity.data["actor"])
 
       conn =
@@ -1073,7 +1072,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
       assert Activity.get_by_ap_id(result["id"])
       assert result["object"]
-      assert %Object{data: object} = Object.normalize(result["object"])
+      assert %Object{data: object} = Object.normalize(result["object"], fetch: false)
       assert object["content"] == activity["object"]["content"]
     end
 
@@ -1109,7 +1108,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
       assert Activity.get_by_ap_id(response["id"])
       assert response["object"]
-      assert %Object{data: response_object} = Object.normalize(response["object"])
+      assert %Object{data: response_object} = Object.normalize(response["object"], fetch: false)
       assert response_object["sensitive"] == true
       assert response_object["content"] == activity["object"]["content"]
 
@@ -1137,7 +1136,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
     test "it erects a tombstone when receiving a delete activity", %{conn: conn} do
       note_activity = insert(:note_activity)
-      note_object = Object.normalize(note_activity)
+      note_object = Object.normalize(note_activity, fetch: false)
       user = User.get_cached_by_ap_id(note_activity.data["actor"])
 
       data = %{
@@ -1162,7 +1161,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
     test "it rejects delete activity of object from other actor", %{conn: conn} do
       note_activity = insert(:note_activity)
-      note_object = Object.normalize(note_activity)
+      note_object = Object.normalize(note_activity, fetch: false)
       user = insert(:user)
 
       data = %{
@@ -1183,7 +1182,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
 
     test "it increases like count when receiving a like action", %{conn: conn} do
       note_activity = insert(:note_activity)
-      note_object = Object.normalize(note_activity)
+      note_object = Object.normalize(note_activity, fetch: false)
       user = User.get_cached_by_ap_id(note_activity.data["actor"])
 
       data = %{
@@ -1240,13 +1239,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       assert cirno_outbox["attributedTo"] == nil
       assert cirno_outbox["actor"] == cirno.ap_id
 
-      assert cirno_object = Object.normalize(cirno_outbox["object"])
+      assert cirno_object = Object.normalize(cirno_outbox["object"], fetch: false)
       assert cirno_object.data["actor"] == cirno.ap_id
       assert cirno_object.data["attributedTo"] == cirno.ap_id
     end
 
     test "Character limitation", %{conn: conn, activity: activity} do
-      Pleroma.Config.put([:instance, :limit], 5)
+      clear_config([:instance, :limit], 5)
       user = insert(:user)
 
       result =
@@ -1275,7 +1274,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
 
     test "on non-federating instance, it returns 404", %{conn: conn} do
-      Config.put([:instance, :federating], false)
+      clear_config([:instance, :federating], false)
       user = insert(:user)
 
       conn
@@ -1296,7 +1295,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     end
 
     test "on non-federating instance, it returns 404", %{conn: conn} do
-      Config.put([:instance, :federating], false)
+      clear_config([:instance, :federating], false)
       user = insert(:user)
 
       conn
@@ -1503,7 +1502,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     test "it tracks a signed object fetch", %{conn: conn} do
       user = insert(:user, local: false)
       activity = insert(:note_activity)
-      object = Object.normalize(activity)
+      object = Object.normalize(activity, fetch: false)
 
       object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
 
@@ -1519,7 +1518,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
     test "it tracks a signed activity fetch", %{conn: conn} do
       user = insert(:user, local: false)
       activity = insert(:note_activity)
-      object = Object.normalize(activity)
+      object = Object.normalize(activity, fetch: false)
 
       activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
 
@@ -1536,7 +1535,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       user = insert(:user, local: false)
       other_user = insert(:user, local: false)
       activity = insert(:note_activity)
-      object = Object.normalize(activity)
+      object = Object.normalize(activity, fetch: false)
 
       object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url())
 
@@ -1560,7 +1559,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       user = insert(:user, local: false)
       other_user = insert(:user, local: false)
       activity = insert(:note_activity)
-      object = Object.normalize(activity)
+      object = Object.normalize(activity, fetch: false)
 
       activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url())
 
@@ -1650,7 +1649,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
       assert activity_response["actor"] == user.ap_id
 
       assert %Object{data: %{"attachment" => [attachment]}} =
-               Object.normalize(activity_response["object"])
+               Object.normalize(activity_response["object"], fetch: false)
 
       assert attachment["type"] == "Document"
       assert attachment["name"] == desc