diff options
| author | lain <lain@soykaf.club> | 2020-09-17 13:26:04 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-09-17 13:26:04 +0200 | 
| commit | 7a7385092885bd3c28497828d7b8da12e769ca83 (patch) | |
| tree | beee4c47c210cf4019d44e4c0b9a659c62436fe2 /test/web/activity_pub | |
| parent | c4061f06ba26656a6a0e61f68c5f097930a4b054 (diff) | |
| parent | c5acbf8a1bd1a14ea82610cb3f69b8ebbb3ea28b (diff) | |
| download | pleroma-7a7385092885bd3c28497828d7b8da12e769ca83.tar.gz pleroma-7a7385092885bd3c28497828d7b8da12e769ca83.zip  | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into alexgleason/pleroma-chat-moderation
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 8 | ||||
| -rw-r--r-- | test/web/activity_pub/object_validators/article_note_validator_test.exs (renamed from test/web/activity_pub/object_validators/note_validator_test.exs) | 6 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier/article_handling_test.exs | 75 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier/video_handling_test.exs | 93 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 157 | 
5 files changed, 180 insertions, 159 deletions
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index d8caa0b00..7bdad3810 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -1810,6 +1810,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do          |> Enum.map(& &1.id)        assert activities_ids == [] + +      activities_ids = +        %{} +        |> Map.put(:reply_visibility, "self") +        |> Map.put(:reply_filtering_user, nil) +        |> ActivityPub.fetch_public_activities() + +      assert activities_ids == []      end      test "home timeline", %{users: %{u1: user}} do diff --git a/test/web/activity_pub/object_validators/note_validator_test.exs b/test/web/activity_pub/object_validators/article_note_validator_test.exs index 30c481ffb..cc6dab872 100644 --- a/test/web/activity_pub/object_validators/note_validator_test.exs +++ b/test/web/activity_pub/object_validators/article_note_validator_test.exs @@ -2,10 +2,10 @@  # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>  # SPDX-License-Identifier: AGPL-3.0-only -defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidatorTest do +defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do    use Pleroma.DataCase -  alias Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator +  alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator    alias Pleroma.Web.ActivityPub.Utils    import Pleroma.Factory @@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidatorTest do      end      test "a basic note validates", %{note: note} do -      %{valid?: true} = NoteValidator.cast_and_validate(note) +      %{valid?: true} = ArticleNoteValidator.cast_and_validate(note)      end    end  end diff --git a/test/web/activity_pub/transmogrifier/article_handling_test.exs b/test/web/activity_pub/transmogrifier/article_handling_test.exs new file mode 100644 index 000000000..9b12a470a --- /dev/null +++ b/test/web/activity_pub/transmogrifier/article_handling_test.exs @@ -0,0 +1,75 @@ +# 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.ArticleHandlingTest do +  use Oban.Testing, repo: Pleroma.Repo +  use Pleroma.DataCase + +  alias Pleroma.Activity +  alias Pleroma.Object +  alias Pleroma.Object.Fetcher +  alias Pleroma.Web.ActivityPub.Transmogrifier + +  test "Pterotype (Wordpress Plugin) Article" do +    Tesla.Mock.mock(fn %{url: "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog"} -> +      %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")} +    end) + +    data = +      File.read!("test/fixtures/tesla_mock/wedistribute-create-article.json") |> Jason.decode!() + +    {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + +    object = Object.normalize(data["object"]) + +    assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support" + +    assert object.data["summary"] == +             "One of the largest platforms in the federated social web is dropping the protocol that it started with." + +    assert object.data["url"] == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/" +  end + +  test "Plume Article" do +    Tesla.Mock.mock(fn +      %{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} -> +        %Tesla.Env{ +          status: 200, +          body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json") +        } + +      %{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} -> +        %Tesla.Env{ +          status: 200, +          body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json") +        } +    end) + +    {:ok, object} = +      Fetcher.fetch_object_from_id( +        "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/" +      ) + +    assert object.data["name"] == "This Month in Plume: June 2018" + +    assert object.data["url"] == +             "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/" +  end + +  test "Prismo Article" do +    Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} -> +      %Tesla.Env{ +        status: 200, +        body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json") +      } +    end) + +    data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!() + +    {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) +    object = Object.normalize(data["object"]) + +    assert object.data["url"] == "https://prismo.news/posts/83" +  end +end diff --git a/test/web/activity_pub/transmogrifier/video_handling_test.exs b/test/web/activity_pub/transmogrifier/video_handling_test.exs new file mode 100644 index 000000000..69c953a2e --- /dev/null +++ b/test/web/activity_pub/transmogrifier/video_handling_test.exs @@ -0,0 +1,93 @@ +# 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.VideoHandlingTest do +  use Oban.Testing, repo: Pleroma.Repo +  use Pleroma.DataCase + +  alias Pleroma.Activity +  alias Pleroma.Object +  alias Pleroma.Object.Fetcher +  alias Pleroma.Web.ActivityPub.Transmogrifier + +  setup_all do +    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) +    :ok +  end + +  test "skip converting the content when it is nil" do +    data = +      File.read!("test/fixtures/tesla_mock/framatube.org-video.json") +      |> Jason.decode!() +      |> Kernel.put_in(["object", "content"], nil) + +    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) + +    assert object = Object.normalize(activity, false) + +    assert object.data["content"] == nil +  end + +  test "it converts content of object to html" do +    data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!() + +    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) + +    assert object = Object.normalize(activity, false) + +    assert object.data["content"] == +             "<p>Après avoir mené avec un certain succès la campagne « Dégooglisons Internet » en 2014, l’association Framasoft annonce fin 2019 arrêter progressivement un certain nombre de ses services alternatifs aux GAFAM. Pourquoi ?</p><p>Transcription par @aprilorg ici : <a href=\"https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft\">https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft</a></p>" +  end + +  test "it remaps video URLs as attachments if necessary" do +    {:ok, object} = +      Fetcher.fetch_object_from_id( +        "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" +      ) + +    assert object.data["url"] == +             "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" + +    assert object.data["attachment"] == [ +             %{ +               "type" => "Link", +               "mediaType" => "video/mp4", +               "name" => nil, +               "url" => [ +                 %{ +                   "href" => +                     "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", +                   "mediaType" => "video/mp4", +                   "type" => "Link" +                 } +               ] +             } +           ] + +    data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!() + +    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) + +    assert object = Object.normalize(activity, false) + +    assert object.data["attachment"] == [ +             %{ +               "type" => "Link", +               "mediaType" => "video/mp4", +               "name" => nil, +               "url" => [ +                 %{ +                   "href" => +                     "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4", +                   "mediaType" => "video/mp4", +                   "type" => "Link" +                 } +               ] +             } +           ] + +    assert object.data["url"] == +             "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206" +  end +end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index cc55a7be7..561674f01 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -8,7 +8,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do    alias Pleroma.Activity    alias Pleroma.Object -  alias Pleroma.Object.Fetcher    alias Pleroma.Tests.ObanHelpers    alias Pleroma.User    alias Pleroma.Web.ActivityPub.Transmogrifier @@ -45,15 +44,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert "test" in object.data["tag"]      end -    test "it works for incoming notices with url not being a string (prismo)" do -      data = File.read!("test/fixtures/prismo-url-map.json") |> Poison.decode!() - -      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) -      object = Object.normalize(data["object"]) - -      assert object.data["url"] == "https://prismo.news/posts/83" -    end -      test "it cleans up incoming notices which are not really DMs" do        user = insert(:user)        other_user = insert(:user) @@ -355,83 +345,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)      end -    test "skip converting the content when it is nil" do -      object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe" - -      {:ok, object} = Fetcher.fetch_and_contain_remote_object_from_id(object_id) - -      result = -        Pleroma.Web.ActivityPub.Transmogrifier.fix_object(Map.merge(object, %{"content" => nil})) - -      assert result["content"] == nil -    end - -    test "it converts content of object to html" do -      object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe" - -      {:ok, %{"content" => content_markdown}} = -        Fetcher.fetch_and_contain_remote_object_from_id(object_id) - -      {:ok, %Pleroma.Object{data: %{"content" => content}} = object} = -        Fetcher.fetch_object_from_id(object_id) - -      assert content_markdown == -               "Support this and our other Michigan!/usr/group videos and meetings. Learn more at http://mug.org/membership\n\nTwenty Years in Jail: FreeBSD's Jails, Then and Now\n\nJails started as a limited virtualization system, but over the last two years they've..." - -      assert content == -               "<p>Support this and our other Michigan!/usr/group videos and meetings. Learn more at <a href=\"http://mug.org/membership\">http://mug.org/membership</a></p><p>Twenty Years in Jail: FreeBSD’s Jails, Then and Now</p><p>Jails started as a limited virtualization system, but over the last two years they’ve…</p>" - -      assert object.data["mediaType"] == "text/html" -    end - -    test "it remaps video URLs as attachments if necessary" do -      {:ok, object} = -        Fetcher.fetch_object_from_id( -          "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" -        ) - -      assert object.data["url"] == -               "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" - -      assert object.data["attachment"] == [ -               %{ -                 "type" => "Link", -                 "mediaType" => "video/mp4", -                 "url" => [ -                   %{ -                     "href" => -                       "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", -                     "mediaType" => "video/mp4", -                     "type" => "Link" -                   } -                 ] -               } -             ] - -      {:ok, object} = -        Fetcher.fetch_object_from_id( -          "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206" -        ) - -      assert object.data["attachment"] == [ -               %{ -                 "type" => "Link", -                 "mediaType" => "video/mp4", -                 "url" => [ -                   %{ -                     "href" => -                       "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4", -                     "mediaType" => "video/mp4", -                     "type" => "Link" -                   } -                 ] -               } -             ] - -      assert object.data["url"] == -               "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206" -    end -      test "it accepts Flag activities" do        user = insert(:user)        other_user = insert(:user) @@ -1133,75 +1046,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do               }      end -    test "fixes data for video object" do -      object = %{ -        "type" => "Video", -        "url" => [ -          %{ -            "type" => "Link", -            "mimeType" => "video/mp4", -            "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4" -          }, -          %{ -            "type" => "Link", -            "mimeType" => "video/mp4", -            "href" => "https://peertube46fb-ad81-2d4c2d1630e3-240.mp4" -          }, -          %{ -            "type" => "Link", -            "mimeType" => "text/html", -            "href" => "https://peertube.-2d4c2d1630e3" -          }, -          %{ -            "type" => "Link", -            "mimeType" => "text/html", -            "href" => "https://peertube.-2d4c2d16377-42" -          } -        ] -      } - -      assert Transmogrifier.fix_url(object) == %{ -               "attachment" => [ -                 %{ -                   "href" => "https://peede8d-46fb-ad81-2d4c2d1630e3-480.mp4", -                   "mimeType" => "video/mp4", -                   "type" => "Link" -                 } -               ], -               "type" => "Video", -               "url" => "https://peertube.-2d4c2d1630e3" -             } -    end - -    test "fixes url for not Video object" do -      object = %{ -        "type" => "Text", -        "url" => [ -          %{ -            "type" => "Link", -            "mimeType" => "text/html", -            "href" => "https://peertube.-2d4c2d1630e3" -          }, -          %{ -            "type" => "Link", -            "mimeType" => "text/html", -            "href" => "https://peertube.-2d4c2d16377-42" -          } -        ] -      } - -      assert Transmogrifier.fix_url(object) == %{ -               "type" => "Text", -               "url" => "https://peertube.-2d4c2d1630e3" -             } - -      assert Transmogrifier.fix_url(%{"type" => "Text", "url" => []}) == %{ -               "type" => "Text", -               "url" => "" -             } -    end - -    test "retunrs not modified object" do +    test "returns non-modified object" do        assert Transmogrifier.fix_url(%{"type" => "Text"}) == %{"type" => "Text"}      end    end  | 
