X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fpleroma%2Fweb%2Factivity_pub%2Fvisibility_test.exs;h=1595f9085f2f8115bfddad5fc19f0d6650fc77f3;hb=9db4c2429fce2d9f56cc59de64b3d6b62e1a7071;hp=8e9354c659b71091fbe4dad563c79e7d60c63864;hpb=7dffaef4799b0e867e91e19b76567c0e1a19bb43;p=akkoma
diff --git a/test/pleroma/web/activity_pub/visibility_test.exs b/test/pleroma/web/activity_pub/visibility_test.exs
index 8e9354c65..1595f9085 100644
--- a/test/pleroma/web/activity_pub/visibility_test.exs
+++ b/test/pleroma/web/activity_pub/visibility_test.exs
@@ -1,11 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.VisibilityTest do
- use Pleroma.DataCase
+ use Pleroma.DataCase, async: true
alias Pleroma.Activity
+ alias Pleroma.Object
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
@@ -15,7 +16,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
mentioned = insert(:user)
following = insert(:user)
unrelated = insert(:user)
- {:ok, following} = Pleroma.User.follow(following, user)
+ remote = insert(:user, local: false)
+ {:ok, following, user} = Pleroma.User.follow(following, user)
{:ok, list} = Pleroma.List.create("foo", user)
Pleroma.List.follow(list, unrelated)
@@ -32,6 +34,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
{:ok, unlisted} =
CommonAPI.post(user, %{status: "@#{mentioned.nickname}", visibility: "unlisted"})
+ {:ok, local} = CommonAPI.post(user, %{status: "@#{mentioned.nickname}", visibility: "local"})
+
{:ok, list} =
CommonAPI.post(user, %{
status: "@#{mentioned.nickname}",
@@ -47,7 +51,9 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
mentioned: mentioned,
following: following,
unrelated: unrelated,
- list: list
+ list: list,
+ local: local,
+ remote: remote
}
end
@@ -56,13 +62,15 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
private: private,
direct: direct,
unlisted: unlisted,
- list: list
+ list: list,
+ local: local
} do
assert Visibility.is_direct?(direct)
refute Visibility.is_direct?(public)
refute Visibility.is_direct?(private)
refute Visibility.is_direct?(unlisted)
assert Visibility.is_direct?(list)
+ refute Visibility.is_direct?(local)
end
test "is_public?", %{
@@ -70,12 +78,14 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
private: private,
direct: direct,
unlisted: unlisted,
+ local: local,
list: list
} do
refute Visibility.is_public?(direct)
assert Visibility.is_public?(public)
refute Visibility.is_public?(private)
assert Visibility.is_public?(unlisted)
+ assert Visibility.is_public?(local)
refute Visibility.is_public?(list)
end
@@ -84,13 +94,15 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
private: private,
direct: direct,
unlisted: unlisted,
- list: list
+ list: list,
+ local: local
} do
refute Visibility.is_private?(direct)
refute Visibility.is_private?(public)
assert Visibility.is_private?(private)
refute Visibility.is_private?(unlisted)
refute Visibility.is_private?(list)
+ refute Visibility.is_private?(local)
end
test "is_list?", %{
@@ -98,16 +110,18 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
private: private,
direct: direct,
unlisted: unlisted,
- list: list
+ list: list,
+ local: local
} do
refute Visibility.is_list?(direct)
refute Visibility.is_list?(public)
refute Visibility.is_list?(private)
refute Visibility.is_list?(unlisted)
assert Visibility.is_list?(list)
+ refute Visibility.is_list?(local)
end
- test "visible_for_user?", %{
+ test "visible_for_user? Activity", %{
public: public,
private: private,
direct: direct,
@@ -116,7 +130,9 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
mentioned: mentioned,
following: following,
unrelated: unrelated,
- list: list
+ list: list,
+ local: local,
+ remote: remote
} do
# All visible to author
@@ -125,6 +141,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(unlisted, user)
assert Visibility.visible_for_user?(direct, user)
assert Visibility.visible_for_user?(list, user)
+ assert Visibility.visible_for_user?(local, user)
# All visible to a mentioned user
@@ -133,6 +150,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(unlisted, mentioned)
assert Visibility.visible_for_user?(direct, mentioned)
assert Visibility.visible_for_user?(list, mentioned)
+ assert Visibility.visible_for_user?(local, mentioned)
# DM not visible for just follower
@@ -141,6 +159,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(unlisted, following)
refute Visibility.visible_for_user?(direct, following)
refute Visibility.visible_for_user?(list, following)
+ assert Visibility.visible_for_user?(local, following)
# Public and unlisted visible for unrelated user
@@ -148,9 +167,86 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
assert Visibility.visible_for_user?(unlisted, unrelated)
refute Visibility.visible_for_user?(private, unrelated)
refute Visibility.visible_for_user?(direct, unrelated)
+ assert Visibility.visible_for_user?(local, unrelated)
+
+ # Public and unlisted visible for unauthenticated
+
+ assert Visibility.visible_for_user?(public, nil)
+ assert Visibility.visible_for_user?(unlisted, nil)
+ refute Visibility.visible_for_user?(private, nil)
+ refute Visibility.visible_for_user?(direct, nil)
+ refute Visibility.visible_for_user?(local, nil)
# Visible for a list member
assert Visibility.visible_for_user?(list, unrelated)
+
+ # Local not visible to remote user
+ refute Visibility.visible_for_user?(local, remote)
+ end
+
+ test "visible_for_user? Object", %{
+ public: public,
+ private: private,
+ direct: direct,
+ unlisted: unlisted,
+ user: user,
+ mentioned: mentioned,
+ following: following,
+ unrelated: unrelated,
+ list: list,
+ local: local,
+ remote: remote
+ } do
+ public = Object.normalize(public)
+ private = Object.normalize(private)
+ unlisted = Object.normalize(unlisted)
+ direct = Object.normalize(direct)
+ list = Object.normalize(list)
+ local = Object.normalize(local)
+
+ # All visible to author
+
+ assert Visibility.visible_for_user?(public, user)
+ assert Visibility.visible_for_user?(private, user)
+ assert Visibility.visible_for_user?(unlisted, user)
+ assert Visibility.visible_for_user?(direct, user)
+ assert Visibility.visible_for_user?(list, user)
+
+ # All visible to a mentioned user
+
+ assert Visibility.visible_for_user?(public, mentioned)
+ assert Visibility.visible_for_user?(private, mentioned)
+ assert Visibility.visible_for_user?(unlisted, mentioned)
+ assert Visibility.visible_for_user?(direct, mentioned)
+ assert Visibility.visible_for_user?(list, mentioned)
+
+ # DM not visible for just follower
+
+ assert Visibility.visible_for_user?(public, following)
+ assert Visibility.visible_for_user?(private, following)
+ assert Visibility.visible_for_user?(unlisted, following)
+ refute Visibility.visible_for_user?(direct, following)
+ refute Visibility.visible_for_user?(list, following)
+
+ # Public and unlisted visible for unrelated user
+
+ assert Visibility.visible_for_user?(public, unrelated)
+ assert Visibility.visible_for_user?(unlisted, unrelated)
+ refute Visibility.visible_for_user?(private, unrelated)
+ refute Visibility.visible_for_user?(direct, unrelated)
+
+ # Public and unlisted visible for unauthenticated
+
+ assert Visibility.visible_for_user?(public, nil)
+ assert Visibility.visible_for_user?(unlisted, nil)
+ refute Visibility.visible_for_user?(private, nil)
+ refute Visibility.visible_for_user?(direct, nil)
+ refute Visibility.visible_for_user?(local, nil)
+
+ # Local posts to remote
+ refute Visibility.visible_for_user?(local, remote)
+ # Visible for a list member
+ # assert Visibility.visible_for_user?(list, unrelated)
end
test "doesn't die when the user doesn't exist",
@@ -159,7 +255,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
user: user
} do
Repo.delete(user)
- Cachex.clear(:user_cache)
+ Pleroma.User.invalidate_cache(user)
refute Visibility.is_private?(direct)
end