Merge remote-tracking branch 'upstream/develop' into aliases
This commit is contained in:
commit
1a5a7ba6e8
186 changed files with 4752 additions and 940 deletions
|
|
@ -1179,7 +1179,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
"id" => activity_ap_id,
|
||||
"content" => content,
|
||||
"published" => activity_with_object.object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: target_account})
|
||||
"actor" =>
|
||||
AccountView.render("show.json", %{user: target_account, skip_visibility_check: true})
|
||||
}
|
||||
|
||||
assert %Activity{
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
alias Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicy
|
||||
|
||||
@id Pleroma.Web.Endpoint.url() <> "/activities/cofe"
|
||||
@local_actor Pleroma.Web.Endpoint.url() <> "/users/cofe"
|
||||
|
||||
test "adds `expires_at` property" do
|
||||
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => @id,
|
||||
"actor" => @local_actor,
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note"}
|
||||
})
|
||||
|
|
@ -25,6 +27,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, %{"type" => "Create", "expires_at" => ^expires_at}} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => @id,
|
||||
"actor" => @local_actor,
|
||||
"type" => "Create",
|
||||
"expires_at" => expires_at,
|
||||
"object" => %{"type" => "Note"}
|
||||
|
|
@ -37,6 +40,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, %{"type" => "Create", "expires_at" => expires_at}} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => @id,
|
||||
"actor" => @local_actor,
|
||||
"type" => "Create",
|
||||
"expires_at" => too_distant_future,
|
||||
"object" => %{"type" => "Note"}
|
||||
|
|
@ -49,6 +53,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, activity} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => "https://example.com/123",
|
||||
"actor" => "https://example.com/users/cofe",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note"}
|
||||
})
|
||||
|
|
@ -60,6 +65,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, activity} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => "https://example.com/123",
|
||||
"actor" => "https://example.com/users/cofe",
|
||||
"type" => "Follow"
|
||||
})
|
||||
|
||||
|
|
@ -68,6 +74,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ActivityExpirationPolicyTest do
|
|||
assert {:ok, activity} =
|
||||
ActivityExpirationPolicy.filter(%{
|
||||
"id" => "https://example.com/123",
|
||||
"actor" => "https://example.com/users/cofe",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Cofe"}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -78,5 +78,15 @@ defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
|
|||
assert {:ok, res} = EnsureRePrepended.filter(message)
|
||||
assert res == message
|
||||
end
|
||||
|
||||
test "it skips if the object is only a reference" do
|
||||
message = %{
|
||||
"type" => "Create",
|
||||
"object" => "somereference"
|
||||
}
|
||||
|
||||
assert {:ok, res} = EnsureRePrepended.filter(message)
|
||||
assert res == message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,6 +38,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
describe "with reject action" do
|
||||
test "works with objects with empty to or cc fields" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
data =
|
||||
get_old_message()
|
||||
|> Map.put("cc", nil)
|
||||
|> Map.put("to", nil)
|
||||
|
||||
assert match?({:reject, _}, ObjectAgePolicy.filter(data))
|
||||
end
|
||||
|
||||
test "it rejects an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
|
|
@ -56,6 +67,21 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
describe "with delist action" do
|
||||
test "works with objects with empty to or cc fields" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
data =
|
||||
get_old_message()
|
||||
|> Map.put("cc", nil)
|
||||
|> Map.put("to", nil)
|
||||
|
||||
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||
|
||||
{:ok, data} = ObjectAgePolicy.filter(data)
|
||||
|
||||
assert Visibility.get_visibility(%{data: data}) == "unlisted"
|
||||
end
|
||||
|
||||
test "it delists an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
|
|
@ -80,6 +106,22 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
end
|
||||
|
||||
describe "with strip_followers action" do
|
||||
test "works with objects with empty to or cc fields" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
data =
|
||||
get_old_message()
|
||||
|> Map.put("cc", nil)
|
||||
|> Map.put("to", nil)
|
||||
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||
|
||||
{:ok, data} = ObjectAgePolicy.filter(data)
|
||||
|
||||
refute user.follower_address in data["to"]
|
||||
refute user.follower_address in data["cc"]
|
||||
end
|
||||
|
||||
test "it strips followers collections from an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
import Pleroma.Factory
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Web.ActivityPub.MRF.SimplePolicy
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
setup do:
|
||||
clear_config(:mrf_simple,
|
||||
|
|
@ -15,6 +16,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
federated_timeline_removal: [],
|
||||
report_removal: [],
|
||||
reject: [],
|
||||
followers_only: [],
|
||||
accept: [],
|
||||
avatar_removal: [],
|
||||
banner_removal: [],
|
||||
|
|
@ -261,6 +263,64 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "when :followers_only" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :followers_only], [])
|
||||
{_, ftl_message} = build_ftl_actor_and_message()
|
||||
local_message = build_local_message()
|
||||
|
||||
assert SimplePolicy.filter(ftl_message) == {:ok, ftl_message}
|
||||
assert SimplePolicy.filter(local_message) == {:ok, local_message}
|
||||
end
|
||||
|
||||
test "has a matching host" do
|
||||
actor = insert(:user)
|
||||
following_user = insert(:user)
|
||||
non_following_user = insert(:user)
|
||||
|
||||
{:ok, _, _, _} = CommonAPI.follow(following_user, actor)
|
||||
|
||||
activity = %{
|
||||
"actor" => actor.ap_id,
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
following_user.ap_id,
|
||||
non_following_user.ap_id
|
||||
],
|
||||
"cc" => [actor.follower_address, "http://foo.bar/qux"]
|
||||
}
|
||||
|
||||
dm_activity = %{
|
||||
"actor" => actor.ap_id,
|
||||
"to" => [
|
||||
following_user.ap_id,
|
||||
non_following_user.ap_id
|
||||
],
|
||||
"cc" => []
|
||||
}
|
||||
|
||||
actor_domain =
|
||||
activity
|
||||
|> Map.fetch!("actor")
|
||||
|> URI.parse()
|
||||
|> Map.fetch!(:host)
|
||||
|
||||
Config.put([:mrf_simple, :followers_only], [actor_domain])
|
||||
|
||||
assert {:ok, new_activity} = SimplePolicy.filter(activity)
|
||||
assert actor.follower_address in new_activity["cc"]
|
||||
assert following_user.ap_id in new_activity["to"]
|
||||
refute "https://www.w3.org/ns/activitystreams#Public" in new_activity["to"]
|
||||
refute "https://www.w3.org/ns/activitystreams#Public" in new_activity["cc"]
|
||||
refute non_following_user.ap_id in new_activity["to"]
|
||||
refute non_following_user.ap_id in new_activity["cc"]
|
||||
|
||||
assert {:ok, new_dm_activity} = SimplePolicy.filter(dm_activity)
|
||||
assert new_dm_activity["to"] == [following_user.ap_id]
|
||||
assert new_dm_activity["cc"] == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "when :accept" do
|
||||
test "is empty" do
|
||||
Config.put([:mrf_simple, :accept], [])
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidationTest do
|
|||
|
||||
{:error, cng} = ObjectValidator.validate(invalid_other_actor, [])
|
||||
|
||||
assert {:actor, {"is not allowed to delete object", []}} in cng.errors
|
||||
assert {:actor, {"is not allowed to modify object", []}} in cng.errors
|
||||
end
|
||||
|
||||
test "it's valid if the actor of the object is a local superuser",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,51 @@ defmodule Pleroma.Web.ActivityPub.PipelineTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
test "when given an `object_data` in meta, Federation will receive a the original activity with the `object` field set to this embedded object" do
|
||||
activity = insert(:note_activity)
|
||||
object = %{"id" => "1", "type" => "Love"}
|
||||
meta = [local: true, object_data: object]
|
||||
|
||||
activity_with_object = %{activity | data: Map.put(activity.data, "object", object)}
|
||||
|
||||
with_mocks([
|
||||
{Pleroma.Web.ActivityPub.ObjectValidator, [], [validate: fn o, m -> {:ok, o, m} end]},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.MRF,
|
||||
[],
|
||||
[filter: fn o -> {:ok, o} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.ActivityPub,
|
||||
[],
|
||||
[persist: fn o, m -> {:ok, o, m} end]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.ActivityPub.SideEffects,
|
||||
[],
|
||||
[
|
||||
handle: fn o, m -> {:ok, o, m} end,
|
||||
handle_after_transaction: fn m -> m end
|
||||
]
|
||||
},
|
||||
{
|
||||
Pleroma.Web.Federator,
|
||||
[],
|
||||
[publish: fn _o -> :ok end]
|
||||
}
|
||||
]) do
|
||||
assert {:ok, ^activity, ^meta} =
|
||||
Pleroma.Web.ActivityPub.Pipeline.common_pipeline(activity, meta)
|
||||
|
||||
assert_called(Pleroma.Web.ActivityPub.ObjectValidator.validate(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.MRF.filter(activity))
|
||||
assert_called(Pleroma.Web.ActivityPub.ActivityPub.persist(activity, meta))
|
||||
assert_called(Pleroma.Web.ActivityPub.SideEffects.handle(activity, meta))
|
||||
refute called(Pleroma.Web.Federator.publish(activity))
|
||||
assert_called(Pleroma.Web.Federator.publish(activity_with_object))
|
||||
end
|
||||
end
|
||||
|
||||
test "it goes through validation, filtering, persisting, side effects and federation for local activities" do
|
||||
activity = insert(:note_activity)
|
||||
meta = [local: true]
|
||||
|
|
|
|||
|
|
@ -312,8 +312,12 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "deletes the original block", %{block_undo: block_undo, block: block} do
|
||||
{:ok, _block_undo, _} = SideEffects.handle(block_undo)
|
||||
test "deletes the original block", %{
|
||||
block_undo: block_undo,
|
||||
block: block
|
||||
} do
|
||||
{:ok, _block_undo, _meta} = SideEffects.handle(block_undo)
|
||||
|
||||
refute Activity.get_by_id(block.id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
# 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.AnswerHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "incoming, rewrites Note to Answer and increments vote counters" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "suya...",
|
||||
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
answer_object = Object.normalize(activity)
|
||||
assert answer_object.data["type"] == "Answer"
|
||||
assert answer_object.data["inReplyTo"] == object.data["id"]
|
||||
|
||||
new_object = Object.get_by_ap_id(object.data["id"])
|
||||
assert new_object.data["replies_count"] == object.data["replies_count"]
|
||||
|
||||
assert Enum.any?(
|
||||
new_object.data["oneOf"],
|
||||
fn
|
||||
%{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
|
||||
_ -> false
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
test "outgoing, rewrites Answer to Note" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, poll_activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "suya...",
|
||||
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
|
||||
})
|
||||
|
||||
poll_object = Object.normalize(poll_activity)
|
||||
# TODO: Replace with CommonAPI vote creation when implemented
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert data["object"]["type"] == "Note"
|
||||
end
|
||||
end
|
||||
|
|
@ -124,6 +124,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageTest do
|
|||
{:ok, %Activity{} = _activity} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it doesn't work for deactivated users" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
_author =
|
||||
insert(:user,
|
||||
ap_id: data["actor"],
|
||||
local: false,
|
||||
last_refreshed_at: DateTime.utc_now(),
|
||||
deactivated: true
|
||||
)
|
||||
|
||||
_recipient = insert(:user, ap_id: List.first(data["to"]), local: true)
|
||||
|
||||
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it inserts it and creates a chat" do
|
||||
data =
|
||||
File.read!("test/fixtures/create-chat-message.json")
|
||||
|
|
|
|||
123
test/web/activity_pub/transmogrifier/question_handling_test.exs
Normal file
123
test/web/activity_pub/transmogrifier/question_handling_test.exs
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
# 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.QuestionHandlingTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "Mastodon Question activity" do
|
||||
data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object = Object.normalize(activity, false)
|
||||
|
||||
assert object.data["closed"] == "2019-05-11T09:03:36Z"
|
||||
|
||||
assert object.data["context"] == activity.data["context"]
|
||||
|
||||
assert object.data["context"] ==
|
||||
"tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation"
|
||||
|
||||
assert object.data["context_id"]
|
||||
|
||||
assert object.data["anyOf"] == []
|
||||
|
||||
assert Enum.sort(object.data["oneOf"]) ==
|
||||
Enum.sort([
|
||||
%{
|
||||
"name" => "25 char limit is dumb",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"},
|
||||
"type" => "Note"
|
||||
},
|
||||
%{
|
||||
"name" => "Dunno",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"},
|
||||
"type" => "Note"
|
||||
},
|
||||
%{
|
||||
"name" => "Everyone knows that!",
|
||||
"replies" => %{"totalItems" => 1, "type" => "Collection"},
|
||||
"type" => "Note"
|
||||
},
|
||||
%{
|
||||
"name" => "I can't even fit a funny",
|
||||
"replies" => %{"totalItems" => 1, "type" => "Collection"},
|
||||
"type" => "Note"
|
||||
}
|
||||
])
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id})
|
||||
|
||||
reply_object = Object.normalize(reply_activity, false)
|
||||
|
||||
assert reply_object.data["context"] == object.data["context"]
|
||||
assert reply_object.data["context_id"] == object.data["context_id"]
|
||||
end
|
||||
|
||||
test "Mastodon Question activity with HTML tags in plaintext" do
|
||||
options = [
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "<input type=\"date\">",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"}
|
||||
},
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "<input type=\"date\"/>",
|
||||
"replies" => %{"totalItems" => 0, "type" => "Collection"}
|
||||
},
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "<input type=\"date\" />",
|
||||
"replies" => %{"totalItems" => 1, "type" => "Collection"}
|
||||
},
|
||||
%{
|
||||
"type" => "Note",
|
||||
"name" => "<input type=\"date\"></input>",
|
||||
"replies" => %{"totalItems" => 1, "type" => "Collection"}
|
||||
}
|
||||
]
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-question-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["object", "oneOf"], options)
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
object = Object.normalize(activity, false)
|
||||
|
||||
assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
|
||||
end
|
||||
|
||||
test "returns an error if received a second time" do
|
||||
data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
|
||||
|
||||
assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "accepts a Question with no content" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-question-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["object", "content"], "")
|
||||
|
||||
assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
end
|
||||
|
|
@ -160,7 +160,15 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert capture_log(fn ->
|
||||
{:ok, _returned_activity} = Transmogrifier.handle_incoming(data)
|
||||
end) =~ "[error] Couldn't fetch \"https://404.site/whatever\", error: nil"
|
||||
end) =~ "[warn] Couldn't fetch \"https://404.site/whatever\", error: nil"
|
||||
end
|
||||
|
||||
test "it does not work for deactivated users" do
|
||||
data = File.read!("test/fixtures/mastodon-post-activity.json") |> Poison.decode!()
|
||||
|
||||
insert(:user, ap_id: data["actor"], deactivated: true)
|
||||
|
||||
assert {:error, _} = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it works for incoming notices" do
|
||||
|
|
@ -217,23 +225,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert Enum.at(object.data["tag"], 2) == "moo"
|
||||
end
|
||||
|
||||
test "it works for incoming questions" do
|
||||
data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert Enum.all?(object.data["oneOf"], fn choice ->
|
||||
choice["name"] in [
|
||||
"Dunno",
|
||||
"Everyone knows that!",
|
||||
"25 char limit is dumb",
|
||||
"I can't even fit a funny"
|
||||
]
|
||||
end)
|
||||
end
|
||||
|
||||
test "it works for incoming listens" do
|
||||
data = %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
|
|
@ -263,38 +254,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert object.data["length"] == 180_000
|
||||
end
|
||||
|
||||
test "it rewrites Note votes to Answers and increments vote counters on question activities" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "suya...",
|
||||
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
answer_object = Object.normalize(activity)
|
||||
assert answer_object.data["type"] == "Answer"
|
||||
object = Object.get_by_ap_id(object.data["id"])
|
||||
|
||||
assert Enum.any?(
|
||||
object.data["oneOf"],
|
||||
fn
|
||||
%{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
|
||||
_ -> false
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
test "it works for incoming notices with contentMap" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity-contentmap.json") |> Poison.decode!()
|
||||
|
|
@ -669,7 +628,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
%{
|
||||
"href" =>
|
||||
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||
"mediaType" => "video/mp4"
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -688,7 +648,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
%{
|
||||
"href" =>
|
||||
"https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
|
||||
"mediaType" => "video/mp4"
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -710,7 +671,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"id" => activity.data["id"],
|
||||
"content" => "test post",
|
||||
"published" => object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: user})
|
||||
"actor" => AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
}
|
||||
|
||||
message = %{
|
||||
|
|
@ -1261,30 +1222,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "Rewrites Answers to Notes" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, poll_activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "suya...",
|
||||
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
|
||||
})
|
||||
|
||||
poll_object = Object.normalize(poll_activity)
|
||||
# TODO: Replace with CommonAPI vote creation when implemented
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-vote.json")
|
||||
|> Poison.decode!()
|
||||
|> Kernel.put_in(["to"], user.ap_id)
|
||||
|> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
|
||||
|> Kernel.put_in(["object", "to"], user.ap_id)
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert data["object"]["type"] == "Note"
|
||||
end
|
||||
|
||||
describe "fix_explicit_addressing" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
@ -1532,8 +1469,13 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Document",
|
||||
"url" => [
|
||||
%{"href" => "https://peertube.moe/stat-480.mp4", "mediaType" => "video/mp4"}
|
||||
%{
|
||||
"href" => "https://peertube.moe/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -1550,14 +1492,24 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
"attachment" => [
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Document",
|
||||
"url" => [
|
||||
%{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
},
|
||||
%{
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Document",
|
||||
"url" => [
|
||||
%{"href" => "https://pe.er/stat-480.mp4", "mediaType" => "video/mp4"}
|
||||
%{
|
||||
"href" => "https://pe.er/stat-480.mp4",
|
||||
"mediaType" => "video/mp4",
|
||||
"type" => "Link"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -482,7 +482,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
"id" => activity_ap_id,
|
||||
"content" => content,
|
||||
"published" => activity.object.data["published"],
|
||||
"actor" => AccountView.render("show.json", %{user: target_account})
|
||||
"actor" =>
|
||||
AccountView.render("show.json", %{user: target_account, skip_visibility_check: true})
|
||||
}
|
||||
|
||||
assert %{
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
|
|
@ -348,7 +349,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
|
||||
assert expected == json_response(conn, 200)
|
||||
|
|
@ -612,6 +615,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
describe "GET /api/pleroma/admin/users" do
|
||||
test "renders users array for the first page", %{conn: conn, admin: admin} do
|
||||
user = insert(:user, local: false, tags: ["foo", "bar"])
|
||||
user2 = insert(:user, approval_pending: true, registration_reason: "I'm a chill dude")
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?page=1")
|
||||
|
||||
users =
|
||||
|
|
@ -626,7 +631,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => admin.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => admin.ap_id,
|
||||
"registration_reason" => nil
|
||||
},
|
||||
%{
|
||||
"deactivated" => user.deactivated,
|
||||
|
|
@ -638,13 +645,29 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
},
|
||||
%{
|
||||
"deactivated" => user2.deactivated,
|
||||
"id" => user2.id,
|
||||
"nickname" => user2.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
"local" => true,
|
||||
"tags" => [],
|
||||
"avatar" => User.avatar_url(user2) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user2.name || user2.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"approval_pending" => true,
|
||||
"url" => user2.ap_id,
|
||||
"registration_reason" => "I'm a chill dude"
|
||||
}
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 2,
|
||||
"count" => 3,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
|
|
@ -711,7 +734,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -737,7 +762,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -763,7 +790,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -789,7 +818,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -815,7 +846,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -841,7 +874,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -862,7 +897,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user2) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user2.name || user2.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user2.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user2.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -895,7 +932,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -921,7 +960,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
},
|
||||
%{
|
||||
"deactivated" => admin.deactivated,
|
||||
|
|
@ -933,7 +974,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => admin.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => admin.ap_id,
|
||||
"registration_reason" => nil
|
||||
},
|
||||
%{
|
||||
"deactivated" => false,
|
||||
|
|
@ -945,7 +988,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(old_admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(old_admin.name || old_admin.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => old_admin.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => old_admin.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
|
@ -957,6 +1002,44 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "only unapproved users", %{conn: conn} do
|
||||
user =
|
||||
insert(:user,
|
||||
nickname: "sadboy",
|
||||
approval_pending: true,
|
||||
registration_reason: "Plz let me in!"
|
||||
)
|
||||
|
||||
insert(:user, nickname: "happyboy", approval_pending: false)
|
||||
|
||||
conn = get(conn, "/api/pleroma/admin/users?filters=need_approval")
|
||||
|
||||
users =
|
||||
[
|
||||
%{
|
||||
"deactivated" => user.deactivated,
|
||||
"id" => user.id,
|
||||
"nickname" => user.nickname,
|
||||
"roles" => %{"admin" => false, "moderator" => false},
|
||||
"local" => true,
|
||||
"tags" => [],
|
||||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"approval_pending" => true,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => "Plz let me in!"
|
||||
}
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"count" => 1,
|
||||
"page_size" => 50,
|
||||
"users" => users
|
||||
}
|
||||
end
|
||||
|
||||
test "load only admins", %{conn: conn, admin: admin} do
|
||||
second_admin = insert(:user, is_admin: true)
|
||||
insert(:user)
|
||||
|
|
@ -976,7 +1059,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => admin.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => admin.ap_id,
|
||||
"registration_reason" => nil
|
||||
},
|
||||
%{
|
||||
"deactivated" => false,
|
||||
|
|
@ -988,7 +1073,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(second_admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(second_admin.name || second_admin.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => second_admin.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => second_admin.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
|
@ -1021,7 +1108,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(moderator) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(moderator.name || moderator.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => moderator.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => moderator.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1047,7 +1136,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user1) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user1.name || user1.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user1.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user1.ap_id,
|
||||
"registration_reason" => nil
|
||||
},
|
||||
%{
|
||||
"deactivated" => false,
|
||||
|
|
@ -1059,7 +1150,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user2) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user2.name || user2.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user2.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user2.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
|> Enum.sort_by(& &1["nickname"])
|
||||
|
|
@ -1099,7 +1192,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1124,7 +1219,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(admin) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(admin.name || admin.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => admin.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => admin.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1171,6 +1268,26 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{admin.nickname} deactivated users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/approve", %{admin: admin, conn: conn} do
|
||||
user_one = insert(:user, approval_pending: true)
|
||||
user_two = insert(:user, approval_pending: true)
|
||||
|
||||
conn =
|
||||
patch(
|
||||
conn,
|
||||
"/api/pleroma/admin/users/approve",
|
||||
%{nicknames: [user_one.nickname, user_two.nickname]}
|
||||
)
|
||||
|
||||
response = json_response(conn, 200)
|
||||
assert Enum.map(response["users"], & &1["approval_pending"]) == [false, false]
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
||||
assert ModerationLog.get_log_entry_message(log_entry) ==
|
||||
"@#{admin.nickname} approved users: @#{user_one.nickname}, @#{user_two.nickname}"
|
||||
end
|
||||
|
||||
test "PATCH /api/pleroma/admin/users/:nickname/toggle_activation", %{admin: admin, conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -1187,7 +1304,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"avatar" => User.avatar_url(user) |> MediaProxy.url(),
|
||||
"display_name" => HTML.strip_tags(user.name || user.nickname),
|
||||
"confirmation_pending" => false,
|
||||
"url" => user.ap_id
|
||||
"approval_pending" => false,
|
||||
"url" => user.ap_id,
|
||||
"registration_reason" => nil
|
||||
}
|
||||
|
||||
log_entry = Repo.one(ModerationLog)
|
||||
|
|
@ -1731,6 +1850,9 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{admin.nickname} re-sent confirmation email for users: @#{first_user.nickname}, @#{
|
||||
second_user.nickname
|
||||
}"
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
assert_email_sent(Pleroma.Emails.UserEmail.account_confirmation_email(first_user))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
test "returns empty response when no reports created", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports")
|
||||
|> get(report_path(conn, :index))
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert Enum.empty?(response["reports"])
|
||||
|
|
@ -224,7 +224,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports")
|
||||
|> get(report_path(conn, :index))
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
[report] = response["reports"]
|
||||
|
|
@ -256,7 +256,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports?state=open")
|
||||
|> get(report_path(conn, :index, %{state: "open"}))
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [open_report] = response["reports"]
|
||||
|
|
@ -268,7 +268,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports?state=closed")
|
||||
|> get(report_path(conn, :index, %{state: "closed"}))
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert [closed_report] = response["reports"]
|
||||
|
|
@ -280,9 +280,7 @@ defmodule Pleroma.Web.AdminAPI.ReportControllerTest do
|
|||
|
||||
assert %{"total" => 0, "reports" => []} ==
|
||||
conn
|
||||
|> get("/api/pleroma/admin/reports?state=resolved", %{
|
||||
"" => ""
|
||||
})
|
||||
|> get(report_path(conn, :index, %{state: "resolved"}))
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -166,5 +166,16 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
|
|||
assert total == 3
|
||||
assert count == 1
|
||||
end
|
||||
|
||||
test "it returns unapproved user" do
|
||||
unapproved = insert(:user, approval_pending: true)
|
||||
insert(:user)
|
||||
insert(:user)
|
||||
|
||||
{:ok, _results, total} = Search.user()
|
||||
{:ok, [^unapproved], count} = Search.user(%{need_approval: true})
|
||||
assert total == 3
|
||||
assert count == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@
|
|||
|
||||
defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Web.AdminAPI
|
||||
alias Pleroma.Web.AdminAPI.Report
|
||||
alias Pleroma.Web.AdminAPI.ReportView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.MastodonAPI
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
|
||||
test "renders a report" do
|
||||
|
|
@ -21,13 +24,16 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
content: nil,
|
||||
actor:
|
||||
Map.merge(
|
||||
AccountView.render("show.json", %{user: user}),
|
||||
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
|
||||
MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
|
||||
AdminAPI.AccountView.render("show.json", %{user: user})
|
||||
),
|
||||
account:
|
||||
Map.merge(
|
||||
AccountView.render("show.json", %{user: other_user}),
|
||||
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
MastodonAPI.AccountView.render("show.json", %{
|
||||
user: other_user,
|
||||
skip_visibility_check: true
|
||||
}),
|
||||
AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
),
|
||||
statuses: [],
|
||||
notes: [],
|
||||
|
|
@ -56,13 +62,16 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
|
|||
content: nil,
|
||||
actor:
|
||||
Map.merge(
|
||||
AccountView.render("show.json", %{user: user}),
|
||||
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: user})
|
||||
MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
|
||||
AdminAPI.AccountView.render("show.json", %{user: user})
|
||||
),
|
||||
account:
|
||||
Map.merge(
|
||||
AccountView.render("show.json", %{user: other_user}),
|
||||
Pleroma.Web.AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
MastodonAPI.AccountView.render("show.json", %{
|
||||
user: other_user,
|
||||
skip_visibility_check: true
|
||||
}),
|
||||
AdminAPI.AccountView.render("show.json", %{user: other_user})
|
||||
),
|
||||
statuses: [StatusView.render("show.json", %{activity: activity})],
|
||||
state: "open",
|
||||
|
|
|
|||
|
|
@ -458,6 +458,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
|
||||
describe "posting" do
|
||||
test "deactivated users can't post" do
|
||||
user = insert(:user, deactivated: true)
|
||||
assert {:error, _} = CommonAPI.post(user, %{status: "ye"})
|
||||
end
|
||||
|
||||
test "it supports explicit addressing" do
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
|
@ -624,14 +629,27 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
|
||||
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||
clear_config([:instance, :federating], true)
|
||||
|
||||
{:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||
with_mock Pleroma.Web.Federator,
|
||||
publish: fn _ -> nil end do
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{status: "cofe"})
|
||||
{:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert unreaction.data["type"] == "Undo"
|
||||
assert unreaction.data["object"] == reaction.data["id"]
|
||||
assert unreaction.local
|
||||
{:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍")
|
||||
|
||||
assert unreaction.data["type"] == "Undo"
|
||||
assert unreaction.data["object"] == reaction.data["id"]
|
||||
assert unreaction.local
|
||||
|
||||
# On federation, it contains the undone (and deleted) object
|
||||
unreaction_with_object = %{
|
||||
unreaction
|
||||
| data: Map.put(unreaction.data, "object", reaction.data)
|
||||
}
|
||||
|
||||
assert called(Pleroma.Web.Federator.publish(unreaction_with_object))
|
||||
end
|
||||
end
|
||||
|
||||
test "repeating a status" do
|
||||
|
|
|
|||
|
|
@ -181,6 +181,17 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
|
|||
|
||||
assert activity_titles == ['public', 'unlisted']
|
||||
end
|
||||
|
||||
test "returns 404 when the user is remote", %{conn: conn} do
|
||||
user = insert(:user, local: false)
|
||||
|
||||
{:ok, _} = CommonAPI.post(user, %{status: "test"})
|
||||
|
||||
assert conn
|
||||
|> put_req_header("accept", "application/atom+xml")
|
||||
|> get(user_feed_path(conn, :feed, user.nickname))
|
||||
|> response(404)
|
||||
end
|
||||
end
|
||||
|
||||
# Note: see ActivityPubControllerTest for JSON format tests
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -16,8 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
describe "account fetching" do
|
||||
setup do: clear_config([:instance, :limit_to_local_content])
|
||||
|
||||
test "works by id" do
|
||||
%User{id: user_id} = insert(:user)
|
||||
|
||||
|
|
@ -42,7 +39,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "works by nickname for remote users" do
|
||||
Config.put([:instance, :limit_to_local_content], false)
|
||||
clear_config([:instance, :limit_to_local_content], false)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
|
|
@ -53,7 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :all for remote user nicknames" do
|
||||
Config.put([:instance, :limit_to_local_content], :all)
|
||||
clear_config([:instance, :limit_to_local_content], :all)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
|
||||
|
|
@ -63,7 +60,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end
|
||||
|
||||
test "respects limit_to_local_content == :unauthenticated for remote user nicknames" do
|
||||
Config.put([:instance, :limit_to_local_content], :unauthenticated)
|
||||
clear_config([:instance, :limit_to_local_content], :unauthenticated)
|
||||
|
||||
user = insert(:user, nickname: "user@example.com", local: false)
|
||||
reading_user = insert(:user)
|
||||
|
|
@ -583,6 +580,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
|> get("/api/v1/accounts/#{user.id}/followers?max_id=#{follower3_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [%{"id" => ^follower2_id}, %{"id" => ^follower1_id}] =
|
||||
conn
|
||||
|> get(
|
||||
"/api/v1/accounts/#{user.id}/followers?id=#{user.id}&limit=20&max_id=#{
|
||||
follower3_id
|
||||
}"
|
||||
)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
res_conn = get(conn, "/api/v1/accounts/#{user.id}/followers?limit=1&max_id=#{follower3_id}")
|
||||
|
||||
assert [%{"id" => ^follower2_id}] = json_response_and_validate_schema(res_conn, 200)
|
||||
|
|
@ -654,6 +660,16 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert id2 == following2.id
|
||||
assert id1 == following1.id
|
||||
|
||||
res_conn =
|
||||
get(
|
||||
conn,
|
||||
"/api/v1/accounts/#{user.id}/following?id=#{user.id}&limit=20&max_id=#{following3.id}"
|
||||
)
|
||||
|
||||
assert [%{"id" => id2}, %{"id" => id1}] = json_response_and_validate_schema(res_conn, 200)
|
||||
assert id2 == following2.id
|
||||
assert id1 == following1.id
|
||||
|
||||
res_conn =
|
||||
get(conn, "/api/v1/accounts/#{user.id}/following?limit=1&max_id=#{following3.id}")
|
||||
|
||||
|
|
@ -884,9 +900,93 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
[valid_params: valid_params]
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
test "registers and logs in without :account_activation_required / :account_approval_required",
|
||||
%{conn: conn} do
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
clear_config([:instance, :account_approval_required], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/apps", %{
|
||||
client_name: "client_name",
|
||||
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||
scopes: "read, write, follow"
|
||||
})
|
||||
|
||||
assert %{
|
||||
"client_id" => client_id,
|
||||
"client_secret" => client_secret,
|
||||
"id" => _,
|
||||
"name" => "client_name",
|
||||
"redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
|
||||
"vapid_key" => _,
|
||||
"website" => nil
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
conn =
|
||||
post(conn, "/oauth/token", %{
|
||||
grant_type: "client_credentials",
|
||||
client_id: client_id,
|
||||
client_secret: client_secret
|
||||
})
|
||||
|
||||
assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
|
||||
json_response(conn, 200)
|
||||
|
||||
assert token
|
||||
token_from_db = Repo.get_by(Token, token: token)
|
||||
assert token_from_db
|
||||
assert refresh
|
||||
assert scope == "read write follow"
|
||||
|
||||
clear_config([User, :email_blacklist], ["example.org"])
|
||||
|
||||
params = %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
bio: "Test Bio",
|
||||
agreement: true
|
||||
}
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer " <> token)
|
||||
|> post("/api/v1/accounts", params)
|
||||
|
||||
assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
|
||||
json_response_and_validate_schema(conn, 400)
|
||||
|
||||
Pleroma.Config.put([User, :email_blacklist], [])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer " <> token)
|
||||
|> post("/api/v1/accounts", params)
|
||||
|
||||
%{
|
||||
"access_token" => token,
|
||||
"created_at" => _created_at,
|
||||
"scope" => ^scope,
|
||||
"token_type" => "Bearer"
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
token_from_db = Repo.get_by(Token, token: token)
|
||||
assert token_from_db
|
||||
user = Repo.preload(token_from_db, :user).user
|
||||
|
||||
assert user
|
||||
refute user.confirmation_pending
|
||||
refute user.approval_pending
|
||||
end
|
||||
|
||||
test "registers but does not log in with :account_activation_required", %{conn: conn} do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_approval_required], false)
|
||||
|
||||
test "Account registration via Application", %{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|
|
@ -934,19 +1034,76 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
agreement: true
|
||||
})
|
||||
|
||||
%{
|
||||
"access_token" => token,
|
||||
"created_at" => _created_at,
|
||||
"scope" => ^scope,
|
||||
"token_type" => "Bearer"
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert %{"identifier" => "missing_confirmed_email"} = response
|
||||
refute response["access_token"]
|
||||
refute response["token_type"]
|
||||
|
||||
user = Repo.get_by(User, email: "lain@example.org")
|
||||
assert user.confirmation_pending
|
||||
end
|
||||
|
||||
test "registers but does not log in with :account_approval_required", %{conn: conn} do
|
||||
clear_config([:instance, :account_approval_required], true)
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/apps", %{
|
||||
client_name: "client_name",
|
||||
redirect_uris: "urn:ietf:wg:oauth:2.0:oob",
|
||||
scopes: "read, write, follow"
|
||||
})
|
||||
|
||||
assert %{
|
||||
"client_id" => client_id,
|
||||
"client_secret" => client_secret,
|
||||
"id" => _,
|
||||
"name" => "client_name",
|
||||
"redirect_uri" => "urn:ietf:wg:oauth:2.0:oob",
|
||||
"vapid_key" => _,
|
||||
"website" => nil
|
||||
} = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
conn =
|
||||
post(conn, "/oauth/token", %{
|
||||
grant_type: "client_credentials",
|
||||
client_id: client_id,
|
||||
client_secret: client_secret
|
||||
})
|
||||
|
||||
assert %{"access_token" => token, "refresh_token" => refresh, "scope" => scope} =
|
||||
json_response(conn, 200)
|
||||
|
||||
assert token
|
||||
token_from_db = Repo.get_by(Token, token: token)
|
||||
assert token_from_db
|
||||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
assert refresh
|
||||
assert scope == "read write follow"
|
||||
|
||||
assert token_from_db.user.confirmation_pending
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer " <> token)
|
||||
|> post("/api/v1/accounts", %{
|
||||
username: "lain",
|
||||
email: "lain@example.org",
|
||||
password: "PlzDontHackLain",
|
||||
bio: "Test Bio",
|
||||
agreement: true,
|
||||
reason: "I'm a cool dude, bro"
|
||||
})
|
||||
|
||||
response = json_response_and_validate_schema(conn, 200)
|
||||
assert %{"identifier" => "awaiting_approval"} = response
|
||||
refute response["access_token"]
|
||||
refute response["token_type"]
|
||||
|
||||
user = Repo.get_by(User, email: "lain@example.org")
|
||||
|
||||
assert user.approval_pending
|
||||
assert user.registration_reason == "I'm a cool dude, bro"
|
||||
end
|
||||
|
||||
test "returns error when user already registred", %{conn: conn, valid_params: valid_params} do
|
||||
|
|
@ -1000,11 +1157,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "returns bad_request if missing email params when :account_activation_required is enabled",
|
||||
%{conn: conn, valid_params: valid_params} do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
app_token = insert(:oauth_token, user: nil)
|
||||
|
||||
|
|
@ -1169,8 +1324,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert token_from_db
|
||||
token_from_db = Repo.preload(token_from_db, :user)
|
||||
assert token_from_db.user
|
||||
|
||||
assert token_from_db.user.confirmation_pending
|
||||
end
|
||||
|
||||
conn =
|
||||
|
|
|
|||
|
|
@ -32,6 +32,38 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
|||
refute User.blocks?(user, other_user)
|
||||
end
|
||||
|
||||
test "blocking a domain via query params" do
|
||||
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
||||
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/domain_blocks?domain=dogwhistle.zone")
|
||||
|
||||
assert %{} == json_response_and_validate_schema(ret_conn, 200)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
assert User.blocks?(user, other_user)
|
||||
end
|
||||
|
||||
test "unblocking a domain via query params" do
|
||||
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
||||
other_user = insert(:user, %{ap_id: "https://dogwhistle.zone/@pundit"})
|
||||
|
||||
User.block_domain(user, "dogwhistle.zone")
|
||||
user = refresh_record(user)
|
||||
assert User.blocks?(user, other_user)
|
||||
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/v1/domain_blocks?domain=dogwhistle.zone")
|
||||
|
||||
assert %{} == json_response_and_validate_schema(ret_conn, 200)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
refute User.blocks?(user, other_user)
|
||||
end
|
||||
|
||||
test "getting a list of domain blocks" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:blocks"])
|
||||
|
||||
|
|
|
|||
|
|
@ -64,11 +64,13 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
test "get a filter" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:filters"])
|
||||
|
||||
# check whole_word false
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"]
|
||||
context: ["home"],
|
||||
whole_word: false
|
||||
}
|
||||
|
||||
{:ok, filter} = Pleroma.Filter.create(query)
|
||||
|
|
@ -76,6 +78,25 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
conn = get(conn, "/api/v1/filters/#{filter.filter_id}")
|
||||
|
||||
assert response = json_response_and_validate_schema(conn, 200)
|
||||
assert response["whole_word"] == false
|
||||
|
||||
# check whole_word true
|
||||
%{user: user, conn: conn} = oauth_access(["read:filters"])
|
||||
|
||||
query = %Pleroma.Filter{
|
||||
user_id: user.id,
|
||||
filter_id: 3,
|
||||
phrase: "knight",
|
||||
context: ["home"],
|
||||
whole_word: true
|
||||
}
|
||||
|
||||
{:ok, filter} = Pleroma.Filter.create(query)
|
||||
|
||||
conn = get(conn, "/api/v1/filters/#{filter.filter_id}")
|
||||
|
||||
assert response = json_response_and_validate_schema(conn, 200)
|
||||
assert response["whole_word"] == true
|
||||
end
|
||||
|
||||
test "update a filter" do
|
||||
|
|
@ -86,7 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
filter_id: 2,
|
||||
phrase: "knight",
|
||||
context: ["home"],
|
||||
hide: true
|
||||
hide: true,
|
||||
whole_word: true
|
||||
}
|
||||
|
||||
{:ok, _filter} = Pleroma.Filter.create(query)
|
||||
|
|
@ -108,6 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.FilterControllerTest do
|
|||
assert response["phrase"] == new.phrase
|
||||
assert response["context"] == new.context
|
||||
assert response["irreversible"] == true
|
||||
assert response["whole_word"] == true
|
||||
end
|
||||
|
||||
test "delete a filter" do
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
"thumbnail" => _,
|
||||
"languages" => _,
|
||||
"registrations" => _,
|
||||
"approval_required" => _,
|
||||
"poll_limits" => _,
|
||||
"upload_limit" => _,
|
||||
"avatar_upload_limit" => _,
|
||||
|
|
|
|||
|
|
@ -1432,6 +1432,20 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
[%{"id" => id}] = response
|
||||
assert id == other_user.id
|
||||
end
|
||||
|
||||
test "returns empty array when :show_reactions is disabled", %{conn: conn, activity: activity} do
|
||||
clear_config([:instance, :show_reactions], false)
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, _} = CommonAPI.favorite(other_user, activity.id)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert Enum.empty?(response)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/statuses/:id/reblogged_by" do
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
|
|||
test "returns error when followed user is deactivated" do
|
||||
follower = insert(:user)
|
||||
user = insert(:user, local: true, deactivated: true)
|
||||
{:error, error} = MastodonAPI.follow(follower, user)
|
||||
assert error == :rejected
|
||||
assert {:error, _error} = MastodonAPI.follow(follower, user)
|
||||
end
|
||||
|
||||
test "following for user" do
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
}
|
||||
}
|
||||
|
||||
assert expected == AccountView.render("show.json", %{user: user})
|
||||
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "Favicon is nil when :instances_favicons is disabled" do
|
||||
|
|
@ -110,11 +110,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
favicon:
|
||||
"https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png"
|
||||
}
|
||||
} = AccountView.render("show.json", %{user: user})
|
||||
} = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|
||||
Config.put([:instances_favicons, :enabled], false)
|
||||
|
||||
assert %{pleroma: %{favicon: nil}} = AccountView.render("show.json", %{user: user})
|
||||
assert %{pleroma: %{favicon: nil}} =
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "Represent the user account for the account owner" do
|
||||
|
|
@ -192,7 +193,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
}
|
||||
}
|
||||
|
||||
assert expected == AccountView.render("show.json", %{user: user})
|
||||
assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "Represent a Funkwhale channel" do
|
||||
|
|
@ -201,7 +202,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
"https://channels.tests.funkwhale.audio/federation/actors/compositions"
|
||||
)
|
||||
|
||||
assert represented = AccountView.render("show.json", %{user: user})
|
||||
assert represented =
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|
||||
assert represented.acct == "compositions@channels.tests.funkwhale.audio"
|
||||
assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions"
|
||||
end
|
||||
|
|
@ -226,6 +229,23 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert expected == AccountView.render("mention.json", %{user: user})
|
||||
end
|
||||
|
||||
test "demands :for or :skip_visibility_check option for account rendering" do
|
||||
clear_config([:restrict_unauthenticated, :profiles, :local], false)
|
||||
|
||||
user = insert(:user)
|
||||
user_id = user.id
|
||||
|
||||
assert %{id: ^user_id} = AccountView.render("show.json", %{user: user, for: nil})
|
||||
assert %{id: ^user_id} = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
||||
assert %{id: ^user_id} =
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|
||||
assert_raise RuntimeError, ~r/:skip_visibility_check or :for option is required/, fn ->
|
||||
AccountView.render("show.json", %{user: user})
|
||||
end
|
||||
end
|
||||
|
||||
describe "relationship" do
|
||||
defp test_relationship_rendering(user, other_user, expected_result) do
|
||||
opts = %{user: user, target: other_user, relationships: nil}
|
||||
|
|
@ -339,7 +359,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
assert result.pleroma.settings_store == %{:fe => "test"}
|
||||
|
||||
result = AccountView.render("show.json", %{user: user, with_pleroma_settings: true})
|
||||
result = AccountView.render("show.json", %{user: user, for: nil, with_pleroma_settings: true})
|
||||
assert result.pleroma[:settings_store] == nil
|
||||
|
||||
result = AccountView.render("show.json", %{user: user, for: user})
|
||||
|
|
@ -348,13 +368,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
test "doesn't sanitize display names" do
|
||||
user = insert(:user, name: "<marquee> username </marquee>")
|
||||
result = AccountView.render("show.json", %{user: user})
|
||||
result = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
assert result.display_name == "<marquee> username </marquee>"
|
||||
end
|
||||
|
||||
test "never display nil user follow counts" do
|
||||
user = insert(:user, following_count: 0, follower_count: 0)
|
||||
result = AccountView.render("show.json", %{user: user})
|
||||
result = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|
||||
assert result.following_count == 0
|
||||
assert result.followers_count == 0
|
||||
|
|
@ -378,7 +398,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
followers_count: 0,
|
||||
following_count: 0,
|
||||
pleroma: %{hide_follows_count: true, hide_followers_count: true}
|
||||
} = AccountView.render("show.json", %{user: user})
|
||||
} = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "shows when follows/followers are hidden" do
|
||||
|
|
@ -391,7 +411,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
followers_count: 1,
|
||||
following_count: 1,
|
||||
pleroma: %{hide_follows: true, hide_followers: true}
|
||||
} = AccountView.render("show.json", %{user: user})
|
||||
} = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
end
|
||||
|
||||
test "shows actual follower/following count to the account owner" do
|
||||
|
|
@ -534,7 +554,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
emoji: %{"joker_smile" => "https://evil.website/society.png"}
|
||||
)
|
||||
|
||||
AccountView.render("show.json", %{user: user})
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|> Enum.all?(fn
|
||||
{key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
|
||||
String.starts_with?(url, Pleroma.Web.base_url())
|
||||
|
|
|
|||
|
|
@ -135,4 +135,33 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
|||
assert result[:expires_at] == nil
|
||||
assert result[:expired] == false
|
||||
end
|
||||
|
||||
test "doesn't strips HTML tags" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "What's with the smug face?",
|
||||
poll: %{
|
||||
options: [
|
||||
"<input type=\"date\">",
|
||||
"<input type=\"date\" >",
|
||||
"<input type=\"date\"/>",
|
||||
"<input type=\"date\"></input>"
|
||||
],
|
||||
expires_in: 20
|
||||
}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert %{
|
||||
options: [
|
||||
%{title: "<input type=\"date\">", votes_count: 0},
|
||||
%{title: "<input type=\"date\" >", votes_count: 0},
|
||||
%{title: "<input type=\"date\"/>", votes_count: 0},
|
||||
%{title: "<input type=\"date\"></input>", votes_count: 0}
|
||||
]
|
||||
} = PollView.render("show.json", %{object: object})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -56,6 +56,23 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
]
|
||||
end
|
||||
|
||||
test "works correctly with badly formatted emojis" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "yo"})
|
||||
|
||||
activity
|
||||
|> Object.normalize(false)
|
||||
|> Object.update_data(%{"reactions" => %{"☕" => [user.ap_id], "x" => 1}})
|
||||
|
||||
activity = Activity.get_by_id(activity.id)
|
||||
|
||||
status = StatusView.render("show.json", activity: activity, for: user)
|
||||
|
||||
assert status[:pleroma][:emoji_reactions] == [
|
||||
%{name: "☕", count: 1, me: true}
|
||||
]
|
||||
end
|
||||
|
||||
test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -177,7 +194,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
id: to_string(note.id),
|
||||
uri: object_data["id"],
|
||||
url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
|
||||
account: AccountView.render("show.json", %{user: user}),
|
||||
account: AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
|
||||
in_reply_to_id: nil,
|
||||
in_reply_to_account_id: nil,
|
||||
card: nil,
|
||||
|
|
|
|||
|
|
@ -29,5 +29,16 @@ defmodule Pleroma.Web.OAuth.AppTest do
|
|||
assert exist_app.id == app.id
|
||||
assert exist_app.scopes == ["read", "write", "follow", "push"]
|
||||
end
|
||||
|
||||
test "has unique client_id" do
|
||||
insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop")
|
||||
|
||||
error =
|
||||
catch_error(insert(:oauth_app, client_name: "", redirect_uris: "", client_id: "boop"))
|
||||
|
||||
assert %Ecto.ConstraintError{} = error
|
||||
assert error.constraint == "apps_client_id_index"
|
||||
assert error.type == :unique
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
|
|||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
import Mock
|
||||
|
||||
@skip if !Code.ensure_loaded?(:eldap), do: :skip
|
||||
|
|
@ -72,9 +71,7 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
|
|||
equalityMatch: fn _type, _value -> :ok end,
|
||||
wholeSubtree: fn -> :ok end,
|
||||
search: fn _connection, _options ->
|
||||
{:ok,
|
||||
{:eldap_search_result, [{:eldap_entry, '', [{'mail', [to_charlist(user.email)]}]}],
|
||||
[]}}
|
||||
{:ok, {:eldap_search_result, [{:eldap_entry, '', []}], []}}
|
||||
end,
|
||||
close: fn _connection ->
|
||||
send(self(), :close_connection)
|
||||
|
|
@ -101,50 +98,6 @@ defmodule Pleroma.Web.OAuth.LDAPAuthorizationTest do
|
|||
end
|
||||
end
|
||||
|
||||
@tag @skip
|
||||
test "falls back to the default authorization when LDAP is unavailable" do
|
||||
password = "testpassword"
|
||||
user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password))
|
||||
app = insert(:oauth_app, scopes: ["read", "write"])
|
||||
|
||||
host = Pleroma.Config.get([:ldap, :host]) |> to_charlist
|
||||
port = Pleroma.Config.get([:ldap, :port])
|
||||
|
||||
with_mocks [
|
||||
{:eldap, [],
|
||||
[
|
||||
open: fn [^host], [{:port, ^port}, {:ssl, false} | _] -> {:error, 'connect failed'} end,
|
||||
simple_bind: fn _connection, _dn, ^password -> :ok end,
|
||||
close: fn _connection ->
|
||||
send(self(), :close_connection)
|
||||
:ok
|
||||
end
|
||||
]}
|
||||
] do
|
||||
log =
|
||||
capture_log(fn ->
|
||||
conn =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "password",
|
||||
"username" => user.nickname,
|
||||
"password" => password,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|
||||
assert %{"access_token" => token} = json_response(conn, 200)
|
||||
|
||||
token = Repo.get_by(Token, token: token)
|
||||
|
||||
assert token.user_id == user.id
|
||||
end)
|
||||
|
||||
assert log =~ "Could not open LDAP connection: 'connect failed'"
|
||||
refute_received :close_connection
|
||||
end
|
||||
end
|
||||
|
||||
@tag @skip
|
||||
test "disallow authorization for wrong LDAP credentials" do
|
||||
password = "testpassword"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
key: "_test",
|
||||
signing_salt: "cooldude"
|
||||
]
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
setup do
|
||||
clear_config([:instance, :account_activation_required])
|
||||
clear_config([:instance, :account_approval_required])
|
||||
end
|
||||
|
||||
describe "in OAuth consumer mode, " do
|
||||
setup do
|
||||
|
|
@ -995,6 +998,30 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
|
|||
}
|
||||
end
|
||||
|
||||
test "rejects token exchange for valid credentials belonging to an unapproved user" do
|
||||
password = "testpassword"
|
||||
|
||||
user = insert(:user, password_hash: Pbkdf2.hash_pwd_salt(password), approval_pending: true)
|
||||
|
||||
refute Pleroma.User.account_status(user) == :active
|
||||
|
||||
app = insert(:oauth_app)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> post("/oauth/token", %{
|
||||
"grant_type" => "password",
|
||||
"username" => user.nickname,
|
||||
"password" => password,
|
||||
"client_id" => app.client_id,
|
||||
"client_secret" => app.client_secret
|
||||
})
|
||||
|
||||
assert resp = json_response(conn, 403)
|
||||
assert %{"error" => _} = resp
|
||||
refute Map.has_key?(resp, "access_token")
|
||||
end
|
||||
|
||||
test "rejects an invalid authorization code" do
|
||||
app = insert(:oauth_app)
|
||||
|
||||
|
|
|
|||
|
|
@ -332,5 +332,27 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
|
|||
chat_1.id |> to_string()
|
||||
]
|
||||
end
|
||||
|
||||
test "it is not affected by :restrict_unauthenticated setting (issue #1973)", %{
|
||||
conn: conn,
|
||||
user: user
|
||||
} do
|
||||
clear_config([:restrict_unauthenticated, :profiles, :local], true)
|
||||
clear_config([:restrict_unauthenticated, :profiles, :remote], true)
|
||||
|
||||
user2 = insert(:user)
|
||||
user3 = insert(:user, local: false)
|
||||
|
||||
{:ok, _chat_12} = Chat.get_or_create(user.id, user2.ap_id)
|
||||
{:ok, _chat_13} = Chat.get_or_create(user.id, user3.ap_id)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/chats")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
account_ids = Enum.map(result, &get_in(&1, ["account", "id"]))
|
||||
assert Enum.sort(account_ids) == Enum.sort([user2.id, user3.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
)
|
||||
setup do: clear_config([:auth, :enforce_oauth_admin_scope_usage], false)
|
||||
|
||||
setup do: clear_config([:instance, :public], true)
|
||||
|
||||
setup do
|
||||
admin = insert(:user, is_admin: true)
|
||||
token = insert(:oauth_admin_token, user: admin)
|
||||
|
|
@ -27,6 +29,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||
{:ok, %{admin_conn: admin_conn}}
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/emoji/packs when :public: false", %{conn: conn} do
|
||||
Config.put([:instance, :public], false)
|
||||
conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/emoji/packs", %{conn: conn} do
|
||||
resp = conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,23 @@ defmodule Pleroma.Web.PleromaAPI.EmojiReactionControllerTest do
|
|||
result
|
||||
end
|
||||
|
||||
test "GET /api/v1/pleroma/statuses/:id/reactions with :show_reactions disabled", %{conn: conn} do
|
||||
clear_config([:instance, :show_reactions], false)
|
||||
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})
|
||||
{:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅")
|
||||
|
||||
result =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert result == []
|
||||
end
|
||||
|
||||
test "GET /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,17 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceViewTest do
|
|||
assert chat_message[:unread] == false
|
||||
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
|
||||
|
||||
{:ok, activity} = CommonAPI.post_chat_message(recipient, user, "gkgkgk", media_id: upload.id)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{url: "https://example.com/ogp"} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
|
||||
end)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post_chat_message(recipient, user, "gkgkgk https://example.com/ogp",
|
||||
media_id: upload.id
|
||||
)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
|
|
@ -52,10 +62,11 @@ defmodule Pleroma.Web.PleromaAPI.Chat.MessageReferenceViewTest do
|
|||
chat_message_two = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
|
||||
|
||||
assert chat_message_two[:id] == cm_ref.id
|
||||
assert chat_message_two[:content] == "gkgkgk"
|
||||
assert chat_message_two[:content] == object.data["content"]
|
||||
assert chat_message_two[:account_id] == recipient.id
|
||||
assert chat_message_two[:chat_id] == chat_message[:chat_id]
|
||||
assert chat_message_two[:attachment]
|
||||
assert chat_message_two[:unread] == true
|
||||
assert chat_message_two[:card]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
|
|||
|
||||
assert represented_chat == %{
|
||||
id: "#{chat.id}",
|
||||
account: AccountView.render("show.json", user: recipient),
|
||||
account:
|
||||
AccountView.render("show.json", user: recipient, skip_visibility_check: true),
|
||||
unread: 0,
|
||||
last_message: nil,
|
||||
updated_at: Utils.to_masto_date(chat.updated_at)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserInviteToken
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.TwitterAPI.TwitterAPI
|
||||
|
||||
setup_all do
|
||||
|
|
@ -27,13 +27,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
||||
fetched_user = User.get_cached_by_nickname("lain")
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
assert user == User.get_cached_by_nickname("lain")
|
||||
end
|
||||
|
||||
test "it registers a new user with empty string in bio and returns the user." do
|
||||
test "it registers a new user with empty string in bio and returns the user" do
|
||||
data = %{
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
|
|
@ -45,10 +42,7 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
||||
fetched_user = User.get_cached_by_nickname("lain")
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
assert user == User.get_cached_by_nickname("lain")
|
||||
end
|
||||
|
||||
test "it sends confirmation email if :account_activation_required is specified in instance config" do
|
||||
|
|
@ -85,6 +79,42 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
)
|
||||
end
|
||||
|
||||
test "it sends an admin email if :account_approval_required is specified in instance config" do
|
||||
admin = insert(:user, is_admin: true)
|
||||
setting = Pleroma.Config.get([:instance, :account_approval_required])
|
||||
|
||||
unless setting do
|
||||
Pleroma.Config.put([:instance, :account_approval_required], true)
|
||||
on_exit(fn -> Pleroma.Config.put([:instance, :account_approval_required], setting) end)
|
||||
end
|
||||
|
||||
data = %{
|
||||
:username => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
:password => "bear",
|
||||
:confirm => "bear",
|
||||
:reason => "I love anime"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert user.approval_pending
|
||||
|
||||
email = Pleroma.Emails.AdminEmail.new_unapproved_registration(admin, user)
|
||||
|
||||
notify_email = Pleroma.Config.get([:instance, :notify_email])
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
Swoosh.TestAssertions.assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {admin.name, admin.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "it registers a new user and parses mentions in the bio" do
|
||||
data1 = %{
|
||||
:username => "john",
|
||||
|
|
@ -134,13 +164,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
assert user == User.get_cached_by_nickname("vinny")
|
||||
|
||||
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
||||
|
||||
assert invite.used == true
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
test "returns error on invalid token" do
|
||||
|
|
@ -197,10 +224,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
check_fn = fn invite ->
|
||||
data = Map.put(data, :token, invite.token)
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
assert user == User.get_cached_by_nickname("vinny")
|
||||
end
|
||||
|
||||
{:ok, data: data, check_fn: check_fn}
|
||||
|
|
@ -260,14 +285,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
assert user == User.get_cached_by_nickname("vinny")
|
||||
|
||||
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
||||
|
||||
assert invite.used == true
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
|
|
@ -302,13 +324,10 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
assert user == User.get_cached_by_nickname("vinny")
|
||||
|
||||
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
||||
|
||||
refute invite.used
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
end
|
||||
|
||||
test "error after max uses" do
|
||||
|
|
@ -327,13 +346,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
assert user == User.get_cached_by_nickname("vinny")
|
||||
|
||||
invite = Repo.get_by(UserInviteToken, token: invite.token)
|
||||
assert invite.used == true
|
||||
|
||||
assert AccountView.render("show.json", %{user: user}) ==
|
||||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
:username => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue