diff options
Diffstat (limited to 'test/web/activity_pub')
6 files changed, 0 insertions, 524 deletions
diff --git a/test/web/activity_pub/object_validators/accept_validation_test.exs b/test/web/activity_pub/object_validators/accept_validation_test.exs deleted file mode 100644 index d6111ba41..000000000 --- a/test/web/activity_pub/object_validators/accept_validation_test.exs +++ /dev/null @@ -1,56 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do -  use Pleroma.DataCase - -  alias Pleroma.Web.ActivityPub.Builder -  alias Pleroma.Web.ActivityPub.ObjectValidator -  alias Pleroma.Web.ActivityPub.Pipeline - -  import Pleroma.Factory - -  setup do -    follower = insert(:user) -    followed = insert(:user, local: false) - -    {:ok, follow_data, _} = Builder.follow(follower, followed) -    {:ok, follow_activity, _} = Pipeline.common_pipeline(follow_data, local: true) - -    {:ok, accept_data, _} = Builder.accept(followed, follow_activity) - -    %{accept_data: accept_data, followed: followed} -  end - -  test "it validates a basic 'accept'", %{accept_data: accept_data} do -    assert {:ok, _, _} = ObjectValidator.validate(accept_data, []) -  end - -  test "it fails when the actor doesn't exist", %{accept_data: accept_data} do -    accept_data = -      accept_data -      |> Map.put("actor", "https://gensokyo.2hu/users/raymoo") - -    assert {:error, _} = ObjectValidator.validate(accept_data, []) -  end - -  test "it fails when the accepted activity doesn't exist", %{accept_data: accept_data} do -    accept_data = -      accept_data -      |> Map.put("object", "https://gensokyo.2hu/users/raymoo/follows/1") - -    assert {:error, _} = ObjectValidator.validate(accept_data, []) -  end - -  test "for an accepted follow, it only validates if the actor of the accept is the followed actor", -       %{accept_data: accept_data} do -    stranger = insert(:user) - -    accept_data = -      accept_data -      |> Map.put("actor", stranger.ap_id) - -    assert {:error, _} = ObjectValidator.validate(accept_data, []) -  end -end diff --git a/test/web/activity_pub/object_validators/reject_validation_test.exs b/test/web/activity_pub/object_validators/reject_validation_test.exs deleted file mode 100644 index 370bb6e5c..000000000 --- a/test/web/activity_pub/object_validators/reject_validation_test.exs +++ /dev/null @@ -1,56 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do -  use Pleroma.DataCase - -  alias Pleroma.Web.ActivityPub.Builder -  alias Pleroma.Web.ActivityPub.ObjectValidator -  alias Pleroma.Web.ActivityPub.Pipeline - -  import Pleroma.Factory - -  setup do -    follower = insert(:user) -    followed = insert(:user, local: false) - -    {:ok, follow_data, _} = Builder.follow(follower, followed) -    {:ok, follow_activity, _} = Pipeline.common_pipeline(follow_data, local: true) - -    {:ok, reject_data, _} = Builder.reject(followed, follow_activity) - -    %{reject_data: reject_data, followed: followed} -  end - -  test "it validates a basic 'reject'", %{reject_data: reject_data} do -    assert {:ok, _, _} = ObjectValidator.validate(reject_data, []) -  end - -  test "it fails when the actor doesn't exist", %{reject_data: reject_data} do -    reject_data = -      reject_data -      |> Map.put("actor", "https://gensokyo.2hu/users/raymoo") - -    assert {:error, _} = ObjectValidator.validate(reject_data, []) -  end - -  test "it fails when the rejected activity doesn't exist", %{reject_data: reject_data} do -    reject_data = -      reject_data -      |> Map.put("object", "https://gensokyo.2hu/users/raymoo/follows/1") - -    assert {:error, _} = ObjectValidator.validate(reject_data, []) -  end - -  test "for an rejected follow, it only validates if the actor of the reject is the followed actor", -       %{reject_data: reject_data} do -    stranger = insert(:user) - -    reject_data = -      reject_data -      |> Map.put("actor", stranger.ap_id) - -    assert {:error, _} = ObjectValidator.validate(reject_data, []) -  end -end diff --git a/test/web/activity_pub/transmogrifier/accept_handling_test.exs b/test/web/activity_pub/transmogrifier/accept_handling_test.exs deleted file mode 100644 index 77d468f5c..000000000 --- a/test/web/activity_pub/transmogrifier/accept_handling_test.exs +++ /dev/null @@ -1,91 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do -  use Pleroma.DataCase - -  alias Pleroma.User -  alias Pleroma.Web.ActivityPub.Transmogrifier -  alias Pleroma.Web.CommonAPI - -  import Pleroma.Factory - -  test "it works for incoming accepts which were pre-accepted" do -    follower = insert(:user) -    followed = insert(:user) - -    {:ok, follower} = User.follow(follower, followed) -    assert User.following?(follower, followed) == true - -    {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) - -    accept_data = -      File.read!("test/fixtures/mastodon-accept-activity.json") -      |> Poison.decode!() -      |> Map.put("actor", followed.ap_id) - -    object = -      accept_data["object"] -      |> Map.put("actor", follower.ap_id) -      |> Map.put("id", follow_activity.data["id"]) - -    accept_data = Map.put(accept_data, "object", object) - -    {:ok, activity} = Transmogrifier.handle_incoming(accept_data) -    refute activity.local - -    assert activity.data["object"] == follow_activity.data["id"] - -    assert activity.data["id"] == accept_data["id"] - -    follower = User.get_cached_by_id(follower.id) - -    assert User.following?(follower, followed) == true -  end - -  test "it works for incoming accepts which are referenced by IRI only" do -    follower = insert(:user) -    followed = insert(:user, locked: true) - -    {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) - -    accept_data = -      File.read!("test/fixtures/mastodon-accept-activity.json") -      |> Poison.decode!() -      |> Map.put("actor", followed.ap_id) -      |> Map.put("object", follow_activity.data["id"]) - -    {:ok, activity} = Transmogrifier.handle_incoming(accept_data) -    assert activity.data["object"] == follow_activity.data["id"] - -    follower = User.get_cached_by_id(follower.id) - -    assert User.following?(follower, followed) == true - -    follower = User.get_by_id(follower.id) -    assert follower.following_count == 1 - -    followed = User.get_by_id(followed.id) -    assert followed.follower_count == 1 -  end - -  test "it fails for incoming accepts which cannot be correlated" do -    follower = insert(:user) -    followed = insert(:user, locked: true) - -    accept_data = -      File.read!("test/fixtures/mastodon-accept-activity.json") -      |> Poison.decode!() -      |> Map.put("actor", followed.ap_id) - -    accept_data = -      Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) - -    {:error, _} = Transmogrifier.handle_incoming(accept_data) - -    follower = User.get_cached_by_id(follower.id) - -    refute User.following?(follower, followed) == true -  end -end diff --git a/test/web/activity_pub/transmogrifier/answer_handling_test.exs b/test/web/activity_pub/transmogrifier/answer_handling_test.exs deleted file mode 100644 index 0f6605c3f..000000000 --- a/test/web/activity_pub/transmogrifier/answer_handling_test.exs +++ /dev/null @@ -1,78 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do -  use Pleroma.DataCase - -  alias Pleroma.Activity -  alias Pleroma.Object -  alias Pleroma.Web.ActivityPub.Transmogrifier -  alias Pleroma.Web.CommonAPI - -  import Pleroma.Factory - -  setup_all do -    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) -    :ok -  end - -  test "incoming, rewrites Note to Answer and increments vote counters" do -    user = insert(:user) - -    {:ok, activity} = -      CommonAPI.post(user, %{ -        status: "suya...", -        poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10} -      }) - -    object = Object.normalize(activity) - -    data = -      File.read!("test/fixtures/mastodon-vote.json") -      |> Poison.decode!() -      |> Kernel.put_in(["to"], user.ap_id) -      |> Kernel.put_in(["object", "inReplyTo"], object.data["id"]) -      |> Kernel.put_in(["object", "to"], user.ap_id) - -    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) -    answer_object = Object.normalize(activity) -    assert answer_object.data["type"] == "Answer" -    assert answer_object.data["inReplyTo"] == object.data["id"] - -    new_object = Object.get_by_ap_id(object.data["id"]) -    assert new_object.data["replies_count"] == object.data["replies_count"] - -    assert Enum.any?( -             new_object.data["oneOf"], -             fn -               %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true -               _ -> false -             end -           ) -  end - -  test "outgoing, rewrites Answer to Note" do -    user = insert(:user) - -    {:ok, poll_activity} = -      CommonAPI.post(user, %{ -        status: "suya...", -        poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10} -      }) - -    poll_object = Object.normalize(poll_activity) -    # TODO: Replace with CommonAPI vote creation when implemented -    data = -      File.read!("test/fixtures/mastodon-vote.json") -      |> Poison.decode!() -      |> Kernel.put_in(["to"], user.ap_id) -      |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"]) -      |> Kernel.put_in(["object", "to"], user.ap_id) - -    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) -    {:ok, data} = Transmogrifier.prepare_outgoing(activity.data) - -    assert data["object"]["type"] == "Note" -  end -end diff --git a/test/web/activity_pub/transmogrifier/question_handling_test.exs b/test/web/activity_pub/transmogrifier/question_handling_test.exs deleted file mode 100644 index d2822ce75..000000000 --- a/test/web/activity_pub/transmogrifier/question_handling_test.exs +++ /dev/null @@ -1,176 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do -  use Pleroma.DataCase - -  alias Pleroma.Activity -  alias Pleroma.Object -  alias Pleroma.Web.ActivityPub.Transmogrifier -  alias Pleroma.Web.CommonAPI - -  import Pleroma.Factory - -  setup_all do -    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) -    :ok -  end - -  test "Mastodon Question activity" do -    data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!() - -    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - -    object = Object.normalize(activity, false) - -    assert object.data["url"] == "https://mastodon.sdf.org/@rinpatch/102070944809637304" - -    assert object.data["closed"] == "2019-05-11T09:03:36Z" - -    assert object.data["context"] == activity.data["context"] - -    assert object.data["context"] == -             "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation" - -    assert object.data["context_id"] - -    assert object.data["anyOf"] == [] - -    assert Enum.sort(object.data["oneOf"]) == -             Enum.sort([ -               %{ -                 "name" => "25 char limit is dumb", -                 "replies" => %{"totalItems" => 0, "type" => "Collection"}, -                 "type" => "Note" -               }, -               %{ -                 "name" => "Dunno", -                 "replies" => %{"totalItems" => 0, "type" => "Collection"}, -                 "type" => "Note" -               }, -               %{ -                 "name" => "Everyone knows that!", -                 "replies" => %{"totalItems" => 1, "type" => "Collection"}, -                 "type" => "Note" -               }, -               %{ -                 "name" => "I can't even fit a funny", -                 "replies" => %{"totalItems" => 1, "type" => "Collection"}, -                 "type" => "Note" -               } -             ]) - -    user = insert(:user) - -    {:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id}) - -    reply_object = Object.normalize(reply_activity, false) - -    assert reply_object.data["context"] == object.data["context"] -    assert reply_object.data["context_id"] == object.data["context_id"] -  end - -  test "Mastodon Question activity with HTML tags in plaintext" do -    options = [ -      %{ -        "type" => "Note", -        "name" => "<input type=\"date\">", -        "replies" => %{"totalItems" => 0, "type" => "Collection"} -      }, -      %{ -        "type" => "Note", -        "name" => "<input type=\"date\"/>", -        "replies" => %{"totalItems" => 0, "type" => "Collection"} -      }, -      %{ -        "type" => "Note", -        "name" => "<input type=\"date\" />", -        "replies" => %{"totalItems" => 1, "type" => "Collection"} -      }, -      %{ -        "type" => "Note", -        "name" => "<input type=\"date\"></input>", -        "replies" => %{"totalItems" => 1, "type" => "Collection"} -      } -    ] - -    data = -      File.read!("test/fixtures/mastodon-question-activity.json") -      |> Poison.decode!() -      |> Kernel.put_in(["object", "oneOf"], options) - -    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) -    object = Object.normalize(activity, false) - -    assert Enum.sort(object.data["oneOf"]) == Enum.sort(options) -  end - -  test "Mastodon Question activity with custom emojis" do -    options = [ -      %{ -        "type" => "Note", -        "name" => ":blobcat:", -        "replies" => %{"totalItems" => 0, "type" => "Collection"} -      }, -      %{ -        "type" => "Note", -        "name" => ":blobfox:", -        "replies" => %{"totalItems" => 0, "type" => "Collection"} -      } -    ] - -    tag = [ -      %{ -        "icon" => %{ -          "type" => "Image", -          "url" => "https://blob.cat/emoji/custom/blobcats/blobcat.png" -        }, -        "id" => "https://blob.cat/emoji/custom/blobcats/blobcat.png", -        "name" => ":blobcat:", -        "type" => "Emoji", -        "updated" => "1970-01-01T00:00:00Z" -      }, -      %{ -        "icon" => %{"type" => "Image", "url" => "https://blob.cat/emoji/blobfox/blobfox.png"}, -        "id" => "https://blob.cat/emoji/blobfox/blobfox.png", -        "name" => ":blobfox:", -        "type" => "Emoji", -        "updated" => "1970-01-01T00:00:00Z" -      } -    ] - -    data = -      File.read!("test/fixtures/mastodon-question-activity.json") -      |> Poison.decode!() -      |> Kernel.put_in(["object", "oneOf"], options) -      |> Kernel.put_in(["object", "tag"], tag) - -    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) -    object = Object.normalize(activity, false) - -    assert object.data["oneOf"] == options - -    assert object.data["emoji"] == %{ -             "blobcat" => "https://blob.cat/emoji/custom/blobcats/blobcat.png", -             "blobfox" => "https://blob.cat/emoji/blobfox/blobfox.png" -           } -  end - -  test "returns same activity if received a second time" do -    data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!() - -    assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - -    assert {:ok, ^activity} = Transmogrifier.handle_incoming(data) -  end - -  test "accepts a Question with no content" do -    data = -      File.read!("test/fixtures/mastodon-question-activity.json") -      |> Poison.decode!() -      |> Kernel.put_in(["object", "content"], "") - -    assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data) -  end -end diff --git a/test/web/activity_pub/transmogrifier/reject_handling_test.exs b/test/web/activity_pub/transmogrifier/reject_handling_test.exs deleted file mode 100644 index 7592fbe1c..000000000 --- a/test/web/activity_pub/transmogrifier/reject_handling_test.exs +++ /dev/null @@ -1,67 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do -  use Pleroma.DataCase - -  alias Pleroma.Activity -  alias Pleroma.User -  alias Pleroma.Web.ActivityPub.Transmogrifier -  alias Pleroma.Web.CommonAPI - -  import Pleroma.Factory - -  test "it fails for incoming rejects which cannot be correlated" do -    follower = insert(:user) -    followed = insert(:user, locked: true) - -    accept_data = -      File.read!("test/fixtures/mastodon-reject-activity.json") -      |> Poison.decode!() -      |> Map.put("actor", followed.ap_id) - -    accept_data = -      Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id)) - -    {:error, _} = Transmogrifier.handle_incoming(accept_data) - -    follower = User.get_cached_by_id(follower.id) - -    refute User.following?(follower, followed) == true -  end - -  test "it works for incoming rejects which are referenced by IRI only" do -    follower = insert(:user) -    followed = insert(:user, locked: true) - -    {:ok, follower} = User.follow(follower, followed) -    {:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed) - -    assert User.following?(follower, followed) == true - -    reject_data = -      File.read!("test/fixtures/mastodon-reject-activity.json") -      |> Poison.decode!() -      |> Map.put("actor", followed.ap_id) -      |> Map.put("object", follow_activity.data["id"]) - -    {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data) - -    follower = User.get_cached_by_id(follower.id) - -    assert User.following?(follower, followed) == false -  end - -  test "it rejects activities without a valid ID" do -    user = insert(:user) - -    data = -      File.read!("test/fixtures/mastodon-follow-activity.json") -      |> Poison.decode!() -      |> Map.put("object", user.ap_id) -      |> Map.put("id", "") - -    :error = Transmogrifier.handle_incoming(data) -  end -end  | 
