diff --git a/.gitignore b/.gitignore index 6ae21e914..62ca61bce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /db /deps /*.ez +/test/instance /test/uploads /.elixir_ls /test/fixtures/DSCN0010_tmp.jpg diff --git a/CHANGELOG.md b/CHANGELOG.md index 9466c0b55..fe79d43cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,24 +10,28 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Polls now always return a `voters_count`, even if they are single-choice. - Admin Emails: The ap id is used as the user link in emails now. +- Improved registration workflow for email confirmation and account approval modes. +- **Breaking:** Changed `mix pleroma.user toggle_confirmed` to `mix pleroma.user confirm` - Search: When using Postgres 11+, Pleroma will use the `websearch_to_tsvector` function to parse search queries. - Emoji: Support the full Unicode 13.1 set of Emoji for reactions, plus regional indicators. -- **Breaking** Besides only the instance, entries for simple_policy, transparency_exclusions and quarantined_instances now contain a reason as well. +- **Breaking** Besides only the instance, entries for simple_policy, transparency_exclusions and +- Admin API: Reports now ordered by newest ### Added - Reports now generate notifications for admins and mods. - Experimental websocket-based federation between Pleroma instances. -- Support for local-only statuses +- Support for local-only statuses. - Support pagination of blocks and mutes. - Account backup. - Configuration: Add `:instance, autofollowing_nicknames` setting to provide a way to make accounts automatically follow new users that register on the local Pleroma instance. - Ability to view remote timelines, with ex. `/api/v1/timelines/public?instance=lain.com` and streams `public:remote` and `public:remote:media`. - The site title is now injected as a `title` tag like preloads or metadata. - Password reset tokens now are not accepted after a certain age. -- Mix tasks to help with displaying and removing ConfigDB entries. See `mix pleroma.config` +- Mix tasks to help with displaying and removing ConfigDB entries. See `mix pleroma.config`. - OAuth form improvements: users are remembered by their cookie, the CSS is overridable by the admin, and the style has been improved. - OAuth improvements and fixes: more secure session-based authentication (by token that could be revoked anytime), ability to revoke belonging OAuth token from any client etc. +- Ability to set ActivityPub aliases for follower migration.
API Changes @@ -35,13 +39,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Pleroma API: Add `idempotency_key` to the chat message entity that can be used for optimistic message sending. - Pleroma API: (`GET /api/v1/pleroma/federation_status`) Add a way to get a list of unreachable instances. - Mastodon API: User and conversation mutes can now auto-expire if `expires_in` parameter was given while adding the mute. -- Admin API: An endpoint to manage frontends -- Streaming API: Add follow relationships updates +- Admin API: An endpoint to manage frontends. +- Streaming API: Add follow relationships updates.
### Fixed - Users with `is_discoverable` field set to false (default value) will appear in in-service search results but be hidden from external services (search bots etc.). +- Streaming API: Posts and notifications are not dropped, when CLI task is executing. +- Creating incorrect IPv4 address-style HTTP links when encountering certain numbers.
API Changes @@ -51,24 +57,35 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased (Patch) +### Fixed + +- Fix ability to update Pleroma Chat push notifications with PUT /api/v1/push/subscription and alert type pleroma:chat_mention +- Emoji Reaction activity filtering from blocked and muted accounts. +- StealEmojiPolicy creates dir for emojis, if it doesn't exist. + +## [2.2.1] - 2020-12-22 + ### Changed +- Updated Pleroma FE ### Fixed - Config generation: rename `Pleroma.Upload.Filter.ExifTool` to `Pleroma.Upload.Filter.Exiftool`. -- Search: RUM index search speed has been fixed. - S3 Uploads with Elixir 1.11. -- Emoji Reaction activity filtering from blocked and muted accounts. - Mix task pleroma.user delete_activities for source installations. -- Fix ability to update Pleroma Chat push notifications with PUT /api/v1/push/subscription and alert type pleroma:chat_mention -- Forwarded reports duplication from Pleroma instances. +- Search: RUM index search speed has been fixed. - Rich Media Previews sometimes showed the wrong preview due to a bug following redirects. +- Fixes for the autolinker. +- Forwarded reports duplication from Pleroma instances. -
- API -- Statuses were not displayed for Mastodon forwarded reports. +-
+ API + - Statuses were not displayed for Mastodon forwarded reports. +
-
+### Upgrade notes + +1. Restart Pleroma ## [2.2.0] - 2020-11-12 @@ -106,7 +123,7 @@ switched to a new configuration mechanism, however it was not officially removed - Media preview proxy (requires `ffmpeg` and `ImageMagick` to be installed and media proxy to be enabled; see `:media_preview_proxy` config for more details). - Mix tasks for controlling user account confirmation status in bulk (`mix pleroma.user confirm_all` and `mix pleroma.user unconfirm_all`) -- Mix task for sending confirmation emails to all unconfirmed users (`mix pleroma.email send_confirmation_mails`) +- Mix task for sending confirmation emails to all unconfirmed users (`mix pleroma.email resend_confirmation_emails`) - Mix task option for force-unfollowing relays - App metrics: ability to restrict access to specified IP whitelist. diff --git a/config/config.exs b/config/config.exs index c7ac0d22c..7b14fbfe5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -47,7 +47,6 @@ config :pleroma, ecto_repos: [Pleroma.Repo] config :pleroma, Pleroma.Repo, - types: Pleroma.PostgresTypes, telemetry_event: [Pleroma.Repo.Instrumenter], migration_lock: nil @@ -64,14 +63,6 @@ filters: [Pleroma.Upload.Filter.Dedupe], link_name: false, proxy_remote: false, - proxy_opts: [ - redirect_on_failure: false, - max_body_length: 25 * 1_048_576, - http: [ - follow_redirect: true, - pool: :upload - ] - ], filename_display_max_length: 30, default_description: nil @@ -306,7 +297,7 @@ hideSitename: false, hideUserStats: false, loginMethod: "password", - logo: "/static/logo.png", + logo: "/static/logo.svg", logoMargin: ".1em", logoMask: true, minimalScopesMode: false, @@ -343,8 +334,8 @@ config :pleroma, :manifest, icons: [ %{ - src: "/static/logo.png", - type: "image/png" + src: "/static/logo.svg", + type: "image/svg+xml" } ], theme_color: "#282c37", @@ -648,7 +639,7 @@ } config :pleroma, :oauth2, - token_expires_in: 3600 * 24 * 30, + token_expires_in: 3600 * 24 * 365 * 100, issue_new_refresh_token: true, clean_expired_tokens: false diff --git a/config/description.exs b/config/description.exs index 73faa5f59..ddb02e435 100644 --- a/config/description.exs +++ b/config/description.exs @@ -101,74 +101,10 @@ %{ key: :proxy_remote, type: :boolean, - description: - "If enabled, requests to media stored using a remote uploader will be proxied instead of being redirected" - }, - %{ - key: :proxy_opts, - label: "Proxy Options", - type: :keyword, - description: "Options for Pleroma.ReverseProxy", - suggestions: [ - redirect_on_failure: false, - max_body_length: 25 * 1_048_576, - http: [ - follow_redirect: true, - pool: :media - ] - ], - children: [ - %{ - key: :redirect_on_failure, - type: :boolean, - description: - "Redirects the client to the real remote URL if there's any HTTP errors. " <> - "Any error during body processing will not be redirected as the response is chunked." - }, - %{ - key: :max_body_length, - type: :integer, - description: - "Limits the content length to be approximately the " <> - "specified length. It is validated with the `content-length` header and also verified when proxying." - }, - %{ - key: :http, - label: "HTTP", - type: :keyword, - description: "HTTP options", - children: [ - %{ - key: :adapter, - type: :keyword, - description: "Adapter specific options", - children: [ - %{ - key: :ssl_options, - type: :keyword, - label: "SSL Options", - description: "SSL options for HTTP adapter", - children: [ - %{ - key: :versions, - type: {:list, :atom}, - description: "List of TLS versions to use", - suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"] - } - ] - } - ] - }, - %{ - key: :proxy_url, - label: "Proxy URL", - type: [:string, :tuple], - description: "Proxy URL", - suggestions: ["127.0.0.1:8123", {:socks5, :localhost, 9050}] - } - ] - } - ] + description: """ + Proxy requests to the remote uploader.\n + Useful if media upload endpoint is not internet accessible. + """ }, %{ key: :filename_display_max_length, @@ -1256,7 +1192,7 @@ hideSitename: false, hideUserStats: false, loginMethod: "password", - logo: "/static/logo.png", + logo: "/static/logo.svg", logoMargin: ".1em", logoMask: true, minimalScopesMode: false, @@ -1342,7 +1278,7 @@ key: :logo, type: {:string, :image}, description: "URL of the logo, defaults to Pleroma's logo", - suggestions: ["/static/logo.png"] + suggestions: ["/static/logo.svg"] }, %{ key: :logoMargin, @@ -1552,7 +1488,7 @@ %{ key: :enabled, type: :boolean, - description: "Enables proxying of remote media to the instance's proxy" + description: "Enables proxying of remote media via the instance's proxy" }, %{ key: :base_url, @@ -1589,80 +1525,41 @@ }, %{ key: :proxy_opts, - label: "Proxy Options", + label: "Advanced MediaProxy Options", type: :keyword, - description: "Options for Pleroma.ReverseProxy", + description: "Internal Pleroma.ReverseProxy settings", suggestions: [ redirect_on_failure: false, max_body_length: 25 * 1_048_576, - max_read_duration: 30_000, - http: [ - follow_redirect: true, - pool: :media - ] + max_read_duration: 30_000 ], children: [ %{ key: :redirect_on_failure, type: :boolean, - description: - "Redirects the client to the real remote URL if there's any HTTP errors. " <> - "Any error during body processing will not be redirected as the response is chunked." + description: """ + Redirects the client to the origin server upon encountering HTTP errors.\n + Note that files larger than Max Body Length will trigger an error. (e.g., Peertube videos)\n\n + **WARNING:** This setting will allow larger files to be accessed, but exposes the\n + IP addresses of your users to the other servers, bypassing the MediaProxy. + """ }, %{ key: :max_body_length, type: :integer, - description: - "Limits the content length to be approximately the " <> - "specified length. It is validated with the `content-length` header and also verified when proxying." + description: "Maximum file size allowed through the Pleroma MediaProxy cache." }, %{ key: :max_read_duration, type: :integer, - description: "Timeout (in milliseconds) of GET request to remote URI." - }, - %{ - key: :http, - label: "HTTP", - type: :keyword, - description: "HTTP options", - children: [ - %{ - key: :adapter, - type: :keyword, - description: "Adapter specific options", - children: [ - %{ - key: :ssl_options, - type: :keyword, - label: "SSL Options", - description: "SSL options for HTTP adapter", - children: [ - %{ - key: :versions, - type: {:list, :atom}, - description: "List of TLS version to use", - suggestions: [:tlsv1, ":tlsv1.1", ":tlsv1.2"] - } - ] - } - ] - }, - %{ - key: :proxy_url, - label: "Proxy URL", - type: [:string, :tuple], - description: "Proxy URL", - suggestions: ["127.0.0.1:8123", {:socks5, :localhost, 9050}] - } - ] + description: "Timeout (in milliseconds) of GET request to the remote URI." } ] }, %{ key: :whitelist, type: {:list, :string}, - description: "List of hosts with scheme to bypass the mediaproxy", + description: "List of hosts with scheme to bypass the MediaProxy", suggestions: ["http://example.com"] } ] @@ -1955,14 +1852,8 @@ group: :pleroma, key: Oban, type: :group, - description: """ - [Oban](https://github.com/sorentwo/oban) asynchronous job processor configuration. - - Note: if you are running PostgreSQL in [`silent_mode`](https://postgresqlco.nf/en/doc/param/silent_mode?version=9.1), - it's advised to set [`log_destination`](https://postgresqlco.nf/en/doc/param/log_destination?version=9.1) to `syslog`, - otherwise `postmaster.log` file may grow because of "you don't own a lock of type ShareLock" warnings - (see https://github.com/sorentwo/oban/issues/52). - """, + description: + "[Oban](https://github.com/sorentwo/oban) asynchronous job processor configuration.", children: [ %{ key: :log, diff --git a/config/emoji.txt b/config/emoji.txt index 200768ad1..a2c5add2e 100644 --- a/config/emoji.txt +++ b/config/emoji.txt @@ -1,2 +1,4 @@ firefox, /emoji/Firefox.gif, Gif,Fun blank, /emoji/blank.png, Fun +dinosaur, /emoji/dino walking.gif, Gif +external_emoji, https://example.com/emoji.png diff --git a/config/test.exs b/config/test.exs index 2a20a03e7..7fc457463 100644 --- a/config/test.exs +++ b/config/test.exs @@ -47,7 +47,10 @@ password: "postgres", database: "pleroma_test", hostname: System.get_env("DB_HOST") || "localhost", - pool: Ecto.Adapters.SQL.Sandbox + pool: Ecto.Adapters.SQL.Sandbox, + pool_size: 50 + +config :pleroma, :dangerzone, override_repo_pool_size: true # Reduce hash rounds for testing config :pbkdf2_elixir, rounds: 1 @@ -121,6 +124,20 @@ config :pleroma, :mrf, policies: [] +config :pleroma, :pipeline, + object_validator: Pleroma.Web.ActivityPub.ObjectValidatorMock, + mrf: Pleroma.Web.ActivityPub.MRFMock, + activity_pub: Pleroma.Web.ActivityPub.ActivityPubMock, + side_effects: Pleroma.Web.ActivityPub.SideEffectsMock, + federator: Pleroma.Web.FederatorMock, + config: Pleroma.ConfigMock + +config :pleroma, :cachex, provider: Pleroma.CachexMock + +config :pleroma, :side_effects, + ap_streamer: Pleroma.Web.ActivityPub.ActivityPubMock, + logger: Pleroma.LoggerMock + if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" else diff --git a/docs/API/admin_api.md b/docs/API/admin_api.md index 266f8cef8..5253dc668 100644 --- a/docs/API/admin_api.md +++ b/docs/API/admin_api.md @@ -1123,6 +1123,7 @@ Loads json generated from `config/descriptions.exs`. ```json [ { + "id": 1234, "data": { "actor": { "id": 1, diff --git a/docs/API/differences_in_mastoapi_responses.md b/docs/API/differences_in_mastoapi_responses.md index 1b197e073..84430408b 100644 --- a/docs/API/differences_in_mastoapi_responses.md +++ b/docs/API/differences_in_mastoapi_responses.md @@ -206,6 +206,7 @@ Additional parameters can be added to the JSON body/Form data: - `pleroma_settings_store` - Opaque user settings to be saved on the backend. - `skip_thread_containment` - if true, skip filtering out broken threads - `allow_following_move` - if true, allows automatically follow moved following accounts +- `also_known_as` - array of ActivityPub IDs, needed for following move - `pleroma_background_image` - sets the background image of the user. Can be set to "" (an empty string) to reset. - `discoverable` - if true, external services (search bots) etc. are allowed to index / list the account (regardless of this setting, user will still appear in regular search results). - `actor_type` - the type of this account. diff --git a/docs/administration/CLI_tasks/email.md b/docs/administration/CLI_tasks/email.md index d9aa0e71b..2bb57bea4 100644 --- a/docs/administration/CLI_tasks/email.md +++ b/docs/administration/CLI_tasks/email.md @@ -16,8 +16,7 @@ mix pleroma.email test [--to ] ``` - -Example: +Example: === "OTP" @@ -36,11 +35,11 @@ Example: === "OTP" ```sh - ./bin/pleroma_ctl email send_confirmation_mails + ./bin/pleroma_ctl email resend_confirmation_emails ``` === "From Source" ```sh - mix pleroma.email send_confirmation_mails + mix pleroma.email resend_confirmation_emails ``` diff --git a/docs/administration/CLI_tasks/user.md b/docs/administration/CLI_tasks/user.md index c64ed4f22..b57dce0e7 100644 --- a/docs/administration/CLI_tasks/user.md +++ b/docs/administration/CLI_tasks/user.md @@ -264,13 +264,13 @@ === "OTP" ```sh - ./bin/pleroma_ctl user toggle_confirmed + ./bin/pleroma_ctl user confirm ``` === "From Source" ```sh - mix pleroma.user toggle_confirmed + mix pleroma.user confirm ``` ## Set confirmation status for all regular active users diff --git a/installation/download-mastofe-build.sh b/installation/download-mastofe-build.sh index ee9e1c217..b8a021ef3 100755 --- a/installation/download-mastofe-build.sh +++ b/installation/download-mastofe-build.sh @@ -9,29 +9,32 @@ static_dir="instance/static" # project_branch="pleroma" # static_dir="priv/static" -if [[ ! -d "${static_dir}" ]] +if [ ! -d "${static_dir}" ] then echo "Error: ${static_dir} directory is missing, are you sure you are running this script at the root of pleroma’s repository?" exit 1 fi -last_modified="$(curl -s -I 'https://git.pleroma.social/api/v4/projects/'${project_id}'/jobs/artifacts/'${project_branch}'/download?job=build' | grep '^Last-Modified:' | cut -d: -f2-)" +last_modified="$(curl --fail -s -I 'https://git.pleroma.social/api/v4/projects/'${project_id}'/jobs/artifacts/'${project_branch}'/download?job=build' | grep '^Last-Modified:' | cut -d: -f2-)" echo "branch:${project_branch}" echo "Last-Modified:${last_modified}" artifact="mastofe.zip" -if [[ -e mastofe.timestamp ]] && [[ "${last_modified}" != "" ]] +if [ "${last_modified}x" = "x" ] then - if [[ "$(cat mastofe.timestamp)" == "${last_modified}" ]] - then - echo "MastoFE is up-to-date, exiting…" - exit 0 - fi + echo "ERROR: Couldn't get the modification date of the latest build archive, maybe it expired, exiting..." + exit 1 fi -curl -c - "https://git.pleroma.social/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=build" -o "${artifact}" || exit +if [ -e mastofe.timestamp ] && [ "$(cat mastofe.timestamp)" = "${last_modified}" ] +then + echo "MastoFE is up-to-date, exiting..." + exit 0 +fi + +curl --fail -c - "https://git.pleroma.social/api/v4/projects/${project_id}/jobs/artifacts/${project_branch}/download?job=build" -o "${artifact}" || exit # TODO: Update the emoji as well rm -fr "${static_dir}/sw.js" "${static_dir}/packs" || exit diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex index 7575f0ef8..a33a9951c 100644 --- a/lib/mix/pleroma.ex +++ b/lib/mix/pleroma.ex @@ -12,7 +12,8 @@ defmodule Mix.Pleroma do :cachex, :flake_id, :swoosh, - :timex + :timex, + :fast_html ] @cachex_children ["object", "user", "scrubber", "web_resp"] @doc "Common functions to be reused in mix tasks" @@ -37,12 +38,23 @@ def start_pleroma do Enum.each(apps, &Application.ensure_all_started/1) + oban_config = [ + crontab: [], + repo: Pleroma.Repo, + log: false, + queues: [], + plugins: [] + ] + children = [ Pleroma.Repo, + Pleroma.Emoji, {Pleroma.Config.TransferTask, false}, Pleroma.Web.Endpoint, - {Oban, Pleroma.Config.get(Oban)} + {Oban, oban_config}, + {Majic.Pool, + [name: Pleroma.MajicPool, pool_size: Pleroma.Config.get([:majic_pool, :size], 2)]} ] ++ http_children(adapter) diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index a01c36ece..22151ce08 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -48,9 +48,15 @@ def run(["bump_all_conversations"]) do def run(["update_users_following_followers_counts"]) do start_pleroma() - User - |> Repo.all() - |> Enum.each(&User.update_follower_count/1) + Repo.transaction( + fn -> + from(u in User, select: u) + |> Repo.stream() + |> Stream.each(&User.update_follower_count/1) + |> Stream.run() + end, + timeout: :infinity + ) end def run(["prune_objects" | args]) do diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index ac8688424..853c4eaa2 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -161,12 +161,21 @@ def run(["gen" | rest]) do ) |> Path.expand() + {strip_uploads_message, strip_uploads_default} = + if Pleroma.Utils.command_available?("exiftool") do + {"Do you want to strip location (GPS) data from uploaded images? This requires exiftool, it was detected as installed. (y/n)", + "y"} + else + {"Do you want to strip location (GPS) data from uploaded images? This requires exiftool, it was detected as not installed, please install it if you answer yes. (y/n)", + "n"} + end + strip_uploads = get_option( options, :strip_uploads, - "Do you want to strip location (GPS) data from uploaded images? (y/n)", - "y" + strip_uploads_message, + strip_uploads_default ) === "y" anonymize_uploads = @@ -253,7 +262,7 @@ def run(["gen" | rest]) do else shell_error( "The task would have overwritten the following files:\n" <> - (Enum.map(paths, &"- #{&1}\n") |> Enum.join("")) <> + (Enum.map(will_overwrite, &"- #{&1}\n") |> Enum.join("")) <> "Rerun with `--force` to overwrite them." ) end diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index ca9c8579f..20fe6c6e4 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -345,11 +345,11 @@ def run(["delete_activities", nickname]) do end end - def run(["toggle_confirmed", nickname]) do + def run(["confirm", nickname]) do start_pleroma() with %User{} = user <- User.get_cached_by_nickname(nickname) do - {:ok, user} = User.toggle_confirmation(user) + {:ok, user} = User.confirm(user) message = if user.confirmation_pending, do: "needs", else: "doesn't need" diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 079823312..62fa9cca3 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -24,6 +24,8 @@ defmodule Pleroma.Activity do @primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true} + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + schema "activities" do field(:data, :map) field(:local, :boolean, default: true) @@ -272,7 +274,7 @@ defp get_in_reply_to_activity_from_object(%Object{data: %{"inReplyTo" => ap_id}} defp get_in_reply_to_activity_from_object(_), do: nil def get_in_reply_to_activity(%Activity{} = activity) do - get_in_reply_to_activity_from_object(Object.normalize(activity)) + get_in_reply_to_activity_from_object(Object.normalize(activity, fetch: false)) end def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"]) @@ -298,7 +300,7 @@ def delete_all_by_object_ap_id(_), do: nil defp purge_web_resp_cache(%Activity{} = activity) do %{path: path} = URI.parse(activity.data["id"]) - Cachex.del(:web_resp_cache, path) + @cachex.del(:web_resp_cache, path) activity end diff --git a/lib/pleroma/activity/ir/topics.ex b/lib/pleroma/activity/ir/topics.ex index fe2e8cb5c..6a26d7fdd 100644 --- a/lib/pleroma/activity/ir/topics.ex +++ b/lib/pleroma/activity/ir/topics.ex @@ -8,7 +8,7 @@ defmodule Pleroma.Activity.Ir.Topics do def get_activity_topics(activity) do activity - |> Object.normalize() + |> Object.normalize(fetch: false) |> generate_topics(activity) |> List.flatten() end diff --git a/lib/pleroma/caching.ex b/lib/pleroma/caching.ex new file mode 100644 index 000000000..766d12d1b --- /dev/null +++ b/lib/pleroma/caching.ex @@ -0,0 +1,19 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Caching do + @callback get!(Cachex.cache(), any()) :: any() + @callback get(Cachex.cache(), any()) :: {atom(), any()} + @callback put(Cachex.cache(), any(), any(), Keyword.t()) :: {Cachex.status(), boolean()} + @callback put(Cachex.cache(), any(), any()) :: {Cachex.status(), boolean()} + @callback fetch!(Cachex.cache(), any(), function() | nil) :: any() + # @callback del(Cachex.cache(), any(), Keyword.t()) :: {Cachex.status(), boolean()} + @callback del(Cachex.cache(), any()) :: {Cachex.status(), boolean()} + @callback stream!(Cachex.cache(), any()) :: Enumerable.t() + @callback expire_at(Cachex.cache(), binary(), number()) :: {Cachex.status(), boolean()} + @callback exists?(Cachex.cache(), any()) :: {Cachex.status(), boolean()} + @callback execute!(Cachex.cache(), function()) :: any() + @callback get_and_update(Cachex.cache(), any(), function()) :: + {:commit | :ignore, any()} +end diff --git a/lib/pleroma/captcha.ex b/lib/pleroma/captcha.ex index 6ab754b6f..990003dcd 100644 --- a/lib/pleroma/captcha.ex +++ b/lib/pleroma/captcha.ex @@ -7,6 +7,8 @@ defmodule Pleroma.Captcha do alias Plug.Crypto.KeyGenerator alias Plug.Crypto.MessageEncryptor + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @doc """ Ask the configured captcha service for a new captcha """ @@ -86,7 +88,7 @@ defp validate_expiration(created_at) do end defp validate_usage(token) do - if is_nil(Cachex.get!(:used_captcha_cache, token)) do + if is_nil(@cachex.get!(:used_captcha_cache, token)) do :ok else {:error, :already_used} @@ -95,7 +97,7 @@ defp validate_usage(token) do defp mark_captcha_as_used(token) do ttl = seconds_valid() |> :timer.seconds() - Cachex.put(:used_captcha_cache, token, true, ttl: ttl) + @cachex.put(:used_captcha_cache, token, true, ttl: ttl) end defp method, do: Pleroma.Config.get!([__MODULE__, :method]) diff --git a/lib/pleroma/config.ex b/lib/pleroma/config.ex index 97f877595..86d4f6b72 100644 --- a/lib/pleroma/config.ex +++ b/lib/pleroma/config.ex @@ -3,14 +3,18 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Config do + @behaviour Pleroma.Config.Getting defmodule Error do defexception [:message] end + @impl true def get(key), do: get(key, nil) + @impl true def get([key], default), do: get(key, default) + @impl true def get([_ | _] = path, default) do case fetch(path) do {:ok, value} -> value @@ -18,6 +22,7 @@ def get([_ | _] = path, default) do end end + @impl true def get(key, default) do Application.get_env(:pleroma, key, default) end diff --git a/lib/pleroma/config/getting.ex b/lib/pleroma/config/getting.ex new file mode 100644 index 000000000..cc557674c --- /dev/null +++ b/lib/pleroma/config/getting.ex @@ -0,0 +1,8 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Config.Getting do + @callback get(any()) :: any() + @callback get(any(), any()) :: any() +end diff --git a/lib/pleroma/conversation.ex b/lib/pleroma/conversation.ex index 77933f0be..e15259091 100644 --- a/lib/pleroma/conversation.ex +++ b/lib/pleroma/conversation.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Conversation do alias Pleroma.Conversation.Participation alias Pleroma.Conversation.Participation.RecipientShip + alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User use Ecto.Schema @@ -58,7 +59,7 @@ def maybe_create_recipientships(participation, activity) do def create_or_bump_for(activity, opts \\ []) do with true <- Pleroma.Web.ActivityPub.Visibility.is_direct?(activity), "Create" <- activity.data["type"], - object <- Pleroma.Object.normalize(activity), + %Object{} = object <- Object.normalize(activity, fetch: false), true <- object.data["type"] in ["Note", "Question"], ap_id when is_binary(ap_id) and byte_size(ap_id) > 0 <- object.data["context"] do {:ok, conversation} = create_for_ap_id(ap_id) diff --git a/lib/pleroma/emails/user_email.ex b/lib/pleroma/emails/user_email.ex index 806a61fd2..2b51d5b05 100644 --- a/lib/pleroma/emails/user_email.ex +++ b/lib/pleroma/emails/user_email.ex @@ -93,6 +93,19 @@ def account_confirmation_email(user) do |> html_body(html_body) end + def approval_pending_email(user) do + html_body = """ +

Awaiting Approval

+

Your account at #{instance_name()} is being reviewed by staff. You will receive another email once your account is approved.

+ """ + + new() + |> to(recipient(user)) + |> from(sender()) + |> subject("Your account is awaiting approval") + |> html_body(html_body) + end + @doc """ Email used in digest email notifications Includes Mentions and New Followers data @@ -106,7 +119,7 @@ def digest_email(user) do notifications |> Enum.filter(&(&1.activity.data["type"] == "Create")) |> Enum.map(fn notification -> - object = Pleroma.Object.normalize(notification.activity) + object = Pleroma.Object.normalize(notification.activity, fetch: false) if not is_nil(object) do object = update_in(object.data["content"], &format_links/1) @@ -129,7 +142,7 @@ def digest_email(user) do if not is_nil(from) do %{ data: notification, - object: Pleroma.Object.normalize(notification.activity), + object: Pleroma.Object.normalize(notification.activity, fetch: false), from: User.get_by_ap_id(notification.activity.actor) } end @@ -151,7 +164,7 @@ def digest_email(user) do logo_path = if is_nil(logo) do - Path.join(:code.priv_dir(:pleroma), "static/static/logo.png") + Path.join(:code.priv_dir(:pleroma), "static/static/logo.svg") else Path.join(Config.get([:instance, :static_dir]), logo) end @@ -162,7 +175,7 @@ def digest_email(user) do |> subject("Your digest from #{instance_name()}") |> put_layout(false) |> render_body("digest.html", html_data) - |> attachment(Swoosh.Attachment.new(logo_path, filename: "logo.png", type: :inline)) + |> attachment(Swoosh.Attachment.new(logo_path, filename: "logo.svg", type: :inline)) end end diff --git a/lib/pleroma/emoji/formatter.ex b/lib/pleroma/emoji/formatter.ex index dc45b8a38..992b20e12 100644 --- a/lib/pleroma/emoji/formatter.ex +++ b/lib/pleroma/emoji/formatter.ex @@ -5,6 +5,7 @@ defmodule Pleroma.Emoji.Formatter do alias Pleroma.Emoji alias Pleroma.HTML + alias Pleroma.Web alias Pleroma.Web.MediaProxy def emojify(text) do @@ -43,7 +44,7 @@ def get_emoji_map(text) when is_binary(text) do Emoji.get_all() |> Enum.filter(fn {emoji, %Emoji{}} -> String.contains?(text, ":#{emoji}:") end) |> Enum.reduce(%{}, fn {name, %Emoji{file: file}}, acc -> - Map.put(acc, name, "#{Pleroma.Web.Endpoint.static_url()}#{file}") + Map.put(acc, name, to_string(URI.merge(Web.base_url(), file))) end) end diff --git a/lib/pleroma/emoji/pack.ex b/lib/pleroma/emoji/pack.ex index ca58e5432..ec97aa652 100644 --- a/lib/pleroma/emoji/pack.ex +++ b/lib/pleroma/emoji/pack.ex @@ -20,16 +20,18 @@ defmodule Pleroma.Emoji.Pack do name: String.t() } + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + alias Pleroma.Emoji alias Pleroma.Emoji.Pack + alias Pleroma.Utils @spec create(String.t()) :: {:ok, t()} | {:error, File.posix()} | {:error, :empty_values} def create(name) do with :ok <- validate_not_empty([name]), dir <- Path.join(emoji_path(), name), :ok <- File.mkdir(dir) do - %__MODULE__{pack_file: Path.join(dir, "pack.json")} - |> save_pack() + save_pack(%__MODULE__{pack_file: Path.join(dir, "pack.json")}) end end @@ -62,10 +64,9 @@ def show(opts) do @spec delete(String.t()) :: {:ok, [binary()]} | {:error, File.posix(), binary()} | {:error, :empty_values} def delete(name) do - with :ok <- validate_not_empty([name]) do - emoji_path() - |> Path.join(name) - |> File.rm_rf() + with :ok <- validate_not_empty([name]), + pack_path <- Path.join(emoji_path(), name) do + File.rm_rf(pack_path) end end @@ -94,7 +95,7 @@ defp unpack_zip_emojies(zip_files) do def add_file(%Pack{} = pack, _, _, %Plug.Upload{content_type: "application/zip"} = file) do with {:ok, zip_files} <- :zip.table(to_charlist(file.path)), [_ | _] = emojies <- unpack_zip_emojies(zip_files), - {:ok, tmp_dir} <- Pleroma.Utils.tmp_dir("emoji") do + {:ok, tmp_dir} <- Utils.tmp_dir("emoji") do try do {:ok, _emoji_files} = :zip.unzip( @@ -282,18 +283,21 @@ def update_metadata(name, data) do end end - @spec load_pack(String.t()) :: {:ok, t()} | {:error, :not_found} + @spec load_pack(String.t()) :: {:ok, t()} | {:error, :file.posix()} def load_pack(name) do pack_file = Path.join([emoji_path(), name, "pack.json"]) - if File.exists?(pack_file) do + with {:ok, _} <- File.stat(pack_file), + {:ok, pack_data} <- File.read(pack_file) do pack = - pack_file - |> File.read!() - |> from_json() - |> Map.put(:pack_file, pack_file) - |> Map.put(:path, Path.dirname(pack_file)) - |> Map.put(:name, name) + from_json( + pack_data, + %{ + pack_file: pack_file, + path: Path.dirname(pack_file), + name: name + } + ) files_count = pack.files @@ -301,8 +305,6 @@ def load_pack(name) do |> length() {:ok, Map.put(pack, :files_count, files_count)} - else - {:error, :not_found} end end @@ -415,7 +417,7 @@ defp create_archive_and_cache(pack, hash) do ttl_per_file = Pleroma.Config.get!([:emoji, :shared_pack_cache_seconds_per_file]) overall_ttl = :timer.seconds(ttl_per_file * Enum.count(files)) - Cachex.put!( + @cachex.put( :emoji_packs_cache, pack.name, # if pack.json MD5 changes, the cache is not valid anymore @@ -434,10 +436,17 @@ defp save_pack(pack) do end end - defp from_json(json) do + defp from_json(json, attrs) do map = Jason.decode!(json) - struct(__MODULE__, %{files: map["files"], pack: map["pack"]}) + pack_attrs = + attrs + |> Map.merge(%{ + files: map["files"], + pack: map["pack"] + }) + + struct(__MODULE__, pack_attrs) end defp validate_shareable_packs_available(uri) do @@ -491,10 +500,10 @@ defp rename_file(pack, filename, new_filename) do end defp create_subdirs(file_path) do - if String.contains?(file_path, "/") do - file_path - |> Path.dirname() - |> File.mkdir_p!() + with true <- String.contains?(file_path, "/"), + path <- Path.dirname(file_path), + false <- File.exists?(path) do + File.mkdir_p!(path) end end @@ -518,10 +527,15 @@ defp remove_dir_if_empty(emoji, filename) do defp get_filename(pack, shortcode) do with %{^shortcode => filename} when is_binary(filename) <- pack.files, - true <- pack.path |> Path.join(filename) |> File.exists?() do + file_path <- Path.join(pack.path, filename), + {:ok, _} <- File.stat(file_path) do {:ok, filename} else - _ -> {:error, :doesnt_exist} + {:error, _} = error -> + error + + _ -> + {:error, :doesnt_exist} end end @@ -606,7 +620,7 @@ defp download_archive(url, sha) do defp fetch_archive(pack) do hash = :crypto.hash(:md5, File.read!(pack.pack_file)) - case Cachex.get!(:emoji_packs_cache, pack.name) do + case @cachex.get!(:emoji_packs_cache, pack.name) do %{hash: ^hash, pack_data: archive} -> archive _ -> create_archive_and_cache(pack, hash) end diff --git a/lib/pleroma/gopher/server.ex b/lib/pleroma/gopher/server.ex index e9f54c4c0..8ac8d18c1 100644 --- a/lib/pleroma/gopher/server.ex +++ b/lib/pleroma/gopher/server.ex @@ -76,7 +76,7 @@ def render_activities(activities) do |> Enum.map(fn activity -> user = User.get_cached_by_ap_id(activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) like_count = object.data["like_count"] || 0 announcement_count = object.data["announcement_count"] || 0 diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex index 43e9145be..c5ece7350 100644 --- a/lib/pleroma/html.ex +++ b/lib/pleroma/html.ex @@ -6,6 +6,8 @@ defmodule Pleroma.HTML do # Scrubbers are compiled on boot so they can be configured in OTP releases # @on_load :compile_scrubbers + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + def compile_scrubbers do dir = Path.join(:code.priv_dir(:pleroma), "scrubbers") @@ -56,8 +58,8 @@ def get_cached_scrubbed_html_for_activity( ) do key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}" - Cachex.fetch!(:scrubber_cache, key, fn _key -> - object = Pleroma.Object.normalize(activity) + @cachex.fetch!(:scrubber_cache, key, fn _key -> + object = Pleroma.Object.normalize(activity, fetch: false) ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback) end) end @@ -105,7 +107,7 @@ def extract_first_external_url_from_object(%{data: %{"content" => content}} = ob unless object.data["fake"] do key = "URL|#{object.id}" - Cachex.fetch!(:scrubber_cache, key, fn _key -> + @cachex.fetch!(:scrubber_cache, key, fn _key -> {:commit, {:ok, extract_first_external_url(content)}} end) else diff --git a/lib/jason_types.ex b/lib/pleroma/logging.ex similarity index 59% rename from lib/jason_types.ex rename to lib/pleroma/logging.ex index f1fdc96f4..37b201c29 100644 --- a/lib/jason_types.ex +++ b/lib/pleroma/logging.ex @@ -2,8 +2,6 @@ # Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only -Postgrex.Types.define( - Pleroma.PostgresTypes, - [] ++ Ecto.Adapters.Postgres.extensions(), - json: Jason -) +defmodule Pleroma.Logging do + @callback error(String.t()) :: any() +end diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index dd7a1c824..4efea9f7d 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -358,7 +358,7 @@ def dismiss(%{id: user_id} = _user, id) do def create_notifications(activity, options \\ []) def create_notifications(%Activity{data: %{"to" => _, "type" => "Create"}} = activity, options) do - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) if object && object.data["type"] == "Answer" do {:ok, []} @@ -625,7 +625,7 @@ def skip?(:recently_followed, %Activity{data: %{"type" => "Follow"}} = activity, def skip?(:filtered, %{data: %{"type" => type}}, _) when type in ["Follow", "Move"], do: false def skip?(:filtered, activity, user) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) cond do is_nil(object) -> diff --git a/lib/pleroma/object.ex b/lib/pleroma/object.ex index 052ad413b..4fb4ec364 100644 --- a/lib/pleroma/object.ex +++ b/lib/pleroma/object.ex @@ -23,6 +23,8 @@ defmodule Pleroma.Object do @derive {Jason.Encoder, only: [:data]} + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + schema "objects" do field(:data, :map) @@ -106,39 +108,42 @@ defp warn_on_no_object_preloaded(ap_id) do Logger.debug("Backtrace: #{inspect(Process.info(:erlang.self(), :current_stacktrace))}") end - def normalize(_, fetch_remote \\ true, options \\ []) + def normalize(_, options \\ [fetch: false]) # If we pass an Activity to Object.normalize(), we can try to use the preloaded object. # Use this whenever possible, especially when walking graphs in an O(N) loop! - def normalize(%Object{} = object, _, _), do: object - def normalize(%Activity{object: %Object{} = object}, _, _), do: object + def normalize(%Object{} = object, _), do: object + def normalize(%Activity{object: %Object{} = object}, _), do: object # A hack for fake activities - def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}, _, _) do + def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}, _) do %Object{id: "pleroma:fake_object_id", data: data} end # No preloaded object - def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}, fetch_remote, _) do + def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}, options) do warn_on_no_object_preloaded(ap_id) - normalize(ap_id, fetch_remote) + normalize(ap_id, options) end # No preloaded object - def normalize(%Activity{data: %{"object" => ap_id}}, fetch_remote, _) do + def normalize(%Activity{data: %{"object" => ap_id}}, options) do warn_on_no_object_preloaded(ap_id) - normalize(ap_id, fetch_remote) + normalize(ap_id, options) end # Old way, try fetching the object through cache. - def normalize(%{"id" => ap_id}, fetch_remote, _), do: normalize(ap_id, fetch_remote) - def normalize(ap_id, false, _) when is_binary(ap_id), do: get_cached_by_ap_id(ap_id) + def normalize(%{"id" => ap_id}, options), do: normalize(ap_id, options) - def normalize(ap_id, true, options) when is_binary(ap_id) do - Fetcher.fetch_object_from_id!(ap_id, options) + def normalize(ap_id, options) when is_binary(ap_id) do + if Keyword.get(options, :fetch) do + Fetcher.fetch_object_from_id!(ap_id, options) + else + get_cached_by_ap_id(ap_id) + end end - def normalize(_, _, _), do: nil + def normalize(_, _), do: nil # Owned objects can only be accessed by their owner def authorize_access(%Object{data: %{"actor" => actor}}, %User{ap_id: ap_id}) do @@ -156,9 +161,9 @@ def authorize_access(%Object{}, %User{}), do: :ok def get_cached_by_ap_id(ap_id) do key = "object:#{ap_id}" - with {:ok, nil} <- Cachex.get(:object_cache, key), + with {:ok, nil} <- @cachex.get(:object_cache, key), object when not is_nil(object) <- get_by_ap_id(ap_id), - {:ok, true} <- Cachex.put(:object_cache, key, object) do + {:ok, true} <- @cachex.put(:object_cache, key, object) do object else {:ok, object} -> object @@ -216,13 +221,13 @@ def prune(%Object{data: %{"id" => _id}} = object) do end def invalid_object_cache(%Object{data: %{"id" => id}}) do - with {:ok, true} <- Cachex.del(:object_cache, "object:#{id}") do - Cachex.del(:web_resp_cache, URI.parse(id).path) + with {:ok, true} <- @cachex.del(:object_cache, "object:#{id}") do + @cachex.del(:web_resp_cache, URI.parse(id).path) end end def set_cache(%Object{data: %{"id" => ap_id}} = object) do - Cachex.put(:object_cache, "object:#{ap_id}", object) + @cachex.put(:object_cache, "object:#{ap_id}", object) {:ok, object} end @@ -283,7 +288,7 @@ def decrease_replies_count(ap_id) do end def increase_vote_count(ap_id, name, actor) do - with %Object{} = object <- Object.normalize(ap_id), + with %Object{} = object <- Object.normalize(ap_id, fetch: false), "Question" <- object.data["type"] do key = if poll_is_multiple?(object), do: "anyOf", else: "oneOf" @@ -324,7 +329,7 @@ def local?(%Object{data: %{"id" => id}}) do end def replies(object, opts \\ []) do - object = Object.normalize(object) + object = Object.normalize(object, fetch: false) query = Object diff --git a/lib/pleroma/object/fetcher.ex b/lib/pleroma/object/fetcher.ex index 20d8f687d..18c383881 100644 --- a/lib/pleroma/object/fetcher.ex +++ b/lib/pleroma/object/fetcher.ex @@ -83,13 +83,13 @@ def fetch_object_from_id(id, options \\ []) do with {_, nil} <- {:fetch_object, Object.get_cached_by_ap_id(id)}, {_, true} <- {:allowed_depth, Federator.allowed_thread_distance?(options[:depth])}, {_, {:ok, data}} <- {:fetch, fetch_and_contain_remote_object_from_id(id)}, - {_, nil} <- {:normalize, Object.normalize(data, false)}, + {_, nil} <- {:normalize, Object.normalize(data, fetch: false)}, params <- prepare_activity_params(data), {_, :ok} <- {:containment, Containment.contain_origin(id, params)}, {_, {:ok, activity}} <- {:transmogrifier, Transmogrifier.handle_incoming(params, options)}, {_, _data, %Object{} = object} <- - {:object, data, Object.normalize(activity, false)} do + {:object, data, Object.normalize(activity, fetch: false)} do {:ok, object} else {:allowed_depth, false} -> diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index 8ae1157df..3ea897c95 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -17,6 +17,8 @@ defmodule Pleroma.ReverseProxy do @failed_request_ttl :timer.seconds(60) @methods ~w(GET HEAD) + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + def max_read_duration_default, do: @max_read_duration def default_cache_control_header, do: @default_cache_control_header @@ -107,7 +109,7 @@ def call(conn = %{method: method}, url, opts) when method in @methods do opts end - with {:ok, nil} <- Cachex.get(:failed_proxy_url_cache, url), + with {:ok, nil} <- @cachex.get(:failed_proxy_url_cache, url), {:ok, code, headers, client} <- request(method, url, req_headers, client_opts), :ok <- header_length_constraint( @@ -427,6 +429,6 @@ defp track_failed_url(url, error, opts) do nil end - Cachex.put(:failed_proxy_url_cache, url, true, ttl: ttl) + @cachex.put(:failed_proxy_url_cache, url, true, ttl: ttl) end end diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1836643a6..52730fd8d 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -81,6 +81,8 @@ defmodule Pleroma.User do ] ] + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + schema "users" do field(:bio, :string, default: "") field(:raw_bio, :string) @@ -140,7 +142,7 @@ defmodule Pleroma.User do field(:allow_following_move, :boolean, default: true) field(:skip_thread_containment, :boolean, default: false) field(:actor_type, :string, default: "Person") - field(:also_known_as, {:array, :string}, default: []) + field(:also_known_as, {:array, ObjectValidators.ObjectID}, default: []) field(:inbox, :string) field(:shared_inbox, :string) field(:accepts_chat_messages, :boolean, default: nil) @@ -246,13 +248,13 @@ def unquote(:"#{outgoing_relation_target}_ap_ids")(user, restrict_deactivated? \ end def cached_blocked_users_ap_ids(user) do - Cachex.fetch!(:user_cache, "blocked_users_ap_ids:#{user.ap_id}", fn _ -> + @cachex.fetch!(:user_cache, "blocked_users_ap_ids:#{user.ap_id}", fn _ -> blocked_users_ap_ids(user) end) end def cached_muted_users_ap_ids(user) do - Cachex.fetch!(:user_cache, "muted_users_ap_ids:#{user.ap_id}", fn _ -> + @cachex.fetch!(:user_cache, "muted_users_ap_ids:#{user.ap_id}", fn _ -> muted_users_ap_ids(user) end) end @@ -513,6 +515,7 @@ def update_changeset(struct, params \\ %{}) do :hide_follows_count, :hide_favorites, :allow_following_move, + :also_known_as, :background, :show_role, :skip_thread_containment, @@ -521,7 +524,6 @@ def update_changeset(struct, params \\ %{}) do :pleroma_settings_store, :is_discoverable, :actor_type, - :also_known_as, :accepts_chat_messages ] ) @@ -806,18 +808,50 @@ def register(%Ecto.Changeset{} = changeset) do end end - def post_register_action(%User{} = user) do + def post_register_action(%User{confirmation_pending: true} = user) do + with {:ok, _} <- try_send_confirmation_email(user) do + {:ok, user} + end + end + + def post_register_action(%User{approval_pending: true} = user) do + with {:ok, _} <- send_user_approval_email(user), + {:ok, _} <- send_admin_approval_emails(user) do + {:ok, user} + end + end + + def post_register_action(%User{approval_pending: false, confirmation_pending: false} = user) do with {:ok, user} <- autofollow_users(user), {:ok, _} <- autofollowing_users(user), {:ok, user} <- set_cache(user), {:ok, _} <- send_welcome_email(user), {:ok, _} <- send_welcome_message(user), - {:ok, _} <- send_welcome_chat_message(user), - {:ok, _} <- try_send_confirmation_email(user) do + {:ok, _} <- send_welcome_chat_message(user) do {:ok, user} end end + defp send_user_approval_email(user) do + user + |> Pleroma.Emails.UserEmail.approval_pending_email() + |> Pleroma.Emails.Mailer.deliver_async() + + {:ok, :enqueued} + end + + defp send_admin_approval_emails(user) do + all_superusers() + |> Enum.filter(fn user -> not is_nil(user.email) end) + |> Enum.each(fn superuser -> + superuser + |> Pleroma.Emails.AdminEmail.new_unapproved_registration(user) + |> Pleroma.Emails.Mailer.deliver_async() + end) + + {:ok, :enqueued} + end + def send_welcome_message(user) do if User.WelcomeMessage.enabled?() do User.WelcomeMessage.post_message(user) @@ -1016,9 +1050,9 @@ def set_cache({:ok, user}), do: set_cache(user) def set_cache({:error, err}), do: {:error, err} def set_cache(%User{} = user) do - Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) - Cachex.put(:user_cache, "nickname:#{user.nickname}", user) - Cachex.put(:user_cache, "friends_ap_ids:#{user.nickname}", get_user_friends_ap_ids(user)) + @cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) + @cachex.put(:user_cache, "nickname:#{user.nickname}", user) + @cachex.put(:user_cache, "friends_ap_ids:#{user.nickname}", get_user_friends_ap_ids(user)) {:ok, user} end @@ -1041,26 +1075,26 @@ def get_user_friends_ap_ids(user) do @spec get_cached_user_friends_ap_ids(User.t()) :: [String.t()] def get_cached_user_friends_ap_ids(user) do - Cachex.fetch!(:user_cache, "friends_ap_ids:#{user.ap_id}", fn _ -> + @cachex.fetch!(:user_cache, "friends_ap_ids:#{user.ap_id}", fn _ -> get_user_friends_ap_ids(user) end) end def invalidate_cache(user) do - Cachex.del(:user_cache, "ap_id:#{user.ap_id}") - Cachex.del(:user_cache, "nickname:#{user.nickname}") - Cachex.del(:user_cache, "friends_ap_ids:#{user.ap_id}") - Cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}") - Cachex.del(:user_cache, "muted_users_ap_ids:#{user.ap_id}") + @cachex.del(:user_cache, "ap_id:#{user.ap_id}") + @cachex.del(:user_cache, "nickname:#{user.nickname}") + @cachex.del(:user_cache, "friends_ap_ids:#{user.ap_id}") + @cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}") + @cachex.del(:user_cache, "muted_users_ap_ids:#{user.ap_id}") end @spec get_cached_by_ap_id(String.t()) :: User.t() | nil def get_cached_by_ap_id(ap_id) do key = "ap_id:#{ap_id}" - with {:ok, nil} <- Cachex.get(:user_cache, key), + with {:ok, nil} <- @cachex.get(:user_cache, key), user when not is_nil(user) <- get_by_ap_id(ap_id), - {:ok, true} <- Cachex.put(:user_cache, key, user) do + {:ok, true} <- @cachex.put(:user_cache, key, user) do user else {:ok, user} -> user @@ -1072,11 +1106,11 @@ def get_cached_by_id(id) do key = "id:#{id}" ap_id = - Cachex.fetch!(:user_cache, key, fn _ -> + @cachex.fetch!(:user_cache, key, fn _ -> user = get_by_id(id) if user do - Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) + @cachex.put(:user_cache, "ap_id:#{user.ap_id}", user) {:commit, user.ap_id} else {:ignore, ""} @@ -1089,7 +1123,7 @@ def get_cached_by_id(id) do def get_cached_by_nickname(nickname) do key = "nickname:#{nickname}" - Cachex.fetch!(:user_cache, key, fn -> + @cachex.fetch!(:user_cache, key, fn _ -> case get_or_fetch_by_nickname(nickname) do {:ok, user} -> {:commit, user} {:error, _error} -> {:ignore, nil} @@ -1358,7 +1392,7 @@ def mute(%User{} = muter, %User{} = mutee, params \\ %{}) do ) end - Cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}") + @cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}") {:ok, Enum.filter([user_mute, user_notification_mute], & &1)} end @@ -1368,7 +1402,7 @@ def unmute(%User{} = muter, %User{} = mutee) do with {:ok, user_mute} <- UserRelationship.delete_mute(muter, mutee), {:ok, user_notification_mute} <- UserRelationship.delete_notification_mute(muter, mutee) do - Cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}") + @cachex.del(:user_cache, "muted_users_ap_ids:#{muter.ap_id}") {:ok, [user_mute, user_notification_mute]} end end @@ -1590,11 +1624,34 @@ def approve(users) when is_list(users) do end) end - def approve(%User{} = user) do - change(user, approval_pending: false) - |> update_and_set_cache() + def approve(%User{approval_pending: true} = user) do + with chg <- change(user, approval_pending: false), + {:ok, user} <- update_and_set_cache(chg) do + post_register_action(user) + {:ok, user} + end end + def approve(%User{} = user), do: {:ok, user} + + def confirm(users) when is_list(users) do + Repo.transaction(fn -> + Enum.map(users, fn user -> + with {:ok, user} <- confirm(user), do: user + end) + end) + end + + def confirm(%User{confirmation_pending: true} = user) do + with chg <- confirmation_changeset(user, need_confirmation: false), + {:ok, user} <- update_and_set_cache(chg) do + post_register_action(user) + {:ok, user} + end + end + + def confirm(%User{} = user), do: {:ok, user} + def update_notification_settings(%User{} = user, settings) do user |> cast(%{notification_settings: settings}, []) @@ -2081,18 +2138,6 @@ def touch_last_digest_emailed_at(user) do updated_user end - @spec toggle_confirmation(User.t()) :: {:ok, User.t()} | {:error, Changeset.t()} - def toggle_confirmation(%User{} = user) do - user - |> confirmation_changeset(need_confirmation: !user.confirmation_pending) - |> update_and_set_cache() - end - - @spec toggle_confirmation([User.t()]) :: [{:ok, User.t()} | {:error, Changeset.t()}] - def toggle_confirmation(users) do - Enum.map(users, &toggle_confirmation/1) - end - @spec need_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} def need_confirmation(%User{} = user, bool) do user @@ -2365,7 +2410,7 @@ def unblock_domain(user, domain_blocked) do {:ok, UserRelationship.t()} | {:error, Ecto.Changeset.t()} defp add_to_block(%User{} = user, %User{} = blocked) do with {:ok, relationship} <- UserRelationship.create_block(user, blocked) do - Cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}") + @cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}") {:ok, relationship} end end @@ -2374,7 +2419,7 @@ defp add_to_block(%User{} = user, %User{} = blocked) do {:ok, UserRelationship.t()} | {:ok, nil} | {:error, Ecto.Changeset.t()} defp remove_from_block(%User{} = user, %User{} = blocked) do with {:ok, relationship} <- UserRelationship.delete_block(user, blocked) do - Cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}") + @cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}") {:ok, relationship} end end diff --git a/lib/pleroma/utils.ex b/lib/pleroma/utils.ex index e95766223..fa75a8c99 100644 --- a/lib/pleroma/utils.ex +++ b/lib/pleroma/utils.ex @@ -3,6 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Utils do + @posix_error_codes ~w( + eacces eagain ebadf ebadmsg ebusy edeadlk edeadlock edquot eexist efault + efbig eftype eintr einval eio eisdir eloop emfile emlink emultihop + enametoolong enfile enobufs enodev enolck enolink enoent enomem enospc + enosr enostr enosys enotblk enotdir enotsup enxio eopnotsupp eoverflow + eperm epipe erange erofs espipe esrch estale etxtbsy exdev + )a + def compile_dir(dir) when is_binary(dir) do dir |> File.ls!() @@ -44,4 +52,12 @@ def tmp_dir(prefix \\ "") do error -> error end end + + @spec posix_error_message(atom()) :: binary() + def posix_error_message(code) when code in @posix_error_codes do + error_message = Gettext.dgettext(Pleroma.Web.Gettext, "posix_errors", "#{code}") + "(POSIX error: #{error_message})" + end + + def posix_error_message(_), do: "" end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 1c91bc074..8c2610eeb 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -32,6 +32,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do require Logger require Pleroma.Constants + @behaviour Pleroma.Web.ActivityPub.ActivityPub.Persisting + @behaviour Pleroma.Web.ActivityPub.ActivityPub.Streaming + defp get_recipients(%{"type" => "Create"} = data) do to = Map.get(data, "to", []) cc = Map.get(data, "cc", []) @@ -85,13 +88,14 @@ defp increase_replies_count_if_reply(%{ defp increase_replies_count_if_reply(_create_data), do: :noop @object_types ~w[ChatMessage Question Answer Audio Video Event Article] - @spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()} + @impl true def persist(%{"type" => type} = object, meta) when type in @object_types do with {:ok, object} <- Object.create(object) do {:ok, object, meta} end end + @impl true def persist(object, meta) do with local <- Keyword.fetch!(meta, :local), {recipients, _, _} <- get_recipients(object), @@ -221,6 +225,7 @@ def stream_out_participations(participations) do Streamer.stream("participation", participations) end + @impl true def stream_out_participations(%Object{data: %{"context" => context}}, user) do with %Conversation{} = conversation <- Conversation.get_for_ap_id(context) do conversation = Repo.preload(conversation, :participations) @@ -237,8 +242,10 @@ def stream_out_participations(%Object{data: %{"context" => context}}, user) do end end + @impl true def stream_out_participations(_, _), do: :noop + @impl true def stream_out(%Activity{data: %{"type" => data_type}} = activity) when data_type in ["Create", "Announce", "Delete"] do activity @@ -246,6 +253,7 @@ def stream_out(%Activity{data: %{"type" => data_type}} = activity) |> Streamer.stream(activity) end + @impl true def stream_out(_activity) do :noop end @@ -600,12 +608,14 @@ def fetch_user_activities(user, reading_user, params \\ %{}) do |> Map.put(:muting_user, reading_user) end + pagination_type = Map.get(params, :pagination_type) || :keyset + %{ godmode: params[:godmode], reading_user: reading_user } |> user_activities_recipients() - |> fetch_activities(params) + |> fetch_activities(params, pagination_type) |> Enum.reverse() end diff --git a/lib/pleroma/web/activity_pub/activity_pub/persisting.ex b/lib/pleroma/web/activity_pub/activity_pub/persisting.ex new file mode 100644 index 000000000..3894f48e2 --- /dev/null +++ b/lib/pleroma/web/activity_pub/activity_pub/persisting.ex @@ -0,0 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ActivityPub.Persisting do + @callback persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()} +end diff --git a/lib/pleroma/web/activity_pub/activity_pub/streaming.ex b/lib/pleroma/web/activity_pub/activity_pub/streaming.ex new file mode 100644 index 000000000..30009f2fb --- /dev/null +++ b/lib/pleroma/web/activity_pub/activity_pub/streaming.ex @@ -0,0 +1,12 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ActivityPub.Streaming do + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.User + + @callback stream_out(Activity.t()) :: any() + @callback stream_out_participations(Object.t(), User.t()) :: any() +end diff --git a/lib/pleroma/web/activity_pub/activity_pub_controller.ex b/lib/pleroma/web/activity_pub/activity_pub_controller.ex index 7e5647f8f..8d9b69cc7 100644 --- a/lib/pleroma/web/activity_pub/activity_pub_controller.ex +++ b/lib/pleroma/web/activity_pub/activity_pub_controller.ex @@ -128,7 +128,7 @@ def activity(conn, _params) do end defp maybe_set_tracking_data(conn, %Activity{data: %{"type" => "Create"}} = activity) do - object_id = Object.normalize(activity).id + object_id = Object.normalize(activity, fetch: false).id assign(conn, :tracking_fun_data, object_id) end @@ -434,7 +434,7 @@ defp handle_user_activity( end defp handle_user_activity(%User{} = user, %{"type" => "Delete"} = params) do - with %Object{} = object <- Object.normalize(params["object"]), + with %Object{} = object <- Object.normalize(params["object"], fetch: false), true <- user.is_moderator || user.ap_id == object.data["actor"], {:ok, delete_data, _} <- Builder.delete(user, object.data["id"]), {:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do @@ -445,7 +445,7 @@ defp handle_user_activity(%User{} = user, %{"type" => "Delete"} = params) do end defp handle_user_activity(%User{} = user, %{"type" => "Like"} = params) do - with %Object{} = object <- Object.normalize(params["object"]), + with %Object{} = object <- Object.normalize(params["object"], fetch: false), {_, {:ok, like_object, meta}} <- {:build_object, Builder.like(user, object)}, {_, {:ok, %Activity{} = activity, _meta}} <- {:common_pipeline, diff --git a/lib/pleroma/web/activity_pub/builder.ex b/lib/pleroma/web/activity_pub/builder.ex index e99f6fd83..74ddc2506 100644 --- a/lib/pleroma/web/activity_pub/builder.ex +++ b/lib/pleroma/web/activity_pub/builder.ex @@ -80,7 +80,7 @@ def undo(actor, object) do @spec delete(User.t(), String.t()) :: {:ok, map(), keyword()} def delete(actor, object_id) do - object = Object.normalize(object_id, false) + object = Object.normalize(object_id, fetch: false) user = !object && User.get_cached_by_ap_id(object_id) diff --git a/lib/pleroma/web/activity_pub/mrf.ex b/lib/pleroma/web/activity_pub/mrf.ex index a7c5d5510..6443b0009 100644 --- a/lib/pleroma/web/activity_pub/mrf.ex +++ b/lib/pleroma/web/activity_pub/mrf.ex @@ -5,6 +5,8 @@ defmodule Pleroma.Web.ActivityPub.MRF do require Logger + @behaviour Pleroma.Web.ActivityPub.MRF.PipelineFiltering + @mrf_config_descriptions [ %{ group: :pleroma, @@ -72,6 +74,7 @@ def filter(policies, %{} = message) do def filter(%{} = object), do: get_policies() |> filter(object) + @impl true def pipeline_filter(%{} = message, meta) do object = meta[:object_data] ap_id = message["object"] diff --git a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex index 3bf70b894..c8c40c702 100644 --- a/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex +++ b/lib/pleroma/web/activity_pub/mrf/ensure_re_prepended.ex @@ -31,7 +31,7 @@ def filter(%{"type" => "Create", "object" => child_object} = object) when is_map(child_object) do child = child_object["inReplyTo"] - |> Object.normalize(child_object["inReplyTo"]) + |> Object.normalize(fetch: false) |> filter_by_summary(child_object) object = Map.put(object, "object", child) diff --git a/lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex b/lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex new file mode 100644 index 000000000..8e0069bc5 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/pipeline_filtering.ex @@ -0,0 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.PipelineFiltering do + @callback pipeline_filter(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()} +end diff --git a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex index 2858af9eb..788f21261 100644 --- a/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/steal_emoji_policy.ex @@ -10,73 +10,75 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do @moduledoc "Detect new emojis by their shortcode and steals them" @behaviour Pleroma.Web.ActivityPub.MRF - defp remote_host?(host), do: host != Config.get([Pleroma.Web.Endpoint, :url, :host]) - defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], []) - defp steal_emoji({shortcode, url}) do + defp steal_emoji({shortcode, url}, emoji_dir_path) do url = Pleroma.Web.MediaProxy.url(url) - {:ok, response} = Pleroma.HTTP.get(url) - size_limit = Config.get([:mrf_steal_emoji, :size_limit], 50_000) - if byte_size(response.body) <= size_limit do - emoji_dir_path = - Config.get( - [:mrf_steal_emoji, :path], - Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") + with {:ok, %{status: status} = response} when status in 200..299 <- Pleroma.HTTP.get(url) do + size_limit = Config.get([:mrf_steal_emoji, :size_limit], 50_000) + + if byte_size(response.body) <= size_limit do + extension = + url + |> URI.parse() + |> Map.get(:path) + |> Path.basename() + |> Path.extname() + + file_path = Path.join(emoji_dir_path, shortcode <> (extension || ".png")) + + case File.write(file_path, response.body) do + :ok -> + shortcode + + e -> + Logger.warn("MRF.StealEmojiPolicy: Failed to write to #{file_path}: #{inspect(e)}") + nil + end + else + Logger.debug( + "MRF.StealEmojiPolicy: :#{shortcode}: at #{url} (#{byte_size(response.body)} B) over size limit (#{ + size_limit + } B)" ) - extension = - url - |> URI.parse() - |> Map.get(:path) - |> Path.basename() - |> Path.extname() - - file_path = Path.join([emoji_dir_path, shortcode <> (extension || ".png")]) - - try do - :ok = File.write(file_path, response.body) - - shortcode - rescue - e -> - Logger.warn("MRF.StealEmojiPolicy: Failed to write to #{file_path}: #{inspect(e)}") - nil + nil end else - Logger.debug( - "MRF.StealEmojiPolicy: :#{shortcode}: at #{url} (#{byte_size(response.body)} B) over size limit (#{ - size_limit - } B)" - ) - - nil + e -> + Logger.warn("MRF.StealEmojiPolicy: Failed to fetch #{url}: #{inspect(e)}") + nil end - rescue - e -> - Logger.warn("MRF.StealEmojiPolicy: Failed to fetch #{url}: #{inspect(e)}") - nil end @impl true def filter(%{"object" => %{"emoji" => foreign_emojis, "actor" => actor}} = message) do host = URI.parse(actor).host - if remote_host?(host) and accept_host?(host) do + if host != Pleroma.Web.Endpoint.host() and accept_host?(host) do installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) + emoji_dir_path = + Config.get( + [:mrf_steal_emoji, :path], + Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") + ) + + File.mkdir_p(emoji_dir_path) + new_emojis = foreign_emojis - |> Enum.filter(fn {shortcode, _url} -> shortcode not in installed_emoji end) + |> Enum.reject(fn {shortcode, _url} -> shortcode in installed_emoji end) |> Enum.filter(fn {shortcode, _url} -> reject_emoji? = - Config.get([:mrf_steal_emoji, :rejected_shortcodes], []) + [:mrf_steal_emoji, :rejected_shortcodes] + |> Config.get([]) |> Enum.find(false, fn regex -> String.match?(shortcode, regex) end) !reject_emoji? end) - |> Enum.map(&steal_emoji(&1)) + |> Enum.map(&steal_emoji(&1, emoji_dir_path)) |> Enum.filter(& &1) if !Enum.empty?(new_emojis) do diff --git a/lib/pleroma/web/activity_pub/object_validator.ex b/lib/pleroma/web/activity_pub/object_validator.ex index bd0a2a8dc..244753c02 100644 --- a/lib/pleroma/web/activity_pub/object_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validator.ex @@ -9,6 +9,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do the system. """ + @behaviour Pleroma.Web.ActivityPub.ObjectValidator.Validating + alias Pleroma.Activity alias Pleroma.EctoType.ActivityPub.ObjectValidators alias Pleroma.Object @@ -32,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidator do alias Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator alias Pleroma.Web.ActivityPub.ObjectValidators.UpdateValidator - @spec validate(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()} + @impl true def validate(object, meta) def validate(%{"type" => type} = object, meta) @@ -286,7 +288,7 @@ def fetch_actor(object) do def fetch_actor_and_object(object) do fetch_actor(object) - Object.normalize(object["object"], true) + Object.normalize(object["object"], fetch: true) :ok end end diff --git a/lib/pleroma/web/activity_pub/object_validator/validating.ex b/lib/pleroma/web/activity_pub/object_validator/validating.ex new file mode 100644 index 000000000..64c0c30c5 --- /dev/null +++ b/lib/pleroma/web/activity_pub/object_validator/validating.ex @@ -0,0 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ObjectValidator.Validating do + @callback validate(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()} +end diff --git a/lib/pleroma/web/activity_pub/pipeline.ex b/lib/pleroma/web/activity_pub/pipeline.ex index 98c32a42b..2715b94d4 100644 --- a/lib/pleroma/web/activity_pub/pipeline.ex +++ b/lib/pleroma/web/activity_pub/pipeline.ex @@ -14,12 +14,19 @@ defmodule Pleroma.Web.ActivityPub.Pipeline do alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.Federator + @side_effects Config.get([:pipeline, :side_effects], SideEffects) + @federator Config.get([:pipeline, :federator], Federator) + @object_validator Config.get([:pipeline, :object_validator], ObjectValidator) + @mrf Config.get([:pipeline, :mrf], MRF) + @activity_pub Config.get([:pipeline, :activity_pub], ActivityPub) + @config Config.get([:pipeline, :config], Config) + @spec common_pipeline(map(), keyword()) :: {:ok, Activity.t() | Object.t(), keyword()} | {:error, any()} def common_pipeline(object, meta) do case Repo.transaction(fn -> do_common_pipeline(object, meta) end) do {:ok, {:ok, activity, meta}} -> - SideEffects.handle_after_transaction(meta) + @side_effects.handle_after_transaction(meta) {:ok, activity, meta} {:ok, value} -> @@ -35,13 +42,13 @@ def common_pipeline(object, meta) do def do_common_pipeline(object, meta) do with {_, {:ok, validated_object, meta}} <- - {:validate_object, ObjectValidator.validate(object, meta)}, + {:validate_object, @object_validator.validate(object, meta)}, {_, {:ok, mrfd_object, meta}} <- - {:mrf_object, MRF.pipeline_filter(validated_object, meta)}, + {:mrf_object, @mrf.pipeline_filter(validated_object, meta)}, {_, {:ok, activity, meta}} <- - {:persist_object, ActivityPub.persist(mrfd_object, meta)}, + {:persist_object, @activity_pub.persist(mrfd_object, meta)}, {_, {:ok, activity, meta}} <- - {:execute_side_effects, SideEffects.handle(activity, meta)}, + {:execute_side_effects, @side_effects.handle(activity, meta)}, {_, {:ok, _}} <- {:federation, maybe_federate(activity, meta)} do {:ok, activity, meta} else @@ -54,7 +61,7 @@ defp maybe_federate(%Object{}, _), do: {:ok, :not_federated} defp maybe_federate(%Activity{} = activity, meta) do with {:ok, local} <- Keyword.fetch(meta, :local) do - do_not_federate = meta[:do_not_federate] || !Config.get([:instance, :federating]) + do_not_federate = meta[:do_not_federate] || !@config.get([:instance, :federating]) if !do_not_federate and local and not Visibility.is_local_public?(activity) do activity = @@ -64,7 +71,7 @@ defp maybe_federate(%Activity{} = activity, meta) do activity end - Federator.publish(activity) + @federator.publish(activity) {:ok, :federated} else {:ok, :not_federated} diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index f700c80bc..1f530e655 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -130,7 +130,7 @@ defp recipients(actor, activity) do fetchers = with %Activity{data: %{"type" => "Delete"}} <- activity, - %Object{id: object_id} <- Object.normalize(activity), + %Object{id: object_id} <- Object.normalize(activity, fetch: false), fetchers <- User.get_delivered_users_by_object_id(object_id), _ <- Delivery.delete_all_by_object_id(object_id) do fetchers diff --git a/lib/pleroma/web/activity_pub/side_effects.ex b/lib/pleroma/web/activity_pub/side_effects.ex index 8556fca1d..76287f274 100644 --- a/lib/pleroma/web/activity_pub/side_effects.ex +++ b/lib/pleroma/web/activity_pub/side_effects.ex @@ -27,11 +27,19 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do require Logger + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @ap_streamer Pleroma.Config.get([:side_effects, :ap_streamer], ActivityPub) + @logger Pleroma.Config.get([:side_effects, :logger], Logger) + + @behaviour Pleroma.Web.ActivityPub.SideEffects.Handling + + @impl true def handle(object, meta \\ []) # Task this handles # - Follows # - Sends a notification + @impl true def handle( %{ data: %{ @@ -59,6 +67,7 @@ def handle( # - Rejects all existing follow activities for this person # - Updates the follow state # - Dismisses notification + @impl true def handle( %{ data: %{ @@ -85,6 +94,7 @@ def handle( # - Follows if possible # - Sends a notification # - Generates accept or reject if appropriate + @impl true def handle( %{ data: %{ @@ -126,6 +136,7 @@ def handle( # Tasks this handles: # - Unfollow and block + @impl true def handle( %{data: %{"type" => "Block", "object" => blocked_user, "actor" => blocking_user}} = object, @@ -144,6 +155,7 @@ def handle( # # For a local user, we also get a changeset with the full information, so we # can update non-federating, non-activitypub settings as well. + @impl true def handle(%{data: %{"type" => "Update", "object" => updated_object}} = object, meta) do if changeset = Keyword.get(meta, :user_update_changeset) do changeset @@ -162,6 +174,7 @@ def handle(%{data: %{"type" => "Update", "object" => updated_object}} = object, # Tasks this handles: # - Add like to object # - Set up notification + @impl true def handle(%{data: %{"type" => "Like"}} = object, meta) do liked_object = Object.get_by_ap_id(object.data["object"]) Utils.add_like_to_object(object, liked_object) @@ -179,6 +192,7 @@ def handle(%{data: %{"type" => "Like"}} = object, meta) do # - Increase replies count # - Set up ActivityExpiration # - Set up notifications + @impl true def handle(%{data: %{"type" => "Create"}} = activity, meta) do with {:ok, object, meta} <- handle_object_creation(meta[:object_data], meta), %User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do @@ -207,6 +221,7 @@ def handle(%{data: %{"type" => "Create"}} = activity, meta) do # - Add announce to object # - Set up notification # - Stream out the announce + @impl true def handle(%{data: %{"type" => "Announce"}} = object, meta) do announced_object = Object.get_by_ap_id(object.data["object"]) user = User.get_cached_by_ap_id(object.data["actor"]) @@ -224,6 +239,7 @@ def handle(%{data: %{"type" => "Announce"}} = object, meta) do {:ok, object, meta} end + @impl true def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do with undone_object <- Activity.get_by_ap_id(undone_object), :ok <- handle_undoing(undone_object) do @@ -234,6 +250,7 @@ def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, met # Tasks this handles: # - Add reaction to object # - Set up notification + @impl true def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do reacted_object = Object.get_by_ap_id(object.data["object"]) Utils.add_emoji_reaction_to_object(object, reacted_object) @@ -250,9 +267,10 @@ def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do # - Reduce the user note count # - Reduce the reply count # - Stream out the activity + @impl true def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do deleted_object = - Object.normalize(deleted_object, false) || + Object.normalize(deleted_object, fetch: false) || User.get_cached_by_ap_id(deleted_object) result = @@ -271,12 +289,12 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, MessageReference.delete_for_object(deleted_object) - ActivityPub.stream_out(object) - ActivityPub.stream_out_participations(deleted_object, user) + @ap_streamer.stream_out(object) + @ap_streamer.stream_out_participations(deleted_object, user) :ok else {:actor, _} -> - Logger.error("The object doesn't have an actor: #{inspect(deleted_object)}") + @logger.error("The object doesn't have an actor: #{inspect(deleted_object)}") :no_object_actor end @@ -295,6 +313,7 @@ def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, end # Nothing to do + @impl true def handle(object, meta) do {:ok, object, meta} end @@ -312,7 +331,7 @@ def handle_object_creation(%{"type" => "ChatMessage"} = object, meta) do {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id) {:ok, cm_ref} = MessageReference.create(chat, object, user.ap_id != actor.ap_id) - Cachex.put( + @cachex.put( :chat_message_id_idempotency_key_cache, cm_ref.id, meta[:idempotency_key] @@ -439,6 +458,7 @@ defp add_notifications(meta, notifications) do |> Keyword.put(:notifications, notifications ++ existing) end + @impl true def handle_after_transaction(meta) do meta |> send_notifications() diff --git a/lib/pleroma/web/activity_pub/side_effects/handling.ex b/lib/pleroma/web/activity_pub/side_effects/handling.ex new file mode 100644 index 000000000..9d64c0e47 --- /dev/null +++ b/lib/pleroma/web/activity_pub/side_effects/handling.ex @@ -0,0 +1,8 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.SideEffects.Handling do + @callback handle(map(), keyword()) :: {:ok, map(), keyword()} | {:error, any()} + @callback handle_after_transaction(map()) :: map() +end diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 565d32433..99cdf91ab 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -653,7 +653,9 @@ def handle_incoming(_, _), do: :error @spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil def get_obj_helper(id, options \\ []) do - case Object.normalize(id, true, options) do + options = Keyword.put(options, :fetch, true) + + case Object.normalize(id, options) do %Object{} = object -> {:ok, object} _ -> nil end @@ -672,7 +674,7 @@ def get_embedded_obj_helper(%{"attributedTo" => attributed_to, "id" => object_id "actor" => attributed_to, "object" => data }) do - {:ok, Object.normalize(activity)} + {:ok, Object.normalize(activity, fetch: false)} else _ -> get_obj_helper(object_id) end @@ -763,7 +765,7 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data) when activity_type in ["Create", "Listen"] do object = object_id - |> Object.normalize() + |> Object.normalize(fetch: false) |> Map.get(:data) |> prepare_object @@ -779,7 +781,7 @@ def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data) def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => object_id} = data) do object = object_id - |> Object.normalize() + |> Object.normalize(fetch: false) data = if Visibility.is_private?(object) && object.data["actor"] == ap_id do @@ -919,7 +921,7 @@ def add_emoji_tags(object), do: object defp build_emoji_tag({name, url}) do %{ - "icon" => %{"url" => url, "type" => "Image"}, + "icon" => %{"url" => "#{URI.encode(url)}", "type" => "Image"}, "name" => ":" <> name <> ":", "type" => "Emoji", "updated" => "1970-01-01T00:00:00Z", diff --git a/lib/pleroma/web/activity_pub/views/object_view.ex b/lib/pleroma/web/activity_pub/views/object_view.ex index e555e9999..44bc5621b 100644 --- a/lib/pleroma/web/activity_pub/views/object_view.ex +++ b/lib/pleroma/web/activity_pub/views/object_view.ex @@ -18,7 +18,7 @@ def render("object.json", %{object: %Object{} = object}) do def render("object.json", %{object: %Activity{data: %{"type" => activity_type}} = activity}) when activity_type in ["Create", "Listen"] do base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header() - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) additional = Transmogrifier.prepare_object(activity.data) @@ -29,7 +29,7 @@ def render("object.json", %{object: %Activity{data: %{"type" => activity_type}} def render("object.json", %{object: %Activity{} = activity}) do base = Pleroma.Web.ActivityPub.Utils.make_json_ld_header() - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) additional = Transmogrifier.prepare_object(activity.data) diff --git a/lib/pleroma/web/activity_pub/views/user_view.ex b/lib/pleroma/web/activity_pub/views/user_view.ex index 93c9f436c..241224b57 100644 --- a/lib/pleroma/web/activity_pub/views/user_view.ex +++ b/lib/pleroma/web/activity_pub/views/user_view.ex @@ -112,7 +112,8 @@ def render("user.json", %{user: user}) do "tag" => emoji_tags, # Note: key name is indeed "discoverable" (not an error) "discoverable" => user.is_discoverable, - "capabilities" => capabilities + "capabilities" => capabilities, + "alsoKnownAs" => user.also_known_as } |> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user)) |> Map.merge(maybe_make_image(&User.banner_url/2, "image", user)) diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex index 5c2c282b3..1c7c26d98 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -103,13 +103,15 @@ def list_user_statuses(%{assigns: %{user: admin}} = conn, %{"nickname" => nickna godmode = params["godmode"] == "true" || params["godmode"] == true with %User{} = user <- User.get_cached_by_nickname_or_id(nickname, for: admin) do - {_, page_size} = page_params(params) + {page, page_size} = page_params(params) activities = ActivityPub.fetch_user_activities(user, nil, %{ limit: page_size, + offset: (page - 1) * page_size, godmode: godmode, - exclude_reblogs: not with_reblogs + exclude_reblogs: not with_reblogs, + pagination_type: :offset }) conn @@ -415,7 +417,7 @@ def reload_emoji(conn, _params) do def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do users = Enum.map(nicknames, &User.get_cached_by_nickname/1) - User.toggle_confirmation(users) + User.confirm(users) ModerationLog.insert_log(%{actor: admin, subject: users, action: "confirm_email"}) diff --git a/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex b/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex index 6d92e9f7f..2f712fb8c 100644 --- a/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/media_proxy_cache_controller.ex @@ -9,6 +9,8 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheController do alias Pleroma.Web.MediaProxy alias Pleroma.Web.Plugs.OAuthScopesPlug + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + plug(Pleroma.Web.ApiSpec.CastAndValidate) plug( @@ -38,7 +40,7 @@ def index(%{assigns: %{user: _}} = conn, params) do defp fetch_entries(params) do MediaProxy.cache_table() - |> Cachex.stream!(Cachex.Query.create(true, :key)) + |> @cachex.stream!(Cachex.Query.create(true, :key)) |> filter_entries(params[:query]) end diff --git a/lib/pleroma/web/admin_api/views/account_view.ex b/lib/pleroma/web/admin_api/views/account_view.ex index 8bac24d3e..ebf90b91b 100644 --- a/lib/pleroma/web/admin_api/views/account_view.ex +++ b/lib/pleroma/web/admin_api/views/account_view.ex @@ -69,6 +69,7 @@ def render("show.json", %{user: user}) do %{ "id" => user.id, + "email" => user.email, "avatar" => avatar, "nickname" => user.nickname, "display_name" => display_name, diff --git a/lib/pleroma/web/admin_api/views/moderation_log_view.ex b/lib/pleroma/web/admin_api/views/moderation_log_view.ex index 112f9e0e1..3fa778b0a 100644 --- a/lib/pleroma/web/admin_api/views/moderation_log_view.ex +++ b/lib/pleroma/web/admin_api/views/moderation_log_view.ex @@ -21,6 +21,7 @@ def render("show.json", %{log_entry: log_entry}) do |> DateTime.to_unix() %{ + id: log_entry.id, data: log_entry.data, time: time, message: ModerationLog.get_log_entry_message(log_entry) diff --git a/lib/pleroma/web/admin_api/views/report_view.ex b/lib/pleroma/web/admin_api/views/report_view.ex index 535556370..da949e306 100644 --- a/lib/pleroma/web/admin_api/views/report_view.ex +++ b/lib/pleroma/web/admin_api/views/report_view.ex @@ -19,8 +19,7 @@ def render("index.json", %{reports: reports}) do reports: reports[:items] |> Enum.map(&Report.extract_report_info/1) - |> Enum.map(&render(__MODULE__, "show.json", &1)) - |> Enum.reverse(), + |> Enum.map(&render(__MODULE__, "show.json", &1)), total: reports[:total] } end diff --git a/lib/pleroma/web/api_spec/operations/account_operation.ex b/lib/pleroma/web/api_spec/operations/account_operation.ex index 280100c3d..bd3a73c11 100644 --- a/lib/pleroma/web/api_spec/operations/account_operation.ex +++ b/lib/pleroma/web/api_spec/operations/account_operation.ex @@ -614,6 +614,12 @@ defp update_credentials_request do nullable: true, description: "Allows automatically follow moved following accounts" }, + also_known_as: %Schema{ + type: :array, + items: %Schema{type: :string}, + nullable: true, + description: "List of alternate ActivityPub IDs" + }, pleroma_background_image: %Schema{ type: :string, nullable: true, @@ -644,6 +650,7 @@ defp update_credentials_request do pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}}, skip_thread_containment: false, allow_following_move: false, + also_known_as: ["https://foo.bar/users/foo"], discoverable: false, actor_type: "Person" } diff --git a/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex index a56641426..747f17e7f 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_emoji_file_operation.ex @@ -27,7 +27,8 @@ def create_operation do 422 => Operation.response("Unprocessable Entity", "application/json", ApiError), 404 => Operation.response("Not Found", "application/json", ApiError), 400 => Operation.response("Bad Request", "application/json", ApiError), - 409 => Operation.response("Conflict", "application/json", ApiError) + 409 => Operation.response("Conflict", "application/json", ApiError), + 500 => Operation.response("Error", "application/json", ApiError) } } end diff --git a/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex index 79f52dcb3..e576ccbad 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_emoji_pack_operation.ex @@ -169,7 +169,8 @@ def delete_operation do responses: %{ 200 => ok_response(), 400 => Operation.response("Bad Request", "application/json", ApiError), - 404 => Operation.response("Not Found", "application/json", ApiError) + 404 => Operation.response("Not Found", "application/json", ApiError), + 500 => Operation.response("Error", "application/json", ApiError) } } end @@ -184,7 +185,8 @@ def update_operation do parameters: [name_param()], responses: %{ 200 => Operation.response("Metadata", "application/json", metadata()), - 400 => Operation.response("Bad Request", "application/json", ApiError) + 400 => Operation.response("Bad Request", "application/json", ApiError), + 500 => Operation.response("Error", "application/json", ApiError) } } end diff --git a/lib/pleroma/web/api_spec/schemas/account.ex b/lib/pleroma/web/api_spec/schemas/account.ex index 684f6fc92..70437003c 100644 --- a/lib/pleroma/web/api_spec/schemas/account.ex +++ b/lib/pleroma/web/api_spec/schemas/account.ex @@ -40,6 +40,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do pleroma: %Schema{ type: :object, properties: %{ + ap_id: %Schema{type: :string}, + also_known_as: %Schema{type: :array, items: %Schema{type: :string}}, allow_following_move: %Schema{ type: :boolean, description: "whether the user allows automatically follow moved following accounts" diff --git a/lib/pleroma/web/common_api.ex b/lib/pleroma/web/common_api.ex index e59254791..87343df75 100644 --- a/lib/pleroma/web/common_api.ex +++ b/lib/pleroma/web/common_api.ex @@ -142,7 +142,7 @@ def delete(activity_id, user) do with {_, %Activity{data: %{"object" => _, "type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(activity_id)}, {_, %Object{} = object, _} <- - {:find_object, Object.normalize(activity, false), activity}, + {:find_object, Object.normalize(activity, fetch: false), activity}, true <- User.superuser?(user) || user.ap_id == object.data["actor"], {:ok, delete_data, _} <- Builder.delete(user, object.data["id"]), {:ok, delete, _} <- Pipeline.common_pipeline(delete_data, local: true) do @@ -173,7 +173,7 @@ def delete(activity_id, user) do def repeat(id, user, params \\ %{}) do with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(id), - object = %Object{} <- Object.normalize(activity, false), + object = %Object{} <- Object.normalize(activity, fetch: false), {_, nil} <- {:existing_announce, Utils.get_existing_announce(user.ap_id, object)}, public = public_announce?(object, params), {:ok, announce, _} <- Builder.announce(user, object, public: public), @@ -191,7 +191,7 @@ def repeat(id, user, params \\ %{}) do def unrepeat(id, user) do with {_, %Activity{data: %{"type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(id)}, - %Object{} = note <- Object.normalize(activity, false), + %Object{} = note <- Object.normalize(activity, fetch: false), %Activity{} = announce <- Utils.get_existing_announce(user.ap_id, note), {:ok, undo, _} <- Builder.undo(user, announce), {:ok, activity, _} <- Pipeline.common_pipeline(undo, local: true) do @@ -253,7 +253,7 @@ def favorite_helper(user, id) do def unfavorite(id, user) do with {_, %Activity{data: %{"type" => "Create"}} = activity} <- {:find_activity, Activity.get_by_id(id)}, - %Object{} = note <- Object.normalize(activity, false), + %Object{} = note <- Object.normalize(activity, fetch: false), %Activity{} = like <- Utils.get_existing_like(user.ap_id, note), {:ok, undo, _} <- Builder.undo(user, like), {:ok, activity, _} <- Pipeline.common_pipeline(undo, local: true) do @@ -266,7 +266,7 @@ def unfavorite(id, user) do def react_with_emoji(id, user, emoji) do with %Activity{} = activity <- Activity.get_by_id(id), - object <- Object.normalize(activity), + object <- Object.normalize(activity, fetch: false), {:ok, emoji_react, _} <- Builder.emoji_react(user, object, emoji), {:ok, activity, _} <- Pipeline.common_pipeline(emoji_react, local: true) do {:ok, activity} @@ -377,7 +377,7 @@ def get_visibility(_, in_reply_to, _), do: {"public", get_replied_to_visibility( def get_replied_to_visibility(nil), do: nil def get_replied_to_visibility(activity) do - with %Object{} = object <- Object.normalize(activity) do + with %Object{} = object <- Object.normalize(activity, fetch: false) do Visibility.get_visibility(object) end end diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 1c74ea787..ddbdb3376 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -319,7 +319,7 @@ def make_note_data(%ActivityDraft{} = draft) do defp add_in_reply_to(object, nil), do: object defp add_in_reply_to(object, in_reply_to) do - with %Object{} = in_reply_to_object <- Object.normalize(in_reply_to) do + with %Object{} = in_reply_to_object <- Object.normalize(in_reply_to, fetch: false) do Map.put(object, "inReplyTo", in_reply_to_object.data["id"]) else _ -> object @@ -399,7 +399,7 @@ def maybe_notify_mentioned_recipients( %Activity{data: %{"to" => _to, "type" => type} = data} = activity ) when type == "Create" do - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) object_data = cond do diff --git a/lib/pleroma/web/embed_controller.ex b/lib/pleroma/web/embed_controller.ex index f6b8a5ee1..f8623d4d6 100644 --- a/lib/pleroma/web/embed_controller.ex +++ b/lib/pleroma/web/embed_controller.ex @@ -31,7 +31,7 @@ def show(conn, %{"id" => id}) do end defp get_counts(%Activity{} = activity) do - %Object{data: data} = Object.normalize(activity) + %Object{data: data} = Object.normalize(activity, fetch: false) %{ likes: Map.get(data, "like_count", 0), diff --git a/lib/pleroma/web/federator.ex b/lib/pleroma/web/federator.ex index 130654145..658d20954 100644 --- a/lib/pleroma/web/federator.ex +++ b/lib/pleroma/web/federator.ex @@ -15,6 +15,8 @@ defmodule Pleroma.Web.Federator do require Logger + @behaviour Pleroma.Web.Federator.Publishing + @doc """ Returns `true` if the distance to target object does not exceed max configured value. Serves to prevent fetching of very long threads, especially useful on smaller instances. @@ -39,10 +41,12 @@ def incoming_ap_doc(params) do ReceiverWorker.enqueue("incoming_ap_doc", %{"params" => params}) end + @impl true def publish(%{id: "pleroma:fakeid"} = activity) do perform(:publish, activity) end + @impl true def publish(activity) do PublisherWorker.enqueue("publish", %{"activity_id" => activity.id}) end diff --git a/lib/pleroma/web/federator/publishing.ex b/lib/pleroma/web/federator/publishing.ex new file mode 100644 index 000000000..d6fba8f24 --- /dev/null +++ b/lib/pleroma/web/federator/publishing.ex @@ -0,0 +1,7 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.Federator.Publishing do + @callback publish(map()) :: any() +end diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex index 56c024617..bc0114e26 100644 --- a/lib/pleroma/web/feed/feed_view.ex +++ b/lib/pleroma/web/feed/feed_view.ex @@ -23,7 +23,7 @@ def pub_date(date) when is_binary(date) do def pub_date(%DateTime{} = date), do: Timex.format!(date, "{RFC822}") def prepare_activity(activity, opts \\ []) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) actor = if opts[:actor] do @@ -51,7 +51,7 @@ def most_recent_update(activities, user) do def feed_logo do case Pleroma.Config.get([:feed, :logo]) do nil -> - "#{Pleroma.Web.base_url()}/static/logo.png" + "#{Pleroma.Web.base_url()}/static/logo.svg" logo -> "#{Pleroma.Web.base_url()}#{logo}" diff --git a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex index b4375872b..3951d10ac 100644 --- a/lib/pleroma/web/mastodon_api/controllers/account_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/account_controller.ex @@ -184,6 +184,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p :show_role, :skip_thread_containment, :allow_following_move, + :also_known_as, :accepts_chat_messages ] |> Enum.reduce(%{}, fn key, acc -> @@ -207,6 +208,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p if bot, do: {:ok, "Service"}, else: {:ok, "Person"} end) |> Maps.put_if_present(:actor_type, params[:actor_type]) + |> Maps.put_if_present(:also_known_as, params[:also_known_as]) # Note: param name is indeed :locked (not an error) |> Maps.put_if_present(:is_locked, params[:locked]) # Note: param name is indeed :discoverable (not an error) diff --git a/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex b/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex index 3dcd1c44f..e26ec7136 100644 --- a/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/poll_controller.ex @@ -26,6 +26,8 @@ defmodule Pleroma.Web.MastodonAPI.PollController do defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PollOperation + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @doc "GET /api/v1/polls/:id" def show(%{assigns: %{user: user}} = conn, %{id: id}) do with %Object{} = object <- Object.get_by_id_and_maybe_refetch(id, interval: 60), @@ -55,7 +57,7 @@ def vote(%{assigns: %{user: user}, body_params: %{choices: choices}} = conn, %{i defp get_cached_vote_or_vote(user, object, choices) do idempotency_key = "polls:#{user.id}:#{object.data["id"]}" - Cachex.fetch!(:idempotency_cache, idempotency_key, fn -> + @cachex.fetch!(:idempotency_cache, idempotency_key, fn _ -> case CommonAPI.vote(user, object, choices) do {:error, _message} = res -> {:ignore, res} res -> {:commit, res} diff --git a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex index 9e3a584f0..acca9d3b2 100644 --- a/lib/pleroma/web/mastodon_api/controllers/status_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/status_controller.ex @@ -318,7 +318,7 @@ def favourited_by(%{assigns: %{user: user}} = conn, %{id: id}) do with true <- Pleroma.Config.get([:instance, :show_reactions]), %Activity{} = activity <- Activity.get_by_id_with_object(id), {:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)}, - %Object{data: %{"likes" => likes}} <- Object.normalize(activity) do + %Object{data: %{"likes" => likes}} <- Object.normalize(activity, fetch: false) do users = User |> Ecto.Query.where([u], u.ap_id in ^likes) @@ -339,7 +339,7 @@ def reblogged_by(%{assigns: %{user: user}} = conn, %{id: id}) do with %Activity{} = activity <- Activity.get_by_id_with_object(id), {:visible, true} <- {:visible, Visibility.visible_for_user?(activity, user)}, %Object{data: %{"announcements" => announces, "id" => ap_id}} <- - Object.normalize(activity) do + Object.normalize(activity, fetch: false) do announces = "Announce" |> Activity.Queries.by_type() diff --git a/lib/pleroma/web/mastodon_api/views/account_view.ex b/lib/pleroma/web/mastodon_api/views/account_view.ex index 3158d09ed..948a05a6d 100644 --- a/lib/pleroma/web/mastodon_api/views/account_view.ex +++ b/lib/pleroma/web/mastodon_api/views/account_view.ex @@ -187,18 +187,14 @@ defp do_render("show.json", %{user: user} = opts) do header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true) following_count = - if !user.hide_follows_count or !user.hide_follows or opts[:for] == user do - user.following_count || 0 - else - 0 - end + if !user.hide_follows_count or !user.hide_follows or opts[:for] == user, + do: user.following_count, + else: 0 followers_count = - if !user.hide_followers_count or !user.hide_followers or opts[:for] == user do - user.follower_count || 0 - else - 0 - end + if !user.hide_followers_count or !user.hide_followers or opts[:for] == user, + do: user.follower_count, + else: 0 bot = user.actor_type == "Service" @@ -269,6 +265,7 @@ defp do_render("show.json", %{user: user} = opts) do # Pleroma extension pleroma: %{ ap_id: user.ap_id, + also_known_as: user.also_known_as, confirmation_pending: user.confirmation_pending, tags: user.tags, hide_followers_count: user.hide_followers_count, diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex index 5b06a6b51..9ec0f311d 100644 --- a/lib/pleroma/web/mastodon_api/views/notification_view.ex +++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex @@ -139,7 +139,7 @@ defp put_emoji(response, activity) do end defp put_chat_message(response, activity, reading_user, opts) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) author = User.get_cached_by_ap_id(object.data["actor"]) chat = Pleroma.Chat.get(reading_user.id, author.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 2301e21cf..b8a35cd38 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -41,7 +41,7 @@ defp get_replied_to_activities(activities) do activities |> Enum.map(fn %{data: %{"type" => "Create"}} = activity -> - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) object && object.data["inReplyTo"] != "" && object.data["inReplyTo"] _ -> @@ -51,7 +51,7 @@ defp get_replied_to_activities(activities) do |> Activity.create_by_object_ap_id_with_object() |> Repo.all() |> Enum.reduce(%{}, fn activity, acc -> - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) if object, do: Map.put(acc, object.data["id"], activity), else: acc end) end @@ -65,7 +65,7 @@ defp get_context_id(%{data: %{"context" => context}}) when is_binary(context), defp get_context_id(_), do: nil defp reblogged?(activity, user) do - object = Object.normalize(activity) || %{} + object = Object.normalize(activity, fetch: false) || %{} present?(user && user.ap_id in (object.data["announcements"] || [])) end @@ -84,7 +84,7 @@ def render("index.json", opts) do parent_activities = activities |> Enum.filter(&(&1.data["type"] == "Announce" && &1.data["object"])) - |> Enum.map(&Object.normalize(&1).data["id"]) + |> Enum.map(&Object.normalize(&1, fetch: false).data["id"]) |> Activity.create_by_object_ap_id() |> Activity.with_preloaded_object(:left) |> Activity.with_preloaded_bookmark(reading_user) @@ -124,7 +124,7 @@ def render( ) do user = CommonAPI.get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) - activity_object = Object.normalize(activity) + activity_object = Object.normalize(activity, fetch: false) reblogged_parent_activity = if opts[:parent_activities] do @@ -193,7 +193,7 @@ def render( end def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) user = CommonAPI.get_user(activity.data["actor"]) user_follower_address = user.follower_address @@ -451,7 +451,7 @@ def render("context.json", %{activity: activity, activities: activities, user: u end def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) with nil <- replied_to_activities[object.data["inReplyTo"]] do # If user didn't participate in the thread @@ -460,7 +460,7 @@ def get_reply_to(activity, %{replied_to_activities: replied_to_activities}) do end def get_reply_to(%{data: %{"object" => _object}} = activity, _) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) if object.data["inReplyTo"] && object.data["inReplyTo"] != "" do Activity.get_create_by_object_ap_id(object.data["inReplyTo"]) diff --git a/lib/pleroma/web/media_proxy.ex b/lib/pleroma/web/media_proxy.ex index 8656b8cad..2793cabc1 100644 --- a/lib/pleroma/web/media_proxy.ex +++ b/lib/pleroma/web/media_proxy.ex @@ -12,29 +12,31 @@ defmodule Pleroma.Web.MediaProxy do @base64_opts [padding: false] @cache_table :banned_urls_cache + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + def cache_table, do: @cache_table @spec in_banned_urls(String.t()) :: boolean() - def in_banned_urls(url), do: elem(Cachex.exists?(@cache_table, url(url)), 1) + def in_banned_urls(url), do: elem(@cachex.exists?(@cache_table, url(url)), 1) def remove_from_banned_urls(urls) when is_list(urls) do - Cachex.execute!(@cache_table, fn cache -> - Enum.each(Invalidation.prepare_urls(urls), &Cachex.del(cache, &1)) + @cachex.execute!(@cache_table, fn cache -> + Enum.each(Invalidation.prepare_urls(urls), &@cachex.del(cache, &1)) end) end def remove_from_banned_urls(url) when is_binary(url) do - Cachex.del(@cache_table, url(url)) + @cachex.del(@cache_table, url(url)) end def put_in_banned_urls(urls) when is_list(urls) do - Cachex.execute!(@cache_table, fn cache -> - Enum.each(Invalidation.prepare_urls(urls), &Cachex.put(cache, &1, true)) + @cachex.execute!(@cache_table, fn cache -> + Enum.each(Invalidation.prepare_urls(urls), &@cachex.put(cache, &1, true)) end) end def put_in_banned_urls(url) when is_binary(url) do - Cachex.put(@cache_table, url(url), true) + @cachex.put(@cache_table, url(url), true) end def url(url) when is_nil(url) or url == "", do: nil diff --git a/lib/pleroma/web/o_status/o_status_controller.ex b/lib/pleroma/web/o_status/o_status_controller.ex index 668ae0ea4..ea182d698 100644 --- a/lib/pleroma/web/o_status/o_status_controller.ex +++ b/lib/pleroma/web/o_status/o_status_controller.ex @@ -74,14 +74,14 @@ def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do cond do format in ["json", "activity+json"] -> if activity.local do - %{data: %{"id" => redirect_url}} = Object.normalize(activity) + %{data: %{"id" => redirect_url}} = Object.normalize(activity, fetch: false) redirect(conn, external: redirect_url) else {:error, :not_found} end activity.data["type"] == "Create" -> - %Object{} = object = Object.normalize(activity) + %Object{} = object = Object.normalize(activity, fetch: false) RedirectController.redirector_with_meta( conn, @@ -112,7 +112,7 @@ def notice_player(conn, %{"id" => id}) do with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id_with_object(id), true <- Visibility.is_public?(activity), {_, true} <- {:visible?, Visibility.visible_for_user?(activity, _reading_user = nil)}, - %Object{} = object <- Object.normalize(activity), + %Object{} = object <- Object.normalize(activity, fetch: false), %{data: %{"attachment" => [%{"url" => [url | _]} | _]}} <- object, true <- String.starts_with?(url["mediaType"], ["audio", "video"]) do conn diff --git a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex index bfc0a1f19..1825e2168 100644 --- a/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/chat_controller.ex @@ -82,7 +82,7 @@ def post_chat_message( media_id: params[:media_id], idempotency_key: idempotency_key(conn) ), - message <- Object.normalize(activity, false), + message <- Object.normalize(activity, fetch: false), cm_ref <- MessageReference.for_chat_and_object(chat, message) do conn |> put_view(MessageReferenceView) diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex index 428c97de6..c15980ff0 100644 --- a/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/emoji_file_controller.ex @@ -42,7 +42,10 @@ def create(%{body_params: params} = conn, %{name: pack_name}) do |> json(%{error: "pack name, shortcode or filename cannot be empty"}) {:error, _} = error -> - handle_error(conn, error, %{pack_name: pack_name}) + handle_error(conn, error, %{ + pack_name: pack_name, + message: "Unexpected error occurred while adding file to pack." + }) end end @@ -69,7 +72,11 @@ def update(%{body_params: %{shortcode: shortcode} = params} = conn, %{name: pack |> json(%{error: "new_shortcode or new_filename cannot be empty"}) {:error, _} = error -> - handle_error(conn, error, %{pack_name: pack_name, code: shortcode}) + handle_error(conn, error, %{ + pack_name: pack_name, + code: shortcode, + message: "Unexpected error occurred while updating." + }) end end @@ -84,7 +91,11 @@ def delete(conn, %{name: pack_name, shortcode: shortcode}) do |> json(%{error: "pack name or shortcode cannot be empty"}) {:error, _} = error -> - handle_error(conn, error, %{pack_name: pack_name, code: shortcode}) + handle_error(conn, error, %{ + pack_name: pack_name, + code: shortcode, + message: "Unexpected error occurred while deleting emoji file." + }) end end @@ -94,18 +105,24 @@ defp handle_error(conn, {:error, :doesnt_exist}, %{code: emoji_code}) do |> json(%{error: "Emoji \"#{emoji_code}\" does not exist"}) end - defp handle_error(conn, {:error, :not_found}, %{pack_name: pack_name}) do + defp handle_error(conn, {:error, :enoent}, %{pack_name: pack_name}) do conn |> put_status(:not_found) |> json(%{error: "pack \"#{pack_name}\" is not found"}) end - defp handle_error(conn, {:error, _}, _) do - render_error( - conn, - :internal_server_error, - "Unexpected error occurred while adding file to pack." - ) + defp handle_error(conn, {:error, error}, opts) do + message = + [ + Map.get(opts, :message, "Unexpected error occurred."), + Pleroma.Utils.posix_error_message(error) + ] + |> Enum.join(" ") + |> String.trim() + + conn + |> put_status(:internal_server_error) + |> json(%{error: message}) end defp get_filename(%Plug.Upload{filename: filename}), do: filename diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex index a9accc5af..bc4c8d840 100644 --- a/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex @@ -71,7 +71,7 @@ def show(conn, %{name: name, page: page, page_size: page_size}) do with {:ok, pack} <- Pack.show(name: name, page: page, page_size: page_size) do json(conn, pack) else - {:error, :not_found} -> + {:error, :enoent} -> conn |> put_status(:not_found) |> json(%{error: "Pack #{name} does not exist"}) @@ -80,6 +80,17 @@ def show(conn, %{name: name, page: page, page_size: page_size}) do conn |> put_status(:bad_request) |> json(%{error: "pack name cannot be empty"}) + + {:error, error} -> + error_message = + add_posix_error( + "Failed to get the contents of the `#{name}` pack.", + error + ) + + conn + |> put_status(:internal_server_error) + |> json(%{error: error_message}) end end @@ -95,7 +106,7 @@ def archive(conn, %{name: name}) do "Pack #{name} cannot be downloaded from this instance, either pack sharing was disabled for this pack or some files are missing" }) - {:error, :not_found} -> + {:error, :enoent} -> conn |> put_status(:not_found) |> json(%{error: "Pack #{name} does not exist"}) @@ -116,10 +127,10 @@ def download(%{body_params: %{url: url, name: name} = params} = conn, _) do |> put_status(:internal_server_error) |> json(%{error: "SHA256 for the pack doesn't match the one sent by the server"}) - {:error, e} -> + {:error, error} -> conn |> put_status(:internal_server_error) - |> json(%{error: e}) + |> json(%{error: error}) end end @@ -139,12 +150,16 @@ def create(conn, %{name: name}) do |> put_status(:bad_request) |> json(%{error: "pack name cannot be empty"}) - {:error, _} -> - render_error( - conn, - :internal_server_error, - "Unexpected error occurred while creating pack." - ) + {:error, error} -> + error_message = + add_posix_error( + "Unexpected error occurred while creating pack.", + error + ) + + conn + |> put_status(:internal_server_error) + |> json(%{error: error_message}) end end @@ -164,10 +179,12 @@ def delete(conn, %{name: name}) do |> put_status(:bad_request) |> json(%{error: "pack name cannot be empty"}) - {:error, _, _} -> + {:error, error, _} -> + error_message = add_posix_error("Couldn't delete the `#{name}` pack", error) + conn |> put_status(:internal_server_error) - |> json(%{error: "Couldn't delete the pack #{name}"}) + |> json(%{error: error_message}) end end @@ -180,12 +197,16 @@ def update(%{body_params: %{metadata: metadata}} = conn, %{name: name}) do |> put_status(:bad_request) |> json(%{error: "The fallback archive does not have all files specified in pack.json"}) - {:error, _} -> - render_error( - conn, - :internal_server_error, - "Unexpected error occurred while updating pack metadata." - ) + {:error, error} -> + error_message = + add_posix_error( + "Unexpected error occurred while updating pack metadata.", + error + ) + + conn + |> put_status(:internal_server_error) + |> json(%{error: error_message}) end end @@ -204,4 +225,10 @@ def import_from_filesystem(conn, _params) do |> json(%{error: "Error accessing emoji pack directory"}) end end + + defp add_posix_error(msg, error) do + [msg, Pleroma.Utils.posix_error_message(error)] + |> Enum.join(" ") + |> String.trim() + end end diff --git a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex index dd9c746dc..dee04f045 100644 --- a/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex +++ b/lib/pleroma/web/pleroma_api/controllers/emoji_reaction_controller.ex @@ -29,7 +29,7 @@ def index(%{assigns: %{user: user}} = conn, %{id: activity_id} = params) do with true <- Pleroma.Config.get([:instance, :show_reactions]), %Activity{} = activity <- Activity.get_by_id_with_object(activity_id), %Object{data: %{"reactions" => reactions}} when is_list(reactions) <- - Object.normalize(activity) do + Object.normalize(activity, fetch: false) do reactions = reactions |> filter(params) diff --git a/lib/pleroma/web/pleroma_api/views/backup_view.ex b/lib/pleroma/web/pleroma_api/views/backup_view.ex index af75876aa..39affe979 100644 --- a/lib/pleroma/web/pleroma_api/views/backup_view.ex +++ b/lib/pleroma/web/pleroma_api/views/backup_view.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupView do def render("show.json", %{backup: %Backup{} = backup}) do %{ + id: backup.id, content_type: backup.content_type, url: download_url(backup), file_size: backup.file_size, diff --git a/lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex b/lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex index c058fb340..df48044e3 100644 --- a/lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex +++ b/lib/pleroma/web/pleroma_api/views/chat/message_reference_view.ex @@ -10,6 +10,8 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceView do alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MastodonAPI.StatusView + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + def render( "show.json", %{ @@ -51,7 +53,7 @@ def render("index.json", opts) do end defp put_idempotency_key(data) do - with {:ok, idempotency_key} <- Cachex.get(:chat_message_id_idempotency_key_cache, data.id) do + with {:ok, idempotency_key} <- @cachex.get(:chat_message_id_idempotency_key_cache, data.id) do data |> Maps.put_if_present(:idempotency_key, idempotency_key) else diff --git a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex index 95bd4c368..98b95c721 100644 --- a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex +++ b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex @@ -15,7 +15,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleView do alias Pleroma.Web.MastodonAPI.AccountView def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) user = CommonAPI.get_user(activity.data["actor"]) created_at = Utils.to_masto_date(activity.data["published"]) diff --git a/lib/pleroma/web/plugs/cache.ex b/lib/pleroma/web/plugs/cache.ex index 6de01804a..18880716a 100644 --- a/lib/pleroma/web/plugs/cache.ex +++ b/lib/pleroma/web/plugs/cache.ex @@ -41,6 +41,8 @@ def index(conn, _params) do @defaults %{ttl: nil, query_params: true} + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @impl true def init([]), do: @defaults @@ -53,7 +55,7 @@ def init(opts) do def call(%{method: "GET"} = conn, opts) do key = cache_key(conn, opts) - case Cachex.get(:web_resp_cache, key) do + case @cachex.get(:web_resp_cache, key) do {:ok, nil} -> cache_resp(conn, opts) @@ -97,11 +99,11 @@ defp cache_resp(conn, opts) do conn = unless opts[:tracking_fun] do - Cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl) + @cachex.put(:web_resp_cache, key, {content_type, body}, ttl: ttl) conn else tracking_fun_data = Map.get(conn.assigns, :tracking_fun_data, nil) - Cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data}, ttl: ttl) + @cachex.put(:web_resp_cache, key, {content_type, body, tracking_fun_data}, ttl: ttl) opts.tracking_fun.(conn, tracking_fun_data) end diff --git a/lib/pleroma/web/plugs/idempotency_plug.ex b/lib/pleroma/web/plugs/idempotency_plug.ex index 254a790b0..4f908779c 100644 --- a/lib/pleroma/web/plugs/idempotency_plug.ex +++ b/lib/pleroma/web/plugs/idempotency_plug.ex @@ -8,6 +8,8 @@ defmodule Pleroma.Web.Plugs.IdempotencyPlug do @behaviour Plug + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @impl true def init(opts), do: opts @@ -25,7 +27,7 @@ def call(%{method: method} = conn, _) when method in ["POST", "PUT", "PATCH"] do def call(conn, _), do: conn def process_request(conn, key) do - case Cachex.get(:idempotency_cache, key) do + case @cachex.get(:idempotency_cache, key) do {:ok, nil} -> cache_resposnse(conn, key) @@ -43,7 +45,7 @@ defp cache_resposnse(conn, key) do content_type = get_content_type(conn) record = {request_id, content_type, conn.status, conn.resp_body} - {:ok, _} = Cachex.put(:idempotency_cache, key, record) + {:ok, _} = @cachex.put(:idempotency_cache, key, record) conn |> put_resp_header("idempotency-key", key) diff --git a/lib/pleroma/web/plugs/rate_limiter.ex b/lib/pleroma/web/plugs/rate_limiter.ex index a589610d1..034a5bbe2 100644 --- a/lib/pleroma/web/plugs/rate_limiter.ex +++ b/lib/pleroma/web/plugs/rate_limiter.ex @@ -72,6 +72,8 @@ defmodule Pleroma.Web.Plugs.RateLimiter do require Logger + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + @doc false def init(plug_opts) do plug_opts @@ -124,7 +126,7 @@ def inspect_bucket(conn, bucket_name_root, plug_opts) do key_name = make_key_name(action_settings) limit = get_limits(action_settings) - case Cachex.get(bucket_name, key_name) do + case @cachex.get(bucket_name, key_name) do {:error, :no_cache} -> @inspect_bucket_not_found @@ -157,7 +159,7 @@ defp check_rate(action_settings) do key_name = make_key_name(action_settings) limit = get_limits(action_settings) - case Cachex.get_and_update(bucket_name, key_name, &increment_value(&1, limit)) do + case @cachex.get_and_update(bucket_name, key_name, &increment_value(&1, limit)) do {:commit, value} -> {:ok, value} diff --git a/lib/pleroma/web/plugs/uploaded_media.ex b/lib/pleroma/web/plugs/uploaded_media.ex index 402a8bb34..94b4c2177 100644 --- a/lib/pleroma/web/plugs/uploaded_media.ex +++ b/lib/pleroma/web/plugs/uploaded_media.ex @@ -87,8 +87,15 @@ defp get_media(conn, {:static_dir, directory}, _, opts) do end defp get_media(conn, {:url, url}, true, _) do + proxy_opts = [ + http: [ + follow_redirect: true, + pool: :upload + ] + ] + conn - |> Pleroma.ReverseProxy.call(url, Pleroma.Config.get([Pleroma.Upload, :proxy_opts], [])) + |> Pleroma.ReverseProxy.call(url, proxy_opts) end defp get_media(conn, {:url, url}, _, _) do diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex index 82152dffa..a9c46f63a 100644 --- a/lib/pleroma/web/push/impl.ex +++ b/lib/pleroma/web/push/impl.ex @@ -32,7 +32,7 @@ def perform( mastodon_type = notification.type gcm_api_key = Application.get_env(:web_push_encryption, :gcm_api_key) avatar_url = User.avatar_url(actor) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) user = User.get_cached_by_id(user_id) direct_conversation_id = Activity.direct_conversation_id(activity, user) diff --git a/lib/pleroma/web/rel_me.ex b/lib/pleroma/web/rel_me.ex index 28f75b18d..650c6a3fc 100644 --- a/lib/pleroma/web/rel_me.ex +++ b/lib/pleroma/web/rel_me.ex @@ -12,8 +12,9 @@ defmodule Pleroma.Web.RelMe do if Pleroma.Config.get(:env) == :test do def parse(url) when is_binary(url), do: parse_url(url) else + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) def parse(url) when is_binary(url) do - Cachex.fetch!(:rel_me_cache, url, fn _ -> + @cachex.fetch!(:rel_me_cache, url, fn _ -> {:commit, parse_url(url)} end) rescue diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 442bf9995..566fc8c8a 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -69,7 +69,7 @@ def fetch_data_for_object(object) do def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do with true <- Config.get([:rich_media, :enabled]), - %Object{} = object <- Object.normalize(activity) do + %Object{} = object <- Object.normalize(activity, fetch: false) do fetch_data_for_object(object) else _ -> %{} diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index c70d2fdba..d7a491198 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -5,6 +5,8 @@ defmodule Pleroma.Web.RichMedia.Parser do require Logger + @cachex Pleroma.Config.get([:cachex, :provider], Cachex) + defp parsers do Pleroma.Config.get([:rich_media, :parsers]) end @@ -24,7 +26,7 @@ def parse(url) do end defp get_cached_or_parse(url) do - case Cachex.fetch(:rich_media_cache, url, fn -> + case @cachex.fetch(:rich_media_cache, url, fn -> case parse_url(url) do {:ok, _} = res -> {:commit, res} @@ -64,7 +66,7 @@ defp set_error_ttl(_url, {:content_type, _}), do: :ok defp set_error_ttl(url, _reason) do ttl = Pleroma.Config.get([:rich_media, :failure_backoff], 60_000) - Cachex.expire(:rich_media_cache, url, ttl) + @cachex.expire(:rich_media_cache, url, ttl) :ok end @@ -106,7 +108,7 @@ def set_ttl_based_on_image(data, url) do {:ok, ttl} when is_number(ttl) -> ttl = ttl * 1000 - case Cachex.expire_at(:rich_media_cache, url, ttl) do + case @cachex.expire_at(:rich_media_cache, url, ttl) do {:ok, true} -> {:ok, ttl} {:ok, false} -> {:error, :no_key} end diff --git a/lib/pleroma/web/static_fe/static_fe_controller.ex b/lib/pleroma/web/static_fe/static_fe_controller.ex index bdec0897a..404cb0473 100644 --- a/lib/pleroma/web/static_fe/static_fe_controller.ex +++ b/lib/pleroma/web/static_fe/static_fe_controller.ex @@ -122,7 +122,7 @@ defp not_found(conn, message) do end defp get_counts(%Activity{} = activity) do - %Object{data: data} = Object.normalize(activity) + %Object{data: data} = Object.normalize(activity, fetch: false) %{ likes: data["like_count"] || 0, diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index 7d4a1304a..1fb8ac1c5 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -151,7 +151,7 @@ def filtered_by_user?(%User{} = user, %Activity{} = item, streamed_type) do recipients = MapSet.new(item.recipients) domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks) - with parent <- Object.normalize(item) || item, + with parent <- Object.normalize(item, fetch: false) || item, true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)), true <- item.data["type"] != "Announce" || item.actor not in reblog_muted_ap_ids, true <- diff --git a/lib/pleroma/web/templates/email/digest.html.eex b/lib/pleroma/web/templates/email/digest.html.eex index 860df5f9c..60eceff22 100644 --- a/lib/pleroma/web/templates/email/digest.html.eex +++ b/lib/pleroma/web/templates/email/digest.html.eex @@ -126,7 +126,7 @@
Image diff --git a/lib/pleroma/web/twitter_api/controller.ex b/lib/pleroma/web/twitter_api/controller.ex index f42dba442..16f43863c 100644 --- a/lib/pleroma/web/twitter_api/controller.ex +++ b/lib/pleroma/web/twitter_api/controller.ex @@ -31,10 +31,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do def confirm_email(conn, %{"user_id" => uid, "token" => token}) do with %User{} = user <- User.get_cached_by_id(uid), true <- user.local and user.confirmation_pending and user.confirmation_token == token, - {:ok, _} <- - user - |> User.confirmation_changeset(need_confirmation: false) - |> User.update_and_set_cache() do + {:ok, _} <- User.confirm(user) do redirect(conn, to: "/") end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 5d7948507..8e20b0d55 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -45,7 +45,6 @@ defp create_user(params, opts) do case User.register(changeset) do {:ok, user} -> - maybe_notify_admins(user) {:ok, user} {:error, changeset} -> @@ -58,18 +57,6 @@ defp create_user(params, opts) do end end - defp maybe_notify_admins(%User{} = account) do - if Pleroma.Config.get([:instance, :account_approval_required]) do - User.all_superusers() - |> Enum.filter(fn user -> not is_nil(user.email) end) - |> Enum.each(fn superuser -> - superuser - |> Pleroma.Emails.AdminEmail.new_unapproved_registration(account) - |> Pleroma.Emails.Mailer.deliver_async() - end) - end - end - def password_reset(nickname_or_email) do with true <- is_binary(nickname_or_email), %User{local: true, email: email, deactivated: false} = user when is_binary(email) <- diff --git a/lib/pleroma/web/web_finger.ex b/lib/pleroma/web/web_finger.ex index 6629f5356..a109e1acc 100644 --- a/lib/pleroma/web/web_finger.ex +++ b/lib/pleroma/web/web_finger.ex @@ -58,12 +58,16 @@ defp gather_links(%User{} = user) do ] ++ Publisher.gather_webfinger_links(user) end + defp gather_aliases(%User{} = user) do + [user.ap_id | user.also_known_as] + end + def represent_user(user, "JSON") do {:ok, user} = User.ensure_keys_present(user) %{ "subject" => "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}", - "aliases" => [user.ap_id], + "aliases" => gather_aliases(user), "links" => gather_links(user) } end @@ -71,6 +75,11 @@ def represent_user(user, "JSON") do def represent_user(user, "XML") do {:ok, user} = User.ensure_keys_present(user) + aliases = + user + |> gather_aliases() + |> Enum.map(&{:Alias, &1}) + links = gather_links(user) |> Enum.map(fn link -> {:Link, link} end) @@ -79,9 +88,8 @@ def represent_user(user, "XML") do :XRD, %{xmlns: "http://docs.oasis-open.org/ns/xri/xrd-1.0"}, [ - {:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"}, - {:Alias, user.ap_id} - ] ++ links + {:Subject, "acct:#{user.nickname}@#{Pleroma.Web.Endpoint.host()}"} + ] ++ aliases ++ links } |> XmlBuilder.to_doc() end @@ -116,6 +124,9 @@ defp webfinger_from_json(doc) do {"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"", "self"} -> Map.put(data, "ap_id", link["href"]) + {nil, "http://ostatus.org/schema/1.0/subscribe"} -> + Map.put(data, "subscribe_address", link["template"]) + _ -> Logger.debug("Unhandled type: #{inspect(link["type"])}") data diff --git a/mix.exs b/mix.exs index c948b0b02..f26a5391a 100644 --- a/mix.exs +++ b/mix.exs @@ -22,7 +22,7 @@ def project do docs: [ source_url_pattern: "https://git.pleroma.social/pleroma/pleroma/blob/develop/%{path}#L%{line}", - logo: "priv/static/static/logo.png", + logo: "priv/static/images/logo.png", extras: ["README.md", "CHANGELOG.md"] ++ Path.wildcard("docs/**/*.md"), groups_for_extras: [ "Installation manuals": Path.wildcard("docs/installation/*.md"), @@ -147,8 +147,8 @@ defp deps do {:earmark, "1.4.3"}, {:bbcode_pleroma, "~> 0.2.0"}, {:crypt, - git: "https://github.com/msantos/crypt.git", - ref: "f63a705f92c26955977ee62a313012e309a4d77a"}, + git: "https://git.pleroma.social/pleroma/elixir-libraries/crypt.git", + ref: "cf2aa3f11632e8b0634810a15b3e612c7526f6a3"}, {:cors_plug, "~> 2.0"}, {:web_push_encryption, "~> 0.3"}, {:swoosh, "~> 1.0"}, @@ -158,7 +158,7 @@ defp deps do {:floki, "~> 0.27"}, {:timex, "~> 3.6"}, {:ueberauth, "~> 0.4"}, - {:linkify, "~> 0.4.0"}, + {:linkify, "~> 0.4.1"}, {:http_signatures, "~> 0.1.0"}, {:telemetry, "~> 0.3"}, {:poolboy, "~> 1.5"}, @@ -211,7 +211,7 @@ defp deps do git: "https://git.pleroma.social/pleroma/elixir-libraries/hackney.git", ref: "7d7119f0651515d6d7669c78393fd90950a3ec6e", override: true}, - {:mox, "~> 0.5", only: :test}, + {:mox, "~> 1.0", only: :test}, {:websocket_client, git: "https://github.com/jeremyong/websocket_client.git", only: :test} ] ++ oauth_deps() end diff --git a/mix.lock b/mix.lock index 7db71453f..01caf319e 100644 --- a/mix.lock +++ b/mix.lock @@ -22,7 +22,7 @@ "cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"}, "credo": {:hex, :credo, "1.4.1", "16392f1edd2cdb1de9fe4004f5ab0ae612c92e230433968eab00aafd976282fc", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "155f8a2989ad77504de5d8291fa0d41320fdcaa6a1030472e9967f285f8c7692"}, "crontab": {:hex, :crontab, "1.1.8", "2ce0e74777dfcadb28a1debbea707e58b879e6aa0ffbf9c9bb540887bce43617", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"}, - "crypt": {:git, "https://github.com/msantos/crypt.git", "f63a705f92c26955977ee62a313012e309a4d77a", [ref: "f63a705f92c26955977ee62a313012e309a4d77a"]}, + "crypt": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/crypt.git", "cf2aa3f11632e8b0634810a15b3e612c7526f6a3", [ref: "cf2aa3f11632e8b0634810a15b3e612c7526f6a3"]}, "custom_base": {:hex, :custom_base, "0.2.1", "4a832a42ea0552299d81652aa0b1f775d462175293e99dfbe4d7dbaab785a706", [:mix], [], "hexpm", "8df019facc5ec9603e94f7270f1ac73ddf339f56ade76a721eaa57c1493ba463"}, "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, @@ -33,7 +33,7 @@ "ecto_enum": {:hex, :ecto_enum, "1.4.0", "d14b00e04b974afc69c251632d1e49594d899067ee2b376277efd8233027aec8", [:mix], [{:ecto, ">= 3.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "> 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "8fb55c087181c2b15eee406519dc22578fa60dd82c088be376d0010172764ee4"}, "ecto_sql": {:hex, :ecto_sql, "3.4.5", "30161f81b167d561a9a2df4329c10ae05ff36eca7ccc84628f2c8b9fa1e43323", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31990c6a3579b36a3c0841d34a94c275e727de8b84f58509da5f1b2032c98ac2"}, "eimp": {:hex, :eimp, "1.0.14", "fc297f0c7e2700457a95a60c7010a5f1dcb768a083b6d53f49cd94ab95a28f22", [:rebar3], [{:p1_utils, "1.0.18", [hex: :p1_utils, repo: "hexpm", optional: false]}], "hexpm", "501133f3112079b92d9e22da8b88bf4f0e13d4d67ae9c15c42c30bd25ceb83b6"}, - "elixir_make": {:hex, :elixir_make, "0.6.1", "8faa29a5597faba999aeeb72bbb9c91694ef8068f0131192fb199f98d32994ef", [:mix], [], "hexpm", "35d33270680f8d839a4003c3e9f43afb595310a592405a00afc12de4c7f55a18"}, + "elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"}, "esshd": {:hex, :esshd, "0.1.1", "d4dd4c46698093a40a56afecce8a46e246eb35463c457c246dacba2e056f31b5", [:mix], [], "hexpm", "d73e341e3009d390aa36387dc8862860bf9f874c94d9fd92ade2926376f49981"}, "eternal": {:hex, :eternal, "1.2.1", "d5b6b2499ba876c57be2581b5b999ee9bdf861c647401066d3eeed111d096bc4", [:mix], [], "hexpm", "b14f1dc204321429479c569cfbe8fb287541184ed040956c8862cb7a677b8406"}, "ex2ms": {:hex, :ex2ms, "1.5.0", "19e27f9212be9a96093fed8cdfbef0a2b56c21237196d26760f11dfcfae58e97", [:mix], [], "hexpm"}, @@ -65,7 +65,7 @@ "jose": {:hex, :jose, "1.10.1", "16d8e460dae7203c6d1efa3f277e25b5af8b659febfc2f2eb4bacf87f128b80a", [:mix, :rebar3], [], "hexpm", "3c7ddc8a9394b92891db7c2771da94bf819834a1a4c92e30857b7d582e2f8257"}, "jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm", "318c59078ac220e966d27af3646026db9b5a5e6703cb2aa3e26bcfaba65b7433"}, "libring": {:hex, :libring, "1.4.0", "41246ba2f3fbc76b3971f6bce83119dfec1eee17e977a48d8a9cfaaf58c2a8d6", [:mix], [], "hexpm"}, - "linkify": {:hex, :linkify, "0.4.0", "7845b6ac33050a41acaf9318923ce6e7f3854418be9a5f22184de103f7a68ff9", [:mix], [], "hexpm", "a0ceb4c78591fecccf1d99fecc10c13dba75a307c663c80e28af9e2cdd9776ee"}, + "linkify": {:hex, :linkify, "0.4.1", "f881eb3429ae88010cf736e6fb3eed406c187bcdd544902ec937496636b7c7b3", [:mix], [], "hexpm", "ce98693f54ae9ace59f2f7a8aed3de2ef311381a8ce7794804bd75484c371dda"}, "majic": {:git, "https://git.pleroma.social/pleroma/elixir-libraries/majic.git", "4c692e544b28d1f5e543fb8a44be090f8cd96f80", [ref: "4c692e544b28d1f5e543fb8a44be090f8cd96f80"]}, "makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"}, "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"}, @@ -76,7 +76,7 @@ "mochiweb": {:hex, :mochiweb, "2.18.0", "eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e", [:rebar3], [], "hexpm"}, "mock": {:hex, :mock, "0.3.5", "feb81f52b8dcf0a0d65001d2fec459f6b6a8c22562d94a965862f6cc066b5431", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm", "6fae404799408300f863550392635d8f7e3da6b71abdd5c393faf41b131c8728"}, "mogrify": {:hex, :mogrify, "0.7.4", "9b2496dde44b1ce12676f85d7dc531900939e6367bc537c7243a1b089435b32d", [:mix], [], "hexpm", "50d79e337fba6bc95bfbef918058c90f50b17eed9537771e61d4619488f099c3"}, - "mox": {:hex, :mox, "0.5.2", "55a0a5ba9ccc671518d068c8dddd20eeb436909ea79d1799e2209df7eaa98b6c", [:mix], [], "hexpm", "df4310628cd628ee181df93f50ddfd07be3e5ecc30232d3b6aadf30bdfe6092b"}, + "mox": {:hex, :mox, "1.0.0", "4b3c7005173f47ff30641ba044eb0fe67287743eec9bd9545e37f3002b0a9f8b", [:mix], [], "hexpm", "201b0a20b7abdaaab083e9cf97884950f8a30a1350a1da403b3145e213c6f4df"}, "myhtmlex": {:git, "https://git.pleroma.social/pleroma/myhtmlex.git", "ad0097e2f61d4953bfef20fb6abddf23b87111e6", [ref: "ad0097e2f61d4953bfef20fb6abddf23b87111e6", submodules: true]}, "nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"}, "nimble_pool": {:hex, :nimble_pool, "0.1.0", "ffa9d5be27eee2b00b0c634eb649aa27f97b39186fec3c493716c2a33e784ec6", [:mix], [], "hexpm", "343a1eaa620ddcf3430a83f39f2af499fe2370390d4f785cd475b4df5acaf3f9"}, diff --git a/priv/gettext/en/LC_MESSAGES/posix_errors.po b/priv/gettext/en/LC_MESSAGES/posix_errors.po new file mode 100644 index 000000000..4d8fbf1d3 --- /dev/null +++ b/priv/gettext/en/LC_MESSAGES/posix_errors.po @@ -0,0 +1,141 @@ +## This file is a PO Template file. +msgid "eperm" +msgstr "Operation not permitted" + +msgid "eacces" +msgstr "Permission denied" + +msgid "eagain" +msgstr "Resource temporarily unavailable" + +msgid "ebadf" +msgstr "Bad file descriptor" + +msgid "ebadmsg" +msgstr "Bad message" + +msgid "ebusy" +msgstr "Device or resource busy" + +msgid "edeadlk" +msgstr "Resource deadlock avoided" + +msgid "edeadlock" +msgstr "Resource deadlock avoided" + +msgid "edquot" +msgstr "Disk quota exceeded" + +msgid "eexist" +msgstr "File exists" + +msgid "efault" +msgstr "Bad address" + +msgid "efbig" +msgstr "File is too large" + +msgid "eftype" +msgstr "Inappropriate file type or format" + +msgid "eintr" +msgstr "Interrupted system call" + +msgid "einval" +msgstr "Invalid argument" + +msgid "eio" +msgstr "Input/output error" + +msgid "eisdir" +msgstr "Illegal operation on a directory" + +msgid "eloop" +msgstr "Too many levels of symbolic links" + +msgid "emfile" +msgstr "Too many open files" + +msgid "emlink" +msgstr "Too many links" + +msgid "emultihop" +msgstr "Multihop attempted" + +msgid "enametoolong" +msgstr "File name is too long" + +msgid "enfile" +msgstr "Too many open files in system" + +msgid "enobufs" +msgstr "No buffer space available" + +msgid "enodev" +msgstr "No such device" + +msgid "enolck" +msgstr "No locks available" + +msgid "enolink" +msgstr "Link has been severed" + +msgid "enoent" +msgstr "No such file or directory" + +msgid "enomem" +msgstr "Cannot allocate memory" + +msgid "enospc" +msgstr "No space left on device" + +msgid "enosr" +msgstr "Out of streams resources" + +msgid "enostr" +msgstr "Device is not a stream" + +msgid "enosys" +msgstr "Function not implemented" + +msgid "enotblk" +msgstr "Block device required" + +msgid "enotdir" +msgstr "Not a directory" + +msgid "enotsup" +msgstr "Operation not supported" + +msgid "enxio" +msgstr "No such device or address" + +msgid "eopnotsupp" +msgstr "Operation not supported" + +msgid "eoverflow" +msgstr "Value too large for defined data type" + +msgid "epipe" +msgstr "Broken pipe" + +msgid "erange" +msgstr "Numerical result out of range" + +msgid "erofs" +msgstr "Read-only file system" + +msgid "espipe" +msgstr "Illegal seek" + +msgid "esrch" +msgstr "No such process" + +msgid "estale" +msgstr "Stale file handle" + +msgid "etxtbsy" +msgstr "Text file busy" + +msgid "exdev" +msgstr "Invalid cross-device link" diff --git a/priv/gettext/posix_errors.pot b/priv/gettext/posix_errors.pot new file mode 100644 index 000000000..c9f593944 --- /dev/null +++ b/priv/gettext/posix_errors.pot @@ -0,0 +1,149 @@ +## This file is a PO Template file. +## +## `msgid`s here are often extracted from source code. +## Add new translations manually only if they're dynamic +## translations that can't be statically extracted. +## +## Run `mix gettext.extract` to bring this file up to +## date. Leave `msgstr`s empty as changing them here as no +## effect: edit them in PO (`.po`) files instead. +msgid "eperm" +msgstr "" + +msgid "eacces" +msgstr "" + +msgid "eagain" +msgstr "" + +msgid "ebadf" +msgstr "" + +msgid "ebadmsg" +msgstr "" + +msgid "ebusy" +msgstr "" + +msgid "edeadlk" +msgstr "" + +msgid "edeadlock" +msgstr "" + +msgid "edquot" +msgstr "" + +msgid "eexist" +msgstr "" + +msgid "efault" +msgstr "" + +msgid "efbig" +msgstr "" + +msgid "eftype" +msgstr "" + +msgid "eintr" +msgstr "" + +msgid "einval" +msgstr "" + +msgid "eio" +msgstr "" + +msgid "eisdir" +msgstr "" + +msgid "eloop" +msgstr "" + +msgid "emfile" +msgstr "" + +msgid "emlink" +msgstr "" + +msgid "emultihop" +msgstr "" + +msgid "enametoolong" +msgstr "" + +msgid "enfile" +msgstr "" + +msgid "enobufs" +msgstr "" + +msgid "enodev" +msgstr "" + +msgid "enolck" +msgstr "" + +msgid "enolink" +msgstr "" + +msgid "enoent" +msgstr "" + +msgid "enomem" +msgstr "" + +msgid "enospc" +msgstr "" + +msgid "enosr" +msgstr "" + +msgid "enostr" +msgstr "" + +msgid "enosys" +msgstr "" + +msgid "enotblk" +msgstr "" + +msgid "enotdir" +msgstr "" + +msgid "enotsup" +msgstr "" + +msgid "enxio" +msgstr "" + +msgid "eopnotsupp" +msgstr "" + +msgid "eoverflow" +msgstr "" + +msgid "epipe" +msgstr "" + +msgid "erange" +msgstr "" + +msgid "erofs" +msgstr "" + +msgid "espipe" +msgstr "" + +msgid "esrch" +msgstr "" + +msgid "estale" +msgstr "" + +msgid "etxtbsy" +msgstr "" + +msgid "exdev" +msgstr "" diff --git a/priv/gettext/zh_Hans/LC_MESSAGES/errors.po b/priv/gettext/zh_Hans/LC_MESSAGES/errors.po index 8b24d4a86..ecf1dab6b 100644 --- a/priv/gettext/zh_Hans/LC_MESSAGES/errors.po +++ b/priv/gettext/zh_Hans/LC_MESSAGES/errors.po @@ -3,7 +3,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-09-20 13:18+0000\n" -"PO-Revision-Date: 2020-10-22 18:25+0000\n" +"PO-Revision-Date: 2020-12-14 06:00+0000\n" "Last-Translator: shironeko \n" "Language-Team: Chinese (Simplified) \n" @@ -146,9 +146,9 @@ msgid "Cannot post an empty status without attachments" msgstr "无法发送空白且不包含附件的状态" #: lib/pleroma/web/common_api/utils.ex:511 -#, elixir-format +#, elixir-format, fuzzy msgid "Comment must be up to %{max_size} characters" -msgstr "" +msgstr "评论最多可使用 %{max_size} 字符" #: lib/pleroma/config/config_db.ex:191 #, elixir-format @@ -250,21 +250,21 @@ msgstr "没有该对话" #: lib/pleroma/web/admin_api/controllers/admin_api_controller.ex:388 #: lib/pleroma/web/admin_api/controllers/admin_api_controller.ex:414 lib/pleroma/web/admin_api/controllers/admin_api_controller.ex:456 -#, elixir-format +#, elixir-format, fuzzy msgid "No such permission_group" -msgstr "" +msgstr "没有该权限组" #: lib/pleroma/plugs/uploaded_media.ex:84 #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:486 lib/pleroma/web/admin_api/controllers/fallback_controller.ex:11 #: lib/pleroma/web/feed/user_controller.ex:71 lib/pleroma/web/ostatus/ostatus_controller.ex:143 #, elixir-format msgid "Not found" -msgstr "" +msgstr "未找到" #: lib/pleroma/web/common_api/common_api.ex:331 #, elixir-format msgid "Poll's author can't vote" -msgstr "" +msgstr "投票的发起者不能投票" #: lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex:20 #: lib/pleroma/web/mastodon_api/controllers/poll_controller.ex:37 lib/pleroma/web/mastodon_api/controllers/poll_controller.ex:49 @@ -272,39 +272,39 @@ msgstr "" #: lib/pleroma/web/mastodon_api/controllers/subscription_controller.ex:71 #, elixir-format msgid "Record not found" -msgstr "" +msgstr "未找到该记录" #: lib/pleroma/web/admin_api/controllers/fallback_controller.ex:35 #: lib/pleroma/web/feed/user_controller.ex:77 lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex:36 #: lib/pleroma/web/ostatus/ostatus_controller.ex:149 #, elixir-format msgid "Something went wrong" -msgstr "" +msgstr "发生了一些错误" #: lib/pleroma/web/common_api/activity_draft.ex:107 #, elixir-format msgid "The message visibility must be direct" -msgstr "" +msgstr "该消息必须为私信" #: lib/pleroma/web/common_api/utils.ex:573 #, elixir-format msgid "The status is over the character limit" -msgstr "" +msgstr "状态超过了字符数限制" #: lib/pleroma/plugs/ensure_public_or_authenticated_plug.ex:31 #, elixir-format msgid "This resource requires authentication." -msgstr "" +msgstr "该资源需要认证。" #: lib/pleroma/plugs/rate_limiter/rate_limiter.ex:206 -#, elixir-format +#, elixir-format, fuzzy msgid "Throttled" -msgstr "" +msgstr "节流了" #: lib/pleroma/web/common_api/common_api.ex:356 #, elixir-format msgid "Too many choices" -msgstr "" +msgstr "太多选项" #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:443 #, elixir-format @@ -314,101 +314,101 @@ msgstr "" #: lib/pleroma/web/admin_api/controllers/admin_api_controller.ex:485 #, elixir-format msgid "You can't revoke your own admin status." -msgstr "" +msgstr "您不能撤消自己的管理员权限。" #: lib/pleroma/web/oauth/oauth_controller.ex:221 #: lib/pleroma/web/oauth/oauth_controller.ex:308 #, elixir-format msgid "Your account is currently disabled" -msgstr "" +msgstr "您的账户已被禁用" #: lib/pleroma/web/oauth/oauth_controller.ex:183 #: lib/pleroma/web/oauth/oauth_controller.ex:331 #, elixir-format msgid "Your login is missing a confirmed e-mail address" -msgstr "" +msgstr "您的账户缺少已认证的 e-mail 地址" #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:390 #, elixir-format msgid "can't read inbox of %{nickname} as %{as_nickname}" -msgstr "" +msgstr "无法以 %{as_nickname} 读取 %{nickname} 的收件箱" #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:473 #, elixir-format msgid "can't update outbox of %{nickname} as %{as_nickname}" -msgstr "" +msgstr "无法以 %{as_nickname} 更新 %{nickname} 的出件箱" #: lib/pleroma/web/common_api/common_api.ex:471 #, elixir-format msgid "conversation is already muted" -msgstr "" +msgstr "对话已经被静音" #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:314 #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:492 #, elixir-format msgid "error" -msgstr "" +msgstr "错误" #: lib/pleroma/web/pleroma_api/controllers/mascot_controller.ex:32 #, elixir-format msgid "mascots can only be images" -msgstr "" +msgstr "吉祥物只能是图片" #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:62 #, elixir-format msgid "not found" -msgstr "" +msgstr "未找到" #: lib/pleroma/web/oauth/oauth_controller.ex:394 #, elixir-format msgid "Bad OAuth request." -msgstr "" +msgstr "错误的 OAuth 请求。" #: lib/pleroma/web/twitter_api/twitter_api.ex:115 #, elixir-format msgid "CAPTCHA already used" -msgstr "" +msgstr "验证码已被使用" #: lib/pleroma/web/twitter_api/twitter_api.ex:112 #, elixir-format msgid "CAPTCHA expired" -msgstr "" +msgstr "验证码已过期" #: lib/pleroma/plugs/uploaded_media.ex:57 #, elixir-format msgid "Failed" -msgstr "" +msgstr "失败" #: lib/pleroma/web/oauth/oauth_controller.ex:410 -#, elixir-format +#, elixir-format, fuzzy msgid "Failed to authenticate: %{message}." -msgstr "" +msgstr "认证失败:%{message}。" #: lib/pleroma/web/oauth/oauth_controller.ex:441 #, elixir-format msgid "Failed to set up user account." -msgstr "" +msgstr "建立用户帐号失败。" #: lib/pleroma/plugs/oauth_scopes_plug.ex:38 #, elixir-format msgid "Insufficient permissions: %{permissions}." -msgstr "" +msgstr "权限不足:%{permissions}。" #: lib/pleroma/plugs/uploaded_media.ex:104 #, elixir-format msgid "Internal Error" -msgstr "" +msgstr "内部错误" #: lib/pleroma/web/oauth/fallback_controller.ex:22 #: lib/pleroma/web/oauth/fallback_controller.ex:29 #, elixir-format msgid "Invalid Username/Password" -msgstr "" +msgstr "无效的用户名/密码" #: lib/pleroma/web/twitter_api/twitter_api.ex:118 -#, elixir-format +#, elixir-format, fuzzy msgid "Invalid answer data" -msgstr "" +msgstr "无效的回答数据" #: lib/pleroma/web/nodeinfo/nodeinfo_controller.ex:33 #, elixir-format @@ -418,12 +418,12 @@ msgstr "" #: lib/pleroma/web/oauth/oauth_controller.ex:172 #, elixir-format msgid "This action is outside the authorized scopes" -msgstr "" +msgstr "此操作在许可范围以外" #: lib/pleroma/web/oauth/fallback_controller.ex:14 #, elixir-format msgid "Unknown error, please check the details and try again." -msgstr "" +msgstr "未知错误,请检查并重试。" #: lib/pleroma/web/oauth/oauth_controller.ex:119 #: lib/pleroma/web/oauth/oauth_controller.ex:158 @@ -434,53 +434,53 @@ msgstr "" #: lib/pleroma/web/oauth/oauth_controller.ex:390 #, elixir-format msgid "Unsupported OAuth provider: %{provider}." -msgstr "" +msgstr "不支持的 OAuth 提供者:%{provider}。" #: lib/pleroma/uploaders/uploader.ex:72 -#, elixir-format +#, elixir-format, fuzzy msgid "Uploader callback timeout" -msgstr "" +msgstr "上传回复超时" #: lib/pleroma/web/uploader_controller.ex:23 #, elixir-format msgid "bad request" -msgstr "" +msgstr "错误的请求" #: lib/pleroma/web/twitter_api/twitter_api.ex:103 #, elixir-format msgid "CAPTCHA Error" -msgstr "" +msgstr "验证码错误" #: lib/pleroma/web/common_api/common_api.ex:290 -#, elixir-format +#, elixir-format, fuzzy msgid "Could not add reaction emoji" -msgstr "" +msgstr "无法添加表情反应" #: lib/pleroma/web/common_api/common_api.ex:301 #, elixir-format msgid "Could not remove reaction emoji" -msgstr "" +msgstr "无法移除表情反应" #: lib/pleroma/web/twitter_api/twitter_api.ex:129 #, elixir-format msgid "Invalid CAPTCHA (Missing parameter: %{name})" -msgstr "" +msgstr "无效的验证码(缺少参数:%{name})" #: lib/pleroma/web/mastodon_api/controllers/list_controller.ex:92 #, elixir-format msgid "List not found" -msgstr "" +msgstr "未找到列表" #: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:123 #, elixir-format msgid "Missing parameter: %{name}" -msgstr "" +msgstr "缺少参数:%{name}" #: lib/pleroma/web/oauth/oauth_controller.ex:210 #: lib/pleroma/web/oauth/oauth_controller.ex:321 #, elixir-format msgid "Password reset is required" -msgstr "" +msgstr "需要重置密码" #: lib/pleroma/tests/auth_test_controller.ex:9 #: lib/pleroma/web/activity_pub/activity_pub_controller.ex:6 lib/pleroma/web/admin_api/controllers/admin_api_controller.ex:6 @@ -520,61 +520,61 @@ msgid "Security violation: OAuth scopes check was neither handled nor explicitly msgstr "" #: lib/pleroma/plugs/ensure_authenticated_plug.ex:28 -#, elixir-format +#, elixir-format, fuzzy msgid "Two-factor authentication enabled, you must use a access token." -msgstr "" +msgstr "已启用两因素验证,您需要使用访问令牌。" #: lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex:210 #, elixir-format msgid "Unexpected error occurred while adding file to pack." -msgstr "" +msgstr "向表情包添加文件时发生了没有预料到的错误。" #: lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex:138 #, elixir-format msgid "Unexpected error occurred while creating pack." -msgstr "" +msgstr "创建表情包时发生了没有预料到的错误。" #: lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex:278 #, elixir-format msgid "Unexpected error occurred while removing file from pack." -msgstr "" +msgstr "从表情包移除文件时发生了没有预料到的错误。" #: lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex:250 #, elixir-format msgid "Unexpected error occurred while updating file in pack." -msgstr "" +msgstr "更新表情包内的文件时发生了没有预料到的错误。" #: lib/pleroma/web/pleroma_api/controllers/emoji_pack_controller.ex:179 #, elixir-format msgid "Unexpected error occurred while updating pack metadata." -msgstr "" +msgstr "更新表情包元数据时发生了没有预料到的错误。" #: lib/pleroma/web/mastodon_api/controllers/subscription_controller.ex:61 -#, elixir-format +#, elixir-format, fuzzy msgid "Web push subscription is disabled on this Pleroma instance" -msgstr "" +msgstr "此 Pleroma 实例禁用了网页推送订阅" #: lib/pleroma/web/admin_api/controllers/admin_api_controller.ex:451 #, elixir-format msgid "You can't revoke your own admin/moderator status." -msgstr "" +msgstr "您不能撤消自己的管理员权限。" #: lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex:126 #, elixir-format msgid "authorization required for timeline view" -msgstr "" +msgstr "浏览时间线需要认证" #: lib/pleroma/web/mastodon_api/controllers/fallback_controller.ex:24 #, elixir-format msgid "Access denied" -msgstr "" +msgstr "拒绝访问" #: lib/pleroma/web/mastodon_api/controllers/account_controller.ex:282 #, elixir-format msgid "This API requires an authenticated user" -msgstr "" +msgstr "此 API 需要已认证的用户" #: lib/pleroma/plugs/user_is_admin_plug.ex:21 #, elixir-format msgid "User is not an admin." -msgstr "" +msgstr "该用户不是管理员。" diff --git a/priv/repo/migrations/20201217172858_data_migration_prolong_o_auth_tokens_valid_until.exs b/priv/repo/migrations/20201217172858_data_migration_prolong_o_auth_tokens_valid_until.exs new file mode 100644 index 000000000..560cc7447 --- /dev/null +++ b/priv/repo/migrations/20201217172858_data_migration_prolong_o_auth_tokens_valid_until.exs @@ -0,0 +1,13 @@ +defmodule Pleroma.Repo.Migrations.DataMigrationProlongOAuthTokensValidUntil do + use Ecto.Migration + + def up do + expires_in = Pleroma.Config.get!([:oauth2, :token_expires_in]) + valid_until = NaiveDateTime.add(NaiveDateTime.utc_now(), expires_in, :second) + execute("update oauth_tokens set valid_until = '#{valid_until}'") + end + + def down do + :noop + end +end diff --git a/priv/repo/migrations/20201231185546_confirm_logged_in_users.exs b/priv/repo/migrations/20201231185546_confirm_logged_in_users.exs new file mode 100644 index 000000000..de2f35169 --- /dev/null +++ b/priv/repo/migrations/20201231185546_confirm_logged_in_users.exs @@ -0,0 +1,22 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.ConfirmLoggedInUsers do + use Ecto.Migration + import Ecto.Query + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Web.OAuth.Token + + def up do + User + |> where([u], u.confirmation_pending == true) + |> join(:inner, [u], t in Token, on: t.user_id == u.id) + |> Repo.update_all(set: [confirmation_pending: false]) + end + + def down do + :noop + end +end diff --git a/priv/static/emoji/dino walking.gif b/priv/static/emoji/dino walking.gif new file mode 100644 index 000000000..694a541e7 Binary files /dev/null and b/priv/static/emoji/dino walking.gif differ diff --git a/priv/static/images/logo.png b/priv/static/images/logo.png new file mode 100644 index 000000000..7744b1acc Binary files /dev/null and b/priv/static/images/logo.png differ diff --git a/priv/templates/sample_config.eex b/priv/templates/sample_config.eex index cdddc47ea..2f5952ef1 100644 --- a/priv/templates/sample_config.eex +++ b/priv/templates/sample_config.eex @@ -32,8 +32,7 @@ config :pleroma, Pleroma.Repo, username: "<%= dbuser %>", password: "<%= dbpass %>", database: "<%= dbname %>", - hostname: "<%= dbhost %>", - pool_size: 10 + hostname: "<%= dbhost %>" # Configure web push notifications config :web_push_encryption, :vapid_details, diff --git a/test/fixtures/guppe-actor.json b/test/fixtures/guppe-actor.json new file mode 100644 index 000000000..d5829ee1f --- /dev/null +++ b/test/fixtures/guppe-actor.json @@ -0,0 +1,26 @@ +{ + "@context" : [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1" + ], + "followers" : "https://gup.pe/u/bernie2020/followers", + "following" : "https://gup.pe/u/bernie2020/following", + "icon" : { + "mediaType" : "image/jpeg", + "type" : "Image", + "url" : "https://gup.pe/f/guppe.png" + }, + "id" : "https://gup.pe/u/bernie2020", + "inbox" : "https://gup.pe/u/bernie2020/inbox", + "liked" : "https://gup.pe/u/bernie2020/liked", + "name" : "Bernie2020 group", + "outbox" : "https://gup.pe/u/bernie2020/outbox", + "preferredUsername" : "Bernie2020", + "publicKey" : { + "id" : "https://gup.pe/u/bernie2020#main-key", + "owner" : "https://gup.pe/u/bernie2020", + "publicKeyPem" : "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAw4J8nSrdWWxFaipgWDhR\nbTFzHUGoFy7Gjdc6gg9ZWGWDm9ZU5Ct0C/4o72dXSWdyLbQGYMbWVHLI1LHWKSiC\nVtwIYoccQBaxfi5bCxsahWhhSNPfK8tVlySHvBy73ir8KUZm93eAYh1iE9x+Dk63\nInmi7wzjsqHSlu1KxPGYcnyxs+xxhlTUSd5LsPfO1b9sHMW+X4rEky7OC90veCdD\nsoHU+nCmf+2zJSlOrU7DAzqB4Axc9oS9Q5RlT3yARJQMeu6JyjJJP9CMbpGFbUNT\n5Gsw0km1Rc1rR4tUoz8pLUYtliEUK+/0EmHi2EHAT1ueEfMoGGbCaX/mCoMmAwYJ\nwIGYXmKn2/ARIJpw2XPmrKWXqa2AndOQdb3l44Sl3ej2rC/JQmimGCn7tbfKEZyC\n6mMkOYTIeBtyW/wXFc1+GzJxtvA3C9HjilE+O/7gLHfCLP6FRIxg/9kOLhEj64Ed\n5HZ3sylvifXXubS/lLZr6sZW6d9ICoYLZpFw9AoF2zaYWpvJqBrWinnCJzvbMCYj\nfq/RAkcQYSxkDOHquiGgbRZHGAMKLnz5fMKJIzBtdQojYCUmB14OArW+ITUE9i2a\nPAJaXEGZ+BHYp/0ScFaXwp5LIgT1S+sPKxWJU//77wQfs25i7NZHSN/jtXVmsFS6\nLFVw49LcWAz3J2Im+A+uSd8CAwEAAQ==\n-----END PUBLIC KEY-----\n" + }, + "summary" : "I'm a group about Bernie2020. Follow me to get all the group posts. Tag me to share with the group. Create other groups by searching for or tagging @yourGroupName@gup.pe", + "type" : "Group" +} diff --git a/test/mix/tasks/pleroma/count_statuses_test.exs b/test/mix/tasks/pleroma/count_statuses_test.exs index c5cd16960..8fe3959ea 100644 --- a/test/mix/tasks/pleroma/count_statuses_test.exs +++ b/test/mix/tasks/pleroma/count_statuses_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.CountStatusesTest do + # Uses log capture, has to stay synchronous use Pleroma.DataCase alias Pleroma.User diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs index a4bd41922..eefb12426 100644 --- a/test/mix/tasks/pleroma/database_test.exs +++ b/test/mix/tasks/pleroma/database_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.DatabaseTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true use Oban.Testing, repo: Pleroma.Repo alias Pleroma.Activity @@ -87,7 +87,8 @@ test "following and followers count are updated" do assert user.follower_count == 3 - assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"]) + assert {:ok, :ok} == + Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"]) user = User.get_by_id(user.id) diff --git a/test/mix/tasks/pleroma/ecto/migrate_test.exs b/test/mix/tasks/pleroma/ecto/migrate_test.exs index 43df176a1..548357508 100644 --- a/test/mix/tasks/pleroma/ecto/migrate_test.exs +++ b/test/mix/tasks/pleroma/ecto/migrate_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-onl defmodule Mix.Tasks.Pleroma.Ecto.MigrateTest do - use Pleroma.DataCase, async: true + use Pleroma.DataCase import ExUnit.CaptureLog require Logger diff --git a/test/mix/tasks/pleroma/ecto/rollback_test.exs b/test/mix/tasks/pleroma/ecto/rollback_test.exs index 0236e35d5..9e39db8fa 100644 --- a/test/mix/tasks/pleroma/ecto/rollback_test.exs +++ b/test/mix/tasks/pleroma/ecto/rollback_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.Ecto.RollbackTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import ExUnit.CaptureLog require Logger diff --git a/test/mix/tasks/pleroma/instance_test.exs b/test/mix/tasks/pleroma/instance_test.exs index 6580fc932..1d2dde108 100644 --- a/test/mix/tasks/pleroma/instance_test.exs +++ b/test/mix/tasks/pleroma/instance_test.exs @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.InstanceTest do - use ExUnit.Case + # Modifies the Application Environment, has to stay synchronous. + use Pleroma.DataCase setup do File.mkdir_p!(tmp_path()) @@ -15,15 +16,17 @@ defmodule Mix.Tasks.Pleroma.InstanceTest do if File.exists?(static_dir) do File.rm_rf(Path.join(static_dir, "robots.txt")) end - - Pleroma.Config.put([:instance, :static_dir], static_dir) end) + # Is being modified by the mix task. + clear_config([:instance, :static_dir]) + :ok end + @uuid Ecto.UUID.generate() defp tmp_path do - "/tmp/generated_files/" + "/tmp/generated_files/#{@uuid}/" end test "running gen" do diff --git a/test/mix/tasks/pleroma/refresh_counter_cache_test.exs b/test/mix/tasks/pleroma/refresh_counter_cache_test.exs index 6a1a9ac17..e79dc0632 100644 --- a/test/mix/tasks/pleroma/refresh_counter_cache_test.exs +++ b/test/mix/tasks/pleroma/refresh_counter_cache_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Mix.Tasks.Pleroma.RefreshCounterCacheTest do + # Uses log capture, has to stay synchronous use Pleroma.DataCase alias Pleroma.Web.CommonAPI import ExUnit.CaptureIO, only: [capture_io: 1] diff --git a/test/mix/tasks/pleroma/relay_test.exs b/test/mix/tasks/pleroma/relay_test.exs index cf48e7dda..b453ed1c6 100644 --- a/test/mix/tasks/pleroma/relay_test.exs +++ b/test/mix/tasks/pleroma/relay_test.exs @@ -100,7 +100,7 @@ test "unfollow when relay is dead" do end) Pleroma.Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance]) @@ -137,7 +137,7 @@ test "force unfollow when relay is dead" do end) Pleroma.Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance, "--force"]) diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs index 127771212..9f898d8f3 100644 --- a/test/mix/tasks/pleroma/user_test.exs +++ b/test/mix/tasks/pleroma/user_test.exs @@ -114,7 +114,7 @@ test "a remote user's create activity is deleted when the object has been pruned {:ok, post} = CommonAPI.post(user, %{status: "uguu"}) {:ok, post2} = CommonAPI.post(user2, %{status: "test"}) - obj = Object.normalize(post2) + obj = Object.normalize(post2, fetch: false) {:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj) @@ -130,7 +130,7 @@ test "a remote user's create activity is deleted when the object has been pruned clear_config([:instance, :federating], true) - object = Object.normalize(post) + object = Object.normalize(post, fetch: false) Object.prune(object) with_mock Pleroma.Web.Federator, @@ -462,24 +462,24 @@ test "it prints an error message when user is not exist" do end end - describe "running toggle_confirmed" do + describe "running confirm" do test "user is confirmed" do %{id: id, nickname: nickname} = insert(:user, confirmation_pending: false) - assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname]) + assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname]) assert_received {:mix_shell, :info, [message]} - assert message == "#{nickname} needs confirmation." + assert message == "#{nickname} doesn't need confirmation." user = Repo.get(User, id) - assert user.confirmation_pending - assert user.confirmation_token + refute user.confirmation_pending + refute user.confirmation_token end test "user is not confirmed" do %{id: id, nickname: nickname} = insert(:user, confirmation_pending: true, confirmation_token: "some token") - assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname]) + assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname]) assert_received {:mix_shell, :info, [message]} assert message == "#{nickname} doesn't need confirmation." @@ -489,7 +489,7 @@ test "user is not confirmed" do end test "it prints an error message when user is not exist" do - Mix.Tasks.Pleroma.User.run(["toggle_confirmed", "foo"]) + Mix.Tasks.Pleroma.User.run(["confirm", "foo"]) assert_received {:mix_shell, :error, [message]} assert message =~ "No local user" diff --git a/test/pleroma/activity/ir/topics_test.exs b/test/pleroma/activity/ir/topics_test.exs index 5e5c2f8da..b464822d9 100644 --- a/test/pleroma/activity/ir/topics_test.exs +++ b/test/pleroma/activity/ir/topics_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Activity.Ir.TopicsTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Activity.Ir.Topics diff --git a/test/pleroma/activity/search_test.exs b/test/pleroma/activity/search_test.exs index fc910e725..49b7aa292 100644 --- a/test/pleroma/activity/search_test.exs +++ b/test/pleroma/activity/search_test.exs @@ -7,7 +7,7 @@ defmodule Pleroma.Activity.SearchTest do alias Pleroma.Web.CommonAPI import Pleroma.Factory - use Pleroma.DataCase + use Pleroma.DataCase, async: true test "it finds something" do user = insert(:user) diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs index 105f9f766..acaa9adb4 100644 --- a/test/pleroma/activity_test.exs +++ b/test/pleroma/activity_test.exs @@ -25,7 +25,7 @@ test "returns an activity by it's AP id" do test "returns activities by it's objects AP ids" do activity = insert(:note_activity) - object_data = Object.normalize(activity).data + object_data = Object.normalize(activity, fetch: false).data [found_activity] = Activity.get_all_create_by_object_ap_id(object_data["id"]) @@ -34,7 +34,7 @@ test "returns activities by it's objects AP ids" do test "returns the activity that created an object" do activity = insert(:note_activity) - object_data = Object.normalize(activity).data + object_data = Object.normalize(activity, fetch: false).data found_activity = Activity.get_create_by_object_ap_id(object_data["id"]) diff --git a/test/pleroma/application_requirements_test.exs b/test/pleroma/application_requirements_test.exs index b432dbc37..e3cca5487 100644 --- a/test/pleroma/application_requirements_test.exs +++ b/test/pleroma/application_requirements_test.exs @@ -15,6 +15,7 @@ defmodule Pleroma.ApplicationRequirementsTest do describe "check_repo_pool_size!/1" do test "raises if the pool size is unexpected" do clear_config([Pleroma.Repo, :pool_size], 11) + clear_config([:dangerzone, :override_repo_pool_size], false) assert_raise Pleroma.ApplicationRequirements.VerifyError, "Repo.pool_size different than recommended value.", diff --git a/test/pleroma/bbs/handler_test.exs b/test/pleroma/bbs/handler_test.exs index e605c2726..8033828f0 100644 --- a/test/pleroma/bbs/handler_test.exs +++ b/test/pleroma/bbs/handler_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.BBS.HandlerTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.BBS.Handler alias Pleroma.Object @@ -54,7 +54,7 @@ test "posting" do ) assert activity.actor == user.ap_id - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "this is a test post" end @@ -63,7 +63,7 @@ test "replying" do another_user = insert(:user) {:ok, activity} = CommonAPI.post(another_user, %{status: "this is a test post"}) - activity_object = Object.normalize(activity) + activity_object = Object.normalize(activity, fetch: false) output = capture_io(fn -> @@ -82,7 +82,7 @@ test "replying" do assert reply.actor == user.ap_id - reply_object_data = Object.normalize(reply).data + reply_object_data = Object.normalize(reply, fetch: false).data assert reply_object_data["content"] == "this is a reply" assert reply_object_data["inReplyTo"] == activity_object.data["id"] end diff --git a/test/pleroma/bookmark_test.exs b/test/pleroma/bookmark_test.exs index 2726fe7cd..ef090d785 100644 --- a/test/pleroma/bookmark_test.exs +++ b/test/pleroma/bookmark_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.BookmarkTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Bookmark alias Pleroma.Web.CommonAPI diff --git a/test/pleroma/captcha_test.exs b/test/pleroma/captcha_test.exs index 1b9f4a12f..bde3c72f7 100644 --- a/test/pleroma/captcha_test.exs +++ b/test/pleroma/captcha_test.exs @@ -80,7 +80,6 @@ test "validate" do assert is_binary(answer) assert :ok = Captcha.validate(token, "63615261b77f5354fb8c4e4986477555", answer) - Cachex.del(:used_captcha_cache, token) end test "doesn't validate invalid answer" do diff --git a/test/pleroma/chat_test.exs b/test/pleroma/chat_test.exs index 9e8a9ebf0..1dd04916c 100644 --- a/test/pleroma/chat_test.exs +++ b/test/pleroma/chat_test.exs @@ -73,7 +73,8 @@ test "a returning chat will have an updated `update_at` field" do other_user = insert(:user) {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id) - :timer.sleep(1500) + {:ok, chat} = time_travel(chat, -2) + {:ok, chat_two} = Chat.bump_or_create(user.id, other_user.ap_id) assert chat.id == chat_two.id diff --git a/test/pleroma/config_test.exs b/test/pleroma/config_test.exs index 1556e4237..f524d90dd 100644 --- a/test/pleroma/config_test.exs +++ b/test/pleroma/config_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ConfigTest do - use ExUnit.Case + use Pleroma.DataCase test "get/1 with an atom" do assert Pleroma.Config.get(:instance) == Application.get_env(:pleroma, :instance) diff --git a/test/pleroma/conversation/participation_test.exs b/test/pleroma/conversation/participation_test.exs index 5a603dcc1..917fb2b98 100644 --- a/test/pleroma/conversation/participation_test.exs +++ b/test/pleroma/conversation/participation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Conversation.ParticipationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Conversation alias Pleroma.Conversation.Participation @@ -96,12 +96,11 @@ test "it creates a participation for a conversation and a user" do {:ok, %Participation{} = participation} = Participation.create_for_user_and_conversation(user, conversation) + {:ok, participation} = time_travel(participation, -2) + assert participation.user_id == user.id assert participation.conversation_id == conversation.id - # Needed because updated_at is accurate down to a second - :timer.sleep(1000) - # Creating again returns the same participation {:ok, %Participation{} = participation_two} = Participation.create_for_user_and_conversation(user, conversation) @@ -176,8 +175,8 @@ test "gets all the participations for a user, ordered by updated at descending" assert [participation_one, participation_two] = Participation.for_user(user) - object2 = Pleroma.Object.normalize(activity_two) - object3 = Pleroma.Object.normalize(activity_three) + object2 = Pleroma.Object.normalize(activity_two, fetch: false) + object3 = Pleroma.Object.normalize(activity_three, fetch: false) user = Repo.get(Pleroma.User, user.id) diff --git a/test/pleroma/conversation_test.exs b/test/pleroma/conversation_test.exs index 359aa6840..4643140dc 100644 --- a/test/pleroma/conversation_test.exs +++ b/test/pleroma/conversation_test.exs @@ -48,7 +48,7 @@ test "public posts don't create conversations" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "Hey"}) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation = Conversation.get_for_ap_id(context) @@ -64,7 +64,7 @@ test "it creates or updates a conversation and participations for a given DM" do {:ok, activity} = CommonAPI.post(har, %{status: "Hey @#{jafnhar.nickname}", visibility: "direct"}) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation = @@ -86,7 +86,7 @@ test "it creates or updates a conversation and participations for a given DM" do in_reply_to_status_id: activity.id }) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation_two = @@ -110,7 +110,7 @@ test "it creates or updates a conversation and participations for a given DM" do in_reply_to_status_id: activity.id }) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) context = object.data["context"] conversation_three = diff --git a/test/pleroma/earmark_renderer_test.exs b/test/pleroma/earmark_renderer_test.exs index 220d97d16..73aaec7f4 100644 --- a/test/pleroma/earmark_renderer_test.exs +++ b/test/pleroma/earmark_renderer_test.exs @@ -2,7 +2,7 @@ # Copyright © 2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.EarmarkRendererTest do - use ExUnit.Case + use Pleroma.DataCase, async: true test "Paragraph" do code = ~s[Hello\n\nWorld!] diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs index 812463454..a8471e2e3 100644 --- a/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs +++ b/test/pleroma/ecto_type/activity_pub/object_validators/date_time_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.DateTimeTest do alias Pleroma.EctoType.ActivityPub.ObjectValidators.DateTime - use Pleroma.DataCase + use Pleroma.DataCase, async: true test "it validates an xsd:Datetime" do valid_strings = [ diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs index 732e2365f..3b6006854 100644 --- a/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs +++ b/test/pleroma/ecto_type/activity_pub/object_validators/object_id_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectIDTest do alias Pleroma.EctoType.ActivityPub.ObjectValidators.ObjectID - use Pleroma.DataCase + use Pleroma.DataCase, async: true @uris [ "http://lain.com/users/lain", diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs index 2e6a0c83d..b7eb59ab0 100644 --- a/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs +++ b/test/pleroma/ecto_type/activity_pub/object_validators/recipients_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.RecipientsTest do alias Pleroma.EctoType.ActivityPub.ObjectValidators.Recipients - use Pleroma.DataCase + use Pleroma.DataCase, async: true test "it asserts that all elements of the list are object ids" do list = ["https://lain.com/users/lain", "invalid"] diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs b/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs index 7eddd2388..154363f68 100644 --- a/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs +++ b/test/pleroma/ecto_type/activity_pub/object_validators/safe_text_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.SafeTextTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.EctoType.ActivityPub.ObjectValidators.SafeText diff --git a/test/pleroma/emails/admin_email_test.exs b/test/pleroma/emails/admin_email_test.exs index 0da0699cc..9aaf7b04f 100644 --- a/test/pleroma/emails/admin_email_test.exs +++ b/test/pleroma/emails/admin_email_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Emails.AdminEmailTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Emails.AdminEmail diff --git a/test/pleroma/emails/user_email_test.exs b/test/pleroma/emails/user_email_test.exs index a75623bb4..bd21d8dec 100644 --- a/test/pleroma/emails/user_email_test.exs +++ b/test/pleroma/emails/user_email_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Emails.UserEmailTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Emails.UserEmail alias Pleroma.Web.Endpoint @@ -45,4 +45,15 @@ test "build account confirmation email" do assert email.html_body =~ Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token") end + + test "build approval pending email" do + config = Pleroma.Config.get(:instance) + user = insert(:user) + email = UserEmail.approval_pending_email(user) + + assert email.from == {config[:name], config[:notify_email]} + assert email.to == [{user.name, user.email}] + assert email.subject == "Your account is awaiting approval" + assert email.html_body =~ "Awaiting Approval" + end end diff --git a/test/pleroma/emoji/formatter_test.exs b/test/pleroma/emoji/formatter_test.exs index 12af6cd8b..096d23ca6 100644 --- a/test/pleroma/emoji/formatter_test.exs +++ b/test/pleroma/emoji/formatter_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Emoji.FormatterTest do alias Pleroma.Emoji.Formatter - use Pleroma.DataCase + use Pleroma.DataCase, async: true describe "emojify" do test "it adds cool emoji" do diff --git a/test/pleroma/emoji/pack_test.exs b/test/pleroma/emoji/pack_test.exs index 70d1eaa1b..158dfee06 100644 --- a/test/pleroma/emoji/pack_test.exs +++ b/test/pleroma/emoji/pack_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Emoji.PackTest do - use ExUnit.Case, async: true + use Pleroma.DataCase alias Pleroma.Emoji.Pack @emoji_path Path.join( diff --git a/test/pleroma/emoji_test.exs b/test/pleroma/emoji_test.exs index 9cfd7b46b..c99c9ef4c 100644 --- a/test/pleroma/emoji_test.exs +++ b/test/pleroma/emoji_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.EmojiTest do - use ExUnit.Case + use ExUnit.Case, async: true alias Pleroma.Emoji describe "is_unicode_emoji?/1" do diff --git a/test/pleroma/filter_test.exs b/test/pleroma/filter_test.exs index 0a5c4426a..da9515902 100644 --- a/test/pleroma/filter_test.exs +++ b/test/pleroma/filter_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.FilterTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/following_relationship_test.exs b/test/pleroma/following_relationship_test.exs index 17a468abb..f0d2c3846 100644 --- a/test/pleroma/following_relationship_test.exs +++ b/test/pleroma/following_relationship_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.FollowingRelationshipTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.FollowingRelationship alias Pleroma.Web.ActivityPub.InternalFetchActor diff --git a/test/pleroma/healthcheck_test.exs b/test/pleroma/healthcheck_test.exs index e341e6983..a1bc25d25 100644 --- a/test/pleroma/healthcheck_test.exs +++ b/test/pleroma/healthcheck_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HealthcheckTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Healthcheck test "system_info/0" do diff --git a/test/pleroma/html_test.exs b/test/pleroma/html_test.exs index 7d3756884..3a926f077 100644 --- a/test/pleroma/html_test.exs +++ b/test/pleroma/html_test.exs @@ -6,7 +6,7 @@ defmodule Pleroma.HTMLTest do alias Pleroma.HTML alias Pleroma.Object alias Pleroma.Web.CommonAPI - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory @@ -175,7 +175,7 @@ test "extracts the url" do "I think I just found the best github repo https://github.com/komeiji-satori/Dress" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://github.com/komeiji-satori/Dress" end @@ -190,7 +190,7 @@ test "skips mentions" do "@#{other_user.nickname} install misskey! https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://github.com/syuilo/misskey/blob/develop/docs/setup.en.md" @@ -206,7 +206,7 @@ test "skips hashtags" do status: "#cofe https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" @@ -222,7 +222,7 @@ test "skips microformats hashtags" do content_type: "text/html" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, url} = HTML.extract_first_external_url_from_object(object) assert url == "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72255140" @@ -233,7 +233,7 @@ test "does not crash when there is an HTML entity in a link" do {:ok, activity} = CommonAPI.post(user, %{status: "\"http://cofe.com/?boomer=ok&foo=bar\""}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert {:ok, nil} = HTML.extract_first_external_url_from_object(object) end @@ -247,7 +247,7 @@ test "skips attachment links" do "image.png" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert {:ok, nil} = HTML.extract_first_external_url_from_object(object) end diff --git a/test/pleroma/http/adapter_helper/gun_test.exs b/test/pleroma/http/adapter_helper/gun_test.exs index 80589c73d..487d2e7c1 100644 --- a/test/pleroma/http/adapter_helper/gun_test.exs +++ b/test/pleroma/http/adapter_helper/gun_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.AdapterHelper.GunTest do - use ExUnit.Case, async: true + use ExUnit.Case use Pleroma.Tests.Helpers import Mox diff --git a/test/pleroma/integration/mastodon_websocket_test.exs b/test/pleroma/integration/mastodon_websocket_test.exs index bb8e795b7..4a7dbda71 100644 --- a/test/pleroma/integration/mastodon_websocket_test.exs +++ b/test/pleroma/integration/mastodon_websocket_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Integration.MastodonWebsocketTest do + # Needs a streamer, needs to stay synchronous use Pleroma.DataCase import ExUnit.CaptureLog diff --git a/test/pleroma/keys_test.exs b/test/pleroma/keys_test.exs index 9e8528cba..55a7aa1bc 100644 --- a/test/pleroma/keys_test.exs +++ b/test/pleroma/keys_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.KeysTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Keys diff --git a/test/pleroma/list_test.exs b/test/pleroma/list_test.exs index b5572cbae..854e276f1 100644 --- a/test/pleroma/list_test.exs +++ b/test/pleroma/list_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.ListTest do alias Pleroma.Repo - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/marker_test.exs b/test/pleroma/marker_test.exs index 7b3943c7b..3055f1ce2 100644 --- a/test/pleroma/marker_test.exs +++ b/test/pleroma/marker_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.MarkerTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Marker import Pleroma.Factory diff --git a/test/pleroma/mfa/backup_codes_test.exs b/test/pleroma/mfa/backup_codes_test.exs index 41adb1e96..c3eaf40b6 100644 --- a/test/pleroma/mfa/backup_codes_test.exs +++ b/test/pleroma/mfa/backup_codes_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.MFA.BackupCodesTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.MFA.BackupCodes diff --git a/test/pleroma/mfa/totp_test.exs b/test/pleroma/mfa/totp_test.exs index 9edb6fd54..8c09bf447 100644 --- a/test/pleroma/mfa/totp_test.exs +++ b/test/pleroma/mfa/totp_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.MFA.TOTPTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.MFA.TOTP diff --git a/test/pleroma/mfa_test.exs b/test/pleroma/mfa_test.exs index 8875cefd9..cd1f7d0af 100644 --- a/test/pleroma/mfa_test.exs +++ b/test/pleroma/mfa_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.MFATest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.MFA diff --git a/test/pleroma/migration_helper/notification_backfill_test.exs b/test/pleroma/migration_helper/notification_backfill_test.exs index 2a62a2b00..6fe8a11ac 100644 --- a/test/pleroma/migration_helper/notification_backfill_test.exs +++ b/test/pleroma/migration_helper/notification_backfill_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.MigrationHelper.NotificationBackfillTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.MigrationHelper.NotificationBackfill diff --git a/test/pleroma/moderation_log_test.exs b/test/pleroma/moderation_log_test.exs index 03b32a060..d1e0e1e6b 100644 --- a/test/pleroma/moderation_log_test.exs +++ b/test/pleroma/moderation_log_test.exs @@ -6,7 +6,7 @@ defmodule Pleroma.ModerationLogTest do alias Pleroma.Activity alias Pleroma.ModerationLog - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/object_test.exs b/test/pleroma/object_test.exs index 5d4e6fb84..fe7f37e7c 100644 --- a/test/pleroma/object_test.exs +++ b/test/pleroma/object_test.exs @@ -256,23 +256,22 @@ test "With custom base_url" do end describe "normalizer" do - test "fetches unknown objects by default" do - %Object{} = - object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367") - - assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367" + @url "http://mastodon.example.org/@admin/99541947525187367" + test "does not fetch unknown objects by default" do + assert nil == Object.normalize(@url) end - test "fetches unknown objects when fetch_remote is explicitly true" do - %Object{} = - object = Object.normalize("http://mastodon.example.org/@admin/99541947525187367", true) + test "fetches unknown objects when fetch is explicitly true" do + %Object{} = object = Object.normalize(@url, fetch: true) - assert object.data["url"] == "http://mastodon.example.org/@admin/99541947525187367" + assert object.data["url"] == @url end - test "does not fetch unknown objects when fetch_remote is false" do + test "does not fetch unknown objects when fetch is false" do assert is_nil( - Object.normalize("http://mastodon.example.org/@admin/99541947525187367", false) + Object.normalize(@url, + fetch: false + ) ) end end @@ -310,7 +309,10 @@ test "refetches if the time since the last refetch is greater than the interval" mock_modified: mock_modified } do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) @@ -332,7 +334,10 @@ test "refetches if the time since the last refetch is greater than the interval" test "returns the old object if refetch fails", %{mock_modified: mock_modified} do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) @@ -355,7 +360,10 @@ test "does not refetch if the time since the last refetch is greater than the in mock_modified: mock_modified } do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) @@ -377,7 +385,10 @@ test "does not refetch if the time since the last refetch is greater than the in test "preserves internal fields on refetch", %{mock_modified: mock_modified} do %Object{} = - object = Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d") + object = + Object.normalize("https://patch.cx/objects/9a172665-2bc5-452d-8428-2361d4c33b1d", + fetch: true + ) Object.set_cache(object) diff --git a/test/pleroma/pagination_test.exs b/test/pleroma/pagination_test.exs index e526f23e8..5ee1e60ae 100644 --- a/test/pleroma/pagination_test.exs +++ b/test/pleroma/pagination_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.PaginationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/registration_test.exs b/test/pleroma/registration_test.exs index 7db8e3664..462ab452b 100644 --- a/test/pleroma/registration_test.exs +++ b/test/pleroma/registration_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.RegistrationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs b/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs new file mode 100644 index 000000000..f1fd89113 --- /dev/null +++ b/test/pleroma/repo/migrations/confirm_logged_in_users_test.exs @@ -0,0 +1,40 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Repo.Migrations.ConfirmLoggedInUsersTest do + alias Pleroma.Repo + alias Pleroma.User + use Pleroma.DataCase, async: true + import Ecto.Query + import Pleroma.Factory + import Pleroma.Tests.Helpers + + setup_all do: require_migration("20201231185546_confirm_logged_in_users") + + test "up/0 confirms unconfirmed but previously-logged-in users", %{migration: migration} do + insert_list(25, :oauth_token) + Repo.update_all(User, set: [confirmation_pending: true]) + insert_list(5, :user, confirmation_pending: true) + + count = + User + |> where(confirmation_pending: true) + |> Repo.aggregate(:count) + + assert count == 30 + + assert {25, nil} == migration.up() + + count = + User + |> where(confirmation_pending: true) + |> Repo.aggregate(:count) + + assert count == 5 + end + + test "down/0 does nothing", %{migration: migration} do + assert :noop == migration.down() + end +end diff --git a/test/pleroma/repo/migrations/fix_legacy_tags_test.exs b/test/pleroma/repo/migrations/fix_legacy_tags_test.exs index 432055e45..adfed1142 100644 --- a/test/pleroma/repo/migrations/fix_legacy_tags_test.exs +++ b/test/pleroma/repo/migrations/fix_legacy_tags_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do alias Pleroma.User - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory import Pleroma.Tests.Helpers diff --git a/test/pleroma/repo/migrations/move_welcome_settings_test.exs b/test/pleroma/repo/migrations/move_welcome_settings_test.exs index 53d05a55a..5dbe9d7b0 100644 --- a/test/pleroma/repo/migrations/move_welcome_settings_test.exs +++ b/test/pleroma/repo/migrations/move_welcome_settings_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory import Pleroma.Tests.Helpers alias Pleroma.ConfigDB diff --git a/test/pleroma/repo_test.exs b/test/pleroma/repo_test.exs index 155791be2..eaddef3a6 100644 --- a/test/pleroma/repo_test.exs +++ b/test/pleroma/repo_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.RepoTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.User diff --git a/test/pleroma/report_note_test.exs b/test/pleroma/report_note_test.exs index 25c1d6a61..cc4561eea 100644 --- a/test/pleroma/report_note_test.exs +++ b/test/pleroma/report_note_test.exs @@ -4,7 +4,7 @@ defmodule Pleroma.ReportNoteTest do alias Pleroma.ReportNote - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory test "create/3" do diff --git a/test/pleroma/reverse_proxy_test.exs b/test/pleroma/reverse_proxy_test.exs index 8df63de65..0a2c169ce 100644 --- a/test/pleroma/reverse_proxy_test.exs +++ b/test/pleroma/reverse_proxy_test.exs @@ -3,8 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ReverseProxyTest do - use Pleroma.Web.ConnCase, async: true - + use Pleroma.Web.ConnCase import ExUnit.CaptureLog import Mox diff --git a/test/pleroma/safe_jsonb_set_test.exs b/test/pleroma/safe_jsonb_set_test.exs index 8b1274545..6d70f1026 100644 --- a/test/pleroma/safe_jsonb_set_test.exs +++ b/test/pleroma/safe_jsonb_set_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.SafeJsonbSetTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true test "it doesn't wipe the object when asked to set the value to NULL" do assert %{rows: [[%{"key" => "value", "test" => nil}]]} = diff --git a/test/pleroma/stats_test.exs b/test/pleroma/stats_test.exs index 74bf785b0..6c2fd5726 100644 --- a/test/pleroma/stats_test.exs +++ b/test/pleroma/stats_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.StatsTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/upload/filter/dedupe_test.exs b/test/pleroma/upload/filter/dedupe_test.exs index 92a3d7df3..6559cbb50 100644 --- a/test/pleroma/upload/filter/dedupe_test.exs +++ b/test/pleroma/upload/filter/dedupe_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter.DedupeTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Upload alias Pleroma.Upload.Filter.Dedupe diff --git a/test/pleroma/upload/filter/exiftool_test.exs b/test/pleroma/upload/filter/exiftool_test.exs index 6b978b64c..b5a5ba18d 100644 --- a/test/pleroma/upload/filter/exiftool_test.exs +++ b/test/pleroma/upload/filter/exiftool_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Upload.Filter.ExiftoolTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Upload.Filter test "apply exiftool filter" do diff --git a/test/pleroma/uploaders/local_test.exs b/test/pleroma/uploaders/local_test.exs index 1ce7be485..5b377d580 100644 --- a/test/pleroma/uploaders/local_test.exs +++ b/test/pleroma/uploaders/local_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Uploaders.LocalTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Uploaders.Local describe "get_file/1" do diff --git a/test/pleroma/user/notification_setting_test.exs b/test/pleroma/user/notification_setting_test.exs index 308da216a..701130380 100644 --- a/test/pleroma/user/notification_setting_test.exs +++ b/test/pleroma/user/notification_setting_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.User.NotificationSettingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.User.NotificationSetting diff --git a/test/pleroma/user/welcome_chat_message_test.exs b/test/pleroma/user/welcome_chat_message_test.exs index fe26d6e4d..0b744fc1b 100644 --- a/test/pleroma/user/welcome_chat_message_test.exs +++ b/test/pleroma/user/welcome_chat_message_test.exs @@ -28,8 +28,10 @@ test "send a chat welcome message" do {:ok, %Pleroma.Activity{} = activity} = WelcomeChatMessage.post_message(user) assert user.ap_id in activity.recipients - assert Pleroma.Object.normalize(activity).data["type"] == "ChatMessage" - assert Pleroma.Object.normalize(activity).data["content"] == "Hello, welcome to Blob/Cat!" + assert Pleroma.Object.normalize(activity, fetch: false).data["type"] == "ChatMessage" + + assert Pleroma.Object.normalize(activity, fetch: false).data["content"] == + "Hello, welcome to Blob/Cat!" end end end diff --git a/test/pleroma/user/welcome_message_test.exs b/test/pleroma/user/welcome_message_test.exs index 3cd6f5cb7..a1779ddec 100644 --- a/test/pleroma/user/welcome_message_test.exs +++ b/test/pleroma/user/welcome_message_test.exs @@ -28,7 +28,9 @@ test "send a direct welcome message" do {:ok, %Pleroma.Activity{} = activity} = WelcomeMessage.post_message(user) assert user.ap_id in activity.recipients assert activity.data["directMessage"] == true - assert Pleroma.Object.normalize(activity).data["content"] =~ "Hello. Welcome to Pleroma" + + assert Pleroma.Object.normalize(activity, fetch: false).data["content"] =~ + "Hello. Welcome to Pleroma" end end end diff --git a/test/pleroma/user_relationship_test.exs b/test/pleroma/user_relationship_test.exs index f12406097..da4982065 100644 --- a/test/pleroma/user_relationship_test.exs +++ b/test/pleroma/user_relationship_test.exs @@ -5,7 +5,7 @@ defmodule Pleroma.UserRelationshipTest do alias Pleroma.UserRelationship - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index f6d19be5b..60741d255 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -438,7 +438,7 @@ test "it sends a welcome message if it is set" do activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients - assert Object.normalize(activity).data["content"] =~ "direct message" + assert Object.normalize(activity, fetch: false).data["content"] =~ "direct message" assert activity.actor == welcome_user.ap_id end @@ -454,7 +454,7 @@ test "it sends a welcome chat message if it is set" do activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients - assert Object.normalize(activity).data["content"] =~ "chat message" + assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message" assert activity.actor == welcome_user.ap_id end @@ -493,7 +493,7 @@ test "it sends a welcome chat message when Simple policy applied to local instan activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients - assert Object.normalize(activity).data["content"] =~ "chat message" + assert Object.normalize(activity, fetch: false).data["content"] =~ "chat message" assert activity.actor == welcome_user.ap_id end @@ -535,6 +535,22 @@ test "it sends a confirm email" do |> assert_email_sent() end + test "sends a pending approval email" do + clear_config([:instance, :account_approval_required], true) + + {:ok, user} = + User.register_changeset(%User{}, @full_user_data) + |> User.register() + + ObanHelpers.perform_all() + + assert_email_sent( + from: Pleroma.Config.Helpers.sender(), + to: {user.name, user.email}, + subject: "Your account is awaiting approval" + ) + end + test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do Pleroma.Config.put([:instance, :account_activation_required], true) @@ -1393,6 +1409,98 @@ test "approves a list of users" do assert false == user.approval_pending end) end + + test "it sends welcome email if it is set" do + clear_config([:welcome, :email, :enabled], true) + clear_config([:welcome, :email, :sender], "tester@test.me") + + user = insert(:user, approval_pending: true) + welcome_user = insert(:user, email: "tester@test.me") + instance_name = Pleroma.Config.get([:instance, :name]) + + User.approve(user) + + ObanHelpers.perform_all() + + assert_email_sent( + from: {instance_name, welcome_user.email}, + to: {user.name, user.email}, + html_body: "Welcome to #{instance_name}" + ) + end + + test "approving an approved user does not trigger post-register actions" do + clear_config([:welcome, :email, :enabled], true) + + user = insert(:user, approval_pending: false) + User.approve(user) + + ObanHelpers.perform_all() + + assert_no_email_sent() + end + end + + describe "confirm" do + test "confirms a user" do + user = insert(:user, confirmation_pending: true) + assert true == user.confirmation_pending + {:ok, user} = User.confirm(user) + assert false == user.confirmation_pending + end + + test "confirms a list of users" do + unconfirmed_users = [ + insert(:user, confirmation_pending: true), + insert(:user, confirmation_pending: true), + insert(:user, confirmation_pending: true) + ] + + {:ok, users} = User.confirm(unconfirmed_users) + + assert Enum.count(users) == 3 + + Enum.each(users, fn user -> + assert false == user.confirmation_pending + end) + end + + test "sends approval emails when `approval_pending: true`" do + admin = insert(:user, is_admin: true) + user = insert(:user, confirmation_pending: true, approval_pending: true) + User.confirm(user) + + ObanHelpers.perform_all() + + user_email = Pleroma.Emails.UserEmail.approval_pending_email(user) + admin_email = Pleroma.Emails.AdminEmail.new_unapproved_registration(admin, user) + + notify_email = Pleroma.Config.get([:instance, :notify_email]) + instance_name = Pleroma.Config.get([:instance, :name]) + + # User approval email + assert_email_sent( + from: {instance_name, notify_email}, + to: {user.name, user.email}, + html_body: user_email.html_body + ) + + # Admin email + assert_email_sent( + from: {instance_name, notify_email}, + to: {admin.name, admin.email}, + html_body: admin_email.html_body + ) + end + + test "confirming a confirmed user does not trigger post-register actions" do + user = insert(:user, confirmation_pending: false, approval_pending: true) + User.confirm(user) + + ObanHelpers.perform_all() + + assert_no_email_sent() + end end describe "delete" do @@ -1889,24 +1997,6 @@ test "Only includes users with no read notifications" do end end - describe "toggle_confirmation/1" do - test "if user is confirmed" do - user = insert(:user, confirmation_pending: false) - {:ok, user} = User.toggle_confirmation(user) - - assert user.confirmation_pending - assert user.confirmation_token - end - - test "if user is unconfirmed" do - user = insert(:user, confirmation_pending: true, confirmation_token: "some token") - {:ok, user} = User.toggle_confirmation(user) - - refute user.confirmation_pending - refute user.confirmation_token - end - end - describe "ensure_keys_present" do test "it creates keys for a user and stores them in info" do user = insert(:user) diff --git a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs index 0063d0482..03aed794f 100644 --- a/test/pleroma/web/activity_pub/activity_pub_controller_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_controller_test.exs @@ -219,7 +219,7 @@ test "it doesn't return a local-only object", %{conn: conn} do assert Pleroma.Web.ActivityPub.Visibility.is_local_public?(post) - object = Object.normalize(post, false) + object = Object.normalize(post, fetch: false) uuid = String.split(object.data["id"], "/") |> List.last() conn = @@ -712,7 +712,7 @@ test "it rejects reads from other users", %{conn: conn} do test "it returns a note activity in a collection", %{conn: conn} do note_activity = insert(:direct_note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(hd(note_activity.data["to"])) conn = @@ -999,7 +999,7 @@ test "it returns 200 even if there're no activities", %{conn: conn} do test "it returns a note activity in a collection", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(note_activity.data["actor"]) conn = @@ -1073,7 +1073,7 @@ test "it inserts an incoming create activity into the database", %{ assert Activity.get_by_ap_id(result["id"]) assert result["object"] - assert %Object{data: object} = Object.normalize(result["object"]) + assert %Object{data: object} = Object.normalize(result["object"], fetch: false) assert object["content"] == activity["object"]["content"] end @@ -1109,7 +1109,7 @@ test "it inserts an incoming sensitive activity into the database", %{ assert Activity.get_by_ap_id(response["id"]) assert response["object"] - assert %Object{data: response_object} = Object.normalize(response["object"]) + assert %Object{data: response_object} = Object.normalize(response["object"], fetch: false) assert response_object["sensitive"] == true assert response_object["content"] == activity["object"]["content"] @@ -1137,7 +1137,7 @@ test "it rejects an incoming activity with bogus type", %{conn: conn, activity: test "it erects a tombstone when receiving a delete activity", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(note_activity.data["actor"]) data = %{ @@ -1162,7 +1162,7 @@ test "it erects a tombstone when receiving a delete activity", %{conn: conn} do test "it rejects delete activity of object from other actor", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = insert(:user) data = %{ @@ -1183,7 +1183,7 @@ test "it rejects delete activity of object from other actor", %{conn: conn} do test "it increases like count when receiving a like action", %{conn: conn} do note_activity = insert(:note_activity) - note_object = Object.normalize(note_activity) + note_object = Object.normalize(note_activity, fetch: false) user = User.get_cached_by_ap_id(note_activity.data["actor"]) data = %{ @@ -1240,7 +1240,7 @@ test "it doesn't spreads faulty attributedTo or actor fields", %{ assert cirno_outbox["attributedTo"] == nil assert cirno_outbox["actor"] == cirno.ap_id - assert cirno_object = Object.normalize(cirno_outbox["object"]) + assert cirno_object = Object.normalize(cirno_outbox["object"], fetch: false) assert cirno_object.data["actor"] == cirno.ap_id assert cirno_object.data["attributedTo"] == cirno.ap_id end @@ -1503,7 +1503,7 @@ test "does not require authentication", %{conn: conn} do test "it tracks a signed object fetch", %{conn: conn} do user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url()) @@ -1519,7 +1519,7 @@ test "it tracks a signed object fetch", %{conn: conn} do test "it tracks a signed activity fetch", %{conn: conn} do user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url()) @@ -1536,7 +1536,7 @@ test "it tracks a signed object fetch when the json is cached", %{conn: conn} do user = insert(:user, local: false) other_user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url()) @@ -1560,7 +1560,7 @@ test "it tracks a signed activity fetch when the json is cached", %{conn: conn} user = insert(:user, local: false) other_user = insert(:user, local: false) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) activity_path = String.trim_leading(activity.data["id"], Pleroma.Web.Endpoint.url()) @@ -1650,7 +1650,7 @@ test "POST /api/ap/upload_media", %{conn: conn} do assert activity_response["actor"] == user.ap_id assert %Object{data: %{"attachment" => [attachment]}} = - Object.normalize(activity_response["object"]) + Object.normalize(activity_response["object"], fetch: false) assert attachment["type"] == "Document" assert attachment["name"] == desc diff --git a/test/pleroma/web/activity_pub/activity_pub_test.exs b/test/pleroma/web/activity_pub/activity_pub_test.exs index 9eb7ae86b..98242ff63 100644 --- a/test/pleroma/web/activity_pub/activity_pub_test.exs +++ b/test/pleroma/web/activity_pub/activity_pub_test.exs @@ -190,6 +190,24 @@ test "it returns a user that accepts chat messages" do assert user.accepts_chat_messages end + + test "works for guppe actors" do + user_id = "https://gup.pe/u/bernie2020" + + Tesla.Mock.mock(fn + %{method: :get, url: ^user_id} -> + %Tesla.Env{ + status: 200, + body: File.read!("test/fixtures/guppe-actor.json"), + headers: [{"content-type", "application/activity+json"}] + } + end) + + {:ok, user} = ActivityPub.make_user_from_ap_id(user_id) + + assert user.name == "Bernie2020 group" + assert user.actor_type == "Group" + end end test "it fetches the appropriate tag-restricted posts" do @@ -321,7 +339,7 @@ test "adds a context when none is there" do } {:ok, %Activity{} = activity} = ActivityPub.insert(data) - object = Pleroma.Object.normalize(activity) + object = Pleroma.Object.normalize(activity, fetch: false) assert is_binary(activity.data["context"]) assert is_binary(object.data["context"]) @@ -344,7 +362,7 @@ test "adds an id to a given object if it lacks one and is a note and inserts it } {:ok, %Activity{} = activity} = ActivityPub.insert(data) - assert object = Object.normalize(activity) + assert object = Object.normalize(activity, fetch: false) assert is_binary(object.data["id"]) end end @@ -678,7 +696,7 @@ test "doesn't return announce activities with blocked users in 'cc'" do {:ok, activity_two} = CommonAPI.post(blockee, %{status: "hey! @#{friend.nickname}"}) - assert object = Pleroma.Object.normalize(activity_two) + assert object = Pleroma.Object.normalize(activity_two, fetch: false) data = %{ "actor" => friend.ap_id, diff --git a/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs b/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs index 3c795f5ac..49bbc271d 100644 --- a/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/anti_followbot_policy_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicyTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy diff --git a/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs b/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs index 9a283f27d..19ea491c0 100644 --- a/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs +++ b/test/pleroma/web/activity_pub/mrf/ensure_re_prepended_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Object diff --git a/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs b/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs index 86dd9ddae..b5f401ad2 100644 --- a/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/force_bot_unlisted_policy_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicyTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.ActivityPub.MRF.ForceBotUnlistedPolicy diff --git a/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs b/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs index 64ea61dd4..d03456b34 100644 --- a/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/no_placeholder_text_policy_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicyTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.MRF.NoPlaceholderTextPolicy test "it clears content object" do diff --git a/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs b/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs index 9b39c45bd..5fccf7760 100644 --- a/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs +++ b/test/pleroma/web/activity_pub/mrf/normalize_markup_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.NormalizeMarkupTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.MRF.NormalizeMarkup @html_sample """ diff --git a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs index 3f8222736..7665d00d0 100644 --- a/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/steal_emoji_policy_test.exs @@ -6,6 +6,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do use Pleroma.DataCase alias Pleroma.Config + alias Pleroma.Emoji alias Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy setup_all do @@ -14,55 +15,91 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicyTest do end setup do - emoji_path = Path.join(Config.get([:instance, :static_dir]), "emoji/stolen") - File.rm_rf!(emoji_path) - File.mkdir!(emoji_path) + emoji_path = [:instance, :static_dir] |> Config.get() |> Path.join("emoji/stolen") - Pleroma.Emoji.reload() + Emoji.reload() + + message = %{ + "type" => "Create", + "object" => %{ + "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}], + "actor" => "https://example.org/users/admin" + } + } on_exit(fn -> File.rm_rf!(emoji_path) end) - :ok + [message: message, path: emoji_path] end - test "does nothing by default" do - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - refute "firedfox" in installed_emoji + test "does nothing by default", %{message: message} do + refute "firedfox" in installed() - message = %{ - "type" => "Create", - "object" => %{ - "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}], - "actor" => "https://example.org/users/admin" - } - } + assert {:ok, _message} = StealEmojiPolicy.filter(message) - assert {:ok, message} == StealEmojiPolicy.filter(message) - - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - refute "firedfox" in installed_emoji + refute "firedfox" in installed() end - test "Steals emoji on unknown shortcode from allowed remote host" do - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - refute "firedfox" in installed_emoji + test "Steals emoji on unknown shortcode from allowed remote host", %{ + message: message, + path: path + } do + refute "firedfox" in installed() + refute File.exists?(path) - message = %{ - "type" => "Create", - "object" => %{ - "emoji" => [{"firedfox", "https://example.org/emoji/firedfox.png"}], - "actor" => "https://example.org/users/admin" - } - } + clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) - clear_config([:mrf_steal_emoji, :hosts], ["example.org"]) - clear_config([:mrf_steal_emoji, :size_limit], 284_468) + assert {:ok, _message} = StealEmojiPolicy.filter(message) - assert {:ok, message} == StealEmojiPolicy.filter(message) + assert "firedfox" in installed() + assert File.exists?(path) - installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end) - assert "firedfox" in installed_emoji + assert path + |> Path.join("firedfox.png") + |> File.exists?() end + + test "reject shortcode", %{message: message} do + refute "firedfox" in installed() + + clear_config(:mrf_steal_emoji, + hosts: ["example.org"], + size_limit: 284_468, + rejected_shortcodes: [~r/firedfox/] + ) + + assert {:ok, _message} = StealEmojiPolicy.filter(message) + + refute "firedfox" in installed() + end + + test "reject if size is above the limit", %{message: message} do + refute "firedfox" in installed() + + clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 50_000) + + assert {:ok, _message} = StealEmojiPolicy.filter(message) + + refute "firedfox" in installed() + end + + test "reject if host returns error", %{message: message} do + refute "firedfox" in installed() + + Tesla.Mock.mock(fn %{method: :get, url: "https://example.org/emoji/firedfox.png"} -> + {:ok, %Tesla.Env{status: 404, body: "Not found"}} + end) + + clear_config(:mrf_steal_emoji, hosts: ["example.org"], size_limit: 284_468) + + ExUnit.CaptureLog.capture_log(fn -> + assert {:ok, _message} = StealEmojiPolicy.filter(message) + end) =~ "MRF.StealEmojiPolicy: Failed to fetch https://example.org/emoji/firedfox.png" + + refute "firedfox" in installed() + end + + defp installed, do: Emoji.get_all() |> Enum.map(fn {k, _} -> k end) end diff --git a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs index ffc30ba62..4f289739f 100644 --- a/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs +++ b/test/pleroma/web/activity_pub/mrf/tag_policy_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.TagPolicyTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.ActivityPub.MRF.TagPolicy diff --git a/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs index d6111ba41..bafa2a672 100644 --- a/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/accept_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs index 4771c4698..da60ac844 100644 --- a/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/announce_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Object alias Pleroma.Web.ActivityPub.Builder @@ -18,7 +18,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidationTest do announcer = insert(:user) {:ok, post_activity} = CommonAPI.post(user, %{status: "uguu"}) - object = Object.normalize(post_activity, false) + object = Object.normalize(post_activity, fetch: false) {:ok, valid_announce, []} = Builder.announce(announcer, object) %{ @@ -81,7 +81,7 @@ test "returns an error if the actor can't announce the object", %{ {:ok, post_activity} = CommonAPI.post(user, %{status: "a secret post", visibility: "private"}) - object = Object.normalize(post_activity, false) + object = Object.normalize(post_activity, fetch: false) # Another user can't announce it {:ok, announce, []} = Builder.announce(announcer, object, public: false) diff --git a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs index cc6dab872..1f992b397 100644 --- a/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/article_note_validator_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidatorTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.ObjectValidators.ArticleNoteValidator alias Pleroma.Web.ActivityPub.Utils diff --git a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs index 2e1975a79..45e1d8852 100644 --- a/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/attachment_validator_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidatorTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator diff --git a/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs index c08d4b2e8..d133aeb1a 100644 --- a/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/block_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs index d7e299224..941a8a3e3 100644 --- a/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/chat_validation_test.exs @@ -17,7 +17,7 @@ test "it is invalid if the object already exists" do user = insert(:user) recipient = insert(:user) {:ok, activity} = CommonAPI.post_chat_message(user, recipient, "hey") - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) {:ok, create_data, _} = Builder.create(user, object.data, [recipient.ap_id]) diff --git a/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs index 02683b899..57de83c8a 100644 --- a/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/delete_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Object alias Pleroma.Web.ActivityPub.Builder diff --git a/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs index 582e6d785..342cfeef8 100644 --- a/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/emoji_react_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs index 6e1378be2..0f77ac8df 100644 --- a/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/follow_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs index 2c033b7e2..4cda3742d 100644 --- a/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/like_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.ObjectValidator alias Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator diff --git a/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs index 370bb6e5c..69f5e8ac4 100644 --- a/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/reject_validation_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs index 75bbcc4b6..dc85d1ac3 100644 --- a/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/undo_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs index 5e80cf731..2c4a50bfd 100644 --- a/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs +++ b/test/pleroma/web/activity_pub/object_validators/update_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.ObjectValidator diff --git a/test/pleroma/web/activity_pub/pipeline_test.exs b/test/pleroma/web/activity_pub/pipeline_test.exs index 210a06563..d568d825b 100644 --- a/test/pleroma/web/activity_pub/pipeline_test.exs +++ b/test/pleroma/web/activity_pub/pipeline_test.exs @@ -3,14 +3,35 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.PipelineTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true - import Mock + import Mox import Pleroma.Factory + alias Pleroma.ConfigMock + alias Pleroma.Web.ActivityPub.ActivityPubMock + alias Pleroma.Web.ActivityPub.MRFMock + alias Pleroma.Web.ActivityPub.ObjectValidatorMock + alias Pleroma.Web.ActivityPub.SideEffectsMock + alias Pleroma.Web.FederatorMock + + setup :verify_on_exit! + describe "common_pipeline/2" do setup do - clear_config([:instance, :federating], true) + ObjectValidatorMock + |> expect(:validate, fn o, m -> {:ok, o, m} end) + + MRFMock + |> expect(:pipeline_filter, fn o, m -> {:ok, o, m} end) + + ActivityPubMock + |> expect(:persist, fn o, m -> {:ok, o, m} end) + + SideEffectsMock + |> expect(:handle, fn o, m -> {:ok, o, m} end) + |> expect(:handle_after_transaction, fn m -> m end) + :ok end @@ -21,159 +42,53 @@ test "when given an `object_data` in meta, Federation will receive a the origina activity_with_object = %{activity | data: Map.put(activity.data, "object", object)} - with_mocks([ - {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]}, - { - Pleroma.Web.ActivityPub.MRF, - [], - [pipeline_filter: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.ActivityPub, - [], - [persist: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.SideEffects, - [], - [ - handle: fn o, m -> {:ok, o, m} end, - handle_after_transaction: fn m -> m end - ] - }, - { - Pleroma.Web.Federator, - [], - [publish: fn _o -> :ok end] - } - ]) do - assert {:ok, ^activity, ^meta} = - Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) + FederatorMock + |> expect(:publish, fn ^activity_with_object -> :ok end) - assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta)) - refute called(Pleroma.Web.Federator.publish(activity)) - assert_called(Pleroma.Web.Federator.publish(activity_with_object)) - end + ConfigMock + |> expect(:get, fn [:instance, :federating] -> true end) + + assert {:ok, ^activity, ^meta} = + Pleroma.Web.ActivityPub.Pipeline.common_pipeline( + activity, + meta + ) end test "it goes through validation, filtering, persisting, side effects and federation for local activities" do activity = insert(:note_activity) meta = [local: true] - with_mocks([ - {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]}, - { - Pleroma.Web.ActivityPub.MRF, - [], - [pipeline_filter: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.ActivityPub, - [], - [persist: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.SideEffects, - [], - [ - handle: fn o, m -> {:ok, o, m} end, - handle_after_transaction: fn m -> m end - ] - }, - { - Pleroma.Web.Federator, - [], - [publish: fn _o -> :ok end] - } - ]) do - assert {:ok, ^activity, ^meta} = - Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) + FederatorMock + |> expect(:publish, fn ^activity -> :ok end) - assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta)) - assert_called(Pleroma.Web.Federator.publish(activity)) - end + ConfigMock + |> expect(:get, fn [:instance, :federating] -> true end) + + assert {:ok, ^activity, ^meta} = + Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) end test "it goes through validation, filtering, persisting, side effects without federation for remote activities" do activity = insert(:note_activity) meta = [local: false] - with_mocks([ - {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]}, - { - Pleroma.Web.ActivityPub.MRF, - [], - [pipeline_filter: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.ActivityPub, - [], - [persist: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.SideEffects, - [], - [handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end] - }, - { - Pleroma.Web.Federator, - [], - [] - } - ]) do - assert {:ok, ^activity, ^meta} = - Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) + ConfigMock + |> expect(:get, fn [:instance, :federating] -> true end) - assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta)) - end + assert {:ok, ^activity, ^meta} = + Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) end test "it goes through validation, filtering, persisting, side effects without federation for local activities if federation is deactivated" do - clear_config([:instance, :federating], false) - activity = insert(:note_activity) meta = [local: true] - with_mocks([ - {Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]}, - { - Pleroma.Web.ActivityPub.MRF, - [], - [pipeline_filter: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.ActivityPub, - [], - [persist: fn o, m -> {:ok, o, m} end] - }, - { - Pleroma.Web.ActivityPub.SideEffects, - [], - [handle: fn o, m -> {:ok, o, m} end, handle_after_transaction: fn m -> m end] - }, - { - Pleroma.Web.Federator, - [], - [] - } - ]) do - assert {:ok, ^activity, ^meta} = - Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) + ConfigMock + |> expect(:get, fn [:instance, :federating] -> false end) - assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.MRF.pipeline_filter(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta)) - assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta)) - end + assert {:ok, ^activity, ^meta} = + Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta) end end end diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 24e373e04..8529911ca 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -396,7 +396,7 @@ test "publish to url with with different ports" do actor = insert(:user) note_activity = insert(:note_activity, user: actor) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) activity_path = String.trim_leading(note_activity.data["id"], Pleroma.Web.Endpoint.url()) object_path = String.trim_leading(object.data["id"], Pleroma.Web.Endpoint.url()) diff --git a/test/pleroma/web/activity_pub/relay_test.exs b/test/pleroma/web/activity_pub/relay_test.exs index 3284980f7..a7cd732bb 100644 --- a/test/pleroma/web/activity_pub/relay_test.exs +++ b/test/pleroma/web/activity_pub/relay_test.exs @@ -84,7 +84,7 @@ test "force unfollow when target service is dead" do ) Pleroma.Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) assert {:ok, %Activity{} = activity} = Relay.unfollow(user_ap_id, %{force: true}) diff --git a/test/pleroma/web/activity_pub/side_effects/delete_test.exs b/test/pleroma/web/activity_pub/side_effects/delete_test.exs new file mode 100644 index 000000000..cb11f93cd --- /dev/null +++ b/test/pleroma/web/activity_pub/side_effects/delete_test.exs @@ -0,0 +1,147 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.SideEffects.DeleteTest do + use Oban.Testing, repo: Pleroma.Repo + use Pleroma.DataCase, async: true + + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.Tests.ObanHelpers + alias Pleroma.User + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Builder + alias Pleroma.Web.ActivityPub.SideEffects + alias Pleroma.Web.CommonAPI + + alias Pleroma.LoggerMock + alias Pleroma.Web.ActivityPub.ActivityPubMock + + import Mox + import Pleroma.Factory + + describe "user deletion" do + setup do + user = insert(:user) + + {:ok, delete_user_data, _meta} = Builder.delete(user, user.ap_id) + {:ok, delete_user, _meta} = ActivityPub.persist(delete_user_data, local: true) + + %{ + user: user, + delete_user: delete_user + } + end + + test "it handles user deletions", %{delete_user: delete, user: user} do + {:ok, _delete, _} = SideEffects.handle(delete) + ObanHelpers.perform_all() + + assert User.get_cached_by_ap_id(user.ap_id).deactivated + end + end + + describe "object deletion" do + setup do + user = insert(:user) + other_user = insert(:user) + + {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"}) + {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op}) + {:ok, favorite} = CommonAPI.favorite(user, post.id) + object = Object.normalize(post, fetch: false) + {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"]) + {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true) + + %{ + user: user, + delete: delete, + post: post, + object: object, + op: op, + favorite: favorite + } + end + + test "it handles object deletions", %{ + delete: delete, + post: post, + object: object, + user: user, + op: op, + favorite: favorite + } do + object_id = object.id + user_id = user.id + + ActivityPubMock + |> expect(:stream_out, fn ^delete -> nil end) + |> expect(:stream_out_participations, fn %Object{id: ^object_id}, %User{id: ^user_id} -> + nil + end) + + {:ok, _delete, _} = SideEffects.handle(delete) + user = User.get_cached_by_ap_id(object.data["actor"]) + + object = Object.get_by_id(object.id) + assert object.data["type"] == "Tombstone" + refute Activity.get_by_id(post.id) + refute Activity.get_by_id(favorite.id) + + user = User.get_by_id(user.id) + assert user.note_count == 0 + + object = Object.normalize(op.data["object"], fetch: false) + + assert object.data["repliesCount"] == 0 + end + + test "it handles object deletions when the object itself has been pruned", %{ + delete: delete, + post: post, + object: object, + user: user, + op: op + } do + object_id = object.id + user_id = user.id + + ActivityPubMock + |> expect(:stream_out, fn ^delete -> nil end) + |> expect(:stream_out_participations, fn %Object{id: ^object_id}, %User{id: ^user_id} -> + nil + end) + + {:ok, _delete, _} = SideEffects.handle(delete) + user = User.get_cached_by_ap_id(object.data["actor"]) + + object = Object.get_by_id(object.id) + assert object.data["type"] == "Tombstone" + refute Activity.get_by_id(post.id) + + user = User.get_by_id(user.id) + assert user.note_count == 0 + + object = Object.normalize(op.data["object"], fetch: false) + + assert object.data["repliesCount"] == 0 + end + + test "it logs issues with objects deletion", %{ + delete: delete, + object: object + } do + {:ok, _object} = + object + |> Object.change(%{data: Map.delete(object.data, "actor")}) + |> Repo.update() + + LoggerMock + |> expect(:error, fn str -> assert str =~ "The object doesn't have an actor" end) + + {:error, :no_object_actor} = SideEffects.handle(delete) + end + end +end diff --git a/test/pleroma/web/activity_pub/side_effects_test.exs b/test/pleroma/web/activity_pub/side_effects_test.exs index 297fc0b84..50af7a507 100644 --- a/test/pleroma/web/activity_pub/side_effects_test.exs +++ b/test/pleroma/web/activity_pub/side_effects_test.exs @@ -19,7 +19,6 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do alias Pleroma.Web.ActivityPub.SideEffects alias Pleroma.Web.CommonAPI - import ExUnit.CaptureLog import Mock import Pleroma.Factory @@ -131,115 +130,6 @@ test "it uses a given changeset to update", %{user: user, update: update} do end end - describe "delete objects" do - setup do - user = insert(:user) - other_user = insert(:user) - - {:ok, op} = CommonAPI.post(other_user, %{status: "big oof"}) - {:ok, post} = CommonAPI.post(user, %{status: "hey", in_reply_to_id: op}) - {:ok, favorite} = CommonAPI.favorite(user, post.id) - object = Object.normalize(post) - {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"]) - {:ok, delete_user_data, _meta} = Builder.delete(user, user.ap_id) - {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true) - {:ok, delete_user, _meta} = ActivityPub.persist(delete_user_data, local: true) - - %{ - user: user, - delete: delete, - post: post, - object: object, - delete_user: delete_user, - op: op, - favorite: favorite - } - end - - test "it handles object deletions", %{ - delete: delete, - post: post, - object: object, - user: user, - op: op, - favorite: favorite - } do - with_mock Pleroma.Web.ActivityPub.ActivityPub, [:passthrough], - stream_out: fn _ -> nil end, - stream_out_participations: fn _, _ -> nil end do - {:ok, delete, _} = SideEffects.handle(delete) - user = User.get_cached_by_ap_id(object.data["actor"]) - - assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out(delete)) - assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out_participations(object, user)) - end - - object = Object.get_by_id(object.id) - assert object.data["type"] == "Tombstone" - refute Activity.get_by_id(post.id) - refute Activity.get_by_id(favorite.id) - - user = User.get_by_id(user.id) - assert user.note_count == 0 - - object = Object.normalize(op.data["object"], false) - - assert object.data["repliesCount"] == 0 - end - - test "it handles object deletions when the object itself has been pruned", %{ - delete: delete, - post: post, - object: object, - user: user, - op: op - } do - with_mock Pleroma.Web.ActivityPub.ActivityPub, [:passthrough], - stream_out: fn _ -> nil end, - stream_out_participations: fn _, _ -> nil end do - {:ok, delete, _} = SideEffects.handle(delete) - user = User.get_cached_by_ap_id(object.data["actor"]) - - assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out(delete)) - assert called(Pleroma.Web.ActivityPub.ActivityPub.stream_out_participations(object, user)) - end - - object = Object.get_by_id(object.id) - assert object.data["type"] == "Tombstone" - refute Activity.get_by_id(post.id) - - user = User.get_by_id(user.id) - assert user.note_count == 0 - - object = Object.normalize(op.data["object"], false) - - assert object.data["repliesCount"] == 0 - end - - test "it handles user deletions", %{delete_user: delete, user: user} do - {:ok, _delete, _} = SideEffects.handle(delete) - ObanHelpers.perform_all() - - assert User.get_cached_by_ap_id(user.ap_id).deactivated - end - - test "it logs issues with objects deletion", %{ - delete: delete, - object: object - } do - {:ok, object} = - object - |> Object.change(%{data: Map.delete(object.data, "actor")}) - |> Repo.update() - - Object.invalid_object_cache(object) - - assert capture_log(fn -> - {:error, :no_object_actor} = SideEffects.handle(delete) - end) =~ "object doesn't have an actor" - end - end - describe "EmojiReact objects" do setup do poster = insert(:user) diff --git a/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs index 485216487..d356fcc72 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/accept_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.User alias Pleroma.Web.ActivityPub.Transmogrifier diff --git a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs index c06bbc5e9..6ec7e1a0a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/announce_handling_test.exs @@ -130,7 +130,7 @@ test "it works for incoming announces with an inlined activity" do assert data["id"] == "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity" - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368" assert object.data["content"] == "this is a private toot" @@ -158,7 +158,7 @@ test "it does not clobber the addressing on announce activities" do data = File.read!("test/fixtures/mastodon-announce.json") |> Jason.decode!() - |> Map.put("object", Object.normalize(activity).data["id"]) + |> Map.put("object", Object.normalize(activity, fetch: false).data["id"]) |> Map.put("to", ["http://mastodon.example.org/users/admin/followers"]) |> Map.put("cc", []) diff --git a/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs index a1c2ba28a..c6483ccaf 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/answer_handling_test.exs @@ -26,7 +26,7 @@ test "incoming, rewrites Note to Answer and increments vote counters" do poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["repliesCount"] == nil data = @@ -37,7 +37,7 @@ test "incoming, rewrites Note to Answer and increments vote counters" do |> Kernel.put_in(["object", "to"], user.ap_id) {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - answer_object = Object.normalize(activity) + answer_object = Object.normalize(activity, fetch: false) assert answer_object.data["type"] == "Answer" assert answer_object.data["inReplyTo"] == object.data["id"] @@ -62,7 +62,7 @@ test "outgoing, rewrites Answer to Note" do poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10} }) - poll_object = Object.normalize(poll_activity) + poll_object = Object.normalize(poll_activity, fetch: false) # TODO: Replace with CommonAPI vote creation when implemented data = File.read!("test/fixtures/mastodon-vote.json") diff --git a/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs index b0ae804c5..26216f7fc 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/article_handling_test.exs @@ -25,7 +25,7 @@ test "Pterotype (Wordpress Plugin) Article" do {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support" @@ -75,7 +75,7 @@ test "Prismo Article" do data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["url"] == "https://prismo.news/posts/83" end diff --git a/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs index 7a2ac5d4d..ac80d0ddd 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/audio_handling_test.exs @@ -35,7 +35,7 @@ test "it works for incoming listens" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" assert object.data["artist"] == "lain" @@ -57,7 +57,7 @@ test "Funkwhale Audio object" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"] diff --git a/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs index 679c33c6c..6adad88f5 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/block_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier.BlockHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.User diff --git a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs index cffaa7c44..6dd508894 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/delete_handling_test.exs @@ -40,7 +40,7 @@ test "it works for incoming deletes" do assert actor == deleting_user.ap_id # Objects are replaced by a tombstone object. - object = Object.normalize(activity.data["object"]) + object = Object.normalize(activity.data["object"], fetch: false) assert object.data["type"] == "Tombstone" end @@ -48,9 +48,10 @@ test "it works for incoming when the object has been pruned" do activity = insert(:note_activity) {:ok, object} = - Object.normalize(activity.data["object"]) + Object.normalize(activity.data["object"], fetch: false) |> Repo.delete() + # TODO: mock cachex Cachex.del(:object_cache, "object:#{object.data["id"]}") deleting_user = insert(:user) diff --git a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs index aea4ed6f8..1ebf6b1e8 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/emoji_react_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Object diff --git a/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs index 967bad151..35211b8f2 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/like_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier.LikeHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Web.ActivityPub.Transmogrifier diff --git a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs index b4a006aec..b61e5013a 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/note_handling_test.exs @@ -28,7 +28,7 @@ test "it works for incoming notices with tag not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-array-less-emoji.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["emoji"] == %{ "icon_e_smile" => "https://puckipedia.com/forum/images/smilies/icon_e_smile.png" @@ -37,7 +37,7 @@ test "it works for incoming notices with tag not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-array-less-hashtag.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert "test" in object.data["tag"] end @@ -66,7 +66,7 @@ test "it cleans up incoming notices which are not really DMs" do assert data["to"] == [] assert data["cc"] == to - object_data = Object.normalize(activity).data + object_data = Object.normalize(activity, fetch: false).data assert object_data["to"] == [] assert object_data["cc"] == to @@ -78,7 +78,7 @@ test "it ignores an incoming notice if we already have it" do data = File.read!("test/fixtures/mastodon-post-activity.json") |> Jason.decode!() - |> Map.put("object", Object.normalize(activity).data) + |> Map.put("object", Object.normalize(activity, fetch: false).data) {:ok, returned_activity} = Transmogrifier.handle_incoming(data) @@ -97,7 +97,7 @@ test "it fetches reply-to activities if we don't have them" do data = Map.put(data, "object", object) {:ok, returned_activity} = Transmogrifier.handle_incoming(data) - returned_object = Object.normalize(returned_activity, false) + returned_object = Object.normalize(returned_activity, fetch: false) assert %Activity{} = Activity.get_create_by_object_ap_id( @@ -123,7 +123,7 @@ test "it does not fetch reply-to activities beyond max replies depth limit" do allowed_thread_distance?: fn _ -> false end do {:ok, returned_activity} = Transmogrifier.handle_incoming(data) - returned_object = Object.normalize(returned_activity, false) + returned_object = Object.normalize(returned_activity, fetch: false) refute Activity.get_create_by_object_ap_id( "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment" @@ -179,7 +179,7 @@ test "it works for incoming notices" do assert data["actor"] == "http://mastodon.example.org/users/admin" - object_data = Object.normalize(data["object"]).data + object_data = Object.normalize(data["object"], fetch: false).data assert object_data["id"] == "http://mastodon.example.org/users/admin/statuses/99512778738411822" @@ -209,7 +209,7 @@ test "it works for incoming notices without the sensitive property but an nsfw h {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object_data = Object.normalize(data["object"], false).data + object_data = Object.normalize(data["object"], fetch: false).data assert object_data["sensitive"] == true end @@ -218,7 +218,7 @@ test "it works for incoming notices with hashtags" do data = File.read!("test/fixtures/mastodon-post-activity-hashtag.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert Enum.at(object.data["tag"], 2) == "moo" end @@ -227,7 +227,7 @@ test "it works for incoming notices with contentMap" do data = File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["content"] == "

@lain

" @@ -237,7 +237,7 @@ test "it works for incoming notices with to/cc not being an array (kroeg)" do data = File.read!("test/fixtures/kroeg-post-activity.json") |> Jason.decode!() {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - object = Object.normalize(data["object"]) + object = Object.normalize(data["object"], fetch: false) assert object.data["content"] == "

henlo from my Psion netBook

message sent from my Psion netBook

" @@ -725,7 +725,7 @@ test "sets `replies` collection with a limited number of self-replies" do in_reply_to_status_id: id1 }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) replies_uris = Enum.map([self_reply1, self_reply2], fn a -> a.object.data["id"] end) assert %{"type" => "Collection", "items" => ^replies_uris} = diff --git a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs index 47f92cf4d..ae470f984 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs @@ -22,7 +22,7 @@ test "Mastodon Question activity" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["url"] == "https://mastodon.sdf.org/@rinpatch/102070944809637304" @@ -65,7 +65,7 @@ test "Mastodon Question activity" do {:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id}) - reply_object = Object.normalize(reply_activity, false) + reply_object = Object.normalize(reply_activity, fetch: false) assert reply_object.data["context"] == object.data["context"] assert reply_object.data["context_id"] == object.data["context_id"] @@ -101,7 +101,7 @@ test "Mastodon Question activity with HTML tags in plaintext" do |> Kernel.put_in(["object", "oneOf"], options) {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert Enum.sort(object.data["oneOf"]) == Enum.sort(options) end @@ -147,7 +147,7 @@ test "Mastodon Question activity with custom emojis" do |> Kernel.put_in(["object", "tag"], tag) {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["oneOf"] == options diff --git a/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs index 5a3bef792..851236758 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/reject_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.User diff --git a/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs index fcfc7b4b6..107121ef8 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/undo_handling_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Object diff --git a/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs index c62d5e139..8ed5e5e90 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/user_update_handling_test.exs @@ -103,7 +103,7 @@ test "it works with custom profile fields" do %{"name" => "foo1", "value" => "updated"} ] - Pleroma.Config.put([:instance, :max_remote_account_fields], 2) + clear_config([:instance, :max_remote_account_fields], 2) update_data = update_data diff --git a/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs index 57411fafa..be4ac4c13 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/video_handling_test.exs @@ -24,7 +24,7 @@ test "skip converting the content when it is nil" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["content"] == nil end @@ -34,7 +34,7 @@ test "it converts content of object to html" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

Après avoir mené avec un certain succès la campagne « Dégooglisons Internet » en 2014, l’association Framasoft annonce fin 2019 arrêter progressivement un certain nombre de ses services alternatifs aux GAFAM. Pourquoi ?

Transcription par @aprilorg ici : https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft

" @@ -70,7 +70,7 @@ test "it remaps video URLs as attachments if necessary" do {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) - assert object = Object.normalize(activity, false) + assert object = Object.normalize(activity, fetch: false) assert object.data["attachment"] == [ %{ diff --git a/test/pleroma/web/activity_pub/transmogrifier_test.exs b/test/pleroma/web/activity_pub/transmogrifier_test.exs index 66ea7664a..c32ea9ae4 100644 --- a/test/pleroma/web/activity_pub/transmogrifier_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier_test.exs @@ -56,7 +56,7 @@ test "it accepts Flag activities" do other_user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "test post"}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) note_obj = %{ "type" => "Note", @@ -281,6 +281,21 @@ test "it can handle Listen activities" do {:ok, _modified} = Transmogrifier.prepare_outgoing(activity.data) end + + test "custom emoji urls are URI encoded" do + # :dinosaur: filename has a space -> dino walking.gif + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{status: "everybody do the dinosaur :dinosaur:"}) + + {:ok, prepared} = Transmogrifier.prepare_outgoing(activity.data) + + assert length(prepared["object"]["tag"]) == 1 + + url = prepared["object"]["tag"] |> List.first() |> Map.get("icon") |> Map.get("url") + + assert url == "http://localhost:4001/emoji/dino%20walking.gif" + end end describe "user upgrade" do diff --git a/test/pleroma/web/activity_pub/utils_test.exs b/test/pleroma/web/activity_pub/utils_test.exs index be9cd7d13..83668caa4 100644 --- a/test/pleroma/web/activity_pub/utils_test.exs +++ b/test/pleroma/web/activity_pub/utils_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.UtilsTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Object alias Pleroma.Repo @@ -165,7 +165,7 @@ test "fetches existing votes" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {: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 @@ -183,7 +183,7 @@ test "fetches only Create activities" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, [vote], object} = CommonAPI.vote(other_user, object, [0]) {:ok, _activity} = CommonAPI.favorite(user, activity.id) [fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object) @@ -242,7 +242,7 @@ test "updates the state of the given follow activity" do test "updates likes" do user = insert(:user) activity = insert(:note_activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert {:ok, updated_object} = Utils.update_element_in_object( @@ -302,7 +302,7 @@ test "removes ap_id from likes" do describe "get_existing_like/2" do test "fetches existing like" do note_activity = insert(:note_activity) - assert object = Object.normalize(note_activity) + assert object = Object.normalize(note_activity, fetch: false) user = insert(:user) refute Utils.get_existing_like(user.ap_id, object) @@ -320,7 +320,7 @@ test "returns nil if announce not found" do test "fetches existing announce" do note_activity = insert(:note_activity) - assert object = Object.normalize(note_activity) + assert object = Object.normalize(note_activity, fetch: false) actor = insert(:user) {:ok, announce} = CommonAPI.repeat(note_activity.id, actor) @@ -412,7 +412,7 @@ test "returns false" do describe "lazy_put_activity_defaults/2" do test "returns map with id and published data" do note_activity = insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) res = Utils.lazy_put_activity_defaults(%{"context" => object.data["id"]}) assert res["context"] == object.data["id"] assert res["context_id"] == object.id @@ -431,7 +431,7 @@ test "returns map with fake id and published data" do test "returns activity data with object" do note_activity = insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) res = Utils.lazy_put_activity_defaults(%{ diff --git a/test/pleroma/web/activity_pub/views/object_view_test.exs b/test/pleroma/web/activity_pub/views/object_view_test.exs index f0389845d..967acad19 100644 --- a/test/pleroma/web/activity_pub/views/object_view_test.exs +++ b/test/pleroma/web/activity_pub/views/object_view_test.exs @@ -24,7 +24,7 @@ test "renders a note object" do test "renders a note activity" do note = insert(:note_activity) - object = Object.normalize(note) + object = Object.normalize(note, fetch: false) result = ObjectView.render("object.json", %{object: note}) @@ -56,7 +56,7 @@ test "renders `replies` collection for a note activity" do test "renders a like activity" do note = insert(:note_activity) - object = Object.normalize(note) + object = Object.normalize(note, fetch: false) user = insert(:user) {:ok, like_activity} = CommonAPI.favorite(user, note.id) @@ -70,7 +70,7 @@ test "renders a like activity" do test "renders an announce activity" do note = insert(:note_activity) - object = Object.normalize(note) + object = Object.normalize(note, fetch: false) user = insert(:user) {:ok, announce_activity} = CommonAPI.repeat(note.id, user) diff --git a/test/pleroma/web/activity_pub/views/user_view_test.exs b/test/pleroma/web/activity_pub/views/user_view_test.exs index 98c7c9d09..5702c1b6f 100644 --- a/test/pleroma/web/activity_pub/views/user_view_test.exs +++ b/test/pleroma/web/activity_pub/views/user_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.UserViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.User @@ -80,6 +80,12 @@ test "renders an invisible user with the invisible property set to true" do assert %{"invisible" => true} = UserView.render("service.json", %{user: user}) end + test "renders AKAs" do + akas = ["https://i.tusooa.xyz/users/test-pleroma"] + user = insert(:user, also_known_as: akas) + assert %{"alsoKnownAs" => ^akas} = UserView.render("user.json", %{user: user}) + end + describe "endpoints" do test "local users have a usable endpoints structure" do user = insert(:user) diff --git a/test/pleroma/web/activity_pub/visibility_test.exs b/test/pleroma/web/activity_pub/visibility_test.exs index 836d44994..1ec41aa19 100644 --- a/test/pleroma/web/activity_pub/visibility_test.exs +++ b/test/pleroma/web/activity_pub/visibility_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.VisibilityTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Activity alias Pleroma.Web.ActivityPub.Visibility @@ -159,7 +159,7 @@ test "doesn't die when the user doesn't exist", user: user } do Repo.delete(user) - Cachex.clear(:user_cache) + Pleroma.User.invalidate_cache(user) refute Visibility.is_private?(direct) end diff --git a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs index e50d1425b..90b25b782 100644 --- a/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/admin_api_controller_test.exs @@ -422,10 +422,20 @@ test "renders user's statuses", %{conn: conn, user: user} do assert json_response(conn, 200) |> length() == 3 end - test "renders user's statuses with a limit", %{conn: conn, user: user} do - conn = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=2") + test "renders user's statuses with pagination", %{conn: conn, user: user} do + conn1 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=1") - assert json_response(conn, 200) |> length() == 2 + response1 = json_response(conn1, 200) + + assert response1 |> length() == 1 + + conn2 = get(conn, "/api/pleroma/admin/users/#{user.nickname}/statuses?page_size=1&page=2") + + response2 = json_response(conn2, 200) + + assert response2 |> length() == 1 + + refute response1 == response2 end test "doesn't return private statuses by default", %{conn: conn, user: user} do diff --git a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs index 5aefa1e60..00e67a91c 100644 --- a/test/pleroma/web/admin_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/chat_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.ChatControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory @@ -36,7 +36,7 @@ test "it deletes a message from the chat", %{conn: conn, admin: admin} do {:ok, message} = CommonAPI.post_chat_message(user, recipient, "Hello darkness my old friend") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) recipient_chat = Chat.get(recipient.id, user.ap_id) @@ -143,7 +143,7 @@ test "it returns a chat", %{conn: conn} do recipient = insert(:user) {:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) @@ -183,7 +183,7 @@ test "GET /api/pleroma/admin/chats/:id", %{conn: conn, chat: chat} do recipient = insert(:user) {:ok, message} = CommonAPI.post_chat_message(user, recipient, "Yo") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index e6b203e74..df5d74d45 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do - use Pleroma.Web.ConnCase, async: true + use Pleroma.Web.ConnCase import ExUnit.CaptureLog import Pleroma.Factory diff --git a/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs b/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs index f243d1fb2..62fb9592a 100644 --- a/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/media_proxy_cache_controller_test.exs @@ -12,10 +12,6 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do setup do: clear_config([:media_proxy]) - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - setup do admin = insert(:user, is_admin: true) token = insert(:oauth_admin_token, user: admin) diff --git a/test/pleroma/web/admin_api/controllers/report_controller_test.exs b/test/pleroma/web/admin_api/controllers/report_controller_test.exs index cbfc2e7b0..2ab2f2f6d 100644 --- a/test/pleroma/web/admin_api/controllers/report_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/report_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.ReportControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory diff --git a/test/pleroma/web/admin_api/controllers/status_controller_test.exs b/test/pleroma/web/admin_api/controllers/status_controller_test.exs index a18ef9e4b..40714c8a4 100644 --- a/test/pleroma/web/admin_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/status_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.StatusControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory diff --git a/test/pleroma/web/admin_api/controllers/user_controller_test.exs b/test/pleroma/web/admin_api/controllers/user_controller_test.exs index 5705306c7..67b0c578c 100644 --- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/user_controller_test.exs @@ -953,6 +953,7 @@ defp user_response(user, attrs \\ %{}) do %{ "deactivated" => user.deactivated, "id" => user.id, + "email" => user.email, "nickname" => user.nickname, "roles" => %{"admin" => false, "moderator" => false}, "local" => user.local, diff --git a/test/pleroma/web/admin_api/search_test.exs b/test/pleroma/web/admin_api/search_test.exs index 9bc58640c..fdf22a8e6 100644 --- a/test/pleroma/web/admin_api/search_test.exs +++ b/test/pleroma/web/admin_api/search_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.SearchTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Web.AdminAPI.Search diff --git a/test/pleroma/web/admin_api/views/account_view_test.exs b/test/pleroma/web/admin_api/views/account_view_test.exs new file mode 100644 index 000000000..f54214575 --- /dev/null +++ b/test/pleroma/web/admin_api/views/account_view_test.exs @@ -0,0 +1,16 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.AdminAPI.AccountViewTest do + use Pleroma.DataCase, async: true + import Pleroma.Factory + alias Pleroma.Web.AdminAPI.AccountView + + describe "show.json" do + test "renders the user's email" do + user = insert(:user, email: "yolo@yolofam.tld") + assert %{"email" => "yolo@yolofam.tld"} = AccountView.render("show.json", %{user: user}) + end + end +end diff --git a/test/pleroma/web/admin_api/views/moderation_log_view_test.exs b/test/pleroma/web/admin_api/views/moderation_log_view_test.exs index e6c5aaa7f..a4748990e 100644 --- a/test/pleroma/web/admin_api/views/moderation_log_view_test.exs +++ b/test/pleroma/web/admin_api/views/moderation_log_view_test.exs @@ -2,13 +2,14 @@ # Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.ModerationLogViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.AdminAPI.ModerationLogView describe "renders `report_note_delete` log messages" do setup do log1 = %Pleroma.ModerationLog{ + id: 1, data: %{ "action" => "report_note_delete", "actor" => %{"id" => "A1I7G8", "nickname" => "admin", "type" => "user"}, @@ -21,6 +22,7 @@ defmodule Pleroma.Web.AdminAPI.ModerationLogViewTest do } log2 = %Pleroma.ModerationLog{ + id: 2, data: %{ "action" => "report_note_delete", "actor" => %{"id" => "A1I7G8", "nickname" => "admin", "type" => "user"}, @@ -42,6 +44,7 @@ test "renders `report_note_delete` log messages", %{log1: log1, log2: log2} do ) == %{ items: [ %{ + id: 1, data: %{ "action" => "report_note_delete", "actor" => %{"id" => "A1I7G8", "nickname" => "admin", "type" => "user"}, @@ -59,6 +62,7 @@ test "renders `report_note_delete` log messages", %{log1: log1, log2: log2} do time: 1_605_622_400 }, %{ + id: 2, data: %{ "action" => "report_note_delete", "actor" => %{"id" => "A1I7G8", "nickname" => "admin", "type" => "user"}, @@ -82,6 +86,7 @@ test "renders `report_note_delete` log messages", %{log1: log1, log2: log2} do test "renders `report_note_delete` log message", %{log1: log} do assert ModerationLogView.render("show.json", %{log_entry: log}) == %{ + id: 1, data: %{ "action" => "report_note_delete", "actor" => %{"id" => "A1I7G8", "nickname" => "admin", "type" => "user"}, diff --git a/test/pleroma/web/admin_api/views/report_view_test.exs b/test/pleroma/web/admin_api/views/report_view_test.exs index 5a02292be..3914751b5 100644 --- a/test/pleroma/web/admin_api/views/report_view_test.exs +++ b/test/pleroma/web/admin_api/views/report_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.AdminAPI.ReportViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory @@ -143,4 +143,29 @@ test "doesn't error out when the user doesn't exists" do assert %{} = ReportView.render("show.json", Report.extract_report_info(activity)) end + + test "reports are ordered newest first" do + user = insert(:user) + other_user = insert(:user) + + {:ok, report1} = + CommonAPI.report(user, %{ + account_id: other_user.id, + comment: "first report" + }) + + {:ok, report2} = + CommonAPI.report(user, %{ + account_id: other_user.id, + comment: "second report" + }) + + %{reports: rendered} = + ReportView.render("index.json", + reports: Pleroma.Web.ActivityPub.Utils.get_reports(%{}, 1, 50) + ) + + assert report2.id == rendered |> Enum.at(0) |> Map.get(:id) + assert report1.id == rendered |> Enum.at(1) |> Map.get(:id) + end end diff --git a/test/pleroma/web/auth/authenticator_test.exs b/test/pleroma/web/auth/authenticator_test.exs index d54253343..862eb8051 100644 --- a/test/pleroma/web/auth/authenticator_test.exs +++ b/test/pleroma/web/auth/authenticator_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Auth.AuthenticatorTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Web.Auth.Authenticator import Pleroma.Factory diff --git a/test/pleroma/web/auth/basic_auth_test.exs b/test/pleroma/web/auth/basic_auth_test.exs index bf6e3d2fc..e56c1e1e8 100644 --- a/test/pleroma/web/auth/basic_auth_test.exs +++ b/test/pleroma/web/auth/basic_auth_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Auth.BasicAuthTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory diff --git a/test/pleroma/web/auth/pleroma_authenticator_test.exs b/test/pleroma/web/auth/pleroma_authenticator_test.exs index 1ba0dfecc..4539ffe87 100644 --- a/test/pleroma/web/auth/pleroma_authenticator_test.exs +++ b/test/pleroma/web/auth/pleroma_authenticator_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Web.Auth.PleromaAuthenticator import Pleroma.Factory diff --git a/test/pleroma/web/auth/totp_authenticator_test.exs b/test/pleroma/web/auth/totp_authenticator_test.exs index 84d4cd840..7f99d62bf 100644 --- a/test/pleroma/web/auth/totp_authenticator_test.exs +++ b/test/pleroma/web/auth/totp_authenticator_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Auth.TOTPAuthenticatorTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.MFA alias Pleroma.MFA.BackupCodes diff --git a/test/pleroma/web/common_api_test.exs b/test/pleroma/web/common_api_test.exs index 585b2c174..56a3d6531 100644 --- a/test/pleroma/web/common_api_test.exs +++ b/test/pleroma/web/common_api_test.exs @@ -39,7 +39,7 @@ test "it posts a poll" do poll: %{expires_in: 600, options: ["reimu", "marisa"]} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["type"] == "Question" assert object.data["oneOf"] |> length() == 2 @@ -174,7 +174,7 @@ test "it adds html newlines" do assert other_user.ap_id not in activity.recipients - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "uguu
uguuu" end @@ -194,7 +194,7 @@ test "it linkifies" do assert other_user.ap_id not in activity.recipients - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "https://example.org is the site of Object.prune() with_mock Pleroma.Web.Federator, @@ -491,7 +491,7 @@ test "it de-duplicates tags" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: "#2hu #2HU"}) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["tag"] == ["2hu"] end @@ -500,10 +500,23 @@ test "it adds emoji in the object" do user = insert(:user) {:ok, activity} = CommonAPI.post(user, %{status: ":firefox:"}) - assert Object.normalize(activity).data["emoji"]["firefox"] + assert Object.normalize(activity, fetch: false).data["emoji"]["firefox"] end describe "posting" do + test "it adds an emoji on an external site" do + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{status: "hey :external_emoji:"}) + + assert %{"external_emoji" => url} = Object.normalize(activity).data["emoji"] + assert url == "https://example.com/emoji.png" + + {:ok, activity} = CommonAPI.post(user, %{status: "hey :blank:"}) + + assert %{"blank" => url} = Object.normalize(activity).data["emoji"] + assert url == "#{Pleroma.Web.base_url()}/emoji/blank.png" + end + test "deactivated users can't post" do user = insert(:user, deactivated: true) assert {:error, _} = CommonAPI.post(user, %{status: "ye"}) @@ -539,7 +552,7 @@ test "it filters out obviously bad tags when accepting a post as HTML" do content_type: "text/html" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

2hu

alert('xss')" assert object.data["source"] == post @@ -556,7 +569,7 @@ test "it filters out obviously bad tags when accepting a post as Markdown" do content_type: "text/markdown" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["content"] == "

2hu

alert('xss')" assert object.data["source"] == post @@ -1211,7 +1224,7 @@ test "does not allow to vote twice" do poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _, object} = CommonAPI.vote(other_user, object, [0]) @@ -1231,7 +1244,7 @@ test "returns a valid activity" do length: 180_000 }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" @@ -1250,7 +1263,7 @@ test "respects visibility=private" do visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert object.data["title"] == "lain radio episode 1" diff --git a/test/pleroma/web/endpoint/metrics_exporter_test.exs b/test/pleroma/web/endpoint/metrics_exporter_test.exs index 875addc96..d0cae3d42 100644 --- a/test/pleroma/web/endpoint/metrics_exporter_test.exs +++ b/test/pleroma/web/endpoint/metrics_exporter_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Endpoint.MetricsExporterTest do + # Modifies AppEnv, has to stay synchronous use Pleroma.Web.ConnCase alias Pleroma.Web.Endpoint.MetricsExporter diff --git a/test/pleroma/web/feed/tag_controller_test.exs b/test/pleroma/web/feed/tag_controller_test.exs index e4084b0e5..48dc3b404 100644 --- a/test/pleroma/web/feed/tag_controller_test.exs +++ b/test/pleroma/web/feed/tag_controller_test.exs @@ -24,7 +24,7 @@ test "gets a feed (ATOM)", %{conn: conn} do user = insert(:user) {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"}) - object = Object.normalize(activity1) + object = Object.normalize(activity1, fetch: false) object_data = Map.put(object.data, "attachment", [ @@ -91,7 +91,7 @@ test "gets a feed (RSS)", %{conn: conn} do user = insert(:user) {:ok, activity1} = CommonAPI.post(user, %{status: "yeah #PleromaArt"}) - object = Object.normalize(activity1) + object = Object.normalize(activity1, fetch: false) object_data = Map.put(object.data, "attachment", [ @@ -131,7 +131,7 @@ test "gets a feed (RSS)", %{conn: conn} do '#{Pleroma.Web.base_url()}/tags/pleromaart.rss' assert xpath(xml, ~x"//channel/webfeeds:logo/text()") == - '#{Pleroma.Web.base_url()}/static/logo.png' + '#{Pleroma.Web.base_url()}/static/logo.svg' assert xpath(xml, ~x"//channel/item/title/text()"l) == [ '42 This is :moominmamm...', @@ -147,8 +147,8 @@ test "gets a feed (RSS)", %{conn: conn} do "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4" ] - obj1 = Object.normalize(activity1) - obj2 = Object.normalize(activity2) + obj1 = Object.normalize(activity1, fetch: false) + obj2 = Object.normalize(activity2, fetch: false) assert xpath(xml, ~x"//channel/item/description/text()"sl) == [ HtmlEntities.decode(FeedView.activity_content(obj2.data)), diff --git a/test/pleroma/web/feed/user_controller_test.exs b/test/pleroma/web/feed/user_controller_test.exs index 16f002717..50445862b 100644 --- a/test/pleroma/web/feed/user_controller_test.exs +++ b/test/pleroma/web/feed/user_controller_test.exs @@ -58,7 +58,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do ) note_activity2 = insert(:note_activity, note: note2) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) [user: user, object: object, max_id: note_activity2.id] end diff --git a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index 3361c8669..cc7b3cf8b 100644 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@ -469,6 +469,21 @@ test "muted reactions", %{user: user, conn: conn} do } ] = result end + + test "paginates a user's statuses", %{user: user, conn: conn} do + {:ok, post_1} = CommonAPI.post(user, %{status: "first post"}) + {:ok, post_2} = CommonAPI.post(user, %{status: "second post"}) + + response_1 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1") + assert [res] = json_response(response_1, 200) + assert res["id"] == post_2.id + + response_2 = get(conn, "/api/v1/accounts/#{user.id}/statuses?limit=1&max_id=#{res["id"]}") + assert [res] = json_response(response_2, 200) + assert res["id"] == post_1.id + + refute response_1 == response_2 + end end defp local_and_remote_activities(%{local: local, remote: remote}) do @@ -1411,8 +1426,6 @@ test "creates an account and returns 200 if captcha is valid", %{conn: conn} do |> json_response_and_validate_schema(:ok) assert Token |> Repo.get_by(token: access_token) |> Repo.preload(:user) |> Map.get(:user) - - Cachex.del(:used_captcha_cache, token) end test "returns 400 if any captcha field is not provided", %{conn: conn} do diff --git a/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs index d7834c876..ce957054b 100644 --- a/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/auth_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Config alias Pleroma.Repo diff --git a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs index b00615ac9..a03513e06 100644 --- a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Conversation.Participation alias Pleroma.User diff --git a/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs index 664654500..b10aa6966 100644 --- a/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/domain_block_controller_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do + # TODO: Should not need Cachex use Pleroma.Web.ConnCase alias Pleroma.User diff --git a/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs index 0d426ec34..e639cdde1 100644 --- a/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/filter_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Web.MastodonAPI.FilterView diff --git a/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs index b977b41ae..f0a466212 100644 --- a/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/follow_request_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.FollowRequestControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.User alias Pleroma.Web.CommonAPI 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 605df6ed6..71a170240 100644 --- a/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/instance_controller_test.exs @@ -3,6 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do + # TODO: Should not need Cachex use Pleroma.Web.ConnCase alias Pleroma.User diff --git a/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs index 091ec006c..01f64cfcc 100644 --- a/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/list_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ListControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Repo diff --git a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs index 9f0481120..ee944a67c 100644 --- a/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/marker_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory diff --git a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs index f41de6448..71cea8462 100644 --- a/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/poll_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.PollControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Object alias Pleroma.Web.CommonAPI @@ -20,7 +20,7 @@ test "returns poll entity for object id", %{user: user, conn: conn} do poll: %{options: ["what Mastodon't", "n't what Mastodoes"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = get(conn, "/api/v1/polls/#{object.id}") @@ -39,7 +39,7 @@ test "does not expose polls for private statuses", %{conn: conn} do visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = get(conn, "/api/v1/polls/#{object.id}") @@ -63,7 +63,7 @@ test "votes are added to the poll", %{conn: conn} do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = conn @@ -85,7 +85,7 @@ test "author can't vote", %{user: user, conn: conn} do poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert conn |> put_req_header("content-type", "application/json") @@ -106,7 +106,7 @@ test "does not allow multiple choices on a single-choice question", %{conn: conn poll: %{options: ["half empty", "half full"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert conn |> put_req_header("content-type", "application/json") @@ -129,7 +129,7 @@ test "does not allow choice index to be greater than options count", %{conn: con poll: %{options: ["Yes", "No"], expires_in: 20} }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = conn @@ -158,7 +158,7 @@ test "returns 404 when poll is private and not available for user", %{conn: conn visibility: "private" }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) conn = conn diff --git a/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs index 6636cff96..322eb475c 100644 --- a/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/report_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Web.CommonAPI diff --git a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs index 1045ab265..664bdce01 100644 --- a/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/search_controller_test.exs @@ -309,7 +309,7 @@ test "search doesn't show statuses that it shouldn't", %{conn: conn} do }) capture_log(fn -> - q = Object.normalize(activity).data["id"] + q = Object.normalize(activity, fetch: false).data["id"] results = conn diff --git a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs index 30d542dfa..ffff0ae9d 100644 --- a/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/status_controller_test.exs @@ -67,10 +67,6 @@ test "posting a status", %{conn: conn} do "sensitive" => "0" }) - {:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key) - # Six hours - assert ttl > :timer.seconds(6 * 60 * 60 - 1) - assert %{"content" => "cofe", "id" => id, "spoiler_text" => "2hu", "sensitive" => false} = json_response_and_validate_schema(conn_one, 200) @@ -804,7 +800,7 @@ test "if user is authenticated", %{local: local, remote: remote} do test "when you created it" do %{user: author, conn: conn} = oauth_access(["write:statuses"]) activity = insert(:note_activity, user: author) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) content = object.data["content"] source = object.data["source"] @@ -1378,7 +1374,9 @@ test "Repeated posts that are replies incorrectly have in_reply_to_id null", %{c activity = Activity.get_by_id_with_object(id) - assert Object.normalize(activity).data["inReplyTo"] == Object.normalize(replied_to).data["id"] + assert Object.normalize(activity, fetch: false).data["inReplyTo"] == + Object.normalize(replied_to, fetch: false).data["id"] + assert Activity.get_in_reply_to_activity(activity).id == replied_to.id # Reblog from the third user diff --git a/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs index 5ef39bdb2..4bb085750 100644 --- a/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/subscription_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory diff --git a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs index 7f08e187c..c3471266a 100644 --- a/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/suggestion_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true setup do: oauth_access(["read"]) diff --git a/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs b/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs index bb4bc4396..be5bf68a3 100644 --- a/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/pleroma/web/mastodon_api/mastodon_api_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true describe "empty_array/2 (stubs)" do test "GET /api/v1/accounts/:id/identity_proofs" do diff --git a/test/pleroma/web/mastodon_api/mastodon_api_test.exs b/test/pleroma/web/mastodon_api/mastodon_api_test.exs index 687fe5585..cf7f464be 100644 --- a/test/pleroma/web/mastodon_api/mastodon_api_test.exs +++ b/test/pleroma/web/mastodon_api/mastodon_api_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Notification alias Pleroma.ScheduledActivity diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index ed1921c91..e3e437a19 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -11,8 +11,6 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do import Mock import Pleroma.Factory - setup do: clear_config([:instance, :max_account_fields]) - describe "updating credentials" do setup do: oauth_access(["write:accounts"]) setup :request_content_type @@ -220,6 +218,25 @@ test "updates the user's name", %{conn: conn} do assert update_activity.data["object"]["name"] == "markorepairs" end + test "updates the user's AKAs", %{conn: conn} do + conn = + patch(conn, "/api/v1/accounts/update_credentials", %{ + "also_known_as" => ["https://mushroom.kingdom/users/mario"] + }) + + assert user_data = json_response_and_validate_schema(conn, 200) + assert user_data["pleroma"]["also_known_as"] == ["https://mushroom.kingdom/users/mario"] + end + + test "doesn't update non-url akas", %{conn: conn} do + conn = + patch(conn, "/api/v1/accounts/update_credentials", %{ + "also_known_as" => ["aReallyCoolGuy"] + }) + + assert json_response_and_validate_schema(conn, 403) + end + test "updates the user's avatar", %{user: user, conn: conn} do new_avatar = %Plug.Upload{ content_type: "image/jpeg", @@ -446,7 +463,7 @@ test "update fields when invalid request", %{conn: conn} do |> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields}) |> json_response_and_validate_schema(403) - Pleroma.Config.put([:instance, :max_account_fields], 1) + clear_config([:instance, :max_account_fields], 1) fields = [ %{"name" => "foo", "value" => "bar"}, diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 8c77f14d4..f9afd0afc 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -35,7 +35,8 @@ test "Represent a user account" do "valid html. a
b
c
d
f '&<>\"", inserted_at: ~N[2017-08-15 15:47:06.597036], emoji: %{"karjalanpiirakka" => "/file.png"}, - raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"" + raw_bio: "valid html. a\nb\nc\nd\nf '&<>\"", + also_known_as: ["https://shitposter.zone/users/shp"] }) expected = %{ @@ -75,6 +76,7 @@ test "Represent a user account" do }, pleroma: %{ ap_id: user.ap_id, + also_known_as: ["https://shitposter.zone/users/shp"], background_image: "https://example.com/images/asuka_hospital.png", favicon: nil, confirmation_pending: false, @@ -173,6 +175,7 @@ test "Represent a Service(bot) account" do }, pleroma: %{ ap_id: user.ap_id, + also_known_as: [], background_image: nil, favicon: nil, confirmation_pending: false, diff --git a/test/pleroma/web/mastodon_api/views/conversation_view_test.exs b/test/pleroma/web/mastodon_api/views/conversation_view_test.exs index 20c10ba3d..f02253b68 100644 --- a/test/pleroma/web/mastodon_api/views/conversation_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/conversation_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Conversation.Participation alias Pleroma.Web.CommonAPI diff --git a/test/pleroma/web/mastodon_api/views/list_view_test.exs b/test/pleroma/web/mastodon_api/views/list_view_test.exs index ca99242cb..377941332 100644 --- a/test/pleroma/web/mastodon_api/views/list_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/list_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ListViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.MastodonAPI.ListView diff --git a/test/pleroma/web/mastodon_api/views/marker_view_test.exs b/test/pleroma/web/mastodon_api/views/marker_view_test.exs index 48a0a6d33..a0bec758f 100644 --- a/test/pleroma/web/mastodon_api/views/marker_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/marker_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.MastodonAPI.MarkerView import Pleroma.Factory diff --git a/test/pleroma/web/mastodon_api/views/notification_view_test.exs b/test/pleroma/web/mastodon_api/views/notification_view_test.exs index 9de11a87e..79dd23a51 100644 --- a/test/pleroma/web/mastodon_api/views/notification_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/notification_view_test.exs @@ -44,7 +44,7 @@ test "ChatMessage notification" do {:ok, [notification]} = Notification.create_notifications(activity) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) chat = Chat.get(recipient.id, user.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/test/pleroma/web/mastodon_api/views/poll_view_test.exs b/test/pleroma/web/mastodon_api/views/poll_view_test.exs index c655ca438..f83e5b368 100644 --- a/test/pleroma/web/mastodon_api/views/poll_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/poll_view_test.exs @@ -29,7 +29,7 @@ test "renders a poll" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) expected = %{ emojis: [], @@ -72,7 +72,7 @@ test "detects if it is multiple choice" do voter = insert(:user) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1]) @@ -98,7 +98,7 @@ test "detects emoji" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert %{emojis: [%{shortcode: "blank"}]} = PollView.render("show.json", %{object: object}) end @@ -117,7 +117,7 @@ test "detects vote status" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) {:ok, _, object} = CommonAPI.vote(other_user, object, [1, 2]) @@ -129,7 +129,7 @@ test "detects vote status" do end test "does not crash on polls with no end date" do - object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i") + object = Object.normalize("https://skippers-bin.com/notes/7x9tmrp97i", fetch: true) result = PollView.render("show.json", %{object: object}) assert result[:expires_at] == nil @@ -153,7 +153,7 @@ test "doesn't strips HTML tags" do } }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert %{ options: [ diff --git a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs index 04f73f5a0..c41ac7f7f 100644 --- a/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.ScheduledActivity alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.CommonAPI diff --git a/test/pleroma/web/mastodon_api/views/status_view_test.exs b/test/pleroma/web/mastodon_api/views/status_view_test.exs index f2a7469ed..789acb487 100644 --- a/test/pleroma/web/mastodon_api/views/status_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/status_view_test.exs @@ -61,7 +61,7 @@ test "works correctly with badly formatted emojis" do {:ok, activity} = CommonAPI.post(user, %{status: "yo"}) activity - |> Object.normalize(false) + |> Object.normalize(fetch: false) |> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}}) activity = Activity.get_by_id(activity.id) @@ -160,7 +160,7 @@ test "returns a temporary ap_id based user for activities missing db users" do {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"}) Repo.delete(user) - Cachex.clear(:user_cache) + User.invalidate_cache(user) finger_url = "https://localhost/.well-known/webfinger?resource=acct:#{user.nickname}@localhost" @@ -194,7 +194,7 @@ test "tries to get a user by nickname if fetching by ap_id doesn't work" do |> Ecto.Changeset.change(%{ap_id: "#{user.ap_id}/extension/#{user.nickname}"}) |> Repo.update() - Cachex.clear(:user_cache) + User.invalidate_cache(user) result = StatusView.render("show.json", activity: activity) @@ -204,7 +204,7 @@ test "tries to get a user by nickname if fetching by ap_id doesn't work" do test "a note with null content" do note = insert(:note_activity) - note_object = Object.normalize(note) + note_object = Object.normalize(note, fetch: false) data = note_object.data @@ -223,7 +223,7 @@ test "a note with null content" do test "a note activity" do note = insert(:note_activity) - object_data = Object.normalize(note).data + object_data = Object.normalize(note, fetch: false).data user = User.get_cached_by_ap_id(note.data["actor"]) convo_id = Utils.context_to_conversation_id(object_data["context"]) diff --git a/test/pleroma/web/mastodon_api/views/subscription_view_test.exs b/test/pleroma/web/mastodon_api/views/subscription_view_test.exs index 981524c0e..c2bb535c5 100644 --- a/test/pleroma/web/mastodon_api/views/subscription_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/subscription_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MastodonAPI.SubscriptionViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.MastodonAPI.SubscriptionView, as: View alias Pleroma.Web.Push diff --git a/test/pleroma/web/media_proxy/invalidation/http_test.exs b/test/pleroma/web/media_proxy/invalidation/http_test.exs index 13d081325..c81010423 100644 --- a/test/pleroma/web/media_proxy/invalidation/http_test.exs +++ b/test/pleroma/web/media_proxy/invalidation/http_test.exs @@ -9,10 +9,6 @@ defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do import ExUnit.CaptureLog import Tesla.Mock - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - test "logs hasn't error message when request is valid" do mock(fn %{method: :purge, url: "http://example.com/media/example.jpg"} -> diff --git a/test/pleroma/web/media_proxy/invalidation/script_test.exs b/test/pleroma/web/media_proxy/invalidation/script_test.exs index 692cbb2df..6940a4539 100644 --- a/test/pleroma/web/media_proxy/invalidation/script_test.exs +++ b/test/pleroma/web/media_proxy/invalidation/script_test.exs @@ -3,15 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do - use ExUnit.Case + use ExUnit.Case, async: true alias Pleroma.Web.MediaProxy.Invalidation import ExUnit.CaptureLog - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - test "it logger error when script not found" do assert capture_log(fn -> assert Invalidation.Script.purge( diff --git a/test/pleroma/web/media_proxy/invalidation_test.exs b/test/pleroma/web/media_proxy/invalidation_test.exs index aa1435ac0..b7be36b47 100644 --- a/test/pleroma/web/media_proxy/invalidation_test.exs +++ b/test/pleroma/web/media_proxy/invalidation_test.exs @@ -3,8 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MediaProxy.InvalidationTest do - use ExUnit.Case - use Pleroma.Tests.Helpers + use Pleroma.DataCase alias Pleroma.Config alias Pleroma.Web.MediaProxy.Invalidation @@ -15,10 +14,6 @@ defmodule Pleroma.Web.MediaProxy.InvalidationTest do setup do: clear_config([:media_proxy]) - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - describe "Invalidation.Http" do test "perform request to clear cache" do Config.put([:media_proxy, :enabled], false) diff --git a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs index e9b584822..65cf2a01b 100644 --- a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs +++ b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs @@ -10,10 +10,6 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do alias Pleroma.Web.MediaProxy alias Plug.Conn - setup do - on_exit(fn -> Cachex.clear(:banned_urls_cache) end) - end - describe "Media Proxy" do setup do clear_config([:media_proxy, :enabled], true) diff --git a/test/pleroma/web/metadata/player_view_test.exs b/test/pleroma/web/metadata/player_view_test.exs index e6c990242..6d22317d2 100644 --- a/test/pleroma/web/metadata/player_view_test.exs +++ b/test/pleroma/web/metadata/player_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.PlayerViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.Metadata.PlayerView diff --git a/test/pleroma/web/metadata/providers/feed_test.exs b/test/pleroma/web/metadata/providers/feed_test.exs index e6e5cc5ed..c7359e00b 100644 --- a/test/pleroma/web/metadata/providers/feed_test.exs +++ b/test/pleroma/web/metadata/providers/feed_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.FeedTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.Metadata.Providers.Feed diff --git a/test/pleroma/web/metadata/providers/rel_me_test.exs b/test/pleroma/web/metadata/providers/rel_me_test.exs index 2293d6e13..ae449c052 100644 --- a/test/pleroma/web/metadata/providers/rel_me_test.exs +++ b/test/pleroma/web/metadata/providers/rel_me_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.Providers.RelMeTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.Metadata.Providers.RelMe diff --git a/test/pleroma/web/metadata/utils_test.exs b/test/pleroma/web/metadata/utils_test.exs index 8183256d8..3794db766 100644 --- a/test/pleroma/web/metadata/utils_test.exs +++ b/test/pleroma/web/metadata/utils_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Metadata.UtilsTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.Metadata.Utils diff --git a/test/pleroma/web/mongoose_im_controller_test.exs b/test/pleroma/web/mongoose_im_controller_test.exs index e3a8aa3d8..4590e1296 100644 --- a/test/pleroma/web/mongoose_im_controller_test.exs +++ b/test/pleroma/web/mongoose_im_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.MongooseIMControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory test "/user_exists", %{conn: conn} do diff --git a/test/pleroma/web/o_auth/app_test.exs b/test/pleroma/web/o_auth/app_test.exs index 993a490e0..24d7049f1 100644 --- a/test/pleroma/web/o_auth/app_test.exs +++ b/test/pleroma/web/o_auth/app_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.AppTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.OAuth.App import Pleroma.Factory diff --git a/test/pleroma/web/o_auth/authorization_test.exs b/test/pleroma/web/o_auth/authorization_test.exs index d74b26cf8..d1920962c 100644 --- a/test/pleroma/web/o_auth/authorization_test.exs +++ b/test/pleroma/web/o_auth/authorization_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.AuthorizationTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.Authorization import Pleroma.Factory diff --git a/test/pleroma/web/o_auth/mfa_controller_test.exs b/test/pleroma/web/o_auth/mfa_controller_test.exs index 6ecd0f6c9..bc50d8d18 100644 --- a/test/pleroma/web/o_auth/mfa_controller_test.exs +++ b/test/pleroma/web/o_auth/mfa_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.MFAControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory alias Pleroma.MFA diff --git a/test/pleroma/web/o_auth/token/utils_test.exs b/test/pleroma/web/o_auth/token/utils_test.exs index a610d92f8..3444692ec 100644 --- a/test/pleroma/web/o_auth/token/utils_test.exs +++ b/test/pleroma/web/o_auth/token/utils_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.Token.UtilsTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.OAuth.Token.Utils import Pleroma.Factory diff --git a/test/pleroma/web/o_auth/token_test.exs b/test/pleroma/web/o_auth/token_test.exs index c88b9cc98..866f1c00a 100644 --- a/test/pleroma/web/o_auth/token_test.exs +++ b/test/pleroma/web/o_auth/token_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.OAuth.TokenTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Repo alias Pleroma.Web.OAuth.App alias Pleroma.Web.OAuth.Authorization diff --git a/test/pleroma/web/o_status/o_status_controller_test.exs b/test/pleroma/web/o_status/o_status_controller_test.exs index 65b2c22db..f21180a89 100644 --- a/test/pleroma/web/o_status/o_status_controller_test.exs +++ b/test/pleroma/web/o_status/o_status_controller_test.exs @@ -72,7 +72,7 @@ test "redirects to /notice/:id for html format for activity", %{ test "redirects to /notice/id for html format", %{conn: conn} do note_activity = insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"])) url = "/objects/#{uuid}" @@ -82,7 +82,7 @@ test "redirects to /notice/id for html format", %{conn: conn} do test "404s on private objects", %{conn: conn} do note_activity = insert(:direct_note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"])) conn @@ -133,7 +133,7 @@ test "redirects to a proper object URL when json requested and the object is loc conn: conn } do note_activity = insert(:note_activity) - expected_redirect_url = Object.normalize(note_activity).data["id"] + expected_redirect_url = Object.normalize(note_activity, fetch: false).data["id"] redirect_url = conn @@ -230,7 +230,7 @@ test "does not require authentication on non-federating instances", %{ describe "GET /notice/:id/embed_player" do setup do note_activity = insert(:note_activity) - object = Pleroma.Object.normalize(note_activity) + object = Pleroma.Object.normalize(note_activity, fetch: false) object_data = Map.put(object.data, "attachment", [ @@ -287,7 +287,7 @@ test "404s when activity is direct message", %{conn: conn} do test "404s when attachment is empty", %{conn: conn} do note_activity = insert(:note_activity) - object = Pleroma.Object.normalize(note_activity) + object = Pleroma.Object.normalize(note_activity, fetch: false) object_data = Map.put(object.data, "attachment", []) object @@ -301,7 +301,7 @@ test "404s when attachment is empty", %{conn: conn} do test "404s when attachment isn't audio or video", %{conn: conn} do note_activity = insert(:note_activity) - object = Pleroma.Object.normalize(note_activity) + object = Pleroma.Object.normalize(note_activity, fetch: false) object_data = Map.put(object.data, "attachment", [ diff --git a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs index a6c9d0c1b..24efeeb73 100644 --- a/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs @@ -22,7 +22,7 @@ test "it marks one message as read", %{conn: conn, user: user} do {:ok, create} = CommonAPI.post_chat_message(other_user, user, "sup") {:ok, _create} = CommonAPI.post_chat_message(other_user, user, "sup part 2") {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id) - object = Object.normalize(create, false) + object = Object.normalize(create, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) assert cm_ref.unread == true @@ -52,7 +52,7 @@ test "given a `last_read_id`, it marks everything until then as read", %{ {:ok, create} = CommonAPI.post_chat_message(other_user, user, "sup") {:ok, _create} = CommonAPI.post_chat_message(other_user, user, "sup part 2") {:ok, chat} = Chat.get_or_create(user.id, other_user.ap_id) - object = Object.normalize(create, false) + object = Object.normalize(create, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) assert cm_ref.unread == true @@ -158,7 +158,7 @@ test "it deletes a message from the chat", %{conn: conn, user: user} do {:ok, other_message} = CommonAPI.post_chat_message(recipient, user, "nico nico ni") - object = Object.normalize(message, false) + object = Object.normalize(message, fetch: false) chat = Chat.get(user.id, recipient.ap_id) @@ -176,7 +176,7 @@ test "it deletes a message from the chat", %{conn: conn, user: user} do assert %{data: %{"type" => "Tombstone"}} = Object.get_by_id(object.id) # Deleting other people's messages just removes the reference - object = Object.normalize(other_message, false) + object = Object.normalize(other_message, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) result = @@ -394,11 +394,11 @@ test "it return a list of chats the current user is participating in, in descend tridi = insert(:user) {:ok, chat_1} = Chat.get_or_create(user.id, har.ap_id) - :timer.sleep(1000) - {:ok, _chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id) - :timer.sleep(1000) + {:ok, chat_1} = time_travel(chat_1, -3) + {:ok, chat_2} = Chat.get_or_create(user.id, jafnhar.ap_id) + {:ok, _chat_2} = time_travel(chat_2, -2) {:ok, chat_3} = Chat.get_or_create(user.id, tridi.ap_id) - :timer.sleep(1000) + {:ok, chat_3} = time_travel(chat_3, -1) # bump the second one {:ok, chat_2} = Chat.bump_or_create(user.id, jafnhar.ap_id) diff --git a/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs index f2feeaaef..c8c2433ae 100644 --- a/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/conversation_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.ConversationControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Conversation.Participation alias Pleroma.Repo diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs index 82de86ee3..6fbdaec7a 100644 --- a/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/emoji_file_controller_test.exs @@ -5,6 +5,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileControllerTest do use Pleroma.Web.ConnCase + import Mock import Tesla.Mock import Pleroma.Factory @@ -200,6 +201,31 @@ test "add file with not loaded pack", %{admin_conn: admin_conn} do } end + test "returns an error on add file when file system is not writable", %{ + admin_conn: admin_conn + } do + pack_file = Path.join([@emoji_path, "not_loaded", "pack.json"]) + + with_mocks([ + {File, [:passthrough], [stat: fn ^pack_file -> {:error, :eacces} end]} + ]) do + assert admin_conn + |> put_req_header("content-type", "multipart/form-data") + |> post("/api/pleroma/emoji/packs/files?name=not_loaded", %{ + shortcode: "blank3", + filename: "dir/blank.png", + file: %Plug.Upload{ + filename: "blank.png", + path: "#{@emoji_path}/test_pack/blank.png" + } + }) + |> json_response_and_validate_schema(500) == %{ + "error" => + "Unexpected error occurred while adding file to pack. (POSIX error: Permission denied)" + } + end + end + test "remove file with not loaded pack", %{admin_conn: admin_conn} do assert admin_conn |> delete("/api/pleroma/emoji/packs/files?name=not_loaded&shortcode=blank3") diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs index 3445f0ca0..d9385389b 100644 --- a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs @@ -3,8 +3,9 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: false + import Mock import Tesla.Mock import Pleroma.Factory @@ -346,7 +347,7 @@ test "other error", %{admin_conn: admin_conn} do end end - describe "PATCH /api/pleroma/emoji/pack?name=:name" do + describe "PATCH/update /api/pleroma/emoji/pack?name=:name" do setup do pack_file = "#{@emoji_path}/test_pack/pack.json" original_content = File.read!(pack_file) @@ -365,6 +366,20 @@ test "other error", %{admin_conn: admin_conn} do }} end + test "returns error when file system not writable", %{admin_conn: conn} = ctx do + with_mocks([ + {File, [:passthrough], [stat: fn _ -> {:error, :eacces} end]} + ]) do + assert conn + |> put_req_header("content-type", "multipart/form-data") + |> patch( + "/api/pleroma/emoji/pack?name=test_pack", + %{"metadata" => ctx[:new_data]} + ) + |> json_response_and_validate_schema(500) + end + end + test "for a pack without a fallback source", ctx do assert ctx[:admin_conn] |> put_req_header("content-type", "multipart/form-data") @@ -424,6 +439,46 @@ test "when the fallback source doesn't have all the files", ctx do end describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do + test "returns an error on creates pack when file system not writable", %{ + admin_conn: admin_conn + } do + path_pack = Path.join(@emoji_path, "test_pack") + + with_mocks([ + {File, [:passthrough], [mkdir: fn ^path_pack -> {:error, :eacces} end]} + ]) do + assert admin_conn + |> post("/api/pleroma/emoji/pack?name=test_pack") + |> json_response_and_validate_schema(500) == %{ + "error" => + "Unexpected error occurred while creating pack. (POSIX error: Permission denied)" + } + end + end + + test "returns an error on deletes pack when the file system is not writable", %{ + admin_conn: admin_conn + } do + path_pack = Path.join(@emoji_path, "test_emoji_pack") + + try do + {:ok, _pack} = Pleroma.Emoji.Pack.create("test_emoji_pack") + + with_mocks([ + {File, [:passthrough], [rm_rf: fn ^path_pack -> {:error, :eacces, path_pack} end]} + ]) do + assert admin_conn + |> delete("/api/pleroma/emoji/pack?name=test_emoji_pack") + |> json_response_and_validate_schema(500) == %{ + "error" => + "Couldn't delete the `test_emoji_pack` pack (POSIX error: Permission denied)" + } + end + after + File.rm_rf(path_pack) + end + end + test "creating and deleting a pack", %{admin_conn: admin_conn} do assert admin_conn |> post("/api/pleroma/emoji/pack?name=test_created") diff --git a/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs index 289119d45..5f8fa03f6 100644 --- a/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/mascot_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.User diff --git a/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs index bb4fe6c49..03af4d70c 100644 --- a/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/notification_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.NotificationControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Notification alias Pleroma.Repo diff --git a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs index f39c07ac6..4ab6d9132 100644 --- a/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/scrobble_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Web.CommonAPI diff --git a/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs index 22988c881..8d4e0104a 100644 --- a/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs +++ b/test/pleroma/web/pleroma_api/controllers/two_factor_authentication_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.TwoFactorAuthenticationControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true import Pleroma.Factory alias Pleroma.MFA.Settings diff --git a/test/pleroma/web/pleroma_api/views/backup_view_test.exs b/test/pleroma/web/pleroma_api/views/backup_view_test.exs new file mode 100644 index 000000000..7dda8480b --- /dev/null +++ b/test/pleroma/web/pleroma_api/views/backup_view_test.exs @@ -0,0 +1,18 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.PleromaAPI.BackupViewTest do + use Pleroma.DataCase, async: true + alias Pleroma.User.Backup + alias Pleroma.Web.PleromaAPI.BackupView + import Pleroma.Factory + + test "it renders the ID" do + user = insert(:user) + backup = Backup.new(user) + + result = BackupView.render("show.json", backup: backup) + assert result.id == backup.id + end +end diff --git a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs index 93eef00a2..0966e9166 100644 --- a/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs +++ b/test/pleroma/web/pleroma_api/views/chat_message_reference_view_test.exs @@ -31,7 +31,7 @@ test "it displays a chat message" do chat = Chat.get(user.id, recipient.ap_id) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) @@ -58,7 +58,7 @@ test "it displays a chat message" do media_id: upload.id ) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) cm_ref = MessageReference.for_chat_and_object(chat, object) diff --git a/test/pleroma/web/pleroma_api/views/chat_view_test.exs b/test/pleroma/web/pleroma_api/views/chat_view_test.exs index 02484b705..1cc5f16ba 100644 --- a/test/pleroma/web/pleroma_api/views/chat_view_test.exs +++ b/test/pleroma/web/pleroma_api/views/chat_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.ChatViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Chat alias Pleroma.Chat.MessageReference @@ -35,7 +35,7 @@ test "it represents a chat" do {:ok, chat_message_creation} = CommonAPI.post_chat_message(user, recipient, "hello") - chat_message = Object.normalize(chat_message_creation, false) + chat_message = Object.normalize(chat_message_creation, fetch: false) {:ok, chat} = Chat.get_or_create(user.id, recipient.ap_id) diff --git a/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs b/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs index 0f43cbdc3..113b8f690 100644 --- a/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs +++ b/test/pleroma/web/pleroma_api/views/scrobble_view_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.PleromaAPI.ScrobbleViewTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.PleromaAPI.ScrobbleView diff --git a/test/pleroma/web/plugs/cache_control_test.exs b/test/pleroma/web/plugs/cache_control_test.exs index fcf3d2be8..c775787ca 100644 --- a/test/pleroma/web/plugs/cache_control_test.exs +++ b/test/pleroma/web/plugs/cache_control_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.CacheControlTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Plug.Conn test "Verify Cache-Control header on static assets", %{conn: conn} do diff --git a/test/pleroma/web/plugs/cache_test.exs b/test/pleroma/web/plugs/cache_test.exs index 93a66f5d3..0e5fa6f36 100644 --- a/test/pleroma/web/plugs/cache_test.exs +++ b/test/pleroma/web/plugs/cache_test.exs @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.CacheTest do - use ExUnit.Case, async: true + # Relies on Cachex, has to stay synchronous + use Pleroma.DataCase use Plug.Test alias Pleroma.Web.Plugs.Cache @@ -24,11 +25,6 @@ defmodule Pleroma.Web.Plugs.CacheTest do @ttl 5 - setup do - Cachex.clear(:web_resp_cache) - :ok - end - test "caches a response" do assert @miss_resp == conn(:get, "/") diff --git a/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs b/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs index 211443a55..9f15f5c93 100644 --- a/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs +++ b/test/pleroma/web/plugs/ensure_public_or_authenticated_plug_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlugTest do - use Pleroma.Web.ConnCase, async: true + use Pleroma.Web.ConnCase alias Pleroma.Config alias Pleroma.User diff --git a/test/pleroma/web/plugs/idempotency_plug_test.exs b/test/pleroma/web/plugs/idempotency_plug_test.exs index 4a7835993..ed8b3fc1a 100644 --- a/test/pleroma/web/plugs/idempotency_plug_test.exs +++ b/test/pleroma/web/plugs/idempotency_plug_test.exs @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.IdempotencyPlugTest do - use ExUnit.Case, async: true + # Relies on Cachex, has to stay synchronous + use Pleroma.DataCase use Plug.Test alias Pleroma.Web.Plugs.IdempotencyPlug diff --git a/test/pleroma/web/plugs/uploaded_media_plug_test.exs b/test/pleroma/web/plugs/uploaded_media_plug_test.exs index 7c8313121..bae9208ec 100644 --- a/test/pleroma/web/plugs/uploaded_media_plug_test.exs +++ b/test/pleroma/web/plugs/uploaded_media_plug_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.UploadedMediaPlugTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Upload defp upload_file(context) do diff --git a/test/pleroma/web/plugs/user_enabled_plug_test.exs b/test/pleroma/web/plugs/user_enabled_plug_test.exs index 71c56f03a..e9c9e5f3e 100644 --- a/test/pleroma/web/plugs/user_enabled_plug_test.exs +++ b/test/pleroma/web/plugs/user_enabled_plug_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.UserEnabledPlugTest do - use Pleroma.Web.ConnCase, async: true + use Pleroma.Web.ConnCase alias Pleroma.Web.Plugs.UserEnabledPlug import Pleroma.Factory diff --git a/test/pleroma/web/preload/providers/instance_test.exs b/test/pleroma/web/preload/providers/instance_test.exs index 8493f2a94..6033899b0 100644 --- a/test/pleroma/web/preload/providers/instance_test.exs +++ b/test/pleroma/web/preload/providers/instance_test.exs @@ -50,7 +50,7 @@ test "it renders the frontend configurations", %{ "/api/pleroma/frontend_configurations" => fe_configs } do assert %{ - pleroma_fe: %{background: "/images/city.jpg", logo: "/static/logo.png"} + pleroma_fe: %{background: "/images/city.jpg", logo: "/static/logo.svg"} } = fe_configs end end diff --git a/test/pleroma/web/preload/providers/user_test.exs b/test/pleroma/web/preload/providers/user_test.exs index 83f065e27..6be03af79 100644 --- a/test/pleroma/web/preload/providers/user_test.exs +++ b/test/pleroma/web/preload/providers/user_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Preload.Providers.UserTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Web.Preload.Providers.User diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index 2a4a8fd06..d14e0bdef 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Push.ImplTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory @@ -118,7 +118,7 @@ test "renders title and body for create activity" do "Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis." }) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body( %{ @@ -137,7 +137,7 @@ test "renders title and body for follow activity" do user = insert(:user, nickname: "Bob") other_user = insert(:user) {:ok, _, _, activity} = CommonAPI.follow(user, other_user) - object = Object.normalize(activity, false) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "follow"}, user, object) == "@Bob has followed you" @@ -156,7 +156,7 @@ test "renders title and body for announce activity" do }) {:ok, announce_activity} = CommonAPI.repeat(activity.id, user) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: announce_activity}, user, object) == "@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..." @@ -175,7 +175,7 @@ test "renders title and body for like activity" do }) {:ok, activity} = CommonAPI.favorite(user, activity.id) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "favourite"}, user, object) == "@Bob has favorited your post" @@ -193,7 +193,7 @@ test "renders title and body for pleroma:emoji_reaction activity" do }) {:ok, activity} = CommonAPI.react_with_emoji(activity.id, user, "👍") - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.format_body(%{activity: activity, type: "pleroma:emoji_reaction"}, user, object) == "@Bob reacted with 👍" @@ -221,7 +221,7 @@ test "builds content for chat messages" do recipient = insert(:user) {:ok, chat} = CommonAPI.post_chat_message(user, recipient, "hey") - object = Object.normalize(chat, false) + object = Object.normalize(chat, fetch: false) [notification] = Notification.for_user(recipient) res = Impl.build_content(notification, user, object) @@ -245,7 +245,7 @@ test "builds content for chat messages with no content" do {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id) {:ok, chat} = CommonAPI.post_chat_message(user, recipient, nil, media_id: upload.id) - object = Object.normalize(chat, false) + object = Object.normalize(chat, fetch: false) [notification] = Notification.for_user(recipient) res = Impl.build_content(notification, user, object) @@ -271,7 +271,7 @@ test "hides contents of notifications when option enabled" do notif = insert(:notification, user: user2, activity: activity) actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "New Direct Message" @@ -286,7 +286,7 @@ test "hides contents of notifications when option enabled" do notif = insert(:notification, user: user2, activity: activity, type: "mention") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "New Mention" @@ -297,7 +297,7 @@ test "hides contents of notifications when option enabled" do notif = insert(:notification, user: user2, activity: activity, type: "favourite") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "New Favorite" @@ -320,7 +320,7 @@ test "returns regular content when hiding contents option disabled" do notif = insert(:notification, user: user2, activity: activity) actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: @@ -338,7 +338,7 @@ test "returns regular content when hiding contents option disabled" do notif = insert(:notification, user: user2, activity: activity, type: "mention") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: @@ -351,7 +351,7 @@ test "returns regular content when hiding contents option disabled" do notif = insert(:notification, user: user2, activity: activity, type: "favourite") actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) - object = Object.normalize(activity) + object = Object.normalize(activity, fetch: false) assert Impl.build_content(notif, actor, object) == %{ body: "@Bob has favorited your post", diff --git a/test/pleroma/web/rel_me_test.exs b/test/pleroma/web/rel_me_test.exs index 65255916d..811cb0893 100644 --- a/test/pleroma/web/rel_me_test.exs +++ b/test/pleroma/web/rel_me_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.RelMeTest do - use ExUnit.Case + use Pleroma.DataCase setup_all do Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) diff --git a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs index 2f17bebd7..242521138 100644 --- a/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs +++ b/test/pleroma/web/rich_media/parser/ttl/aws_signed_url_test.exs @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrlTest do - use ExUnit.Case, async: true + # Relies on Cachex, needs to be synchronous + use Pleroma.DataCase test "s3 signed url is parsed correct for expiration time" do url = "https://pleroma.social/amz" diff --git a/test/pleroma/web/streamer_test.exs b/test/pleroma/web/streamer_test.exs index ad66ddc9d..764b799bb 100644 --- a/test/pleroma/web/streamer_test.exs +++ b/test/pleroma/web/streamer_test.exs @@ -266,7 +266,7 @@ test "it sends chat messages to the 'user:pleroma_chat' stream", %{ {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno", idempotency_key: "123") - object = Object.normalize(create_activity, false) + object = Object.normalize(create_activity, fetch: false) chat = Chat.get(user.id, other_user.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) cm_ref = %{cm_ref | chat: chat, object: object} @@ -284,7 +284,7 @@ test "it sends chat messages to the 'user' stream", %{user: user, token: oauth_t other_user = insert(:user) {:ok, create_activity} = CommonAPI.post_chat_message(other_user, user, "hey cirno") - object = Object.normalize(create_activity, false) + object = Object.normalize(create_activity, fetch: false) chat = Chat.get(user.id, other_user.ap_id) cm_ref = MessageReference.for_chat_and_object(chat, object) cm_ref = %{cm_ref | chat: chat, object: object} diff --git a/test/pleroma/web/twitter_api/controller_test.exs b/test/pleroma/web/twitter_api/controller_test.exs index 464d0ea2e..b3ca67637 100644 --- a/test/pleroma/web/twitter_api/controller_test.exs +++ b/test/pleroma/web/twitter_api/controller_test.exs @@ -3,11 +3,11 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.TwitterAPI.ControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true - alias Pleroma.Builders.ActivityBuilder alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.OAuth.Token import Pleroma.Factory @@ -36,22 +36,20 @@ test "with credentials, with params" do other_user = insert(:user) {:ok, _activity} = - ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user}) + CommonAPI.post(other_user, %{ + status: "Hey @#{current_user.nickname}" + }) response_conn = conn - |> assign(:user, current_user) |> get("/api/v1/notifications") - [notification] = response = json_response(response_conn, 200) - - assert length(response) == 1 + [notification] = json_response(response_conn, 200) 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) diff --git a/test/pleroma/web/twitter_api/password_controller_test.exs b/test/pleroma/web/twitter_api/password_controller_test.exs index 6d08075cc..c1f5bc5c7 100644 --- a/test/pleroma/web/twitter_api/password_controller_test.exs +++ b/test/pleroma/web/twitter_api/password_controller_test.exs @@ -37,8 +37,7 @@ test "it returns an error when the token has expired", %{conn: conn} do user = insert(:user) {:ok, token} = PasswordResetToken.create_token(user) - - :timer.sleep(2000) + {:ok, token} = time_travel(token, -2) response = conn @@ -55,7 +54,7 @@ test "it fails for an expired token", %{conn: conn} do user = insert(:user) {:ok, token} = PasswordResetToken.create_token(user) - :timer.sleep(2000) + {:ok, token} = time_travel(token, -2) {:ok, _access_token} = Token.create(insert(:oauth_app), user, %{}) params = %{ diff --git a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs index a3e784d13..dfe5b02be 100644 --- a/test/pleroma/web/twitter_api/remote_follow_controller_test.exs +++ b/test/pleroma/web/twitter_api/remote_follow_controller_test.exs @@ -14,18 +14,27 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do import Pleroma.Factory import Ecto.Query - setup do - Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end) - :ok - end - setup_all do: clear_config([:instance, :federating], true) - setup do: clear_config([:instance]) - setup do: clear_config([:frontend_configurations, :pleroma_fe]) setup do: clear_config([:user, :deny_follow_blocked]) describe "GET /ostatus_subscribe - remote_follow/2" do test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do + Tesla.Mock.mock(fn + %{method: :get, url: "https://mastodon.social/users/emelie/statuses/101849165031453009"} -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/activity+json"}], + body: File.read!("test/fixtures/tesla_mock/status.emelie.json") + } + + %{method: :get, url: "https://mastodon.social/users/emelie"} -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/activity+json"}], + body: File.read!("test/fixtures/tesla_mock/emelie.json") + } + end) + assert conn |> get( remote_follow_path(conn, :follow, %{ @@ -36,6 +45,15 @@ test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} end test "show follow account page if the `acct` is a account link", %{conn: conn} do + Tesla.Mock.mock(fn + %{method: :get, url: "https://mastodon.social/users/emelie"} -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/activity+json"}], + body: File.read!("test/fixtures/tesla_mock/emelie.json") + } + end) + response = conn |> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"})) @@ -45,6 +63,15 @@ test "show follow account page if the `acct` is a account link", %{conn: conn} d end test "show follow page if the `acct` is a account link", %{conn: conn} do + Tesla.Mock.mock(fn + %{method: :get, url: "https://mastodon.social/users/emelie"} -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/activity+json"}], + body: File.read!("test/fixtures/tesla_mock/emelie.json") + } + end) + user = insert(:user) response = @@ -56,7 +83,14 @@ test "show follow page if the `acct` is a account link", %{conn: conn} do assert response =~ "Remote follow" end - test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do + test "show follow page with error when user can not be fetched by `acct` link", %{conn: conn} do + Tesla.Mock.mock(fn + %{method: :get, url: "https://mastodon.social/users/not_found"} -> + %Tesla.Env{ + status: 404 + } + end) + user = insert(:user) assert capture_log(fn -> diff --git a/test/pleroma/web/twitter_api/twitter_api_test.exs b/test/pleroma/web/twitter_api/twitter_api_test.exs index 20a45cb6f..5586a9a13 100644 --- a/test/pleroma/web/twitter_api/twitter_api_test.exs +++ b/test/pleroma/web/twitter_api/twitter_api_test.exs @@ -80,13 +80,9 @@ test "it sends confirmation email if :account_activation_required is specified i end test "it sends an admin email if :account_approval_required is specified in instance config" do - admin = insert(:user, is_admin: true) - setting = Pleroma.Config.get([:instance, :account_approval_required]) + clear_config([:instance, :account_approval_required], true) - unless setting do - Pleroma.Config.put([:instance, :account_approval_required], true) - on_exit(fn -> Pleroma.Config.put([:instance, :account_approval_required], setting) end) - end + admin = insert(:user, is_admin: true) data = %{ :username => "lain", @@ -103,15 +99,24 @@ test "it sends an admin email if :account_approval_required is specified in inst assert user.approval_pending - email = Pleroma.Emails.AdminEmail.new_unapproved_registration(admin, user) + user_email = Pleroma.Emails.UserEmail.approval_pending_email(user) + admin_email = Pleroma.Emails.AdminEmail.new_unapproved_registration(admin, user) notify_email = Pleroma.Config.get([:instance, :notify_email]) instance_name = Pleroma.Config.get([:instance, :name]) + # User approval email + Swoosh.TestAssertions.assert_email_sent( + from: {instance_name, notify_email}, + to: {user.name, user.email}, + html_body: user_email.html_body + ) + + # Admin email Swoosh.TestAssertions.assert_email_sent( from: {instance_name, notify_email}, to: {admin.name, admin.email}, - html_body: email.html_body + html_body: admin_email.html_body ) end @@ -423,10 +428,4 @@ test "it returns the error on registration problems" do assert is_binary(error) refute User.get_cached_by_nickname("lain") end - - setup do - Supervisor.terminate_child(Pleroma.Supervisor, Cachex) - Supervisor.restart_child(Pleroma.Supervisor, Cachex) - :ok - end end diff --git a/test/pleroma/web/uploader_controller_test.exs b/test/pleroma/web/uploader_controller_test.exs index 21e518236..00f9e72ec 100644 --- a/test/pleroma/web/uploader_controller_test.exs +++ b/test/pleroma/web/uploader_controller_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.UploaderControllerTest do - use Pleroma.Web.ConnCase + use Pleroma.Web.ConnCase, async: true alias Pleroma.Uploaders.Uploader describe "callback/2" do diff --git a/test/pleroma/web/web_finger/web_finger_controller_test.exs b/test/pleroma/web/web_finger/web_finger_controller_test.exs index 0023f1e81..ce9eb0650 100644 --- a/test/pleroma/web/web_finger/web_finger_controller_test.exs +++ b/test/pleroma/web/web_finger/web_finger_controller_test.exs @@ -30,14 +30,24 @@ test "GET host-meta" do end test "Webfinger JRD" do - user = insert(:user) + user = + insert(:user, + ap_id: "https://hyrule.world/users/zelda", + also_known_as: ["https://mushroom.kingdom/users/toad"] + ) response = build_conn() |> put_req_header("accept", "application/jrd+json") |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost") + |> json_response(200) - assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost" + assert response["subject"] == "acct:#{user.nickname}@localhost" + + assert response["aliases"] == [ + "https://hyrule.world/users/zelda", + "https://mushroom.kingdom/users/toad" + ] end test "it returns 404 when user isn't found (JSON)" do @@ -51,14 +61,20 @@ test "it returns 404 when user isn't found (JSON)" do end test "Webfinger XML" do - user = insert(:user) + user = + insert(:user, + ap_id: "https://hyrule.world/users/zelda", + also_known_as: ["https://mushroom.kingdom/users/toad"] + ) response = build_conn() |> put_req_header("accept", "application/xrd+xml") |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost") + |> response(200) - assert response(response, 200) + assert response =~ "https://hyrule.world/users/zelda" + assert response =~ "https://mushroom.kingdom/users/toad" end test "it returns 404 when user isn't found (XML)" do diff --git a/test/pleroma/web/web_finger_test.exs b/test/pleroma/web/web_finger_test.exs index 96fc0bbaa..cdb84ae1e 100644 --- a/test/pleroma/web/web_finger_test.exs +++ b/test/pleroma/web/web_finger_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.WebFingerTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.Web.WebFinger import Pleroma.Factory import Tesla.Mock @@ -56,12 +56,13 @@ test "returns the ActivityPub actor URI for an ActivityPub user" do {:ok, _data} = WebFinger.finger(user) end - test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do + test "returns the ActivityPub actor URI and subscribe address for an ActivityPub user with the ld+json mimetype" do user = "kaniini@gerzilla.de" {:ok, data} = WebFinger.finger(user) assert data["ap_id"] == "https://gerzilla.de/channel/kaniini" + assert data["subscribe_address"] == "https://gerzilla.de/follow?f=&url={uri}" end test "it work for AP-only user" do diff --git a/test/pleroma/workers/cron/new_users_digest_worker_test.exs b/test/pleroma/workers/cron/new_users_digest_worker_test.exs index 129534cb1..e00ed6745 100644 --- a/test/pleroma/workers/cron/new_users_digest_worker_test.exs +++ b/test/pleroma/workers/cron/new_users_digest_worker_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true import Pleroma.Factory alias Pleroma.Tests.ObanHelpers @@ -28,7 +28,7 @@ test "it sends new users digest emails" do assert email.html_body =~ user.nickname assert email.html_body =~ user2.nickname assert email.html_body =~ "cofe" - assert email.html_body =~ "#{Pleroma.Web.Endpoint.url()}/static/logo.png" + assert email.html_body =~ "#{Pleroma.Web.Endpoint.url()}/static/logo.svg" end test "it doesn't fail when admin has no email" do diff --git a/test/pleroma/workers/scheduled_activity_worker_test.exs b/test/pleroma/workers/scheduled_activity_worker_test.exs index f3eddf7b1..c9e2091a9 100644 --- a/test/pleroma/workers/scheduled_activity_worker_test.exs +++ b/test/pleroma/workers/scheduled_activity_worker_test.exs @@ -36,7 +36,7 @@ test "creates a status from the scheduled activity" do refute Repo.get(ScheduledActivity, scheduled_activity.id) activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id)) - assert Pleroma.Object.normalize(activity).data["content"] == "hi" + assert Pleroma.Object.normalize(activity, fetch: false).data["content"] == "hi" end test "adds log message if ScheduledActivity isn't find" do diff --git a/test/pleroma/xml_builder_test.exs b/test/pleroma/xml_builder_test.exs index 059384c34..a4c73359d 100644 --- a/test/pleroma/xml_builder_test.exs +++ b/test/pleroma/xml_builder_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.XmlBuilderTest do - use Pleroma.DataCase + use Pleroma.DataCase, async: true alias Pleroma.XmlBuilder test "Build a basic xml string from a tuple" do diff --git a/test/support/cachex_proxy.ex b/test/support/cachex_proxy.ex new file mode 100644 index 000000000..e296b5c6a --- /dev/null +++ b/test/support/cachex_proxy.ex @@ -0,0 +1,40 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.CachexProxy do + @behaviour Pleroma.Caching + + @impl true + defdelegate get!(cache, key), to: Cachex + + @impl true + defdelegate stream!(cache, key), to: Cachex + + @impl true + defdelegate put(cache, key, value, options), to: Cachex + + @impl true + defdelegate put(cache, key, value), to: Cachex + + @impl true + defdelegate get_and_update(cache, key, func), to: Cachex + + @impl true + defdelegate get(cache, key), to: Cachex + + @impl true + defdelegate fetch!(cache, key, func), to: Cachex + + @impl true + defdelegate expire_at(cache, str, num), to: Cachex + + @impl true + defdelegate exists?(cache, key), to: Cachex + + @impl true + defdelegate del(cache, key), to: Cachex + + @impl true + defdelegate execute!(cache, func), to: Cachex +end diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex index 114184a9f..f4696adb3 100644 --- a/test/support/channel_case.ex +++ b/test/support/channel_case.ex @@ -33,8 +33,14 @@ defmodule Pleroma.Web.ChannelCase do setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) - unless tags[:async] do + if tags[:async] do + Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache) + Mox.set_mox_private() + else Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) + Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) + Mox.set_mox_global() + Pleroma.DataCase.clear_cachex() end :ok diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 47cb65a80..f20e3d955 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -116,12 +116,16 @@ defp json_response_and_validate_schema(conn, _status) do end setup tags do - Cachex.clear(:user_cache) - Cachex.clear(:object_cache) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) - unless tags[:async] do + if tags[:async] do + Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache) + Mox.set_mox_private() + else Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) + Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) + Mox.set_mox_global() + Pleroma.DataCase.clear_cachex() end if tags[:needs_streamer] do @@ -132,6 +136,10 @@ defp json_response_and_validate_schema(conn, _status) do }) end + Pleroma.DataCase.stub_pipeline() + + Mox.verify_on_exit!() + {:ok, conn: Phoenix.ConnTest.build_conn()} end end diff --git a/test/support/data_case.ex b/test/support/data_case.ex index d5456521c..0b41f0f63 100644 --- a/test/support/data_case.ex +++ b/test/support/data_case.ex @@ -45,13 +45,34 @@ defp oauth_access(scopes, opts \\ []) do end end + def clear_cachex do + Pleroma.Supervisor + |> Supervisor.which_children() + |> Enum.each(fn + {name, _, _, [Cachex]} -> + name + |> to_string + |> String.trim_leading("cachex_") + |> Kernel.<>("_cache") + |> String.to_existing_atom() + |> Cachex.clear() + + _ -> + nil + end) + end + setup tags do - Cachex.clear(:user_cache) - Cachex.clear(:object_cache) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Pleroma.Repo) - unless tags[:async] do + if tags[:async] do + Mox.stub_with(Pleroma.CachexMock, Pleroma.NullCache) + Mox.set_mox_private() + else Ecto.Adapters.SQL.Sandbox.mode(Pleroma.Repo, {:shared, self()}) + Mox.stub_with(Pleroma.CachexMock, Pleroma.CachexProxy) + Mox.set_mox_global() + clear_cachex() end if tags[:needs_streamer] do @@ -62,9 +83,27 @@ defp oauth_access(scopes, opts \\ []) do }) end + stub_pipeline() + + Mox.verify_on_exit!() + :ok end + def stub_pipeline do + Mox.stub_with(Pleroma.Web.ActivityPub.SideEffectsMock, Pleroma.Web.ActivityPub.SideEffects) + + Mox.stub_with( + Pleroma.Web.ActivityPub.ObjectValidatorMock, + Pleroma.Web.ActivityPub.ObjectValidator + ) + + Mox.stub_with(Pleroma.Web.ActivityPub.MRFMock, Pleroma.Web.ActivityPub.MRF) + Mox.stub_with(Pleroma.Web.ActivityPub.ActivityPubMock, Pleroma.Web.ActivityPub.ActivityPub) + Mox.stub_with(Pleroma.Web.FederatorMock, Pleroma.Web.Federator) + Mox.stub_with(Pleroma.ConfigMock, Pleroma.Config) + end + def ensure_local_uploader(context) do test_uploader = Map.get(context, :uploader, Pleroma.Uploaders.Local) uploader = Pleroma.Config.get([Pleroma.Upload, :uploader]) diff --git a/test/support/factory.ex b/test/support/factory.ex index bbb04837a..786d12c4b 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -291,7 +291,7 @@ def announce_activity_factory(attrs \\ %{}) do def like_activity_factory(attrs \\ %{}) do note_activity = attrs[:note_activity] || insert(:note_activity) - object = Object.normalize(note_activity) + object = Object.normalize(note_activity, fetch: false) user = insert(:user) data = diff --git a/test/support/helpers.ex b/test/support/helpers.ex index 224034521..15e8cbd9d 100644 --- a/test/support/helpers.ex +++ b/test/support/helpers.ex @@ -55,6 +55,14 @@ defmacro __using__(_opts) do clear_config: 2 ] + def time_travel(entity, seconds) do + new_time = NaiveDateTime.add(entity.inserted_at, seconds) + + entity + |> Ecto.Changeset.change(%{inserted_at: new_time, updated_at: new_time}) + |> Pleroma.Repo.update() + end + def to_datetime(%NaiveDateTime{} = naive_datetime) do naive_datetime |> DateTime.from_naive!("Etc/UTC") diff --git a/test/support/mocks.ex b/test/support/mocks.ex new file mode 100644 index 000000000..442ff5b71 --- /dev/null +++ b/test/support/mocks.ex @@ -0,0 +1,30 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +Mox.defmock(Pleroma.CachexMock, for: Pleroma.Caching) + +Mox.defmock(Pleroma.Web.ActivityPub.ObjectValidatorMock, + for: Pleroma.Web.ActivityPub.ObjectValidator.Validating +) + +Mox.defmock(Pleroma.Web.ActivityPub.MRFMock, + for: Pleroma.Web.ActivityPub.MRF.PipelineFiltering +) + +Mox.defmock(Pleroma.Web.ActivityPub.ActivityPubMock, + for: [ + Pleroma.Web.ActivityPub.ActivityPub.Persisting, + Pleroma.Web.ActivityPub.ActivityPub.Streaming + ] +) + +Mox.defmock(Pleroma.Web.ActivityPub.SideEffectsMock, + for: Pleroma.Web.ActivityPub.SideEffects.Handling +) + +Mox.defmock(Pleroma.Web.FederatorMock, for: Pleroma.Web.Federator.Publishing) + +Mox.defmock(Pleroma.ConfigMock, for: Pleroma.Config.Getting) + +Mox.defmock(Pleroma.LoggerMock, for: Pleroma.Logging) diff --git a/test/support/null_cache.ex b/test/support/null_cache.ex new file mode 100644 index 000000000..c63df6a39 --- /dev/null +++ b/test/support/null_cache.ex @@ -0,0 +1,49 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.NullCache do + @moduledoc """ + A module simulating a permanently empty cache. + """ + @behaviour Pleroma.Caching + + @impl true + def get!(_, _), do: nil + + @impl true + def put(_, _, _, _ \\ nil), do: {:ok, true} + + @impl true + def stream!(_, _), do: [] + + @impl true + def get(_, _), do: {:ok, nil} + + @impl true + def fetch!(_, key, func) do + case func.(key) do + {_, res} -> res + res -> res + end + end + + @impl true + def get_and_update(_, _, func) do + func.(nil) + end + + @impl true + def expire_at(_, _, _), do: {:ok, true} + + @impl true + def exists?(_, _), do: {:ok, false} + + @impl true + def execute!(_, func) do + func.(:nothing) + end + + @impl true + def del(_, _), do: {:ok, true} +end