diff options
Diffstat (limited to 'test/web')
5 files changed, 173 insertions, 1 deletions
| diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index d437ad456..2677b9e36 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -4,8 +4,11 @@  defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    use Pleroma.DataCase +  use Oban.Testing, repo: Pleroma.Repo +    alias Pleroma.Activity    alias Pleroma.Builders.ActivityBuilder +  alias Pleroma.Notification    alias Pleroma.Object    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub @@ -1554,5 +1557,80 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert follow_info.hide_followers == false        assert follow_info.hide_follows == true      end + +    test "detects hidden follows/followers for friendica" do +      user = +        insert(:user, +          local: false, +          follower_address: "http://localhost:8080/followers/fuser3", +          following_address: "http://localhost:8080/following/fuser3" +        ) + +      {:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user) +      assert follow_info.hide_followers == true +      assert follow_info.follower_count == 296 +      assert follow_info.following_count == 32 +      assert follow_info.hide_follows == true +    end +  end + +  describe "Move activity" do +    test "create" do +      %{ap_id: old_ap_id} = old_user = insert(:user) +      %{ap_id: new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id]) +      follower = insert(:user) +      follower_move_opted_out = insert(:user, allow_following_move: false) + +      User.follow(follower, old_user) +      User.follow(follower_move_opted_out, old_user) + +      assert User.following?(follower, old_user) +      assert User.following?(follower_move_opted_out, old_user) + +      assert {:ok, activity} = ActivityPub.move(old_user, new_user) + +      assert %Activity{ +               actor: ^old_ap_id, +               data: %{ +                 "actor" => ^old_ap_id, +                 "object" => ^old_ap_id, +                 "target" => ^new_ap_id, +                 "type" => "Move" +               }, +               local: true +             } = activity + +      params = %{ +        "op" => "move_following", +        "origin_id" => old_user.id, +        "target_id" => new_user.id +      } + +      assert_enqueued(worker: Pleroma.Workers.BackgroundWorker, args: params) + +      Pleroma.Workers.BackgroundWorker.perform(params, nil) + +      refute User.following?(follower, old_user) +      assert User.following?(follower, new_user) + +      assert User.following?(follower_move_opted_out, old_user) +      refute User.following?(follower_move_opted_out, new_user) + +      activity = %Activity{activity | object: nil} + +      assert [%Notification{activity: ^activity}] = +               Notification.for_user_since(follower, ~N[2019-04-13 11:22:33]) + +      assert [%Notification{activity: ^activity}] = +               Notification.for_user_since(follower_move_opted_out, ~N[2019-04-13 11:22:33]) +    end + +    test "old user must be in the new user's `also_known_as` list" do +      old_user = insert(:user) +      new_user = insert(:user) + +      assert {:error, "Target account must have the origin in `alsoKnownAs`"} = +               ActivityPub.move(old_user, new_user) +    end    end  end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index b31c411dc..5da358c43 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -683,6 +683,37 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert user.bio == "<p>Some bio</p>"      end +    test "it works with alsoKnownAs" do +      {:ok, %Activity{data: %{"actor" => actor}}} = +        "test/fixtures/mastodon-post-activity.json" +        |> File.read!() +        |> Poison.decode!() +        |> Transmogrifier.handle_incoming() + +      assert User.get_cached_by_ap_id(actor).also_known_as == ["http://example.org/users/foo"] + +      {:ok, _activity} = +        "test/fixtures/mastodon-update.json" +        |> File.read!() +        |> Poison.decode!() +        |> Map.put("actor", actor) +        |> Map.update!("object", fn object -> +          object +          |> Map.put("actor", actor) +          |> Map.put("id", actor) +          |> Map.put("alsoKnownAs", [ +            "http://mastodon.example.org/users/foo", +            "http://example.org/users/bar" +          ]) +        end) +        |> Transmogrifier.handle_incoming() + +      assert User.get_cached_by_ap_id(actor).also_known_as == [ +               "http://mastodon.example.org/users/foo", +               "http://example.org/users/bar" +             ] +    end +      test "it works with custom profile fields" do        {:ok, activity} =          "test/fixtures/mastodon-post-activity.json" @@ -1272,6 +1303,30 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert ["https://www.w3.org/ns/activitystreams#Public"] == activity.data["cc"]        assert [user.follower_address] == activity.data["to"]      end + +    test "it accepts Move activities" do +      old_user = insert(:user) +      new_user = insert(:user) + +      message = %{ +        "@context" => "https://www.w3.org/ns/activitystreams", +        "type" => "Move", +        "actor" => old_user.ap_id, +        "object" => old_user.ap_id, +        "target" => new_user.ap_id +      } + +      assert :error = Transmogrifier.handle_incoming(message) + +      {:ok, _new_user} = User.update_and_set_cache(new_user, %{also_known_as: [old_user.ap_id]}) + +      assert {:ok, %Activity{} = activity} = Transmogrifier.handle_incoming(message) +      assert activity.actor == old_user.ap_id +      assert activity.data["actor"] == old_user.ap_id +      assert activity.data["object"] == old_user.ap_id +      assert activity.data["target"] == new_user.ap_id +      assert activity.data["type"] == "Move" +    end    end    describe "prepare outgoing" do diff --git a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs index 519b56d6c..77cfce4fa 100644 --- a/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs +++ b/test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs @@ -103,6 +103,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do        assert user["locked"] == true      end +    test "updates the user's allow_following_move", %{conn: conn} do +      user = insert(:user) + +      assert user.allow_following_move == true + +      conn = +        conn +        |> assign(:user, user) +        |> patch("/api/v1/accounts/update_credentials", %{allow_following_move: "false"}) + +      assert refresh_record(user).allow_following_move == false +      assert user = json_response(conn, 200) +      assert user["pleroma"]["allow_following_move"] == false +    end +      test "updates the user's default scope", %{conn: conn} do        user = insert(:user) diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index d147079ab..35aefb7dc 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -102,7 +102,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do      privacy = user.default_scope      assert %{ -             pleroma: %{notification_settings: ^notification_settings}, +             pleroma: %{notification_settings: ^notification_settings, allow_following_move: true},               source: %{privacy: ^privacy}             } = AccountView.render("show.json", %{user: user, for: user})    end diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index c9043a69a..80b6d414c 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -107,4 +107,28 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      assert [] ==               NotificationView.render("index.json", %{notifications: [notification], for: followed})    end + +  test "Move notification" do +    %{ap_id: old_ap_id} = old_user = insert(:user) +    %{ap_id: _new_ap_id} = new_user = insert(:user, also_known_as: [old_ap_id]) +    follower = insert(:user) + +    User.follow(follower, old_user) +    Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user) +    Pleroma.Tests.ObanHelpers.perform_all() + +    [notification] = Notification.for_user(follower) + +    expected = %{ +      id: to_string(notification.id), +      pleroma: %{is_seen: false}, +      type: "move", +      account: AccountView.render("show.json", %{user: old_user, for: follower}), +      target: AccountView.render("show.json", %{user: new_user, for: follower}), +      created_at: Utils.to_masto_date(notification.inserted_at) +    } + +    assert [expected] == +             NotificationView.render("index.json", %{notifications: [notification], for: follower}) +  end  end | 
