From e8fa477793e1395664f79d572800f11994cdd38d Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 13 Jul 2019 19:17:57 +0300
Subject: Refactor Follows/Followers counter syncronization
- Actually sync counters in the database instead of info cache (which got
overriden after user update was finished anyway)
- Add following count field to user info
- Set hide_followers/hide_follows for remote users based on http status
codes for the first collection page
---
test/web/activity_pub/transmogrifier_test.exs | 28 ---------------------------
1 file changed, 28 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index b896a532b..6d05138fb 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -1359,32 +1359,4 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
refute recipient.follower_address in fixed_object["to"]
end
end
-
- test "update_following_followers_counters/1" do
- user1 =
- insert(:user,
- local: false,
- follower_address: "http://localhost:4001/users/masto_closed/followers",
- following_address: "http://localhost:4001/users/masto_closed/following"
- )
-
- user2 =
- insert(:user,
- local: false,
- follower_address: "http://localhost:4001/users/fuser2/followers",
- following_address: "http://localhost:4001/users/fuser2/following"
- )
-
- Transmogrifier.update_following_followers_counters(user1)
- Transmogrifier.update_following_followers_counters(user2)
-
- %{follower_count: followers, following_count: following} = User.get_cached_user_info(user1)
- assert followers == 437
- assert following == 152
-
- %{follower_count: followers, following_count: following} = User.get_cached_user_info(user2)
-
- assert followers == 527
- assert following == 267
- end
end
--
cgit v1.2.3
From 183da33e005c8a8e8472350a3b6b36ff6f82d67d Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sun, 14 Jul 2019 00:56:02 +0300
Subject: Add tests for fetch_follow_information_for_user and check object type
when fetching the page
---
test/web/activity_pub/activity_pub_test.exs | 81 +++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 59d56f3a7..448ffbf54 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -1222,4 +1222,85 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert result.id == activity.id
end
end
+
+ describe "fetch_follow_information_for_user" do
+ test "syncronizes following/followers counters" do
+ user =
+ insert(:user,
+ local: false,
+ follower_address: "http://localhost:4001/users/fuser2/followers",
+ following_address: "http://localhost:4001/users/fuser2/following"
+ )
+
+ {:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
+ assert user.info.follower_count == 527
+ assert user.info.following_count == 267
+ end
+
+ test "detects hidden followers" do
+ mock(fn env ->
+ case env.url do
+ "http://localhost:4001/users/masto_closed/followers?page=1" ->
+ %Tesla.Env{status: 403, body: ""}
+
+ "http://localhost:4001/users/masto_closed/following?page=1" ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ Jason.encode!(%{
+ "id" => "http://localhost:4001/users/masto_closed/following?page=1",
+ "type" => "OrderedCollectionPage"
+ })
+ }
+
+ _ ->
+ apply(HttpRequestMock, :request, [env])
+ end
+ end)
+
+ user =
+ insert(:user,
+ local: false,
+ follower_address: "http://localhost:4001/users/masto_closed/followers",
+ following_address: "http://localhost:4001/users/masto_closed/following"
+ )
+
+ {:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
+ assert user.info.hide_followers == true
+ assert user.info.hide_follows == false
+ end
+
+ test "detects hidden follows" do
+ mock(fn env ->
+ case env.url do
+ "http://localhost:4001/users/masto_closed/following?page=1" ->
+ %Tesla.Env{status: 403, body: ""}
+
+ "http://localhost:4001/users/masto_closed/followers?page=1" ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ Jason.encode!(%{
+ "id" => "http://localhost:4001/users/masto_closed/followers?page=1",
+ "type" => "OrderedCollectionPage"
+ })
+ }
+
+ _ ->
+ apply(HttpRequestMock, :request, [env])
+ end
+ end)
+
+ user =
+ insert(:user,
+ local: false,
+ follower_address: "http://localhost:4001/users/masto_closed/followers",
+ following_address: "http://localhost:4001/users/masto_closed/following"
+ )
+
+ {:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
+ assert user.info.hide_followers == false
+ assert user.info.hide_follows == true
+ end
+ end
end
--
cgit v1.2.3
From 0c2dcb4c69ed340d02a4b20a4f341f1d9aaaba38 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sun, 14 Jul 2019 01:58:39 +0300
Subject: Add follow information refetching after following/unfollowing
---
test/web/activity_pub/activity_pub_test.exs | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 448ffbf54..24d8493fe 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -1232,9 +1232,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
following_address: "http://localhost:4001/users/fuser2/following"
)
- {:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
- assert user.info.follower_count == 527
- assert user.info.following_count == 267
+ {:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
+ assert info.follower_count == 527
+ assert info.following_count == 267
end
test "detects hidden followers" do
@@ -1265,9 +1265,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
following_address: "http://localhost:4001/users/masto_closed/following"
)
- {:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
- assert user.info.hide_followers == true
- assert user.info.hide_follows == false
+ {:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
+ assert info.hide_followers == true
+ assert info.hide_follows == false
end
test "detects hidden follows" do
@@ -1298,9 +1298,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
following_address: "http://localhost:4001/users/masto_closed/following"
)
- {:ok, user} = ActivityPub.fetch_follow_information_for_user(user)
- assert user.info.hide_followers == false
- assert user.info.hide_follows == true
+ {:ok, info} = ActivityPub.fetch_follow_information_for_user(user)
+ assert info.hide_followers == false
+ assert info.hide_follows == true
end
end
end
--
cgit v1.2.3
From 4af4f6166bd04b5a302856034fdda94dd61045ed Mon Sep 17 00:00:00 2001
From: Sadposter
Date: Wed, 24 Jul 2019 11:09:06 +0100
Subject: honour domain blocks on streaming notifications
---
test/web/streamer_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test/web')
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index 8f56e7486..95d5e5d58 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -103,6 +103,24 @@ defmodule Pleroma.Web.StreamerTest do
Streamer.stream("user:notification", notif)
Task.await(task)
end
+
+ test "it doesn't send notify to the 'user:notification' stream' when a domain is blocked", %{
+ user: user
+ } do
+ user2 = insert(:user, %{ap_id: "https://hecking-lewd-place.com/user/meanie"})
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user:notification",
+ %{transport_pid: task.pid, assigns: %{user: user}}
+ )
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+ {:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
+ {:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+ Streamer.stream("user:notification", notif)
+ Task.await(task)
+ end
end
test "it sends to public" do
--
cgit v1.2.3
From f5d574f4ed9aa997a47d03f02adeb701d96f6789 Mon Sep 17 00:00:00 2001
From: sadposter
Date: Wed, 24 Jul 2019 11:35:16 +0100
Subject: check both item and parent domain blocks
---
test/web/streamer_test.exs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index 95d5e5d58..d47b37efb 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -115,9 +115,10 @@ defmodule Pleroma.Web.StreamerTest do
%{transport_pid: task.pid, assigns: %{user: user}}
)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
{:ok, user} = User.block_domain(user, "hecking-lewd-place.com")
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
{:ok, notif, _} = CommonAPI.favorite(activity.id, user2)
+
Streamer.stream("user:notification", notif)
Task.await(task)
end
--
cgit v1.2.3
From 4504135894d5b52c74818fadc3f7ed49ace1702b Mon Sep 17 00:00:00 2001
From: Eugenij
Date: Wed, 24 Jul 2019 15:12:27 +0000
Subject: Add `domain_blocking` to the relationship API (GET
/api/v1/accounts/relationships)
---
test/web/mastodon_api/account_view_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index fa44d35cc..905e9af98 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -231,6 +231,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
AccountView.render("relationship.json", %{user: user, target: other_user})
end
+ test "represent a relationship for the user blocking a domain" do
+ user = insert(:user)
+ other_user = insert(:user, ap_id: "https://bad.site/users/other_user")
+
+ {:ok, user} = User.block_domain(user, "bad.site")
+
+ assert %{domain_blocking: true, blocking: false} =
+ AccountView.render("relationship.json", %{user: user, target: other_user})
+ end
+
test "represent a relationship for the user with a pending follow request" do
user = insert(:user)
other_user = insert(:user, %{info: %User.Info{locked: true}})
--
cgit v1.2.3
From 55341ac71740d3d8aded9c6520e06b9c509a6670 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Wed, 24 Jul 2019 15:13:10 +0000
Subject: tests WebFinger
---
test/web/web_finger/web_finger_controller_test.exs | 43 ++++++++++++++++++++++
test/web/web_finger/web_finger_test.exs | 5 +++
2 files changed, 48 insertions(+)
(limited to 'test/web')
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index a14ed3126..7d861cbf5 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -19,6 +19,19 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
:ok
end
+ test "GET host-meta" do
+ response =
+ build_conn()
+ |> get("/.well-known/host-meta")
+
+ assert response.status == 200
+
+ assert response.resp_body ==
+ ~s()
+ end
+
test "Webfinger JRD" do
user = insert(:user)
@@ -30,6 +43,16 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
assert json_response(response, 200)["subject"] == "acct:#{user.nickname}@localhost"
end
+ test "it returns 404 when user isn't found (JSON)" do
+ result =
+ build_conn()
+ |> put_req_header("accept", "application/jrd+json")
+ |> get("/.well-known/webfinger?resource=acct:jimm@localhost")
+ |> json_response(404)
+
+ assert result == "Couldn't find user"
+ end
+
test "Webfinger XML" do
user = insert(:user)
@@ -41,6 +64,26 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
assert response(response, 200)
end
+ test "it returns 404 when user isn't found (XML)" do
+ result =
+ build_conn()
+ |> put_req_header("accept", "application/xrd+xml")
+ |> get("/.well-known/webfinger?resource=acct:jimm@localhost")
+ |> response(404)
+
+ assert result == "Couldn't find user"
+ end
+
+ test "Sends a 404 when invalid format" do
+ user = insert(:user)
+
+ assert_raise Phoenix.NotAcceptableError, fn ->
+ build_conn()
+ |> put_req_header("accept", "text/html")
+ |> get("/.well-known/webfinger?resource=acct:#{user.nickname}@localhost")
+ end
+ end
+
test "Sends a 400 when resource param is missing" do
response =
build_conn()
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 0578b4b8e..abf512604 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -40,6 +40,11 @@ defmodule Pleroma.Web.WebFingerTest do
end
describe "fingering" do
+ test "returns error when fails parse xml or json" do
+ user = "invalid_content@social.heldscal.la"
+ assert {:error, %Jason.DecodeError{}} = WebFinger.finger(user)
+ end
+
test "returns the info for an OStatus user" do
user = "shp@social.heldscal.la"
--
cgit v1.2.3
From 8d9f43e1d1a55f445e4e6e4659b9493cd35d99d9 Mon Sep 17 00:00:00 2001
From: kPherox
Date: Thu, 25 Jul 2019 01:27:34 +0900
Subject: Add WebFinger test for AP-only account
---
test/web/web_finger/web_finger_test.exs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'test/web')
diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs
index 0578b4b8e..0d3ef6717 100644
--- a/test/web/web_finger/web_finger_test.exs
+++ b/test/web/web_finger/web_finger_test.exs
@@ -81,6 +81,20 @@ defmodule Pleroma.Web.WebFingerTest do
assert data["subscribe_address"] == "https://gnusocial.de/main/ostatussub?profile={uri}"
end
+ test "it work for AP-only user" do
+ user = "kpherox@mstdn.jp"
+
+ {:ok, data} = WebFinger.finger(user)
+
+ assert data["magic_key"] == nil
+ assert data["salmon"] == nil
+
+ assert data["topic"] == "https://mstdn.jp/users/kPherox.atom"
+ assert data["subject"] == "acct:kPherox@mstdn.jp"
+ assert data["ap_id"] == "https://mstdn.jp/users/kPherox"
+ assert data["subscribe_address"] == "https://mstdn.jp/authorize_interaction?acct={uri}"
+ end
+
test "it works for friendica" do
user = "lain@squeet.me"
--
cgit v1.2.3
From b20020da160404f6f668eec2a2a42aaa2b6a09b2 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Wed, 24 Jul 2019 19:28:21 +0000
Subject: Show the url advertised in the Activity in the Status JSON response
---
test/web/mastodon_api/status_view_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 3447c5b1f..0b167f839 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -300,6 +300,16 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
assert %{id: "2"} = StatusView.render("attachment.json", %{attachment: object})
end
+ test "put the url advertised in the Activity in to the url attribute" do
+ id = "https://wedistribute.org/wp-json/pterotype/v1/object/85810"
+ [activity] = Activity.search(nil, id)
+
+ status = StatusView.render("status.json", %{activity: activity})
+
+ assert status.uri == id
+ assert status.url == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
+ end
+
test "a reblog" do
user = insert(:user)
activity = insert(:note_activity)
--
cgit v1.2.3
From 6b77a88365f3a58cf8d1f9c00ed04532f706b87c Mon Sep 17 00:00:00 2001
From: Maksim
Date: Fri, 26 Jul 2019 20:27:38 +0000
Subject: [#1097] added redirect: /pleroma/admin -> /pleroma/admin/
---
test/web/fallback_test.exs | 4 ++++
1 file changed, 4 insertions(+)
(limited to 'test/web')
diff --git a/test/web/fallback_test.exs b/test/web/fallback_test.exs
index cc78b3ae1..c13db9526 100644
--- a/test/web/fallback_test.exs
+++ b/test/web/fallback_test.exs
@@ -30,6 +30,10 @@ defmodule Pleroma.Web.FallbackTest do
|> json_response(404) == %{"error" => "Not implemented"}
end
+ test "GET /pleroma/admin -> /pleroma/admin/", %{conn: conn} do
+ assert redirected_to(get(conn, "/pleroma/admin")) =~ "/pleroma/admin/"
+ end
+
test "GET /*path", %{conn: conn} do
assert conn
|> get("/foo")
--
cgit v1.2.3
From 242f5c585ed797917ba8c61ceb5d266f4c670c90 Mon Sep 17 00:00:00 2001
From: Sachin Joshi
Date: Sun, 28 Jul 2019 20:30:10 +0000
Subject: add account confirmation email resend in mastodon api
---
.../mastodon_api/mastodon_api_controller_test.exs | 41 ++++++++++++++++++++++
1 file changed, 41 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index ce2e44499..d7f92fac2 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3923,4 +3923,45 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert conn.resp_body == ""
end
end
+
+ describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
+ setup do
+ setting = Pleroma.Config.get([:instance, :account_activation_required])
+
+ unless setting do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ end
+
+ user = insert(:user)
+ info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
+
+ {:ok, user} =
+ user
+ |> Changeset.change()
+ |> Changeset.put_embed(:info, info_change)
+ |> Repo.update()
+
+ assert user.info.confirmation_pending
+
+ [user: user]
+ end
+
+ test "resend account confirmation email", %{conn: conn, user: user} do
+ conn
+ |> assign(:user, user)
+ |> post("/api/v1/pleroma/accounts/confirmation_resend?email=#{user.email}")
+ |> json_response(:no_content)
+
+ email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
+ notify_email = Pleroma.Config.get([:instance, :notify_email])
+ instance_name = Pleroma.Config.get([:instance, :name])
+
+ assert_email_sent(
+ from: {instance_name, notify_email},
+ to: {user.name, user.email},
+ html_body: email.html_body
+ )
+ end
+ end
end
--
cgit v1.2.3
From b93498eb5289dc92587b77c316ed9f697bb9e5c8 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Mon, 29 Jul 2019 02:43:19 +0000
Subject: constants: add as_public constant and use it everywhere
---
test/web/push/impl_test.exs | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
(limited to 'test/web')
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 1e948086a..e2f89f40a 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -124,8 +124,7 @@ defmodule Pleroma.Web.Push.ImplTest do
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
object = Object.normalize(activity)
- assert Impl.format_body(%{activity: activity}, user, object) ==
- "@Bob has followed you"
+ assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has followed you"
end
test "renders body for announce activity" do
@@ -156,7 +155,6 @@ defmodule Pleroma.Web.Push.ImplTest do
{:ok, activity, _} = CommonAPI.favorite(activity.id, user)
object = Object.normalize(activity)
- assert Impl.format_body(%{activity: activity}, user, object) ==
- "@Bob has favorited your post"
+ assert Impl.format_body(%{activity: activity}, user, object) == "@Bob has favorited your post"
end
end
--
cgit v1.2.3
From 159bbec570c308bf3d71487726737a91eb569178 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Mon, 29 Jul 2019 05:02:20 +0000
Subject: added tests for OstatusController
---
test/web/ostatus/ostatus_controller_test.exs | 602 ++++++++++++++++++++++-----
1 file changed, 490 insertions(+), 112 deletions(-)
(limited to 'test/web')
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index bb7648bdd..9f756effb 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -101,160 +101,538 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
assert response(conn, 404)
end
- test "gets an object", %{conn: conn} do
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
- user = User.get_cached_by_ap_id(note_activity.data["actor"])
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
- url = "/objects/#{uuid}"
+ describe "GET object/2" do
+ test "gets an object", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
+ url = "/objects/#{uuid}"
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get(url)
+
+ expected =
+ ActivityRepresenter.to_simple_form(note_activity, user, true)
+ |> ActivityRepresenter.wrap_with_entry()
+ |> :xmerl.export_simple(:xmerl_xml)
+ |> to_string
+
+ assert response(conn, 200) == expected
+ end
+
+ test "redirects to /notice/id for html format", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
+ url = "/objects/#{uuid}"
+
+ conn =
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get(url)
+
+ assert redirected_to(conn) == "/notice/#{note_activity.id}"
+ end
+
+ test "500s when user not found", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ User.invalidate_cache(user)
+ Pleroma.Repo.delete(user)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
+ url = "/objects/#{uuid}"
+
+ conn =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get(url)
+
+ assert response(conn, 500) == ~S({"error":"Something went wrong"})
+ end
+
+ test "404s on private objects", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ object = Object.normalize(note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
+
+ conn
+ |> get("/objects/#{uuid}")
+ |> response(404)
+ end
+
+ test "404s on nonexisting objects", %{conn: conn} do
+ conn
+ |> get("/objects/123")
+ |> response(404)
+ end
+ end
+
+ describe "GET activity/2" do
+ test "gets an activity in xml format", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
- conn =
conn
|> put_req_header("accept", "application/xml")
- |> get(url)
+ |> get("/activities/#{uuid}")
+ |> response(200)
+ end
- expected =
- ActivityRepresenter.to_simple_form(note_activity, user, true)
- |> ActivityRepresenter.wrap_with_entry()
- |> :xmerl.export_simple(:xmerl_xml)
- |> to_string
+ test "redirects to /notice/id for html format", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
- assert response(conn, 200) == expected
- end
+ conn =
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/activities/#{uuid}")
- test "404s on private objects", %{conn: conn} do
- note_activity = insert(:direct_note_activity)
- object = Object.normalize(note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
+ assert redirected_to(conn) == "/notice/#{note_activity.id}"
+ end
- conn
- |> get("/objects/#{uuid}")
- |> response(404)
- end
+ test "505s when user not found", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ User.invalidate_cache(user)
+ Pleroma.Repo.delete(user)
- test "404s on nonexisting objects", %{conn: conn} do
- conn
- |> get("/objects/123")
- |> response(404)
- end
+ conn =
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/activities/#{uuid}")
- test "gets an activity in xml format", %{conn: conn} do
- note_activity = insert(:note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
+ assert response(conn, 500) == ~S({"error":"Something went wrong"})
+ end
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/activities/#{uuid}")
- |> response(200)
- end
+ test "404s on deleted objects", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Object.normalize(note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
- test "404s on deleted objects", %{conn: conn} do
- note_activity = insert(:note_activity)
- object = Object.normalize(note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, object.data["id"]))
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/objects/#{uuid}")
+ |> response(200)
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/objects/#{uuid}")
- |> response(200)
+ Object.delete(object)
- Object.delete(object)
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/objects/#{uuid}")
+ |> response(404)
+ end
- conn
- |> put_req_header("accept", "application/xml")
- |> get("/objects/#{uuid}")
- |> response(404)
- end
+ test "404s on private activities", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
- test "404s on private activities", %{conn: conn} do
- note_activity = insert(:direct_note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
+ conn
+ |> get("/activities/#{uuid}")
+ |> response(404)
+ end
- conn
- |> get("/activities/#{uuid}")
- |> response(404)
- end
+ test "404s on nonexistent activities", %{conn: conn} do
+ conn
+ |> get("/activities/123")
+ |> response(404)
+ end
- test "404s on nonexistent activities", %{conn: conn} do
- conn
- |> get("/activities/123")
- |> response(404)
- end
+ test "gets an activity in AS2 format", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
+ url = "/activities/#{uuid}"
- test "gets a notice in xml format", %{conn: conn} do
- note_activity = insert(:note_activity)
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get(url)
- conn
- |> get("/notice/#{note_activity.id}")
- |> response(200)
+ assert json_response(conn, 200)
+ end
end
- test "gets a notice in AS2 format", %{conn: conn} do
- note_activity = insert(:note_activity)
+ describe "GET notice/2" do
+ test "gets a notice in xml format", %{conn: conn} do
+ note_activity = insert(:note_activity)
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get("/notice/#{note_activity.id}")
- |> json_response(200)
- end
+ conn
+ |> get("/notice/#{note_activity.id}")
+ |> response(200)
+ end
- test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
- note_activity = insert(:note_activity)
- url = "/notice/#{note_activity.id}"
+ test "gets a notice in AS2 format", %{conn: conn} do
+ note_activity = insert(:note_activity)
- conn =
conn
|> put_req_header("accept", "application/activity+json")
- |> get(url)
+ |> get("/notice/#{note_activity.id}")
+ |> json_response(200)
+ end
- assert json_response(conn, 200)
+ test "500s when actor not found", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ User.invalidate_cache(user)
+ Pleroma.Repo.delete(user)
- user = insert(:user)
+ conn =
+ conn
+ |> get("/notice/#{note_activity.id}")
- {:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
- url = "/notice/#{like_activity.id}"
+ assert response(conn, 500) == ~S({"error":"Something went wrong"})
+ end
- assert like_activity.data["type"] == "Like"
+ test "only gets a notice in AS2 format for Create messages", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ url = "/notice/#{note_activity.id}"
- conn =
- build_conn()
- |> put_req_header("accept", "application/activity+json")
- |> get(url)
+ conn =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get(url)
- assert response(conn, 404)
- end
+ assert json_response(conn, 200)
- test "gets an activity in AS2 format", %{conn: conn} do
- note_activity = insert(:note_activity)
- [_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["id"]))
- url = "/activities/#{uuid}"
+ user = insert(:user)
- conn =
- conn
- |> put_req_header("accept", "application/activity+json")
- |> get(url)
+ {:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
+ url = "/notice/#{like_activity.id}"
+
+ assert like_activity.data["type"] == "Like"
+
+ conn =
+ build_conn()
+ |> put_req_header("accept", "application/activity+json")
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
+ test "render html for redirect for html format", %{conn: conn} do
+ note_activity = insert(:note_activity)
+
+ resp =
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/notice/#{note_activity.id}")
+ |> response(200)
+
+ assert resp =~
+ ""
+
+ user = insert(:user)
+
+ {:ok, like_activity, _} = CommonAPI.favorite(note_activity.id, user)
+
+ assert like_activity.data["type"] == "Like"
+
+ resp =
+ conn
+ |> put_req_header("accept", "text/html")
+ |> get("/notice/#{like_activity.id}")
+ |> response(200)
+
+ assert resp =~ ""
+ end
+
+ test "404s a private notice", %{conn: conn} do
+ note_activity = insert(:direct_note_activity)
+ url = "/notice/#{note_activity.id}"
+
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
+
+ test "404s a nonexisting notice", %{conn: conn} do
+ url = "/notice/123"
- assert json_response(conn, 200)
+ conn =
+ conn
+ |> get(url)
+
+ assert response(conn, 404)
+ end
end
- test "404s a private notice", %{conn: conn} do
- note_activity = insert(:direct_note_activity)
- url = "/notice/#{note_activity.id}"
+ describe "feed_redirect" do
+ test "undefined format. it redirects to feed", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/users/#{user.nickname}")
+ |> response(302)
+
+ assert response ==
+ "You are being redirected."
+ end
- conn =
- conn
- |> get(url)
+ test "undefined format. it returns error when user not found", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/users/jimm")
+ |> response(404)
- assert response(conn, 404)
+ assert response == ~S({"error":"Not found"})
+ end
+
+ test "activity+json format. it redirects on actual feed of user", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/#{user.nickname}")
+ |> json_response(200)
+
+ assert response["endpoints"] == %{
+ "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
+ "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
+ "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
+ "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox"
+ }
+
+ assert response["@context"] == [
+ "https://www.w3.org/ns/activitystreams",
+ "http://localhost:4001/schemas/litepub-0.1.jsonld",
+ %{"@language" => "und"}
+ ]
+
+ assert Map.take(response, [
+ "followers",
+ "following",
+ "id",
+ "inbox",
+ "manuallyApprovesFollowers",
+ "name",
+ "outbox",
+ "preferredUsername",
+ "summary",
+ "tag",
+ "type",
+ "url"
+ ]) == %{
+ "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
+ "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
+ "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
+ "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
+ "manuallyApprovesFollowers" => false,
+ "name" => user.name,
+ "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
+ "preferredUsername" => user.nickname,
+ "summary" => user.bio,
+ "tag" => [],
+ "type" => "Person",
+ "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
+ }
+ end
+
+ test "activity+json format. it returns error whe use not found", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/users/jimm")
+ |> json_response(404)
+
+ assert response == "Not found"
+ end
+
+ test "json format. it redirects on actual feed of user", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/users/#{user.nickname}")
+ |> json_response(200)
+
+ assert response["endpoints"] == %{
+ "oauthAuthorizationEndpoint" => "#{Pleroma.Web.base_url()}/oauth/authorize",
+ "oauthRegistrationEndpoint" => "#{Pleroma.Web.base_url()}/api/v1/apps",
+ "oauthTokenEndpoint" => "#{Pleroma.Web.base_url()}/oauth/token",
+ "sharedInbox" => "#{Pleroma.Web.base_url()}/inbox"
+ }
+
+ assert response["@context"] == [
+ "https://www.w3.org/ns/activitystreams",
+ "http://localhost:4001/schemas/litepub-0.1.jsonld",
+ %{"@language" => "und"}
+ ]
+
+ assert Map.take(response, [
+ "followers",
+ "following",
+ "id",
+ "inbox",
+ "manuallyApprovesFollowers",
+ "name",
+ "outbox",
+ "preferredUsername",
+ "summary",
+ "tag",
+ "type",
+ "url"
+ ]) == %{
+ "followers" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/followers",
+ "following" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/following",
+ "id" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}",
+ "inbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/inbox",
+ "manuallyApprovesFollowers" => false,
+ "name" => user.name,
+ "outbox" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}/outbox",
+ "preferredUsername" => user.nickname,
+ "summary" => user.bio,
+ "tag" => [],
+ "type" => "Person",
+ "url" => "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
+ }
+ end
+
+ test "json format. it returns error whe use not found", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/users/jimm")
+ |> json_response(404)
+
+ assert response == "Not found"
+ end
+
+ test "html format. it redirects on actual feed of user", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+
+ response =
+ conn
+ |> get("/users/#{user.nickname}")
+ |> response(200)
+
+ assert response ==
+ Fallback.RedirectController.redirector_with_meta(
+ conn,
+ %{user: user}
+ ).resp_body
+ end
+
+ test "html format. it returns error when user not found", %{conn: conn} do
+ response =
+ conn
+ |> get("/users/jimm")
+ |> json_response(404)
+
+ assert response == %{"error" => "Not found"}
+ end
end
- test "404s a nonexisting notice", %{conn: conn} do
- url = "/notice/123"
+ describe "GET /notice/:id/embed_player" do
+ test "render embed player", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Pleroma.Object.normalize(note_activity)
+
+ object_data =
+ Map.put(object.data, "attachment", [
+ %{
+ "url" => [
+ %{
+ "href" =>
+ "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
+ "mediaType" => "video/mp4",
+ "type" => "Link"
+ }
+ ]
+ }
+ ])
+
+ object
+ |> Ecto.Changeset.change(data: object_data)
+ |> Pleroma.Repo.update()
+
+ conn =
+ conn
+ |> get("/notice/#{note_activity.id}/embed_player")
+
+ assert Plug.Conn.get_resp_header(conn, "x-frame-options") == ["ALLOW"]
+
+ assert Plug.Conn.get_resp_header(
+ conn,
+ "content-security-policy"
+ ) == [
+ "default-src 'none';style-src 'self' 'unsafe-inline';img-src 'self' data: https:; media-src 'self' https:;"
+ ]
+
+ assert response(conn, 200) =~
+ ""
+ end
- conn =
- conn
- |> get(url)
+ test "404s when activity isn't create", %{conn: conn} do
+ note_activity = insert(:note_activity, data_attrs: %{"type" => "Like"})
- assert response(conn, 404)
+ assert conn
+ |> get("/notice/#{note_activity.id}/embed_player")
+ |> response(404)
+ end
+
+ test "404s when activity is direct message", %{conn: conn} do
+ note_activity = insert(:note_activity, data_attrs: %{"directMessage" => true})
+
+ assert conn
+ |> get("/notice/#{note_activity.id}/embed_player")
+ |> response(404)
+ end
+
+ test "404s when attachment is empty", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Pleroma.Object.normalize(note_activity)
+ object_data = Map.put(object.data, "attachment", [])
+
+ object
+ |> Ecto.Changeset.change(data: object_data)
+ |> Pleroma.Repo.update()
+
+ assert conn
+ |> get("/notice/#{note_activity.id}/embed_player")
+ |> response(404)
+ end
+
+ test "404s when attachment isn't audio or video", %{conn: conn} do
+ note_activity = insert(:note_activity)
+ object = Pleroma.Object.normalize(note_activity)
+
+ object_data =
+ Map.put(object.data, "attachment", [
+ %{
+ "url" => [
+ %{
+ "href" => "https://peertube.moe/static/webseed/480.jpg",
+ "mediaType" => "image/jpg",
+ "type" => "Link"
+ }
+ ]
+ }
+ ])
+
+ object
+ |> Ecto.Changeset.change(data: object_data)
+ |> Pleroma.Repo.update()
+
+ assert conn
+ |> get("/notice/#{note_activity.id}/embed_player")
+ |> response(404)
+ end
end
end
--
cgit v1.2.3
From c0e258cf21395fa2d5338ee238e4fcf4f3b3bf30 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Mon, 29 Jul 2019 16:17:22 +0000
Subject: Redirect not logged-in users to the MastoFE login page on private
instances
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index d7f92fac2..66016c886 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -3154,6 +3154,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert redirected_to(conn) == "/web/login"
end
+ test "redirects not logged-in users to the login page on private instances", %{
+ conn: conn,
+ path: path
+ } do
+ is_public = Pleroma.Config.get([:instance, :public])
+ Pleroma.Config.put([:instance, :public], false)
+
+ conn = get(conn, path)
+
+ assert conn.status == 302
+ assert redirected_to(conn) == "/web/login"
+
+ Pleroma.Config.put([:instance, :public], is_public)
+ end
+
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
token = insert(:oauth_token)
--
cgit v1.2.3
From 5795a890e9d14a9e51e2613d26620899b2171623 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Mon, 29 Jul 2019 19:09:58 +0000
Subject: markdown: clean up html generated by earmark
---
test/web/common_api/common_api_utils_test.exs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index af320f31f..38b2319ac 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -99,14 +99,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "works for bare text/markdown" do
text = "**hello world**"
- expected = "hello world
\n"
+ expected = "hello world
"
{output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
text = "**hello world**\n\n*another paragraph*"
- expected = "hello world
\nanother paragraph
\n"
+ expected = "hello world
another paragraph
"
{output, [], []} = Utils.format_input(text, "text/markdown")
@@ -118,7 +118,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
by someone
"""
- expected = "cool quote
\n
\nby someone
\n"
+ expected = "cool quote
by someone
"
{output, [], []} = Utils.format_input(text, "text/markdown")
@@ -157,11 +157,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
expected =
- "hello world
\nanother hello world
another @user__test and @user__test google.com paragraph
\n"
+ }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@user__test google.com paragraph
"
{output, _, _} = Utils.format_input(text, "text/markdown")
--
cgit v1.2.3
From 5835069215b880ad261a006cf310da624a82ca4a Mon Sep 17 00:00:00 2001
From: kaniini
Date: Mon, 29 Jul 2019 19:42:26 +0000
Subject: Revert "Merge branch 'bugfix/clean-up-markdown-rendering' into
'develop'"
This reverts merge request !1504
---
test/web/common_api/common_api_utils_test.exs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 38b2319ac..af320f31f 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -99,14 +99,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
test "works for bare text/markdown" do
text = "**hello world**"
- expected = "hello world
"
+ expected = "hello world
\n"
{output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
text = "**hello world**\n\n*another paragraph*"
- expected = "hello world
another paragraph
"
+ expected = "hello world
\nanother paragraph
\n"
{output, [], []} = Utils.format_input(text, "text/markdown")
@@ -118,7 +118,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
by someone
"""
- expected = "cool quote
by someone
"
+ expected = "cool quote
\n
\nby someone
\n"
{output, [], []} = Utils.format_input(text, "text/markdown")
@@ -157,11 +157,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
expected =
- "hello world
another hello world
\nanother @user__test and @user__test google.com paragraph
"
+ }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@user__test google.com paragraph\n"
{output, _, _} = Utils.format_input(text, "text/markdown")
--
cgit v1.2.3
From 51b3b6d8164de9196159dc7de8d5abf0c4fa1bce Mon Sep 17 00:00:00 2001
From: Alexander Strizhakov
Date: Tue, 30 Jul 2019 16:36:05 +0000
Subject: Admin changes
---
test/web/admin_api/admin_api_controller_test.exs | 37 ++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'test/web')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 6dda4ae51..824ad23e6 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1916,6 +1916,43 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
end
+ describe "config mix tasks run" do
+ setup %{conn: conn} do
+ admin = insert(:user, info: %{is_admin: true})
+
+ temp_file = "config/test.exported_from_db.secret.exs"
+
+ on_exit(fn ->
+ :ok = File.rm(temp_file)
+ end)
+
+ dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
+
+ Pleroma.Config.put([:instance, :dynamic_configuration], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
+ end)
+
+ %{conn: assign(conn, :user, admin), admin: admin}
+ end
+
+ test "transfer settings to DB and to file", %{conn: conn, admin: admin} do
+ assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
+ conn = get(conn, "/api/pleroma/admin/config/migrate_to_db")
+ assert json_response(conn, 200) == %{}
+ assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) > 0
+
+ conn =
+ build_conn()
+ |> assign(:user, admin)
+ |> get("/api/pleroma/admin/config/migrate_from_db")
+
+ assert json_response(conn, 200) == %{}
+ assert Pleroma.Repo.all(Pleroma.Web.AdminAPI.Config) == []
+ end
+ end
+
describe "GET /api/pleroma/admin/users/:nickname/statuses" do
setup do
admin = insert(:user, info: %{is_admin: true})
--
cgit v1.2.3
From 7483679a7b6ff63c9c61c3df3e9e37f2c24012ff Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 31 Jul 2019 15:12:29 +0200
Subject: StatusView: Return direct conversation id.
---
test/web/mastodon_api/status_view_test.exs | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 0b167f839..c983b494f 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -23,6 +23,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
:ok
end
+ test "returns the direct conversation id when given the `with_conversation_id` option" do
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
+
+ status =
+ StatusView.render("status.json",
+ activity: activity,
+ with_direct_conversation_id: true,
+ for: user
+ )
+
+ assert status[:pleroma][:direct_conversation_id]
+ end
+
test "returns a temporary ap_id based user for activities missing db users" do
user = insert(:user)
@@ -133,7 +148,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
conversation_id: convo_id,
in_reply_to_account_acct: nil,
content: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["content"])},
- spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])}
+ spoiler_text: %{"text/plain" => HtmlSanitizeEx.strip_tags(object_data["summary"])},
+ direct_conversation_id: nil
}
}
--
cgit v1.2.3
From 58443d0cd683c227199eb34d660191292e487a14 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Wed, 31 Jul 2019 15:14:36 +0000
Subject: tests for TwitterApi/UtilController
---
test/web/twitter_api/util_controller_test.exs | 404 +++++++++++++++++++++++++-
1 file changed, 402 insertions(+), 2 deletions(-)
(limited to 'test/web')
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 3d699e1df..640579c09 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -14,6 +14,17 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
setup do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+
+ instance_config = Pleroma.Config.get([:instance])
+ pleroma_fe = Pleroma.Config.get([:frontend_configurations, :pleroma_fe])
+ deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
+
+ on_exit(fn ->
+ Pleroma.Config.put([:instance], instance_config)
+ Pleroma.Config.put([:frontend_configurations, :pleroma_fe], pleroma_fe)
+ Pleroma.Config.put([:user, :deny_follow_blocked], deny_follow_blocked)
+ end)
+
:ok
end
@@ -31,6 +42,35 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert response == "job started"
end
+ test "it imports follow lists from file", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+
+ with_mocks([
+ {File, [],
+ read!: fn "follow_list.txt" ->
+ "Account address,Show boosts\n#{user2.ap_id},true"
+ end},
+ {PleromaJobQueue, [:passthrough], []}
+ ]) do
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/pleroma/follow_import", %{"list" => %Plug.Upload{path: "follow_list.txt"}})
+ |> json_response(:ok)
+
+ assert called(
+ PleromaJobQueue.enqueue(
+ :background,
+ User,
+ [:follow_import, user1, [user2.ap_id]]
+ )
+ )
+
+ assert response == "job started"
+ end
+ end
+
test "it imports new-style mastodon follow lists", %{conn: conn} do
user1 = insert(:user)
user2 = insert(:user)
@@ -79,6 +119,33 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert response == "job started"
end
+
+ test "it imports blocks users from file", %{conn: conn} do
+ user1 = insert(:user)
+ user2 = insert(:user)
+ user3 = insert(:user)
+
+ with_mocks([
+ {File, [], read!: fn "blocks_list.txt" -> "#{user2.ap_id} #{user3.ap_id}" end},
+ {PleromaJobQueue, [:passthrough], []}
+ ]) do
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/pleroma/blocks_import", %{"list" => %Plug.Upload{path: "blocks_list.txt"}})
+ |> json_response(:ok)
+
+ assert called(
+ PleromaJobQueue.enqueue(
+ :background,
+ User,
+ [:blocks_import, user1, [user2.ap_id, user3.ap_id]]
+ )
+ )
+
+ assert response == "job started"
+ end
+ end
end
describe "POST /api/pleroma/notifications/read" do
@@ -98,6 +165,18 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert Repo.get(Notification, notification1.id).seen
refute Repo.get(Notification, notification2.id).seen
end
+
+ test "it returns error when notification not found", %{conn: conn} do
+ user1 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user1)
+ |> post("/api/pleroma/notifications/read", %{"id" => "22222222222222"})
+ |> json_response(403)
+
+ assert response == %{"error" => "Cannot get notification"}
+ end
end
describe "PUT /api/pleroma/notification_settings" do
@@ -123,7 +202,63 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- describe "GET /api/statusnet/config.json" do
+ describe "GET /api/statusnet/config" do
+ test "it returns config in xml format", %{conn: conn} do
+ instance = Pleroma.Config.get(:instance)
+
+ response =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/api/statusnet/config")
+ |> response(:ok)
+
+ assert response ==
+ "\n\n#{Keyword.get(instance, :name)}\n#{
+ Pleroma.Web.base_url()
+ }\n#{Keyword.get(instance, :limit)}\n#{
+ !Keyword.get(instance, :registrations_open)
+ }\n\n\n"
+ end
+
+ test "it returns config in json format", %{conn: conn} do
+ instance = Pleroma.Config.get(:instance)
+ Pleroma.Config.put([:instance, :managed_config], true)
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ Pleroma.Config.put([:instance, :invites_enabled], true)
+ Pleroma.Config.put([:instance, :public], false)
+ Pleroma.Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
+
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/api/statusnet/config")
+ |> json_response(:ok)
+
+ expected_data = %{
+ "site" => %{
+ "accountActivationRequired" => "0",
+ "closed" => "1",
+ "description" => Keyword.get(instance, :description),
+ "invitesEnabled" => "1",
+ "name" => Keyword.get(instance, :name),
+ "pleromafe" => %{"theme" => "asuka-hospital"},
+ "private" => "1",
+ "safeDMMentionsEnabled" => "0",
+ "server" => Pleroma.Web.base_url(),
+ "textlimit" => to_string(Keyword.get(instance, :limit)),
+ "uploadlimit" => %{
+ "avatarlimit" => to_string(Keyword.get(instance, :avatar_upload_limit)),
+ "backgroundlimit" => to_string(Keyword.get(instance, :background_upload_limit)),
+ "bannerlimit" => to_string(Keyword.get(instance, :banner_upload_limit)),
+ "uploadlimit" => to_string(Keyword.get(instance, :upload_limit))
+ },
+ "vapidPublicKey" => Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
+ }
+ }
+
+ assert response == expected_data
+ end
+
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
option = Pleroma.Config.get([:instance, :safe_dm_mentions])
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
@@ -210,7 +345,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
end
- describe "GET /ostatus_subscribe?acct=...." do
+ describe "GET /ostatus_subscribe - remote_follow/2" do
test "adds status to pleroma instance if the `acct` is a status", %{conn: conn} do
conn =
get(
@@ -230,6 +365,172 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert html_response(response, 200) =~ "Log in to follow"
end
+
+ test "show follow page if the `acct` is a account link", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/ostatus_subscribe?acct=https://mastodon.social/users/emelie")
+
+ assert html_response(response, 200) =~ "Remote follow"
+ end
+
+ test "show follow page with error when user cannot fecth by `acct` link", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> get("/ostatus_subscribe?acct=https://mastodon.social/users/not_found")
+
+ assert html_response(response, 200) =~ "Error fetching user"
+ end
+ end
+
+ describe "POST /ostatus_subscribe - do_remote_follow/2 with assigned user " do
+ test "follows user", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
+ |> response(200)
+
+ assert response =~ "Account followed!"
+ assert user2.follower_address in refresh_record(user).following
+ end
+
+ test "returns error when user is deactivated", %{conn: conn} do
+ user = insert(:user, info: %{deactivated: true})
+ user2 = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
+ |> response(200)
+
+ assert response =~ "Error following account"
+ end
+
+ test "returns error when user is blocked", %{conn: conn} do
+ Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ user = insert(:user)
+ user2 = insert(:user)
+
+ {:ok, _user} = Pleroma.User.block(user2, user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
+ |> response(200)
+
+ assert response =~ "Error following account"
+ end
+
+ test "returns error when followee not found", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/ostatus_subscribe", %{"user" => %{"id" => "jimm"}})
+ |> response(200)
+
+ assert response =~ "Error following account"
+ end
+
+ test "returns success result when user already in followers", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, _, _, _} = CommonAPI.follow(user, user2)
+
+ response =
+ conn
+ |> assign(:user, refresh_record(user))
+ |> post("/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
+ |> response(200)
+
+ assert response =~ "Account followed!"
+ end
+ end
+
+ describe "POST /ostatus_subscribe - do_remote_follow/2 without assigned user " do
+ test "follows", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ response =
+ conn
+ |> post("/ostatus_subscribe", %{
+ "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
+ })
+ |> response(200)
+
+ assert response =~ "Account followed!"
+ assert user2.follower_address in refresh_record(user).following
+ end
+
+ test "returns error when followee not found", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> post("/ostatus_subscribe", %{
+ "authorization" => %{"name" => user.nickname, "password" => "test", "id" => "jimm"}
+ })
+ |> response(200)
+
+ assert response =~ "Error following account"
+ end
+
+ test "returns error when login invalid", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> post("/ostatus_subscribe", %{
+ "authorization" => %{"name" => "jimm", "password" => "test", "id" => user.id}
+ })
+ |> response(200)
+
+ assert response =~ "Wrong username or password"
+ end
+
+ test "returns error when password invalid", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user)
+
+ response =
+ conn
+ |> post("/ostatus_subscribe", %{
+ "authorization" => %{"name" => user.nickname, "password" => "42", "id" => user2.id}
+ })
+ |> response(200)
+
+ assert response =~ "Wrong username or password"
+ end
+
+ test "returns error when user is blocked", %{conn: conn} do
+ Pleroma.Config.put([:user, :deny_follow_blocked], true)
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, _user} = Pleroma.User.block(user2, user)
+
+ response =
+ conn
+ |> post("/ostatus_subscribe", %{
+ "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
+ })
+ |> response(200)
+
+ assert response =~ "Error following account"
+ end
end
describe "GET /api/pleroma/healthcheck" do
@@ -311,5 +612,104 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
assert user.info.deactivated == true
end
+
+ test "it returns returns when password invalid", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> assign(:user, user)
+ |> post("/api/pleroma/disable_account", %{"password" => "test1"})
+ |> json_response(:ok)
+
+ assert response == %{"error" => "Invalid password."}
+ user = User.get_cached_by_id(user.id)
+
+ refute user.info.deactivated
+ end
+ end
+
+ describe "GET /api/statusnet/version" do
+ test "it returns version in xml format", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/xml")
+ |> get("/api/statusnet/version")
+ |> response(:ok)
+
+ assert response == "#{Pleroma.Application.named_version()}"
+ end
+
+ test "it returns version in json format", %{conn: conn} do
+ response =
+ conn
+ |> put_req_header("accept", "application/json")
+ |> get("/api/statusnet/version")
+ |> json_response(:ok)
+
+ assert response == "#{Pleroma.Application.named_version()}"
+ end
+ end
+
+ describe "POST /main/ostatus - remote_subscribe/2" do
+ test "renders subscribe form", %{conn: conn} do
+ user = insert(:user)
+
+ response =
+ conn
+ |> post("/main/ostatus", %{"nickname" => user.nickname, "profile" => ""})
+ |> response(:ok)
+
+ refute response =~ "Could not find user"
+ assert response =~ "Remotely follow #{user.nickname}"
+ end
+
+ test "renders subscribe form with error when user not found", %{conn: conn} do
+ response =
+ conn
+ |> post("/main/ostatus", %{"nickname" => "nickname", "profile" => ""})
+ |> response(:ok)
+
+ assert response =~ "Could not find user"
+ refute response =~ "Remotely follow"
+ end
+
+ test "it redirect to webfinger url", %{conn: conn} do
+ user = insert(:user)
+ user2 = insert(:user, ap_id: "shp@social.heldscal.la")
+
+ conn =
+ conn
+ |> post("/main/ostatus", %{
+ "user" => %{"nickname" => user.nickname, "profile" => user2.ap_id}
+ })
+
+ assert redirected_to(conn) ==
+ "https://social.heldscal.la/main/ostatussub?profile=#{user.ap_id}"
+ end
+
+ test "it renders form with error when use not found", %{conn: conn} do
+ user2 = insert(:user, ap_id: "shp@social.heldscal.la")
+
+ response =
+ conn
+ |> post("/main/ostatus", %{"user" => %{"nickname" => "jimm", "profile" => user2.ap_id}})
+ |> response(:ok)
+
+ assert response =~ "Something went wrong."
+ end
+ end
+
+ test "it returns new captcha", %{conn: conn} do
+ with_mock Pleroma.Captcha,
+ new: fn -> "test_captcha" end do
+ resp =
+ conn
+ |> get("/api/pleroma/captcha")
+ |> response(200)
+
+ assert resp == "\"test_captcha\""
+ assert called(Pleroma.Captcha.new())
+ end
end
end
--
cgit v1.2.3
From 301ea0dc0466371032f44f3e936d1b951ed9784c Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 31 Jul 2019 19:37:55 +0300
Subject: Add tests for counters being updated on follow
---
test/web/activity_pub/activity_pub_test.exs | 20 --------------------
1 file changed, 20 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 853c93ab5..3d9a678dd 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -1149,16 +1149,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"http://localhost:4001/users/masto_closed/followers?page=1" ->
%Tesla.Env{status: 403, body: ""}
- "http://localhost:4001/users/masto_closed/following?page=1" ->
- %Tesla.Env{
- status: 200,
- body:
- Jason.encode!(%{
- "id" => "http://localhost:4001/users/masto_closed/following?page=1",
- "type" => "OrderedCollectionPage"
- })
- }
-
_ ->
apply(HttpRequestMock, :request, [env])
end
@@ -1182,16 +1172,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
"http://localhost:4001/users/masto_closed/following?page=1" ->
%Tesla.Env{status: 403, body: ""}
- "http://localhost:4001/users/masto_closed/followers?page=1" ->
- %Tesla.Env{
- status: 200,
- body:
- Jason.encode!(%{
- "id" => "http://localhost:4001/users/masto_closed/followers?page=1",
- "type" => "OrderedCollectionPage"
- })
- }
-
_ ->
apply(HttpRequestMock, :request, [env])
end
--
cgit v1.2.3
From f72e0b7caddd96da67269552db3102733e4a2581 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Wed, 31 Jul 2019 17:23:16 +0000
Subject: ostatus: explicitly disallow protocol downgrade from activitypub
This closes embargoed bug #1135.
---
test/web/ostatus/ostatus_test.exs | 48 ++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
(limited to 'test/web')
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index 4e8f3a0fc..d244dbcf7 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -426,7 +426,7 @@ defmodule Pleroma.Web.OStatusTest do
}
end
- test "find_make_or_update_user takes an author element and returns an updated user" do
+ test "find_make_or_update_actor takes an author element and returns an updated user" do
uri = "https://social.heldscal.la/user/23211"
{:ok, user} = OStatus.find_or_make_user(uri)
@@ -439,14 +439,56 @@ defmodule Pleroma.Web.OStatusTest do
doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
[author] = :xmerl_xpath.string('//author[1]', doc)
- {:ok, user} = OStatus.find_make_or_update_user(author)
+ {:ok, user} = OStatus.find_make_or_update_actor(author)
assert user.avatar["type"] == "Image"
assert user.name == old_name
assert user.bio == old_bio
- {:ok, user_again} = OStatus.find_make_or_update_user(author)
+ {:ok, user_again} = OStatus.find_make_or_update_actor(author)
assert user_again == user
end
+
+ test "find_or_make_user disallows protocol downgrade" do
+ user = insert(:user, %{local: true})
+ {:ok, user} = OStatus.find_or_make_user(user.ap_id)
+
+ assert User.ap_enabled?(user)
+
+ user =
+ insert(:user, %{
+ ap_id: "https://social.heldscal.la/user/23211",
+ info: %{ap_enabled: true},
+ local: false
+ })
+
+ assert User.ap_enabled?(user)
+
+ {:ok, user} = OStatus.find_or_make_user(user.ap_id)
+ assert User.ap_enabled?(user)
+ end
+
+ test "find_make_or_update_actor disallows protocol downgrade" do
+ user = insert(:user, %{local: true})
+ {:ok, user} = OStatus.find_or_make_user(user.ap_id)
+
+ assert User.ap_enabled?(user)
+
+ user =
+ insert(:user, %{
+ ap_id: "https://social.heldscal.la/user/23211",
+ info: %{ap_enabled: true},
+ local: false
+ })
+
+ assert User.ap_enabled?(user)
+
+ {:ok, user} = OStatus.find_or_make_user(user.ap_id)
+ assert User.ap_enabled?(user)
+
+ doc = XML.parse_document(File.read!("test/fixtures/23211.atom"))
+ [author] = :xmerl_xpath.string('//author[1]', doc)
+ {:error, :invalid_protocol} = OStatus.find_make_or_update_actor(author)
+ end
end
describe "gathering user info from a user id" do
--
cgit v1.2.3
From 6eb33e73035789fd9160e697617feb30a3070589 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Wed, 31 Jul 2019 18:35:15 +0000
Subject: test for Pleroma.Web.CommonAPI.Utils.get_by_id_or_ap_id
---
test/web/common_api/common_api_utils_test.exs | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index af320f31f..4b5666c29 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -360,4 +360,24 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert third_user.ap_id in to
end
end
+
+ describe "get_by_id_or_ap_id/1" do
+ test "get activity by id" do
+ activity = insert(:note_activity)
+ %Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.id)
+ assert note.id == activity.id
+ end
+
+ test "get activity by ap_id" do
+ activity = insert(:note_activity)
+ %Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.data["object"])
+ assert note.id == activity.id
+ end
+
+ test "get activity by object when type isn't `Create` " do
+ activity = insert(:like_activity)
+ %Pleroma.Activity{} = like = Utils.get_by_id_or_ap_id(activity.id)
+ assert like.data["object"] == activity.data["object"]
+ end
+ end
end
--
cgit v1.2.3
From 813c686dd77e6d441c235b2f7a57ac7911e249af Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 31 Jul 2019 22:05:12 +0300
Subject: Disallow following locked accounts over OStatus
---
test/web/ostatus/ostatus_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test/web')
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index d244dbcf7..f8d389020 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -326,6 +326,14 @@ defmodule Pleroma.Web.OStatusTest do
assert User.following?(follower, followed)
end
+ test "refuse following over OStatus if the followed's account is locked" do
+ incoming = File.read!("test/fixtures/follow.xml")
+ _user = insert(:user, info: %{locked: true}, ap_id: "https://pawoo.net/users/pekorino")
+
+ {:ok, [{:error, "It's not possible to follow locked accounts over OStatus"}]} =
+ OStatus.handle_incoming(incoming)
+ end
+
test "handle incoming unfollows with existing follow" do
incoming_follow = File.read!("test/fixtures/follow.xml")
{:ok, [_activity]} = OStatus.handle_incoming(incoming_follow)
--
cgit v1.2.3
From f98235f2adfff290d95c7353c63225c07e5f86ff Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 1 Aug 2019 16:33:36 +0700
Subject: Clean up tests output
---
test/web/admin_api/admin_api_controller_test.exs | 3 +++
1 file changed, 3 insertions(+)
(limited to 'test/web')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index 824ad23e6..f61499a22 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1922,7 +1922,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
temp_file = "config/test.exported_from_db.secret.exs"
+ Mix.shell(Mix.Shell.Quiet)
+
on_exit(fn ->
+ Mix.shell(Mix.Shell.IO)
:ok = File.rm(temp_file)
end)
--
cgit v1.2.3
From 56b1c3af13c9519e13da688bdbbfdd8d69cda4ac Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 2 Aug 2019 15:05:27 +0200
Subject: CommonAPI: Extend api with conversation replies.
---
test/web/common_api/common_api_test.exs | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 16b3f121d..e2a5bf117 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -5,6 +5,7 @@
defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Activity
+ alias Pleroma.Conversation.Participation
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
@@ -12,6 +13,35 @@ defmodule Pleroma.Web.CommonAPITest do
import Pleroma.Factory
+ test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
+ har = insert(:user)
+ jafnhar = insert(:user)
+ tridi = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(har, %{
+ "status" => "@#{jafnhar.nickname} hey",
+ "visibility" => "direct"
+ })
+
+ assert har.ap_id in activity.recipients
+ assert jafnhar.ap_id in activity.recipients
+
+ [participation] = Participation.for_user(har)
+
+ {:ok, activity} =
+ CommonAPI.post(har, %{
+ "status" => "I don't really like @#{tridi.nickname}",
+ "visibility" => "direct",
+ "in_reply_to_status_id" => activity.id,
+ "in_reply_to_conversation_id" => participation.id
+ })
+
+ assert har.ap_id in activity.recipients
+ assert jafnhar.ap_id in activity.recipients
+ refute tridi.ap_id in activity.recipients
+ end
+
test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
har = insert(:user)
jafnhar = insert(:user)
--
cgit v1.2.3
From d93d7779151c811e991e99098e64c1da2c783d68 Mon Sep 17 00:00:00 2001
From: feld
Date: Fri, 2 Aug 2019 17:07:09 +0000
Subject: Fix/mediaproxy whitelist base url
---
.../mastodon_api/mastodon_api_controller_test.exs | 34 -------------
test/web/media_proxy/media_proxy_test.exs | 58 ++++++++++++++--------
2 files changed, 37 insertions(+), 55 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 66016c886..e49c4cc22 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -1671,40 +1671,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
object = Repo.get(Object, media["id"])
assert object.data["actor"] == User.ap_id(conn.assigns[:user])
end
-
- test "returns proxied url when media proxy is enabled", %{conn: conn, image: image} do
- Pleroma.Config.put([Pleroma.Upload, :base_url], "https://media.pleroma.social")
-
- proxy_url = "https://cache.pleroma.social"
- Pleroma.Config.put([:media_proxy, :enabled], true)
- Pleroma.Config.put([:media_proxy, :base_url], proxy_url)
-
- media =
- conn
- |> post("/api/v1/media", %{"file" => image})
- |> json_response(:ok)
-
- assert String.starts_with?(media["url"], proxy_url)
- end
-
- test "returns media url when proxy is enabled but media url is whitelisted", %{
- conn: conn,
- image: image
- } do
- media_url = "https://media.pleroma.social"
- Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
-
- Pleroma.Config.put([:media_proxy, :enabled], true)
- Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
- Pleroma.Config.put([:media_proxy, :whitelist], ["media.pleroma.social"])
-
- media =
- conn
- |> post("/api/v1/media", %{"file" => image})
- |> json_response(:ok)
-
- assert String.starts_with?(media["url"], media_url)
- end
end
describe "locked accounts" do
diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index edbbf9b66..0c94755df 100644
--- a/test/web/media_proxy/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -171,21 +171,6 @@ defmodule Pleroma.Web.MediaProxyTest do
encoded = url(url)
assert decode_result(encoded) == url
end
-
- test "does not change whitelisted urls" do
- upload_config = Pleroma.Config.get([Pleroma.Upload])
- media_url = "https://media.pleroma.social"
- Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
- Pleroma.Config.put([:media_proxy, :whitelist], ["media.pleroma.social"])
- Pleroma.Config.put([:media_proxy, :base_url], "https://cache.pleroma.social")
-
- url = "#{media_url}/static/logo.png"
- encoded = url(url)
-
- assert String.starts_with?(encoded, media_url)
-
- Pleroma.Config.put([Pleroma.Upload], upload_config)
- end
end
describe "when disabled" do
@@ -215,12 +200,43 @@ defmodule Pleroma.Web.MediaProxyTest do
decoded
end
- test "mediaproxy whitelist" do
- Pleroma.Config.put([:media_proxy, :enabled], true)
- Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
- url = "https://feld.me/foo.png"
+ describe "whitelist" do
+ setup do
+ Pleroma.Config.put([:media_proxy, :enabled], true)
+ :ok
+ end
+
+ test "mediaproxy whitelist" do
+ Pleroma.Config.put([:media_proxy, :whitelist], ["google.com", "feld.me"])
+ url = "https://feld.me/foo.png"
+
+ unencoded = url(url)
+ assert unencoded == url
+ 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")
+
+ media_url = "https://mycdn.akamai.com"
- unencoded = url(url)
- assert unencoded == url
+ url = "#{media_url}/static/logo.png"
+ encoded = url(url)
+
+ assert String.starts_with?(encoded, media_url)
+ end
+
+ test "ensure Pleroma.Upload base_url is always whitelisted" do
+ upload_config = Pleroma.Config.get([Pleroma.Upload])
+ media_url = "https://media.pleroma.social"
+ Pleroma.Config.put([Pleroma.Upload, :base_url], media_url)
+
+ url = "#{media_url}/static/logo.png"
+ encoded = url(url)
+
+ assert String.starts_with?(encoded, media_url)
+
+ Pleroma.Config.put([Pleroma.Upload], upload_config)
+ end
end
end
--
cgit v1.2.3
From eee98aaa738c1aa5f2e4203a61b67648d62965c8 Mon Sep 17 00:00:00 2001
From: lain
Date: Fri, 2 Aug 2019 19:53:08 +0200
Subject: Pleroma API: Add endpoint to get conversation statuses.
---
test/web/common_api/common_api_utils_test.exs | 16 ++++----
.../pleroma_api/pleroma_api_controller_test.exs | 45 ++++++++++++++++++++++
2 files changed, 53 insertions(+), 8 deletions(-)
create mode 100644 test/web/pleroma_api/pleroma_api_controller_test.exs
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index af320f31f..7510c8def 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -239,7 +239,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "public", nil)
assert length(to) == 2
assert length(cc) == 1
@@ -256,7 +256,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "public", nil)
assert length(to) == 3
assert length(cc) == 1
@@ -272,7 +272,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "unlisted", nil)
assert length(to) == 2
assert length(cc) == 1
@@ -289,7 +289,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "unlisted", nil)
assert length(to) == 3
assert length(cc) == 1
@@ -305,7 +305,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private", nil)
assert length(to) == 2
assert length(cc) == 0
@@ -321,7 +321,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "private", nil)
assert length(to) == 3
assert length(cc) == 0
@@ -336,7 +336,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentioned_user = insert(:user)
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "direct", nil)
assert length(to) == 1
assert length(cc) == 0
@@ -351,7 +351,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{:ok, activity} = CommonAPI.post(third_user, %{"status" => "uguu"})
mentions = [mentioned_user.ap_id]
- {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct")
+ {to, cc} = Utils.get_to_and_cc(user, mentions, activity, "direct", nil)
assert length(to) == 2
assert length(cc) == 0
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
new file mode 100644
index 000000000..43104e36e
--- /dev/null
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -0,0 +1,45 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Web.CommonAPI
+
+ import Pleroma.Factory
+
+ test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+ third_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ {:ok, activity_two} =
+ CommonAPI.post(other_user, %{
+ "status" => "Hi!",
+ "in_reply_to_status_id" => activity.id,
+ "in_reply_to_conversation_id" => participation.id
+ })
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses")
+ |> json_response(200)
+
+ assert length(result) == 2
+
+ id_one = activity.id
+ id_two = activity_two.id
+ assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
+ end
+end
--
cgit v1.2.3
From 8b2fa31fed1a970c75e077d419dc78be7fc73a93 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Sat, 3 Aug 2019 18:12:38 +0000
Subject: Handle MRF rejections of incoming AP activities
---
test/web/federator_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test/web')
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 6e143eee4..73cfaa8f1 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -229,5 +229,21 @@ defmodule Pleroma.Web.FederatorTest do
:error = Federator.incoming_ap_doc(params)
end
+
+ test "it does not crash if MRF rejects the post" do
+ policies = Pleroma.Config.get([:instance, :rewrite_policy])
+ mrf_keyword_policy = Pleroma.Config.get(:mrf_keyword)
+ Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
+ Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.KeywordPolicy)
+
+ params =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+
+ assert Federator.incoming_ap_doc(params) == :error
+
+ Pleroma.Config.put([:instance, :rewrite_policy], policies)
+ Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
+ end
end
end
--
cgit v1.2.3
From 040347b24820e2773c45a38d4cb6a184d6b14366 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Sat, 3 Aug 2019 18:13:20 +0000
Subject: Remove spaces from the domain search
---
test/web/mastodon_api/search_controller_test.exs | 12 ++++++++++++
1 file changed, 12 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/search_controller_test.exs b/test/web/mastodon_api/search_controller_test.exs
index 043b96c14..49c79ff0a 100644
--- a/test/web/mastodon_api/search_controller_test.exs
+++ b/test/web/mastodon_api/search_controller_test.exs
@@ -95,6 +95,18 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do
assert user_three.nickname in result_ids
end
+
+ test "returns account if query contains a space", %{conn: conn} do
+ user = insert(:user, %{nickname: "shp@shitposter.club"})
+
+ results =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/accounts/search", %{"q" => "shp@shitposter.club xxx "})
+ |> json_response(200)
+
+ assert length(results) == 1
+ end
end
describe ".search" do
--
cgit v1.2.3
From de0f3b73dd7c76b6b19b38804f98f6e7ccba7222 Mon Sep 17 00:00:00 2001
From: Alexander Strizhakov
Date: Sat, 3 Aug 2019 18:16:09 +0000
Subject: Admin fixes
---
test/web/admin_api/admin_api_controller_test.exs | 32 ++++++++++++++++++++++++
1 file changed, 32 insertions(+)
(limited to 'test/web')
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index f61499a22..bcbc18639 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -1914,6 +1914,38 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
]
}
end
+
+ test "delete part of settings by atom subkeys", %{conn: conn} do
+ config =
+ insert(:config,
+ key: "keyaa1",
+ value: :erlang.term_to_binary(subkey1: "val1", subkey2: "val2", subkey3: "val3")
+ )
+
+ conn =
+ post(conn, "/api/pleroma/admin/config", %{
+ configs: [
+ %{
+ group: config.group,
+ key: config.key,
+ subkeys: [":subkey1", ":subkey3"],
+ delete: "true"
+ }
+ ]
+ })
+
+ assert(
+ json_response(conn, 200) == %{
+ "configs" => [
+ %{
+ "group" => "pleroma",
+ "key" => "keyaa1",
+ "value" => [%{"tuple" => [":subkey2", "val2"]}]
+ }
+ ]
+ }
+ )
+ end
end
describe "config mix tasks run" do
--
cgit v1.2.3
From e8ad116c2a5a166613f9609c8fe2559af2b97505 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Sun, 4 Aug 2019 17:13:06 +0000
Subject: Do not add the "next" key to likes.json if there is no more items
---
.../activity_pub/activity_pub_controller_test.exs | 53 ++++++++++++++++++++--
1 file changed, 50 insertions(+), 3 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 40344f17e..251055ee1 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -180,18 +180,65 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
end
describe "/object/:uuid/likes" do
- test "it returns the like activities in a collection", %{conn: conn} do
+ setup do
like = insert(:like_activity)
like_object_ap_id = Object.normalize(like).data["id"]
- uuid = String.split(like_object_ap_id, "/") |> List.last()
+ uuid =
+ like_object_ap_id
+ |> String.split("/")
+ |> List.last()
+
+ [id: like.data["id"], uuid: uuid]
+ end
+
+ test "it returns the like activities in a collection", %{conn: conn, id: id, uuid: uuid} do
result =
conn
|> put_req_header("accept", "application/activity+json")
|> get("/objects/#{uuid}/likes")
|> json_response(200)
- assert List.first(result["first"]["orderedItems"])["id"] == like.data["id"]
+ assert List.first(result["first"]["orderedItems"])["id"] == id
+ assert result["type"] == "OrderedCollection"
+ assert result["totalItems"] == 1
+ refute result["first"]["next"]
+ end
+
+ test "it does not crash when page number is exceeded total pages", %{conn: conn, uuid: uuid} do
+ result =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}/likes?page=2")
+ |> json_response(200)
+
+ assert result["type"] == "OrderedCollectionPage"
+ assert result["totalItems"] == 1
+ refute result["next"]
+ assert Enum.empty?(result["orderedItems"])
+ end
+
+ test "it contains the next key when likes count is more than 10", %{conn: conn} do
+ note = insert(:note_activity)
+ insert_list(11, :like_activity, note_activity: note)
+
+ uuid =
+ note
+ |> Object.normalize()
+ |> Map.get(:data)
+ |> Map.get("id")
+ |> String.split("/")
+ |> List.last()
+
+ result =
+ conn
+ |> put_req_header("accept", "application/activity+json")
+ |> get("/objects/#{uuid}/likes?page=1")
+ |> json_response(200)
+
+ assert result["totalItems"] == 11
+ assert length(result["orderedItems"]) == 10
+ assert result["next"]
end
end
--
cgit v1.2.3
From 3af6d14da769aa5adfdd6360b43c691fd8c8eed5 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 5 Aug 2019 15:09:19 +0200
Subject: Pleroma Conversations API: Add a way to set recipients.
---
test/web/mastodon_api/conversation_view_test.exs | 40 ++++++++++++++++++++++
.../pleroma_api/pleroma_api_controller_test.exs | 31 +++++++++++++++++
2 files changed, 71 insertions(+)
create mode 100644 test/web/mastodon_api/conversation_view_test.exs
(limited to 'test/web')
diff --git a/test/web/mastodon_api/conversation_view_test.exs b/test/web/mastodon_api/conversation_view_test.exs
new file mode 100644
index 000000000..2a4b41fa4
--- /dev/null
+++ b/test/web/mastodon_api/conversation_view_test.exs
@@ -0,0 +1,40 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Conversation.Participation
+ alias Pleroma.Web.MastodonAPI.ConversationView
+
+ import Pleroma.Factory
+
+ test "represents a Mastodon Conversation entity" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}", "visibility" => "direct"})
+
+ [participation] = Participation.for_user_with_last_activity_id(user)
+
+ assert participation
+
+ conversation =
+ ConversationView.render("participation.json", %{participation: participation, user: user})
+
+ assert conversation.id == participation.id |> to_string()
+ assert conversation.last_status.id == activity.id
+
+ assert [account] = conversation.accounts
+ assert account.id == other_user.id
+
+ assert recipients = conversation.pleroma.recipients
+ recipient_ids = recipients |> Enum.map(& &1.id)
+
+ assert user.id in recipient_ids
+ assert other_user.id in recipient_ids
+ end
+end
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
index 43104e36e..7989defe0 100644
--- a/test/web/pleroma_api/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
alias Pleroma.Conversation.Participation
alias Pleroma.Web.CommonAPI
+ alias Pleroma.Repo
import Pleroma.Factory
@@ -42,4 +43,34 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
id_two = activity_two.id
assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result
end
+
+ test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ participation = Repo.preload(participation, :recipients)
+
+ assert [user] == participation.recipients
+ assert other_user not in participation.recipients
+
+ result =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{
+ "recipients" => [user.id, other_user.id]
+ })
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string
+
+ assert recipients = result["pleroma"]["recipients"]
+ recipient_ids = Enum.map(recipients, & &1["id"])
+
+ assert user.id in recipient_ids
+ assert other_user.id in recipient_ids
+ end
end
--
cgit v1.2.3
From b64b6fee2a78fbfbc557b89550128494ca7d2894 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 5 Aug 2019 15:33:22 +0200
Subject: CommonAPI: Replies to conversations also get the correct context id.
---
test/web/common_api/common_api_test.exs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index e2a5bf117..454523349 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -9,10 +9,25 @@ defmodule Pleroma.Web.CommonAPITest do
alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
+ test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(user)
+
+ {:ok, convo_reply} =
+ CommonAPI.post(user, %{"status" => ".", "in_reply_to_conversation_id" => participation.id})
+
+ assert Visibility.is_direct?(convo_reply)
+
+ assert activity.data["context"] == convo_reply.data["context"]
+ end
+
test "when replying to a conversation / participation, it only mentions the recipients explicitly declared in the participation" do
har = insert(:user)
jafnhar = insert(:user)
--
cgit v1.2.3
From d6fe220e32d581220cc33f4f44d6517a401eabbf Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 5 Aug 2019 16:11:23 +0200
Subject: Linting.
---
test/web/mastodon_api/conversation_view_test.exs | 2 +-
test/web/pleroma_api/pleroma_api_controller_test.exs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/conversation_view_test.exs b/test/web/mastodon_api/conversation_view_test.exs
index 2a4b41fa4..e32cde5a8 100644
--- a/test/web/mastodon_api/conversation_view_test.exs
+++ b/test/web/mastodon_api/conversation_view_test.exs
@@ -5,8 +5,8 @@
defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
use Pleroma.DataCase
- alias Pleroma.Web.CommonAPI
alias Pleroma.Conversation.Participation
+ alias Pleroma.Web.CommonAPI
alias Pleroma.Web.MastodonAPI.ConversationView
import Pleroma.Factory
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
index 7989defe0..7c75fb229 100644
--- a/test/web/pleroma_api/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -6,8 +6,8 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
use Pleroma.Web.ConnCase
alias Pleroma.Conversation.Participation
- alias Pleroma.Web.CommonAPI
alias Pleroma.Repo
+ alias Pleroma.Web.CommonAPI
import Pleroma.Factory
--
cgit v1.2.3
From bdc9a7222cca9988a238cbe76d0e51125a016f8d Mon Sep 17 00:00:00 2001
From: Maksim
Date: Mon, 5 Aug 2019 15:37:05 +0000
Subject: tests for CommonApi/Utils
---
test/web/common_api/common_api_utils_test.exs | 219 +++++++++++++++++++++++++-
1 file changed, 218 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 4b5666c29..5989d7d29 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -306,7 +306,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
mentions = [mentioned_user.ap_id]
{to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private")
-
assert length(to) == 2
assert length(cc) == 0
@@ -380,4 +379,222 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert like.data["object"] == activity.data["object"]
end
end
+
+ describe "to_master_date/1" do
+ test "removes microseconds from date (NaiveDateTime)" do
+ assert Utils.to_masto_date(~N[2015-01-23 23:50:07.123]) == "2015-01-23T23:50:07.000Z"
+ end
+
+ test "removes microseconds from date (String)" do
+ assert Utils.to_masto_date("2015-01-23T23:50:07.123Z") == "2015-01-23T23:50:07.000Z"
+ end
+
+ test "returns empty string when date invalid" do
+ assert Utils.to_masto_date("2015-01?23T23:50:07.123Z") == ""
+ end
+ end
+
+ describe "conversation_id_to_context/1" do
+ test "returns id" do
+ object = insert(:note)
+ assert Utils.conversation_id_to_context(object.id) == object.data["id"]
+ end
+
+ test "returns error if object not found" do
+ assert Utils.conversation_id_to_context("123") == {:error, "No such conversation"}
+ end
+ end
+
+ describe "maybe_notify_mentioned_recipients/2" do
+ test "returns recipients when activity is not `Create`" do
+ activity = insert(:like_activity)
+ assert Utils.maybe_notify_mentioned_recipients(["test"], activity) == ["test"]
+ end
+
+ test "returns recipients from tag" do
+ user = insert(:user)
+
+ object =
+ insert(:note,
+ user: user,
+ data: %{
+ "tag" => [
+ %{"type" => "Hashtag"},
+ "",
+ %{"type" => "Mention", "href" => "https://testing.pleroma.lol/users/lain"},
+ %{"type" => "Mention", "href" => "https://shitposter.club/user/5381"},
+ %{"type" => "Mention", "href" => "https://shitposter.club/user/5381"}
+ ]
+ }
+ )
+
+ activity = insert(:note_activity, user: user, note: object)
+
+ assert Utils.maybe_notify_mentioned_recipients(["test"], activity) == [
+ "test",
+ "https://testing.pleroma.lol/users/lain",
+ "https://shitposter.club/user/5381"
+ ]
+ end
+
+ test "returns recipients when object is map" do
+ user = insert(:user)
+ object = insert(:note, user: user)
+
+ activity =
+ insert(:note_activity,
+ user: user,
+ note: object,
+ data_attrs: %{
+ "object" => %{
+ "tag" => [
+ %{"type" => "Hashtag"},
+ "",
+ %{"type" => "Mention", "href" => "https://testing.pleroma.lol/users/lain"},
+ %{"type" => "Mention", "href" => "https://shitposter.club/user/5381"},
+ %{"type" => "Mention", "href" => "https://shitposter.club/user/5381"}
+ ]
+ }
+ }
+ )
+
+ Pleroma.Repo.delete(object)
+
+ assert Utils.maybe_notify_mentioned_recipients(["test"], activity) == [
+ "test",
+ "https://testing.pleroma.lol/users/lain",
+ "https://shitposter.club/user/5381"
+ ]
+ end
+
+ test "returns recipients when object not found" do
+ user = insert(:user)
+ object = insert(:note, user: user)
+
+ activity = insert(:note_activity, user: user, note: object)
+ Pleroma.Repo.delete(object)
+
+ assert Utils.maybe_notify_mentioned_recipients(["test-test"], activity) == [
+ "test-test"
+ ]
+ end
+ end
+
+ describe "attachments_from_ids_descs/2" do
+ test "returns [] when attachment ids is empty" do
+ assert Utils.attachments_from_ids_descs([], "{}") == []
+ end
+
+ test "returns list attachments with desc" do
+ object = insert(:note)
+ desc = Jason.encode!(%{object.id => "test-desc"})
+
+ assert Utils.attachments_from_ids_descs(["#{object.id}", "34"], desc) == [
+ Map.merge(object.data, %{"name" => "test-desc"})
+ ]
+ end
+ end
+
+ describe "attachments_from_ids/1" do
+ test "returns attachments with descs" do
+ object = insert(:note)
+ desc = Jason.encode!(%{object.id => "test-desc"})
+
+ assert Utils.attachments_from_ids(%{
+ "media_ids" => ["#{object.id}"],
+ "descriptions" => desc
+ }) == [
+ Map.merge(object.data, %{"name" => "test-desc"})
+ ]
+ end
+
+ test "returns attachments without descs" do
+ object = insert(:note)
+ assert Utils.attachments_from_ids(%{"media_ids" => ["#{object.id}"]}) == [object.data]
+ end
+
+ test "returns [] when not pass media_ids" do
+ assert Utils.attachments_from_ids(%{}) == []
+ end
+ end
+
+ describe "maybe_add_list_data/3" do
+ test "adds list params when found user list" do
+ user = insert(:user)
+ {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", user)
+
+ assert Utils.maybe_add_list_data(%{additional: %{}, object: %{}}, user, {:list, list.id}) ==
+ %{
+ additional: %{"bcc" => [list.ap_id], "listMessage" => list.ap_id},
+ object: %{"listMessage" => list.ap_id}
+ }
+ end
+
+ test "returns original params when list not found" do
+ user = insert(:user)
+ {:ok, %Pleroma.List{} = list} = Pleroma.List.create("title", insert(:user))
+
+ assert Utils.maybe_add_list_data(%{additional: %{}, object: %{}}, user, {:list, list.id}) ==
+ %{additional: %{}, object: %{}}
+ end
+ end
+
+ describe "make_note_data/11" do
+ test "returns note data" do
+ user = insert(:user)
+ note = insert(:note)
+ user2 = insert(:user)
+ user3 = insert(:user)
+
+ assert Utils.make_note_data(
+ user.ap_id,
+ [user2.ap_id],
+ "2hu",
+ "This is :moominmamma: note
",
+ [],
+ note.id,
+ [name: "jimm"],
+ "test summary",
+ [user3.ap_id],
+ false,
+ %{"custom_tag" => "test"}
+ ) == %{
+ "actor" => user.ap_id,
+ "attachment" => [],
+ "cc" => [user3.ap_id],
+ "content" => "This is :moominmamma: note
",
+ "context" => "2hu",
+ "sensitive" => false,
+ "summary" => "test summary",
+ "tag" => ["jimm"],
+ "to" => [user2.ap_id],
+ "type" => "Note",
+ "custom_tag" => "test"
+ }
+ end
+ end
+
+ describe "maybe_add_attachments/3" do
+ test "returns parsed results when no_links is true" do
+ assert Utils.maybe_add_attachments(
+ {"test", [], ["tags"]},
+ [],
+ true
+ ) == {"test", [], ["tags"]}
+ end
+
+ test "adds attachments to parsed results" do
+ attachment = %{"url" => [%{"href" => "SakuraPM.png"}]}
+
+ assert Utils.maybe_add_attachments(
+ {"test", [], ["tags"]},
+ [attachment],
+ false
+ ) == {
+ "test
SakuraPM.png",
+ [],
+ ["tags"]
+ }
+ end
+ end
end
--
cgit v1.2.3
From 139b196bc0328d812adb9434b2da97265d57257d Mon Sep 17 00:00:00 2001
From: Maksim
Date: Tue, 6 Aug 2019 20:19:28 +0000
Subject: [#1150] fixed parser TwitterCard
---
test/web/rich_media/parsers/twitter_card_test.exs | 69 +++++++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 test/web/rich_media/parsers/twitter_card_test.exs
(limited to 'test/web')
diff --git a/test/web/rich_media/parsers/twitter_card_test.exs b/test/web/rich_media/parsers/twitter_card_test.exs
new file mode 100644
index 000000000..f8e1c9b40
--- /dev/null
+++ b/test/web/rich_media/parsers/twitter_card_test.exs
@@ -0,0 +1,69 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.RichMedia.Parsers.TwitterCardTest do
+ use ExUnit.Case, async: true
+ alias Pleroma.Web.RichMedia.Parsers.TwitterCard
+
+ test "returns error when html not contains twitter card" do
+ assert TwitterCard.parse("", %{}) == {:error, "No twitter card metadata found"}
+ end
+
+ test "parses twitter card with only name attributes" do
+ html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers3.html")
+
+ assert TwitterCard.parse(html, %{}) ==
+ {:ok,
+ %{
+ "app:id:googleplay": "com.nytimes.android",
+ "app:name:googleplay": "NYTimes",
+ "app:url:googleplay": "nytimes://reader/id/100000006583622",
+ site: nil,
+ title:
+ "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database. - The New York Times"
+ }}
+ end
+
+ test "parses twitter card with only property attributes" do
+ html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers2.html")
+
+ assert TwitterCard.parse(html, %{}) ==
+ {:ok,
+ %{
+ card: "summary_large_image",
+ description:
+ "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
+ image:
+ "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
+ "image:alt": "",
+ title:
+ "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
+ url:
+ "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
+ }}
+ end
+
+ test "parses twitter card with name & property attributes" do
+ html = File.read!("test/fixtures/nypd-facial-recognition-children-teenagers.html")
+
+ assert TwitterCard.parse(html, %{}) ==
+ {:ok,
+ %{
+ "app:id:googleplay": "com.nytimes.android",
+ "app:name:googleplay": "NYTimes",
+ "app:url:googleplay": "nytimes://reader/id/100000006583622",
+ card: "summary_large_image",
+ description:
+ "With little oversight, the N.Y.P.D. has been using powerful surveillance technology on photos of children and teenagers.",
+ image:
+ "https://static01.nyt.com/images/2019/08/01/nyregion/01nypd-juveniles-promo/01nypd-juveniles-promo-videoSixteenByNineJumbo1600.jpg",
+ "image:alt": "",
+ site: nil,
+ title:
+ "She Was Arrested at 14. Then Her Photo Went to a Facial Recognition Database.",
+ url:
+ "https://www.nytimes.com/2019/08/01/nyregion/nypd-facial-recognition-children-teenagers.html"
+ }}
+ end
+end
--
cgit v1.2.3
From 32018a4ee0fab43fc0982e6428d3fb93e5ac3c47 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 7 Aug 2019 00:36:13 +0300
Subject: ActivityPub tests: remove assertions of embedded object being
updated, because the objects are no longer supposed to be embedded
---
test/web/activity_pub/activity_pub_test.exs | 6 ------
1 file changed, 6 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 3d9a678dd..d723f331f 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -677,14 +677,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert object.data["likes"] == [user.ap_id]
assert object.data["like_count"] == 1
- [note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
- assert note_activity.data["object"]["like_count"] == 1
-
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
assert object.data["like_count"] == 2
-
- [note_activity] = Activity.get_all_create_by_object_ap_id(object.data["id"])
- assert note_activity.data["object"]["like_count"] == 2
end
end
--
cgit v1.2.3
From 5329e84d62bbdf87a4b66e2ba9302a840802416f Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Wed, 7 Aug 2019 00:58:48 +0300
Subject: OStatus tests: stop relying on embedded objects
---
test/web/ostatus/ostatus_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs
index f8d389020..803a97695 100644
--- a/test/web/ostatus/ostatus_test.exs
+++ b/test/web/ostatus/ostatus_test.exs
@@ -199,7 +199,7 @@ defmodule Pleroma.Web.OStatusTest do
assert retweeted_activity.data["type"] == "Create"
assert retweeted_activity.data["actor"] == user.ap_id
assert retweeted_activity.local
- assert retweeted_activity.data["object"]["announcement_count"] == 1
+ assert Object.normalize(retweeted_activity).data["announcement_count"] == 1
end
test "handle incoming retweets - Mastodon, salmon" do
--
cgit v1.2.3
From 409bcad54b5de631536761952faed05ad5fe3b99 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Fri, 9 Aug 2019 16:49:09 +0300
Subject: Mastodon API: Set follower/following counters to 0 when hiding
followers/following is enabled
We are already doing that in AP representation, so I think we should do
it here as well for consistency.
---
test/web/mastodon_api/account_view_test.exs | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index 905e9af98..a26f514a5 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -356,4 +356,31 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
result = AccountView.render("account.json", %{user: user})
refute result.display_name == ""
end
+
+ describe "hiding follows/following" do
+ test "shows when follows/following are hidden and sets follower/following count to 0" do
+ user = insert(:user, info: %{hide_followers: true, hide_follows: true})
+ other_user = insert(:user)
+ {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{
+ followers_count: 0,
+ following_count: 0,
+ pleroma: %{hide_follows: true, hide_followers: true}
+ } = AccountView.render("account.json", %{user: user})
+ end
+
+ test "shows actual follower/following count to the account owner" do
+ user = insert(:user, info: %{hide_followers: true, hide_follows: true})
+ other_user = insert(:user)
+ {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
+ {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
+
+ assert %{
+ followers_count: 1,
+ following_count: 1
+ } = AccountView.render("account.json", %{user: user, for: user})
+ end
+ end
end
--
cgit v1.2.3
From 0802a08871afee7f09362cbca8b802f0e27ff4b9 Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Sat, 10 Aug 2019 16:27:46 +0300
Subject: Mastodon API: Fix thread mute detection
It was calling CommonAPI.thread_muted? with post author's account
instead of viewer's one.
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index e49c4cc22..b023d1e4f 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2901,8 +2901,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "conversation muting" do
setup do
+ post_user = insert(:user)
user = insert(:user)
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HIE"})
+
+ {:ok, activity} = CommonAPI.post(post_user, %{"status" => "HIE"})
[user: user, activity: activity]
end
--
cgit v1.2.3
From af4cf35e2096a6d1660271f6935b6b9ce77c6757 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Sat, 10 Aug 2019 18:47:40 +0000
Subject: Strip internal fields including likes from incoming and outgoing
activities
---
test/web/activity_pub/transmogrifier_test.exs | 30 ++++++++++++++++++++-------
1 file changed, 22 insertions(+), 8 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index e7498e005..060b91e29 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -450,6 +450,27 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert !is_nil(data["cc"])
end
+ test "it strips internal likes" do
+ data =
+ File.read!("test/fixtures/mastodon-post-activity.json")
+ |> Poison.decode!()
+
+ likes = %{
+ "first" =>
+ "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes?page=1",
+ "id" => "http://mastodon.example.org/objects/dbdbc507-52c8-490d-9b7c-1e1d52e5c132/likes",
+ "totalItems" => 3,
+ "type" => "OrderedCollection"
+ }
+
+ object = Map.put(data["object"], "likes", likes)
+ data = Map.put(data, "object", object)
+
+ {:ok, %Activity{object: object}} = Transmogrifier.handle_incoming(data)
+
+ refute Map.has_key?(object.data, "likes")
+ end
+
test "it works for incoming update activities" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
@@ -1061,14 +1082,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert is_nil(modified["object"]["announcements"])
assert is_nil(modified["object"]["announcement_count"])
assert is_nil(modified["object"]["context_id"])
- end
-
- test "it adds like collection to object" do
- activity = insert(:note_activity)
- {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
-
- assert modified["object"]["likes"]["type"] == "OrderedCollection"
- assert modified["object"]["likes"]["totalItems"] == 0
+ assert is_nil(modified["object"]["likes"])
end
test "the directMessage flag is present" do
--
cgit v1.2.3
From 9cfc289594c1d2a1b53c99e3e72bba4b6dc615ca Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sat, 10 Aug 2019 21:18:26 +0000
Subject: MRF: ensure that subdomain_match calls are case-insensitive
---
test/web/activity_pub/mrf/mrf_test.exs | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/mrf/mrf_test.exs b/test/web/activity_pub/mrf/mrf_test.exs
index a9cdf5317..1a888e18f 100644
--- a/test/web/activity_pub/mrf/mrf_test.exs
+++ b/test/web/activity_pub/mrf/mrf_test.exs
@@ -4,8 +4,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "subdomains_regex/1" do
assert MRF.subdomains_regex(["unsafe.tld", "*.unsafe.tld"]) == [
- ~r/^unsafe.tld$/,
- ~r/^(.*\.)*unsafe.tld$/
+ ~r/^unsafe.tld$/i,
+ ~r/^(.*\.)*unsafe.tld$/i
]
end
@@ -13,7 +13,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "common domains" do
regexes = MRF.subdomains_regex(["unsafe.tld", "unsafe2.tld"])
- assert regexes == [~r/^unsafe.tld$/, ~r/^unsafe2.tld$/]
+ assert regexes == [~r/^unsafe.tld$/i, ~r/^unsafe2.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "unsafe2.tld")
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "wildcard domains with one subdomain" do
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
- assert regexes == [~r/^(.*\.)*unsafe.tld$/]
+ assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "sub.unsafe.tld")
@@ -35,12 +35,26 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
test "wildcard domains with two subdomains" do
regexes = MRF.subdomains_regex(["*.unsafe.tld"])
- assert regexes == [~r/^(.*\.)*unsafe.tld$/]
+ assert regexes == [~r/^(.*\.)*unsafe.tld$/i]
assert MRF.subdomain_match?(regexes, "unsafe.tld")
assert MRF.subdomain_match?(regexes, "sub.sub.unsafe.tld")
refute MRF.subdomain_match?(regexes, "sub.anotherunsafe.tld")
refute MRF.subdomain_match?(regexes, "sub.unsafe.tldanother")
end
+
+ test "matches are case-insensitive" do
+ regexes = MRF.subdomains_regex(["UnSafe.TLD", "UnSAFE2.Tld"])
+
+ assert regexes == [~r/^UnSafe.TLD$/i, ~r/^UnSAFE2.Tld$/i]
+
+ assert MRF.subdomain_match?(regexes, "UNSAFE.TLD")
+ assert MRF.subdomain_match?(regexes, "UNSAFE2.TLD")
+ assert MRF.subdomain_match?(regexes, "unsafe.tld")
+ assert MRF.subdomain_match?(regexes, "unsafe2.tld")
+
+ refute MRF.subdomain_match?(regexes, "EXAMPLE.COM")
+ refute MRF.subdomain_match?(regexes, "example.com")
+ end
end
end
--
cgit v1.2.3
From 23c46f7e72701b773d87b825526450e5f4ec6322 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 12 Aug 2019 12:51:08 +0200
Subject: Conversations: Use 'recipients' for accounts in conversation view.
According to gargron, this is the intended usage.
---
test/web/mastodon_api/conversation_view_test.exs | 6 ------
test/web/pleroma_api/pleroma_api_controller_test.exs | 8 ++++----
2 files changed, 4 insertions(+), 10 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/conversation_view_test.exs b/test/web/mastodon_api/conversation_view_test.exs
index e32cde5a8..27f668d9f 100644
--- a/test/web/mastodon_api/conversation_view_test.exs
+++ b/test/web/mastodon_api/conversation_view_test.exs
@@ -30,11 +30,5 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
assert [account] = conversation.accounts
assert account.id == other_user.id
-
- assert recipients = conversation.pleroma.recipients
- recipient_ids = recipients |> Enum.map(& &1.id)
-
- assert user.id in recipient_ids
- assert other_user.id in recipient_ids
end
end
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
index 7c75fb229..56bc1572c 100644
--- a/test/web/pleroma_api/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -67,10 +67,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
assert result["id"] == participation.id |> to_string
- assert recipients = result["pleroma"]["recipients"]
- recipient_ids = Enum.map(recipients, & &1["id"])
+ [participation] = Participation.for_user(user)
+ participation = Repo.preload(participation, :recipients)
- assert user.id in recipient_ids
- assert other_user.id in recipient_ids
+ assert user in participation.recipients
+ assert other_user in participation.recipients
end
end
--
cgit v1.2.3
From 60231ec7bd0af993dc19f69a57b261b3b4167636 Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 12 Aug 2019 13:58:04 +0200
Subject: Conversation: Add endpoint to get a conversation by id.
---
test/web/pleroma_api/pleroma_api_controller_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test/web')
diff --git a/test/web/pleroma_api/pleroma_api_controller_test.exs b/test/web/pleroma_api/pleroma_api_controller_test.exs
index 56bc1572c..ed6b79727 100644
--- a/test/web/pleroma_api/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/pleroma_api_controller_test.exs
@@ -11,6 +11,24 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
import Pleroma.Factory
+ test "/api/v1/pleroma/conversations/:id", %{conn: conn} do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"})
+
+ [participation] = Participation.for_user(other_user)
+
+ result =
+ conn
+ |> assign(:user, other_user)
+ |> get("/api/v1/pleroma/conversations/#{participation.id}")
+ |> json_response(200)
+
+ assert result["id"] == participation.id |> to_string()
+ end
+
test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
--
cgit v1.2.3
From 511ccea5aa36b4b0098e49b409b335b0ce8f042e Mon Sep 17 00:00:00 2001
From: lain
Date: Mon, 12 Aug 2019 14:23:06 +0200
Subject: ConversationView: Align parameter names with other views.
---
test/web/mastodon_api/conversation_view_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/conversation_view_test.exs b/test/web/mastodon_api/conversation_view_test.exs
index 27f668d9f..a2a880705 100644
--- a/test/web/mastodon_api/conversation_view_test.exs
+++ b/test/web/mastodon_api/conversation_view_test.exs
@@ -23,7 +23,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
assert participation
conversation =
- ConversationView.render("participation.json", %{participation: participation, user: user})
+ ConversationView.render("participation.json", %{participation: participation, for: user})
assert conversation.id == participation.id |> to_string()
assert conversation.last_status.id == activity.id
--
cgit v1.2.3
From f7e3b7ff752f0285bea8eb92e83cf1a5cc0e05a0 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Tue, 13 Aug 2019 20:55:13 +0000
Subject: tests: add tests for mrf_vocabulary
---
.../activity_pub/mrf/vocabulary_policy_test.exs | 123 +++++++++++++++++++++
1 file changed, 123 insertions(+)
create mode 100644 test/web/activity_pub/mrf/vocabulary_policy_test.exs
(limited to 'test/web')
diff --git a/test/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
new file mode 100644
index 000000000..c3b11d7a1
--- /dev/null
+++ b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
@@ -0,0 +1,123 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
+
+ describe "accept" do
+ test "it accepts based on parent activity type" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :accept])
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
+
+ message = %{
+ "type" => "Like",
+ "object" => "whatever"
+ }
+
+ {:ok, ^message} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :accept], config)
+ end
+
+ test "it accepts based on child object type" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :accept])
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "whatever"
+ }
+ }
+
+ {:ok, ^message} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :accept], config)
+ end
+
+ test "it does not accept disallowed child objects" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :accept])
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Article",
+ "content" => "whatever"
+ }
+ }
+
+ {:reject, nil} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :accept], config)
+ end
+
+ test "it does not accept disallowed parent types" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :accept])
+ Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "whatever"
+ }
+ }
+
+ {:reject, nil} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :accept], config)
+ end
+ end
+
+ describe "reject" do
+ test "it rejects based on parent activity type" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :reject])
+ Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+
+ message = %{
+ "type" => "Like",
+ "object" => "whatever"
+ }
+
+ {:reject, nil} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :reject], config)
+ end
+
+ test "it rejects based on child object type" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :reject])
+ Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
+
+ message = %{
+ "type" => "Create",
+ "object" => %{
+ "type" => "Note",
+ "content" => "whatever"
+ }
+ }
+
+ {:reject, nil} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :reject], config)
+ end
+
+ test "it passes through objects that aren't disallowed" do
+ config = Pleroma.Config.get([:mrf_vocabulary, :reject])
+ Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
+
+ message = %{
+ "type" => "Announce",
+ "object" => "whatever"
+ }
+
+ {:ok, ^message} = VocabularyPolicy.filter(message)
+
+ Pleroma.Config.put([:mrf_vocabulary, :reject], config)
+ end
+ end
+end
--
cgit v1.2.3
From 04da1166db3db5b03da7dbb048e40840a6e6279f Mon Sep 17 00:00:00 2001
From: Maksim
Date: Tue, 13 Aug 2019 21:12:37 +0000
Subject: tests for /web/mastodon_api/mastodon_api.ex
---
.../mastodon_api/mastodon_api_controller_test.exs | 137 ++++++++++++++++-----
test/web/mastodon_api/mastodon_api_test.exs | 103 ++++++++++++++++
2 files changed, 212 insertions(+), 28 deletions(-)
create mode 100644 test/web/mastodon_api/mastodon_api_test.exs
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index b023d1e4f..2febe8b3a 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
alias Ecto.Changeset
alias Pleroma.Activity
+ alias Pleroma.Config
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Repo
@@ -85,11 +86,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "the public timeline when public is set to false", %{conn: conn} do
- public = Pleroma.Config.get([:instance, :public])
- Pleroma.Config.put([:instance, :public], false)
+ public = Config.get([:instance, :public])
+ Config.put([:instance, :public], false)
on_exit(fn ->
- Pleroma.Config.put([:instance, :public], public)
+ Config.put([:instance, :public], public)
end)
assert conn
@@ -250,7 +251,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "posting a status with OGP link preview", %{conn: conn} do
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
conn =
conn
@@ -260,7 +261,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
assert Activity.get_by_id(id)
- Pleroma.Config.put([:rich_media, :enabled], false)
+ Config.put([:rich_media, :enabled], false)
end
test "posting a direct status", %{conn: conn} do
@@ -304,7 +305,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "option limit is enforced", %{conn: conn} do
user = insert(:user)
- limit = Pleroma.Config.get([:instance, :poll_limits, :max_options])
+ limit = Config.get([:instance, :poll_limits, :max_options])
conn =
conn
@@ -320,7 +321,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "option character limit is enforced", %{conn: conn} do
user = insert(:user)
- limit = Pleroma.Config.get([:instance, :poll_limits, :max_option_chars])
+ limit = Config.get([:instance, :poll_limits, :max_option_chars])
conn =
conn
@@ -339,7 +340,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "minimal date limit is enforced", %{conn: conn} do
user = insert(:user)
- limit = Pleroma.Config.get([:instance, :poll_limits, :min_expiration])
+ limit = Config.get([:instance, :poll_limits, :min_expiration])
conn =
conn
@@ -358,7 +359,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
test "maximum date limit is enforced", %{conn: conn} do
user = insert(:user)
- limit = Pleroma.Config.get([:instance, :poll_limits, :max_expiration])
+ limit = Config.get([:instance, :poll_limits, :max_expiration])
conn =
conn
@@ -1633,12 +1634,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "media upload" do
setup do
- upload_config = Pleroma.Config.get([Pleroma.Upload])
- proxy_config = Pleroma.Config.get([:media_proxy])
+ upload_config = Config.get([Pleroma.Upload])
+ proxy_config = Config.get([:media_proxy])
on_exit(fn ->
- Pleroma.Config.put([Pleroma.Upload], upload_config)
- Pleroma.Config.put([:media_proxy], proxy_config)
+ Config.put([Pleroma.Upload], upload_config)
+ Config.put([:media_proxy], proxy_config)
end)
user = insert(:user)
@@ -2581,7 +2582,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn = get(conn, "/api/v1/instance")
assert result = json_response(conn, 200)
- email = Pleroma.Config.get([:instance, :email])
+ email = Config.get([:instance, :email])
# Note: not checking for "max_toot_chars" since it's optional
assert %{
"uri" => _,
@@ -2666,7 +2667,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "pinned statuses" do
setup do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -2766,10 +2767,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "cards" do
setup do
- Pleroma.Config.put([:rich_media, :enabled], true)
+ Config.put([:rich_media, :enabled], true)
on_exit(fn ->
- Pleroma.Config.put([:rich_media, :enabled], false)
+ Config.put([:rich_media, :enabled], false)
end)
user = insert(:user)
@@ -2997,7 +2998,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
reporter: reporter,
target_user: target_user
} do
- max_size = Pleroma.Config.get([:instance, :max_report_comment_size], 1000)
+ max_size = Config.get([:instance, :max_report_comment_size], 1000)
comment = String.pad_trailing("a", max_size + 1, "a")
error = %{"error" => "Comment must be up to #{max_size} characters"}
@@ -3126,15 +3127,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn: conn,
path: path
} do
- is_public = Pleroma.Config.get([:instance, :public])
- Pleroma.Config.put([:instance, :public], false)
+ is_public = Config.get([:instance, :public])
+ Config.put([:instance, :public], false)
conn = get(conn, path)
assert conn.status == 302
assert redirected_to(conn) == "/web/login"
- Pleroma.Config.put([:instance, :public], is_public)
+ Config.put([:instance, :public], is_public)
end
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
@@ -3876,8 +3877,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
- notify_email = Pleroma.Config.get([:instance, :notify_email])
- instance_name = Pleroma.Config.get([:instance, :name])
+ notify_email = Config.get([:instance, :notify_email])
+ instance_name = Config.get([:instance, :name])
assert_email_sent(
from: {instance_name, notify_email},
@@ -3909,11 +3910,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
setup do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
+ setting = Config.get([:instance, :account_activation_required])
unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
+ Config.put([:instance, :account_activation_required], true)
+ on_exit(fn -> Config.put([:instance, :account_activation_required], setting) end)
end
user = insert(:user)
@@ -3937,8 +3938,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> json_response(:no_content)
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
- notify_email = Pleroma.Config.get([:instance, :notify_email])
- instance_name = Pleroma.Config.get([:instance, :name])
+ notify_email = Config.get([:instance, :notify_email])
+ instance_name = Config.get([:instance, :name])
assert_email_sent(
from: {instance_name, notify_email},
@@ -3947,4 +3948,84 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
)
end
end
+
+ describe "GET /api/v1/suggestions" do
+ setup do
+ user = insert(:user)
+ other_user = insert(:user)
+ config = Config.get(:suggestions)
+ on_exit(fn -> Config.put(:suggestions, config) end)
+
+ host = Config.get([Pleroma.Web.Endpoint, :url, :host])
+ url500 = "http://test500?#{host}{user.nickname}"
+ url200 = "http://test200?#{host}{user.nickname}"
+
+ mock(fn
+ %{method: :get, url: ^url500} ->
+ %Tesla.Env{status: 500, body: "bad request"}
+
+ %{method: :get, url: ^url200} ->
+ %Tesla.Env{
+ status: 200,
+ body:
+ ~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{
+ other_user.ap_id
+ }","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}])
+ }
+ end)
+
+ [user: user, other_user: other_user]
+ end
+
+ test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
+ Config.put([:suggestions, :enabled], false)
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(200)
+
+ assert res == []
+ end
+
+ test "returns error", %{conn: conn, user: user} do
+ Config.put([:suggestions, :enabled], true)
+ Config.put([:suggestions, :third_party_engine], "http://test500?{{host}}&{{user}}")
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(500)
+
+ assert res == "Something went wrong"
+ end
+
+ test "returns suggestions", %{conn: conn, user: user, other_user: other_user} do
+ Config.put([:suggestions, :enabled], true)
+ Config.put([:suggestions, :third_party_engine], "http://test200?{{host}}&{{user}}")
+
+ res =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/suggestions")
+ |> json_response(200)
+
+ assert res == [
+ %{
+ "acct" => "yj455",
+ "avatar" => "https://social.heldscal.la/avatar/201.jpeg",
+ "avatar_static" => "https://social.heldscal.la/avatar/s/201.jpeg",
+ "id" => 0
+ },
+ %{
+ "acct" => other_user.ap_id,
+ "avatar" => "https://social.heldscal.la/avatar/202.jpeg",
+ "avatar_static" => "https://social.heldscal.la/avatar/s/202.jpeg",
+ "id" => other_user.id
+ }
+ ]
+ end
+ end
end
diff --git a/test/web/mastodon_api/mastodon_api_test.exs b/test/web/mastodon_api/mastodon_api_test.exs
new file mode 100644
index 000000000..b4c0427c9
--- /dev/null
+++ b/test/web/mastodon_api/mastodon_api_test.exs
@@ -0,0 +1,103 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Notification
+ alias Pleroma.ScheduledActivity
+ alias Pleroma.User
+ alias Pleroma.Web.MastodonAPI.MastodonAPI
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
+
+ import Pleroma.Factory
+
+ describe "follow/3" do
+ test "returns error when user deactivated" do
+ follower = insert(:user)
+ user = insert(:user, local: true, info: %{deactivated: true})
+ {:error, error} = MastodonAPI.follow(follower, user)
+ assert error == "Could not follow user: You are deactivated."
+ end
+
+ test "following for user" do
+ follower = insert(:user)
+ user = insert(:user)
+ {:ok, follower} = MastodonAPI.follow(follower, user)
+ assert User.following?(follower, user)
+ end
+
+ test "returns ok if user already followed" do
+ follower = insert(:user)
+ user = insert(:user)
+ {:ok, follower} = User.follow(follower, user)
+ {:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
+ assert User.following?(follower, user)
+ end
+ end
+
+ describe "get_followers/2" do
+ test "returns user followers" do
+ follower1_user = insert(:user)
+ follower2_user = insert(:user)
+ user = insert(:user)
+ {:ok, _follower1_user} = User.follow(follower1_user, user)
+ {:ok, follower2_user} = User.follow(follower2_user, user)
+
+ assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
+ end
+ end
+
+ describe "get_friends/2" do
+ test "returns user friends" do
+ user = insert(:user)
+ followed_one = insert(:user)
+ followed_two = insert(:user)
+ followed_three = insert(:user)
+
+ {:ok, user} = User.follow(user, followed_one)
+ {:ok, user} = User.follow(user, followed_two)
+ {:ok, user} = User.follow(user, followed_three)
+ res = MastodonAPI.get_friends(user)
+
+ assert length(res) == 3
+ assert Enum.member?(res, refresh_record(followed_three))
+ assert Enum.member?(res, refresh_record(followed_two))
+ assert Enum.member?(res, refresh_record(followed_one))
+ end
+ end
+
+ describe "get_notifications/2" do
+ test "returns notifications for user" do
+ user = insert(:user)
+ subscriber = insert(:user)
+
+ User.subscribe(subscriber, user)
+
+ {:ok, status} = TwitterAPI.create_status(user, %{"status" => "Akariiiin"})
+ {:ok, status1} = TwitterAPI.create_status(user, %{"status" => "Magi"})
+ {:ok, [notification]} = Notification.create_notifications(status)
+ {:ok, [notification1]} = Notification.create_notifications(status1)
+ res = MastodonAPI.get_notifications(subscriber)
+
+ assert Enum.member?(Enum.map(res, & &1.id), notification.id)
+ assert Enum.member?(Enum.map(res, & &1.id), notification1.id)
+ end
+ end
+
+ describe "get_scheduled_activities/2" do
+ test "returns user scheduled activities" do
+ user = insert(:user)
+
+ today =
+ NaiveDateTime.utc_now()
+ |> NaiveDateTime.add(:timer.minutes(6), :millisecond)
+ |> NaiveDateTime.to_iso8601()
+
+ attrs = %{params: %{}, scheduled_at: today}
+ {:ok, schedule} = ScheduledActivity.create(user, attrs)
+ assert MastodonAPI.get_scheduled_activities(user) == [schedule]
+ end
+ end
+end
--
cgit v1.2.3
From fea4d89e9f59b6fbdbd727eecde9b046e9ca46c6 Mon Sep 17 00:00:00 2001
From: Maksim
Date: Tue, 13 Aug 2019 21:12:59 +0000
Subject: tests for Web/ActivityPub/Relay
---
test/web/activity_pub/relay_test.exs | 62 +++++++++++++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/relay_test.exs b/test/web/activity_pub/relay_test.exs
index 21a63c493..e10b808f7 100644
--- a/test/web/activity_pub/relay_test.exs
+++ b/test/web/activity_pub/relay_test.exs
@@ -5,11 +5,71 @@
defmodule Pleroma.Web.ActivityPub.RelayTest do
use Pleroma.DataCase
+ alias Pleroma.Activity
+ alias Pleroma.Object
+ alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Relay
+ import Pleroma.Factory
+
test "gets an actor for the relay" do
user = Relay.get_actor()
+ assert user.ap_id == "#{Pleroma.Web.Endpoint.url()}/relay"
+ end
+
+ describe "follow/1" do
+ test "returns errors when user not found" do
+ assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
+ end
+
+ test "returns activity" do
+ user = insert(:user)
+ service_actor = Relay.get_actor()
+ assert {:ok, %Activity{} = activity} = Relay.follow(user.ap_id)
+ assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
+ assert user.ap_id in activity.recipients
+ assert activity.data["type"] == "Follow"
+ assert activity.data["actor"] == service_actor.ap_id
+ assert activity.data["object"] == user.ap_id
+ end
+ end
+
+ describe "unfollow/1" do
+ test "returns errors when user not found" do
+ assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
+ end
+
+ test "returns activity" do
+ user = insert(:user)
+ service_actor = Relay.get_actor()
+ ActivityPub.follow(service_actor, user)
+ assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
+ assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
+ assert user.ap_id in activity.recipients
+ assert activity.data["type"] == "Undo"
+ assert activity.data["actor"] == service_actor.ap_id
+ assert activity.data["to"] == [user.ap_id]
+ end
+ end
+
+ describe "publish/1" do
+ test "returns error when activity not `Create` type" do
+ activity = insert(:like_activity)
+ assert Relay.publish(activity) == {:error, "Not implemented"}
+ end
+
+ test "returns error when activity not public" do
+ activity = insert(:direct_note_activity)
+ assert Relay.publish(activity) == {:error, false}
+ end
- assert user.ap_id =~ "/relay"
+ test "returns announce activity" do
+ service_actor = Relay.get_actor()
+ note = insert(:note_activity)
+ assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
+ assert activity.data["type"] == "Announce"
+ assert activity.data["actor"] == service_actor.ap_id
+ assert activity.data["object"] == obj.data["id"]
+ end
end
end
--
cgit v1.2.3
From dd0b71ea6d0b758ee5425f295a8ee14f33c4ec07 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Tue, 13 Aug 2019 22:19:15 +0000
Subject: tests: add tests for MRF.describe()
---
test/web/activity_pub/mrf/mrf_test.exs | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
(limited to 'test/web')
diff --git a/test/web/activity_pub/mrf/mrf_test.exs b/test/web/activity_pub/mrf/mrf_test.exs
index 1a888e18f..19e172939 100644
--- a/test/web/activity_pub/mrf/mrf_test.exs
+++ b/test/web/activity_pub/mrf/mrf_test.exs
@@ -57,4 +57,30 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
refute MRF.subdomain_match?(regexes, "example.com")
end
end
+
+ describe "describe/0" do
+ test "it works as expected with noop policy" do
+ expected = %{
+ mrf_policies: ["NoOpPolicy"],
+ exclusions: false
+ }
+
+ {:ok, ^expected} = MRF.describe()
+ end
+
+ test "it works as expected with mock policy" do
+ config = Pleroma.Config.get([:instance, :rewrite_policy])
+ Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
+
+ expected = %{
+ mrf_policies: ["MRFModuleMock"],
+ mrf_module_mock: "some config data",
+ exclusions: false
+ }
+
+ {:ok, ^expected} = MRF.describe()
+
+ Pleroma.Config.put([:instance, :rewrite_policy], config)
+ end
+ end
end
--
cgit v1.2.3
From 10fef2fceee6d527d3fae0f67d81868b457d71b1 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Tue, 13 Aug 2019 22:32:40 +0000
Subject: tests: fix up nodeinfo tests
---
test/web/node_info_test.exs | 8 ++++++++
1 file changed, 8 insertions(+)
(limited to 'test/web')
diff --git a/test/web/node_info_test.exs b/test/web/node_info_test.exs
index d7f848bfa..f6147c286 100644
--- a/test/web/node_info_test.exs
+++ b/test/web/node_info_test.exs
@@ -85,6 +85,9 @@ defmodule Pleroma.Web.NodeInfoTest do
end
test "it shows MRF transparency data if enabled", %{conn: conn} do
+ config = Pleroma.Config.get([:instance, :rewrite_policy])
+ Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
+
option = Pleroma.Config.get([:instance, :mrf_transparency])
Pleroma.Config.put([:instance, :mrf_transparency], true)
@@ -98,11 +101,15 @@ defmodule Pleroma.Web.NodeInfoTest do
assert response["metadata"]["federation"]["mrf_simple"] == simple_config
+ Pleroma.Config.put([:instance, :rewrite_policy], config)
Pleroma.Config.put([:instance, :mrf_transparency], option)
Pleroma.Config.put(:mrf_simple, %{})
end
test "it performs exclusions from MRF transparency data if configured", %{conn: conn} do
+ config = Pleroma.Config.get([:instance, :rewrite_policy])
+ Pleroma.Config.put([:instance, :rewrite_policy], [Pleroma.Web.ActivityPub.MRF.SimplePolicy])
+
option = Pleroma.Config.get([:instance, :mrf_transparency])
Pleroma.Config.put([:instance, :mrf_transparency], true)
@@ -122,6 +129,7 @@ defmodule Pleroma.Web.NodeInfoTest do
assert response["metadata"]["federation"]["mrf_simple"] == expected_config
assert response["metadata"]["federation"]["exclusions"] == true
+ Pleroma.Config.put([:instance, :rewrite_policy], config)
Pleroma.Config.put([:instance, :mrf_transparency], option)
Pleroma.Config.put([:instance, :mrf_transparency_exclusions], exclusions)
Pleroma.Config.put(:mrf_simple, %{})
--
cgit v1.2.3
From e0ac5c7a66664c897e1b3af9a55e0b73f32fa034 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 24 Jul 2019 19:26:35 +0700
Subject: Add custom profile fields
---
.../update_credentials_test.exs | 39 ++++++++++++++++++++++
1 file changed, 39 insertions(+)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index 71d0c8af8..a3eadde16 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -300,5 +300,44 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
assert user["display_name"] == name
assert [%{"shortcode" => "blank"}, %{"shortcode" => "firefox"}] = user["emojis"]
end
+
+ test "update fields", %{conn: conn} do
+ user = insert(:user)
+
+ fields = [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ account =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(200)
+
+ assert account["fields"] == [
+ %{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ assert account["source"]["fields"] == [
+ %{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ Pleroma.Config.put([:instance, :max_account_fields], 1)
+
+ fields = [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "link", "value" => "cofe.io"}
+ ]
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+
+ assert %{"error" => "Invalid request"} == json_response(conn, 403)
+ end
end
end
--
cgit v1.2.3
From d6094b405d1a744eaa1c17752b3088dfee16c8d2 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 24 Jul 2019 19:48:15 +0700
Subject: Fix tests
---
test/web/mastodon_api/account_view_test.exs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/account_view_test.exs b/test/web/mastodon_api/account_view_test.exs
index a26f514a5..1d8b28339 100644
--- a/test/web/mastodon_api/account_view_test.exs
+++ b/test/web/mastodon_api/account_view_test.exs
@@ -67,7 +67,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: "valid html",
sensitive: false,
- pleroma: %{}
+ pleroma: %{},
+ fields: []
},
pleroma: %{
background_image: "https://example.com/images/asuka_hospital.png",
@@ -134,7 +135,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: user.bio,
sensitive: false,
- pleroma: %{}
+ pleroma: %{},
+ fields: []
},
pleroma: %{
background_image: nil,
@@ -304,7 +306,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
source: %{
note: user.bio,
sensitive: false,
- pleroma: %{}
+ pleroma: %{},
+ fields: []
},
pleroma: %{
background_image: nil,
--
cgit v1.2.3
From 88598c9bafcdcf89b0f1fb00d0785c77b583cd65 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 25 Jul 2019 19:35:34 +0700
Subject: Add profile custom fields to ActivityPub.UserView
---
test/web/activity_pub/views/user_view_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test/web')
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 86254117f..48a522c6c 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -22,6 +22,22 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY")
end
+ test "Renders profile fields" do
+ fields = [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "website", "value" => "cofe.my"}
+ ]
+
+ user = insert(:user, info: %{fields: fields})
+
+ assert %{
+ "attachment" => [
+ %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
+ %{"name" => "website", "type" => "PropertyValue", "value" => "cofe.my"}
+ ]
+ } = UserView.render("user.json", %{user: user})
+ end
+
test "Does not add an avatar image if the user hasn't set one" do
user = insert(:user)
{:ok, user} = User.ensure_keys_present(user)
--
cgit v1.2.3
From 5178f960c3f5a35e2071bd5463b537cadc9a53af Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 29 Jul 2019 19:01:15 +0700
Subject: Support user attachment update in Transmogrifier
---
test/web/activity_pub/transmogrifier_test.exs | 36 +++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
(limited to 'test/web')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 060b91e29..05ec09ec1 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -509,6 +509,42 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert user.bio == "Some bio
"
end
+ test "it works with custom profile fields" do
+ {:ok, activity} =
+ "test/fixtures/mastodon-post-activity.json"
+ |> File.read!()
+ |> Poison.decode!()
+ |> Transmogrifier.handle_incoming()
+
+ user = User.get_cached_by_ap_id(activity.actor)
+
+ assert user.info.source_data["attachment"] == [
+ %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
+ %{"name" => "foo1", "type" => "PropertyValue", "value" => "bar1"}
+ ]
+
+ update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
+
+ object =
+ update_data["object"]
+ |> Map.put("actor", user.ap_id)
+ |> Map.put("id", user.ap_id)
+
+ update_data =
+ update_data
+ |> Map.put("actor", user.ap_id)
+ |> Map.put("object", object)
+
+ {:ok, _update_activity} = Transmogrifier.handle_incoming(update_data)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
+ assert user.info.source_data["attachment"] == [
+ %{"name" => "foo", "type" => "PropertyValue", "value" => "updated"},
+ %{"name" => "foo1", "type" => "PropertyValue", "value" => "updated"}
+ ]
+ end
+
test "it works for incoming update activities which lock the account" do
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
--
cgit v1.2.3
From 7d6f8a7fd75e5de4e0c9ce208ac9276dcbe044f5 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 29 Jul 2019 19:17:09 +0700
Subject: Linkify custom fields values in ActivityPub.UserViewx
---
test/web/activity_pub/views/user_view_test.exs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index 48a522c6c..a2aa52381 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -33,7 +33,11 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
assert %{
"attachment" => [
%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
- %{"name" => "website", "type" => "PropertyValue", "value" => "cofe.my"}
+ %{
+ "name" => "website",
+ "type" => "PropertyValue",
+ "value" => "cofe.my"
+ }
]
} = UserView.render("user.json", %{user: user})
end
--
cgit v1.2.3
From db3c05f6b4c226733633a409cb1f1a290db4c48b Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 30 Jul 2019 17:22:52 +0700
Subject: Add configurable account field value length limit
---
.../update_credentials_test.exs | 31 +++++++++++++++++-----
1 file changed, 25 insertions(+), 6 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index a3eadde16..992a692f0 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -325,6 +325,26 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
%{"name" => "link", "value" => "cofe.io"}
]
+ value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
+
+ long_str = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
+
+ fields = [%{"name" => "foo", "value" => long_str}]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+
+ fields = [%{"name" => long_str, "value" => "bar"}]
+
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
+
Pleroma.Config.put([:instance, :max_account_fields], 1)
fields = [
@@ -332,12 +352,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
%{"name" => "link", "value" => "cofe.io"}
]
- conn =
- conn
- |> assign(:user, user)
- |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
-
- assert %{"error" => "Invalid request"} == json_response(conn, 403)
+ assert %{"error" => "Invalid request"} ==
+ conn
+ |> assign(:user, user)
+ |> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
+ |> json_response(403)
end
end
end
--
cgit v1.2.3
From 2c35d4b0b04e58368c51f2828536d295f72839a2 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Thu, 1 Aug 2019 15:09:15 +0700
Subject: Add configurable account field name length limit
---
.../mastodon_api_controller/update_credentials_test.exs | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index 992a692f0..e75f25d51 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -325,11 +325,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
%{"name" => "link", "value" => "cofe.io"}
]
+ name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
- long_str = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
+ long_value = Enum.map(0..value_limit, fn _ -> "x" end) |> Enum.join()
- fields = [%{"name" => "foo", "value" => long_str}]
+ fields = [%{"name" => "foo", "value" => long_value}]
assert %{"error" => "Invalid request"} ==
conn
@@ -337,7 +338,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|> json_response(403)
- fields = [%{"name" => long_str, "value" => "bar"}]
+ long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
+
+ fields = [%{"name" => long_name, "value" => "bar"}]
assert %{"error" => "Invalid request"} ==
conn
--
cgit v1.2.3
From f7bbf99caade7f06756e95e3a4e2f0e4d3e76579 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 6 Aug 2019 18:21:25 +0700
Subject: Use info.fields instead of source_data for remote users
---
test/web/activity_pub/transmogrifier_test.exs | 12 ++++++------
test/web/activity_pub/views/user_view_test.exs | 17 ++++++-----------
.../mastodon_api_controller/update_credentials_test.exs | 9 ++++++---
3 files changed, 18 insertions(+), 20 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 05ec09ec1..7e2c8769d 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -518,9 +518,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(activity.actor)
- assert user.info.source_data["attachment"] == [
- %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
- %{"name" => "foo1", "type" => "PropertyValue", "value" => "bar1"}
+ assert User.Info.fields(user.info) == [
+ %{"name" => "foo", "value" => "bar"},
+ %{"name" => "foo1", "value" => "bar1"}
]
update_data = File.read!("test/fixtures/mastodon-update.json") |> Poison.decode!()
@@ -539,9 +539,9 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(user.ap_id)
- assert user.info.source_data["attachment"] == [
- %{"name" => "foo", "type" => "PropertyValue", "value" => "updated"},
- %{"name" => "foo1", "type" => "PropertyValue", "value" => "updated"}
+ assert User.Info.fields(user.info) == [
+ %{"name" => "foo", "value" => "updated"},
+ %{"name" => "foo1", "value" => "updated"}
]
end
diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs
index a2aa52381..fb7fd9e79 100644
--- a/test/web/activity_pub/views/user_view_test.exs
+++ b/test/web/activity_pub/views/user_view_test.exs
@@ -24,21 +24,16 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
test "Renders profile fields" do
fields = [
- %{"name" => "foo", "value" => "bar"},
- %{"name" => "website", "value" => "cofe.my"}
+ %{"name" => "foo", "value" => "bar"}
]
- user = insert(:user, info: %{fields: fields})
+ {:ok, user} =
+ insert(:user)
+ |> User.upgrade_changeset(%{info: %{fields: fields}})
+ |> User.update_and_set_cache()
assert %{
- "attachment" => [
- %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
- %{
- "name" => "website",
- "type" => "PropertyValue",
- "value" => "cofe.my"
- }
- ]
+ "attachment" => [%{"name" => "foo", "type" => "PropertyValue", "value" => "bar"}]
} = UserView.render("user.json", %{user: user})
end
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index e75f25d51..dd443495b 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -305,7 +305,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
user = insert(:user)
fields = [
- %{"name" => "foo", "value" => "bar"},
+ %{"name" => "foo", "value" => ""},
%{"name" => "link", "value" => "cofe.io"}
]
@@ -316,12 +316,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|> json_response(200)
assert account["fields"] == [
- %{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
+ %{"name" => "foo", "value" => "bar"},
%{"name" => "link", "value" => "cofe.io"}
]
assert account["source"]["fields"] == [
- %{"name" => "<b>foo<b>", "value" => "<i>bar</i>"},
+ %{
+ "name" => "foo",
+ "value" => ""
+ },
%{"name" => "link", "value" => "cofe.io"}
]
--
cgit v1.2.3
From e457fcc47971df6c76c3da096e6b45c2972e4029 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 7 Aug 2019 18:14:22 +0700
Subject: Add `:max_remote_account_fields` config option
---
test/web/activity_pub/transmogrifier_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test/web')
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index 7e2c8769d..d8fbcd628 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -539,6 +539,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
user = User.get_cached_by_ap_id(user.ap_id)
+ assert User.Info.fields(user.info) == [
+ %{"name" => "foo", "value" => "updated"},
+ %{"name" => "foo1", "value" => "updated"}
+ ]
+
+ Pleroma.Config.put([:instance, :max_remote_account_fields], 2)
+
+ update_data =
+ put_in(update_data, ["object", "attachment"], [
+ %{"name" => "foo", "type" => "PropertyValue", "value" => "bar"},
+ %{"name" => "foo11", "type" => "PropertyValue", "value" => "bar11"},
+ %{"name" => "foo22", "type" => "PropertyValue", "value" => "bar22"}
+ ])
+
+ {:ok, _} = Transmogrifier.handle_incoming(update_data)
+
+ user = User.get_cached_by_ap_id(user.ap_id)
+
assert User.Info.fields(user.info) == [
%{"name" => "foo", "value" => "updated"},
%{"name" => "foo1", "value" => "updated"}
--
cgit v1.2.3
From d81f63845a71e5cc60d95007ecaa2aea52a90422 Mon Sep 17 00:00:00 2001
From: stwf
Date: Wed, 14 Aug 2019 11:59:33 -0400
Subject: Implement Pleroma.Stats as GenServer
---
test/web/mastodon_api/mastodon_api_controller_test.exs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'test/web')
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 2febe8b3a..112e272f9 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -2624,7 +2624,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> Changeset.put_embed(:info, info_change)
|> User.update_and_set_cache()
- Pleroma.Stats.update_stats()
+ Pleroma.Stats.force_update()
conn = get(conn, "/api/v1/instance")
@@ -2642,7 +2642,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
insert(:user, %{local: false, nickname: "u@peer1.com"})
insert(:user, %{local: false, nickname: "u@peer2.com"})
- Pleroma.Stats.update_stats()
+ Pleroma.Stats.force_update()
conn = get(conn, "/api/v1/instance/peers")
--
cgit v1.2.3
From a4a3e3becd5e008dbfa9a23157ae4b16a0652bce Mon Sep 17 00:00:00 2001
From: rinpatch
Date: Thu, 15 Aug 2019 17:37:30 +0300
Subject: Hide muted theads from home/public timelines unless `with_muted` is
set
---
test/web/activity_pub/activity_pub_test.exs | 23 +++++++++++++++++++++++
test/web/streamer_test.exs | 20 ++++++++++++++++++++
2 files changed, 43 insertions(+)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index d723f331f..0377d29f6 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -538,6 +538,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert Enum.member?(activities, activity_one)
end
+ test "doesn't return thread muted activities" do
+ user = insert(:user)
+ activity_one = insert(:note_activity)
+ note_two = insert(:note, data: %{"context" => "suya.."})
+ activity_two = insert(:note_activity, note: note_two)
+
+ {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
+
+ assert [activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
+ end
+
+ test "returns thread muted activities when with_muted is set" do
+ user = insert(:user)
+ activity_one = insert(:note_activity)
+ note_two = insert(:note, data: %{"context" => "suya.."})
+ activity_two = insert(:note_activity, note: note_two)
+
+ {:ok, activity_two} = CommonAPI.add_mute(user, activity_two)
+
+ assert [activity_two, activity_one] =
+ ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
+ end
+
test "does include announces on request" do
activity_three = insert(:note_activity)
user = insert(:user)
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index d47b37efb..5b7fe44d4 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -414,6 +414,26 @@ defmodule Pleroma.Web.StreamerTest do
Task.await(task)
end
+ test "it doesn't send posts from muted threads" do
+ user = insert(:user)
+ user2 = insert(:user)
+ {:ok, user2, user, _activity} = CommonAPI.follow(user2, user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "super hot take"})
+
+ {:ok, activity} = CommonAPI.add_mute(user2, activity)
+
+ task = Task.async(fn -> refute_receive {:text, _}, 4_000 end)
+
+ Streamer.add_socket(
+ "user",
+ %{transport_pid: task.pid, assigns: %{user: user2}}
+ )
+
+ Streamer.stream("user", activity)
+ Task.await(task)
+ end
+
describe "direct streams" do
setup do
GenServer.start(Streamer, %{}, name: Streamer)
--
cgit v1.2.3
From a2fdc32368dec49449505ed85ebeff982afa449c Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Sun, 18 Aug 2019 22:21:31 +0000
Subject: tests: activitypub: fix typo
---
test/web/activity_pub/activity_pub_test.exs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index 0377d29f6..f20cd2840 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -540,24 +540,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
test "doesn't return thread muted activities" do
user = insert(:user)
- activity_one = insert(:note_activity)
+ _activity_one = insert(:note_activity)
note_two = insert(:note, data: %{"context" => "suya.."})
activity_two = insert(:note_activity, note: note_two)
{:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
- assert [activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
+ assert [_activity_one] = ActivityPub.fetch_activities([], %{"muting_user" => user})
end
test "returns thread muted activities when with_muted is set" do
user = insert(:user)
- activity_one = insert(:note_activity)
+ _activity_one = insert(:note_activity)
note_two = insert(:note, data: %{"context" => "suya.."})
activity_two = insert(:note_activity, note: note_two)
{:ok, activity_two} = CommonAPI.add_mute(user, activity_two)
- assert [activity_two, activity_one] =
+ assert [_activity_two, _activity_one] =
ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
end
--
cgit v1.2.3
From a320358703db249ab20df5afd81c92fb42b8cadb Mon Sep 17 00:00:00 2001
From: Maksim
Date: Mon, 19 Aug 2019 15:34:29 +0000
Subject: added test helpers to clear config after tests
---
.../activity_pub/activity_pub_controller_test.exs | 15 +++---
test/web/activity_pub/mrf/mrf_test.exs | 6 +--
.../activity_pub/mrf/reject_non_public_test.exs | 7 +--
test/web/activity_pub/mrf/simple_policy_test.exs | 8 +---
.../mrf/user_allowlist_policy_test.exs | 7 +--
.../activity_pub/mrf/vocabulary_policy_test.exs | 25 ++--------
test/web/admin_api/admin_api_controller_test.exs | 56 +++++++---------------
test/web/common_api/common_api_test.exs | 9 ++--
test/web/federator_test.exs | 27 +++++------
test/web/instances/instance_test.exs | 10 +---
test/web/instances/instances_test.exs | 10 +---
.../mastodon_api/mastodon_api_controller_test.exs | 49 +++++++------------
test/web/media_proxy/media_proxy_test.exs | 7 +--
test/web/oauth/ldap_authorization_test.exs | 17 ++-----
test/web/oauth/oauth_controller_test.exs | 36 +++++---------
test/web/ostatus/ostatus_controller_test.exs | 11 ++---
test/web/plugs/federating_plug_test.exs | 10 +---
test/web/rich_media/helpers_test.exs | 4 +-
test/web/streamer_test.exs | 10 +---
.../twitter_api/twitter_api_controller_test.exs | 21 +++-----
test/web/twitter_api/util_controller_test.exs | 28 ++---------
test/web/web_finger/web_finger_controller_test.exs | 10 ++--
test/web/websub/websub_controller_test.exs | 10 +---
23 files changed, 112 insertions(+), 281 deletions(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs
index 251055ee1..77f5e39fa 100644
--- a/test/web/activity_pub/activity_pub_controller_test.exs
+++ b/test/web/activity_pub/activity_pub_controller_test.exs
@@ -16,17 +16,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ clear_config_all([:instance, :federating],
+ do: Pleroma.Config.put([:instance, :federating], true)
+ )
+
describe "/relay" do
+ clear_config([:instance, :allow_relay])
+
test "with the relay active, it returns the relay user", %{conn: conn} do
res =
conn
@@ -43,8 +42,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|> get(activity_pub_path(conn, :relay))
|> json_response(404)
|> assert
-
- Pleroma.Config.put([:instance, :allow_relay], true)
end
end
diff --git a/test/web/activity_pub/mrf/mrf_test.exs b/test/web/activity_pub/mrf/mrf_test.exs
index 19e172939..04709df17 100644
--- a/test/web/activity_pub/mrf/mrf_test.exs
+++ b/test/web/activity_pub/mrf/mrf_test.exs
@@ -1,5 +1,6 @@
defmodule Pleroma.Web.ActivityPub.MRFTest do
use ExUnit.Case, async: true
+ use Pleroma.Tests.Helpers
alias Pleroma.Web.ActivityPub.MRF
test "subdomains_regex/1" do
@@ -59,6 +60,8 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
describe "describe/0" do
+ clear_config([:instance, :rewrite_policy])
+
test "it works as expected with noop policy" do
expected = %{
mrf_policies: ["NoOpPolicy"],
@@ -69,7 +72,6 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
end
test "it works as expected with mock policy" do
- config = Pleroma.Config.get([:instance, :rewrite_policy])
Pleroma.Config.put([:instance, :rewrite_policy], [MRFModuleMock])
expected = %{
@@ -79,8 +81,6 @@ defmodule Pleroma.Web.ActivityPub.MRFTest do
}
{:ok, ^expected} = MRF.describe()
-
- Pleroma.Config.put([:instance, :rewrite_policy], config)
end
end
end
diff --git a/test/web/activity_pub/mrf/reject_non_public_test.exs b/test/web/activity_pub/mrf/reject_non_public_test.exs
index fdf6b245e..fc1d190bb 100644
--- a/test/web/activity_pub/mrf/reject_non_public_test.exs
+++ b/test/web/activity_pub/mrf/reject_non_public_test.exs
@@ -8,12 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.RejectNonPublicTest do
alias Pleroma.Web.ActivityPub.MRF.RejectNonPublic
- setup do
- policy = Pleroma.Config.get([:mrf_rejectnonpublic])
- on_exit(fn -> Pleroma.Config.put([:mrf_rejectnonpublic], policy) end)
-
- :ok
- end
+ clear_config([:mrf_rejectnonpublic])
describe "public message" do
test "it's allowed when address is public" do
diff --git a/test/web/activity_pub/mrf/simple_policy_test.exs b/test/web/activity_pub/mrf/simple_policy_test.exs
index 8e86d2219..7203b27da 100644
--- a/test/web/activity_pub/mrf/simple_policy_test.exs
+++ b/test/web/activity_pub/mrf/simple_policy_test.exs
@@ -8,9 +8,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
alias Pleroma.Config
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
- setup do
- orig = Config.get!(:mrf_simple)
-
+ clear_config([:mrf_simple]) do
Config.put(:mrf_simple,
media_removal: [],
media_nsfw: [],
@@ -21,10 +19,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
avatar_removal: [],
banner_removal: []
)
-
- on_exit(fn ->
- Config.put(:mrf_simple, orig)
- end)
end
describe "when :media_removal" do
diff --git a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
index 6519e2398..72084c0fd 100644
--- a/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
+++ b/test/web/activity_pub/mrf/user_allowlist_policy_test.exs
@@ -7,12 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.UserAllowListPolicyTest do
alias Pleroma.Web.ActivityPub.MRF.UserAllowListPolicy
- setup do
- policy = Pleroma.Config.get([:mrf_user_allowlist]) || []
- on_exit(fn -> Pleroma.Config.put([:mrf_user_allowlist], policy) end)
-
- :ok
- end
+ clear_config([:mrf_user_allowlist, :localhost])
test "pass filter if allow list is empty" do
actor = insert(:user)
diff --git a/test/web/activity_pub/mrf/vocabulary_policy_test.exs b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
index c3b11d7a1..38309f9f1 100644
--- a/test/web/activity_pub/mrf/vocabulary_policy_test.exs
+++ b/test/web/activity_pub/mrf/vocabulary_policy_test.exs
@@ -8,8 +8,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
alias Pleroma.Web.ActivityPub.MRF.VocabularyPolicy
describe "accept" do
+ clear_config([:mrf_vocabulary, :accept])
+
test "it accepts based on parent activity type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Like"])
message = %{
@@ -18,12 +19,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:ok, ^message} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
test "it accepts based on child object type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
@@ -35,12 +33,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:ok, ^message} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
test "it does not accept disallowed child objects" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Create", "Note"])
message = %{
@@ -52,12 +47,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
test "it does not accept disallowed parent types" do
- config = Pleroma.Config.get([:mrf_vocabulary, :accept])
Pleroma.Config.put([:mrf_vocabulary, :accept], ["Announce", "Note"])
message = %{
@@ -69,14 +61,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :accept], config)
end
end
describe "reject" do
+ clear_config([:mrf_vocabulary, :reject])
+
test "it rejects based on parent activity type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :reject])
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
message = %{
@@ -85,12 +76,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :reject], config)
end
test "it rejects based on child object type" do
- config = Pleroma.Config.get([:mrf_vocabulary, :reject])
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Note"])
message = %{
@@ -102,12 +90,9 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:reject, nil} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :reject], config)
end
test "it passes through objects that aren't disallowed" do
- config = Pleroma.Config.get([:mrf_vocabulary, :reject])
Pleroma.Config.put([:mrf_vocabulary, :reject], ["Like"])
message = %{
@@ -116,8 +101,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.VocabularyPolicyTest do
}
{:ok, ^message} = VocabularyPolicy.filter(message)
-
- Pleroma.Config.put([:mrf_vocabulary, :reject], config)
end
end
end
diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs
index bcbc18639..844cd0732 100644
--- a/test/web/admin_api/admin_api_controller_test.exs
+++ b/test/web/admin_api/admin_api_controller_test.exs
@@ -294,18 +294,15 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
describe "POST /api/pleroma/admin/email_invite, with valid config" do
setup do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
- Pleroma.Config.put([:instance, :registrations_open], false)
- Pleroma.Config.put([:instance, :invites_enabled], true)
+ [user: insert(:user, info: %{is_admin: true})]
+ end
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
+ clear_config([:instance, :registrations_open]) do
+ Pleroma.Config.put([:instance, :registrations_open], false)
+ end
- [user: insert(:user, info: %{is_admin: true})]
+ clear_config([:instance, :invites_enabled]) do
+ Pleroma.Config.put([:instance, :invites_enabled], true)
end
test "sends invitation and returns 204", %{conn: conn, user: user} do
@@ -360,18 +357,13 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
[user: insert(:user, info: %{is_admin: true})]
end
+ clear_config([:instance, :registrations_open])
+ clear_config([:instance, :invites_enabled])
+
test "it returns 500 if `invites_enabled` is not enabled", %{conn: conn, user: user} do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
Pleroma.Config.put([:instance, :registrations_open], false)
Pleroma.Config.put([:instance, :invites_enabled], false)
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
conn =
conn
|> assign(:user, user)
@@ -381,17 +373,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
end
test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: user} do
- registrations_open = Pleroma.Config.get([:instance, :registrations_open])
- invites_enabled = Pleroma.Config.get([:instance, :invites_enabled])
Pleroma.Config.put([:instance, :registrations_open], true)
Pleroma.Config.put([:instance, :invites_enabled], true)
- on_exit(fn ->
- Pleroma.Config.put([:instance, :registrations_open], registrations_open)
- Pleroma.Config.put([:instance, :invites_enabled], invites_enabled)
- :ok
- end)
-
conn =
conn
|> assign(:user, user)
@@ -1402,15 +1386,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
:ok = File.rm(temp_file)
end)
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
+ %{conn: assign(conn, :user, admin)}
+ end
+ clear_config([:instance, :dynamic_configuration]) do
Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
- end)
-
- %{conn: assign(conn, :user, admin)}
end
test "create new config setting in db", %{conn: conn} do
@@ -1961,15 +1941,11 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
:ok = File.rm(temp_file)
end)
- dynamic = Pleroma.Config.get([:instance, :dynamic_configuration])
+ %{conn: assign(conn, :user, admin), admin: admin}
+ end
+ clear_config([:instance, :dynamic_configuration]) do
Pleroma.Config.put([:instance, :dynamic_configuration], true)
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :dynamic_configuration], dynamic)
- end)
-
- %{conn: assign(conn, :user, admin), admin: admin}
end
test "transfer settings to DB and to file", %{conn: conn, admin: admin} do
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 454523349..bcbaad665 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -14,6 +14,10 @@ defmodule Pleroma.Web.CommonAPITest do
import Pleroma.Factory
+ clear_config([:instance, :safe_dm_mentions])
+ clear_config([:instance, :limit])
+ clear_config([:instance, :max_pinned_statuses])
+
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
@@ -61,7 +65,6 @@ defmodule Pleroma.Web.CommonAPITest do
har = insert(:user)
jafnhar = insert(:user)
tridi = insert(:user)
- option = Pleroma.Config.get([:instance, :safe_dm_mentions])
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
{:ok, activity} =
@@ -72,7 +75,6 @@ defmodule Pleroma.Web.CommonAPITest do
refute tridi.ap_id in activity.recipients
assert jafnhar.ap_id in activity.recipients
- Pleroma.Config.put([:instance, :safe_dm_mentions], option)
end
test "it de-duplicates tags" do
@@ -195,15 +197,12 @@ defmodule Pleroma.Web.CommonAPITest do
end
test "it returns error when character limit is exceeded" do
- limit = Pleroma.Config.get([:instance, :limit])
Pleroma.Config.put([:instance, :limit], 5)
user = insert(:user)
assert {:error, "The status is over the character limit"} =
CommonAPI.post(user, %{"status" => "foobar"})
-
- Pleroma.Config.put([:instance, :limit], limit)
end
end
diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs
index 73cfaa8f1..09e54533f 100644
--- a/test/web/federator_test.exs
+++ b/test/web/federator_test.exs
@@ -13,15 +13,17 @@ defmodule Pleroma.Web.FederatorTest do
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
+ clear_config([:instance, :allow_relay])
+ clear_config([:instance, :rewrite_policy])
+ clear_config([:mrf_keyword])
+
describe "Publisher.perform" do
test "call `perform` with unknown task" do
assert {
@@ -67,8 +69,6 @@ defmodule Pleroma.Web.FederatorTest do
end
refute_received :relay_publish
-
- Pleroma.Config.put([:instance, :allow_relay], true)
end
end
@@ -231,19 +231,18 @@ defmodule Pleroma.Web.FederatorTest do
end
test "it does not crash if MRF rejects the post" do
- policies = Pleroma.Config.get([:instance, :rewrite_policy])
- mrf_keyword_policy = Pleroma.Config.get(:mrf_keyword)
Pleroma.Config.put([:mrf_keyword, :reject], ["lain"])
- Pleroma.Config.put([:instance, :rewrite_policy], Pleroma.Web.ActivityPub.MRF.KeywordPolicy)
+
+ Pleroma.Config.put(
+ [:instance, :rewrite_policy],
+ Pleroma.Web.ActivityPub.MRF.KeywordPolicy
+ )
params =
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
assert Federator.incoming_ap_doc(params) == :error
-
- Pleroma.Config.put([:instance, :rewrite_policy], policies)
- Pleroma.Config.put(:mrf_keyword, mrf_keyword_policy)
end
end
end
diff --git a/test/web/instances/instance_test.exs b/test/web/instances/instance_test.exs
index d28730994..3fd011fd3 100644
--- a/test/web/instances/instance_test.exs
+++ b/test/web/instances/instance_test.exs
@@ -10,14 +10,8 @@ defmodule Pleroma.Instances.InstanceTest do
import Pleroma.Factory
- setup_all do
- config_path = [:instance, :federation_reachability_timeout_days]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, 1)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federation_reachability_timeout_days]) do
+ Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
end
describe "set_reachable/1" do
diff --git a/test/web/instances/instances_test.exs b/test/web/instances/instances_test.exs
index f0d84edea..dea8e2aea 100644
--- a/test/web/instances/instances_test.exs
+++ b/test/web/instances/instances_test.exs
@@ -7,14 +7,8 @@ defmodule Pleroma.InstancesTest do
use Pleroma.DataCase
- setup_all do
- config_path = [:instance, :federation_reachability_timeout_days]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, 1)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federation_reachability_timeout_days]) do
+ Pleroma.Config.put([:instance, :federation_reachability_timeout_days], 1)
end
describe "reachable?/1" do
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 112e272f9..77430e9c9 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -33,6 +33,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
:ok
end
+ clear_config([:instance, :public])
+ clear_config([:rich_media, :enabled])
+
test "the home timeline", %{conn: conn} do
user = insert(:user)
following = insert(:user)
@@ -86,13 +89,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
end
test "the public timeline when public is set to false", %{conn: conn} do
- public = Config.get([:instance, :public])
Config.put([:instance, :public], false)
- on_exit(fn ->
- Config.put([:instance, :public], public)
- end)
-
assert conn
|> get("/api/v1/timelines/public", %{"local" => "False"})
|> json_response(403) == %{"error" => "This resource requires authentication."}
@@ -261,7 +259,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
assert %{"id" => id, "card" => %{"title" => "The Rock"}} = json_response(conn, 200)
assert Activity.get_by_id(id)
- Config.put([:rich_media, :enabled], false)
end
test "posting a direct status", %{conn: conn} do
@@ -1634,14 +1631,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "media upload" do
setup do
- upload_config = Config.get([Pleroma.Upload])
- proxy_config = Config.get([:media_proxy])
-
- on_exit(fn ->
- Config.put([Pleroma.Upload], upload_config)
- Config.put([:media_proxy], proxy_config)
- end)
-
user = insert(:user)
conn =
@@ -1657,6 +1646,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[conn: conn, image: image]
end
+ clear_config([:media_proxy])
+ clear_config([Pleroma.Upload])
+
test "returns uploaded image", %{conn: conn, image: image} do
desc = "Description of the image"
@@ -2667,14 +2659,16 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "pinned statuses" do
setup do
- Config.put([:instance, :max_pinned_statuses], 1)
-
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
[user: user, activity: activity]
end
+ clear_config([:instance, :max_pinned_statuses]) do
+ Config.put([:instance, :max_pinned_statuses], 1)
+ end
+
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
{:ok, _} = CommonAPI.pin(activity.id, user)
@@ -2769,10 +2763,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
setup do
Config.put([:rich_media, :enabled], true)
- on_exit(fn ->
- Config.put([:rich_media, :enabled], false)
- end)
-
user = insert(:user)
%{user: user}
end
@@ -3127,15 +3117,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
conn: conn,
path: path
} do
- is_public = Config.get([:instance, :public])
Config.put([:instance, :public], false)
conn = get(conn, path)
assert conn.status == 302
assert redirected_to(conn) == "/web/login"
-
- Config.put([:instance, :public], is_public)
end
test "does not redirect logged in users to the login page", %{conn: conn, path: path} do
@@ -3910,13 +3897,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
setup do
- setting = Config.get([:instance, :account_activation_required])
-
- unless setting do
- Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Config.put([:instance, :account_activation_required], setting) end)
- end
-
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
@@ -3931,6 +3911,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[user: user]
end
+ clear_config([:instance, :account_activation_required]) do
+ Config.put([:instance, :account_activation_required], true)
+ end
+
test "resend account confirmation email", %{conn: conn, user: user} do
conn
|> assign(:user, user)
@@ -3953,9 +3937,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
setup do
user = insert(:user)
other_user = insert(:user)
- config = Config.get(:suggestions)
- on_exit(fn -> Config.put(:suggestions, config) end)
-
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
url500 = "http://test500?#{host}{user.nickname}"
url200 = "http://test200?#{host}{user.nickname}"
@@ -3977,6 +3958,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
[user: user, other_user: other_user]
end
+ clear_config(:suggestions)
+
test "returns empty result when suggestions disabled", %{conn: conn, user: user} do
Config.put([:suggestions, :enabled], false)
diff --git a/test/web/media_proxy/media_proxy_test.exs b/test/web/media_proxy/media_proxy_test.exs
index 0c94755df..79699cac5 100644
--- a/test/web/media_proxy/media_proxy_test.exs
+++ b/test/web/media_proxy/media_proxy_test.exs
@@ -4,14 +4,11 @@
defmodule Pleroma.Web.MediaProxyTest do
use ExUnit.Case
+ use Pleroma.Tests.Helpers
import Pleroma.Web.MediaProxy
alias Pleroma.Web.MediaProxy.MediaProxyController
- setup do
- enabled = Pleroma.Config.get([:media_proxy, :enabled])
- on_exit(fn -> Pleroma.Config.put([:media_proxy, :enabled], enabled) end)
- :ok
- end
+ clear_config([:media_proxy, :enabled])
describe "when enabled" do
setup do
diff --git a/test/web/oauth/ldap_authorization_test.exs b/test/web/oauth/ldap_authorization_test.exs
index 0eb191c76..1cbe133b7 100644
--- a/test/web/oauth/ldap_authorization_test.exs
+++ b/test/web/oauth/ldap_authorization_test.exs
@@ -12,21 +12,12 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
@skip if !Code.ensure_loaded?(:eldap), do: :skip
- setup_all do
- ldap_authenticator =
- Pleroma.Config.get(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.PleromaAuthenticator)
-
- ldap_enabled = Pleroma.Config.get([:ldap, :enabled])
-
- on_exit(fn ->
- Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, ldap_authenticator)
- Pleroma.Config.put([:ldap, :enabled], ldap_enabled)
- end)
-
- Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
+ clear_config_all([:ldap, :enabled]) do
Pleroma.Config.put([:ldap, :enabled], true)
+ end
- :ok
+ clear_config_all(Pleroma.Web.Auth.Authenticator) do
+ Pleroma.Config.put(Pleroma.Web.Auth.Authenticator, Pleroma.Web.Auth.LDAPAuthenticator)
end
@tag @skip
diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs
index 92e156347..b492c7794 100644
--- a/test/web/oauth/oauth_controller_test.exs
+++ b/test/web/oauth/oauth_controller_test.exs
@@ -11,23 +11,15 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
alias Pleroma.Web.OAuth.OAuthController
alias Pleroma.Web.OAuth.Token
- @oauth_config_path [:oauth2, :issue_new_refresh_token]
@session_opts [
store: :cookie,
key: "_test",
signing_salt: "cooldude"
]
+ clear_config_all([:instance, :account_activation_required])
describe "in OAuth consumer mode, " do
setup do
- oauth_consumer_strategies_path = [:auth, :oauth_consumer_strategies]
- oauth_consumer_strategies = Pleroma.Config.get(oauth_consumer_strategies_path)
- Pleroma.Config.put(oauth_consumer_strategies_path, ~w(twitter facebook))
-
- on_exit(fn ->
- Pleroma.Config.put(oauth_consumer_strategies_path, oauth_consumer_strategies)
- end)
-
[
app: insert(:oauth_app),
conn:
@@ -37,6 +29,13 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
]
end
+ clear_config([:auth, :oauth_consumer_strategies]) do
+ Pleroma.Config.put(
+ [:auth, :oauth_consumer_strategies],
+ ~w(twitter facebook)
+ )
+ end
+
test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %{
app: app,
conn: conn
@@ -775,12 +774,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "rejects token exchange for valid credentials belonging to unconfirmed user and confirmation is required" do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
+ Pleroma.Config.put([:instance, :account_activation_required], true)
password = "testpassword"
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt(password))
@@ -857,16 +851,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
describe "POST /oauth/token - refresh token" do
- setup do
- oauth_token_config = Pleroma.Config.get(@oauth_config_path)
-
- on_exit(fn ->
- Pleroma.Config.get(@oauth_config_path, oauth_token_config)
- end)
- end
+ clear_config([:oauth2, :issue_new_refresh_token])
test "issues a new access token with keep fresh token" do
- Pleroma.Config.put(@oauth_config_path, true)
+ Pleroma.Config.put([:oauth2, :issue_new_refresh_token], true)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
@@ -906,7 +894,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
end
test "issues a new access token with new fresh token" do
- Pleroma.Config.put(@oauth_config_path, false)
+ Pleroma.Config.put([:oauth2, :issue_new_refresh_token], false)
user = insert(:user)
app = insert(:oauth_app, scopes: ["read", "write"])
diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs
index 9f756effb..095ae7041 100644
--- a/test/web/ostatus/ostatus_controller_test.exs
+++ b/test/web/ostatus/ostatus_controller_test.exs
@@ -15,16 +15,13 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
describe "salmon_incoming" do
test "decodes a salmon", %{conn: conn} do
user = insert(:user)
diff --git a/test/web/plugs/federating_plug_test.exs b/test/web/plugs/federating_plug_test.exs
index c01e01124..bb2e1687a 100644
--- a/test/web/plugs/federating_plug_test.exs
+++ b/test/web/plugs/federating_plug_test.exs
@@ -4,15 +4,7 @@
defmodule Pleroma.Web.FederatingPlugTest do
use Pleroma.Web.ConnCase
-
- setup_all do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
- end
+ clear_config_all([:instance, :federating])
test "returns and halt the conn when federating is disabled" do
Pleroma.Config.put([:instance, :federating], false)
diff --git a/test/web/rich_media/helpers_test.exs b/test/web/rich_media/helpers_test.exs
index 92198f3d9..48884319d 100644
--- a/test/web/rich_media/helpers_test.exs
+++ b/test/web/rich_media/helpers_test.exs
@@ -15,12 +15,12 @@ defmodule Pleroma.Web.RichMedia.HelpersTest do
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
- rich_media = Config.get([:rich_media, :enabled])
- on_exit(fn -> Config.put([:rich_media, :enabled], rich_media) end)
:ok
end
+ clear_config([:rich_media, :enabled])
+
test "refuses to crawl incomplete URLs" do
user = insert(:user)
diff --git a/test/web/streamer_test.exs b/test/web/streamer_test.exs
index 5b7fe44d4..96fa7645f 100644
--- a/test/web/streamer_test.exs
+++ b/test/web/streamer_test.exs
@@ -11,15 +11,7 @@ defmodule Pleroma.Web.StreamerTest do
alias Pleroma.Web.Streamer
import Pleroma.Factory
- setup do
- skip_thread_containment = Pleroma.Config.get([:instance, :skip_thread_containment])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :skip_thread_containment], skip_thread_containment)
- end)
-
- :ok
- end
+ clear_config_all([:instance, :skip_thread_containment])
describe "user streams" do
setup do
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
index 8bb8aa36d..8ef14b4c5 100644
--- a/test/web/twitter_api/twitter_api_controller_test.exs
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -151,6 +151,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /statuses/public_timeline.json" do
setup [:valid_user]
+ clear_config([:instance, :public])
test "returns statuses", %{conn: conn} do
user = insert(:user)
@@ -173,8 +174,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn
|> get("/api/statuses/public_timeline.json")
|> json_response(403)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
@@ -185,8 +184,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_timeline.json")
|> json_response(200)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
@@ -220,6 +217,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "GET /statuses/public_and_external_timeline.json" do
setup [:valid_user]
+ clear_config([:instance, :public])
test "returns 403 to unauthenticated request when the instance is not public", %{conn: conn} do
Pleroma.Config.put([:instance, :public], false)
@@ -227,8 +225,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
conn
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(403)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to authenticated request when the instance is not public",
@@ -239,8 +235,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|> with_credentials(user.nickname, "test")
|> get("/api/statuses/public_and_external_timeline.json")
|> json_response(200)
-
- Pleroma.Config.put([:instance, :public], true)
end
test "returns 200 to unauthenticated request when the instance is public", %{conn: conn} do
@@ -1176,13 +1170,6 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
describe "POST /api/account/resend_confirmation_email" do
setup do
- setting = Pleroma.Config.get([:instance, :account_activation_required])
-
- unless setting do
- Pleroma.Config.put([:instance, :account_activation_required], true)
- on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
- end
-
user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, need_confirmation: true)
@@ -1197,6 +1184,10 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
[user: user]
end
+ clear_config([:instance, :account_activation_required]) do
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+ end
+
test "it returns 204 No Content", %{conn: conn, user: user} do
conn
|> assign(:user, user)
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 640579c09..fe4ffdb59 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -14,20 +14,13 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
setup do
Tesla.Mock.mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- instance_config = Pleroma.Config.get([:instance])
- pleroma_fe = Pleroma.Config.get([:frontend_configurations, :pleroma_fe])
- deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance], instance_config)
- Pleroma.Config.put([:frontend_configurations, :pleroma_fe], pleroma_fe)
- Pleroma.Config.put([:user, :deny_follow_blocked], deny_follow_blocked)
- end)
-
:ok
end
+ clear_config([:instance])
+ clear_config([:frontend_configurations, :pleroma_fe])
+ clear_config([:user, :deny_follow_blocked])
+
describe "POST /api/pleroma/follow_import" do
test "it returns HTTP 200", %{conn: conn} do
user1 = insert(:user)
@@ -260,7 +253,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
test "returns the state of safe_dm_mentions flag", %{conn: conn} do
- option = Pleroma.Config.get([:instance, :safe_dm_mentions])
Pleroma.Config.put([:instance, :safe_dm_mentions], true)
response =
@@ -278,8 +270,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|> json_response(:ok)
assert response["site"]["safeDMMentionsEnabled"] == "0"
-
- Pleroma.Config.put([:instance, :safe_dm_mentions], option)
end
test "it returns the managed config", %{conn: conn} do
@@ -534,15 +524,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
end
describe "GET /api/pleroma/healthcheck" do
- setup do
- config_healthcheck = Pleroma.Config.get([:instance, :healthcheck])
-
- on_exit(fn ->
- Pleroma.Config.put([:instance, :healthcheck], config_healthcheck)
- end)
-
- :ok
- end
+ clear_config([:instance, :healthcheck])
test "returns 503 when healthcheck disabled", %{conn: conn} do
Pleroma.Config.put([:instance, :healthcheck], false)
diff --git a/test/web/web_finger/web_finger_controller_test.exs b/test/web/web_finger/web_finger_controller_test.exs
index 7d861cbf5..e23086b2a 100644
--- a/test/web/web_finger/web_finger_controller_test.exs
+++ b/test/web/web_finger/web_finger_controller_test.exs
@@ -10,15 +10,13 @@ defmodule Pleroma.Web.WebFinger.WebFingerControllerTest do
setup do
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
-
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
:ok
end
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
+ end
+
test "GET host-meta" do
response =
build_conn()
diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs
index aa7262beb..59cacbe68 100644
--- a/test/web/websub/websub_controller_test.exs
+++ b/test/web/websub/websub_controller_test.exs
@@ -9,14 +9,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.WebsubClientSubscription
- setup_all do
- config_path = [:instance, :federating]
- initial_setting = Pleroma.Config.get(config_path)
-
- Pleroma.Config.put(config_path, true)
- on_exit(fn -> Pleroma.Config.put(config_path, initial_setting) end)
-
- :ok
+ clear_config_all([:instance, :federating]) do
+ Pleroma.Config.put([:instance, :federating], true)
end
test "websub subscription request", %{conn: conn} do
--
cgit v1.2.3
From 75a5dd41ee4a1c196487f4cf2759a4d63bc393ef Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Mon, 19 Aug 2019 16:10:00 +0000
Subject: Add more tests for Database tasks and DigestEmailWorker
---
test/web/digest_email_worker_test.exs | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
create mode 100644 test/web/digest_email_worker_test.exs
(limited to 'test/web')
diff --git a/test/web/digest_email_worker_test.exs b/test/web/digest_email_worker_test.exs
new file mode 100644
index 000000000..15002330f
--- /dev/null
+++ b/test/web/digest_email_worker_test.exs
@@ -0,0 +1,31 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.DigestEmailWorkerTest do
+ use Pleroma.DataCase
+ import Pleroma.Factory
+
+ alias Pleroma.DigestEmailWorker
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ test "it sends digest emails" do
+ user = insert(:user)
+
+ date =
+ Timex.now()
+ |> Timex.shift(days: -10)
+ |> Timex.to_naive_datetime()
+
+ user2 = insert(:user, last_digest_emailed_at: date)
+ User.switch_email_notifications(user2, "digest", true)
+ CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
+
+ DigestEmailWorker.perform()
+
+ assert_received {:email, email}
+ assert email.to == [{user2.name, user2.email}]
+ assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
+ end
+end
--
cgit v1.2.3
From 76bb3572dddf1e35697e071c94aa327382f0b990 Mon Sep 17 00:00:00 2001
From: Ariadne Conill
Date: Tue, 20 Aug 2019 20:19:23 +0000
Subject: test: rich media: aws signed url: increase TTL delta check to 2
seconds from 1
---
test/web/rich_media/aws_signed_url_test.exs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/rich_media/aws_signed_url_test.exs b/test/web/rich_media/aws_signed_url_test.exs
index 122787bc2..a3a50cbb1 100644
--- a/test/web/rich_media/aws_signed_url_test.exs
+++ b/test/web/rich_media/aws_signed_url_test.exs
@@ -60,7 +60,8 @@ defmodule Pleroma.Web.RichMedia.TTL.AwsSignedUrlTest do
{:ok, cache_ttl} = Cachex.ttl(:rich_media_cache, url)
# as there is delay in setting and pulling the data from cache we ignore 1 second
- assert_in_delta(valid_till * 1000, cache_ttl, 1000)
+ # make it 2 seconds for flakyness
+ assert_in_delta(valid_till * 1000, cache_ttl, 2000)
end
defp construct_s3_url(timestamp, valid_till) do
--
cgit v1.2.3
From 85bd8a4e31761f835cd5d79519c3644577643012 Mon Sep 17 00:00:00 2001
From: Maksim Pechnikov
Date: Wed, 21 Aug 2019 21:24:35 +0300
Subject: fixed clear config after test
---
test/web/activity_pub/activity_pub_test.exs | 2 +-
test/web/activity_pub/transmogrifier_test.exs | 2 ++
.../mastodon_api/mastodon_api_controller/update_credentials_test.exs | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)
(limited to 'test/web')
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs
index f20cd2840..1515f4eb6 100644
--- a/test/web/activity_pub/activity_pub_test.exs
+++ b/test/web/activity_pub/activity_pub_test.exs
@@ -555,7 +555,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
note_two = insert(:note, data: %{"context" => "suya.."})
activity_two = insert(:note_activity, note: note_two)
- {:ok, activity_two} = CommonAPI.add_mute(user, activity_two)
+ {:ok, _activity_two} = CommonAPI.add_mute(user, activity_two)
assert [_activity_two, _activity_one] =
ActivityPub.fetch_activities([], %{"muting_user" => user, "with_muted" => true})
diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs
index d8fbcd628..629c76c97 100644
--- a/test/web/activity_pub/transmogrifier_test.exs
+++ b/test/web/activity_pub/transmogrifier_test.exs
@@ -24,6 +24,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
:ok
end
+ clear_config([:instance, :max_remote_account_fields])
+
describe "handle_incoming" do
test "it ignores an incoming notice if we already have it" do
activity = insert(:note_activity)
diff --git a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
index dd443495b..87ee82050 100644
--- a/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller/update_credentials_test.exs
@@ -9,6 +9,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
use Pleroma.Web.ConnCase
import Pleroma.Factory
+ clear_config([:instance, :max_account_fields])
describe "updating credentials" do
test "sets user settings in a generic way", %{conn: conn} do
--
cgit v1.2.3