Merge remote-tracking branch 'remotes/origin/develop' into 2168-media-preview-proxy
This commit is contained in:
commit
27e7999a15
263 changed files with 2408 additions and 1169 deletions
|
|
@ -11,7 +11,10 @@ defmodule Pleroma.ActivityExpirationTest do
|
|||
|
||||
test "finds activities due to be deleted only" do
|
||||
activity = insert(:note_activity)
|
||||
expiration_due = insert(:expiration_in_the_past, %{activity_id: activity.id})
|
||||
|
||||
expiration_due =
|
||||
insert(:expiration_in_the_past, %{activity_id: activity.id}) |> Repo.preload(:activity)
|
||||
|
||||
activity2 = insert(:note_activity)
|
||||
insert(:expiration_in_the_future, %{activity_id: activity2.id})
|
||||
|
||||
|
|
|
|||
|
|
@ -1417,7 +1417,6 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
test "delete/1 when approval is pending deletes the user" do
|
||||
user = insert(:user, approval_pending: true)
|
||||
{:ok, user: user}
|
||||
|
||||
{:ok, job} = User.delete(user)
|
||||
{:ok, _} = ObanHelpers.perform(job)
|
||||
|
|
@ -1426,6 +1425,85 @@ defmodule Pleroma.UserTest do
|
|||
refute User.get_by_id(user.id)
|
||||
end
|
||||
|
||||
test "delete/1 purges a user when they wouldn't be fully deleted" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
bio: "eyy lmao",
|
||||
name: "qqqqqqq",
|
||||
password_hash: "pdfk2$1b3n159001",
|
||||
keys: "RSA begin buplic key",
|
||||
public_key: "--PRIVATE KEYE--",
|
||||
avatar: %{"a" => "b"},
|
||||
tags: ["qqqqq"],
|
||||
banner: %{"a" => "b"},
|
||||
background: %{"a" => "b"},
|
||||
note_count: 9,
|
||||
follower_count: 9,
|
||||
following_count: 9001,
|
||||
locked: true,
|
||||
confirmation_pending: true,
|
||||
password_reset_pending: true,
|
||||
approval_pending: true,
|
||||
registration_reason: "ahhhhh",
|
||||
confirmation_token: "qqqq",
|
||||
domain_blocks: ["lain.com"],
|
||||
deactivated: true,
|
||||
ap_enabled: true,
|
||||
is_moderator: true,
|
||||
is_admin: true,
|
||||
mastofe_settings: %{"a" => "b"},
|
||||
mascot: %{"a" => "b"},
|
||||
emoji: %{"a" => "b"},
|
||||
pleroma_settings_store: %{"q" => "x"},
|
||||
fields: [%{"gg" => "qq"}],
|
||||
raw_fields: [%{"gg" => "qq"}],
|
||||
discoverable: true,
|
||||
also_known_as: ["https://lol.olo/users/loll"]
|
||||
})
|
||||
|
||||
{:ok, job} = User.delete(user)
|
||||
{:ok, _} = ObanHelpers.perform(job)
|
||||
user = User.get_by_id(user.id)
|
||||
|
||||
assert %User{
|
||||
bio: nil,
|
||||
raw_bio: nil,
|
||||
email: nil,
|
||||
name: nil,
|
||||
password_hash: nil,
|
||||
keys: nil,
|
||||
public_key: nil,
|
||||
avatar: %{},
|
||||
tags: [],
|
||||
last_refreshed_at: nil,
|
||||
last_digest_emailed_at: nil,
|
||||
banner: %{},
|
||||
background: %{},
|
||||
note_count: 0,
|
||||
follower_count: 0,
|
||||
following_count: 0,
|
||||
locked: false,
|
||||
confirmation_pending: false,
|
||||
password_reset_pending: false,
|
||||
approval_pending: false,
|
||||
registration_reason: nil,
|
||||
confirmation_token: nil,
|
||||
domain_blocks: [],
|
||||
deactivated: true,
|
||||
ap_enabled: false,
|
||||
is_moderator: false,
|
||||
is_admin: false,
|
||||
mastofe_settings: nil,
|
||||
mascot: nil,
|
||||
emoji: %{},
|
||||
pleroma_settings_store: %{},
|
||||
fields: [],
|
||||
raw_fields: [],
|
||||
discoverable: false,
|
||||
also_known_as: []
|
||||
} = user
|
||||
end
|
||||
|
||||
test "get_public_key_for_ap_id fetches a user that's not in the db" do
|
||||
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptValidationTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
alias Pleroma.Web.ActivityPub.Pipeline
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, local: false)
|
||||
|
||||
{:ok, follow_data, _} = Builder.follow(follower, followed)
|
||||
{:ok, follow_activity, _} = Pipeline.common_pipeline(follow_data, local: true)
|
||||
|
||||
{:ok, accept_data, _} = Builder.accept(followed, follow_activity)
|
||||
|
||||
%{accept_data: accept_data, followed: followed}
|
||||
end
|
||||
|
||||
test "it validates a basic 'accept'", %{accept_data: accept_data} do
|
||||
assert {:ok, _, _} = ObjectValidator.validate(accept_data, [])
|
||||
end
|
||||
|
||||
test "it fails when the actor doesn't exist", %{accept_data: accept_data} do
|
||||
accept_data =
|
||||
accept_data
|
||||
|> Map.put("actor", "https://gensokyo.2hu/users/raymoo")
|
||||
|
||||
assert {:error, _} = ObjectValidator.validate(accept_data, [])
|
||||
end
|
||||
|
||||
test "it fails when the accepted activity doesn't exist", %{accept_data: accept_data} do
|
||||
accept_data =
|
||||
accept_data
|
||||
|> Map.put("object", "https://gensokyo.2hu/users/raymoo/follows/1")
|
||||
|
||||
assert {:error, _} = ObjectValidator.validate(accept_data, [])
|
||||
end
|
||||
|
||||
test "for an accepted follow, it only validates if the actor of the accept is the followed actor",
|
||||
%{accept_data: accept_data} do
|
||||
stranger = insert(:user)
|
||||
|
||||
accept_data =
|
||||
accept_data
|
||||
|> Map.put("actor", stranger.ap_id)
|
||||
|
||||
assert {:error, _} = ObjectValidator.validate(accept_data, [])
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.RejectValidationTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.ObjectValidator
|
||||
alias Pleroma.Web.ActivityPub.Pipeline
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, local: false)
|
||||
|
||||
{:ok, follow_data, _} = Builder.follow(follower, followed)
|
||||
{:ok, follow_activity, _} = Pipeline.common_pipeline(follow_data, local: true)
|
||||
|
||||
{:ok, reject_data, _} = Builder.reject(followed, follow_activity)
|
||||
|
||||
%{reject_data: reject_data, followed: followed}
|
||||
end
|
||||
|
||||
test "it validates a basic 'reject'", %{reject_data: reject_data} do
|
||||
assert {:ok, _, _} = ObjectValidator.validate(reject_data, [])
|
||||
end
|
||||
|
||||
test "it fails when the actor doesn't exist", %{reject_data: reject_data} do
|
||||
reject_data =
|
||||
reject_data
|
||||
|> Map.put("actor", "https://gensokyo.2hu/users/raymoo")
|
||||
|
||||
assert {:error, _} = ObjectValidator.validate(reject_data, [])
|
||||
end
|
||||
|
||||
test "it fails when the rejected activity doesn't exist", %{reject_data: reject_data} do
|
||||
reject_data =
|
||||
reject_data
|
||||
|> Map.put("object", "https://gensokyo.2hu/users/raymoo/follows/1")
|
||||
|
||||
assert {:error, _} = ObjectValidator.validate(reject_data, [])
|
||||
end
|
||||
|
||||
test "for an rejected follow, it only validates if the actor of the reject is the followed actor",
|
||||
%{reject_data: reject_data} do
|
||||
stranger = insert(:user)
|
||||
|
||||
reject_data =
|
||||
reject_data
|
||||
|> Map.put("actor", stranger.ap_id)
|
||||
|
||||
assert {:error, _} = ObjectValidator.validate(reject_data, [])
|
||||
end
|
||||
end
|
||||
|
|
@ -19,8 +19,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
alias Pleroma.Web.ActivityPub.SideEffects
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "handle_after_transaction" do
|
||||
test "it streams out notifications and streams" do
|
||||
|
|
@ -221,6 +222,22 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
|
||||
assert User.get_cached_by_ap_id(user.ap_id).deactivated
|
||||
end
|
||||
|
||||
test "it logs issues with objects deletion", %{
|
||||
delete: delete,
|
||||
object: object
|
||||
} do
|
||||
{:ok, object} =
|
||||
object
|
||||
|> Object.change(%{data: Map.delete(object.data, "actor")})
|
||||
|> Repo.update()
|
||||
|
||||
Object.invalid_object_cache(object)
|
||||
|
||||
assert capture_log(fn ->
|
||||
{:error, :no_object_actor} = SideEffects.handle(delete)
|
||||
end) =~ "object doesn't have an actor"
|
||||
end
|
||||
end
|
||||
|
||||
describe "EmojiReact objects" do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AcceptHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it works for incoming accepts which were pre-accepted" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
object =
|
||||
accept_data["object"]
|
||||
|> Map.put("actor", follower.ap_id)
|
||||
|> Map.put("id", follow_activity.data["id"])
|
||||
|
||||
accept_data = Map.put(accept_data, "object", object)
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
refute activity.local
|
||||
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
assert activity.data["id"] == accept_data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
follower = User.get_by_id(follower.id)
|
||||
assert follower.following_count == 1
|
||||
|
||||
followed = User.get_by_id(followed.id)
|
||||
assert followed.follower_count == 1
|
||||
end
|
||||
|
||||
test "it fails for incoming accepts which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
{:error, _} = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
refute User.following?(follower, followed) == true
|
||||
end
|
||||
end
|
||||
45
test/web/activity_pub/transmogrifier/audio_handling_test.exs
Normal file
45
test/web/activity_pub/transmogrifier/audio_handling_test.exs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
||||
use Oban.Testing, repo: Pleroma.Repo
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it works for incoming listens" do
|
||||
_user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"type" => "Listen",
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
|
||||
"actor" => "http://mastodon.example.org/users/admin",
|
||||
"object" => %{
|
||||
"type" => "Audio",
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio",
|
||||
"length" => 180_000
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
assert object.data["artist"] == "lain"
|
||||
assert object.data["album"] == "lain radio"
|
||||
assert object.data["length"] == 180_000
|
||||
end
|
||||
end
|
||||
|
|
@ -185,5 +185,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do
|
|||
assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
|
||||
assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it works for incoming follows to locked account" do
|
||||
pending_follower = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
user = insert(:user, locked: true)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Follow"
|
||||
assert data["object"] == user.ap_id
|
||||
assert data["state"] == "pending"
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
assert [^pending_follower] = User.get_follow_requests(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.RejectHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "it fails for incoming rejects which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
{:error, _} = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
refute User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming rejects which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
reject_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == false
|
||||
end
|
||||
|
||||
test "it rejects activities without a valid ID" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|> Map.put("id", "")
|
||||
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
end
|
||||
|
|
@ -130,7 +130,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do
|
|||
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||
end
|
||||
|
||||
test "it works for incomming unfollows with an existing follow" do
|
||||
test "it works for incoming unfollows with an existing follow" do
|
||||
user = insert(:user)
|
||||
|
||||
follow_data =
|
||||
|
|
|
|||
|
|
@ -225,35 +225,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert Enum.at(object.data["tag"], 2) == "moo"
|
||||
end
|
||||
|
||||
test "it works for incoming listens" do
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||
"cc" => [],
|
||||
"type" => "Listen",
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
|
||||
"actor" => "http://mastodon.example.org/users/admin",
|
||||
"object" => %{
|
||||
"type" => "Audio",
|
||||
"id" => "http://mastodon.example.org/users/admin/listens/1234",
|
||||
"attributedTo" => "http://mastodon.example.org/users/admin",
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio",
|
||||
"length" => 180_000
|
||||
}
|
||||
}
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert object.data["title"] == "lain radio episode 1"
|
||||
assert object.data["artist"] == "lain"
|
||||
assert object.data["album"] == "lain radio"
|
||||
assert object.data["length"] == 180_000
|
||||
end
|
||||
|
||||
test "it works for incoming notices with contentMap" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
|
||||
|
|
@ -359,7 +330,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute Map.has_key?(object_data, "reaction_count")
|
||||
end
|
||||
|
||||
test "it works for incomming unfollows with an existing follow" do
|
||||
test "it works for incoming unfollows with an existing follow" do
|
||||
user = insert(:user)
|
||||
|
||||
follow_data =
|
||||
|
|
@ -384,204 +355,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
|
||||
end
|
||||
|
||||
test "it works for incoming follows to locked account" do
|
||||
pending_follower = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
||||
user = insert(:user, locked: true)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["type"] == "Follow"
|
||||
assert data["object"] == user.ap_id
|
||||
assert data["state"] == "pending"
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
|
||||
assert [^pending_follower] = User.get_follow_requests(user)
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which were pre-accepted" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
object =
|
||||
accept_data["object"]
|
||||
|> Map.put("actor", follower.ap_id)
|
||||
|> Map.put("id", follow_activity.data["id"])
|
||||
|
||||
accept_data = Map.put(accept_data, "object", object)
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
refute activity.local
|
||||
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
assert activity.data["id"] == accept_data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which were orphaned" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming accepts which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
|
||||
assert activity.data["object"] == follow_activity.data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
follower = User.get_by_id(follower.id)
|
||||
assert follower.following_count == 1
|
||||
|
||||
followed = User.get_by_id(followed.id)
|
||||
assert followed.follower_count == 1
|
||||
end
|
||||
|
||||
test "it fails for incoming accepts which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-accept-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
:error = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
refute User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it fails for incoming rejects which cannot be correlated" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
accept_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
accept_data =
|
||||
Map.put(accept_data, "object", Map.put(accept_data["object"], "actor", follower.ap_id))
|
||||
|
||||
:error = Transmogrifier.handle_incoming(accept_data)
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
refute User.following?(follower, followed) == true
|
||||
end
|
||||
|
||||
test "it works for incoming rejects which are orphaned" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
reject_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|
||||
reject_data =
|
||||
Map.put(reject_data, "object", Map.put(reject_data["object"], "actor", follower.ap_id))
|
||||
|
||||
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
|
||||
refute activity.local
|
||||
assert activity.data["id"] == reject_data["id"]
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == false
|
||||
end
|
||||
|
||||
test "it works for incoming rejects which are referenced by IRI only" do
|
||||
follower = insert(:user)
|
||||
followed = insert(:user, locked: true)
|
||||
|
||||
{:ok, follower} = User.follow(follower, followed)
|
||||
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|
||||
|
||||
assert User.following?(follower, followed) == true
|
||||
|
||||
reject_data =
|
||||
File.read!("test/fixtures/mastodon-reject-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("actor", followed.ap_id)
|
||||
|> Map.put("object", follow_activity.data["id"])
|
||||
|
||||
{:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
|
||||
|
||||
follower = User.get_cached_by_id(follower.id)
|
||||
|
||||
assert User.following?(follower, followed) == false
|
||||
end
|
||||
|
||||
test "it rejects activities without a valid ID" do
|
||||
user = insert(:user)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-follow-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("object", user.ap_id)
|
||||
|> Map.put("id", "")
|
||||
|
||||
:error = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "skip converting the content when it is nil" do
|
||||
object_id = "https://peertube.social/videos/watch/278d2b7c-0f38-4aaa-afe6-9ecc0c4a34fe"
|
||||
|
||||
|
|
|
|||
|
|
@ -155,11 +155,30 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
describe "DELETE /api/pleroma/admin/users" do
|
||||
test "single user", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
user =
|
||||
insert(:user,
|
||||
avatar: %{"url" => [%{"href" => "https://someurl"}]},
|
||||
banner: %{"url" => [%{"href" => "https://somebanner"}]},
|
||||
bio: "Hello world!",
|
||||
name: "A guy"
|
||||
)
|
||||
|
||||
# Create some activities to check they got deleted later
|
||||
follower = insert(:user)
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
{:ok, _, _, _} = CommonAPI.follow(user, follower)
|
||||
{:ok, _, _, _} = CommonAPI.follow(follower, user)
|
||||
user = Repo.get(User, user.id)
|
||||
assert user.note_count == 1
|
||||
assert user.follower_count == 1
|
||||
assert user.following_count == 1
|
||||
refute user.deactivated
|
||||
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end do
|
||||
publish: fn _ -> nil end,
|
||||
perform: fn _, _ -> nil end do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("accept", "application/json")
|
||||
|
|
@ -176,6 +195,17 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|
||||
assert json_response(conn, 200) == [user.nickname]
|
||||
|
||||
user = Repo.get(User, user.id)
|
||||
assert user.deactivated
|
||||
|
||||
assert user.avatar == %{}
|
||||
assert user.banner == %{}
|
||||
assert user.note_count == 0
|
||||
assert user.follower_count == 0
|
||||
assert user.following_count == 0
|
||||
assert user.bio == nil
|
||||
assert user.name == nil
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(:_))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1342,6 +1342,75 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
args: ["auto-orient", "strip", {"implode", "1"}, {"resize", "3840x1080>"}]
|
||||
]
|
||||
end
|
||||
|
||||
test "enables the welcome messages", %{conn: conn} do
|
||||
clear_config([:welcome])
|
||||
|
||||
params = %{
|
||||
"group" => ":pleroma",
|
||||
"key" => ":welcome",
|
||||
"value" => [
|
||||
%{
|
||||
"tuple" => [
|
||||
":direct_message",
|
||||
[
|
||||
%{"tuple" => [":enabled", true]},
|
||||
%{"tuple" => [":message", "Welcome to Pleroma!"]},
|
||||
%{"tuple" => [":sender_nickname", "pleroma"]}
|
||||
]
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
":chat_message",
|
||||
[
|
||||
%{"tuple" => [":enabled", true]},
|
||||
%{"tuple" => [":message", "Welcome to Pleroma!"]},
|
||||
%{"tuple" => [":sender_nickname", "pleroma"]}
|
||||
]
|
||||
]
|
||||
},
|
||||
%{
|
||||
"tuple" => [
|
||||
":email",
|
||||
[
|
||||
%{"tuple" => [":enabled", true]},
|
||||
%{"tuple" => [":sender", %{"tuple" => ["pleroma@dev.dev", "Pleroma"]}]},
|
||||
%{"tuple" => [":subject", "Welcome to <%= instance_name %>!"]},
|
||||
%{"tuple" => [":html", "Welcome to <%= instance_name %>!"]},
|
||||
%{"tuple" => [":text", "Welcome to <%= instance_name %>!"]}
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
refute Pleroma.User.WelcomeEmail.enabled?()
|
||||
refute Pleroma.User.WelcomeMessage.enabled?()
|
||||
refute Pleroma.User.WelcomeChatMessage.enabled?()
|
||||
|
||||
res =
|
||||
assert conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/config", %{"configs" => [params]})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert Pleroma.User.WelcomeEmail.enabled?()
|
||||
assert Pleroma.User.WelcomeMessage.enabled?()
|
||||
assert Pleroma.User.WelcomeChatMessage.enabled?()
|
||||
|
||||
assert res == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"db" => [":direct_message", ":chat_message", ":email"],
|
||||
"group" => ":pleroma",
|
||||
"key" => ":welcome",
|
||||
"value" => params["value"]
|
||||
}
|
||||
],
|
||||
"need_reboot" => false
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/config/descriptions" do
|
||||
|
|
|
|||
|
|
@ -48,6 +48,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["page_size"] == 2
|
||||
assert response["count"] == 5
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/fb1f4d.jpg",
|
||||
"http://localhost:4001/media/a688346.jpg"
|
||||
|
|
@ -63,6 +66,9 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
"http://localhost:4001/media/tb13f47.jpg"
|
||||
]
|
||||
|
||||
assert response["page_size"] == 2
|
||||
assert response["count"] == 5
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&page=3")
|
||||
|
|
@ -70,6 +76,30 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
|
||||
assert response["urls"] == ["http://localhost:4001/media/wb1f46.jpg"]
|
||||
end
|
||||
|
||||
test "search banned MediaProxy URLs", %{conn: conn} do
|
||||
MediaProxy.put_in_banned_urls([
|
||||
"http://localhost:4001/media/a688346.jpg",
|
||||
"http://localhost:4001/media/ff44b1f4d.jpg"
|
||||
])
|
||||
|
||||
MediaProxy.put_in_banned_urls("http://localhost:4001/media/gb1f44.jpg")
|
||||
MediaProxy.put_in_banned_urls("http://localhost:4001/media/tb13f47.jpg")
|
||||
MediaProxy.put_in_banned_urls("http://localhost:4001/media/wb1f46.jpg")
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/media_proxy_caches?page_size=2&query=F44")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == [
|
||||
"http://localhost:4001/media/gb1f44.jpg",
|
||||
"http://localhost:4001/media/ff44b1f4d.jpg"
|
||||
]
|
||||
|
||||
assert response["page_size"] == 2
|
||||
assert response["count"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/media_proxy_caches/delete" do
|
||||
|
|
@ -79,15 +109,13 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
"http://localhost:4001/media/fb1f4d.jpg"
|
||||
])
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/delete", %{
|
||||
urls: ["http://localhost:4001/media/a688346.jpg"]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/delete", %{
|
||||
urls: ["http://localhost:4001/media/a688346.jpg"]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == ["http://localhost:4001/media/a688346.jpg"]
|
||||
refute MediaProxy.in_banned_urls("http://localhost:4001/media/a688346.jpg")
|
||||
assert MediaProxy.in_banned_urls("http://localhost:4001/media/fb1f4d.jpg")
|
||||
end
|
||||
|
|
@ -106,13 +134,10 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
purge: fn _, _ -> {"ok", 0} end
|
||||
]}
|
||||
] do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/purge", %{urls: urls, ban: false})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == urls
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/purge", %{urls: urls, ban: false})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
refute MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
|
||||
refute MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
|
||||
|
|
@ -126,16 +151,13 @@ defmodule Pleroma.Web.AdminAPI.MediaProxyCacheControllerTest do
|
|||
]
|
||||
|
||||
with_mocks [{MediaProxy.Invalidation.Script, [], [purge: fn _, _ -> {"ok", 0} end]}] do
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/pleroma/admin/media_proxy_caches/purge", %{
|
||||
urls: urls,
|
||||
ban: true
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["urls"] == urls
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
"/api/pleroma/admin/media_proxy_caches/purge",
|
||||
%{urls: urls, ban: true}
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
|
||||
assert MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
|
||||
|
|
|
|||
|
|
@ -445,6 +445,23 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
assert length(json_response(res_conn, 200)) == 2
|
||||
end
|
||||
|
||||
test "with default settings on private instances, returns 403 for unauthenticated users", %{
|
||||
conn: conn,
|
||||
base_uri: base_uri,
|
||||
error_response: error_response
|
||||
} do
|
||||
clear_config([:instance, :public], false)
|
||||
clear_config([:restrict_unauthenticated, :timelines])
|
||||
|
||||
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: true, federated: true}`, returns 403 for unauthenticated users", %{
|
||||
conn: conn,
|
||||
base_uri: base_uri,
|
||||
|
|
|
|||
|
|
@ -12,16 +12,8 @@ defmodule Pleroma.Web.Preload.Providers.TimelineTest do
|
|||
@public_url "/api/v1/timelines/public"
|
||||
|
||||
describe "unauthenticated timeliness when restricted" do
|
||||
setup do
|
||||
svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{local: true, federated: true})
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
||||
|
||||
test "return nothing" do
|
||||
tl_data = Timelines.generate_terms(%{})
|
||||
|
|
@ -31,20 +23,10 @@ defmodule Pleroma.Web.Preload.Providers.TimelineTest do
|
|||
end
|
||||
|
||||
describe "unauthenticated timeliness when unrestricted" do
|
||||
setup do
|
||||
svd_config = Pleroma.Config.get([:restrict_unauthenticated, :timelines])
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], false)
|
||||
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], false)
|
||||
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], %{
|
||||
local: false,
|
||||
federated: false
|
||||
})
|
||||
|
||||
on_exit(fn ->
|
||||
Pleroma.Config.put([:restrict_unauthenticated, :timelines], svd_config)
|
||||
end)
|
||||
|
||||
{:ok, user: insert(:user)}
|
||||
end
|
||||
setup do: {:ok, user: insert(:user)}
|
||||
|
||||
test "returns the timeline when not restricted" do
|
||||
assert Timelines.generate_terms(%{})
|
||||
|
|
|
|||
|
|
@ -586,10 +586,16 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "with proper permissions and valid password", %{conn: conn} do
|
||||
test "with proper permissions and valid password", %{conn: conn, user: user} do
|
||||
conn = post(conn, "/api/pleroma/delete_account", %{"password" => "test"})
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
assert json_response(conn, 200) == %{"status" => "success"}
|
||||
|
||||
user = User.get_by_id(user.id)
|
||||
assert user.deactivated == true
|
||||
assert user.name == nil
|
||||
assert user.bio == nil
|
||||
assert user.password_hash == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue