diff options
Diffstat (limited to 'test/web')
| -rw-r--r-- | test/web/activity_pub/mrf/subchain_policy_test.exs | 32 | ||||
| -rw-r--r-- | test/web/activity_pub/utils_test.exs | 43 | ||||
| -rw-r--r-- | test/web/activity_pub/visibilty_test.exs | 43 | ||||
| -rw-r--r-- | test/web/mastodon_api/account_view_test.exs | 24 | ||||
| -rw-r--r-- | test/web/mastodon_api/mastodon_api_controller_test.exs | 73 | ||||
| -rw-r--r-- | test/web/streamer_test.exs | 78 | ||||
| -rw-r--r-- | test/web/twitter_api/twitter_api_controller_test.exs | 25 | ||||
| -rw-r--r-- | test/web/twitter_api/views/user_view_test.exs | 12 | 
8 files changed, 322 insertions, 8 deletions
diff --git a/test/web/activity_pub/mrf/subchain_policy_test.exs b/test/web/activity_pub/mrf/subchain_policy_test.exs new file mode 100644 index 000000000..f7cbcad48 --- /dev/null +++ b/test/web/activity_pub/mrf/subchain_policy_test.exs @@ -0,0 +1,32 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do +  use Pleroma.DataCase + +  alias Pleroma.Web.ActivityPub.MRF.DropPolicy +  alias Pleroma.Web.ActivityPub.MRF.SubchainPolicy + +  @message %{ +    "actor" => "https://banned.com", +    "type" => "Create", +    "object" => %{"content" => "hi"} +  } + +  test "it matches and processes subchains when the actor matches a configured target" do +    Pleroma.Config.put([:mrf_subchain, :match_actor], %{ +      ~r/^https:\/\/banned.com/s => [DropPolicy] +    }) + +    {:reject, _} = SubchainPolicy.filter(@message) +  end + +  test "it doesn't match and process subchains when the actor doesn't match a configured target" do +    Pleroma.Config.put([:mrf_subchain, :match_actor], %{ +      ~r/^https:\/\/borked.com/s => [DropPolicy] +    }) + +    {:ok, _message} = SubchainPolicy.filter(@message) +  end +end diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index c57fae437..de741c64b 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -1,6 +1,7 @@  defmodule Pleroma.Web.ActivityPub.UtilsTest do    use Pleroma.DataCase    alias Pleroma.Activity +  alias Pleroma.Object    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Utils @@ -204,4 +205,46 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do               ]             }    end + +  describe "get_existing_votes" do +    test "fetches existing votes" do +      user = insert(:user) +      other_user = insert(:user) + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "status" => "How do I pronounce LaTeX?", +          "poll" => %{ +            "options" => ["laytekh", "lahtekh", "latex"], +            "expires_in" => 20, +            "multiple" => true +          } +        }) + +      object = Object.normalize(activity) +      {:ok, votes, object} = CommonAPI.vote(other_user, object, [0, 1]) +      assert Enum.sort(Utils.get_existing_votes(other_user.ap_id, object)) == Enum.sort(votes) +    end + +    test "fetches only Create activities" do +      user = insert(:user) +      other_user = insert(:user) + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "status" => "Are we living in a society?", +          "poll" => %{ +            "options" => ["yes", "no"], +            "expires_in" => 20 +          } +        }) + +      object = Object.normalize(activity) +      {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) +      vote_object = Object.normalize(vote) +      {:ok, _activity, _object} = ActivityPub.like(user, vote_object) +      [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) +      assert fetched_vote.id == vote.id +    end +  end  end diff --git a/test/web/activity_pub/visibilty_test.exs b/test/web/activity_pub/visibilty_test.exs index 466d980dc..e24df3cab 100644 --- a/test/web/activity_pub/visibilty_test.exs +++ b/test/web/activity_pub/visibilty_test.exs @@ -1,6 +1,7 @@  defmodule Pleroma.Web.ActivityPub.VisibilityTest do    use Pleroma.DataCase +  alias Pleroma.Activity    alias Pleroma.Web.ActivityPub.Visibility    alias Pleroma.Web.CommonAPI    import Pleroma.Factory @@ -121,4 +122,46 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do    test "get_visibility with directMessage flag" do      assert Visibility.get_visibility(%{data: %{"directMessage" => true}}) == "direct"    end + +  describe "entire_thread_visible_for_user?/2" do +    test "returns false if not found activity", %{user: user} do +      refute Visibility.entire_thread_visible_for_user?(%Activity{}, user) +    end + +    test "returns true if activity hasn't 'Create' type", %{user: user} do +      activity = insert(:like_activity) +      assert Visibility.entire_thread_visible_for_user?(activity, user) +    end + +    test "returns false when invalid recipients", %{user: user} do +      author = insert(:user) + +      activity = +        insert(:note_activity, +          note: +            insert(:note, +              user: author, +              data: %{"to" => ["test-user"]} +            ) +        ) + +      refute Visibility.entire_thread_visible_for_user?(activity, user) +    end + +    test "returns true if user following to author" do +      author = insert(:user) +      user = insert(:user, following: [author.ap_id]) + +      activity = +        insert(:note_activity, +          note: +            insert(:note, +              user: author, +              data: %{"to" => [user.ap_id]} +            ) +        ) + +      assert Visibility.entire_thread_visible_for_user?(activity, user) +    end +  end  end diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs index 23f250990..e2244dcb7 100644 --- a/test/web/mastodon_api/account_view_test.exs +++ b/test/web/mastodon_api/account_view_test.exs @@ -67,7 +67,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_favorites: true,          hide_followers: false,          hide_follows: false, -        relationship: %{} +        relationship: %{}, +        skip_thread_containment: false        }      } @@ -132,7 +133,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do          hide_favorites: true,          hide_followers: false,          hide_follows: false, -        relationship: %{} +        relationship: %{}, +        skip_thread_containment: false        }      } @@ -233,10 +235,26 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do            domain_blocking: false,            showing_reblogs: true,            endorsed: false -        } +        }, +        skip_thread_containment: false        }      }      assert expected == AccountView.render("account.json", %{user: user, for: other_user})    end + +  test "returns the settings store if the requesting user is the represented user and it's requested specifically" do +    user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}}) + +    result = +      AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true}) + +    assert result.pleroma.settings_store == %{:fe => "test"} + +    result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true}) +    assert result.pleroma[:settings_store] == nil + +    result = AccountView.render("account.json", %{user: user, for: user}) +    assert result.pleroma[:settings_store] == nil +  end  end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index e941aae5b..8679a083d 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -2423,6 +2423,66 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do    end    describe "updating credentials" do +    test "sets user settings in a generic way", %{conn: conn} do +      user = insert(:user) + +      res_conn = +        conn +        |> assign(:user, user) +        |> patch("/api/v1/accounts/update_credentials", %{ +          "pleroma_settings_store" => %{ +            pleroma_fe: %{ +              theme: "bla" +            } +          } +        }) + +      assert user = json_response(res_conn, 200) +      assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}} + +      user = Repo.get(User, user["id"]) + +      res_conn = +        conn +        |> assign(:user, user) +        |> patch("/api/v1/accounts/update_credentials", %{ +          "pleroma_settings_store" => %{ +            masto_fe: %{ +              theme: "bla" +            } +          } +        }) + +      assert user = json_response(res_conn, 200) + +      assert user["pleroma"]["settings_store"] == +               %{ +                 "pleroma_fe" => %{"theme" => "bla"}, +                 "masto_fe" => %{"theme" => "bla"} +               } + +      user = Repo.get(User, user["id"]) + +      res_conn = +        conn +        |> assign(:user, user) +        |> patch("/api/v1/accounts/update_credentials", %{ +          "pleroma_settings_store" => %{ +            masto_fe: %{ +              theme: "blub" +            } +          } +        }) + +      assert user = json_response(res_conn, 200) + +      assert user["pleroma"]["settings_store"] == +               %{ +                 "pleroma_fe" => %{"theme" => "bla"}, +                 "masto_fe" => %{"theme" => "blub"} +               } +    end +      test "updates the user's bio", %{conn: conn} do        user = insert(:user)        user2 = insert(:user) @@ -2479,6 +2539,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do        assert user["pleroma"]["hide_followers"] == true      end +    test "updates the user's skip_thread_containment option", %{conn: conn} do +      user = insert(:user) + +      response = +        conn +        |> assign(:user, user) +        |> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"}) +        |> json_response(200) + +      assert response["pleroma"]["skip_thread_containment"] == true +      assert refresh_record(user).info.skip_thread_containment +    end +      test "updates the user's hide_follows status", %{conn: conn} do        user = insert(:user) diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs index bfe18cb7f..c18b9f9fe 100644 --- a/test/web/streamer_test.exs +++ b/test/web/streamer_test.exs @@ -11,6 +11,16 @@ defmodule Pleroma.Web.StreamerTest do    alias Pleroma.Web.Streamer    import Pleroma.Factory +  setup do +    skip_thread_containment = Pleroma.Config.get([:instance, :skip_thread_containment]) + +    on_exit(fn -> +      Pleroma.Config.put([:instance, :skip_thread_containment], skip_thread_containment) +    end) + +    :ok +  end +    test "it sends to public" do      user = insert(:user)      other_user = insert(:user) @@ -68,6 +78,74 @@ defmodule Pleroma.Web.StreamerTest do      Task.await(task)    end +  describe "thread_containment" do +    test "it doesn't send to user if recipients invalid and thread containment is enabled" do +      Pleroma.Config.put([:instance, :skip_thread_containment], false) +      author = insert(:user) +      user = insert(:user, following: [author.ap_id]) + +      activity = +        insert(:note_activity, +          note: +            insert(:note, +              user: author, +              data: %{"to" => ["TEST-FFF"]} +            ) +        ) + +      task = Task.async(fn -> refute_receive {:text, _}, 1_000 end) +      fake_socket = %{transport_pid: task.pid, assigns: %{user: user}} +      topics = %{"public" => [fake_socket]} +      Streamer.push_to_socket(topics, "public", activity) + +      Task.await(task) +    end + +    test "it sends message if recipients invalid and thread containment is disabled" do +      Pleroma.Config.put([:instance, :skip_thread_containment], true) +      author = insert(:user) +      user = insert(:user, following: [author.ap_id]) + +      activity = +        insert(:note_activity, +          note: +            insert(:note, +              user: author, +              data: %{"to" => ["TEST-FFF"]} +            ) +        ) + +      task = Task.async(fn -> assert_receive {:text, _}, 1_000 end) +      fake_socket = %{transport_pid: task.pid, assigns: %{user: user}} +      topics = %{"public" => [fake_socket]} +      Streamer.push_to_socket(topics, "public", activity) + +      Task.await(task) +    end + +    test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do +      Pleroma.Config.put([:instance, :skip_thread_containment], false) +      author = insert(:user) +      user = insert(:user, following: [author.ap_id], info: %{skip_thread_containment: true}) + +      activity = +        insert(:note_activity, +          note: +            insert(:note, +              user: author, +              data: %{"to" => ["TEST-FFF"]} +            ) +        ) + +      task = Task.async(fn -> assert_receive {:text, _}, 1_000 end) +      fake_socket = %{transport_pid: task.pid, assigns: %{user: user}} +      topics = %{"public" => [fake_socket]} +      Streamer.push_to_socket(topics, "public", activity) + +      Task.await(task) +    end +  end +    test "it doesn't send to blocked users" do      user = insert(:user)      blocked_user = insert(:user) diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index bcd0f522d..8187ffd0e 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -1495,7 +1495,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do            "hide_follows" => "false"          }) -      user = Repo.get!(User, user.id) +      user = refresh_record(user)        assert user.info.hide_follows == false        assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})      end @@ -1548,6 +1548,29 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do        assert json_response(conn, 200) == UserView.render("user.json", %{user: user, for: user})      end +    test "it sets and un-sets skip_thread_containment", %{conn: conn} do +      user = insert(:user) + +      response = +        conn +        |> assign(:user, user) +        |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "true"}) +        |> json_response(200) + +      assert response["pleroma"]["skip_thread_containment"] == true +      user = refresh_record(user) +      assert user.info.skip_thread_containment + +      response = +        conn +        |> assign(:user, user) +        |> post("/api/account/update_profile.json", %{"skip_thread_containment" => "false"}) +        |> json_response(200) + +      assert response["pleroma"]["skip_thread_containment"] == false +      refute refresh_record(user).info.skip_thread_containment +    end +      test "it locks an account", %{conn: conn} do        user = insert(:user) diff --git a/test/web/twitter_api/views/user_view_test.exs b/test/web/twitter_api/views/user_view_test.exs index a48fc9b78..70c5a0b7f 100644 --- a/test/web/twitter_api/views/user_view_test.exs +++ b/test/web/twitter_api/views/user_view_test.exs @@ -99,7 +99,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "fields" => [],        "pleroma" => %{          "confirmation_pending" => false, -        "tags" => [] +        "tags" => [], +        "skip_thread_containment" => false        },        "rights" => %{"admin" => false, "delete_others_notice" => false},        "role" => "member" @@ -154,7 +155,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "fields" => [],        "pleroma" => %{          "confirmation_pending" => false, -        "tags" => [] +        "tags" => [], +        "skip_thread_containment" => false        },        "rights" => %{"admin" => false, "delete_others_notice" => false},        "role" => "member" @@ -199,7 +201,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "fields" => [],        "pleroma" => %{          "confirmation_pending" => false, -        "tags" => [] +        "tags" => [], +        "skip_thread_containment" => false        },        "rights" => %{"admin" => false, "delete_others_notice" => false},        "role" => "member" @@ -281,7 +284,8 @@ defmodule Pleroma.Web.TwitterAPI.UserViewTest do        "fields" => [],        "pleroma" => %{          "confirmation_pending" => false, -        "tags" => [] +        "tags" => [], +        "skip_thread_containment" => false        },        "rights" => %{"admin" => false, "delete_others_notice" => false},        "role" => "member"  | 
