tests: add a second spoofing variant
[akkoma] / test / web / ostatus / ostatus_test.exs
index 3e7cf01556e764fd41742e7b5acad336c25db079..f95da8b0a1fc1d4ad5869f9605b1c0bb624927d1 100644 (file)
@@ -278,6 +278,30 @@ defmodule Pleroma.Web.OStatusTest do
     assert User.following?(follower, followed)
   end
 
+  test "handle incoming unfollows with existing follow" do
+    incoming_follow = File.read!("test/fixtures/follow.xml")
+    {:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)
+
+    incoming = File.read!("test/fixtures/unfollow.xml")
+    {:ok, [activity]} = OStatus.handle_incoming(incoming)
+
+    assert activity.data["type"] == "Undo"
+
+    assert activity.data["id"] ==
+             "undo:tag:social.heldscal.la,2017-05-07:subscription:23211:person:44803:2017-05-07T09:54:48+00:00"
+
+    assert activity.data["actor"] == "https://social.heldscal.la/user/23211"
+    assert is_map(activity.data["object"])
+    assert activity.data["object"]["type"] == "Follow"
+    assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino"
+    refute activity.local
+
+    follower = User.get_by_ap_id(activity.data["actor"])
+    followed = User.get_by_ap_id(activity.data["object"]["object"])
+
+    refute User.following?(follower, followed)
+  end
+
   describe "new remote user creation" do
     test "returns local users" do
       local_user = insert(:user)
@@ -432,4 +456,28 @@ defmodule Pleroma.Web.OStatusTest do
              "https://www.w3.org/ns/activitystreams#Public"
            ]
   end
+
+  describe "is_representable?" do
+    test "Note objects are representable" do
+      note_activity = insert(:note_activity)
+
+      assert OStatus.is_representable?(note_activity)
+    end
+
+    test "Article objects are not representable" do
+      note_activity = insert(:note_activity)
+
+      note_object = Object.normalize(note_activity.data["object"])
+
+      note_data =
+        note_object.data
+        |> Map.put("type", "Article")
+
+      cs = Object.change(note_object, %{data: note_data})
+      {: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)
+    end
+  end
 end