Merge remote-tracking branch 'upstream/develop' into patch-image-description
[akkoma] / test / web / ostatus / ostatus_test.exs
index 32bf6691b5e3e37575c8e98e5491521a8c8a662d..b4b19ab05351167166f31598b30317b13ca94986 100644 (file)
@@ -1,11 +1,24 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.OStatusTest do
   use Pleroma.DataCase
   alias Pleroma.Web.OStatus
   alias Pleroma.Web.XML
-  alias Pleroma.{Object, Repo, User, Activity}
+  alias Pleroma.Object
+  alias Pleroma.Repo
+  alias Pleroma.User
+  alias Pleroma.Activity
+  alias Pleroma.Instances
   import Pleroma.Factory
   import ExUnit.CaptureLog
 
+  setup_all do
+    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
+    :ok
+  end
+
   test "don't insert create notes twice" do
     incoming = File.read!("test/fixtures/incoming_note_activity.xml")
     {:ok, [activity]} = OStatus.handle_incoming(incoming)
@@ -302,6 +315,22 @@ defmodule Pleroma.Web.OStatusTest do
     refute User.following?(follower, followed)
   end
 
+  test "it clears `unreachable` federation status of the sender" do
+    incoming_reaction_xml = File.read!("test/fixtures/share-gs.xml")
+    doc = XML.parse_document(incoming_reaction_xml)
+    actor_uri = XML.string_from_xpath("//author/uri[1]", doc)
+    reacted_to_author_uri = XML.string_from_xpath("//author/uri[2]", doc)
+
+    Instances.set_consistently_unreachable(actor_uri)
+    Instances.set_consistently_unreachable(reacted_to_author_uri)
+    refute Instances.reachable?(actor_uri)
+    refute Instances.reachable?(reacted_to_author_uri)
+
+    {:ok, _} = OStatus.handle_incoming(incoming_reaction_xml)
+    assert Instances.reachable?(actor_uri)
+    refute Instances.reachable?(reacted_to_author_uri)
+  end
+
   describe "new remote user creation" do
     test "returns local users" do
       local_user = insert(:user)
@@ -505,8 +534,10 @@ defmodule Pleroma.Web.OStatusTest do
         note_object.data
         |> Map.put("type", "Article")
 
+      Cachex.clear(:object_cache)
+
       cs = Object.change(note_object, %{data: note_data})
-      {:ok, article_object} = Repo.update(cs)
+      {:ok, _article_object} = Repo.update(cs)
 
       # the underlying object is now an Article instead of a note, so this should fail
       refute OStatus.is_representable?(note_activity)