summaryrefslogtreecommitdiff
path: root/test/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'test/tasks')
-rw-r--r--test/tasks/app_test.exs65
-rw-r--r--test/tasks/config_test.exs56
-rw-r--r--test/tasks/count_statuses_test.exs6
-rw-r--r--test/tasks/database_test.exs47
-rw-r--r--test/tasks/digest_test.exs4
-rw-r--r--test/tasks/email_test.exs2
-rw-r--r--test/tasks/emoji_test.exs239
-rw-r--r--test/tasks/frontend_test.exs78
-rw-r--r--test/tasks/instance_test.exs3
-rw-r--r--test/tasks/refresh_counter_cache_test.exs16
-rw-r--r--test/tasks/relay_test.exs26
-rw-r--r--test/tasks/robots_txt_test.exs2
-rw-r--r--test/tasks/user_test.exs123
13 files changed, 582 insertions, 85 deletions
diff --git a/test/tasks/app_test.exs b/test/tasks/app_test.exs
new file mode 100644
index 000000000..71a84ac8e
--- /dev/null
+++ b/test/tasks/app_test.exs
@@ -0,0 +1,65 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Mix.Tasks.Pleroma.AppTest do
+ use Pleroma.DataCase, async: true
+
+ setup_all do
+ Mix.shell(Mix.Shell.Process)
+
+ on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
+ end)
+ end
+
+ describe "creates new app" do
+ test "with default scopes" do
+ name = "Some name"
+ redirect = "https://example.com"
+ Mix.Tasks.Pleroma.App.run(["create", "-n", name, "-r", redirect])
+
+ assert_app(name, redirect, ["read", "write", "follow", "push"])
+ end
+
+ test "with custom scopes" do
+ name = "Another name"
+ redirect = "https://example.com"
+
+ Mix.Tasks.Pleroma.App.run([
+ "create",
+ "-n",
+ name,
+ "-r",
+ redirect,
+ "-s",
+ "read,write,follow,push,admin"
+ ])
+
+ assert_app(name, redirect, ["read", "write", "follow", "push", "admin"])
+ end
+ end
+
+ test "with errors" do
+ Mix.Tasks.Pleroma.App.run(["create"])
+ {:mix_shell, :error, ["Creating failed:"]}
+ {:mix_shell, :error, ["name: can't be blank"]}
+ {:mix_shell, :error, ["redirect_uris: can't be blank"]}
+ end
+
+ defp assert_app(name, redirect, scopes) do
+ app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
+
+ assert_receive {:mix_shell, :info, [message]}
+ assert message == "#{name} successfully created:"
+
+ assert_receive {:mix_shell, :info, [message]}
+ assert message == "App client_id: #{app.client_id}"
+
+ assert_receive {:mix_shell, :info, [message]}
+ assert message == "App client_secret: #{app.client_secret}"
+
+ assert app.scopes == scopes
+ assert app.redirect_uris == redirect
+ end
+end
diff --git a/test/tasks/config_test.exs b/test/tasks/config_test.exs
index a6c0de351..fb12e7fb3 100644
--- a/test/tasks/config_test.exs
+++ b/test/tasks/config_test.exs
@@ -5,6 +5,8 @@
defmodule Mix.Tasks.Pleroma.ConfigTest do
use Pleroma.DataCase
+ import Pleroma.Factory
+
alias Pleroma.ConfigDB
alias Pleroma.Repo
@@ -20,9 +22,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
:ok
end
- clear_config_all(:configurable_from_database) do
- Pleroma.Config.put(:configurable_from_database, true)
- end
+ setup_all do: clear_config(:configurable_from_database, true)
test "error if file with custom settings doesn't exist" do
Mix.Tasks.Pleroma.Config.migrate_to_db("config/not_existance_config_file.exs")
@@ -40,7 +40,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
end
- test "settings are migrated to db" do
+ test "filtered settings are migrated to db" do
assert Repo.all(ConfigDB) == []
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
@@ -49,25 +49,22 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
+ refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"})
+ refute ConfigDB.get_by_params(%{group: ":pleroma", key: ":database"})
- assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
- assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
- assert ConfigDB.from_binary(config3.value) == :info
+ assert config1.value == [key: "value", key2: [Repo]]
+ assert config2.value == [key: "value2", key2: ["Activity"]]
+ assert config3.value == :info
end
test "config table is truncated before migration" do
- ConfigDB.create(%{
- group: ":pleroma",
- key: ":first_setting",
- value: [key: "value", key2: ["Activity"]]
- })
-
+ insert(:config, key: :first_setting, value: [key: "value", key2: ["Activity"]])
assert Repo.aggregate(ConfigDB, :count, :id) == 1
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
config = ConfigDB.get_by_params(%{group: ":pleroma", key: ":first_setting"})
- assert ConfigDB.from_binary(config.value) == [key: "value", key2: [Repo]]
+ assert config.value == [key: "value", key2: [Repo]]
end
end
@@ -83,19 +80,9 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
- ConfigDB.create(%{
- group: ":pleroma",
- key: ":setting_first",
- value: [key: "value", key2: ["Activity"]]
- })
-
- ConfigDB.create(%{
- group: ":pleroma",
- key: ":setting_second",
- value: [key: "value2", key2: [Repo]]
- })
-
- ConfigDB.create(%{group: ":quack", key: ":level", value: :info})
+ insert(:config, key: :setting_first, value: [key: "value", key2: ["Activity"]])
+ insert(:config, key: :setting_second, value: [key: "value2", key2: [Repo]])
+ insert(:config, group: :quack, key: :level, value: :info)
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
@@ -108,9 +95,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
test "load a settings with large values and pass to file", %{temp_file: temp_file} do
- ConfigDB.create(%{
- group: ":pleroma",
- key: ":instance",
+ insert(:config,
+ key: :instance,
value: [
name: "Pleroma",
email: "example@example.com",
@@ -135,19 +121,14 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
federation_reachability_timeout_days: 7,
federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],
allow_relay: true,
- rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,
public: true,
quarantined_instances: [],
managed_config: true,
static_dir: "instance/static/",
allowed_post_formats: ["text/plain", "text/html", "text/markdown", "text/bbcode"],
- mrf_transparency: true,
- mrf_transparency_exclusions: [],
autofollowed_nicknames: [],
max_pinned_statuses: 1,
attachment_links: false,
- welcome_user_nickname: nil,
- welcome_message: nil,
max_report_comment_size: 1000,
safe_dm_mentions: false,
healthcheck: false,
@@ -164,7 +145,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
extended_nickname_format: true,
multi_factor_authentication: [
totp: [
- # digits 6 or 8
digits: 6,
period: 30
],
@@ -174,7 +154,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
]
]
]
- })
+ )
Mix.Tasks.Pleroma.Config.run(["migrate_from_db", "--env", "temp", "-d"])
@@ -190,7 +170,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
end
assert file ==
- "#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n rewrite_policy: Pleroma.Web.ActivityPub.MRF.NoOpPolicy,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n mrf_transparency: true,\n mrf_transparency_exclusions: [],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
+ "#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
end
end
end
diff --git a/test/tasks/count_statuses_test.exs b/test/tasks/count_statuses_test.exs
index 73c2ea690..c5cd16960 100644
--- a/test/tasks/count_statuses_test.exs
+++ b/test/tasks/count_statuses_test.exs
@@ -13,11 +13,11 @@ defmodule Mix.Tasks.Pleroma.CountStatusesTest do
test "counts statuses" do
user = insert(:user)
- {:ok, _} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, _} = CommonAPI.post(user, %{"status" => "test2"})
+ {:ok, _} = CommonAPI.post(user, %{status: "test"})
+ {:ok, _} = CommonAPI.post(user, %{status: "test2"})
user2 = insert(:user)
- {:ok, _} = CommonAPI.post(user2, %{"status" => "test3"})
+ {:ok, _} = CommonAPI.post(user2, %{status: "test3"})
user = refresh_record(user)
user2 = refresh_record(user2)
diff --git a/test/tasks/database_test.exs b/test/tasks/database_test.exs
index ed1c31d9c..3a28aa133 100644
--- a/test/tasks/database_test.exs
+++ b/test/tasks/database_test.exs
@@ -26,7 +26,7 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
describe "running remove_embedded_objects" do
test "it replaces objects with references" do
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
+ {:ok, activity} = CommonAPI.post(user, %{status: "test"})
new_data = Map.put(activity.data, "object", activity.object.data)
{:ok, activity} =
@@ -99,10 +99,10 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
test "it turns OrderedCollection likes into empty arrays" do
[user, user2] = insert_pair(:user)
- {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{"status" => "test"})
- {:ok, %{object: object2}} = CommonAPI.post(user, %{"status" => "test test"})
+ {:ok, %{id: id, object: object}} = CommonAPI.post(user, %{status: "test"})
+ {:ok, %{object: object2}} = CommonAPI.post(user, %{status: "test test"})
- CommonAPI.favorite(id, user2)
+ CommonAPI.favorite(user2, id)
likes = %{
"first" =>
@@ -127,4 +127,43 @@ defmodule Mix.Tasks.Pleroma.DatabaseTest do
assert Enum.empty?(Object.get_by_id(object2.id).data["likes"])
end
end
+
+ describe "ensure_expiration" do
+ test "it adds to expiration old statuses" do
+ %{id: activity_id1} = insert(:note_activity)
+
+ %{id: activity_id2} =
+ insert(:note_activity, %{inserted_at: NaiveDateTime.from_iso8601!("2015-01-23 23:50:07")})
+
+ %{id: activity_id3} = activity3 = insert(:note_activity)
+
+ expires_at =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(60 * 61, :second)
+ |> NaiveDateTime.truncate(:second)
+
+ Pleroma.ActivityExpiration.create(activity3, expires_at)
+
+ Mix.Tasks.Pleroma.Database.run(["ensure_expiration"])
+
+ expirations =
+ Pleroma.ActivityExpiration
+ |> order_by(:activity_id)
+ |> Repo.all()
+
+ assert [
+ %Pleroma.ActivityExpiration{
+ activity_id: ^activity_id1
+ },
+ %Pleroma.ActivityExpiration{
+ activity_id: ^activity_id2,
+ scheduled_at: ~N[2016-01-23 23:50:07]
+ },
+ %Pleroma.ActivityExpiration{
+ activity_id: ^activity_id3,
+ scheduled_at: ^expires_at
+ }
+ ] = expirations
+ end
+ end
end
diff --git a/test/tasks/digest_test.exs b/test/tasks/digest_test.exs
index 96d762685..0b444c86d 100644
--- a/test/tasks/digest_test.exs
+++ b/test/tasks/digest_test.exs
@@ -17,6 +17,8 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
:ok
end
+ setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
+
describe "pleroma.digest test" do
test "Sends digest to the given user" do
user1 = insert(:user)
@@ -25,7 +27,7 @@ defmodule Mix.Tasks.Pleroma.DigestTest do
Enum.each(0..10, fn i ->
{:ok, _activity} =
CommonAPI.post(user1, %{
- "status" => "hey ##{i} @#{user2.nickname}!"
+ status: "hey ##{i} @#{user2.nickname}!"
})
end)
diff --git a/test/tasks/email_test.exs b/test/tasks/email_test.exs
index 944c07064..c3af7ef68 100644
--- a/test/tasks/email_test.exs
+++ b/test/tasks/email_test.exs
@@ -16,6 +16,8 @@ defmodule Mix.Tasks.Pleroma.EmailTest do
:ok
end
+ setup do: clear_config([Pleroma.Emails.Mailer, :enabled], true)
+
describe "pleroma.email test" do
test "Sends test email with no given address" do
mail_to = Config.get([:instance, :email])
diff --git a/test/tasks/emoji_test.exs b/test/tasks/emoji_test.exs
new file mode 100644
index 000000000..499f098c2
--- /dev/null
+++ b/test/tasks/emoji_test.exs
@@ -0,0 +1,239 @@
+defmodule Mix.Tasks.Pleroma.EmojiTest do
+ use ExUnit.Case, async: true
+
+ import ExUnit.CaptureIO
+ import Tesla.Mock
+
+ alias Mix.Tasks.Pleroma.Emoji
+
+ describe "ls-packs" do
+ test "with default manifest as url" do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
+ }
+ end)
+
+ capture_io(fn -> Emoji.run(["ls-packs"]) end) =~
+ "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
+ end
+
+ test "with passed manifest as file" do
+ capture_io(fn ->
+ Emoji.run(["ls-packs", "-m", "test/fixtures/emoji/packs/manifest.json"])
+ end) =~ "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
+ end
+ end
+
+ describe "get-packs" do
+ test "download pack from default manifest" do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
+ }
+
+ %{
+ method: :get,
+ url: "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
+ }
+
+ %{
+ method: :get,
+ url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/finmoji.json"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/emoji/packs/finmoji.json")
+ }
+ end)
+
+ assert capture_io(fn -> Emoji.run(["get-packs", "finmoji"]) end) =~ "Writing pack.json for"
+
+ emoji_path =
+ Path.join(
+ Pleroma.Config.get!([:instance, :static_dir]),
+ "emoji"
+ )
+
+ assert File.exists?(Path.join([emoji_path, "finmoji", "pack.json"]))
+ on_exit(fn -> File.rm_rf!("test/instance_static/emoji/finmoji") end)
+ end
+
+ test "install local emoji pack" do
+ assert capture_io(fn ->
+ Emoji.run([
+ "get-packs",
+ "local",
+ "--manifest",
+ "test/instance_static/local_pack/manifest.json"
+ ])
+ end) =~ "Writing pack.json for"
+
+ on_exit(fn -> File.rm_rf!("test/instance_static/emoji/local") end)
+ end
+
+ test "pack not found" do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/index.json"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/emoji/packs/default-manifest.json")
+ }
+ end)
+
+ assert capture_io(fn -> Emoji.run(["get-packs", "not_found"]) end) =~
+ "No pack named \"not_found\" found"
+ end
+
+ test "raise on bad sha256" do
+ mock(fn
+ %{
+ method: :get,
+ url: "https://git.pleroma.social/pleroma/emoji-index/raw/master/packs/blobs_gg.zip"
+ } ->
+ %Tesla.Env{
+ status: 200,
+ body: File.read!("test/fixtures/emoji/packs/blank.png.zip")
+ }
+ end)
+
+ assert_raise RuntimeError, ~r/^Bad SHA256 for blobs.gg/, fn ->
+ capture_io(fn ->
+ Emoji.run(["get-packs", "blobs.gg", "-m", "test/fixtures/emoji/packs/manifest.json"])
+ end)
+ end
+ end
+ end
+
+ describe "gen-pack" do
+ setup do
+ url = "https://finland.fi/wp-content/uploads/2017/06/finland-emojis.zip"
+
+ mock(fn %{
+ method: :get,
+ url: ^url
+ } ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/emoji/packs/blank.png.zip")}
+ end)
+
+ {:ok, url: url}
+ end
+
+ test "with default extensions", %{url: url} do
+ name = "pack1"
+ pack_json = "#{name}.json"
+ files_json = "#{name}_file.json"
+ refute File.exists?(pack_json)
+ refute File.exists?(files_json)
+
+ captured =
+ capture_io(fn ->
+ Emoji.run([
+ "gen-pack",
+ url,
+ "--name",
+ name,
+ "--license",
+ "license",
+ "--homepage",
+ "homepage",
+ "--description",
+ "description",
+ "--files",
+ files_json,
+ "--extensions",
+ ".png .gif"
+ ])
+ end)
+
+ assert captured =~ "#{pack_json} has been created with the pack1 pack"
+ assert captured =~ "Using .png .gif extensions"
+
+ assert File.exists?(pack_json)
+ assert File.exists?(files_json)
+
+ on_exit(fn ->
+ File.rm!(pack_json)
+ File.rm!(files_json)
+ end)
+ end
+
+ test "with custom extensions and update existing files", %{url: url} do
+ name = "pack2"
+ pack_json = "#{name}.json"
+ files_json = "#{name}_file.json"
+ refute File.exists?(pack_json)
+ refute File.exists?(files_json)
+
+ captured =
+ capture_io(fn ->
+ Emoji.run([
+ "gen-pack",
+ url,
+ "--name",
+ name,
+ "--license",
+ "license",
+ "--homepage",
+ "homepage",
+ "--description",
+ "description",
+ "--files",
+ files_json,
+ "--extensions",
+ " .png .gif .jpeg "
+ ])
+ end)
+
+ assert captured =~ "#{pack_json} has been created with the pack2 pack"
+ assert captured =~ "Using .png .gif .jpeg extensions"
+
+ assert File.exists?(pack_json)
+ assert File.exists?(files_json)
+
+ captured =
+ capture_io(fn ->
+ Emoji.run([
+ "gen-pack",
+ url,
+ "--name",
+ name,
+ "--license",
+ "license",
+ "--homepage",
+ "homepage",
+ "--description",
+ "description",
+ "--files",
+ files_json,
+ "--extensions",
+ " .png .gif .jpeg "
+ ])
+ end)
+
+ assert captured =~ "#{pack_json} has been updated with the pack2 pack"
+
+ on_exit(fn ->
+ File.rm!(pack_json)
+ File.rm!(files_json)
+ end)
+ end
+ end
+end
diff --git a/test/tasks/frontend_test.exs b/test/tasks/frontend_test.exs
new file mode 100644
index 000000000..0ca2b9a28
--- /dev/null
+++ b/test/tasks/frontend_test.exs
@@ -0,0 +1,78 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.FrontendTest do
+ use Pleroma.DataCase
+ alias Mix.Tasks.Pleroma.Frontend
+
+ import ExUnit.CaptureIO, only: [capture_io: 1]
+
+ @dir "test/frontend_static_test"
+
+ setup do
+ File.mkdir_p!(@dir)
+ clear_config([:instance, :static_dir], @dir)
+
+ on_exit(fn ->
+ File.rm_rf(@dir)
+ end)
+ end
+
+ test "it downloads and unzips a known frontend" do
+ clear_config([:frontends, :available], %{
+ "pleroma" => %{
+ "ref" => "fantasy",
+ "name" => "pleroma",
+ "build_url" => "http://gensokyo.2hu/builds/${ref}"
+ }
+ })
+
+ Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/builds/fantasy"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend_dist.zip")}
+ end)
+
+ capture_io(fn ->
+ Frontend.run(["install", "pleroma"])
+ end)
+
+ assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
+ end
+
+ test "it also works given a file" do
+ clear_config([:frontends, :available], %{
+ "pleroma" => %{
+ "ref" => "fantasy",
+ "name" => "pleroma",
+ "build_dir" => ""
+ }
+ })
+
+ capture_io(fn ->
+ Frontend.run(["install", "pleroma", "--file", "test/fixtures/tesla_mock/frontend.zip"])
+ end)
+
+ assert File.exists?(Path.join([@dir, "frontends", "pleroma", "fantasy", "test.txt"]))
+ end
+
+ test "it downloads and unzips unknown frontends" do
+ Tesla.Mock.mock(fn %{url: "http://gensokyo.2hu/madeup.zip"} ->
+ %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/frontend.zip")}
+ end)
+
+ capture_io(fn ->
+ Frontend.run([
+ "install",
+ "unknown",
+ "--ref",
+ "baka",
+ "--build-url",
+ "http://gensokyo.2hu/madeup.zip",
+ "--build-dir",
+ ""
+ ])
+ end)
+
+ assert File.exists?(Path.join([@dir, "frontends", "unknown", "baka", "test.txt"]))
+ end
+end
diff --git a/test/tasks/instance_test.exs b/test/tasks/instance_test.exs
index f6a4ba508..3b4c041d9 100644
--- a/test/tasks/instance_test.exs
+++ b/test/tasks/instance_test.exs
@@ -63,7 +63,7 @@ defmodule Pleroma.InstanceTest do
"--uploads-dir",
"test/uploads",
"--static-dir",
- "instance/static/"
+ "./test/../test/instance/static/"
])
end
@@ -83,6 +83,7 @@ defmodule Pleroma.InstanceTest do
assert generated_config =~ "configurable_from_database: true"
assert generated_config =~ "http: [ip: {127, 0, 0, 1}, port: 4000]"
assert File.read!(tmp_path() <> "setup.psql") == generated_setup_psql()
+ assert File.exists?(Path.expand("./test/instance/static/robots.txt"))
end
defp generated_setup_psql do
diff --git a/test/tasks/refresh_counter_cache_test.exs b/test/tasks/refresh_counter_cache_test.exs
index b63f44c08..6a1a9ac17 100644
--- a/test/tasks/refresh_counter_cache_test.exs
+++ b/test/tasks/refresh_counter_cache_test.exs
@@ -12,32 +12,32 @@ defmodule Mix.Tasks.Pleroma.RefreshCounterCacheTest do
user = insert(:user)
other_user = insert(:user)
- CommonAPI.post(user, %{"visibility" => "public", "status" => "hey"})
+ CommonAPI.post(user, %{visibility: "public", status: "hey"})
Enum.each(0..1, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "unlisted",
- "status" => "hey"
+ visibility: "unlisted",
+ status: "hey"
})
end)
Enum.each(0..2, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "direct",
- "status" => "hey @#{other_user.nickname}"
+ visibility: "direct",
+ status: "hey @#{other_user.nickname}"
})
end)
Enum.each(0..3, fn _ ->
CommonAPI.post(user, %{
- "visibility" => "private",
- "status" => "hey"
+ visibility: "private",
+ status: "hey"
})
end)
assert capture_io(fn -> Mix.Tasks.Pleroma.RefreshCounterCache.run([]) end) =~ "Done\n"
- assert %{direct: 3, private: 4, public: 1, unlisted: 2} =
+ assert %{"direct" => 3, "private" => 4, "public" => 1, "unlisted" => 2} =
Pleroma.Stats.get_status_visibility_count()
end
end
diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs
index d3d88467d..e5225b64c 100644
--- a/test/tasks/relay_test.exs
+++ b/test/tasks/relay_test.exs
@@ -10,6 +10,8 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
alias Pleroma.Web.ActivityPub.Utils
use Pleroma.DataCase
+ import Pleroma.Factory
+
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
@@ -40,13 +42,18 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
assert activity.data["object"] == target_user.ap_id
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
- assert_receive {:mix_shell, :info, ["mastodon.example.org (no Accept received)"]}
+
+ assert_receive {:mix_shell, :info,
+ [
+ "http://mastodon.example.org/users/admin - no Accept received (relay didn't follow back)"
+ ]}
end
end
describe "running unfollow" do
test "relay is unfollowed" do
- target_instance = "http://mastodon.example.org/users/admin"
+ user = insert(:user)
+ target_instance = user.ap_id
Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
@@ -62,15 +69,16 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
[undo_activity] =
ActivityPub.fetch_activities([], %{
- "type" => "Undo",
- "actor_id" => follower_id,
- "limit" => 1,
- "skip_preload" => true
+ type: "Undo",
+ actor_id: follower_id,
+ limit: 1,
+ skip_preload: true,
+ invisible_actors: true
})
assert undo_activity.data["type"] == "Undo"
assert undo_activity.data["actor"] == local_user.ap_id
- assert undo_activity.data["object"] == cancelled_activity.data
+ assert undo_activity.data["object"]["id"] == cancelled_activity.data["id"]
refute "#{target_instance}/followers" in User.following(local_user)
end
end
@@ -91,8 +99,8 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
:ok = Mix.Tasks.Pleroma.Relay.run(["list"])
- assert_receive {:mix_shell, :info, ["mstdn.io"]}
- assert_receive {:mix_shell, :info, ["mastodon.example.org"]}
+ assert_receive {:mix_shell, :info, ["https://mstdn.io/users/mayuutann"]}
+ assert_receive {:mix_shell, :info, ["http://mastodon.example.org/users/admin"]}
end
end
end
diff --git a/test/tasks/robots_txt_test.exs b/test/tasks/robots_txt_test.exs
index e03c9c192..7040a0e4e 100644
--- a/test/tasks/robots_txt_test.exs
+++ b/test/tasks/robots_txt_test.exs
@@ -7,7 +7,7 @@ defmodule Mix.Tasks.Pleroma.RobotsTxtTest do
use Pleroma.Tests.Helpers
alias Mix.Tasks.Pleroma.RobotsTxt
- clear_config([:instance, :static_dir])
+ setup do: clear_config([:instance, :static_dir])
test "creates new dir" do
path = "test/fixtures/new_dir/"
diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs
index 0f6ffb2b1..ce43a9cc7 100644
--- a/test/tasks/user_test.exs
+++ b/test/tasks/user_test.exs
@@ -3,15 +3,22 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.UserTest do
+ alias Pleroma.Activity
+ alias Pleroma.MFA
+ alias Pleroma.Object
alias Pleroma.Repo
+ alias Pleroma.Tests.ObanHelpers
alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OAuth.Authorization
alias Pleroma.Web.OAuth.Token
use Pleroma.DataCase
+ use Oban.Testing, repo: Pleroma.Repo
- import Pleroma.Factory
import ExUnit.CaptureIO
+ import Mock
+ import Pleroma.Factory
setup_all do
Mix.shell(Mix.Shell.Process)
@@ -85,14 +92,61 @@ defmodule Mix.Tasks.Pleroma.UserTest do
describe "running rm" do
test "user is deleted" do
+ clear_config([:instance, :federating], true)
user = insert(:user)
- Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
+ ObanHelpers.perform_all()
- assert_received {:mix_shell, :info, [message]}
- assert message =~ " deleted"
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " deleted"
+ assert %{deactivated: true} = User.get_by_nickname(user.nickname)
- assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+ assert called(Pleroma.Web.Federator.publish(:_))
+ end
+ end
+
+ test "a remote user's create activity is deleted when the object has been pruned" do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, post} = CommonAPI.post(user, %{status: "uguu"})
+ {:ok, post2} = CommonAPI.post(user2, %{status: "test"})
+ obj = Object.normalize(post2)
+
+ {:ok, like_object, meta} = Pleroma.Web.ActivityPub.Builder.like(user, obj)
+
+ {:ok, like_activity, _meta} =
+ Pleroma.Web.ActivityPub.Pipeline.common_pipeline(
+ like_object,
+ Keyword.put(meta, :local, true)
+ )
+
+ like_activity.data["object"]
+ |> Pleroma.Object.get_by_ap_id()
+ |> Repo.delete()
+
+ clear_config([:instance, :federating], true)
+
+ object = Object.normalize(post)
+ Object.prune(object)
+
+ with_mock Pleroma.Web.Federator,
+ publish: fn _ -> nil end do
+ Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
+ ObanHelpers.perform_all()
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message =~ " deleted"
+ assert %{deactivated: true} = User.get_by_nickname(user.nickname)
+
+ assert called(Pleroma.Web.Federator.publish(:_))
+ refute Pleroma.Repo.get(Pleroma.Activity, like_activity.id)
+ end
+
+ refute Activity.get_by_id(post.id)
end
test "no user to delete" do
@@ -136,31 +190,31 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
- describe "running unsubscribe" do
+ describe "running deactivate" do
test "user is unsubscribed" do
followed = insert(:user)
+ remote_followed = insert(:user, local: false)
user = insert(:user)
+
User.follow(user, followed, :follow_accept)
+ User.follow(user, remote_followed, :follow_accept)
- Mix.Tasks.Pleroma.User.run(["unsubscribe", user.nickname])
+ Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
assert_received {:mix_shell, :info, [message]}
assert message =~ "Deactivating"
- assert_received {:mix_shell, :info, [message]}
- assert message =~ "Unsubscribing"
-
# Note that the task has delay :timer.sleep(500)
assert_received {:mix_shell, :info, [message]}
assert message =~ "Successfully unsubscribed"
user = User.get_cached_by_nickname(user.nickname)
- assert Enum.empty?(User.get_friends(user))
+ assert Enum.empty?(Enum.filter(User.get_friends(user), & &1.local))
assert user.deactivated
end
- test "no user to unsubscribe" do
- Mix.Tasks.Pleroma.User.run(["unsubscribe", "nonexistent"])
+ test "no user to deactivate" do
+ Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
assert_received {:mix_shell, :error, [message]}
assert message =~ "No user"
@@ -242,6 +296,35 @@ defmodule Mix.Tasks.Pleroma.UserTest do
end
end
+ describe "running reset_mfa" do
+ test "disables MFA" do
+ user =
+ insert(:user,
+ multi_factor_authentication_settings: %MFA.Settings{
+ enabled: true,
+ totp: %MFA.Settings.TOTP{secret: "xx", confirmed: true}
+ }
+ )
+
+ Mix.Tasks.Pleroma.User.run(["reset_mfa", user.nickname])
+
+ assert_received {:mix_shell, :info, [message]}
+ assert message == "Multi-Factor Authentication disabled for #{user.nickname}"
+
+ assert %{enabled: false, totp: false} ==
+ user.nickname
+ |> User.get_cached_by_nickname()
+ |> MFA.mfa_settings()
+ end
+
+ test "no user to reset MFA" do
+ Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
+
+ assert_received {:mix_shell, :error, [message]}
+ assert message =~ "No local user"
+ end
+ end
+
describe "running invite" do
test "invite token is generated" do
assert capture_io(fn ->
@@ -398,17 +481,17 @@ defmodule Mix.Tasks.Pleroma.UserTest do
moot = insert(:user, nickname: "moot")
kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
- {:ok, user} = User.follow(user, kawen)
+ {:ok, user} = User.follow(user, moon)
assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
+
res = User.search("moo") |> Enum.map(& &1.id)
- assert moon.id in res
- assert moot.id in res
- assert kawen.id in res
- assert [moon.id, kawen.id] == User.Search.search("moon fediverse") |> Enum.map(& &1.id)
+ assert Enum.sort([moon.id, moot.id, kawen.id]) == Enum.sort(res)
+
+ assert [kawen.id, moon.id] == User.Search.search("expert fediverse") |> Enum.map(& &1.id)
- assert [kawen.id, moon.id] ==
- User.Search.search("moon fediverse", for_user: user) |> Enum.map(& &1.id)
+ assert [moon.id, kawen.id] ==
+ User.Search.search("expert fediverse", for_user: user) |> Enum.map(& &1.id)
end
end