aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-05-29 12:36:17 +0200
committerlain <lain@soykaf.club>2020-05-29 12:36:17 +0200
commitaf6d01ec93a07cd896bc4f0a2c2cf437c6fd51fc (patch)
tree54e02858d0fa9ca905ffe5a057c9f0accbeae115 /test
parentdbd07d29a358a446d87078d60b993a59b757ad1d (diff)
parent396bc69aeef951f163c0c20474ce4653df1dd667 (diff)
downloadpleroma-af6d01ec93a07cd896bc4f0a2c2cf437c6fd51fc.tar.gz
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
Diffstat (limited to 'test')
-rw-r--r--test/instance_static/local_pack/files.json3
-rw-r--r--test/instance_static/local_pack/manifest.json10
-rw-r--r--test/notification_test.exs11
-rw-r--r--test/plugs/authentication_plug_test.exs1
-rw-r--r--test/plugs/http_security_plug_test.exs2
-rw-r--r--test/support/factory.ex3
-rw-r--r--test/tasks/emoji_test.exs13
-rw-r--r--test/user_test.exs20
-rw-r--r--test/web/activity_pub/activity_pub_controller_test.exs30
-rw-r--r--test/web/activity_pub/transmogrifier_test.exs33
-rw-r--r--test/web/admin_api/controllers/admin_api_controller_test.exs35
-rw-r--r--test/web/feed/user_controller_test.exs26
-rw-r--r--test/web/mastodon_api/views/account_view_test.exs35
-rw-r--r--test/web/media_proxy/media_proxy_test.exs14
14 files changed, 196 insertions, 40 deletions
diff --git a/test/instance_static/local_pack/files.json b/test/instance_static/local_pack/files.json
new file mode 100644
index 000000000..279770998
--- /dev/null
+++ b/test/instance_static/local_pack/files.json
@@ -0,0 +1,3 @@
+{
+ "blank": "blank.png"
+} \ No newline at end of file
diff --git a/test/instance_static/local_pack/manifest.json b/test/instance_static/local_pack/manifest.json
new file mode 100644
index 000000000..01067042f
--- /dev/null
+++ b/test/instance_static/local_pack/manifest.json
@@ -0,0 +1,10 @@
+{
+ "local": {
+ "src_sha256": "384025A1AC6314473863A11AC7AB38A12C01B851A3F82359B89B4D4211D3291D",
+ "src": "test/fixtures/emoji/packs/blank.png.zip",
+ "license": "Apache 2.0",
+ "homepage": "https://example.com",
+ "files": "files.json",
+ "description": "Some local pack"
+ }
+} \ No newline at end of file
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 3a96721fa..37c255fee 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -454,8 +454,7 @@ defmodule Pleroma.NotificationTest do
status: "hey again @#{other_user.nickname}!"
})
- [n2, n1] = notifs = Notification.for_user(other_user)
- assert length(notifs) == 2
+ [n2, n1] = Notification.for_user(other_user)
assert n2.id > n1.id
@@ -464,7 +463,9 @@ defmodule Pleroma.NotificationTest do
status: "hey yet again @#{other_user.nickname}!"
})
- Notification.set_read_up_to(other_user, n2.id)
+ [_, read_notification] = Notification.set_read_up_to(other_user, n2.id)
+
+ assert read_notification.activity.object
[n3, n2, n1] = Notification.for_user(other_user)
@@ -972,7 +973,9 @@ defmodule Pleroma.NotificationTest do
{:ok, _activity} = CommonAPI.post(muted, %{status: "hey @#{user.nickname}"})
- assert length(Notification.for_user(user)) == 1
+ [notification] = Notification.for_user(user)
+
+ assert notification.activity.object
end
test "it doesn't return notifications for muted user with notifications" do
diff --git a/test/plugs/authentication_plug_test.exs b/test/plugs/authentication_plug_test.exs
index 3c70c1747..777ae15ae 100644
--- a/test/plugs/authentication_plug_test.exs
+++ b/test/plugs/authentication_plug_test.exs
@@ -68,6 +68,7 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
assert "$pbkdf2" <> _ = user.password_hash
end
+ @tag :skip_on_mac
test "with a crypt hash, it updates to a pkbdf2 hash", %{conn: conn} do
user =
insert(:user,
diff --git a/test/plugs/http_security_plug_test.exs b/test/plugs/http_security_plug_test.exs
index 84e4c274f..63b4d3f31 100644
--- a/test/plugs/http_security_plug_test.exs
+++ b/test/plugs/http_security_plug_test.exs
@@ -67,7 +67,7 @@ defmodule Pleroma.Web.Plugs.HTTPSecurityPlugTest do
[csp] = Conn.get_resp_header(conn, "content-security-policy")
- assert csp =~ ~r|report-uri https://endpoint.com; report-to csp-endpoint;|
+ assert csp =~ ~r|report-uri https://endpoint.com;report-to csp-endpoint;|
[reply_to] = Conn.get_resp_header(conn, "reply-to")
diff --git a/test/support/factory.ex b/test/support/factory.ex
index d4284831c..6e3676aca 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -34,7 +34,8 @@ defmodule Pleroma.Factory do
last_digest_emailed_at: NaiveDateTime.utc_now(),
last_refreshed_at: NaiveDateTime.utc_now(),
notification_settings: %Pleroma.User.NotificationSetting{},
- multi_factor_authentication_settings: %Pleroma.MFA.Settings{}
+ multi_factor_authentication_settings: %Pleroma.MFA.Settings{},
+ ap_enabled: true
}
%{
diff --git a/test/tasks/emoji_test.exs b/test/tasks/emoji_test.exs
index f5de3ef0e..499f098c2 100644
--- a/test/tasks/emoji_test.exs
+++ b/test/tasks/emoji_test.exs
@@ -73,6 +73,19 @@ defmodule Mix.Tasks.Pleroma.EmojiTest do
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
%{
diff --git a/test/user_test.exs b/test/user_test.exs
index 45125f704..3556ef1b4 100644
--- a/test/user_test.exs
+++ b/test/user_test.exs
@@ -586,6 +586,26 @@ defmodule Pleroma.UserTest do
refute user.last_refreshed_at == orig_user.last_refreshed_at
end
+
+ @tag capture_log: true
+ test "it returns the old user if stale, but unfetchable" do
+ a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
+
+ orig_user =
+ insert(
+ :user,
+ local: false,
+ nickname: "admin@mastodon.example.org",
+ ap_id: "http://mastodon.example.org/users/raymoo",
+ last_refreshed_at: a_week_ago
+ )
+
+ assert orig_user.last_refreshed_at == a_week_ago
+
+ {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/raymoo")
+
+ assert user.last_refreshed_at == orig_user.last_refreshed_at
+ end
end
test "returns an ap_id for a user" do
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index dd2a48a61..24edab41a 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -451,6 +451,36 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
assert Activity.get_by_ap_id(data["id"])
end
+ @tag capture_log: true
+ test "it inserts an incoming activity into the database" <>
+ "even if we can't fetch the user but have it in our db",
+ %{conn: conn} do
+ user =
+ insert(:user,
+ ap_id: "https://mastodon.example.org/users/raymoo",
+ ap_enabled: true,
+ local: false,
+ last_refreshed_at: nil
+ )
+
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+ |> Map.put("actor", user.ap_id)
+ |> put_in(["object", "attridbutedTo"], user.ap_id)
+
+ conn =
+ conn
+ |> assign(:valid_signature, true)
+ |> put_req_header("content-type", "application/activity+json")
+ |> post("/inbox", data)
+
+ assert "ok" == json_response(conn, 200)
+
+ ObanHelpers.perform(all_enqueued(worker: ReceiverWorker))
+ assert Activity.get_by_ap_id(data["id"])
+ end
+
test "it clears `unreachable` federation status of the sender", %{conn: conn} do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 356004d48..94d8552e8 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1094,23 +1094,28 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
{:ok, activity} =
CommonAPI.post(user, %{status: "hey, @#{other_user.nickname}, how are ya? #2hu"})
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- object = modified["object"]
+ with_mock Pleroma.Notification,
+ get_notified_from_activity: fn _, _ -> [] end do
+ {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
- expected_mention = %{
- "href" => other_user.ap_id,
- "name" => "@#{other_user.nickname}",
- "type" => "Mention"
- }
+ object = modified["object"]
- expected_tag = %{
- "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
- "type" => "Hashtag",
- "name" => "#2hu"
- }
+ expected_mention = %{
+ "href" => other_user.ap_id,
+ "name" => "@#{other_user.nickname}",
+ "type" => "Mention"
+ }
- assert Enum.member?(object["tag"], expected_tag)
- assert Enum.member?(object["tag"], expected_mention)
+ expected_tag = %{
+ "href" => Pleroma.Web.Endpoint.url() <> "/tags/2hu",
+ "type" => "Hashtag",
+ "name" => "#2hu"
+ }
+
+ refute called(Pleroma.Notification.get_notified_from_activity(:_, :_))
+ assert Enum.member?(object["tag"], expected_tag)
+ assert Enum.member?(object["tag"], expected_mention)
+ end
end
test "it adds the sensitive property" do
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 321840a8c..ead840186 100644
--- a/test/web/admin_api/controllers/admin_api_controller_test.exs
+++ b/test/web/admin_api/controllers/admin_api_controller_test.exs
@@ -3191,8 +3191,12 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
describe "PATCH /users/:nickname/credentials" do
- test "changes password and email", %{conn: conn, admin: admin} do
+ setup do
user = insert(:user)
+ [user: user]
+ end
+
+ test "changes password and email", %{conn: conn, admin: admin, user: user} do
assert user.password_reset_pending == false
conn =
@@ -3222,9 +3226,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
"@#{admin.nickname} forced password reset for users: @#{user.nickname}"
end
- test "returns 403 if requested by a non-admin" do
- user = insert(:user)
-
+ test "returns 403 if requested by a non-admin", %{user: user} do
conn =
build_conn()
|> assign(:user, user)
@@ -3236,6 +3238,31 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
assert json_response(conn, :forbidden)
end
+
+ test "changes actor type from permitted list", %{conn: conn, user: user} do
+ assert user.actor_type == "Person"
+
+ assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
+ "actor_type" => "Service"
+ })
+ |> json_response(200) == %{"status" => "success"}
+
+ updated_user = User.get_by_id(user.id)
+
+ assert updated_user.actor_type == "Service"
+
+ assert patch(conn, "/api/pleroma/admin/users/#{user.nickname}/credentials", %{
+ "actor_type" => "Application"
+ })
+ |> json_response(200) == %{"errors" => %{"actor_type" => "is invalid"}}
+ end
+
+ test "update non existing user", %{conn: conn} do
+ assert patch(conn, "/api/pleroma/admin/users/non-existing/credentials", %{
+ "password" => "new_password"
+ })
+ |> json_response(200) == %{"error" => "Unable to update user."}
+ end
end
describe "PATCH /users/:nickname/force_password_reset" do
diff --git a/test/web/feed/user_controller_test.exs b/test/web/feed/user_controller_test.exs
index 05ad427c2..fa2ed1ea5 100644
--- a/test/web/feed/user_controller_test.exs
+++ b/test/web/feed/user_controller_test.exs
@@ -11,13 +11,14 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
alias Pleroma.Config
alias Pleroma.Object
alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
setup do: clear_config([:instance, :federating], true)
describe "feed" do
setup do: clear_config([:feed])
- test "gets a feed", %{conn: conn} do
+ test "gets an atom feed", %{conn: conn} do
Config.put(
[:feed, :post_title],
%{max_length: 10, omission: "..."}
@@ -157,6 +158,29 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
assert response(conn, 404)
end
+
+ test "returns feed with public and unlisted activities", %{conn: conn} do
+ user = insert(:user)
+
+ {:ok, _} = CommonAPI.post(user, %{status: "public", visibility: "public"})
+ {:ok, _} = CommonAPI.post(user, %{status: "direct", visibility: "direct"})
+ {:ok, _} = CommonAPI.post(user, %{status: "unlisted", visibility: "unlisted"})
+ {:ok, _} = CommonAPI.post(user, %{status: "private", visibility: "private"})
+
+ resp =
+ conn
+ |> put_req_header("accept", "application/atom+xml")
+ |> get(user_feed_path(conn, :feed, user.nickname))
+ |> response(200)
+
+ activity_titles =
+ resp
+ |> SweetXml.parse()
+ |> SweetXml.xpath(~x"//entry/title/text()"l)
+ |> Enum.sort()
+
+ assert activity_titles == ['public', 'unlisted']
+ end
end
# Note: see ActivityPubControllerTest for JSON format tests
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index d5d7236a0..044f088a4 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -54,10 +54,10 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
header_static: "http://localhost:4001/images/banner.png",
emojis: [
%{
- "static_url" => "/file.png",
- "url" => "/file.png",
- "shortcode" => "karjalanpiirakka",
- "visible_in_picker" => false
+ static_url: "/file.png",
+ url: "/file.png",
+ shortcode: "karjalanpiirakka",
+ visible_in_picker: false
}
],
fields: [],
@@ -493,4 +493,31 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
AccountView.render("show.json", %{user: user, for: user})
end
end
+
+ test "uses mediaproxy urls when it's enabled" do
+ clear_config([:media_proxy, :enabled], true)
+
+ user =
+ insert(:user,
+ avatar: %{"url" => [%{"href" => "https://evil.website/avatar.png"}]},
+ banner: %{"url" => [%{"href" => "https://evil.website/banner.png"}]},
+ emoji: %{"joker_smile" => "https://evil.website/society.png"}
+ )
+
+ AccountView.render("show.json", %{user: user})
+ |> Enum.all?(fn
+ {key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
+ String.starts_with?(url, Pleroma.Web.base_url())
+
+ {:emojis, emojis} ->
+ Enum.all?(emojis, fn %{url: url, static_url: static_url} ->
+ String.starts_with?(url, Pleroma.Web.base_url()) &&
+ String.starts_with?(static_url, Pleroma.Web.base_url())
+ end)
+
+ _ ->
+ true
+ end)
+ |> assert()
+ end
end
diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index 69c2d5dae..69d2a71a6 100644
--- a/test/web/media_proxy/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -124,15 +124,7 @@ defmodule Pleroma.Web.MediaProxyTest do
end
test "uses the configured base_url" do
- base_url = Pleroma.Config.get([:media_proxy, :base_url])
-
- if base_url do
- on_exit(fn ->
- Pleroma.Config.put([:media_proxy, :base_url], base_url)
- end)
- end
-
- Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
+ clear_config([:media_proxy, :base_url], "https://cache.pleroma.social")
url = "https://pleroma.soykaf.com/static/logo.png"
encoded = url(url)
@@ -213,8 +205,8 @@ defmodule Pleroma.Web.MediaProxyTest do
end
test "does not change whitelisted urls" do
- Pleroma.Config.put([:media_proxy, :whitelist], ["mycdn.akamai.com"])
- Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
+ clear_config([:media_proxy, :whitelist], ["mycdn.akamai.com"])
+ clear_config([:media_proxy, :base_url], "https://cache.pleroma.social")
media_url = "https://mycdn.akamai.com"