From bbd0049faef310d1ef9f1f04ecceee3fc924249d Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 13:24:23 +0100 Subject: Respect blocks in mass follow. --- test/user_test.exs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 98d3bc464..523ab1ea4 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -53,16 +53,20 @@ defmodule Pleroma.UserTest do followed_zero = insert(:user) followed_one = insert(:user) followed_two = insert(:user) + blocked = insert(:user) not_followed = insert(:user) + {:ok, user} = User.block(user, blocked) + {:ok, user} = User.follow(user, followed_zero) - {:ok, user} = User.follow_all(user, [followed_one, followed_two]) + {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked]) assert User.following?(user, followed_one) assert User.following?(user, followed_two) assert User.following?(user, followed_zero) refute User.following?(user, not_followed) + refute User.following?(user, blocked) end test "follow_all follows mutliple users without duplicating" do -- cgit v1.2.3 From 09189c3a7c61d15dc8c73c2474df19320f5032d0 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 14:23:51 +0100 Subject: Made a test! --- test/web/thread_mute_test.exs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/web/thread_mute_test.exs (limited to 'test') diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs new file mode 100644 index 000000000..4dea44d2f --- /dev/null +++ b/test/web/thread_mute_test.exs @@ -0,0 +1,25 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ThreadMuteTest do + use Pleroma.DataCase + import Pleroma.Web.ThreadMute + + import Pleroma.Factory + + test "add a mute" do + user = insert(:user, %{id: "1"}) + + activity = + insert(:note_activity, %{ + data: %{"context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"} + }) + + id = activity.id + {:ok, mute} = add_mute(user, id) + + assert mute.user_id == "1" + assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592" + end +end -- cgit v1.2.3 From 4430a0ad127411b818d875dbbaf14369c109f331 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 14:34:42 +0100 Subject: added another test --- test/web/thread_mute_test.exs | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs index 4dea44d2f..75277ef62 100644 --- a/test/web/thread_mute_test.exs +++ b/test/web/thread_mute_test.exs @@ -8,18 +8,33 @@ defmodule Pleroma.Web.ThreadMuteTest do import Pleroma.Factory - test "add a mute" do - user = insert(:user, %{id: "1"}) + describe "mute tests" do + setup do + user = insert(:user, %{id: "1"}) - activity = - insert(:note_activity, %{ - data: %{"context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592"} - }) + activity = + insert(:note_activity, %{ + data: %{ + "context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592" + } + }) - id = activity.id - {:ok, mute} = add_mute(user, id) + [user: user, activity: activity] + end - assert mute.user_id == "1" - assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592" + test "add mute", %{user: user, activity: activity} do + id = activity.id + {:ok, mute} = add_mute(user, id) + + assert mute.user_id == "1" + assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592" + end + + test "remove mute", %{user: user, activity: activity} do + id = activity.id + + add_mute(user, id) + {1, nil} = remove_mute(user, id) + end end end -- cgit v1.2.3 From a0d732ec55fcbce8cf345344d1456dc77bb0f3bf Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 17:47:57 +0100 Subject: it works!! --- test/web/thread_mute_test.exs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs index 75277ef62..212cae860 100644 --- a/test/web/thread_mute_test.exs +++ b/test/web/thread_mute_test.exs @@ -10,31 +10,32 @@ defmodule Pleroma.Web.ThreadMuteTest do describe "mute tests" do setup do - user = insert(:user, %{id: "1"}) + user = insert(:user) - activity = - insert(:note_activity, %{ - data: %{ - "context" => "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592" - } - }) + activity = insert(:note_activity) [user: user, activity: activity] end test "add mute", %{user: user, activity: activity} do id = activity.id - {:ok, mute} = add_mute(user, id) - - assert mute.user_id == "1" - assert mute.context == "http://localhost:4000/contexts/361ca23e-ffa7-4773-b981-a355a18dc592" + {:ok, _activity} = add_mute(user, id) end test "remove mute", %{user: user, activity: activity} do id = activity.id add_mute(user, id) - {1, nil} = remove_mute(user, id) + {:ok, _activity} = remove_mute(user, id) + end + + test "check mute", %{user: user, activity: activity} do + id = activity.id + + add_mute(user, id) + assert muted?(user, activity) + remove_mute(user, id) + refute muted?(user, activity) end end end -- cgit v1.2.3 From 478a05b4c99d696846b71d0eb4d6982ba422bfb8 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 18:34:00 +0100 Subject: Merged "check mute" test into the other two --- test/web/thread_mute_test.exs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'test') diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs index 212cae860..119a06f52 100644 --- a/test/web/thread_mute_test.exs +++ b/test/web/thread_mute_test.exs @@ -20,6 +20,7 @@ defmodule Pleroma.Web.ThreadMuteTest do test "add mute", %{user: user, activity: activity} do id = activity.id {:ok, _activity} = add_mute(user, id) + assert muted?(user, activity) end test "remove mute", %{user: user, activity: activity} do @@ -27,14 +28,6 @@ defmodule Pleroma.Web.ThreadMuteTest do add_mute(user, id) {:ok, _activity} = remove_mute(user, id) - end - - test "check mute", %{user: user, activity: activity} do - id = activity.id - - add_mute(user, id) - assert muted?(user, activity) - remove_mute(user, id) refute muted?(user, activity) end end -- cgit v1.2.3 From 6a150de3bd416cfe0b4870deee2e6557791345f8 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 9 Feb 2019 20:52:11 +0100 Subject: Add unique index and unique constraint check, uniqueness test fails --- test/web/thread_mute_test.exs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs index 119a06f52..f3a24613c 100644 --- a/test/web/thread_mute_test.exs +++ b/test/web/thread_mute_test.exs @@ -18,17 +18,20 @@ defmodule Pleroma.Web.ThreadMuteTest do end test "add mute", %{user: user, activity: activity} do - id = activity.id - {:ok, _activity} = add_mute(user, id) + {:ok, _activity} = add_mute(user, activity.id) assert muted?(user, activity) end test "remove mute", %{user: user, activity: activity} do - id = activity.id - - add_mute(user, id) - {:ok, _activity} = remove_mute(user, id) + add_mute(user, activity.id) + {:ok, _activity} = remove_mute(user, activity.id) refute muted?(user, activity) end + + test "check that mutes can't be duplicate", %{user: user, activity: activity} do + add_mute(user, activity.id) + assert muted?(user, activity) + {:error, _} = add_mute(user, activity.id) + end end end -- cgit v1.2.3 From f8388be9c69981958e9a96dce68fc39bdedb5cd3 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 9 Feb 2019 22:01:08 +0100 Subject: Do object insertion through Cachex So we don't flood our postgres logs with errors. Should also make things slightly faster. --- test/object_test.exs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/object_test.exs b/test/object_test.exs index 72194975d..ab6431012 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -57,4 +57,32 @@ defmodule Pleroma.ObjectTest do assert cached_object.data["type"] == "Tombstone" end end + + describe "insert_or_get" do + test "inserting the same object twice (by id) just returns the original object" do + data = %{data: %{"id" => Ecto.UUID.generate()}} + cng = Object.change(%Object{}, data) + {:ok, object} = Object.insert_or_get(cng) + {:ok, second_object} = Object.insert_or_get(cng) + + Cachex.clear(:object_cache) + {:ok, third_object} = Object.insert_or_get(cng) + + assert object == second_object + assert object == third_object + end + end + + describe "create" do + test "inserts an object for a given data set" do + data = %{"id" => Ecto.UUID.generate()} + + {:ok, object} = Object.create(data) + assert object.data["id"] == data["id"] + + # Works when doing it twice. + {:ok, object} = Object.create(data) + assert object.data["id"] == data["id"] + end + end end -- cgit v1.2.3 From 8bb7e19b3814e261e66c2d3592d146f72d4ce623 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sun, 10 Feb 2019 22:57:38 +0100 Subject: test: de-group alias/es --- test/notification_test.exs | 3 ++- test/object_test.exs | 3 ++- test/support/builders/user_builder.ex | 3 ++- test/tasks/relay_test.exs | 4 +++- test/user_test.exs | 4 +++- test/web/activity_pub/activity_pub_controller_test.exs | 9 +++++++-- test/web/activity_pub/activity_pub_test.exs | 5 ++++- test/web/admin_api/admin_api_controller_test.exs | 3 ++- test/web/common_api/common_api_utils_test.exs | 2 +- test/web/federator_test.exs | 3 ++- test/web/mastodon_api/mastodon_api_controller_test.exs | 9 +++++++-- test/web/mastodon_api/status_view_test.exs | 3 ++- test/web/oauth/authorization_test.exs | 3 ++- test/web/oauth/oauth_controller_test.exs | 3 ++- test/web/oauth/token_test.exs | 4 +++- test/web/ostatus/activity_representer_test.exs | 4 +++- test/web/ostatus/feed_representer_test.exs | 4 +++- test/web/ostatus/incoming_documents/delete_handling_test.exs | 4 +++- test/web/ostatus/ostatus_controller_test.exs | 4 +++- test/web/ostatus/ostatus_test.exs | 6 +++++- test/web/salmon/salmon_test.exs | 4 +++- test/web/twitter_api/representers/activity_representer_test.exs | 7 +++++-- test/web/twitter_api/twitter_api_controller_test.exs | 9 +++++++-- test/web/twitter_api/twitter_api_test.exs | 9 +++++++-- test/web/twitter_api/views/notification_view_test.exs | 3 ++- test/web/websub/websub_controller_test.exs | 3 ++- test/web/websub/websub_test.exs | 3 ++- 27 files changed, 89 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index 94fb0ab15..d36a92a7c 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -6,7 +6,8 @@ defmodule Pleroma.NotificationTest do use Pleroma.DataCase alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.CommonAPI - alias Pleroma.{User, Notification} + alias Pleroma.User + alias Pleroma.Notification alias Pleroma.Web.ActivityPub.Transmogrifier import Pleroma.Factory diff --git a/test/object_test.exs b/test/object_test.exs index ab6431012..9f5283d2d 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -5,7 +5,8 @@ defmodule Pleroma.ObjectTest do use Pleroma.DataCase import Pleroma.Factory - alias Pleroma.{Repo, Object} + alias Pleroma.Repo + alias Pleroma.Object test "returns an object by it's AP id" do object = insert(:note) diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex index 7a1ca79b5..611a5be18 100644 --- a/test/support/builders/user_builder.ex +++ b/test/support/builders/user_builder.ex @@ -1,5 +1,6 @@ defmodule Pleroma.Builders.UserBuilder do - alias Pleroma.{User, Repo} + alias Pleroma.User + alias Pleroma.Repo def build(data \\ %{}) do user = %User{ diff --git a/test/tasks/relay_test.exs b/test/tasks/relay_test.exs index 96fac4811..64ff07753 100644 --- a/test/tasks/relay_test.exs +++ b/test/tasks/relay_test.exs @@ -4,7 +4,9 @@ defmodule Mix.Tasks.Pleroma.RelayTest do alias Pleroma.Activity - alias Pleroma.Web.ActivityPub.{ActivityPub, Relay, Utils} + alias Pleroma.Web.ActivityPub.ActivityPub + alias Pleroma.Web.ActivityPub.Utils + alias Pleroma.Web.ActivityPub.Relay alias Pleroma.User use Pleroma.DataCase diff --git a/test/user_test.exs b/test/user_test.exs index 523ab1ea4..1fd54b944 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -4,7 +4,9 @@ defmodule Pleroma.UserTest do alias Pleroma.Builders.UserBuilder - alias Pleroma.{User, Repo, Activity} + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.User alias Pleroma.Web.CommonAPI use Pleroma.DataCase diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 570bee6b3..acd295988 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -5,8 +5,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.Web.ActivityPub.{UserView, ObjectView} - alias Pleroma.{Object, Repo, Activity, User, Instances} + alias Pleroma.Web.ActivityPub.UserView + alias Pleroma.Web.ActivityPub.ObjectView + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Instances setup_all do Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index a55961ac4..a6f8b822a 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -7,7 +7,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.CommonAPI - alias Pleroma.{Activity, Object, User, Instances} + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.User + alias Pleroma.Instances alias Pleroma.Builders.ActivityBuilder import Pleroma.Factory diff --git a/test/web/admin_api/admin_api_controller_test.exs b/test/web/admin_api/admin_api_controller_test.exs index 42450a7b6..a27c26f95 100644 --- a/test/web/admin_api/admin_api_controller_test.exs +++ b/test/web/admin_api/admin_api_controller_test.exs @@ -5,7 +5,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do use Pleroma.Web.ConnCase - alias Pleroma.{Repo, User} + alias Pleroma.Repo + alias Pleroma.User import Pleroma.Factory describe "/api/pleroma/admin/user" do diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index 754bc7255..faed6b685 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -5,7 +5,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.Endpoint - alias Pleroma.Builders.{UserBuilder} + alias Pleroma.Builders.UserBuilder use Pleroma.DataCase test "it adds attachment links to a given text and attachment set" do diff --git a/test/web/federator_test.exs b/test/web/federator_test.exs index 05f813291..9f8d71454 100644 --- a/test/web/federator_test.exs +++ b/test/web/federator_test.exs @@ -3,7 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.FederatorTest do - alias Pleroma.Web.{CommonAPI, Federator} + alias Pleroma.Web.CommonAPI + alias Pleroma.Web.Federator alias Pleroma.Instances use Pleroma.DataCase import Pleroma.Factory diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index f8da86004..9fd505f84 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -6,8 +6,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do use Pleroma.Web.ConnCase alias Pleroma.Web.TwitterAPI.TwitterAPI - alias Pleroma.{Repo, User, Object, Activity, Notification} - alias Pleroma.Web.{OStatus, CommonAPI} + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Activity + alias Pleroma.Notification + alias Pleroma.Web.OStatus + alias Pleroma.Web.CommonAPI alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.MastodonAPI.FilterView alias Ecto.Changeset diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs index 2106253f2..0dc9c538c 100644 --- a/test/web/mastodon_api/status_view_test.exs +++ b/test/web/mastodon_api/status_view_test.exs @@ -5,7 +5,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do use Pleroma.DataCase - alias Pleroma.Web.MastodonAPI.{StatusView, AccountView} + alias Pleroma.Web.MastodonAPI.AccountView + alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.User alias Pleroma.Web.OStatus alias Pleroma.Web.CommonAPI diff --git a/test/web/oauth/authorization_test.exs b/test/web/oauth/authorization_test.exs index 3b1ddada8..81618e935 100644 --- a/test/web/oauth/authorization_test.exs +++ b/test/web/oauth/authorization_test.exs @@ -4,7 +4,8 @@ defmodule Pleroma.Web.OAuth.AuthorizationTest do use Pleroma.DataCase - alias Pleroma.Web.OAuth.{Authorization, App} + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.App import Pleroma.Factory test "create an authorization token for a valid app" do diff --git a/test/web/oauth/oauth_controller_test.exs b/test/web/oauth/oauth_controller_test.exs index e0d3cb55f..2315f9a34 100644 --- a/test/web/oauth/oauth_controller_test.exs +++ b/test/web/oauth/oauth_controller_test.exs @@ -7,7 +7,8 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do import Pleroma.Factory alias Pleroma.Repo - alias Pleroma.Web.OAuth.{Authorization, Token} + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.Token test "redirects with oauth authorization" do user = insert(:user) diff --git a/test/web/oauth/token_test.exs b/test/web/oauth/token_test.exs index 9a241d61a..4dab4a308 100644 --- a/test/web/oauth/token_test.exs +++ b/test/web/oauth/token_test.exs @@ -4,7 +4,9 @@ defmodule Pleroma.Web.OAuth.TokenTest do use Pleroma.DataCase - alias Pleroma.Web.OAuth.{App, Token, Authorization} + alias Pleroma.Web.OAuth.App + alias Pleroma.Web.OAuth.Authorization + alias Pleroma.Web.OAuth.Token alias Pleroma.Repo import Pleroma.Factory diff --git a/test/web/ostatus/activity_representer_test.exs b/test/web/ostatus/activity_representer_test.exs index 0869f2fd5..eebc5c040 100644 --- a/test/web/ostatus/activity_representer_test.exs +++ b/test/web/ostatus/activity_representer_test.exs @@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do use Pleroma.DataCase alias Pleroma.Web.OStatus.ActivityRepresenter - alias Pleroma.{User, Activity, Object} + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Object alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.OStatus diff --git a/test/web/ostatus/feed_representer_test.exs b/test/web/ostatus/feed_representer_test.exs index 55717dec7..efd4e7217 100644 --- a/test/web/ostatus/feed_representer_test.exs +++ b/test/web/ostatus/feed_representer_test.exs @@ -6,7 +6,9 @@ defmodule Pleroma.Web.OStatus.FeedRepresenterTest do use Pleroma.DataCase import Pleroma.Factory alias Pleroma.User - alias Pleroma.Web.OStatus.{FeedRepresenter, UserRepresenter, ActivityRepresenter} + alias Pleroma.Web.OStatus.ActivityRepresenter + alias Pleroma.Web.OStatus.FeedRepresenter + alias Pleroma.Web.OStatus.UserRepresenter alias Pleroma.Web.OStatus test "returns a feed of the last 20 items of the user" do diff --git a/test/web/ostatus/incoming_documents/delete_handling_test.exs b/test/web/ostatus/incoming_documents/delete_handling_test.exs index d97cd79f4..d295cc539 100644 --- a/test/web/ostatus/incoming_documents/delete_handling_test.exs +++ b/test/web/ostatus/incoming_documents/delete_handling_test.exs @@ -4,7 +4,9 @@ defmodule Pleroma.Web.OStatus.DeleteHandlingTest do import Pleroma.Factory import Tesla.Mock - alias Pleroma.{Repo, Activity, Object} + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.Object alias Pleroma.Web.OStatus setup do diff --git a/test/web/ostatus/ostatus_controller_test.exs b/test/web/ostatus/ostatus_controller_test.exs index 3145ca9a1..da9c72be8 100644 --- a/test/web/ostatus/ostatus_controller_test.exs +++ b/test/web/ostatus/ostatus_controller_test.exs @@ -5,7 +5,9 @@ defmodule Pleroma.Web.OStatus.OStatusControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory - alias Pleroma.{User, Repo, Object} + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Object alias Pleroma.Web.CommonAPI alias Pleroma.Web.OStatus.ActivityRepresenter diff --git a/test/web/ostatus/ostatus_test.exs b/test/web/ostatus/ostatus_test.exs index dbe5de2e2..b4b19ab05 100644 --- a/test/web/ostatus/ostatus_test.exs +++ b/test/web/ostatus/ostatus_test.exs @@ -6,7 +6,11 @@ defmodule Pleroma.Web.OStatusTest do use Pleroma.DataCase alias Pleroma.Web.OStatus alias Pleroma.Web.XML - alias Pleroma.{Object, Repo, User, Activity, Instances} + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Instances import Pleroma.Factory import ExUnit.CaptureLog diff --git a/test/web/salmon/salmon_test.exs b/test/web/salmon/salmon_test.exs index c539a28b2..9e583ba40 100644 --- a/test/web/salmon/salmon_test.exs +++ b/test/web/salmon/salmon_test.exs @@ -5,7 +5,9 @@ defmodule Pleroma.Web.Salmon.SalmonTest do use Pleroma.DataCase alias Pleroma.Web.Salmon - alias Pleroma.{Repo, Activity, User} + alias Pleroma.Activity + alias Pleroma.Repo + alias Pleroma.User import Pleroma.Factory @magickey "RSA.pu0s-halox4tu7wmES1FVSx6u-4wc0YrUFXcqWXZG4-27UmbCOpMQftRCldNRfyA-qLbz-eqiwQhh-1EwUvjsD4cYbAHNGHwTvDOyx5AKthQUP44ykPv7kjKGh3DWKySJvcs9tlUG87hlo7AvnMo9pwRS_Zz2CacQ-MKaXyDepk=.AQAB" diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index ea5813733..365c7f659 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -4,8 +4,11 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do use Pleroma.DataCase - alias Pleroma.{User, Activity, Object} - alias Pleroma.Web.TwitterAPI.Representers.{ActivityRepresenter, ObjectRepresenter} + alias Pleroma.User + alias Pleroma.Activity + alias Pleroma.Object + alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter + alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView import Pleroma.Factory diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 855ae1526..acb03b146 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -5,8 +5,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do use Pleroma.Web.ConnCase alias Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter - alias Pleroma.Builders.{ActivityBuilder, UserBuilder} - alias Pleroma.{Repo, Activity, User, Object, Notification} + alias Pleroma.Builders.ActivityBuilder + alias Pleroma.Builders.UserBuilder + alias Pleroma.Repo + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Notification alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.NotificationView diff --git a/test/web/twitter_api/twitter_api_test.exs b/test/web/twitter_api/twitter_api_test.exs index 48ddbcf50..aa2a4d650 100644 --- a/test/web/twitter_api/twitter_api_test.exs +++ b/test/web/twitter_api/twitter_api_test.exs @@ -4,8 +4,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do use Pleroma.DataCase - alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView} - alias Pleroma.{Activity, User, Object, Repo, UserInviteToken} + alias Pleroma.Web.TwitterAPI.TwitterAPI + alias Pleroma.Web.TwitterAPI.UserView + alias Pleroma.Activity + alias Pleroma.User + alias Pleroma.Object + alias Pleroma.Repo + alias Pleroma.UserInviteToken alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.TwitterAPI.ActivityView diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs index 8367fc6c7..3a67f7292 100644 --- a/test/web/twitter_api/views/notification_view_test.exs +++ b/test/web/twitter_api/views/notification_view_test.exs @@ -5,7 +5,8 @@ defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do use Pleroma.DataCase - alias Pleroma.{User, Notification} + alias Pleroma.User + alias Pleroma.Notification alias Pleroma.Web.TwitterAPI.TwitterAPI alias Pleroma.Web.TwitterAPI.NotificationView alias Pleroma.Web.TwitterAPI.UserView diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 6492df2a0..04fb4a5a3 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -6,7 +6,8 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do use Pleroma.Web.ConnCase import Pleroma.Factory alias Pleroma.Web.Websub.WebsubClientSubscription - alias Pleroma.{Repo, Activity} + alias Pleroma.Activity + alias Pleroma.Repo alias Pleroma.Web.Websub test "websub subscription request", %{conn: conn} do diff --git a/test/web/websub/websub_test.exs b/test/web/websub/websub_test.exs index 9751d161d..9a9b9df02 100644 --- a/test/web/websub/websub_test.exs +++ b/test/web/websub/websub_test.exs @@ -5,7 +5,8 @@ defmodule Pleroma.Web.WebsubTest do use Pleroma.DataCase alias Pleroma.Web.Websub - alias Pleroma.Web.Websub.{WebsubServerSubscription, WebsubClientSubscription} + alias Pleroma.Web.Websub.WebsubServerSubscription + alias Pleroma.Web.Websub.WebsubClientSubscription import Pleroma.Factory alias Pleroma.Web.Router.Helpers import Tesla.Mock -- cgit v1.2.3 From 74579115a73d697aed67abe2dc8ea1a664c89c5b Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Mon, 11 Feb 2019 00:08:48 +0100 Subject: =?UTF-8?q?test:=20Change=20`lenght(=E2=80=A6)=20=3D=3D=200`=20to?= =?UTF-8?q?=20`Enum.empty=3F(=E2=80=A6)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/formatter_test.exs | 2 +- test/notification_test.exs | 30 +++++++++++----------- test/tasks/user_test.exs | 2 +- .../mastodon_api/mastodon_api_controller_test.exs | 2 +- test/web/websub/websub_controller_test.exs | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/formatter_test.exs b/test/formatter_test.exs index 2e717194b..f14077d25 100644 --- a/test/formatter_test.exs +++ b/test/formatter_test.exs @@ -197,7 +197,7 @@ defmodule Pleroma.FormatterTest do {subs, text} = Formatter.add_user_links({[], text}, mentions) - assert length(subs) == 0 + assert Enum.empty?(subs) Enum.each(subs, fn {uuid, _} -> assert String.contains?(text, uuid) end) expected_text = "@a hi" diff --git a/test/notification_test.exs b/test/notification_test.exs index d36a92a7c..755874a3d 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -300,7 +300,7 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) @@ -308,7 +308,7 @@ defmodule Pleroma.NotificationTest do {:ok, _} = CommonAPI.delete(activity.id, user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end test "liking an activity results in 1 notification, then 0 if the activity is unliked" do @@ -317,7 +317,7 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:ok, _, _} = CommonAPI.favorite(activity.id, other_user) @@ -325,7 +325,7 @@ defmodule Pleroma.NotificationTest do {:ok, _, _, _} = CommonAPI.unfavorite(activity.id, other_user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end test "repeating an activity results in 1 notification, then 0 if the activity is deleted" do @@ -334,7 +334,7 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:ok, _, _} = CommonAPI.repeat(activity.id, other_user) @@ -342,7 +342,7 @@ defmodule Pleroma.NotificationTest do {:ok, _} = CommonAPI.delete(activity.id, user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end test "repeating an activity results in 1 notification, then 0 if the activity is unrepeated" do @@ -351,7 +351,7 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:ok, _, _} = CommonAPI.repeat(activity.id, other_user) @@ -359,7 +359,7 @@ defmodule Pleroma.NotificationTest do {:ok, _, _} = CommonAPI.unrepeat(activity.id, other_user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end test "liking an activity which is already deleted does not generate a notification" do @@ -368,15 +368,15 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:error, _} = CommonAPI.favorite(activity.id, other_user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end test "repeating an activity which is already deleted does not generate a notification" do @@ -385,15 +385,15 @@ defmodule Pleroma.NotificationTest do {:ok, activity} = CommonAPI.post(user, %{"status" => "test post"}) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:ok, _deletion_activity} = CommonAPI.delete(activity.id, user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) {:error, _} = CommonAPI.repeat(activity.id, other_user) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end test "replying to a deleted post without tagging does not generate a notification" do @@ -409,7 +409,7 @@ defmodule Pleroma.NotificationTest do "in_reply_to_status_id" => activity.id }) - assert length(Notification.for_user(user)) == 0 + assert Enum.empty?(Notification.for_user(user)) end end end diff --git a/test/tasks/user_test.exs b/test/tasks/user_test.exs index 44271898c..7b814d171 100644 --- a/test/tasks/user_test.exs +++ b/test/tasks/user_test.exs @@ -151,7 +151,7 @@ defmodule Mix.Tasks.Pleroma.UserTest do assert message =~ "Successfully unsubscribed" user = User.get_by_nickname(user.nickname) - assert length(user.following) == 0 + assert Enum.empty?(user.following) assert user.info.deactivated end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index 9fd505f84..19393f355 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -36,7 +36,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> assign(:user, user) |> get("/api/v1/timelines/home") - assert length(json_response(conn, 200)) == 0 + assert Enum.empty?(json_response(conn, 200)) {:ok, user} = User.follow(user, following) diff --git a/test/web/websub/websub_controller_test.exs b/test/web/websub/websub_controller_test.exs index 04fb4a5a3..87b01d89b 100644 --- a/test/web/websub/websub_controller_test.exs +++ b/test/web/websub/websub_controller_test.exs @@ -81,7 +81,7 @@ defmodule Pleroma.Web.Websub.WebsubControllerTest do assert response(conn, 500) == "Error" - assert length(Repo.all(Activity)) == 0 + assert Enum.empty?(Repo.all(Activity)) end end end -- cgit v1.2.3 From d53e36bf1e004177277cb5917bb290d512278aa9 Mon Sep 17 00:00:00 2001 From: lambda Date: Mon, 11 Feb 2019 08:07:39 +0000 Subject: Revert "Merge branch 'object-creation' into 'develop'" This reverts merge request !802 --- test/object_test.exs | 28 ---------------------------- 1 file changed, 28 deletions(-) (limited to 'test') diff --git a/test/object_test.exs b/test/object_test.exs index ab6431012..72194975d 100644 --- a/test/object_test.exs +++ b/test/object_test.exs @@ -57,32 +57,4 @@ defmodule Pleroma.ObjectTest do assert cached_object.data["type"] == "Tombstone" end end - - describe "insert_or_get" do - test "inserting the same object twice (by id) just returns the original object" do - data = %{data: %{"id" => Ecto.UUID.generate()}} - cng = Object.change(%Object{}, data) - {:ok, object} = Object.insert_or_get(cng) - {:ok, second_object} = Object.insert_or_get(cng) - - Cachex.clear(:object_cache) - {:ok, third_object} = Object.insert_or_get(cng) - - assert object == second_object - assert object == third_object - end - end - - describe "create" do - test "inserts an object for a given data set" do - data = %{"id" => Ecto.UUID.generate()} - - {:ok, object} = Object.create(data) - assert object.data["id"] == data["id"] - - # Works when doing it twice. - {:ok, object} = Object.create(data) - assert object.data["id"] == data["id"] - end - end end -- cgit v1.2.3 From c01ef574c192488c2643a20b4064439757613449 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 11 Feb 2019 11:59:51 +0100 Subject: Refactor as per Rin's suggestions, add endpoint tests --- test/web/common_api/common_api_test.exs | 26 +++++++++++++++ .../mastodon_api/mastodon_api_controller_test.exs | 33 +++++++++++++++++++ test/web/thread_mute_test.exs | 37 ---------------------- 3 files changed, 59 insertions(+), 37 deletions(-) delete mode 100644 test/web/thread_mute_test.exs (limited to 'test') diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index a7d9e6161..d26b6e49c 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -164,4 +164,30 @@ defmodule Pleroma.Web.CommonAPI.Test do assert %User{info: %{pinned_activities: []}} = user end end + + describe "mute tests" do + setup do + user = insert(:user) + + activity = insert(:note_activity) + + [user: user, activity: activity] + end + + test "add mute", %{user: user, activity: activity} do + {:ok, _} = CommonAPI.add_mute(user, activity) + assert CommonAPI.thread_muted?(user, activity) + end + + test "remove mute", %{user: user, activity: activity} do + CommonAPI.add_mute(user, activity) + {:ok, _} = CommonAPI.remove_mute(user, activity) + refute CommonAPI.thread_muted?(user, activity) + end + + test "check that mutes can't be duplicate", %{user: user, activity: activity} do + CommonAPI.add_mute(user, activity) + {:error, _} = CommonAPI.add_mute(user, activity) + end + end end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index f8da86004..f7c059663 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1749,4 +1749,37 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert [json_response(response2, 200)] == json_response(bookmarks, 200) end + + describe "conversation muting" do + setup do + + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "HIE"}) + + [user: user, activity: activity] + end + + test "mute conversation", %{conn: conn, user: user, activity: activity} do + id_str = to_string(activity.id) + + assert %{"id" => ^id_str, "muted" => true} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/mute") + |> json_response(200) + end + + test "unmute conversation", %{conn: conn, user: user, activity: activity} do + {:ok, _} = CommonAPI.add_mute(user, activity) + + id_str = to_string(activity.id) + user = refresh_record(user) + + assert %{"id" => ^id_str, "muted" => false} = + conn + |> assign(:user, user) + |> post("/api/v1/statuses/#{activity.id}/unmute") + |> json_response(200) + end + end end diff --git a/test/web/thread_mute_test.exs b/test/web/thread_mute_test.exs deleted file mode 100644 index f3a24613c..000000000 --- a/test/web/thread_mute_test.exs +++ /dev/null @@ -1,37 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.ThreadMuteTest do - use Pleroma.DataCase - import Pleroma.Web.ThreadMute - - import Pleroma.Factory - - describe "mute tests" do - setup do - user = insert(:user) - - activity = insert(:note_activity) - - [user: user, activity: activity] - end - - test "add mute", %{user: user, activity: activity} do - {:ok, _activity} = add_mute(user, activity.id) - assert muted?(user, activity) - end - - test "remove mute", %{user: user, activity: activity} do - add_mute(user, activity.id) - {:ok, _activity} = remove_mute(user, activity.id) - refute muted?(user, activity) - end - - test "check that mutes can't be duplicate", %{user: user, activity: activity} do - add_mute(user, activity.id) - assert muted?(user, activity) - {:error, _} = add_mute(user, activity.id) - end - end -end -- cgit v1.2.3 From 379d04692cdbf558c611c588c0e6a4262c02a58c Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 11 Feb 2019 21:35:40 +0300 Subject: Filter summary in keywordpolicy --- test/web/activity_pub/mrf/keyword_policy_test.exs | 132 ++++++++++++++++++++-- 1 file changed, 120 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/mrf/keyword_policy_test.exs b/test/web/activity_pub/mrf/keyword_policy_test.exs index 67a5858d7..602892a37 100644 --- a/test/web/activity_pub/mrf/keyword_policy_test.exs +++ b/test/web/activity_pub/mrf/keyword_policy_test.exs @@ -12,18 +12,35 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do end describe "rejecting based on keywords" do - test "rejects if string matches" do + test "rejects if string matches in content" do Pleroma.Config.put([:mrf_keyword, :reject], ["pun"]) message = %{ "type" => "Create", - "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"} + "object" => %{ + "content" => "just a daily reminder that compLAINer is a good pun", + "summary" => "" + } } assert {:reject, nil} == KeywordPolicy.filter(message) end - test "rejects if regex matches" do + test "rejects if string matches in summary" do + Pleroma.Config.put([:mrf_keyword, :reject], ["pun"]) + + message = %{ + "type" => "Create", + "object" => %{ + "summary" => "just a daily reminder that compLAINer is a good pun", + "content" => "" + } + } + + assert {:reject, nil} == KeywordPolicy.filter(message) + end + + test "rejects if regex matches in content" do Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/]) assert true == @@ -31,7 +48,25 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do message = %{ "type" => "Create", "object" => %{ - "content" => "just a daily reminder that #{content} is a good pun" + "content" => "just a daily reminder that #{content} is a good pun", + "summary" => "" + } + } + + {:reject, nil} == KeywordPolicy.filter(message) + end) + end + + test "rejects if regex matches in summary" do + Pleroma.Config.put([:mrf_keyword, :reject], [~r/comp[lL][aA][iI][nN]er/]) + + assert true == + Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content -> + message = %{ + "type" => "Create", + "object" => %{ + "summary" => "just a daily reminder that #{content} is a good pun", + "content" => "" } } @@ -41,13 +76,16 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do end describe "delisting from ftl based on keywords" do - test "delists if string matches" do + test "delists if string matches in content" do Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"]) message = %{ "to" => ["https://www.w3.org/ns/activitystreams#Public"], "type" => "Create", - "object" => %{"content" => "just a daily reminder that compLAINer is a good pun"} + "object" => %{ + "content" => "just a daily reminder that compLAINer is a good pun", + "summary" => "" + } } {:ok, result} = KeywordPolicy.filter(message) @@ -55,7 +93,45 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"] end - test "delists if regex matches" do + test "delists if string matches in summary" do + Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], ["pun"]) + + message = %{ + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "type" => "Create", + "object" => %{ + "summary" => "just a daily reminder that compLAINer is a good pun", + "content" => "" + } + } + + {:ok, result} = KeywordPolicy.filter(message) + assert ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"] + refute ["https://www.w3.org/ns/activitystreams#Public"] == result["to"] + end + + test "delists if regex matches in content" do + Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/]) + + assert true == + Enum.all?(["complainer", "compLainer", "compLAiNer", "compLAINer"], fn content -> + message = %{ + "type" => "Create", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "object" => %{ + "content" => "just a daily reminder that #{content} is a good pun", + "summary" => "" + } + } + + {:ok, result} = KeywordPolicy.filter(message) + + ["https://www.w3.org/ns/activitystreams#Public"] == result["cc"] and + not (["https://www.w3.org/ns/activitystreams#Public"] == result["to"]) + end) + end + + test "delists if regex matches in summary" do Pleroma.Config.put([:mrf_keyword, :federated_timeline_removal], [~r/comp[lL][aA][iI][nN]er/]) assert true == @@ -64,7 +140,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do "type" => "Create", "to" => ["https://www.w3.org/ns/activitystreams#Public"], "object" => %{ - "content" => "just a daily reminder that #{content} is a good pun" + "summary" => "just a daily reminder that #{content} is a good pun", + "content" => "" } } @@ -77,20 +154,33 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do end describe "replacing keywords" do - test "replaces keyword if string matches" do + test "replaces keyword if string matches in content" do Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}]) message = %{ "type" => "Create", "to" => ["https://www.w3.org/ns/activitystreams#Public"], - "object" => %{"content" => "ZFS is opensource"} + "object" => %{"content" => "ZFS is opensource", "summary" => ""} } {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message) assert result == "ZFS is free software" end - test "replaces keyword if regex matches" do + test "replaces keyword if string matches in summary" do + Pleroma.Config.put([:mrf_keyword, :replace], [{"opensource", "free software"}]) + + message = %{ + "type" => "Create", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "object" => %{"summary" => "ZFS is opensource", "content" => ""} + } + + {:ok, %{"object" => %{"summary" => result}}} = KeywordPolicy.filter(message) + assert result == "ZFS is free software" + end + + test "replaces keyword if regex matches in content" do Pleroma.Config.put([:mrf_keyword, :replace], [ {~r/open(-|\s)?source\s?(software)?/, "free software"} ]) @@ -100,12 +190,30 @@ defmodule Pleroma.Web.ActivityPub.MRF.KeywordPolicyTest do message = %{ "type" => "Create", "to" => ["https://www.w3.org/ns/activitystreams#Public"], - "object" => %{"content" => "ZFS is #{content}"} + "object" => %{"content" => "ZFS is #{content}", "summary" => ""} } {:ok, %{"object" => %{"content" => result}}} = KeywordPolicy.filter(message) result == "ZFS is free software" end) end + + test "replaces keyword if regex matches in summary" do + Pleroma.Config.put([:mrf_keyword, :replace], [ + {~r/open(-|\s)?source\s?(software)?/, "free software"} + ]) + + assert true == + Enum.all?(["opensource", "open-source", "open source"], fn content -> + message = %{ + "type" => "Create", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "object" => %{"summary" => "ZFS is #{content}", "content" => ""} + } + + {:ok, %{"object" => %{"summary" => result}}} = KeywordPolicy.filter(message) + result == "ZFS is free software" + end) + end end end -- cgit v1.2.3 From 88a4de24f9bc6fc73696cb5c986440c2c659b636 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 13 Feb 2019 13:52:27 +0100 Subject: User.follow_all: Respect blocks in both directions. --- test/user_test.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 523ab1ea4..a282274ce 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -55,18 +55,21 @@ defmodule Pleroma.UserTest do followed_two = insert(:user) blocked = insert(:user) not_followed = insert(:user) + reverse_blocked = insert(:user) {:ok, user} = User.block(user, blocked) + {:ok, reverse_blocked} = User.block(reverse_blocked, user) {:ok, user} = User.follow(user, followed_zero) - {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked]) + {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked]) assert User.following?(user, followed_one) assert User.following?(user, followed_two) assert User.following?(user, followed_zero) refute User.following?(user, not_followed) refute User.following?(user, blocked) + refute User.following?(user, reverse_blocked) end test "follow_all follows mutliple users without duplicating" do -- cgit v1.2.3 From d54c483964692e1ca6b813d6b35a0635d3c0abf9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 13 Feb 2019 19:48:24 +0000 Subject: tests: add tests for endpoints --- test/web/activity_pub/views/user_view_test.exs | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 7fc870e96..95d736c50 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -15,4 +15,32 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do assert String.contains?(result["publicKey"]["publicKeyPem"], "BEGIN PUBLIC KEY") end + + describe "endpoints" do + test "local users have a usable endpoints structure" do + user = insert(:user) + {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user) + + result = UserView.render("user.json", %{user: user}) + + assert result["id"] == user.ap_id + + %{ + "sharedInbox" => _, + "oauthAuthorizationEndpoint" => _, + "oauthRegistrationEndpoint" => _, + "oauthTokenEndpoint" => _ + } = result["endpoints"] + end + + test "remote users have an empty endpoints structure" do + user = insert(:user, local: false) + {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user) + + result = UserView.render("user.json", %{user: user}) + + assert result["id"] == user.ap_id + assert result["endpoints"] == %{} + end + end end -- cgit v1.2.3 From 889ad95a2a766b82d17aa148d92754ecda244bf7 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 00:59:18 +0000 Subject: tests: add some reserialization tests based on IR differences --- test/web/activity_pub/transmogrifier_test.exs | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index e5e3c8d33..86c66deff 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -1128,4 +1128,58 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do ) end end + + describe "reserialization" do + test "successfully reserializes a message with inReplyTo == nil" do + user = insert(:user) + + message = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "cc" => [], + "type" => "Create", + "object" => %{ + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "cc" => [], + "type" => "Note", + "content" => "Hi", + "inReplyTo" => nil, + "attributedTo" => user.ap_id + }, + "actor" => user.ap_id + } + + {:ok, activity} = Transmogrifier.handle_incoming(message) + + {:ok, _} = Transmogrifier.prepare_outgoing(activity.data) + end + + test "successfully reserializes a message with AS2 objects in IR" do + user = insert(:user) + + message = %{ + "@context" => "https://www.w3.org/ns/activitystreams", + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "cc" => [], + "type" => "Create", + "object" => %{ + "to" => ["https://www.w3.org/ns/activitystreams#Public"], + "cc" => [], + "type" => "Note", + "content" => "Hi", + "inReplyTo" => nil, + "attributedTo" => user.ap_id, + "tag" => [ + %{"name" => "#2hu", "href" => "http://example.com/2hu", "type" => "Hashtag"}, + %{"name" => "Bob", "href" => "http://example.com/bob", "type" => "Mention"} + ] + }, + "actor" => user.ap_id + } + + {:ok, activity} = Transmogrifier.handle_incoming(message) + + {:ok, _} = Transmogrifier.prepare_outgoing(activity.data) + end + end end -- cgit v1.2.3 From 64620d8980e3e93791d3f880296be2060ffc4d39 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 02:41:21 +0000 Subject: activitypub: user view: do not expose oAuth endpoints for instance users --- test/web/activity_pub/views/user_view_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 95d736c50..0bc1d4728 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -42,5 +42,16 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do assert result["id"] == user.ap_id assert result["endpoints"] == %{} end + + test "instance users do not expose oAuth endpoints" do + user = insert(:user, nickname: nil, local: true) + {:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user) + + result = UserView.render("user.json", %{user: user}) + + refute result["endpoints"]["oauthAuthorizationEndpoint"] + refute result["endpoints"]["oauthRegistrationEndpoint"] + refute result["endpoints"]["oauthTokenEndpoint"] + end end end -- cgit v1.2.3 From e031cc6473e12cae7249324fe6fdea5287b6304a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 03:22:54 +0000 Subject: tests: update tests for totalItems leak fix --- test/web/activity_pub/activity_pub_controller_test.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index 570bee6b3..9f6d87caa 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -397,7 +397,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do |> json_response(200) assert result["first"]["orderedItems"] == [] - assert result["totalItems"] == 1 + assert result["totalItems"] == 0 end test "it works for more than 10 users", %{conn: conn} do @@ -452,7 +452,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do |> json_response(200) assert result["first"]["orderedItems"] == [] - assert result["totalItems"] == 1 + assert result["totalItems"] == 0 end test "it works for more than 10 users", %{conn: conn} do -- cgit v1.2.3 From 907306174b082cccd823894c855194a4fc1e8305 Mon Sep 17 00:00:00 2001 From: Egor Kislitsyn Date: Thu, 14 Feb 2019 15:55:21 +0700 Subject: fix S3 links encoding in Mediaproxy --- test/media_proxy_test.exs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs index 05d927422..ddbadfbf5 100644 --- a/test/media_proxy_test.exs +++ b/test/media_proxy_test.exs @@ -140,6 +140,15 @@ defmodule Pleroma.MediaProxyTest do assert String.starts_with?(encoded, Pleroma.Config.get([:media_proxy, :base_url])) end + + # https://git.pleroma.social/pleroma/pleroma/issues/580 + test "encoding S3 links (must preserve `%2F`)" do + url = + "https://s3.amazonaws.com/example/test.png?X-Amz-Credential=your-access-key-id%2F20130721%2Fus-east-1%2Fs3%2Faws4_request" + + encoded = url(url) + assert decode_result(encoded) == url + end end describe "when disabled" do -- cgit v1.2.3 From 32b164943433ddebfdb04494bbd4d4e8a90578d4 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Feb 2019 19:59:12 +0000 Subject: test: user: add a test for whether user search returns a user or not --- test/user_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index 58587bd82..a99b79a0d 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -878,6 +878,16 @@ defmodule Pleroma.UserTest do assert [] == User.search(query) end) end + + test "works with URIs" do + results = User.search("http://mastodon.example.org/users/admin", true) + result = results |> List.first() + + user = User.get_by_ap_id("http://mastodon.example.org/users/admin") + + assert length(results) == 1 + assert user == result |> Map.put(:search_rank, nil) + end end test "auth_active?/1 works correctly" do -- cgit v1.2.3 From d943c90249e0a598e57a0dbdf41d387b53916092 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 15 Feb 2019 12:47:50 +0100 Subject: Add tests, change default config values, fix a bug --- .../activity_pub/mrf/hellthread_policy_test.exs | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/web/activity_pub/mrf/hellthread_policy_test.exs (limited to 'test') diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs new file mode 100644 index 000000000..b5bdd35cc --- /dev/null +++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs @@ -0,0 +1,50 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do + use Pleroma.DataCase + import Pleroma.Factory + + import Pleroma.Web.ActivityPub.MRF.HellthreadPolicy + + describe "hellthread filter tests" do + setup do + user = insert(:user) + + message = %{ + "actor" => user.ap_id, + "cc" => [user.follower_address], + "type" => "Create", + "to" => [ + "https://www.w3.org/ns/activitystreams#Public", + "https://instace.tld/users/user1", + "https://instace.tld/users/user2", + "https://instace.tld/users/user3" + ] + } + + [user: user, message: message] + end + + test "reject test", %{message: message} do + Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 2}) + + {:reject, nil} = filter(message) + end + + test "delist test", %{user: user, message: message} do + Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 2, reject_threshold: 0}) + + {:ok, message} = filter(message) + assert user.follower_address in message["to"] + assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"] + end + + test "threshold test", %{message: message} do + Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3}) + + {:ok, _} = filter(message) + end + end +end -- cgit v1.2.3 From dca6bee2f7eba1dc366cc65d3087f20678549739 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Fri, 15 Feb 2019 13:43:14 +0100 Subject: Rename test, add check for follower collection when delisting --- test/web/activity_pub/mrf/hellthread_policy_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/web/activity_pub/mrf/hellthread_policy_test.exs b/test/web/activity_pub/mrf/hellthread_policy_test.exs index b5bdd35cc..ebf9997cd 100644 --- a/test/web/activity_pub/mrf/hellthread_policy_test.exs +++ b/test/web/activity_pub/mrf/hellthread_policy_test.exs @@ -41,7 +41,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicyTest do assert "https://www.w3.org/ns/activitystreams#Public" in message["cc"] end - test "threshold test", %{message: message} do + test "excludes follower collection and public URI from threshold count", %{message: message} do Pleroma.Config.put([:mrf_hellthread], %{delist_threshold: 0, reject_threshold: 3}) {:ok, _} = filter(message) -- cgit v1.2.3 From d812a347ca936dba764eb223fde029d83ca3fba0 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 16 Feb 2019 16:42:34 +0100 Subject: Add optional welcome message. --- test/user_test.exs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index a99b79a0d..d89fe379f 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -196,6 +196,25 @@ defmodule Pleroma.UserTest do assert User.following?(registered_user, user) refute User.following?(registered_user, remote_user) + + Pleroma.Config.put([:instance, :autofollowed_nicknames], []) + end + + test "it sends a welcome message if it is set" do + welcome_user = insert(:user) + + Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname) + Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site") + + cng = User.register_changeset(%User{}, @full_user_data) + {:ok, registered_user} = User.register(cng) + + activity = Repo.one(Pleroma.Activity) + assert registered_user.ap_id in activity.recipients + assert activity.data["object"]["content"] =~ "cool site" + + Pleroma.Config.put([:instance, :welcome_user_nickname], nil) + Pleroma.Config.put([:instance, :welcome_message], nil) end test "it requires an email, name, nickname and password, bio is optional" do -- cgit v1.2.3 From f469a8610f47d6d36b2bcaa1974a1744990db7b4 Mon Sep 17 00:00:00 2001 From: lain Date: Sat, 16 Feb 2019 17:24:31 +0100 Subject: Check that the welcome message is sent from the correct user. --- test/user_test.exs | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/user_test.exs b/test/user_test.exs index d89fe379f..92991d063 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -212,6 +212,7 @@ defmodule Pleroma.UserTest do activity = Repo.one(Pleroma.Activity) assert registered_user.ap_id in activity.recipients assert activity.data["object"]["content"] =~ "cool site" + assert activity.actor == welcome_user.ap_id Pleroma.Config.put([:instance, :welcome_user_nickname], nil) Pleroma.Config.put([:instance, :welcome_message], nil) -- cgit v1.2.3