Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into issue/1880
This commit is contained in:
commit
cdc153db31
131 changed files with 1474 additions and 729 deletions
|
|
@ -3,37 +3,39 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.FilterTest do
|
||||
alias Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Filter
|
||||
alias Pleroma.Repo
|
||||
|
||||
describe "creating filters" do
|
||||
test "creating one filter" do
|
||||
user = insert(:user)
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
query = %Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 42,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, %Pleroma.Filter{} = filter} = Pleroma.Filter.create(query)
|
||||
result = Pleroma.Filter.get(filter.filter_id, user)
|
||||
{:ok, %Filter{} = filter} = Filter.create(query)
|
||||
result = Filter.get(filter.filter_id, user)
|
||||
assert query.phrase == result.phrase
|
||||
end
|
||||
|
||||
test "creating one filter without a pre-defined filter_id" do
|
||||
user = insert(:user)
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
query = %Filter{
|
||||
user_id: user.id,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, %Pleroma.Filter{} = filter} = Pleroma.Filter.create(query)
|
||||
{:ok, %Filter{} = filter} = Filter.create(query)
|
||||
# Should start at 1
|
||||
assert filter.filter_id == 1
|
||||
end
|
||||
|
|
@ -41,23 +43,23 @@ defmodule Pleroma.FilterTest do
|
|||
test "creating additional filters uses previous highest filter_id + 1" do
|
||||
user = insert(:user)
|
||||
|
||||
query_one = %Pleroma.Filter{
|
||||
query_one = %Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 42,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, %Pleroma.Filter{} = filter_one} = Pleroma.Filter.create(query_one)
|
||||
{:ok, %Filter{} = filter_one} = Filter.create(query_one)
|
||||
|
||||
query_two = %Pleroma.Filter{
|
||||
query_two = %Filter{
|
||||
user_id: user.id,
|
||||
# No filter_id
|
||||
phrase: "who",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, %Pleroma.Filter{} = filter_two} = Pleroma.Filter.create(query_two)
|
||||
{:ok, %Filter{} = filter_two} = Filter.create(query_two)
|
||||
assert filter_two.filter_id == filter_one.filter_id + 1
|
||||
end
|
||||
|
||||
|
|
@ -65,29 +67,29 @@ defmodule Pleroma.FilterTest do
|
|||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
query_one = %Pleroma.Filter{
|
||||
query_one = %Filter{
|
||||
user_id: user_one.id,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, %Pleroma.Filter{} = filter_one} = Pleroma.Filter.create(query_one)
|
||||
{:ok, %Filter{} = filter_one} = Filter.create(query_one)
|
||||
|
||||
query_two = %Pleroma.Filter{
|
||||
query_two = %Filter{
|
||||
user_id: user_two.id,
|
||||
phrase: "who",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, %Pleroma.Filter{} = filter_two} = Pleroma.Filter.create(query_two)
|
||||
{:ok, %Filter{} = filter_two} = Filter.create(query_two)
|
||||
|
||||
assert filter_one.filter_id == 1
|
||||
assert filter_two.filter_id == 1
|
||||
|
||||
result_one = Pleroma.Filter.get(filter_one.filter_id, user_one)
|
||||
result_one = Filter.get(filter_one.filter_id, user_one)
|
||||
assert result_one.phrase == filter_one.phrase
|
||||
|
||||
result_two = Pleroma.Filter.get(filter_two.filter_id, user_two)
|
||||
result_two = Filter.get(filter_two.filter_id, user_two)
|
||||
assert result_two.phrase == filter_two.phrase
|
||||
end
|
||||
end
|
||||
|
|
@ -95,38 +97,38 @@ defmodule Pleroma.FilterTest do
|
|||
test "deleting a filter" do
|
||||
user = insert(:user)
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
query = %Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 0,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, _filter} = Pleroma.Filter.create(query)
|
||||
{:ok, filter} = Pleroma.Filter.delete(query)
|
||||
assert is_nil(Repo.get(Pleroma.Filter, filter.filter_id))
|
||||
{:ok, _filter} = Filter.create(query)
|
||||
{:ok, filter} = Filter.delete(query)
|
||||
assert is_nil(Repo.get(Filter, filter.filter_id))
|
||||
end
|
||||
|
||||
test "getting all filters by an user" do
|
||||
user = insert(:user)
|
||||
|
||||
query_one = %Pleroma.Filter{
|
||||
query_one = %Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 1,
|
||||
phrase: "knights",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
query_two = %Pleroma.Filter{
|
||||
query_two = %Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "who",
|
||||
context: ["home"]
|
||||
}
|
||||
|
||||
{:ok, filter_one} = Pleroma.Filter.create(query_one)
|
||||
{:ok, filter_two} = Pleroma.Filter.create(query_two)
|
||||
filters = Pleroma.Filter.get_filters(user)
|
||||
{:ok, filter_one} = Filter.create(query_one)
|
||||
{:ok, filter_two} = Filter.create(query_two)
|
||||
filters = Filter.get_filters(user)
|
||||
assert filter_one in filters
|
||||
assert filter_two in filters
|
||||
end
|
||||
|
|
@ -134,7 +136,7 @@ defmodule Pleroma.FilterTest do
|
|||
test "updating a filter" do
|
||||
user = insert(:user)
|
||||
|
||||
query_one = %Pleroma.Filter{
|
||||
query_one = %Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 1,
|
||||
phrase: "knights",
|
||||
|
|
@ -146,8 +148,9 @@ defmodule Pleroma.FilterTest do
|
|||
context: ["home", "timeline"]
|
||||
}
|
||||
|
||||
{:ok, filter_one} = Pleroma.Filter.create(query_one)
|
||||
{:ok, filter_two} = Pleroma.Filter.update(filter_one, changes)
|
||||
{:ok, filter_one} = Filter.create(query_one)
|
||||
{:ok, filter_two} = Filter.update(filter_one, changes)
|
||||
|
||||
assert filter_one != filter_two
|
||||
assert filter_two.phrase == changes.phrase
|
||||
assert filter_two.context == changes.context
|
||||
|
|
|
|||
1
test/fixtures/tesla_mock/framatube.org-video.json
vendored
Normal file
1
test/fixtures/tesla_mock/framatube.org-video.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
test/fixtures/tesla_mock/https___framatube.org_accounts_framasoft.json
vendored
Normal file
1
test/fixtures/tesla_mock/https___framatube.org_accounts_framasoft.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"type":"Person","id":"https://framatube.org/accounts/framasoft","following":"https://framatube.org/accounts/framasoft/following","followers":"https://framatube.org/accounts/framasoft/followers","playlists":"https://framatube.org/accounts/framasoft/playlists","inbox":"https://framatube.org/accounts/framasoft/inbox","outbox":"https://framatube.org/accounts/framasoft/outbox","preferredUsername":"framasoft","url":"https://framatube.org/accounts/framasoft","name":"Framasoft","endpoints":{"sharedInbox":"https://framatube.org/inbox"},"publicKey":{"id":"https://framatube.org/accounts/framasoft#main-key","owner":"https://framatube.org/accounts/framasoft","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuRh3frgIg866D0y0FThp\nSUkJImMcHGkUvpYQYv2iUgarZZtEbwT8PfQf0bJazy+cP8KqQmMDf5PBhT7dfdny\nf/GKGMw9Olc+QISeKDj3sqZ3Csrm4KV4avMGCfth6eSU7LozojeSGCXdUFz/8UgE\nfhV4mJjEX/FbwRYoKlagv5rY9mkX5XomzZU+z9j6ZVXyofwOwJvmI1hq0SYDv2bc\neB/RgIh/H0nyMtF8o+0CT42FNEET9j9m1BKOBtPzwZHmitKRkEmui5cK256s1laB\nT61KHpcD9gQKkQ+I3sFEzCBUJYfVo6fUe+GehBZuAfq4qDhd15SfE4K9veDscDFI\nTwIDAQAB\n-----END PUBLIC KEY-----"},"icon":{"type":"Image","mediaType":"image/png","url":"https://framatube.org/lazy-static/avatars/f73876f5-1d45-4f8a-942a-d3d5d5ac5dc1.png"},"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"RsaSignature2017":"https://w3id.org/security#RsaSignature2017","pt":"https://joinpeertube.org/ns#","sc":"http://schema.org#","Hashtag":"as:Hashtag","uuid":"sc:identifier","category":"sc:category","licence":"sc:license","subtitleLanguage":"sc:subtitleLanguage","sensitive":"as:sensitive","language":"sc:inLanguage","expires":"sc:expires","CacheFile":"pt:CacheFile","Infohash":"pt:Infohash","originallyPublishedAt":"sc:datePublished","views":{"@type":"sc:Number","@id":"pt:views"},"state":{"@type":"sc:Number","@id":"pt:state"},"size":{"@type":"sc:Number","@id":"pt:size"},"fps":{"@type":"sc:Number","@id":"pt:fps"},"startTimestamp":{"@type":"sc:Number","@id":"pt:startTimestamp"},"stopTimestamp":{"@type":"sc:Number","@id":"pt:stopTimestamp"},"position":{"@type":"sc:Number","@id":"pt:position"},"commentsEnabled":{"@type":"sc:Boolean","@id":"pt:commentsEnabled"},"downloadEnabled":{"@type":"sc:Boolean","@id":"pt:downloadEnabled"},"waitTranscoding":{"@type":"sc:Boolean","@id":"pt:waitTranscoding"},"support":{"@type":"sc:Text","@id":"pt:support"}},{"likes":{"@id":"as:likes","@type":"@id"},"dislikes":{"@id":"as:dislikes","@type":"@id"},"playlists":{"@id":"pt:playlists","@type":"@id"},"shares":{"@id":"as:shares","@type":"@id"},"comments":{"@id":"as:comments","@type":"@id"}}],"summary":null}
|
||||
|
|
@ -324,6 +324,44 @@ defmodule Pleroma.NotificationTest do
|
|||
{:ok, status} = CommonAPI.post(author, %{status: "hey @#{user.nickname}"})
|
||||
refute Notification.create_notification(status, user)
|
||||
end
|
||||
|
||||
test "it doesn't create notifications if content matches with an irreversible filter" do
|
||||
user = insert(:user)
|
||||
subscriber = insert(:user)
|
||||
|
||||
User.subscribe(subscriber, user)
|
||||
insert(:filter, user: subscriber, phrase: "cofe", hide: true)
|
||||
|
||||
{:ok, status} = CommonAPI.post(user, %{status: "got cofe?"})
|
||||
|
||||
assert {:ok, []} == Notification.create_notifications(status)
|
||||
end
|
||||
|
||||
test "it creates notifications if content matches with a not irreversible filter" do
|
||||
user = insert(:user)
|
||||
subscriber = insert(:user)
|
||||
|
||||
User.subscribe(subscriber, user)
|
||||
insert(:filter, user: subscriber, phrase: "cofe", hide: false)
|
||||
|
||||
{:ok, status} = CommonAPI.post(user, %{status: "got cofe?"})
|
||||
{:ok, [notification]} = Notification.create_notifications(status)
|
||||
|
||||
assert notification
|
||||
end
|
||||
|
||||
test "it creates notifications when someone likes user's status with a filtered word" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
insert(:filter, user: user, phrase: "tesla", hide: true)
|
||||
|
||||
{:ok, activity_one} = CommonAPI.post(user, %{status: "wow tesla"})
|
||||
{:ok, activity_two} = CommonAPI.favorite(other_user, activity_one.id)
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity_two)
|
||||
|
||||
assert notification
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow / follow_request notifications" do
|
||||
|
|
@ -990,8 +1028,13 @@ defmodule Pleroma.NotificationTest do
|
|||
end
|
||||
|
||||
describe "for_user" do
|
||||
test "it returns notifications for muted user without notifications" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, %{user: user}}
|
||||
end
|
||||
|
||||
test "it returns notifications for muted user without notifications", %{user: user} do
|
||||
muted = insert(:user)
|
||||
{:ok, _user_relationships} = User.mute(user, muted, false)
|
||||
|
||||
|
|
@ -1002,8 +1045,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert notification.activity.object
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for muted user with notifications" do
|
||||
user = insert(:user)
|
||||
test "it doesn't return notifications for muted user with notifications", %{user: user} do
|
||||
muted = insert(:user)
|
||||
{:ok, _user_relationships} = User.mute(user, muted)
|
||||
|
||||
|
|
@ -1012,8 +1054,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for blocked user" do
|
||||
user = insert(:user)
|
||||
test "it doesn't return notifications for blocked user", %{user: user} do
|
||||
blocked = insert(:user)
|
||||
{:ok, _user_relationship} = User.block(user, blocked)
|
||||
|
||||
|
|
@ -1022,8 +1063,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for domain-blocked non-followed user" do
|
||||
user = insert(:user)
|
||||
test "it doesn't return notifications for domain-blocked non-followed user", %{user: user} do
|
||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
|
||||
|
|
@ -1044,8 +1084,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert length(Notification.for_user(user)) == 1
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for muted thread" do
|
||||
user = insert(:user)
|
||||
test "it doesn't return notifications for muted thread", %{user: user} do
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(another_user, %{status: "hey @#{user.nickname}"})
|
||||
|
|
@ -1054,8 +1093,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
||||
test "it returns notifications from a muted user when with_muted is set" do
|
||||
user = insert(:user)
|
||||
test "it returns notifications from a muted user when with_muted is set", %{user: user} do
|
||||
muted = insert(:user)
|
||||
{:ok, _user_relationships} = User.mute(user, muted)
|
||||
|
||||
|
|
@ -1064,8 +1102,9 @@ defmodule Pleroma.NotificationTest do
|
|||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||
end
|
||||
|
||||
test "it doesn't return notifications from a blocked user when with_muted is set" do
|
||||
user = insert(:user)
|
||||
test "it doesn't return notifications from a blocked user when with_muted is set", %{
|
||||
user: user
|
||||
} do
|
||||
blocked = insert(:user)
|
||||
{:ok, _user_relationship} = User.block(user, blocked)
|
||||
|
||||
|
|
@ -1075,8 +1114,8 @@ defmodule Pleroma.NotificationTest do
|
|||
end
|
||||
|
||||
test "when with_muted is set, " <>
|
||||
"it doesn't return notifications from a domain-blocked non-followed user" do
|
||||
user = insert(:user)
|
||||
"it doesn't return notifications from a domain-blocked non-followed user",
|
||||
%{user: user} do
|
||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
|
||||
|
|
@ -1085,8 +1124,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
|
||||
end
|
||||
|
||||
test "it returns notifications from muted threads when with_muted is set" do
|
||||
user = insert(:user)
|
||||
test "it returns notifications from muted threads when with_muted is set", %{user: user} do
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(another_user, %{status: "hey @#{user.nickname}"})
|
||||
|
|
@ -1094,5 +1132,33 @@ defmodule Pleroma.NotificationTest do
|
|||
{:ok, _} = Pleroma.ThreadMute.add_mute(user.id, activity.data["context"])
|
||||
assert length(Notification.for_user(user, %{with_muted: true})) == 1
|
||||
end
|
||||
|
||||
test "it doesn't return notifications about mentions with filtered word", %{user: user} do
|
||||
insert(:filter, user: user, phrase: "cofe", hide: true)
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(another_user, %{status: "@#{user.nickname} got cofe?"})
|
||||
|
||||
assert Enum.empty?(Notification.for_user(user))
|
||||
end
|
||||
|
||||
test "it returns notifications about mentions with not hidden filtered word", %{user: user} do
|
||||
insert(:filter, user: user, phrase: "test", hide: false)
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post(another_user, %{status: "@#{user.nickname} test"})
|
||||
|
||||
assert length(Notification.for_user(user)) == 1
|
||||
end
|
||||
|
||||
test "it returns notifications about favorites with filtered word", %{user: user} do
|
||||
insert(:filter, user: user, phrase: "cofe", hide: true)
|
||||
another_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "Give me my cofe!"})
|
||||
{:ok, _} = CommonAPI.favorite(another_user, activity.id)
|
||||
|
||||
assert length(Notification.for_user(user)) == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -428,4 +428,12 @@ defmodule Pleroma.Factory do
|
|||
user: build(:user)
|
||||
}
|
||||
end
|
||||
|
||||
def filter_factory do
|
||||
%Pleroma.Filter{
|
||||
user: build(:user),
|
||||
filter_id: sequence(:filter_id, & &1),
|
||||
phrase: "cofe"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -308,6 +308,22 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://framatube.org/accounts/framasoft", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/https___framatube.org_accounts_framasoft.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/framatube.org-video.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://peertube.social/accounts/craigmaloney", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
|
|||
|
|
@ -507,6 +507,33 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
activities = ActivityPub.fetch_activities_for_context("2hu", %{blocking_user: user})
|
||||
assert activities == [activity_two, activity]
|
||||
end
|
||||
|
||||
test "doesn't return activities with filtered words" do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
insert(:filter, user: user, phrase: "test", hide: true)
|
||||
|
||||
{:ok, %{id: id1, data: %{"context" => context}}} = CommonAPI.post(user, %{status: "1"})
|
||||
|
||||
{:ok, %{id: id2}} = CommonAPI.post(user_two, %{status: "2", in_reply_to_status_id: id1})
|
||||
|
||||
{:ok, %{id: id3} = user_activity} =
|
||||
CommonAPI.post(user, %{status: "3 test?", in_reply_to_status_id: id2})
|
||||
|
||||
{:ok, %{id: id4} = filtered_activity} =
|
||||
CommonAPI.post(user_two, %{status: "4 test!", in_reply_to_status_id: id3})
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "5", in_reply_to_status_id: id4})
|
||||
|
||||
activities =
|
||||
context
|
||||
|> ActivityPub.fetch_activities_for_context(%{user: user})
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities) == 4
|
||||
assert user_activity.id in activities
|
||||
refute filtered_activity.id in activities
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't return blocked activities" do
|
||||
|
|
@ -785,6 +812,75 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
assert activity == expected_activity
|
||||
end
|
||||
|
||||
describe "irreversible filters" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
insert(:filter, user: user_two, phrase: "cofe", hide: true)
|
||||
insert(:filter, user: user_two, phrase: "ok boomer", hide: true)
|
||||
insert(:filter, user: user_two, phrase: "test", hide: false)
|
||||
|
||||
params = %{
|
||||
type: ["Create", "Announce"],
|
||||
user: user_two
|
||||
}
|
||||
|
||||
{:ok, %{user: user, user_two: user_two, params: params}}
|
||||
end
|
||||
|
||||
test "it returns statuses if they don't contain exact filter words", %{
|
||||
user: user,
|
||||
params: params
|
||||
} do
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "hey"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "got cofefe?"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "I am not a boomer"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "ok boomers"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "ccofee is not a word"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "this is a test"})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], params)
|
||||
|
||||
assert Enum.count(activities) == 6
|
||||
end
|
||||
|
||||
test "it does not filter user's own statuses", %{user_two: user_two, params: params} do
|
||||
{:ok, _} = CommonAPI.post(user_two, %{status: "Give me some cofe!"})
|
||||
{:ok, _} = CommonAPI.post(user_two, %{status: "ok boomer"})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], params)
|
||||
|
||||
assert Enum.count(activities) == 2
|
||||
end
|
||||
|
||||
test "it excludes statuses with filter words", %{user: user, params: params} do
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "Give me some cofe!"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "ok boomer"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "is it a cOfE?"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "cofe is all I need"})
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "— ok BOOMER\n"})
|
||||
|
||||
activities = ActivityPub.fetch_activities([], params)
|
||||
|
||||
assert Enum.empty?(activities)
|
||||
end
|
||||
|
||||
test "it returns all statuses if user does not have any filters" do
|
||||
another_user = insert(:user)
|
||||
{:ok, _} = CommonAPI.post(another_user, %{status: "got cofe?"})
|
||||
{:ok, _} = CommonAPI.post(another_user, %{status: "test!"})
|
||||
|
||||
activities =
|
||||
ActivityPub.fetch_activities([], %{
|
||||
type: ["Create", "Announce"],
|
||||
user: another_user
|
||||
})
|
||||
|
||||
assert Enum.count(activities) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "public fetch activities" do
|
||||
test "doesn't retrieve unlisted activities" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -659,22 +659,44 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||
)
|
||||
|
||||
attachment = %{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert object.data["url"] ==
|
||||
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||
|
||||
assert object.data["attachment"] == [attachment]
|
||||
assert object.data["attachment"] == [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
"https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
|
||||
)
|
||||
|
||||
assert object.data["attachment"] == [
|
||||
%{
|
||||
"type" => "Link",
|
||||
"mediaType" => "video/mp4",
|
||||
"url" => [
|
||||
%{
|
||||
"href" =>
|
||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||
"mediaType" => "video/mp4"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
assert object.data["url"] ==
|
||||
"https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
|
||||
end
|
||||
|
||||
test "it accepts Flag activities" do
|
||||
|
|
|
|||
|
|
@ -216,10 +216,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
|
||||
assert user.avatar == %{}
|
||||
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
res = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
|
||||
|
||||
assert user_response = json_response_and_validate_schema(res, 200)
|
||||
assert user_response["avatar"] != User.avatar_url(user)
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
refute user.avatar == %{}
|
||||
|
||||
# Also resets it
|
||||
_res = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => ""})
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
assert user.avatar == nil
|
||||
end
|
||||
|
||||
test "updates the user's banner", %{user: user, conn: conn} do
|
||||
|
|
@ -229,26 +240,39 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header})
|
||||
res = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header})
|
||||
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(res, 200)
|
||||
assert user_response["header"] != User.banner_url(user)
|
||||
|
||||
# Also resets it
|
||||
_res = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => ""})
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
assert user.banner == nil
|
||||
end
|
||||
|
||||
test "updates the user's background", %{conn: conn} do
|
||||
test "updates the user's background", %{conn: conn, user: user} do
|
||||
new_header = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
conn =
|
||||
res =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{
|
||||
"pleroma_background_image" => new_header
|
||||
})
|
||||
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(res, 200)
|
||||
assert user_response["pleroma"]["background_image"]
|
||||
#
|
||||
# Also resets it
|
||||
_res =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{"pleroma_background_image" => ""})
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
assert user.background == nil
|
||||
end
|
||||
|
||||
test "requires 'write:accounts' permission" do
|
||||
|
|
|
|||
|
|
@ -418,4 +418,78 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
assert [status_none] == json_response_and_validate_schema(all_test, :ok)
|
||||
end
|
||||
end
|
||||
|
||||
describe "hashtag timeline handling of :restrict_unauthenticated setting" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, activity1} = CommonAPI.post(user, %{status: "test #tag1"})
|
||||
{:ok, _activity2} = CommonAPI.post(user, %{status: "test #tag1"})
|
||||
|
||||
activity1
|
||||
|> Ecto.Changeset.change(%{local: false})
|
||||
|> Pleroma.Repo.update()
|
||||
|
||||
base_uri = "/api/v1/timelines/tag/tag1"
|
||||
error_response = %{"error" => "authorization required for timeline view"}
|
||||
|
||||
%{base_uri: base_uri, error_response: error_response}
|
||||
end
|
||||
|
||||
defp ensure_authenticated_access(base_uri) do
|
||||
%{conn: auth_conn} = oauth_access(["read:statuses"])
|
||||
|
||||
res_conn = get(auth_conn, "#{base_uri}?local=true")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(auth_conn, "#{base_uri}?local=false")
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
|
||||
test "with `%{local: true, federated: true}`, returns 403 for unauthenticated users", %{
|
||||
conn: conn,
|
||||
base_uri: base_uri,
|
||||
error_response: error_response
|
||||
} do
|
||||
clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
for local <- [true, false] do
|
||||
res_conn = get(conn, "#{base_uri}?local=#{local}")
|
||||
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
end
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
|
||||
test "with `%{local: false, federated: true}`, forbids unauthenticated access to federated timeline",
|
||||
%{conn: conn, base_uri: base_uri, error_response: error_response} do
|
||||
clear_config([:restrict_unauthenticated, :timelines, :local], false)
|
||||
clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
res_conn = get(conn, "#{base_uri}?local=true")
|
||||
assert length(json_response(res_conn, 200)) == 1
|
||||
|
||||
res_conn = get(conn, "#{base_uri}?local=false")
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
|
||||
test "with `%{local: true, federated: false}`, forbids unauthenticated access to public timeline" <>
|
||||
"(but not to local public activities which are delivered as part of federated timeline)",
|
||||
%{conn: conn, base_uri: base_uri, error_response: error_response} do
|
||||
clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
clear_config([:restrict_unauthenticated, :timelines, :federated], false)
|
||||
|
||||
res_conn = get(conn, "#{base_uri}?local=true")
|
||||
assert json_response(res_conn, :unauthorized) == error_response
|
||||
|
||||
# Note: local activities get delivered as part of federated timeline
|
||||
res_conn = get(conn, "#{base_uri}?local=false")
|
||||
assert length(json_response(res_conn, 200)) == 2
|
||||
|
||||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
@image "data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7"
|
||||
|
||||
describe "POST /api/v1/pleroma/accounts/confirmation_resend" do
|
||||
setup do
|
||||
{:ok, user} =
|
||||
|
|
@ -68,103 +66,6 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/v1/pleroma/accounts/update_avatar" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
|
||||
test "user avatar can be set", %{user: user, conn: conn} do
|
||||
avatar_image = File.read!("test/fixtures/avatar_data_uri")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_avatar", %{img: avatar_image})
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %{
|
||||
"name" => _,
|
||||
"type" => _,
|
||||
"url" => [
|
||||
%{
|
||||
"href" => _,
|
||||
"mediaType" => _,
|
||||
"type" => _
|
||||
}
|
||||
]
|
||||
} = user.avatar
|
||||
|
||||
assert %{"url" => _} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "user avatar can be reset", %{user: user, conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_avatar", %{img: ""})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.avatar == nil
|
||||
|
||||
assert %{"url" => nil} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/v1/pleroma/accounts/update_banner" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
|
||||
test "can set profile banner", %{user: user, conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.banner["type"] == "Image"
|
||||
|
||||
assert %{"url" => _} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "can reset profile banner", %{user: user, conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.banner == %{}
|
||||
|
||||
assert %{"url" => nil} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/v1/pleroma/accounts/update_background" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
|
||||
test "background image can be set", %{user: user, conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_background", %{"img" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.background["type"] == "Image"
|
||||
# assert %{"url" => _} = json_response(conn, 200)
|
||||
assert %{"url" => _} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "background image can be reset", %{user: user, conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_background", %{"img" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.background == %{}
|
||||
assert %{"url" => nil} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting favorites timeline of specified user" do
|
||||
setup do
|
||||
[current_user, user] = insert_pair(:user, hide_favorites: false)
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.StatusNetTest do
|
||||
use Pleroma.DataCase
|
||||
alias Pleroma.Web.Preload.Providers.StatusNet
|
||||
|
||||
setup do: {:ok, StatusNet.generate_terms(nil)}
|
||||
|
||||
test "it renders the info", %{"/api/statusnet/config.json" => info} do
|
||||
assert {:ok, res} = Jason.decode(info)
|
||||
assert res["site"]
|
||||
end
|
||||
end
|
||||
|
|
@ -224,105 +224,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /api/statusnet/config" do
|
||||
test "it returns config in xml format", %{conn: conn} do
|
||||
instance = Config.get(:instance)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("accept", "application/xml")
|
||||
|> get("/api/statusnet/config")
|
||||
|> response(:ok)
|
||||
|
||||
assert response ==
|
||||
"<config>\n<site>\n<name>#{Keyword.get(instance, :name)}</name>\n<site>#{
|
||||
Pleroma.Web.base_url()
|
||||
}</site>\n<textlimit>#{Keyword.get(instance, :limit)}</textlimit>\n<closed>#{
|
||||
!Keyword.get(instance, :registrations_open)
|
||||
}</closed>\n</site>\n</config>\n"
|
||||
end
|
||||
|
||||
test "it returns config in json format", %{conn: conn} do
|
||||
instance = Config.get(:instance)
|
||||
Config.put([:instance, :managed_config], true)
|
||||
Config.put([:instance, :registrations_open], false)
|
||||
Config.put([:instance, :invites_enabled], true)
|
||||
Config.put([:instance, :public], false)
|
||||
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
|
||||
Config.put([:instance, :safe_dm_mentions], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/statusnet/config.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["site"]["safeDMMentionsEnabled"] == "1"
|
||||
|
||||
Config.put([:instance, :safe_dm_mentions], false)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/statusnet/config.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["site"]["safeDMMentionsEnabled"] == "0"
|
||||
end
|
||||
|
||||
test "it returns the managed config", %{conn: conn} do
|
||||
Config.put([:instance, :managed_config], false)
|
||||
Config.put([:frontend_configurations, :pleroma_fe], %{theme: "asuka-hospital"})
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/statusnet/config.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
refute response["site"]["pleromafe"]
|
||||
|
||||
Config.put([:instance, :managed_config], true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/statusnet/config.json")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response["site"]["pleromafe"] == %{"theme" => "asuka-hospital"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/frontend_configurations" do
|
||||
test "returns everything in :pleroma, :frontend_configurations", %{conn: conn} do
|
||||
config = [
|
||||
|
|
@ -451,28 +352,6 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
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 == "<version>#{Pleroma.Application.named_version()}</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
|
||||
setup do: clear_config([:instance, :federating], true)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue