Merge remote-tracking branch 'upstream/develop' into aliases
This commit is contained in:
commit
1a5a7ba6e8
186 changed files with 4752 additions and 940 deletions
|
|
@ -9,6 +9,56 @@ defmodule Pleroma.ApplicationRequirementsTest do
|
|||
|
||||
alias Pleroma.Repo
|
||||
|
||||
describe "check_welcome_message_config!/1" do
|
||||
setup do: clear_config([:welcome])
|
||||
setup do: clear_config([Pleroma.Emails.Mailer])
|
||||
|
||||
test "raises if welcome email enabled but mail disabled" do
|
||||
Pleroma.Config.put([:welcome, :email, :enabled], true)
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
|
||||
assert_raise Pleroma.ApplicationRequirements.VerifyError, "The mail disabled.", fn ->
|
||||
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "check_confirmation_accounts!" do
|
||||
setup_with_mocks([
|
||||
{Pleroma.ApplicationRequirements, [:passthrough],
|
||||
[
|
||||
check_migrations_applied!: fn _ -> :ok end
|
||||
]}
|
||||
]) do
|
||||
:ok
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "raises if account confirmation is required but mailer isn't enable" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
|
||||
assert_raise Pleroma.ApplicationRequirements.VerifyError,
|
||||
"Account activation enabled, but Mailer is disabled. Cannot send confirmation emails.",
|
||||
fn ->
|
||||
capture_log(&Pleroma.ApplicationRequirements.verify!/0)
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't do anything if account confirmation is disabled" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], false)
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||
end
|
||||
|
||||
test "doesn't do anything if account confirmation is required and mailer is enabled" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], true)
|
||||
assert Pleroma.ApplicationRequirements.verify!() == :ok
|
||||
end
|
||||
end
|
||||
|
||||
describe "check_rum!" do
|
||||
setup_with_mocks([
|
||||
{Pleroma.ApplicationRequirements, [:passthrough],
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ defmodule Pleroma.CaptchaTest do
|
|||
answer_data: answer,
|
||||
token: ^token,
|
||||
url: ^url,
|
||||
type: :kocaptcha
|
||||
type: :kocaptcha,
|
||||
seconds_valid: 300
|
||||
} = new
|
||||
|
||||
assert Kocaptcha.validate(token, "7oEy8c", answer) == :ok
|
||||
|
|
@ -56,7 +57,8 @@ defmodule Pleroma.CaptchaTest do
|
|||
answer_data: answer,
|
||||
token: token,
|
||||
type: :native,
|
||||
url: "data:image/png;base64," <> _
|
||||
url: "data:image/png;base64," <> _,
|
||||
seconds_valid: 300
|
||||
} = new
|
||||
|
||||
assert is_binary(answer)
|
||||
|
|
|
|||
|
|
@ -28,6 +28,34 @@ defmodule Pleroma.ConfigTest do
|
|||
assert Pleroma.Config.get([:azerty, :uiop], true) == true
|
||||
end
|
||||
|
||||
describe "nil values" do
|
||||
setup do
|
||||
Pleroma.Config.put(:lorem, nil)
|
||||
Pleroma.Config.put(:ipsum, %{dolor: [sit: nil]})
|
||||
Pleroma.Config.put(:dolor, sit: %{amet: nil})
|
||||
|
||||
on_exit(fn -> Enum.each(~w(lorem ipsum dolor)a, &Pleroma.Config.delete/1) end)
|
||||
end
|
||||
|
||||
test "get/1 with an atom for nil value" do
|
||||
assert Pleroma.Config.get(:lorem) == nil
|
||||
end
|
||||
|
||||
test "get/2 with an atom for nil value" do
|
||||
assert Pleroma.Config.get(:lorem, true) == nil
|
||||
end
|
||||
|
||||
test "get/1 with a list of keys for nil value" do
|
||||
assert Pleroma.Config.get([:ipsum, :dolor, :sit]) == nil
|
||||
assert Pleroma.Config.get([:dolor, :sit, :amet]) == nil
|
||||
end
|
||||
|
||||
test "get/2 with a list of keys for nil value" do
|
||||
assert Pleroma.Config.get([:ipsum, :dolor, :sit], true) == nil
|
||||
assert Pleroma.Config.get([:dolor, :sit, :amet], true) == nil
|
||||
end
|
||||
end
|
||||
|
||||
test "get/1 when value is false" do
|
||||
Pleroma.Config.put([:instance, :false_test], false)
|
||||
Pleroma.Config.put([:instance, :nested], [])
|
||||
|
|
@ -89,5 +117,23 @@ defmodule Pleroma.ConfigTest do
|
|||
Pleroma.Config.put([:delete_me, :delete_me], hello: "world", world: "Hello")
|
||||
Pleroma.Config.delete([:delete_me, :delete_me, :world])
|
||||
assert Pleroma.Config.get([:delete_me, :delete_me]) == [hello: "world"]
|
||||
|
||||
assert Pleroma.Config.delete([:this_key_does_not_exist])
|
||||
assert Pleroma.Config.delete([:non, :existing, :key])
|
||||
end
|
||||
|
||||
test "fetch/1" do
|
||||
Pleroma.Config.put([:lorem], :ipsum)
|
||||
Pleroma.Config.put([:ipsum], dolor: :sit)
|
||||
|
||||
assert Pleroma.Config.fetch([:lorem]) == {:ok, :ipsum}
|
||||
assert Pleroma.Config.fetch(:lorem) == {:ok, :ipsum}
|
||||
assert Pleroma.Config.fetch([:ipsum, :dolor]) == {:ok, :sit}
|
||||
assert Pleroma.Config.fetch([:lorem, :ipsum]) == :error
|
||||
assert Pleroma.Config.fetch([:loremipsum]) == :error
|
||||
assert Pleroma.Config.fetch(:loremipsum) == :error
|
||||
|
||||
Pleroma.Config.delete([:lorem])
|
||||
Pleroma.Config.delete([:ipsum])
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,4 +46,24 @@ defmodule Pleroma.Emails.AdminEmailTest do
|
|||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
end
|
||||
|
||||
test "new unapproved registration email" do
|
||||
config = Pleroma.Config.get(:instance)
|
||||
to_user = insert(:user)
|
||||
account = insert(:user, registration_reason: "Plz let me in")
|
||||
|
||||
res = AdminEmail.new_unapproved_registration(to_user, account)
|
||||
|
||||
account_url = Helpers.user_feed_url(Pleroma.Web.Endpoint, :feed_redirect, account.id)
|
||||
|
||||
assert res.to == [{to_user.name, to_user.email}]
|
||||
assert res.from == {config[:name], config[:notify_email]}
|
||||
assert res.subject == "New account up for review on #{config[:name]} (@#{account.nickname})"
|
||||
|
||||
assert res.html_body == """
|
||||
<p>New account for review: <a href="#{account_url}">@#{account.nickname}</a></p>
|
||||
<blockquote>Plz let me in</blockquote>
|
||||
<a href="http://localhost:4001/pleroma/admin">Visit AdminFE</a>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ defmodule Pleroma.Emails.MailerTest do
|
|||
test "not send email when mailer is disabled" do
|
||||
Pleroma.Config.put([Pleroma.Emails.Mailer, :enabled], false)
|
||||
Mailer.deliver(@email)
|
||||
:timer.sleep(100)
|
||||
|
||||
refute_email_sent(
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
|
|
@ -30,6 +31,7 @@ defmodule Pleroma.Emails.MailerTest do
|
|||
|
||||
test "send email" do
|
||||
Mailer.deliver(@email)
|
||||
:timer.sleep(100)
|
||||
|
||||
assert_email_sent(
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
|
|
@ -41,6 +43,7 @@ defmodule Pleroma.Emails.MailerTest do
|
|||
|
||||
test "perform" do
|
||||
Mailer.perform(:deliver_async, @email, [])
|
||||
:timer.sleep(100)
|
||||
|
||||
assert_email_sent(
|
||||
from: {"Pleroma", "noreply@example.com"},
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@
|
|||
"en": "<p>Why is Tenshi eating a corndog so cute?</p>"
|
||||
},
|
||||
"endTime": "2019-05-11T09:03:36Z",
|
||||
"closed": "2019-05-11T09:03:36Z",
|
||||
"attachment": [],
|
||||
"tag": [],
|
||||
"replies": {
|
||||
|
|
|
|||
99
test/fixtures/tesla_mock/poll_attachment.json
vendored
Normal file
99
test/fixtures/tesla_mock/poll_attachment.json
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://patch.cx/schemas/litepub-0.1.jsonld",
|
||||
{
|
||||
"@language": "und"
|
||||
}
|
||||
],
|
||||
"actor": "https://patch.cx/users/rin",
|
||||
"anyOf": [],
|
||||
"attachment": [
|
||||
{
|
||||
"mediaType": "image/jpeg",
|
||||
"name": "screenshot_mpv:Totoro@01:18:44.345.jpg",
|
||||
"type": "Document",
|
||||
"url": "https://shitposter.club/media/3bb4c4d402f8fdcc7f80963c3d7cf6f10f936897fd374922ade33199d2f86d87.jpg?name=screenshot_mpv%3ATotoro%4001%3A18%3A44.345.jpg"
|
||||
}
|
||||
],
|
||||
"attributedTo": "https://patch.cx/users/rin",
|
||||
"cc": [
|
||||
"https://patch.cx/users/rin/followers"
|
||||
],
|
||||
"closed": "2020-06-19T23:22:02.754678Z",
|
||||
"content": "<span class=\"h-card\"><a class=\"u-url mention\" data-user=\"9vwjTNzEWEM1TfkBGq\" href=\"https://mastodon.sdf.org/users/rinpatch\" rel=\"ugc\">@<span>rinpatch</span></a></span>",
|
||||
"closed": "2019-09-19T00:32:36.785333",
|
||||
"content": "can you vote on this poll?",
|
||||
"id": "https://patch.cx/objects/tesla_mock/poll_attachment",
|
||||
"oneOf": [
|
||||
{
|
||||
"name": "a",
|
||||
"replies": {
|
||||
"totalItems": 0,
|
||||
"type": "Collection"
|
||||
},
|
||||
"type": "Note"
|
||||
},
|
||||
{
|
||||
"name": "A",
|
||||
"replies": {
|
||||
"totalItems": 0,
|
||||
"type": "Collection"
|
||||
},
|
||||
"type": "Note"
|
||||
},
|
||||
{
|
||||
"name": "Aa",
|
||||
"replies": {
|
||||
"totalItems": 0,
|
||||
"type": "Collection"
|
||||
},
|
||||
"type": "Note"
|
||||
},
|
||||
{
|
||||
"name": "AA",
|
||||
"replies": {
|
||||
"totalItems": 0,
|
||||
"type": "Collection"
|
||||
},
|
||||
"type": "Note"
|
||||
},
|
||||
{
|
||||
"name": "AAa",
|
||||
"replies": {
|
||||
"totalItems": 1,
|
||||
"type": "Collection"
|
||||
},
|
||||
"type": "Note"
|
||||
},
|
||||
{
|
||||
"name": "AAA",
|
||||
"replies": {
|
||||
"totalItems": 3,
|
||||
"type": "Collection"
|
||||
},
|
||||
"type": "Note"
|
||||
}
|
||||
],
|
||||
"published": "2020-06-19T23:12:02.786113Z",
|
||||
"sensitive": false,
|
||||
"summary": "",
|
||||
"tag": [
|
||||
{
|
||||
"href": "https://mastodon.sdf.org/users/rinpatch",
|
||||
"name": "@rinpatch@mastodon.sdf.org",
|
||||
"type": "Mention"
|
||||
}
|
||||
],
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
"https://mastodon.sdf.org/users/rinpatch"
|
||||
],
|
||||
"type": "Question",
|
||||
"voters": [
|
||||
"https://shitposter.club/users/moonman",
|
||||
"https://skippers-bin.com/users/7v1w1r8ce6",
|
||||
"https://mastodon.sdf.org/users/rinpatch",
|
||||
"https://mastodon.social/users/emelie"
|
||||
]
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.FormatterTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
clear_config(Pleroma.Formatter)
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
|
@ -255,6 +256,36 @@ defmodule Pleroma.FormatterTest do
|
|||
|
||||
assert {_text, ^expected_mentions, []} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "it parses URL containing local mention" do
|
||||
_user = insert(:user, %{nickname: "lain"})
|
||||
|
||||
text = "https://example.com/@lain"
|
||||
|
||||
expected = ~S(<a href="https://example.com/@lain" rel="ugc">https://example.com/@lain</a>)
|
||||
|
||||
assert {^expected, [], []} = Formatter.linkify(text)
|
||||
end
|
||||
|
||||
test "it correctly parses angry face D:< with mention" do
|
||||
lain =
|
||||
insert(:user, %{
|
||||
nickname: "lain@lain.com",
|
||||
ap_id: "https://lain.com/users/lain",
|
||||
id: "9qrWmR0cKniB0YU0TA"
|
||||
})
|
||||
|
||||
text = "@lain@lain.com D:<"
|
||||
|
||||
expected_text =
|
||||
~S(<span class="h-card"><a class="u-url mention" data-user="9qrWmR0cKniB0YU0TA" href="https://lain.com/users/lain" rel="ugc">@<span>lain</span></a></span> D:<)
|
||||
|
||||
expected_mentions = [
|
||||
{"@lain@lain.com", lain}
|
||||
]
|
||||
|
||||
assert {^expected_text, ^expected_mentions, []} = Formatter.linkify(text)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".parse_tags" do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
defmodule Pleroma.Repo.Migrations.AutolinkerToLinkifyTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup do: clear_config(Pleroma.Formatter)
|
||||
setup_all do: require_migration("20200716195806_autolinker_to_linkify")
|
||||
|
||||
test "change/0 converts auto_linker opts for Pleroma.Formatter", %{migration: migration} do
|
||||
autolinker_opts = [
|
||||
extra: true,
|
||||
validate_tld: true,
|
||||
class: false,
|
||||
strip_prefix: false,
|
||||
new_window: false,
|
||||
rel: "testing"
|
||||
]
|
||||
|
||||
insert(:config, group: :auto_linker, key: :opts, value: autolinker_opts)
|
||||
|
||||
migration.change()
|
||||
|
||||
assert nil == ConfigDB.get_by_params(%{group: :auto_linker, key: :opts})
|
||||
|
||||
%{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
|
||||
|
||||
assert new_opts == [
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "testing",
|
||||
strip_prefix: false
|
||||
]
|
||||
|
||||
Pleroma.Config.put(Pleroma.Formatter, new_opts)
|
||||
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
|
||||
|
||||
{text, _mentions, []} =
|
||||
Pleroma.Formatter.linkify(
|
||||
"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
|
||||
)
|
||||
|
||||
assert text ==
|
||||
"<a href=\"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\" rel=\"testing\">https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7</a>\n\nOmg will COVID finally end Black Friday???"
|
||||
end
|
||||
|
||||
test "transform_opts/1 returns a list of compatible opts", %{migration: migration} do
|
||||
old_opts = [
|
||||
extra: true,
|
||||
validate_tld: true,
|
||||
class: false,
|
||||
strip_prefix: false,
|
||||
new_window: false,
|
||||
rel: "qqq"
|
||||
]
|
||||
|
||||
expected_opts = [
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "qqq",
|
||||
strip_prefix: false
|
||||
]
|
||||
|
||||
assert migration.transform_opts(old_opts) == expected_opts
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
defmodule Pleroma.Repo.Migrations.FixMalformedFormatterConfigTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup do: clear_config(Pleroma.Formatter)
|
||||
setup_all do: require_migration("20200722185515_fix_malformed_formatter_config")
|
||||
|
||||
test "change/0 converts a map into a list", %{migration: migration} do
|
||||
incorrect_opts = %{
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "F",
|
||||
strip_prefix: false
|
||||
}
|
||||
|
||||
insert(:config, group: :pleroma, key: Pleroma.Formatter, value: incorrect_opts)
|
||||
|
||||
assert :ok == migration.change()
|
||||
|
||||
%{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
|
||||
|
||||
assert new_opts == [
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "F",
|
||||
strip_prefix: false
|
||||
]
|
||||
|
||||
Pleroma.Config.put(Pleroma.Formatter, new_opts)
|
||||
assert new_opts == Pleroma.Config.get(Pleroma.Formatter)
|
||||
|
||||
{text, _mentions, []} =
|
||||
Pleroma.Formatter.linkify(
|
||||
"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\n\nOmg will COVID finally end Black Friday???"
|
||||
)
|
||||
|
||||
assert text ==
|
||||
"<a href=\"https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7\" rel=\"F\">https://www.businessinsider.com/walmart-will-close-stores-on-thanksgiving-ending-black-friday-tradition-2020-7</a>\n\nOmg will COVID finally end Black Friday???"
|
||||
end
|
||||
|
||||
test "change/0 skips if Pleroma.Formatter config is already a list", %{migration: migration} do
|
||||
opts = [
|
||||
class: false,
|
||||
extra: true,
|
||||
new_window: false,
|
||||
rel: "ugc",
|
||||
strip_prefix: false
|
||||
]
|
||||
|
||||
insert(:config, group: :pleroma, key: Pleroma.Formatter, value: opts)
|
||||
|
||||
assert :skipped == migration.change()
|
||||
|
||||
%{value: new_opts} = ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Formatter})
|
||||
|
||||
assert new_opts == opts
|
||||
end
|
||||
|
||||
test "change/0 skips if Pleroma.Formatter is empty", %{migration: migration} do
|
||||
assert :skipped == migration.change()
|
||||
end
|
||||
end
|
||||
140
test/migrations/20200724133313_move_welcome_settings_test.exs
Normal file
140
test/migrations/20200724133313_move_welcome_settings_test.exs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
defmodule Pleroma.Repo.Migrations.MoveWelcomeSettingsTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
alias Pleroma.ConfigDB
|
||||
|
||||
setup_all do: require_migration("20200724133313_move_welcome_settings")
|
||||
|
||||
describe "up/0" do
|
||||
test "converts welcome settings", %{migration: migration} do
|
||||
insert(:config,
|
||||
group: :pleroma,
|
||||
key: :instance,
|
||||
value: [
|
||||
welcome_message: "Test message",
|
||||
welcome_user_nickname: "jimm",
|
||||
name: "Pleroma"
|
||||
]
|
||||
)
|
||||
|
||||
migration.up()
|
||||
instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
|
||||
welcome_config = ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
|
||||
|
||||
assert instance_config.value == [name: "Pleroma"]
|
||||
|
||||
assert welcome_config.value == [
|
||||
direct_message: %{
|
||||
enabled: true,
|
||||
message: "Test message",
|
||||
sender_nickname: "jimm"
|
||||
},
|
||||
email: %{
|
||||
enabled: false,
|
||||
html: "Welcome to <%= instance_name %>",
|
||||
sender: nil,
|
||||
subject: "Welcome to <%= instance_name %>",
|
||||
text: "Welcome to <%= instance_name %>"
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "does nothing when message empty", %{migration: migration} do
|
||||
insert(:config,
|
||||
group: :pleroma,
|
||||
key: :instance,
|
||||
value: [
|
||||
welcome_message: "",
|
||||
welcome_user_nickname: "jimm",
|
||||
name: "Pleroma"
|
||||
]
|
||||
)
|
||||
|
||||
migration.up()
|
||||
instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
|
||||
refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
|
||||
assert instance_config.value == [name: "Pleroma"]
|
||||
end
|
||||
|
||||
test "does nothing when welcome_message not set", %{migration: migration} do
|
||||
insert(:config,
|
||||
group: :pleroma,
|
||||
key: :instance,
|
||||
value: [welcome_user_nickname: "jimm", name: "Pleroma"]
|
||||
)
|
||||
|
||||
migration.up()
|
||||
instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
|
||||
refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
|
||||
assert instance_config.value == [name: "Pleroma"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "down/0" do
|
||||
test "revert new settings to old when instance setting not exists", %{migration: migration} do
|
||||
insert(:config,
|
||||
group: :pleroma,
|
||||
key: :welcome,
|
||||
value: [
|
||||
direct_message: %{
|
||||
enabled: true,
|
||||
message: "Test message",
|
||||
sender_nickname: "jimm"
|
||||
},
|
||||
email: %{
|
||||
enabled: false,
|
||||
html: "Welcome to <%= instance_name %>",
|
||||
sender: nil,
|
||||
subject: "Welcome to <%= instance_name %>",
|
||||
text: "Welcome to <%= instance_name %>"
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
migration.down()
|
||||
|
||||
refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
|
||||
instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
|
||||
|
||||
assert instance_config.value == [
|
||||
welcome_user_nickname: "jimm",
|
||||
welcome_message: "Test message"
|
||||
]
|
||||
end
|
||||
|
||||
test "revert new settings to old when instance setting exists", %{migration: migration} do
|
||||
insert(:config, group: :pleroma, key: :instance, value: [name: "Pleroma App"])
|
||||
|
||||
insert(:config,
|
||||
group: :pleroma,
|
||||
key: :welcome,
|
||||
value: [
|
||||
direct_message: %{
|
||||
enabled: true,
|
||||
message: "Test message",
|
||||
sender_nickname: "jimm"
|
||||
},
|
||||
email: %{
|
||||
enabled: false,
|
||||
html: "Welcome to <%= instance_name %>",
|
||||
sender: nil,
|
||||
subject: "Welcome to <%= instance_name %>",
|
||||
text: "Welcome to <%= instance_name %>"
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
migration.down()
|
||||
|
||||
refute ConfigDB.get_by_params(%{group: :pleroma, key: :welcome})
|
||||
instance_config = ConfigDB.get_by_params(%{group: :pleroma, key: :instance})
|
||||
|
||||
assert instance_config.value == [
|
||||
name: "Pleroma App",
|
||||
welcome_user_nickname: "jimm",
|
||||
welcome_message: "Test message"
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
24
test/migrations/20200802170532_fix_legacy_tags_test.exs
Normal file
24
test/migrations/20200802170532_fix_legacy_tags_test.exs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule Pleroma.Repo.Migrations.FixLegacyTagsTest do
|
||||
alias Pleroma.User
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
import Pleroma.Tests.Helpers
|
||||
|
||||
setup_all do: require_migration("20200802170532_fix_legacy_tags")
|
||||
|
||||
test "change/0 converts legacy user tags into correct values", %{migration: migration} do
|
||||
user = insert(:user, tags: ["force_nsfw", "force_unlisted", "verified"])
|
||||
user2 = insert(:user)
|
||||
|
||||
assert :ok == migration.change()
|
||||
|
||||
fixed_user = User.get_by_id(user.id)
|
||||
fixed_user2 = User.get_by_id(user2.id)
|
||||
|
||||
assert fixed_user.tags == ["mrf_tag:media-force-nsfw", "mrf_tag:force-unlisted", "verified"]
|
||||
assert fixed_user2.tags == []
|
||||
|
||||
# user2 should not have been updated
|
||||
assert fixed_user2.updated_at == fixed_user2.inserted_at
|
||||
end
|
||||
end
|
||||
|
|
@ -177,6 +177,13 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
"https://mastodon.example.org/users/userisgone404"
|
||||
)
|
||||
end
|
||||
|
||||
test "it can fetch pleroma polls with attachments" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id("https://patch.cx/objects/tesla_mock/poll_attachment")
|
||||
|
||||
assert object
|
||||
end
|
||||
end
|
||||
|
||||
describe "pruning" do
|
||||
|
|
|
|||
|
|
@ -54,6 +54,20 @@ defmodule Pleroma.PaginationTest do
|
|||
|
||||
assert length(paginated) == 1
|
||||
end
|
||||
|
||||
test "handles id gracefully", %{notes: notes} do
|
||||
id = Enum.at(notes, 1).id |> Integer.to_string()
|
||||
|
||||
paginated =
|
||||
Pagination.fetch_paginated(Object, %{
|
||||
id: "9s99Hq44Cnv8PKBwWG",
|
||||
max_id: id,
|
||||
limit: 20,
|
||||
offset: 0
|
||||
})
|
||||
|
||||
assert length(paginated) == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "offset" do
|
||||
|
|
|
|||
30
test/plugs/frontend_static_test.exs
Normal file
30
test/plugs/frontend_static_test.exs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.FrontendStaticPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
|
||||
setup do
|
||||
File.mkdir_p!(@dir)
|
||||
on_exit(fn -> File.rm_rf(@dir) end)
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :static_dir], @dir)
|
||||
|
||||
test "overrides existing static files", %{conn: conn} do
|
||||
name = "pelmora"
|
||||
ref = "uguu"
|
||||
|
||||
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||
|
||||
File.mkdir_p!(path)
|
||||
File.write!("#{path}/index.html", "from frontend plug")
|
||||
|
||||
index = get(conn, "/")
|
||||
assert html_response(index, 200) == "from frontend plug"
|
||||
end
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
||||
defmodule Pleroma.Web.InstanceStaticPlugTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
@dir "test/tmp/instance_static"
|
||||
|
|
@ -24,6 +24,28 @@ defmodule Pleroma.Web.RuntimeStaticPlugTest do
|
|||
assert html_response(index, 200) == "hello world"
|
||||
end
|
||||
|
||||
test "also overrides frontend files", %{conn: conn} do
|
||||
name = "pelmora"
|
||||
ref = "uguu"
|
||||
|
||||
clear_config([:frontends, :primary], %{"name" => name, "ref" => ref})
|
||||
|
||||
bundled_index = get(conn, "/")
|
||||
refute html_response(bundled_index, 200) == "from frontend plug"
|
||||
|
||||
path = "#{@dir}/frontends/#{name}/#{ref}"
|
||||
File.mkdir_p!(path)
|
||||
File.write!("#{path}/index.html", "from frontend plug")
|
||||
|
||||
index = get(conn, "/")
|
||||
assert html_response(index, 200) == "from frontend plug"
|
||||
|
||||
File.write!(@dir <> "/index.html", "from instance static")
|
||||
|
||||
index = get(conn, "/")
|
||||
assert html_response(index, 200) == "from instance static"
|
||||
end
|
||||
|
||||
test "overrides any file in static/static" do
|
||||
bundled_index = get(build_conn(), "/static/terms-of-service.html")
|
||||
|
||||
|
|
|
|||
16
test/report_note_test.exs
Normal file
16
test/report_note_test.exs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.ReportNoteTest do
|
||||
alias Pleroma.ReportNote
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
|
||||
test "create/3" do
|
||||
user = insert(:user)
|
||||
report = insert(:report_activity)
|
||||
assert {:ok, note} = ReportNote.create(user.id, report.id, "naughty boy")
|
||||
assert note.content == "naughty boy"
|
||||
end
|
||||
end
|
||||
|
|
@ -16,7 +16,8 @@ defmodule Pleroma.Captcha.Mock do
|
|||
type: :mock,
|
||||
token: "afa1815e14e29355e6c8f6b143a39fa2",
|
||||
answer_data: @solution,
|
||||
url: "https://example.org/captcha.png"
|
||||
url: "https://example.org/captcha.png",
|
||||
seconds_valid: 300
|
||||
}
|
||||
|
||||
@impl Service
|
||||
|
|
|
|||
|
|
@ -297,6 +297,30 @@ defmodule Pleroma.Factory do
|
|||
}
|
||||
end
|
||||
|
||||
def report_activity_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
activity = attrs[:activity] || insert(:note_activity)
|
||||
state = attrs[:state] || "open"
|
||||
|
||||
data = %{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"actor" => user.ap_id,
|
||||
"type" => "Flag",
|
||||
"object" => [activity.actor, activity.data["id"]],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||
"to" => [],
|
||||
"cc" => [activity.actor],
|
||||
"context" => activity.data["context"],
|
||||
"state" => state
|
||||
}
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data,
|
||||
actor: data["actor"],
|
||||
recipients: data["to"] ++ data["cc"]
|
||||
}
|
||||
end
|
||||
|
||||
def oauth_app_factory do
|
||||
%Pleroma.Web.OAuth.App{
|
||||
client_name: sequence(:client_name, &"Some client #{&1}"),
|
||||
|
|
|
|||
|
|
@ -17,9 +17,19 @@ defmodule Pleroma.Tests.Helpers do
|
|||
|
||||
defmacro clear_config(config_path, do: yield) do
|
||||
quote do
|
||||
initial_setting = Config.get(unquote(config_path))
|
||||
initial_setting = Config.fetch(unquote(config_path))
|
||||
unquote(yield)
|
||||
on_exit(fn -> Config.put(unquote(config_path), initial_setting) end)
|
||||
|
||||
on_exit(fn ->
|
||||
case initial_setting do
|
||||
:error ->
|
||||
Config.delete(unquote(config_path))
|
||||
|
||||
{:ok, value} ->
|
||||
Config.put(unquote(config_path), value)
|
||||
end
|
||||
end)
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
|
|
@ -32,6 +42,11 @@ defmodule Pleroma.Tests.Helpers do
|
|||
end
|
||||
end
|
||||
|
||||
def require_migration(migration_name) do
|
||||
[{module, _}] = Code.require_file("#{migration_name}.exs", "priv/repo/migrations")
|
||||
{:ok, %{migration: module}}
|
||||
end
|
||||
|
||||
defmacro __using__(_opts) do
|
||||
quote do
|
||||
import Pleroma.Tests.Helpers,
|
||||
|
|
|
|||
|
|
@ -82,6 +82,14 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://patch.cx/objects/tesla_mock/poll_attachment", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/poll_attachment.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get(
|
||||
"https://mastodon.social/.well-known/webfinger?resource=https://mastodon.social/users/emelie",
|
||||
_,
|
||||
|
|
|
|||
|
|
@ -50,13 +50,13 @@ defmodule Mix.Tasks.Pleroma.AppTest do
|
|||
defp assert_app(name, redirect, scopes) do
|
||||
app = Repo.get_by(Pleroma.Web.OAuth.App, client_name: name)
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message == "#{name} successfully created:"
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message == "App client_id: #{app.client_id}"
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert_receive {:mix_shell, :info, [message]}
|
||||
assert message == "App client_secret: #{app.client_secret}"
|
||||
|
||||
assert app.scopes == scopes
|
||||
|
|
|
|||
|
|
@ -129,8 +129,6 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
autofollowed_nicknames: [],
|
||||
max_pinned_statuses: 1,
|
||||
attachment_links: false,
|
||||
welcome_user_nickname: nil,
|
||||
welcome_message: nil,
|
||||
max_report_comment_size: 1000,
|
||||
safe_dm_mentions: false,
|
||||
healthcheck: false,
|
||||
|
|
@ -172,7 +170,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
end
|
||||
|
||||
assert file ==
|
||||
"#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n welcome_user_nickname: nil,\n welcome_message: nil,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
"#{header}\n\nconfig :pleroma, :instance,\n name: \"Pleroma\",\n email: \"example@example.com\",\n notify_email: \"noreply@example.com\",\n description: \"A Pleroma instance, an alternative fediverse server\",\n limit: 5000,\n chat_limit: 5000,\n remote_limit: 100_000,\n upload_limit: 16_000_000,\n avatar_upload_limit: 2_000_000,\n background_upload_limit: 4_000_000,\n banner_upload_limit: 4_000_000,\n poll_limits: %{\n max_expiration: 31_536_000,\n max_option_chars: 200,\n max_options: 20,\n min_expiration: 0\n },\n registrations_open: true,\n federating: true,\n federation_incoming_replies_max_depth: 100,\n federation_reachability_timeout_days: 7,\n federation_publisher_modules: [Pleroma.Web.ActivityPub.Publisher],\n allow_relay: true,\n public: true,\n quarantined_instances: [],\n managed_config: true,\n static_dir: \"instance/static/\",\n allowed_post_formats: [\"text/plain\", \"text/html\", \"text/markdown\", \"text/bbcode\"],\n autofollowed_nicknames: [],\n max_pinned_statuses: 1,\n attachment_links: false,\n max_report_comment_size: 1000,\n safe_dm_mentions: false,\n healthcheck: false,\n remote_post_retention_days: 90,\n skip_thread_containment: true,\n limit_to_local_content: :unauthenticated,\n user_bio_length: 5000,\n user_name_length: 100,\n max_account_fields: 10,\n max_remote_account_fields: 20,\n account_field_name_length: 512,\n account_field_value_length: 2048,\n external_user_synchronization: true,\n extended_nickname_format: true,\n multi_factor_authentication: [\n totp: [digits: 6, period: 30],\n backup_codes: [number: 2, length: 6]\n ]\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
30
test/tasks/release_env_test.exs
Normal file
30
test/tasks/release_env_test.exs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Mix.Tasks.Pleroma.ReleaseEnvTest do
|
||||
use ExUnit.Case
|
||||
import ExUnit.CaptureIO, only: [capture_io: 1]
|
||||
|
||||
@path "config/pleroma.test.env"
|
||||
|
||||
def do_clean do
|
||||
if File.exists?(@path) do
|
||||
File.rm_rf(@path)
|
||||
end
|
||||
end
|
||||
|
||||
setup do
|
||||
do_clean()
|
||||
on_exit(fn -> do_clean() end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "generate pleroma.env" do
|
||||
assert capture_io(fn ->
|
||||
Mix.Tasks.Pleroma.ReleaseEnv.run(["gen", "--path", @path, "--force"])
|
||||
end) =~ "The file generated"
|
||||
|
||||
assert File.read!(@path) =~ "RELEASE_COOKIE="
|
||||
end
|
||||
end
|
||||
|
|
@ -9,6 +9,8 @@ defmodule Pleroma.Upload.Filter.AnonymizeFilenameTest do
|
|||
alias Pleroma.Upload
|
||||
|
||||
setup do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
upload_file = %Upload{
|
||||
name: "an… image.jpg",
|
||||
content_type: "image/jpg",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ defmodule Pleroma.Upload.Filter.ExiftoolTest do
|
|||
alias Pleroma.Upload.Filter
|
||||
|
||||
test "apply exiftool filter" do
|
||||
assert Pleroma.Utils.command_available?("exiftool")
|
||||
|
||||
File.cp!(
|
||||
"test/fixtures/DSCN0010.jpg",
|
||||
"test/fixtures/DSCN0010_tmp.jpg"
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Uploaders.LocalTest do
|
|||
|
||||
describe "put_file/1" do
|
||||
test "put file to local folder" do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
file_path = "local_upload/files/image.jpg"
|
||||
|
||||
file = %Pleroma.Upload{
|
||||
|
|
@ -32,6 +33,7 @@ defmodule Pleroma.Uploaders.LocalTest do
|
|||
|
||||
describe "delete_file/1" do
|
||||
test "deletes local file" do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
file_path = "local_upload/files/image.jpg"
|
||||
|
||||
file = %Pleroma.Upload{
|
||||
|
|
|
|||
35
test/user/welcome_chat_massage_test.exs
Normal file
35
test/user/welcome_chat_massage_test.exs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.WelcomeChatMessageTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User.WelcomeChatMessage
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([:welcome])
|
||||
|
||||
describe "post_message/1" do
|
||||
test "send a chat welcome message" do
|
||||
welcome_user = insert(:user, name: "mewmew")
|
||||
user = insert(:user)
|
||||
|
||||
Config.put([:welcome, :chat_message, :enabled], true)
|
||||
Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
|
||||
|
||||
Config.put(
|
||||
[:welcome, :chat_message, :message],
|
||||
"Hello, welcome to Blob/Cat!"
|
||||
)
|
||||
|
||||
{:ok, %Pleroma.Activity{} = activity} = WelcomeChatMessage.post_message(user)
|
||||
|
||||
assert user.ap_id in activity.recipients
|
||||
assert Pleroma.Object.normalize(activity).data["type"] == "ChatMessage"
|
||||
assert Pleroma.Object.normalize(activity).data["content"] == "Hello, welcome to Blob/Cat!"
|
||||
end
|
||||
end
|
||||
end
|
||||
61
test/user/welcome_email_test.exs
Normal file
61
test/user/welcome_email_test.exs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.WelcomeEmailTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User.WelcomeEmail
|
||||
|
||||
import Pleroma.Factory
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
setup do: clear_config([:welcome])
|
||||
|
||||
describe "send_email/1" do
|
||||
test "send a welcome email" do
|
||||
user = insert(:user, name: "Jimm")
|
||||
|
||||
Config.put([:welcome, :email, :enabled], true)
|
||||
Config.put([:welcome, :email, :sender], "welcome@pleroma.app")
|
||||
|
||||
Config.put(
|
||||
[:welcome, :email, :subject],
|
||||
"Hello, welcome to pleroma: <%= instance_name %>"
|
||||
)
|
||||
|
||||
Config.put(
|
||||
[:welcome, :email, :html],
|
||||
"<h1>Hello <%= user.name %>.</h1> <p>Welcome to <%= instance_name %></p>"
|
||||
)
|
||||
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
{:ok, _job} = WelcomeEmail.send_email(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, "welcome@pleroma.app"},
|
||||
to: {user.name, user.email},
|
||||
subject: "Hello, welcome to pleroma: #{instance_name}",
|
||||
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
|
||||
)
|
||||
|
||||
Config.put([:welcome, :email, :sender], {"Pleroma App", "welcome@pleroma.app"})
|
||||
|
||||
{:ok, _job} = WelcomeEmail.send_email(user)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: {"Pleroma App", "welcome@pleroma.app"},
|
||||
to: {user.name, user.email},
|
||||
subject: "Hello, welcome to pleroma: #{instance_name}",
|
||||
html_body: "<h1>Hello #{user.name}.</h1> <p>Welcome to #{instance_name}</p>"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
34
test/user/welcome_message_test.exs
Normal file
34
test/user/welcome_message_test.exs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.User.WelcomeMessageTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User.WelcomeMessage
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup do: clear_config([:welcome])
|
||||
|
||||
describe "post_message/1" do
|
||||
test "send a direct welcome message" do
|
||||
welcome_user = insert(:user)
|
||||
user = insert(:user, name: "Jimm")
|
||||
|
||||
Config.put([:welcome, :direct_message, :enabled], true)
|
||||
Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
|
||||
|
||||
Config.put(
|
||||
[:welcome, :direct_message, :message],
|
||||
"Hello. Welcome to Pleroma"
|
||||
)
|
||||
|
||||
{:ok, %Pleroma.Activity{} = activity} = WelcomeMessage.post_message(user)
|
||||
assert user.ap_id in activity.recipients
|
||||
assert activity.data["directMessage"] == true
|
||||
assert Pleroma.Object.normalize(activity).data["content"] =~ "Hello. Welcome to Pleroma"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -17,6 +17,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
import ExUnit.CaptureLog
|
||||
import Swoosh.TestAssertions
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
|
|
@ -385,9 +386,10 @@ defmodule Pleroma.UserTest do
|
|||
password_confirmation: "test",
|
||||
email: "email@example.com"
|
||||
}
|
||||
|
||||
setup do: clear_config([:instance, :autofollowed_nicknames])
|
||||
setup do: clear_config([:instance, :welcome_message])
|
||||
setup do: clear_config([:instance, :welcome_user_nickname])
|
||||
setup do: clear_config([:welcome])
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
|
||||
test "it autofollows accounts that are set for it" do
|
||||
user = insert(:user)
|
||||
|
|
@ -408,20 +410,68 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
test "it sends a welcome message if it is set" do
|
||||
welcome_user = insert(:user)
|
||||
|
||||
Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
|
||||
Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
|
||||
Pleroma.Config.put([:welcome, :direct_message, :enabled], true)
|
||||
Pleroma.Config.put([:welcome, :direct_message, :sender_nickname], welcome_user.nickname)
|
||||
Pleroma.Config.put([:welcome, :direct_message, :message], "Hello, this is a direct message")
|
||||
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
{:ok, registered_user} = User.register(cng)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
activity = Repo.one(Pleroma.Activity)
|
||||
assert registered_user.ap_id in activity.recipients
|
||||
assert Object.normalize(activity).data["content"] =~ "cool site"
|
||||
assert Object.normalize(activity).data["content"] =~ "direct message"
|
||||
assert activity.actor == welcome_user.ap_id
|
||||
end
|
||||
|
||||
setup do: clear_config([:instance, :account_activation_required])
|
||||
test "it sends a welcome chat message if it is set" do
|
||||
welcome_user = insert(:user)
|
||||
Pleroma.Config.put([:welcome, :chat_message, :enabled], true)
|
||||
Pleroma.Config.put([:welcome, :chat_message, :sender_nickname], welcome_user.nickname)
|
||||
Pleroma.Config.put([:welcome, :chat_message, :message], "Hello, this is a chat message")
|
||||
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
{:ok, registered_user} = User.register(cng)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
activity = Repo.one(Pleroma.Activity)
|
||||
assert registered_user.ap_id in activity.recipients
|
||||
assert Object.normalize(activity).data["content"] =~ "chat message"
|
||||
assert activity.actor == welcome_user.ap_id
|
||||
end
|
||||
|
||||
test "it sends a welcome email message if it is set" do
|
||||
welcome_user = insert(:user)
|
||||
Pleroma.Config.put([:welcome, :email, :enabled], true)
|
||||
Pleroma.Config.put([:welcome, :email, :sender], welcome_user.email)
|
||||
|
||||
Pleroma.Config.put(
|
||||
[:welcome, :email, :subject],
|
||||
"Hello, welcome to cool site: <%= instance_name %>"
|
||||
)
|
||||
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
{:ok, registered_user} = User.register(cng)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, welcome_user.email},
|
||||
to: {registered_user.name, registered_user.email},
|
||||
subject: "Hello, welcome to cool site: #{instance_name}",
|
||||
html_body: "Welcome to #{instance_name}"
|
||||
)
|
||||
end
|
||||
|
||||
test "it sends a confirm email" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
||||
cng = User.register_changeset(%User{}, @full_user_data)
|
||||
{:ok, registered_user} = User.register(cng)
|
||||
ObanHelpers.perform_all()
|
||||
assert_email_sent(Pleroma.Emails.UserEmail.account_confirmation_email(registered_user))
|
||||
end
|
||||
|
||||
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
|
||||
Pleroma.Config.put([:instance, :account_activation_required], true)
|
||||
|
|
@ -463,6 +513,29 @@ defmodule Pleroma.UserTest do
|
|||
refute changeset.valid?
|
||||
end
|
||||
|
||||
test "it blocks blacklisted email domains" do
|
||||
clear_config([User, :email_blacklist], ["trolling.world"])
|
||||
|
||||
# Block with match
|
||||
params = Map.put(@full_user_data, :email, "troll@trolling.world")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
refute changeset.valid?
|
||||
|
||||
# Block with subdomain match
|
||||
params = Map.put(@full_user_data, :email, "troll@gnomes.trolling.world")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
refute changeset.valid?
|
||||
|
||||
# Pass with different domains that are similar
|
||||
params = Map.put(@full_user_data, :email, "troll@gnomestrolling.world")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
assert changeset.valid?
|
||||
|
||||
params = Map.put(@full_user_data, :email, "troll@trolling.world.us")
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
assert changeset.valid?
|
||||
end
|
||||
|
||||
test "it sets the password_hash and ap_id" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
|
||||
|
|
@ -473,6 +546,24 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
|
||||
end
|
||||
|
||||
test "it sets the 'accepts_chat_messages' set to true" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
assert changeset.valid?
|
||||
|
||||
{:ok, user} = Repo.insert(changeset)
|
||||
|
||||
assert user.accepts_chat_messages
|
||||
end
|
||||
|
||||
test "it creates a confirmed user" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
assert changeset.valid?
|
||||
|
||||
{:ok, user} = Repo.insert(changeset)
|
||||
|
||||
refute user.confirmation_pending
|
||||
end
|
||||
end
|
||||
|
||||
describe "user registration, with :account_activation_required" do
|
||||
|
|
@ -486,15 +577,6 @@ defmodule Pleroma.UserTest do
|
|||
}
|
||||
setup do: clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
test "it sets the 'accepts_chat_messages' set to true" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
assert changeset.valid?
|
||||
|
||||
{:ok, user} = Repo.insert(changeset)
|
||||
|
||||
assert user.accepts_chat_messages
|
||||
end
|
||||
|
||||
test "it creates unconfirmed user" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
assert changeset.valid?
|
||||
|
|
@ -516,6 +598,46 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "user registration, with :account_approval_required" do
|
||||
@full_user_data %{
|
||||
bio: "A guy",
|
||||
name: "my name",
|
||||
nickname: "nick",
|
||||
password: "test",
|
||||
password_confirmation: "test",
|
||||
email: "email@example.com",
|
||||
registration_reason: "I'm a cool guy :)"
|
||||
}
|
||||
setup do: clear_config([:instance, :account_approval_required], true)
|
||||
|
||||
test "it creates unapproved user" do
|
||||
changeset = User.register_changeset(%User{}, @full_user_data)
|
||||
assert changeset.valid?
|
||||
|
||||
{:ok, user} = Repo.insert(changeset)
|
||||
|
||||
assert user.approval_pending
|
||||
assert user.registration_reason == "I'm a cool guy :)"
|
||||
end
|
||||
|
||||
test "it restricts length of registration reason" do
|
||||
reason_limit = Pleroma.Config.get([:instance, :registration_reason_length])
|
||||
|
||||
assert is_integer(reason_limit)
|
||||
|
||||
params =
|
||||
@full_user_data
|
||||
|> Map.put(
|
||||
:registration_reason,
|
||||
"Quia et nesciunt dolores numquam ipsam nisi sapiente soluta. Ullam repudiandae nisi quam porro officiis officiis ad. Consequatur animi velit ex quia. Odit voluptatem perferendis quia ut nisi. Dignissimos sit soluta atque aliquid dolorem ut dolorum ut. Labore voluptates iste iusto amet voluptatum earum. Ad fugit illum nam eos ut nemo. Pariatur ea fuga non aspernatur. Dignissimos debitis officia corporis est nisi ab et. Atque itaque alias eius voluptas minus. Accusamus numquam tempore occaecati in."
|
||||
)
|
||||
|
||||
changeset = User.register_changeset(%User{}, params)
|
||||
|
||||
refute changeset.valid?
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_or_fetch/1" do
|
||||
test "gets an existing user by nickname" do
|
||||
user = insert(:user)
|
||||
|
|
@ -1181,6 +1303,31 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "approve" do
|
||||
test "approves a user" do
|
||||
user = insert(:user, approval_pending: true)
|
||||
assert true == user.approval_pending
|
||||
{:ok, user} = User.approve(user)
|
||||
assert false == user.approval_pending
|
||||
end
|
||||
|
||||
test "approves a list of users" do
|
||||
unapproved_users = [
|
||||
insert(:user, approval_pending: true),
|
||||
insert(:user, approval_pending: true),
|
||||
insert(:user, approval_pending: true)
|
||||
]
|
||||
|
||||
{:ok, users} = User.approve(unapproved_users)
|
||||
|
||||
assert Enum.count(users) == 3
|
||||
|
||||
Enum.each(users, fn user ->
|
||||
assert false == user.approval_pending
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete" do
|
||||
setup do
|
||||
{:ok, user} = insert(:user) |> User.set_cache()
|
||||
|
|
@ -1268,6 +1415,17 @@ defmodule Pleroma.UserTest do
|
|||
end
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
refute User.get_cached_by_id(user.id)
|
||||
refute User.get_by_id(user.id)
|
||||
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
|
||||
|
|
@ -1342,6 +1500,14 @@ defmodule Pleroma.UserTest do
|
|||
user = insert(:user, local: true, confirmation_pending: false, deactivated: true)
|
||||
assert User.account_status(user) == :deactivated
|
||||
end
|
||||
|
||||
test "returns :approval_pending for unapproved user" do
|
||||
user = insert(:user, local: true, approval_pending: true)
|
||||
assert User.account_status(user) == :approval_pending
|
||||
|
||||
user = insert(:user, local: true, confirmation_pending: true, approval_pending: true)
|
||||
assert User.account_status(user) == :approval_pending
|
||||
end
|
||||
end
|
||||
|
||||
describe "superuser?/1" do
|
||||
|
|
|
|||
|
|
@ -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