diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/fixtures/minds-invalid-mention-post.json | 1 | ||||
| -rw-r--r-- | test/fixtures/minds-pleroma-mentioned-post.json | 1 | ||||
| -rw-r--r-- | test/pleroma/user/backup_test.exs | 13 | ||||
| -rw-r--r-- | test/pleroma/user_test.exs | 47 | ||||
| -rw-r--r-- | test/pleroma/web/activity_pub/mrf/force_mention_test.exs | 73 | ||||
| -rw-r--r-- | test/pleroma/web/activity_pub/publisher_test.exs | 12 | ||||
| -rw-r--r-- | test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs | 12 | ||||
| -rw-r--r-- | test/pleroma/web/mastodon_api/update_credentials_test.exs | 20 | 
8 files changed, 172 insertions, 7 deletions
diff --git a/test/fixtures/minds-invalid-mention-post.json b/test/fixtures/minds-invalid-mention-post.json new file mode 100644 index 000000000..ea2cb2739 --- /dev/null +++ b/test/fixtures/minds-invalid-mention-post.json @@ -0,0 +1 @@ +{"@context":"https://www.w3.org/ns/activitystreams","type":"Note","id":"https://www.minds.com/api/activitypub/users/1198929502760083472/entities/urn:comment:1600926863310458883:0:0:0:1600932467852709903","attributedTo":"https://www.minds.com/api/activitypub/users/1198929502760083472","content":"\u003Ca class=\u0022u-url mention\u0022 href=\u0022https://www.minds.com/lain\u0022 target=\u0022_blank\u0022\u003E@lain\u003C/a\u003E corn syrup.","to":["https://www.w3.org/ns/activitystreams#Public"],"cc":["https://www.minds.com/api/activitypub/users/1198929502760083472/followers","https://lain.com/users/lain"],"tag":[{"type":"Mention","href":"https://www.minds.com/api/activitypub/users/464237775479123984","name":"@lain"}],"url":"https://www.minds.com/newsfeed/1600926863310458883?focusedCommentUrn=urn:comment:1600926863310458883:0:0:0:1600932467852709903","published":"2024-02-04T17:34:03+00:00","inReplyTo":"https://lain.com/objects/36254095-c839-4167-bcc2-b361d5de9198","source":{"content":"@lain corn syrup.","mediaType":"text/plain"}}
\ No newline at end of file diff --git a/test/fixtures/minds-pleroma-mentioned-post.json b/test/fixtures/minds-pleroma-mentioned-post.json new file mode 100644 index 000000000..9dfa42c90 --- /dev/null +++ b/test/fixtures/minds-pleroma-mentioned-post.json @@ -0,0 +1 @@ +{"@context":["https://www.w3.org/ns/activitystreams","https://lain.com/schemas/litepub-0.1.jsonld",{"@language":"und"}],"actor":"https://lain.com/users/lain","attachment":[],"attributedTo":"https://lain.com/users/lain","cc":["https://lain.com/users/lain/followers"],"content":"which diet is the best for cognitive dissonance","context":"https://lain.com/contexts/98c8a130-e813-4797-8973-600e80114317","conversation":"https://lain.com/contexts/98c8a130-e813-4797-8973-600e80114317","id":"https://lain.com/objects/36254095-c839-4167-bcc2-b361d5de9198","published":"2024-02-04T17:11:23.931890Z","repliesCount":11,"sensitive":null,"source":{"content":"which diet is the best for cognitive dissonance","mediaType":"text/plain"},"summary":"","tag":[],"to":["https://www.w3.org/ns/activitystreams#Public"],"type":"Note"}
\ No newline at end of file diff --git a/test/pleroma/user/backup_test.exs b/test/pleroma/user/backup_test.exs index 0ac57e334..5503d15bc 100644 --- a/test/pleroma/user/backup_test.exs +++ b/test/pleroma/user/backup_test.exs @@ -166,6 +166,7 @@ defmodule Pleroma.User.BackupTest do    test "it creates a zip archive with user data" do      user = insert(:user, %{nickname: "cofe", name: "Cofe", ap_id: "http://cofe.io/users/cofe"}) +    %{ap_id: other_ap_id} = other_user = insert(:user)      {:ok, %{object: %{data: %{"id" => id1}}} = status1} =        CommonAPI.post(user, %{status: "status1"}) @@ -182,6 +183,8 @@ defmodule Pleroma.User.BackupTest do      Bookmark.create(user.id, status2.id)      Bookmark.create(user.id, status3.id) +    CommonAPI.follow(user, other_user) +      assert {:ok, backup} = user |> Backup.new() |> Repo.insert()      assert {:ok, path} = Backup.export(backup, self())      assert {:ok, zipfile} = :zip.zip_open(String.to_charlist(path), [:memory]) @@ -261,6 +264,16 @@ defmodule Pleroma.User.BackupTest do               "type" => "OrderedCollection"             } = Jason.decode!(json) +    assert {:ok, {'following.json', json}} = :zip.zip_get('following.json', zipfile) + +    assert %{ +             "@context" => "https://www.w3.org/ns/activitystreams", +             "id" => "following.json", +             "orderedItems" => [^other_ap_id], +             "totalItems" => 1, +             "type" => "OrderedCollection" +           } = Jason.decode!(json) +      :zip.zip_close(zipfile)      File.rm!(path)    end diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 15809ad63..a93f81659 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -2928,4 +2928,51 @@ defmodule Pleroma.UserTest do        refute User.endorses?(user, pinned_user)      end    end + +  test "it checks fields links for a backlink" do +    user = insert(:user, ap_id: "https://social.example.org/users/lain") + +    fields = [ +      %{"name" => "Link", "value" => "http://example.com/rel_me/null"}, +      %{"name" => "Verified link", "value" => "http://example.com/rel_me/link"}, +      %{"name" => "Not a link", "value" => "i'm not a link"} +    ] + +    user +    |> User.update_and_set_cache(%{raw_fields: fields}) + +    ObanHelpers.perform_all() + +    user = User.get_cached_by_id(user.id) + +    assert [ +             %{"verified_at" => nil}, +             %{"verified_at" => verified_at}, +             %{"verified_at" => nil} +           ] = user.fields + +    assert is_binary(verified_at) +  end + +  test "updating fields does not invalidate previously validated links" do +    user = insert(:user, ap_id: "https://social.example.org/users/lain") + +    user +    |> User.update_and_set_cache(%{ +      raw_fields: [%{"name" => "verified link", "value" => "http://example.com/rel_me/link"}] +    }) + +    ObanHelpers.perform_all() + +    %User{fields: [%{"verified_at" => verified_at}]} = user = User.get_cached_by_id(user.id) + +    user +    |> User.update_and_set_cache(%{ +      raw_fields: [%{"name" => "Verified link", "value" => "http://example.com/rel_me/link"}] +    }) + +    user = User.get_cached_by_id(user.id) + +    assert [%{"verified_at" => ^verified_at}] = user.fields +  end  end diff --git a/test/pleroma/web/activity_pub/mrf/force_mention_test.exs b/test/pleroma/web/activity_pub/mrf/force_mention_test.exs new file mode 100644 index 000000000..b026bab66 --- /dev/null +++ b/test/pleroma/web/activity_pub/mrf/force_mention_test.exs @@ -0,0 +1,73 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionTest do +  use Pleroma.DataCase +  require Pleroma.Constants + +  alias Pleroma.Web.ActivityPub.MRF.ForceMention + +  import Pleroma.Factory + +  test "adds mention to a reply" do +    lain = +      insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain@lain.com", local: false) + +    niobleoum = +      insert(:user, +        ap_id: "https://www.minds.com/api/activitypub/users/1198929502760083472", +        nickname: "niobleoum@minds.com", +        local: false +      ) + +    status = File.read!("test/fixtures/minds-pleroma-mentioned-post.json") |> Jason.decode!() + +    status_activity = %{ +      "type" => "Create", +      "actor" => lain.ap_id, +      "object" => status +    } + +    Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(status_activity) + +    reply = File.read!("test/fixtures/minds-invalid-mention-post.json") |> Jason.decode!() + +    reply_activity = %{ +      "type" => "Create", +      "actor" => niobleoum.ap_id, +      "object" => reply +    } + +    {:ok, %{"object" => %{"tag" => tag}}} = ForceMention.filter(reply_activity) + +    assert Enum.find(tag, fn %{"href" => href} -> href == lain.ap_id end) +  end + +  test "adds mention to a quote" do +    user1 = insert(:user, ap_id: "https://misskey.io/users/83ssedkv53") +    user2 = insert(:user, ap_id: "https://misskey.io/users/7rkrarq81i") + +    status = File.read!("test/fixtures/tesla_mock/misskey.io_8vs6wxufd0.json") |> Jason.decode!() + +    status_activity = %{ +      "type" => "Create", +      "actor" => user1.ap_id, +      "object" => status +    } + +    Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(status_activity) + +    quote_post = File.read!("test/fixtures/quote_post/misskey_quote_post.json") |> Jason.decode!() + +    quote_activity = %{ +      "type" => "Create", +      "actor" => user2.ap_id, +      "object" => quote_post +    } + +    {:ok, %{"object" => %{"tag" => tag}}} = ForceMention.filter(quote_activity) + +    assert Enum.find(tag, fn %{"href" => href} -> href == user1.ap_id end) +  end +end diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 7aa06a5c4..870f1f77a 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -25,6 +25,17 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do    setup_all do: clear_config([:instance, :federating], true) +  describe "should_federate?/1" do +    test "it returns false when the inbox is nil" do +      refute Publisher.should_federate?(nil, false) +      refute Publisher.should_federate?(nil, true) +    end + +    test "it returns true when public is true" do +      assert Publisher.should_federate?(false, true) +    end +  end +    describe "gather_webfinger_links/1" do      test "it returns links" do        user = insert(:user) @@ -205,6 +216,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do        refute called(Instances.set_reachable(inbox))      end +    @tag capture_log: true      test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code",                     Instances,                     [:passthrough], diff --git a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs index 2243b0d4a..353ed1a72 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -107,6 +107,18 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do               |> json_response_and_validate_schema(200)    end +  test "get instance contact information", %{conn: conn} do +    user = insert(:user, %{local: true}) + +    clear_config([:instance, :contact_username], user.nickname) + +    conn = get(conn, "/api/v1/instance") + +    assert result = json_response_and_validate_schema(conn, 200) + +    assert result["contact_account"]["id"] == user.id +  end +    test "get instance information v2", %{conn: conn} do      clear_config([:auth, :oauth_consumer_strategies], []) diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index cf26cd9a6..bea0cae69 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -511,10 +511,15 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do          |> json_response_and_validate_schema(200)        assert account_data["fields"] == [ -               %{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"}, +               %{ +                 "name" => "<a href=\"http://google.com\">foo</a>", +                 "value" => "bar", +                 "verified_at" => nil +               },                 %{                   "name" => "link.io", -                 "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>) +                 "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>), +                 "verified_at" => nil                 }               ] @@ -573,8 +578,8 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do          |> json_response_and_validate_schema(200)        assert account_data["fields"] == [ -               %{"name" => ":firefox:", "value" => "is best 2hu"}, -               %{"name" => "they wins", "value" => ":blank:"} +               %{"name" => ":firefox:", "value" => "is best 2hu", "verified_at" => nil}, +               %{"name" => "they wins", "value" => ":blank:", "verified_at" => nil}               ]        assert account_data["source"]["fields"] == [ @@ -602,10 +607,11 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do          |> json_response_and_validate_schema(200)        assert account["fields"] == [ -               %{"name" => "foo", "value" => "bar"}, +               %{"name" => "foo", "value" => "bar", "verified_at" => nil},                 %{                   "name" => "link", -                 "value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>) +                 "value" => ~S(<a href="http://cofe.io" rel="ugc">http://cofe.io</a>), +                 "verified_at" => nil                 }               ] @@ -627,7 +633,7 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do          |> json_response_and_validate_schema(200)        assert account["fields"] == [ -               %{"name" => "foo", "value" => ""} +               %{"name" => "foo", "value" => "", "verified_at" => nil}               ]      end  | 
