diff options
Diffstat (limited to 'test')
38 files changed, 428 insertions, 179 deletions
| diff --git a/test/activity_test.exs b/test/activity_test.exs index e7ea2bd5e..8aeece96d 100644 --- a/test/activity_test.exs +++ b/test/activity_test.exs @@ -138,6 +138,8 @@ defmodule Pleroma.ActivityTest do        }      end +    clear_config([:instance, :limit_to_local_content]) +      test "finds utf8 text in statuses", %{        japanese_activity: japanese_activity,        user: user @@ -165,7 +167,6 @@ defmodule Pleroma.ActivityTest do           %{local_activity: local_activity} do        Pleroma.Config.put([:instance, :limit_to_local_content], :all)        assert [^local_activity] = Activity.search(nil, "find me") -      Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)      end      test "find all statuses for unauthenticated users when `limit_to_local_content` is `false`", @@ -178,8 +179,6 @@ defmodule Pleroma.ActivityTest do        activities = Enum.sort_by(Activity.search(nil, "find me"), & &1.id)        assert [^local_activity, ^remote_activity] = activities - -      Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)      end    end diff --git a/test/config/transfer_task_test.exs b/test/config/transfer_task_test.exs index ebdc951cf..3d7218dde 100644 --- a/test/config/transfer_task_test.exs +++ b/test/config/transfer_task_test.exs @@ -109,6 +109,10 @@ defmodule Pleroma.Config.TransferTaskTest do    end    describe "pleroma restart" do +    setup do +      on_exit(fn -> Restarter.Pleroma.refresh() end) +    end +      test "don't restart if no reboot time settings were changed" do        emoji = Application.get_env(:pleroma, :emoji)        on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end) @@ -125,7 +129,7 @@ defmodule Pleroma.Config.TransferTaskTest do               )      end -    test "restart pleroma on reboot time key" do +    test "on reboot time key" do        chat = Application.get_env(:pleroma, :chat)        on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end) @@ -138,7 +142,7 @@ defmodule Pleroma.Config.TransferTaskTest do        assert capture_log(fn -> TransferTask.start_link([]) end) =~ "pleroma restarted"      end -    test "restart pleroma on reboot time subkey" do +    test "on reboot time subkey" do        captcha = Application.get_env(:pleroma, Pleroma.Captcha)        on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end) diff --git a/test/http/request_builder_test.exs b/test/http/request_builder_test.exs index 80ef25d7b..113158c9f 100644 --- a/test/http/request_builder_test.exs +++ b/test/http/request_builder_test.exs @@ -9,6 +9,7 @@ defmodule Pleroma.HTTP.RequestBuilderTest do    describe "headers/2" do      clear_config([:http, :send_user_agent]) +    clear_config([:http, :user_agent])      test "don't send pleroma user agent" do        assert RequestBuilder.headers(%{}, []) == %{headers: []} diff --git a/test/object_test.exs b/test/object_test.exs index 5690bedec..75f192da2 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -75,6 +75,7 @@ defmodule Pleroma.ObjectTest do    describe "delete attachments" do      clear_config([Pleroma.Upload]) +    clear_config([:instance, :cleanup_attachments])      test "Disabled via config" do        Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local) diff --git a/test/plugs/admin_secret_authentication_plug_test.exs b/test/plugs/admin_secret_authentication_plug_test.exs index 506b1f609..e41ce1825 100644 --- a/test/plugs/admin_secret_authentication_plug_test.exs +++ b/test/plugs/admin_secret_authentication_plug_test.exs @@ -23,6 +23,8 @@ defmodule Pleroma.Plugs.AdminSecretAuthenticationPlugTest do    end    describe "when secret set it assigns an admin user" do +    clear_config([:admin_token]) +      test "with `admin_token` query parameter", %{conn: conn} do        Pleroma.Config.put(:admin_token, "password123") diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs index 9c1c20541..aa285d827 100644 --- a/test/plugs/http_security_plug_test.exs +++ b/test/plugs/http_security_plug_test.exs @@ -9,6 +9,7 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do    clear_config([:http_securiy, :enabled])    clear_config([:http_security, :sts]) +  clear_config([:http_security, :referrer_policy])    describe "http security enabled" do      setup do diff --git a/test/plugs/remote_ip_test.exs b/test/plugs/remote_ip_test.exs index d120c588b..93e276454 100644 --- a/test/plugs/remote_ip_test.exs +++ b/test/plugs/remote_ip_test.exs @@ -8,6 +8,10 @@ defmodule Pleroma.Plugs.RemoteIpTest do    alias Pleroma.Plugs.RemoteIp +  import Pleroma.Tests.Helpers, only: [clear_config: 1, clear_config: 2] + +  clear_config(RemoteIp) +    test "disabled" do      Pleroma.Config.put(RemoteIp, enabled: false) diff --git a/test/plugs/user_enabled_plug_test.exs b/test/plugs/user_enabled_plug_test.exs index a4035bf0e..b6f297552 100644 --- a/test/plugs/user_enabled_plug_test.exs +++ b/test/plugs/user_enabled_plug_test.exs @@ -8,6 +8,8 @@ defmodule Pleroma.Plugs.UserEnabledPlugTest do    alias Pleroma.Plugs.UserEnabledPlug    import Pleroma.Factory +  clear_config([:instance, :account_activation_required]) +    test "doesn't do anything if the user isn't set", %{conn: conn} do      ret_conn =        conn @@ -18,7 +20,6 @@ defmodule Pleroma.Plugs.UserEnabledPlugTest do    test "with a user that's not confirmed and a config requiring confirmation, it removes that user",         %{conn: conn} do -    old = Pleroma.Config.get([:instance, :account_activation_required])      Pleroma.Config.put([:instance, :account_activation_required], true)      user = insert(:user, confirmation_pending: true) @@ -29,8 +30,6 @@ defmodule Pleroma.Plugs.UserEnabledPlugTest do        |> UserEnabledPlug.call(%{})      assert conn.assigns.user == nil - -    Pleroma.Config.put([:instance, :account_activation_required], old)    end    test "with a user that is deactivated, it removes that user", %{conn: conn} do diff --git a/test/repo_test.exs b/test/repo_test.exs index 5526b0327..2224a6b2b 100644 --- a/test/repo_test.exs +++ b/test/repo_test.exs @@ -67,6 +67,8 @@ defmodule Pleroma.RepoTest do        :ok      end +    clear_config([:i_am_aware_this_may_cause_data_loss, :disable_migration_check]) +      test "raises if it detects unapplied migrations" do        assert_raise Pleroma.Repo.UnappliedMigrationsError, fn ->          capture_log(&Repo.check_migrations_applied!/0) @@ -74,18 +76,8 @@ defmodule Pleroma.RepoTest do      end      test "doesn't do anything if disabled" do -      disable_migration_check = -        Pleroma.Config.get([:i_am_aware_this_may_cause_data_loss, :disable_migration_check]) -        Pleroma.Config.put([:i_am_aware_this_may_cause_data_loss, :disable_migration_check], true) -      on_exit(fn -> -        Pleroma.Config.put( -          [:i_am_aware_this_may_cause_data_loss, :disable_migration_check], -          disable_migration_check -        ) -      end) -        assert :ok == Repo.check_migrations_applied!()      end    end diff --git a/test/support/helpers.ex b/test/support/helpers.ex index d36c29cef..db2f08c81 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -26,6 +26,7 @@ defmodule Pleroma.Tests.Helpers do      end    end +  @doc "Stores initial config value and restores it after *all* test examples are executed."    defmacro clear_config_all(config_path) do      quote do        clear_config_all(unquote(config_path)) do @@ -33,6 +34,11 @@ defmodule Pleroma.Tests.Helpers do      end    end +  @doc """ +  Stores initial config value and restores it after *all* test examples are executed. +  Only use if *all* test examples should work with the same stubbed value +  (*no* examples set a different value). +  """    defmacro clear_config_all(config_path, do: yield) do      quote do        setup_all do diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs index d79d34276..2f9405550 100644 --- a/test/tasks/config_test.exs +++ b/test/tasks/config_test.exs @@ -145,7 +145,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do            mrf_transparency_exclusions: [],            autofollowed_nicknames: [],            max_pinned_statuses: 1, -          no_attachment_links: true, +          attachment_links: false,            welcome_user_nickname: nil,            welcome_message: nil,            max_report_comment_size: 1000, @@ -190,7 +190,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do          end        assert file == -               "#{header}\n\nconfig :pleroma, :instance,\n  name: \"Pleroma\",\n  email: \"example@example.com\",\n  notify_email: \"noreply@example.com\",\n  description: \"A Pleroma instance, an alternative fediverse server\",\n  limit: 5000,\n  chat_limit: 5000,\n  remote_limit: 100_000,\n  upload_limit: 16_000_000,\n  avatar_upload_limit: 2_000_000,\n  background_upload_limit: 4_000_000,\n  banner_upload_limit: 4_000_000,\n  poll_limits: %{\n    max_expiration: 31_536_000,\n    max_option_chars: 200,\n    max_options: 20,\n    min_expiration: 0\n  },\n  registrations_open: true,\n  federating: true,\n  federation_incoming_replies_max_depth: 100,\n  federation_reachability_timeout_days: 7,\n  federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n  allow_relay: true,\n  rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n  public: true,\n  quarantined_instances: [],\n  managed_config: true,\n  static_dir: \"instance/static/\",\n  allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n  mrf_transparency: true,\n  mrf_transparency_exclusions: [],\n  autofollowed_nicknames: [],\n  max_pinned_statuses: 1,\n  no_attachment_links: true,\n  welcome_user_nickname: nil,\n  welcome_message: nil,\n  max_report_comment_size: 1000,\n  safe_dm_mentions: false,\n  healthcheck: false,\n  remote_post_retention_days: 90,\n  skip_thread_containment: true,\n  limit_to_local_content: :unauthenticated,\n  user_bio_length: 5000,\n  user_name_length: 100,\n  max_account_fields: 10,\n  max_remote_account_fields: 20,\n  account_field_name_length: 512,\n  account_field_value_length: 2048,\n  external_user_synchronization: true,\n  extended_nickname_format: true,\n  multi_factor_authentication: [\n    totp: [digits: 6, period: 30],\n    backup_codes: [number: 2, length: 6]\n  ]\n" +               "#{header}\n\nconfig :pleroma, :instance,\n  name: \"Pleroma\",\n  email: \"example@example.com\",\n  notify_email: \"noreply@example.com\",\n  description: \"A Pleroma instance, an alternative fediverse server\",\n  limit: 5000,\n  chat_limit: 5000,\n  remote_limit: 100_000,\n  upload_limit: 16_000_000,\n  avatar_upload_limit: 2_000_000,\n  background_upload_limit: 4_000_000,\n  banner_upload_limit: 4_000_000,\n  poll_limits: %{\n    max_expiration: 31_536_000,\n    max_option_chars: 200,\n    max_options: 20,\n    min_expiration: 0\n  },\n  registrations_open: true,\n  federating: true,\n  federation_incoming_replies_max_depth: 100,\n  federation_reachability_timeout_days: 7,\n  federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n  allow_relay: true,\n  rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n  public: true,\n  quarantined_instances: [],\n  managed_config: true,\n  static_dir: \"instance/static/\",\n  allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n  mrf_transparency: true,\n  mrf_transparency_exclusions: [],\n  autofollowed_nicknames: [],\n  max_pinned_statuses: 1,\n  attachment_links: false,\n  welcome_user_nickname: nil,\n  welcome_message: nil,\n  max_report_comment_size: 1000,\n  safe_dm_mentions: false,\n  healthcheck: false,\n  remote_post_retention_days: 90,\n  skip_thread_containment: true,\n  limit_to_local_content: :unauthenticated,\n  user_bio_length: 5000,\n  user_name_length: 100,\n  max_account_fields: 10,\n  max_remote_account_fields: 20,\n  account_field_name_length: 512,\n  account_field_value_length: 2048,\n  external_user_synchronization: true,\n  extended_nickname_format: true,\n  multi_factor_authentication: [\n    totp: [digits: 6, period: 30],\n    backup_codes: [number: 2, length: 6]\n  ]\n"      end    end  end diff --git a/test/user_search_test.exs b/test/user_search_test.exs index 821858476..fe52cc7a1 100644 --- a/test/user_search_test.exs +++ b/test/user_search_test.exs @@ -15,6 +15,8 @@ defmodule Pleroma.UserSearchTest do    end    describe "User.search" do +    clear_config([:instance, :limit_to_local_content]) +      test "excluded invisible users from results" do        user = insert(:user, %{nickname: "john t1000"})        insert(:user, %{invisible: true, nickname: "john t800"}) @@ -127,8 +129,6 @@ defmodule Pleroma.UserSearchTest do        insert(:user, %{nickname: "lain@pleroma.soykaf.com", local: false})        assert [%{id: ^id}] = User.search("lain") - -      Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)      end      test "find all users for unauthenticated users when `limit_to_local_content` is `false`" do @@ -145,8 +145,6 @@ defmodule Pleroma.UserSearchTest do          |> Enum.sort()        assert [u1.id, u2.id, u3.id] == results - -      Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)      end      test "does not yield false-positive matches" do diff --git a/test/user_test.exs b/test/user_test.exs index 1b5e63bd4..2fc42a90d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -297,15 +297,7 @@ defmodule Pleroma.UserTest do    end    describe "unfollow/2" do -    setup do -      setting = Pleroma.Config.get([:instance, :external_user_synchronization]) - -      on_exit(fn -> -        Pleroma.Config.put([:instance, :external_user_synchronization], setting) -      end) - -      :ok -    end +    clear_config([:instance, :external_user_synchronization])      test "unfollow with syncronizes external user" do        Pleroma.Config.put([:instance, :external_user_synchronization], true) @@ -383,6 +375,7 @@ defmodule Pleroma.UserTest do        password_confirmation: "test",        email: "email@example.com"      } +      clear_config([:instance, :autofollowed_nicknames])      clear_config([:instance, :welcome_message])      clear_config([:instance, :welcome_user_nickname]) @@ -1754,17 +1747,14 @@ defmodule Pleroma.UserTest do    describe "get_cached_by_nickname_or_id" do      setup do -      limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])        local_user = insert(:user)        remote_user = insert(:user, nickname: "nickname@example.com", local: false) -      on_exit(fn -> -        Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content) -      end) -        [local_user: local_user, remote_user: remote_user]      end +    clear_config([:instance, :limit_to_local_content]) +      test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{        remote_user: remote_user      } do diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index ce68e7d0e..9b7cfee63 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -1224,6 +1224,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    end    describe "deletion" do +    clear_config([:instance, :rewrite_policy]) +      test "it creates a delete activity and deletes the original object" do        note = insert(:note_activity)        object = Object.normalize(note) @@ -1327,11 +1329,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      end      test "it passes delete activity through MRF before deleting the object" do -      rewrite_policy = Pleroma.Config.get([:instance, :rewrite_policy])        Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.DropPolicy) -      on_exit(fn -> Pleroma.Config.put([:instance, :rewrite_policy], rewrite_policy) end) -        note = insert(:note_activity)        object = Object.normalize(note) @@ -1396,6 +1395,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    end    describe "update" do +    clear_config([:instance, :max_pinned_statuses]) +      test "it creates an update activity with the new user data" do        user = insert(:user)        {:ok, user} = User.ensure_keys_present(user) diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs index eb6ee4d04..a78752a12 100644 --- a/test/web/activity_pub/mrf/hellthread_policy_test.exs +++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs @@ -26,6 +26,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do      [user: user, message: message]    end +  clear_config(:mrf_hellthread) +    describe "reject" do      test "rejects the message if the recipient count is above reject_threshold", %{        message: message diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs index 602892a37..d950ddd56 100644 --- a/test/web/activity_pub/mrf/keyword_policy_test.exs +++ b/test/web/activity_pub/mrf/keyword_policy_test.exs @@ -7,6 +7,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do    alias Pleroma.Web.ActivityPub.MRF.KeywordPolicy +  clear_config(:mrf_keyword) +    setup do      Pleroma.Config.put([:mrf_keyword], %{reject: [], federated_timeline_removal: [], replace: []})    end diff --git a/test/web/activity_pub/mrf/mention_policy_test.exs b/test/web/activity_pub/mrf/mention_policy_test.exs index 9fd9c31df..93a55850f 100644 --- a/test/web/activity_pub/mrf/mention_policy_test.exs +++ b/test/web/activity_pub/mrf/mention_policy_test.exs @@ -7,6 +7,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.MentionPolicyTest do    alias Pleroma.Web.ActivityPub.MRF.MentionPolicy +  clear_config(:mrf_mention) +    test "pass filter if allow list is empty" do      Pleroma.Config.delete([:mrf_mention]) diff --git a/test/web/activity_pub/mrf/subchain_policy_test.exs b/test/web/activity_pub/mrf/subchain_policy_test.exs index f7cbcad48..29065f612 100644 --- a/test/web/activity_pub/mrf/subchain_policy_test.exs +++ b/test/web/activity_pub/mrf/subchain_policy_test.exs @@ -14,6 +14,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do      "object" => %{"content" => "hi"}    } +  clear_config([:mrf_subchain, :match_actor]) +    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] diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs index 1c88b05c2..fd771ac54 100644 --- a/test/web/activity_pub/transmogrifier/follow_handling_test.exs +++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs @@ -19,6 +19,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do    end    describe "handle_incoming" do +    clear_config([:user, :deny_follow_blocked]) +      test "it works for osada follow request" do        user = insert(:user) diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 5fbdf96f6..908ef4d37 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -6,7 +6,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    use Pleroma.Web.ConnCase    use Oban.Testing, repo: Pleroma.Repo +  import Pleroma.Factory +  import ExUnit.CaptureLog +    alias Pleroma.Activity +  alias Pleroma.Config    alias Pleroma.ConfigDB    alias Pleroma.HTML    alias Pleroma.ModerationLog @@ -19,7 +23,6 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.MastodonAPI.StatusView    alias Pleroma.Web.MediaProxy -  import Pleroma.Factory    setup_all do      Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) @@ -41,7 +44,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    describe "with [:auth, :enforce_oauth_admin_scope_usage]," do      clear_config([:auth, :enforce_oauth_admin_scope_usage]) do -      Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], true) +      Config.put([:auth, :enforce_oauth_admin_scope_usage], true)      end      test "GET /api/pleroma/admin/users/:nickname requires admin:read:accounts or broader scope", @@ -91,7 +94,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    describe "unless [:auth, :enforce_oauth_admin_scope_usage]," do      clear_config([:auth, :enforce_oauth_admin_scope_usage]) do -      Pleroma.Config.put([:auth, :enforce_oauth_admin_scope_usage], false) +      Config.put([:auth, :enforce_oauth_admin_scope_usage], false)      end      test "GET /api/pleroma/admin/users/:nickname requires " <> @@ -579,11 +582,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    describe "POST /api/pleroma/admin/email_invite, with valid config" do      clear_config([:instance, :registrations_open]) do -      Pleroma.Config.put([:instance, :registrations_open], false) +      Config.put([:instance, :registrations_open], false)      end      clear_config([:instance, :invites_enabled]) do -      Pleroma.Config.put([:instance, :invites_enabled], true) +      Config.put([:instance, :invites_enabled], true)      end      test "sends invitation and returns 204", %{admin: admin, conn: conn} do @@ -602,8 +605,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do        assert token_record        refute token_record.used -      notify_email = Pleroma.Config.get([:instance, :notify_email]) -      instance_name = Pleroma.Config.get([:instance, :name]) +      notify_email = Config.get([:instance, :notify_email]) +      instance_name = Config.get([:instance, :name])        email =          Pleroma.Emails.UserEmail.user_invitation_email( @@ -639,8 +642,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      clear_config([:instance, :invites_enabled])      test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn} do -      Pleroma.Config.put([:instance, :registrations_open], false) -      Pleroma.Config.put([:instance, :invites_enabled], false) +      Config.put([:instance, :registrations_open], false) +      Config.put([:instance, :invites_enabled], false)        conn = post(conn, "/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD") @@ -648,8 +651,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end      test "it returns 500 if `registrations_open` is enabled", %{conn: conn} do -      Pleroma.Config.put([:instance, :registrations_open], true) -      Pleroma.Config.put([:instance, :invites_enabled], true) +      Config.put([:instance, :registrations_open], true) +      Config.put([:instance, :invites_enabled], true)        conn = post(conn, "/api/pleroma/admin/users/email_invite?email=foo@bar.com&name=JD") @@ -1886,13 +1889,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    describe "GET /api/pleroma/admin/config" do      clear_config(:configurable_from_database) do -      Pleroma.Config.put(:configurable_from_database, true) +      Config.put(:configurable_from_database, true)      end      test "when configuration from database is off", %{conn: conn} do -      initial = Pleroma.Config.get(:configurable_from_database) -      Pleroma.Config.put(:configurable_from_database, false) -      on_exit(fn -> Pleroma.Config.put(:configurable_from_database, initial) end) +      Config.put(:configurable_from_database, false)        conn = get(conn, "/api/pleroma/admin/config")        assert json_response(conn, 400) == @@ -2036,11 +2037,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do          Application.delete_env(:pleroma, Pleroma.Captcha.NotReal)          Application.put_env(:pleroma, :http, http)          Application.put_env(:tesla, :adapter, Tesla.Mock) +        Restarter.Pleroma.refresh()        end)      end      clear_config(:configurable_from_database) do -      Pleroma.Config.put(:configurable_from_database, true) +      Config.put(:configurable_from_database, true)      end      @tag capture_log: true @@ -2249,21 +2251,63 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do      end      test "saving config which need pleroma reboot", %{conn: conn} do -      chat = Pleroma.Config.get(:chat) -      on_exit(fn -> Pleroma.Config.put(:chat, chat) end) +      chat = Config.get(:chat) +      on_exit(fn -> Config.put(:chat, chat) end) -      conn = -        post( -          conn, -          "/api/pleroma/admin/config", -          %{ -            configs: [ -              %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]} -            ] -          } -        ) +      assert post( +               conn, +               "/api/pleroma/admin/config", +               %{ +                 configs: [ +                   %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]} +                 ] +               } +             ) +             |> json_response(200) == %{ +               "configs" => [ +                 %{ +                   "db" => [":enabled"], +                   "group" => ":pleroma", +                   "key" => ":chat", +                   "value" => [%{"tuple" => [":enabled", true]}] +                 } +               ], +               "need_reboot" => true +             } -      assert json_response(conn, 200) == %{ +      configs = +        conn +        |> get("/api/pleroma/admin/config") +        |> json_response(200) + +      assert configs["need_reboot"] + +      capture_log(fn -> +        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{} +      end) =~ "pleroma restarted" + +      configs = +        conn +        |> get("/api/pleroma/admin/config") +        |> json_response(200) + +      refute Map.has_key?(configs, "need_reboot") +    end + +    test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do +      chat = Config.get(:chat) +      on_exit(fn -> Config.put(:chat, chat) end) + +      assert post( +               conn, +               "/api/pleroma/admin/config", +               %{ +                 configs: [ +                   %{group: ":pleroma", key: ":chat", value: [%{"tuple" => [":enabled", true]}]} +                 ] +               } +             ) +             |> json_response(200) == %{                 "configs" => [                   %{                     "db" => [":enabled"], @@ -2274,6 +2318,36 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                 ],                 "need_reboot" => true               } + +      assert post(conn, "/api/pleroma/admin/config", %{ +               configs: [ +                 %{group: ":pleroma", key: ":key1", value: [%{"tuple" => [":key3", 3]}]} +               ] +             }) +             |> json_response(200) == %{ +               "configs" => [ +                 %{ +                   "group" => ":pleroma", +                   "key" => ":key1", +                   "value" => [ +                     %{"tuple" => [":key3", 3]} +                   ], +                   "db" => [":key3"] +                 } +               ], +               "need_reboot" => true +             } + +      capture_log(fn -> +        assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{} +      end) =~ "pleroma restarted" + +      configs = +        conn +        |> get("/api/pleroma/admin/config") +        |> json_response(200) + +      refute Map.has_key?(configs, "need_reboot")      end      test "saving config with nested merge", %{conn: conn} do @@ -2410,7 +2484,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do                 {ExSyslogger, :ex_syslogger}               ] -      ExUnit.CaptureLog.capture_log(fn -> +      capture_log(fn ->          require Logger          Logger.warn("Ooops...")        end) =~ "Ooops..." @@ -2543,7 +2617,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do          })        assert Application.get_env(:tesla, :adapter) == Tesla.Adapter.Httpc -      assert Pleroma.Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma" +      assert Config.get([Pleroma.Captcha.NotReal, :name]) == "Pleroma"        assert json_response(conn, 200) == %{                 "configs" => [ @@ -2979,13 +3053,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do    describe "GET /api/pleroma/admin/restart" do      clear_config(:configurable_from_database) do -      Pleroma.Config.put(:configurable_from_database, true) +      Config.put(:configurable_from_database, true)      end      test "pleroma restarts", %{conn: conn} do -      ExUnit.CaptureLog.capture_log(fn -> +      capture_log(fn ->          assert conn |> get("/api/pleroma/admin/restart") |> json_response(200) == %{}        end) =~ "pleroma restarted" + +      refute Restarter.Pleroma.need_reboot?()      end    end diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 11f7c068f..601c32954 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -68,6 +68,7 @@ defmodule Pleroma.Web.CommonAPITest do      har = insert(:user)      jafnhar = insert(:user)      tridi = insert(:user) +      Pleroma.Config.put([:instance, :safe_dm_mentions], true)      {:ok, activity} = diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index 4b761e039..848300ef3 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -575,11 +575,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do    end    describe "maybe_add_attachments/3" do -    test "returns parsed results when no_links is true" do +    test "returns parsed results when attachment_links is false" do        assert Utils.maybe_add_attachments(                 {"test", [], ["tags"]},                 [], -               true +               false               ) == {"test", [], ["tags"]}      end @@ -589,7 +589,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do        assert Utils.maybe_add_attachments(                 {"test", [], ["tags"]},                 [attachment], -               false +               true               ) == {                 "test<br><a href=\"SakuraPM.png\" class='attachment'>SakuraPM.png</a>",                 [], diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index e2abcd7c5..8625bb9cf 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -15,6 +15,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    import Pleroma.Factory    describe "account fetching" do +    clear_config([:instance, :limit_to_local_content]) +      test "works by id" do        user = insert(:user) @@ -44,7 +46,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do      end      test "works by nickname for remote users" do -      limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])        Pleroma.Config.put([:instance, :limit_to_local_content], false)        user = insert(:user, nickname: "user@example.com", local: false) @@ -52,13 +53,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do          build_conn()          |> get("/api/v1/accounts/#{user.nickname}") -      Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)        assert %{"id" => id} = json_response(conn, 200)        assert id == user.id      end      test "respects limit_to_local_content == :all for remote user nicknames" do -      limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])        Pleroma.Config.put([:instance, :limit_to_local_content], :all)        user = insert(:user, nickname: "user@example.com", local: false) @@ -67,12 +66,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do          build_conn()          |> get("/api/v1/accounts/#{user.nickname}") -      Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)        assert json_response(conn, 404)      end      test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do -      limit_to_local = Pleroma.Config.get([:instance, :limit_to_local_content])        Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)        user = insert(:user, nickname: "user@example.com", local: false) @@ -90,7 +87,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do          |> assign(:token, insert(:oauth_token, user: reading_user, scopes: ["read:accounts"]))          |> get("/api/v1/accounts/#{user.nickname}") -      Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local)        assert %{"id" => id} = json_response(conn, 200)        assert id == user.id      end @@ -677,6 +673,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do        assert json_response(res, 400) == %{"error" => "{\"email\":[\"has already been taken\"]}"}      end +    clear_config([Pleroma.Plugs.RemoteIp, :enabled]) +      test "rate limit", %{conn: conn} do        Pleroma.Config.put([Pleroma.Plugs.RemoteIp, :enabled], true)        app_token = insert(:oauth_token, user: nil) diff --git a/test/web/mastodon_api/controllers/status_controller_test.exs b/test/web/mastodon_api/controllers/status_controller_test.exs index 83138d7ef..781c3f7dc 100644 --- a/test/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/web/mastodon_api/controllers/status_controller_test.exs @@ -21,6 +21,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do    clear_config([:instance, :federating])    clear_config([:instance, :allow_relay]) +  clear_config([:rich_media, :enabled])    describe "posting statuses" do      setup do: oauth_access(["write:statuses"]) @@ -121,6 +122,32 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do                 NaiveDateTime.to_iso8601(expiration.scheduled_at)      end +    test "it fails to create a status if `expires_in` is less or equal than an hour", %{ +      conn: conn +    } do +      # 1 hour +      expires_in = 60 * 60 + +      assert %{"error" => "Expiry date is too soon"} = +               conn +               |> post("api/v1/statuses", %{ +                 "status" => "oolong", +                 "expires_in" => expires_in +               }) +               |> json_response(422) + +      # 30 minutes +      expires_in = 30 * 60 + +      assert %{"error" => "Expiry date is too soon"} = +               conn +               |> post("api/v1/statuses", %{ +                 "status" => "oolong", +                 "expires_in" => expires_in +               }) +               |> json_response(422) +    end +      test "posting an undefined status with an attachment", %{user: user, conn: conn} do        file = %Plug.Upload{          content_type: "image/jpg", @@ -1228,4 +1255,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do      assert [] = json_response(third_conn, 200)    end + +  test "expires_at is nil for another user" do +    %{conn: conn, user: user} = oauth_access(["read:statuses"]) +    {:ok, activity} = CommonAPI.post(user, %{"status" => "foobar", "expires_in" => 1_000_000}) + +    expires_at = +      activity.id +      |> ActivityExpiration.get_by_activity_id() +      |> Map.get(:scheduled_at) +      |> NaiveDateTime.to_iso8601() + +    assert %{"pleroma" => %{"expires_at" => ^expires_at}} = +             conn |> get("/api/v1/statuses/#{activity.id}") |> json_response(:ok) + +    %{conn: conn} = oauth_access(["read:statuses"]) + +    assert %{"pleroma" => %{"expires_at" => nil}} = +             conn |> get("/api/v1/statuses/#{activity.id}") |> json_response(:ok) +  end  end diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index fc110417c..560f8179f 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -37,15 +37,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      status = StatusView.render("show.json", activity: activity)      assert status[:pleroma][:emoji_reactions] == [ -             %{emoji: "☕", count: 2, reacted: false}, -             %{emoji: "🍵", count: 1, reacted: false} +             %{name: "☕", count: 2, me: false}, +             %{name: "🍵", count: 1, me: false}             ]      status = StatusView.render("show.json", activity: activity, for: user)      assert status[:pleroma][:emoji_reactions] == [ -             %{emoji: "☕", count: 2, reacted: true}, -             %{emoji: "🍵", count: 1, reacted: false} +             %{name: "☕", count: 2, me: true}, +             %{name: "🍵", count: 1, me: false}             ]    end @@ -491,7 +491,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do          title: "Example website"        } -      %{provider_name: "Example site name"} = +      %{provider_name: "example.com"} =          StatusView.render("card.json", %{page_url: page_url, rich_media: card})      end @@ -506,7 +506,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do          description: "Example description"        } -      %{provider_name: "Example site name"} = +      %{provider_name: "example.com"} =          StatusView.render("card.json", %{page_url: page_url, rich_media: card})      end    end diff --git a/test/web/media_proxy/media_proxy_controller_test.exs b/test/web/media_proxy/media_proxy_controller_test.exs index fdfdb5ec6..8c0c2a0e2 100644 --- a/test/web/media_proxy/media_proxy_controller_test.exs +++ b/test/web/media_proxy/media_proxy_controller_test.exs @@ -7,11 +7,8 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do    import Mock    alias Pleroma.Config -  setup do -    media_proxy_config = Config.get([:media_proxy]) || [] -    on_exit(fn -> Config.put([:media_proxy], media_proxy_config) end) -    :ok -  end +  clear_config(:media_proxy) +  clear_config([Pleroma.Web.Endpoint, :secret_key_base])    test "it returns 404 when MediaProxy disabled", %{conn: conn} do      Config.put([:media_proxy, :enabled], false) diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs index 96bdde219..2be5c9de0 100644 --- a/test/web/media_proxy/media_proxy_test.exs +++ b/test/web/media_proxy/media_proxy_test.exs @@ -9,6 +9,7 @@ defmodule Pleroma.Web.MediaProxyTest do    alias Pleroma.Web.MediaProxy.MediaProxyController    clear_config([:media_proxy, :enabled]) +  clear_config(Pleroma.Upload)    describe "when enabled" do      setup do @@ -224,7 +225,6 @@ defmodule Pleroma.Web.MediaProxyTest do      end      test "ensure Pleroma.Upload base_url is always whitelisted" do -      upload_config = Pleroma.Config.get([Pleroma.Upload])        media_url = "https://media.pleroma.social"        Pleroma.Config.put([Pleroma.Upload, :base_url], media_url) @@ -232,8 +232,6 @@ defmodule Pleroma.Web.MediaProxyTest do        encoded = url(url)        assert String.starts_with?(encoded, media_url) - -      Pleroma.Config.put([Pleroma.Upload], upload_config)      end    end  end diff --git a/test/web/metadata/opengraph_test.exs b/test/web/metadata/opengraph_test.exs index 4283f72cd..0d47b1cb8 100644 --- a/test/web/metadata/opengraph_test.exs +++ b/test/web/metadata/opengraph_test.exs @@ -7,6 +7,8 @@ defmodule Pleroma.Web.Metadata.Providers.OpenGraphTest do    import Pleroma.Factory    alias Pleroma.Web.Metadata.Providers.OpenGraph +  clear_config([Pleroma.Web.Metadata, :unfurl_nsfw]) +    test "it renders all supported types of attachments and skips unknown types" do      user = insert(:user) diff --git a/test/web/metadata/twitter_card_test.exs b/test/web/metadata/twitter_card_test.exs index 85a654f52..faf347cc6 100644 --- a/test/web/metadata/twitter_card_test.exs +++ b/test/web/metadata/twitter_card_test.exs @@ -13,6 +13,8 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do    alias Pleroma.Web.Metadata.Utils    alias Pleroma.Web.Router +  clear_config([Pleroma.Web.Metadata, :unfurl_nsfw]) +    test "it renders twitter card for user info" do      user = insert(:user, name: "Jimmy Hendriks", bio: "born 19 March 1994")      avatar_url = Utils.attachment_url(User.avatar_url(user)) diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs index 39dd72cec..d1d7a3ce8 100644 --- a/test/web/node_info_test.exs +++ b/test/web/node_info_test.exs @@ -6,7 +6,9 @@ defmodule Pleroma.Web.NodeInfoTest do    use Pleroma.Web.ConnCase    import Pleroma.Factory +    clear_config([:mrf_simple]) +  clear_config(:instance)    test "GET /.well-known/nodeinfo", %{conn: conn} do      links = @@ -63,11 +65,6 @@ defmodule Pleroma.Web.NodeInfoTest do    end    test "returns fieldsLimits field", %{conn: conn} do -    max_account_fields = Pleroma.Config.get([:instance, :max_account_fields]) -    max_remote_account_fields = Pleroma.Config.get([:instance, :max_remote_account_fields]) -    account_field_name_length = Pleroma.Config.get([:instance, :account_field_name_length]) -    account_field_value_length = Pleroma.Config.get([:instance, :account_field_value_length]) -      Pleroma.Config.put([:instance, :max_account_fields], 10)      Pleroma.Config.put([:instance, :max_remote_account_fields], 15)      Pleroma.Config.put([:instance, :account_field_name_length], 255) @@ -82,11 +79,6 @@ defmodule Pleroma.Web.NodeInfoTest do      assert response["metadata"]["fieldsLimits"]["maxRemoteFields"] == 15      assert response["metadata"]["fieldsLimits"]["nameLength"] == 255      assert response["metadata"]["fieldsLimits"]["valueLength"] == 2048 - -    Pleroma.Config.put([:instance, :max_account_fields], max_account_fields) -    Pleroma.Config.put([:instance, :max_remote_account_fields], max_remote_account_fields) -    Pleroma.Config.put([:instance, :account_field_name_length], account_field_name_length) -    Pleroma.Config.put([:instance, :account_field_value_length], account_field_value_length)    end    test "it returns the safe_dm_mentions feature if enabled", %{conn: conn} do @@ -112,28 +104,28 @@ defmodule Pleroma.Web.NodeInfoTest do      Pleroma.Config.put([:instance, :safe_dm_mentions], option)    end -  test "it shows if federation is enabled/disabled", %{conn: conn} do -    original = Pleroma.Config.get([:instance, :federating]) +  describe "`metadata/federation/enabled`" do +    clear_config([:instance, :federating]) -    Pleroma.Config.put([:instance, :federating], true) - -    response = -      conn -      |> get("/nodeinfo/2.1.json") -      |> json_response(:ok) +    test "it shows if federation is enabled/disabled", %{conn: conn} do +      Pleroma.Config.put([:instance, :federating], true) -    assert response["metadata"]["federation"]["enabled"] == true +      response = +        conn +        |> get("/nodeinfo/2.1.json") +        |> json_response(:ok) -    Pleroma.Config.put([:instance, :federating], false) +      assert response["metadata"]["federation"]["enabled"] == true -    response = -      conn -      |> get("/nodeinfo/2.1.json") -      |> json_response(:ok) +      Pleroma.Config.put([:instance, :federating], false) -    assert response["metadata"]["federation"]["enabled"] == false +      response = +        conn +        |> get("/nodeinfo/2.1.json") +        |> json_response(:ok) -    Pleroma.Config.put([:instance, :federating], original) +      assert response["metadata"]["federation"]["enabled"] == false +    end    end    test "it shows MRF transparency data if enabled", %{conn: conn} do diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index adeff8e25..89fcf8c36 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -17,7 +17,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do      key: "_test",      signing_salt: "cooldude"    ] -  clear_config_all([:instance, :account_activation_required]) + +  clear_config([:instance, :account_activation_required])    describe "in OAuth consumer mode, " do      setup do diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs index be5007de5..36868db38 100644 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs @@ -14,7 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do    import Pleroma.Factory -  test "POST /api/v1/pleroma/statuses/:id/react_with_emoji", %{conn: conn} do +  test "PUT /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do      user = insert(:user)      other_user = insert(:user) @@ -24,18 +24,19 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do        conn        |> assign(:user, other_user)        |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"])) -      |> post("/api/v1/pleroma/statuses/#{activity.id}/react_with_emoji", %{"emoji" => "☕"}) +      |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/☕")        |> json_response(200) +    # We return the status, but this our implementation detail.      assert %{"id" => id} = result      assert to_string(activity.id) == id      assert result["pleroma"]["emoji_reactions"] == [ -             %{"emoji" => "☕", "count" => 1, "reacted" => true} +             %{"name" => "☕", "count" => 1, "me" => true}             ]    end -  test "POST /api/v1/pleroma/statuses/:id/unreact_with_emoji", %{conn: conn} do +  test "DELETE /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do      user = insert(:user)      other_user = insert(:user) @@ -46,7 +47,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do        conn        |> assign(:user, other_user)        |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"])) -      |> post("/api/v1/pleroma/statuses/#{activity.id}/unreact_with_emoji", %{"emoji" => "☕"}) +      |> delete("/api/v1/pleroma/statuses/#{activity.id}/reactions/☕")      assert %{"id" => id} = json_response(result, 200)      assert to_string(activity.id) == id @@ -56,7 +57,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      assert object.data["reaction_count"] == 0    end -  test "GET /api/v1/pleroma/statuses/:id/emoji_reactions_by", %{conn: conn} do +  test "GET /api/v1/pleroma/statuses/:id/reactions", %{conn: conn} do      user = insert(:user)      other_user = insert(:user)      doomed_user = insert(:user) @@ -65,7 +66,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      result =        conn -      |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by") +      |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")        |> json_response(200)      assert result == [] @@ -77,11 +78,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      result =        conn -      |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by") +      |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")        |> json_response(200) -    [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user], "reacted" => false}] = -      result +    [%{"name" => "🎅", "count" => 1, "accounts" => [represented_user], "me" => false}] = result      assert represented_user["id"] == other_user.id @@ -89,10 +89,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do        conn        |> assign(:user, other_user)        |> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:statuses"])) -      |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by") +      |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")        |> json_response(200) -    assert [%{"emoji" => "🎅", "count" => 1, "accounts" => [_represented_user], "reacted" => true}] = +    assert [%{"name" => "🎅", "count" => 1, "accounts" => [_represented_user], "me" => true}] =               result    end diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs index 9dcab93da..c26b487d9 100644 --- a/test/web/plugs/federating_plug_test.exs +++ b/test/web/plugs/federating_plug_test.exs @@ -4,7 +4,8 @@  defmodule Pleroma.Web.FederatingPlugTest do    use Pleroma.Web.ConnCase -  clear_config_all([:instance, :federating]) + +  clear_config([:instance, :federating])    test "returns and halt the conn when federating is disabled" do      Pleroma.Config.put([:instance, :federating], false) diff --git a/test/web/rich_media/parsers/twitter_card_test.exs b/test/web/rich_media/parsers/twitter_card_test.exs index 751ca614c..f2ebbde7e 100644 --- a/test/web/rich_media/parsers/twitter_card_test.exs +++ b/test/web/rich_media/parsers/twitter_card_test.exs @@ -7,11 +7,14 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do    alias Pleroma.Web.RichMedia.Parsers.TwitterCard    test "returns error when html not contains twitter card" do -    assert TwitterCard.parse("", %{}) == {:error, "No twitter card metadata found"} +    assert TwitterCard.parse([{"html", [], [{"head", [], []}, {"body", [], []}]}], %{}) == +             {:error, "No twitter card metadata found"}    end    test "parses twitter card with only name attributes" do -    html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html") +    html = +      File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html") +      |> Floki.parse_document!()      assert TwitterCard.parse(html, %{}) ==               {:ok, @@ -26,7 +29,9 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do    end    test "parses twitter card with only property attributes" do -    html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html") +    html = +      File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html") +      |> Floki.parse_document!()      assert TwitterCard.parse(html, %{}) ==               {:ok, @@ -45,7 +50,9 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do    end    test "parses twitter card with name & property attributes" do -    html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html") +    html = +      File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html") +      |> Floki.parse_document!()      assert TwitterCard.parse(html, %{}) ==               {:ok, @@ -73,7 +80,8 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do          "YTQ5MF9EQVIgZXhodW1hdGlvbiBvZiBNYXJnYXJldCBDb3JiaW4gZ3JhdmUgMTkyNi5qcGciXSxbInAiLCJjb252ZXJ0IiwiIl0sWyJwIiwiY29udmVydCIsIi1xdWFsaXR5IDgxIC1hdXRvLW9" <>          "yaWVudCJdLFsicCIsInRodW1iIiwiNjAweD4iXV0/DAR%20exhumation%20of%20Margaret%20Corbin%20grave%201926.jpg" -    html = File.read!("test/fixtures/margaret-corbin-grave-west-point.html") +    html = +      File.read!("test/fixtures/margaret-corbin-grave-west-point.html") |> Floki.parse_document!()      assert TwitterCard.parse(html, %{}) ==               {:ok, @@ -87,7 +95,9 @@ defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do    end    test "takes first founded title in html head if there is html markup error" do -    html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html") +    html = +      File.read!("test/fixtures/nypd-facial-recognition-children-teenagers4.html") +      |> Floki.parse_document!()      assert TwitterCard.parse(html, %{}) ==               {:ok, diff --git a/test/web/streamer/streamer_test.exs b/test/web/streamer/streamer_test.exs index 2a7550551..1cf20f1c2 100644 --- a/test/web/streamer/streamer_test.exs +++ b/test/web/streamer/streamer_test.exs @@ -20,7 +20,7 @@ defmodule Pleroma.Web.StreamerTest do    @streamer_timeout 150    @streamer_start_wait 10 -  clear_config_all([:instance, :skip_thread_containment]) +  clear_config([:instance, :skip_thread_containment])    describe "user streams" do      setup do diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs new file mode 100644 index 000000000..ab0a2c3df --- /dev/null +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -0,0 +1,142 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.TwitterAPI.ControllerTest do +  use Pleroma.Web.ConnCase + +  alias Pleroma.Builders.ActivityBuilder +  alias Pleroma.Repo +  alias Pleroma.User +  alias Pleroma.Web.OAuth.Token + +  import Pleroma.Factory + +  describe "POST /api/qvitter/statuses/notifications/read" do +    test "without valid credentials", %{conn: conn} do +      conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567}) +      assert json_response(conn, 403) == %{"error" => "Invalid credentials."} +    end + +    test "with credentials, without any params" do +      %{user: current_user, conn: conn} = +        oauth_access(["read:notifications", "write:notifications"]) + +      conn = +        conn +        |> assign(:user, current_user) +        |> post("/api/qvitter/statuses/notifications/read") + +      assert json_response(conn, 400) == %{ +               "error" => "You need to specify latest_id", +               "request" => "/api/qvitter/statuses/notifications/read" +             } +    end + +    test "with credentials, with params" do +      %{user: current_user, conn: conn} = +        oauth_access(["read:notifications", "write:notifications"]) + +      other_user = insert(:user) + +      {:ok, _activity} = +        ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) + +      response_conn = +        conn +        |> assign(:user, current_user) +        |> get("/api/v1/notifications") + +      [notification] = response = json_response(response_conn, 200) + +      assert length(response) == 1 + +      assert notification["pleroma"]["is_seen"] == false + +      response_conn = +        conn +        |> assign(:user, current_user) +        |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]}) + +      [notification] = response = json_response(response_conn, 200) + +      assert length(response) == 1 + +      assert notification["pleroma"]["is_seen"] == true +    end +  end + +  describe "GET /api/account/confirm_email/:id/:token" do +    setup do +      {:ok, user} = +        insert(:user) +        |> User.confirmation_changeset(need_confirmation: true) +        |> Repo.update() + +      assert user.confirmation_pending + +      [user: user] +    end + +    test "it redirects to root url", %{conn: conn, user: user} do +      conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}") + +      assert 302 == conn.status +    end + +    test "it confirms the user account", %{conn: conn, user: user} do +      get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}") + +      user = User.get_cached_by_id(user.id) + +      refute user.confirmation_pending +      refute user.confirmation_token +    end + +    test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do +      conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}") + +      assert 500 == conn.status +    end + +    test "it returns 500 if token is invalid", %{conn: conn, user: user} do +      conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token") + +      assert 500 == conn.status +    end +  end + +  describe "GET /api/oauth_tokens" do +    setup do +      token = insert(:oauth_token) |> Repo.preload(:user) + +      %{token: token} +    end + +    test "renders list", %{token: token} do +      response = +        build_conn() +        |> assign(:user, token.user) +        |> get("/api/oauth_tokens") + +      keys = +        json_response(response, 200) +        |> hd() +        |> Map.keys() + +      assert keys -- ["id", "app_name", "valid_until"] == [] +    end + +    test "revoke token", %{token: token} do +      response = +        build_conn() +        |> assign(:user, token.user) +        |> delete("/api/oauth_tokens/#{token.id}") + +      tokens = Token.get_user_tokens(token.user) + +      assert tokens == [] +      assert response.status == 201 +    end +  end +end diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 85a9be3e0..7650238f2 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -117,15 +117,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    end    describe "register with one time token" do -    setup do -      setting = Pleroma.Config.get([:instance, :registrations_open]) - -      if setting do -        Pleroma.Config.put([:instance, :registrations_open], false) -        on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end) -      end - -      :ok +    clear_config([:instance, :registrations_open]) do +      Pleroma.Config.put([:instance, :registrations_open], false)      end      test "returns user on success" do @@ -191,14 +184,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    end    describe "registers with date limited token" do -    setup do -      setting = Pleroma.Config.get([:instance, :registrations_open]) - -      if setting do -        Pleroma.Config.put([:instance, :registrations_open], false) -        on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end) -      end +    clear_config([:instance, :registrations_open]) do +      Pleroma.Config.put([:instance, :registrations_open], false) +    end +    setup do        data = %{          "nickname" => "vinny",          "email" => "pasta@pizza.vs", @@ -256,15 +246,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    end    describe "registers with reusable token" do -    setup do -      setting = Pleroma.Config.get([:instance, :registrations_open]) - -      if setting do -        Pleroma.Config.put([:instance, :registrations_open], false) -        on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end) -      end - -      :ok +    clear_config([:instance, :registrations_open]) do +      Pleroma.Config.put([:instance, :registrations_open], false)      end      test "returns user on success, after him registration fails" do @@ -309,15 +292,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do    end    describe "registers with reusable date limited token" do -    setup do -      setting = Pleroma.Config.get([:instance, :registrations_open]) - -      if setting do -        Pleroma.Config.put([:instance, :registrations_open], false) -        on_exit(fn -> Pleroma.Config.put([:instance, :registrations_open], setting) end) -      end - -      :ok +    clear_config([:instance, :registrations_open]) do +      Pleroma.Config.put([:instance, :registrations_open], false)      end      test "returns user on success" do diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 5d60c0d51..56633ffce 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -19,7 +19,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do    clear_config([:instance])    clear_config([:frontend_configurations, :pleroma_fe]) -  clear_config([:user, :deny_follow_blocked])    describe "POST /api/pleroma/follow_import" do      setup do: oauth_access(["follow"]) | 
