summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/user_test.exs80
-rw-r--r--test/web/activity_pub/transmogrifier/audio_handling_test.exs45
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs29
-rw-r--r--test/web/admin_api/controllers/admin_api_controller_test.exs29
-rw-r--r--test/web/admin_api/controllers/media_proxy_cache_controller_test.exs72
-rw-r--r--test/web/mastodon_api/controllers/timeline_controller_test.exs17
-rw-r--r--test/web/preload/timeline_test.exs28
-rw-r--r--test/web/twitter_api/util_controller_test.exs10
8 files changed, 228 insertions, 82 deletions
diff --git a/test/user_test.exs b/test/user_test.exs
index b47405895..3cf248659 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -1417,7 +1417,6 @@ defmodule Pleroma.UserTest do
test "delete/1 when approval is pending deletes the user" do
user = insert(:user, approval_pending: true)
- {:ok, user: user}
{:ok, job} = User.delete(user)
{:ok, _} = ObanHelpers.perform(job)
@@ -1426,6 +1425,85 @@ defmodule Pleroma.UserTest do
refute User.get_by_id(user.id)
end
+ test "delete/1 purges a user when they wouldn't be fully deleted" do
+ user =
+ insert(:user, %{
+ bio: "eyy lmao",
+ name: "qqqqqqq",
+ password_hash: "pdfk2$1b3n159001",
+ keys: "RSA begin buplic key",
+ public_key: "--PRIVATE KEYE--",
+ avatar: %{"a" => "b"},
+ tags: ["qqqqq"],
+ banner: %{"a" => "b"},
+ background: %{"a" => "b"},
+ note_count: 9,
+ follower_count: 9,
+ following_count: 9001,
+ locked: true,
+ confirmation_pending: true,
+ password_reset_pending: true,
+ approval_pending: true,
+ registration_reason: "ahhhhh",
+ confirmation_token: "qqqq",
+ domain_blocks: ["lain.com"],
+ deactivated: true,
+ ap_enabled: true,
+ is_moderator: true,
+ is_admin: true,
+ mastofe_settings: %{"a" => "b"},
+ mascot: %{"a" => "b"},
+ emoji: %{"a" => "b"},
+ pleroma_settings_store: %{"q" => "x"},
+ fields: [%{"gg" => "qq"}],
+ raw_fields: [%{"gg" => "qq"}],
+ discoverable: true,
+ also_known_as: ["https://lol.olo/users/loll"]
+ })
+
+ {:ok, job} = User.delete(user)
+ {:ok, _} = ObanHelpers.perform(job)
+ user = User.get_by_id(user.id)
+
+ assert %User{
+ bio: nil,
+ raw_bio: nil,
+ email: nil,
+ name: nil,
+ password_hash: nil,
+ keys: nil,
+ public_key: nil,
+ avatar: %{},
+ tags: [],
+ last_refreshed_at: nil,
+ last_digest_emailed_at: nil,
+ banner: %{},
+ background: %{},
+ note_count: 0,
+ follower_count: 0,
+ following_count: 0,
+ locked: false,
+ confirmation_pending: false,
+ password_reset_pending: false,
+ approval_pending: false,
+ registration_reason: nil,
+ confirmation_token: nil,
+ domain_blocks: [],
+ deactivated: true,
+ ap_enabled: false,
+ is_moderator: false,
+ is_admin: false,
+ mastofe_settings: nil,
+ mascot: nil,
+ emoji: %{},
+ pleroma_settings_store: %{},
+ fields: [],
+ raw_fields: [],
+ discoverable: false,
+ also_known_as: []
+ } = user
+ end
+
test "get_public_key_for_ap_id fetches a user that's not in the db" do
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end
diff --git a/test/web/activity_pub/transmogrifier/audio_handling_test.exs b/test/web/activity_pub/transmogrifier/audio_handling_test.exs
new file mode 100644
index 000000000..c74a9c45d
--- /dev/null
+++ b/test/web/activity_pub/transmogrifier/audio_handling_test.exs
@@ -0,0 +1,45 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
+ use Oban.Testing, repo: Pleroma.Repo
+ use Pleroma.DataCase
+
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.Transmogrifier
+
+ import Pleroma.Factory
+
+ test "it works for incoming listens" do
+ _user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
+
+ data = %{
+ "@context" => "https://www.w3.org/ns/activitystreams",
+ "to" => ["https://www.w3.org/ns/activitystreams#Public"],
+ "cc" => [],
+ "type" => "Listen",
+ "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
+ "actor" => "http://mastodon.example.org/users/admin",
+ "object" => %{
+ "type" => "Audio",
+ "id" => "http://mastodon.example.org/users/admin/listens/1234",
+ "attributedTo" => "http://mastodon.example.org/users/admin",
+ "title" => "lain radio episode 1",
+ "artist" => "lain",
+ "album" => "lain radio",
+ "length" => 180_000
+ }
+ }
+
+ {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
+
+ object = Object.normalize(activity)
+
+ assert object.data["title"] == "lain radio episode 1"
+ assert object.data["artist"] == "lain"
+ assert object.data["album"] == "lain radio"
+ assert object.data["length"] == 180_000
+ end
+end
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 0dd4e6e47..3fa41b0c7 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -225,35 +225,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert Enum.at(object.data["tag"], 2) == "moo"
end
- test "it works for incoming listens" do
- data = %{
- "@context" => "https://www.w3.org/ns/activitystreams",
- "to" => ["https://www.w3.org/ns/activitystreams#Public"],
- "cc" => [],
- "type" => "Listen",
- "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
- "actor" => "http://mastodon.example.org/users/admin",
- "object" => %{
- "type" => "Audio",
- "id" => "http://mastodon.example.org/users/admin/listens/1234",
- "attributedTo" => "http://mastodon.example.org/users/admin",
- "title" => "lain radio episode 1",
- "artist" => "lain",
- "album" => "lain radio",
- "length" => 180_000
- }
- }
-
- {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
-
- object = Object.normalize(activity)
-
- assert object.data["title"] == "lain radio episode 1"
- assert object.data["artist"] == "lain"
- assert object.data["album"] == "lain radio"
- assert object.data["length"] == 180_000
- end
-
test "it works for incoming notices with contentMap" do
data =
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
diff --git a/test/web/admin_api/controllers/admin_api_controller_test.exs b/test/web/admin_api/controllers/admin_api_controller_test.exs
index 66d4b1ef3..2eb698807 100644
--- a/test/web/admin_api/controllers/admin_api_controller_test.exs
+++ b/test/web/admin_api/controllers/admin_api_controller_test.exs
@@ -155,13 +155,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "DELETE /api/pleroma/admin/users" do
test "single user", %{admin: admin, conn: conn} do
- user = insert(:user)
clear_config([:instance, :federating], true)
+ user =
+ insert(:user,
+ avatar: %{"url" => [%{"href" => "https://someurl"}]},
+ banner: %{"url" => [%{"href" => "https://somebanner"}]},
+ bio: "Hello world!",
+ name: "A guy"
+ )
+
+ # Create some activities to check they got deleted later
+ follower = insert(:user)
+ {:ok, _} = CommonAPI.post(user, %{status: "test"})
+ {:ok, _, _, _} = CommonAPI.follow(user, follower)
+ {:ok, _, _, _} = CommonAPI.follow(follower, user)
+ user = Repo.get(User, user.id)
+ assert user.note_count == 1
+ assert user.follower_count == 1
+ assert user.following_count == 1
refute user.deactivated
with_mock Pleroma.Web.Federator,
- publish: fn _ -> nil end do
+ publish: fn _ -> nil end,
+ perform: fn _, _ -> nil end do
conn =
conn
|> put_req_header("accept", "application/json")
@@ -181,6 +198,14 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
user = Repo.get(User, user.id)
assert user.deactivated
+ assert user.avatar == %{}
+ assert user.banner == %{}
+ assert user.note_count == 0
+ assert user.follower_count == 0
+ assert user.following_count == 0
+ assert user.bio == nil
+ assert user.name == nil
+
assert called(Pleroma.Web.Federator.publish(:_))
end
end
diff --git a/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs b/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs
index 5ab6cb78a..f243d1fb2 100644
--- a/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs
+++ b/test/web/admin_api/controllers/media_proxy_cache_controller_test.exs
@@ -48,6 +48,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2")
|> json_response_and_validate_schema(200)
+ assert response["page_size"] == 2
+ assert response["count"] == 5
+
assert response["urls"] == [
"http://localhost:4001/media/fb1f4d.jpg",
"http://localhost:4001/media/a688346.jpg"
@@ -63,6 +66,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
"http://localhost:4001/media/tb13f47.jpg"
]
+ assert response["page_size"] == 2
+ assert response["count"] == 5
+
response =
conn
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=3")
@@ -70,6 +76,30 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
assert response["urls"] == ["http://localhost:4001/media/wb1f46.jpg"]
end
+
+ test "search banned MediaProxy URLs", %{conn: conn} do
+ MediaProxy.put_in_banned_urls([
+ "http://localhost:4001/media/a688346.jpg",
+ "http://localhost:4001/media/ff44b1f4d.jpg"
+ ])
+
+ MediaProxy.put_in_banned_urls("http://localhost:4001/media/gb1f44.jpg")
+ MediaProxy.put_in_banned_urls("http://localhost:4001/media/tb13f47.jpg")
+ MediaProxy.put_in_banned_urls("http://localhost:4001/media/wb1f46.jpg")
+
+ response =
+ conn
+ |> get("/api/pleroma/admin/media_proxy_caches?page_size=2&query=F44")
+ |> json_response_and_validate_schema(200)
+
+ assert response["urls"] == [
+ "http://localhost:4001/media/gb1f44.jpg",
+ "http://localhost:4001/media/ff44b1f4d.jpg"
+ ]
+
+ assert response["page_size"] == 2
+ assert response["count"] == 2
+ end
end
describe "POST /api/pleroma/admin/media_proxy_caches/delete" do
@@ -79,15 +109,13 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
"http://localhost:4001/media/fb1f4d.jpg"
])
- response =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/pleroma/admin/media_proxy_caches/delete", %{
- urls: ["http://localhost:4001/media/a688346.jpg"]
- })
- |> json_response_and_validate_schema(200)
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/media_proxy_caches/delete", %{
+ urls: ["http://localhost:4001/media/a688346.jpg"]
+ })
+ |> json_response_and_validate_schema(200)
- assert response["urls"] == ["http://localhost:4001/media/a688346.jpg"]
refute MediaProxy.in_banned_urls("http://localhost:4001/media/a688346.jpg")
assert MediaProxy.in_banned_urls("http://localhost:4001/media/fb1f4d.jpg")
end
@@ -106,13 +134,10 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
purge: fn _, _ -> {"ok", 0} end
]}
] do
- response =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/pleroma/admin/media_proxy_caches/purge", %{urls: urls, ban: false})
- |> json_response_and_validate_schema(200)
-
- assert response["urls"] == urls
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post("/api/pleroma/admin/media_proxy_caches/purge", %{urls: urls, ban: false})
+ |> json_response_and_validate_schema(200)
refute MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
refute MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
@@ -126,16 +151,13 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
]
with_mocks [{MediaProxy.Invalidation.Script, [], [purge: fn _, _ -> {"ok", 0} end]}] do
- response =
- conn
- |> put_req_header("content-type", "application/json")
- |> post("/api/pleroma/admin/media_proxy_caches/purge", %{
- urls: urls,
- ban: true
- })
- |> json_response_and_validate_schema(200)
-
- assert response["urls"] == urls
+ conn
+ |> put_req_header("content-type", "application/json")
+ |> post(
+ "/api/pleroma/admin/media_proxy_caches/purge",
+ %{urls: urls, ban: true}
+ )
+ |> json_response_and_validate_schema(200)
assert MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
assert MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
diff --git a/test/web/mastodon_api/controllers/timeline_controller_test.exs b/test/web/mastodon_api/controllers/timeline_controller_test.exs
index 50e0d783d..71bac99f7 100644
--- a/test/web/mastodon_api/controllers/timeline_controller_test.exs
+++ b/test/web/mastodon_api/controllers/timeline_controller_test.exs
@@ -445,6 +445,23 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
assert length(json_response(res_conn, 200)) == 2
end
+ test "with default settings on private instances, returns 403 for unauthenticated users", %{
+ conn: conn,
+ base_uri: base_uri,
+ error_response: error_response
+ } do
+ clear_config([:instance, :public], false)
+ clear_config([:restrict_unauthenticated, :timelines])
+
+ for local <- [true, false] do
+ res_conn = get(conn, "#{base_uri}?local=#{local}")
+
+ assert json_response(res_conn, :unauthorized) == error_response
+ end
+
+ ensure_authenticated_access(base_uri)
+ end
+
test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
conn: conn,
base_uri: base_uri,
diff --git a/test/web/preload/timeline_test.exs b/test/web/preload/timeline_test.exs
index fea95a6a4..3b1f2f1aa 100644
--- a/test/web/preload/timeline_test.exs
+++ b/test/web/preload/timeline_test.exs
@@ -12,16 +12,8 @@ defmodule Pleroma.Web.Preload.Providers.TimelineTest do
@public_url "/api/v1/timelines/public"
describe "unauthenticated timeliness when restricted" do
- setup do
- svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
- Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{local: true, federated: true})
-
- on_exit(fn ->
- Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
- end)
-
- :ok
- end
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
test "return nothing" do
tl_data = Timelines.generate_terms(%{})
@@ -31,20 +23,10 @@ defmodule Pleroma.Web.Preload.Providers.TimelineTest do
end
describe "unauthenticated timeliness when unrestricted" do
- setup do
- svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :local], false)
+ setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], false)
- Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{
- local: false,
- federated: false
- })
-
- on_exit(fn ->
- Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
- end)
-
- {:ok, user: insert(:user)}
- end
+ setup do: {:ok, user: insert(:user)}
test "returns the timeline when not restricted" do
assert Timelines.generate_terms(%{})
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 109c1e637..354d77b56 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -586,10 +586,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- test "with proper permissions and valid password", %{conn: conn} do
+ test "with proper permissions and valid password", %{conn: conn, user: user} do
conn = post(conn, "/api/pleroma/delete_account", %{"password" => "test"})
-
+ ObanHelpers.perform_all()
assert json_response(conn, 200) == %{"status" => "success"}
+
+ user = User.get_by_id(user.id)
+ assert user.deactivated == true
+ assert user.name == nil
+ assert user.bio == nil
+ assert user.password_hash == nil
end
end
end