Merge branch 'develop' into issue/1276-2
This commit is contained in:
commit
a92c713d9c
300 changed files with 7770 additions and 3577 deletions
|
|
@ -16,6 +16,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
refute Application.get_env(:pleroma, :test_key)
|
||||
refute Application.get_env(:idna, :test_key)
|
||||
refute Application.get_env(:quack, :test_key)
|
||||
refute Application.get_env(:postgrex, :test_key)
|
||||
initial = Application.get_env(:logger, :level)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
|
|
@ -35,16 +37,28 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
value: [:test_value1, :test_value2]
|
||||
})
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":postgrex",
|
||||
key: ":test_key",
|
||||
value: :value
|
||||
})
|
||||
|
||||
ConfigDB.create(%{group: ":logger", key: ":level", value: :debug})
|
||||
|
||||
TransferTask.start_link([])
|
||||
|
||||
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
|
||||
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
|
||||
assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
|
||||
assert Application.get_env(:logger, :level) == :debug
|
||||
assert Application.get_env(:postgrex, :test_key) == :value
|
||||
|
||||
on_exit(fn ->
|
||||
Application.delete_env(:pleroma, :test_key)
|
||||
Application.delete_env(:idna, :test_key)
|
||||
Application.delete_env(:quack, :test_key)
|
||||
Application.delete_env(:postgrex, :test_key)
|
||||
Application.put_env(:logger, :level, initial)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
@ -78,8 +92,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "transfer config values with full subkey update" do
|
||||
emoji = Application.get_env(:pleroma, :emoji)
|
||||
assets = Application.get_env(:pleroma, :assets)
|
||||
clear_config(:emoji)
|
||||
clear_config(:assets)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
|
|
@ -99,11 +113,6 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
assert emoji_env[:groups] == [a: 1, b: 2]
|
||||
assets_env = Application.get_env(:pleroma, :assets)
|
||||
assert assets_env[:mascots] == [a: 1, b: 2]
|
||||
|
||||
on_exit(fn ->
|
||||
Application.put_env(:pleroma, :emoji, emoji)
|
||||
Application.put_env(:pleroma, :assets, assets)
|
||||
end)
|
||||
end
|
||||
|
||||
describe "pleroma restart" do
|
||||
|
|
@ -112,8 +121,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "don't restart if no reboot time settings were changed" do
|
||||
emoji = Application.get_env(:pleroma, :emoji)
|
||||
on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
|
||||
clear_config(:emoji)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
|
|
@ -128,8 +136,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "on reboot time key" do
|
||||
chat = Application.get_env(:pleroma, :chat)
|
||||
on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
|
||||
clear_config(:chat)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
|
|
@ -141,8 +148,7 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "on reboot time subkey" do
|
||||
captcha = Application.get_env(:pleroma, Pleroma.Captcha)
|
||||
on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
|
||||
clear_config(Pleroma.Captcha)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
|
|
@ -154,13 +160,8 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
end
|
||||
|
||||
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
|
||||
chat = Application.get_env(:pleroma, :chat)
|
||||
captcha = Application.get_env(:pleroma, Pleroma.Captcha)
|
||||
|
||||
on_exit(fn ->
|
||||
Application.put_env(:pleroma, :chat, chat)
|
||||
Application.put_env(:pleroma, Pleroma.Captcha, captcha)
|
||||
end)
|
||||
clear_config(:chat)
|
||||
clear_config(Pleroma.Captcha)
|
||||
|
||||
ConfigDB.create(%{
|
||||
group: ":pleroma",
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Emoji.FormatterTest do
|
||||
alias Pleroma.Emoji
|
||||
alias Pleroma.Emoji.Formatter
|
||||
use Pleroma.DataCase
|
||||
|
||||
|
|
@ -32,30 +31,19 @@ defmodule Pleroma.Emoji.FormatterTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "get_emoji" do
|
||||
describe "get_emoji_map" do
|
||||
test "it returns the emoji used in the text" do
|
||||
text = "I love :firefox:"
|
||||
|
||||
assert Formatter.get_emoji(text) == [
|
||||
{"firefox",
|
||||
%Emoji{
|
||||
code: "firefox",
|
||||
file: "/emoji/Firefox.gif",
|
||||
tags: ["Gif", "Fun"],
|
||||
safe_code: "firefox",
|
||||
safe_file: "/emoji/Firefox.gif"
|
||||
}}
|
||||
]
|
||||
assert Formatter.get_emoji_map("I love :firefox:") == %{
|
||||
"firefox" => "http://localhost:4001/emoji/Firefox.gif"
|
||||
}
|
||||
end
|
||||
|
||||
test "it returns a nice empty result when no emojis are present" do
|
||||
text = "I love moominamma"
|
||||
assert Formatter.get_emoji(text) == []
|
||||
assert Formatter.get_emoji_map("I love moominamma") == %{}
|
||||
end
|
||||
|
||||
test "it doesn't die when text is absent" do
|
||||
text = nil
|
||||
assert Formatter.get_emoji(text) == []
|
||||
assert Formatter.get_emoji_map(nil) == %{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
2
test/fixtures/config/temp.secret.exs
vendored
2
test/fixtures/config/temp.secret.exs
vendored
|
|
@ -7,3 +7,5 @@ config :pleroma, :second_setting, key: "value2", key2: ["Activity"]
|
|||
config :quack, level: :info
|
||||
|
||||
config :pleroma, Pleroma.Repo, pool: Ecto.Adapters.SQL.Sandbox
|
||||
|
||||
config :postgrex, :json_library, Poison
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ defmodule Pleroma.FormatterTest do
|
|||
archaeme =
|
||||
insert(:user,
|
||||
nickname: "archa_eme_",
|
||||
source_data: %{"url" => "https://archeme/@archa_eme_"}
|
||||
uri: "https://archeme/@archa_eme_"
|
||||
)
|
||||
|
||||
archaeme_remote = insert(:user, %{nickname: "archaeme@archae.me"})
|
||||
|
|
|
|||
BIN
test/instance_static/add/shortcode.png
Normal file
BIN
test/instance_static/add/shortcode.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 B |
BIN
test/instance_static/emoji/pack_bad_sha/blank.png
Normal file
BIN
test/instance_static/emoji/pack_bad_sha/blank.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 95 B |
13
test/instance_static/emoji/pack_bad_sha/pack.json
Normal file
13
test/instance_static/emoji/pack_bad_sha/pack.json
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"pack": {
|
||||
"license": "Test license",
|
||||
"homepage": "https://pleroma.social",
|
||||
"description": "Test description",
|
||||
"can-download": true,
|
||||
"share-files": true,
|
||||
"download-sha256": "57482F30674FD3DE821FF48C81C00DA4D4AF1F300209253684ABA7075E5FC238"
|
||||
},
|
||||
"files": {
|
||||
"blank": "blank.png"
|
||||
}
|
||||
}
|
||||
BIN
test/instance_static/emoji/pack_bad_sha/pack_bad_sha.zip
Normal file
BIN
test/instance_static/emoji/pack_bad_sha/pack_bad_sha.zip
Normal file
Binary file not shown.
|
|
@ -1,13 +1,11 @@
|
|||
{
|
||||
"pack": {
|
||||
"license": "Test license",
|
||||
"homepage": "https://pleroma.social",
|
||||
"description": "Test description",
|
||||
|
||||
"share-files": true
|
||||
},
|
||||
|
||||
"files": {
|
||||
"blank": "blank.png"
|
||||
},
|
||||
"pack": {
|
||||
"description": "Test description",
|
||||
"homepage": "https://pleroma.social",
|
||||
"license": "Test license",
|
||||
"share-files": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,11 @@
|
|||
"license": "Test license",
|
||||
"homepage": "https://pleroma.social",
|
||||
"description": "Test description",
|
||||
|
||||
"fallback-src": "https://nonshared-pack",
|
||||
"fallback-src-sha256": "74409E2674DAA06C072729C6C8426C4CB3B7E0B85ED77792DB7A436E11D76DAF",
|
||||
|
||||
"share-files": false
|
||||
},
|
||||
|
||||
"files": {
|
||||
"blank": "blank.png"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,11 +8,13 @@ defmodule Pleroma.NotificationTest do
|
|||
import Pleroma.Factory
|
||||
import Mock
|
||||
|
||||
alias Pleroma.FollowingRelationship
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.NotificationView
|
||||
alias Pleroma.Web.Push
|
||||
alias Pleroma.Web.Streamer
|
||||
|
||||
|
|
@ -275,16 +277,6 @@ defmodule Pleroma.NotificationTest do
|
|||
refute Notification.create_notification(activity, author)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for follow-unfollow-follow chains" do
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user)
|
||||
{:ok, _, _, activity} = CommonAPI.follow(user, followed_user)
|
||||
Notification.create_notification(activity, followed_user)
|
||||
CommonAPI.unfollow(user, followed_user)
|
||||
{:ok, _, _, activity_dupe} = CommonAPI.follow(user, followed_user)
|
||||
refute Notification.create_notification(activity_dupe, followed_user)
|
||||
end
|
||||
|
||||
test "it doesn't create duplicate notifications for follow+subscribed users" do
|
||||
user = insert(:user)
|
||||
subscriber = insert(:user)
|
||||
|
|
@ -307,6 +299,84 @@ defmodule Pleroma.NotificationTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "follow / follow_request notifications" do
|
||||
test "it creates `follow` notification for approved Follow activity" do
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user, locked: false)
|
||||
|
||||
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
|
||||
assert FollowingRelationship.following?(user, followed_user)
|
||||
assert [notification] = Notification.for_user(followed_user)
|
||||
|
||||
assert %{type: "follow"} =
|
||||
NotificationView.render("show.json", %{
|
||||
notification: notification,
|
||||
for: followed_user
|
||||
})
|
||||
end
|
||||
|
||||
test "if `follow_request` notifications are enabled, " <>
|
||||
"it creates `follow_request` notification for pending Follow activity" do
|
||||
clear_config([:notifications, :enable_follow_request_notifications], true)
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user, locked: true)
|
||||
|
||||
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
|
||||
refute FollowingRelationship.following?(user, followed_user)
|
||||
assert [notification] = Notification.for_user(followed_user)
|
||||
|
||||
render_opts = %{notification: notification, for: followed_user}
|
||||
assert %{type: "follow_request"} = NotificationView.render("show.json", render_opts)
|
||||
|
||||
# After request is accepted, the same notification is rendered with type "follow":
|
||||
assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user)
|
||||
|
||||
notification_id = notification.id
|
||||
assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
|
||||
assert %{type: "follow"} = NotificationView.render("show.json", render_opts)
|
||||
end
|
||||
|
||||
test "if `follow_request` notifications are disabled, " <>
|
||||
"it does NOT create `follow*` notification for pending Follow activity" do
|
||||
clear_config([:notifications, :enable_follow_request_notifications], false)
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user, locked: true)
|
||||
|
||||
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
|
||||
refute FollowingRelationship.following?(user, followed_user)
|
||||
assert [] = Notification.for_user(followed_user)
|
||||
|
||||
# After request is accepted, no new notifications are generated:
|
||||
assert {:ok, _} = CommonAPI.accept_follow_request(user, followed_user)
|
||||
assert [] = Notification.for_user(followed_user)
|
||||
end
|
||||
|
||||
test "it doesn't create a notification for follow-unfollow-follow chains" do
|
||||
user = insert(:user)
|
||||
followed_user = insert(:user, locked: false)
|
||||
|
||||
{:ok, _, _, _activity} = CommonAPI.follow(user, followed_user)
|
||||
assert FollowingRelationship.following?(user, followed_user)
|
||||
assert [notification] = Notification.for_user(followed_user)
|
||||
|
||||
CommonAPI.unfollow(user, followed_user)
|
||||
{:ok, _, _, _activity_dupe} = CommonAPI.follow(user, followed_user)
|
||||
|
||||
notification_id = notification.id
|
||||
assert [%{id: ^notification_id}] = Notification.for_user(followed_user)
|
||||
end
|
||||
|
||||
test "dismisses the notification on follow request rejection" do
|
||||
clear_config([:notifications, :enable_follow_request_notifications], true)
|
||||
user = insert(:user, locked: true)
|
||||
follower = insert(:user)
|
||||
{:ok, _, _, _follow_activity} = CommonAPI.follow(follower, user)
|
||||
assert [notification] = Notification.for_user(user)
|
||||
{:ok, _follower} = CommonAPI.reject_follow_request(follower, user)
|
||||
assert [] = Notification.for_user(user)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get notification" do
|
||||
test "it gets a notification that belongs to the user" do
|
||||
user = insert(:user)
|
||||
|
|
@ -622,6 +692,37 @@ defmodule Pleroma.NotificationTest do
|
|||
assert [other_user] == disabled_receivers
|
||||
refute other_user in enabled_receivers
|
||||
end
|
||||
|
||||
test "it returns non-following domain-blocking recipient in disabled recipients list" do
|
||||
blocked_domain = "blocked.domain"
|
||||
user = insert(:user, %{ap_id: "https://#{blocked_domain}/@actor"})
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
|
||||
|
||||
{enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
|
||||
|
||||
assert [] == enabled_receivers
|
||||
assert [other_user] == disabled_receivers
|
||||
end
|
||||
|
||||
test "it returns following domain-blocking recipient in enabled recipients list" do
|
||||
blocked_domain = "blocked.domain"
|
||||
user = insert(:user, %{ap_id: "https://#{blocked_domain}/@actor"})
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}!"})
|
||||
|
||||
{enabled_receivers, disabled_receivers} = Notification.get_notified_from_activity(activity)
|
||||
|
||||
assert [other_user] == enabled_receivers
|
||||
assert [] == disabled_receivers
|
||||
end
|
||||
end
|
||||
|
||||
describe "notification lifecycle" do
|
||||
|
|
@ -884,7 +985,7 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for blocked domain" do
|
||||
test "it doesn't return notifications for domain-blocked non-followed user" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
|
|
@ -894,6 +995,18 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Notification.for_user(user) == []
|
||||
end
|
||||
|
||||
test "it returns notifications for domain-blocked but followed user" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
{:ok, _} = User.follow(user, blocked)
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"})
|
||||
|
||||
assert length(Notification.for_user(user)) == 1
|
||||
end
|
||||
|
||||
test "it doesn't return notifications for muted thread" do
|
||||
user = insert(:user)
|
||||
another_user = insert(:user)
|
||||
|
|
@ -924,7 +1037,8 @@ defmodule Pleroma.NotificationTest do
|
|||
assert Enum.empty?(Notification.for_user(user, %{with_muted: true}))
|
||||
end
|
||||
|
||||
test "it doesn't return notifications from a domain-blocked user when with_muted is set" do
|
||||
test "when with_muted is set, " <>
|
||||
"it doesn't return notifications from a domain-blocked non-followed user" do
|
||||
user = insert(:user)
|
||||
blocked = insert(:user, ap_id: "http://some-domain.com")
|
||||
{:ok, user} = User.block_domain(user, "some-domain.com")
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
|
|||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Plugs.AuthenticationPlug
|
||||
alias Pleroma.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Plugs.PlugHelper
|
||||
alias Pleroma.User
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
|
@ -36,13 +38,16 @@ defmodule Pleroma.Plugs.AuthenticationPlugTest do
|
|||
assert ret_conn == conn
|
||||
end
|
||||
|
||||
test "with a correct password in the credentials, it assigns the auth_user", %{conn: conn} do
|
||||
test "with a correct password in the credentials, " <>
|
||||
"it assigns the auth_user and marks OAuthScopesPlug as skipped",
|
||||
%{conn: conn} do
|
||||
conn =
|
||||
conn
|
||||
|> assign(:auth_credentials, %{password: "guy"})
|
||||
|> AuthenticationPlug.call(%{})
|
||||
|
||||
assert conn.assigns.user == conn.assigns.auth_user
|
||||
assert PlugHelper.plug_skipped?(conn, OAuthScopesPlug)
|
||||
end
|
||||
|
||||
test "with a wrong password in the credentials, it does nothing", %{conn: conn} do
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule Pleroma.Plugs.EnsureAuthenticatedPlugTest do
|
|||
conn = assign(conn, :user, %User{})
|
||||
ret_conn = EnsureAuthenticatedPlug.call(conn, %{})
|
||||
|
||||
assert ret_conn == conn
|
||||
refute ret_conn.halted
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -34,20 +34,22 @@ defmodule Pleroma.Plugs.EnsureAuthenticatedPlugTest do
|
|||
|
||||
test "it continues if a user is assigned", %{conn: conn, true_fn: true_fn, false_fn: false_fn} do
|
||||
conn = assign(conn, :user, %User{})
|
||||
assert EnsureAuthenticatedPlug.call(conn, if_func: true_fn) == conn
|
||||
assert EnsureAuthenticatedPlug.call(conn, if_func: false_fn) == conn
|
||||
assert EnsureAuthenticatedPlug.call(conn, unless_func: true_fn) == conn
|
||||
assert EnsureAuthenticatedPlug.call(conn, unless_func: false_fn) == conn
|
||||
refute EnsureAuthenticatedPlug.call(conn, if_func: true_fn).halted
|
||||
refute EnsureAuthenticatedPlug.call(conn, if_func: false_fn).halted
|
||||
refute EnsureAuthenticatedPlug.call(conn, unless_func: true_fn).halted
|
||||
refute EnsureAuthenticatedPlug.call(conn, unless_func: false_fn).halted
|
||||
end
|
||||
|
||||
test "it continues if a user is NOT assigned but :if_func evaluates to `false`",
|
||||
%{conn: conn, false_fn: false_fn} do
|
||||
assert EnsureAuthenticatedPlug.call(conn, if_func: false_fn) == conn
|
||||
ret_conn = EnsureAuthenticatedPlug.call(conn, if_func: false_fn)
|
||||
refute ret_conn.halted
|
||||
end
|
||||
|
||||
test "it continues if a user is NOT assigned but :unless_func evaluates to `true`",
|
||||
%{conn: conn, true_fn: true_fn} do
|
||||
assert EnsureAuthenticatedPlug.call(conn, unless_func: true_fn) == conn
|
||||
ret_conn = EnsureAuthenticatedPlug.call(conn, unless_func: true_fn)
|
||||
refute ret_conn.halted
|
||||
end
|
||||
|
||||
test "it halts if a user is NOT assigned and :if_func evaluates to `true`",
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
conn
|
||||
|> EnsurePublicOrAuthenticatedPlug.call(%{})
|
||||
|
||||
assert ret_conn == conn
|
||||
refute ret_conn.halted
|
||||
end
|
||||
|
||||
test "it continues if a user is assigned, even if not public", %{conn: conn} do
|
||||
|
|
@ -43,6 +43,6 @@ defmodule Pleroma.Plugs.EnsurePublicOrAuthenticatedPlugTest do
|
|||
conn
|
||||
|> EnsurePublicOrAuthenticatedPlug.call(%{})
|
||||
|
||||
assert ret_conn == conn
|
||||
refute ret_conn.halted
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
|
|||
import Pleroma.Factory
|
||||
|
||||
alias Pleroma.Plugs.LegacyAuthenticationPlug
|
||||
alias Pleroma.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Plugs.PlugHelper
|
||||
alias Pleroma.User
|
||||
|
||||
setup do
|
||||
|
|
@ -36,7 +38,8 @@ defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
|
|||
end
|
||||
|
||||
@tag :skip_on_mac
|
||||
test "it authenticates the auth_user if present and password is correct and resets the password",
|
||||
test "if `auth_user` is present and password is correct, " <>
|
||||
"it authenticates the user, resets the password, marks OAuthScopesPlug as skipped",
|
||||
%{
|
||||
conn: conn,
|
||||
user: user
|
||||
|
|
@ -49,6 +52,7 @@ defmodule Pleroma.Plugs.LegacyAuthenticationPlugTest do
|
|||
conn = LegacyAuthenticationPlug.call(conn, %{})
|
||||
|
||||
assert conn.assigns.user.id == user.id
|
||||
assert PlugHelper.plug_skipped?(conn, OAuthScopesPlug)
|
||||
end
|
||||
|
||||
@tag :skip_on_mac
|
||||
|
|
|
|||
|
|
@ -5,15 +5,22 @@
|
|||
defmodule Pleroma.Plugs.OAuthScopesPlugTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
|
||||
alias Pleroma.Plugs.OAuthScopesPlug
|
||||
alias Pleroma.Repo
|
||||
|
||||
import Mock
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_with_mocks([{EnsurePublicOrAuthenticatedPlug, [], [call: fn conn, _ -> conn end]}]) do
|
||||
:ok
|
||||
test "is not performed if marked as skipped", %{conn: conn} do
|
||||
with_mock OAuthScopesPlug, [:passthrough], perform: &passthrough([&1, &2]) do
|
||||
conn =
|
||||
conn
|
||||
|> OAuthScopesPlug.skip_plug()
|
||||
|> OAuthScopesPlug.call(%{scopes: ["random_scope"]})
|
||||
|
||||
refute called(OAuthScopesPlug.perform(:_, :_))
|
||||
refute conn.halted
|
||||
end
|
||||
end
|
||||
|
||||
test "if `token.scopes` fulfills specified 'any of' conditions, " <>
|
||||
|
|
@ -48,7 +55,7 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
|
|||
|
||||
describe "with `fallback: :proceed_unauthenticated` option, " do
|
||||
test "if `token.scopes` doesn't fulfill specified conditions, " <>
|
||||
"clears :user and :token assigns and calls EnsurePublicOrAuthenticatedPlug",
|
||||
"clears :user and :token assigns",
|
||||
%{conn: conn} do
|
||||
user = insert(:user)
|
||||
token1 = insert(:oauth_token, scopes: ["read", "write"], user: user)
|
||||
|
|
@ -67,35 +74,6 @@ defmodule Pleroma.Plugs.OAuthScopesPlugTest do
|
|||
refute ret_conn.halted
|
||||
refute ret_conn.assigns[:user]
|
||||
refute ret_conn.assigns[:token]
|
||||
|
||||
assert called(EnsurePublicOrAuthenticatedPlug.call(ret_conn, :_))
|
||||
end
|
||||
end
|
||||
|
||||
test "with :skip_instance_privacy_check option, " <>
|
||||
"if `token.scopes` doesn't fulfill specified conditions, " <>
|
||||
"clears :user and :token assigns and does NOT call EnsurePublicOrAuthenticatedPlug",
|
||||
%{conn: conn} do
|
||||
user = insert(:user)
|
||||
token1 = insert(:oauth_token, scopes: ["read:statuses", "write"], user: user)
|
||||
|
||||
for token <- [token1, nil], op <- [:|, :&] do
|
||||
ret_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> assign(:token, token)
|
||||
|> OAuthScopesPlug.call(%{
|
||||
scopes: ["read"],
|
||||
op: op,
|
||||
fallback: :proceed_unauthenticated,
|
||||
skip_instance_privacy_check: true
|
||||
})
|
||||
|
||||
refute ret_conn.halted
|
||||
refute ret_conn.assigns[:user]
|
||||
refute ret_conn.assigns[:token]
|
||||
|
||||
refute called(EnsurePublicOrAuthenticatedPlug.call(ret_conn, :_))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,12 +19,7 @@ defmodule Pleroma.SignatureTest do
|
|||
|
||||
@private_key "-----BEGIN RSA PRIVATE KEY-----\nMIIEpQIBAAKCAQEA48qb4v6kqigZutO9Ot0wkp27GIF2LiVaADgxQORZozZR63jH\nTaoOrS3Xhngbgc8SSOhfXET3omzeCLqaLNfXnZ8OXmuhJfJSU6mPUvmZ9QdT332j\nfN/g3iWGhYMf/M9ftCKh96nvFVO/tMruzS9xx7tkrfJjehdxh/3LlJMMImPtwcD7\nkFXwyt1qZTAU6Si4oQAJxRDQXHp1ttLl3Ob829VM7IKkrVmY8TD+JSlV0jtVJPj6\n1J19ytKTx/7UaucYvb9HIiBpkuiy5n/irDqKLVf5QEdZoNCdojOZlKJmTLqHhzKP\n3E9TxsUjhrf4/EqegNc/j982RvOxeu4i40zMQwIDAQABAoIBAQDH5DXjfh21i7b4\ncXJuw0cqget617CDUhemdakTDs9yH+rHPZd3mbGDWuT0hVVuFe4vuGpmJ8c+61X0\nRvugOlBlavxK8xvYlsqTzAmPgKUPljyNtEzQ+gz0I+3mH2jkin2rL3D+SksZZgKm\nfiYMPIQWB2WUF04gB46DDb2mRVuymGHyBOQjIx3WC0KW2mzfoFUFRlZEF+Nt8Ilw\nT+g/u0aZ1IWoszbsVFOEdghgZET0HEarum0B2Je/ozcPYtwmU10iBANGMKdLqaP/\nj954BPunrUf6gmlnLZKIKklJj0advx0NA+cL79+zeVB3zexRYSA5o9q0WPhiuTwR\n/aedWHnBAoGBAP0sDWBAM1Y4TRAf8ZI9PcztwLyHPzfEIqzbObJJnx1icUMt7BWi\n+/RMOnhrlPGE1kMhOqSxvXYN3u+eSmWTqai2sSH5Hdw2EqnrISSTnwNUPINX7fHH\njEkgmXQ6ixE48SuBZnb4w1EjdB/BA6/sjL+FNhggOc87tizLTkMXmMtTAoGBAOZV\n+wPuAMBDBXmbmxCuDIjoVmgSlgeRunB1SA8RCPAFAiUo3+/zEgzW2Oz8kgI+xVwM\n33XkLKrWG1Orhpp6Hm57MjIc5MG+zF4/YRDpE/KNG9qU1tiz0UD5hOpIU9pP4bR/\ngxgPxZzvbk4h5BfHWLpjlk8UUpgk6uxqfti48c1RAoGBALBOKDZ6HwYRCSGMjUcg\n3NPEUi84JD8qmFc2B7Tv7h2he2ykIz9iFAGpwCIyETQsJKX1Ewi0OlNnD3RhEEAy\nl7jFGQ+mkzPSeCbadmcpYlgIJmf1KN/x7fDTAepeBpCEzfZVE80QKbxsaybd3Dp8\nCfwpwWUFtBxr4c7J+gNhAGe/AoGAPn8ZyqkrPv9wXtyfqFjxQbx4pWhVmNwrkBPi\nZ2Qh3q4dNOPwTvTO8vjghvzIyR8rAZzkjOJKVFgftgYWUZfM5gE7T2mTkBYq8W+U\n8LetF+S9qAM2gDnaDx0kuUTCq7t87DKk6URuQ/SbI0wCzYjjRD99KxvChVGPBHKo\n1DjqMuECgYEAgJGNm7/lJCS2wk81whfy/ttKGsEIkyhPFYQmdGzSYC5aDc2gp1R3\nxtOkYEvdjfaLfDGEa4UX8CHHF+w3t9u8hBtcdhMH6GYb9iv6z0VBTt4A/11HUR49\n3Z7TQ18Iyh3jAUCzFV9IJlLIExq5Y7P4B3ojWFBN607sDCt8BMPbDYs=\n-----END RSA PRIVATE KEY-----"
|
||||
|
||||
@public_key %{
|
||||
"id" => "https://mastodon.social/users/lambadalambda#main-key",
|
||||
"owner" => "https://mastodon.social/users/lambadalambda",
|
||||
"publicKeyPem" =>
|
||||
"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw0P/Tq4gb4G/QVuMGbJo\nC/AfMNcv+m7NfrlOwkVzcU47jgESuYI4UtJayissCdBycHUnfVUd9qol+eznSODz\nCJhfJloqEIC+aSnuEPGA0POtWad6DU0E6/Ho5zQn5WAWUwbRQqowbrsm/GHo2+3v\neR5jGenwA6sYhINg/c3QQbksyV0uJ20Umyx88w8+TJuv53twOfmyDWuYNoQ3y5cc\nHKOZcLHxYOhvwg3PFaGfFHMFiNmF40dTXt9K96r7sbzc44iLD+VphbMPJEjkMuf8\nPGEFOBzy8pm3wJZw2v32RNW2VESwMYyqDzwHXGSq1a73cS7hEnc79gXlELsK04L9\nQQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
}
|
||||
@public_key "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw0P/Tq4gb4G/QVuMGbJo\nC/AfMNcv+m7NfrlOwkVzcU47jgESuYI4UtJayissCdBycHUnfVUd9qol+eznSODz\nCJhfJloqEIC+aSnuEPGA0POtWad6DU0E6/Ho5zQn5WAWUwbRQqowbrsm/GHo2+3v\neR5jGenwA6sYhINg/c3QQbksyV0uJ20Umyx88w8+TJuv53twOfmyDWuYNoQ3y5cc\nHKOZcLHxYOhvwg3PFaGfFHMFiNmF40dTXt9K96r7sbzc44iLD+VphbMPJEjkMuf8\nPGEFOBzy8pm3wJZw2v32RNW2VESwMYyqDzwHXGSq1a73cS7hEnc79gXlELsK04L9\nQQIDAQAB\n-----END PUBLIC KEY-----\n"
|
||||
|
||||
@rsa_public_key {
|
||||
:RSAPublicKey,
|
||||
|
|
@ -42,7 +37,7 @@ defmodule Pleroma.SignatureTest do
|
|||
test "it returns key" do
|
||||
expected_result = {:ok, @rsa_public_key}
|
||||
|
||||
user = insert(:user, source_data: %{"publicKey" => @public_key})
|
||||
user = insert(:user, public_key: @public_key)
|
||||
|
||||
assert Signature.fetch_public_key(make_fake_conn(user.ap_id)) == expected_result
|
||||
end
|
||||
|
|
@ -53,8 +48,8 @@ defmodule Pleroma.SignatureTest do
|
|||
end) =~ "[error] Could not decode user"
|
||||
end
|
||||
|
||||
test "it returns error if public key is empty" do
|
||||
user = insert(:user, source_data: %{"publicKey" => %{}})
|
||||
test "it returns error if public key is nil" do
|
||||
user = insert(:user, public_key: nil)
|
||||
|
||||
assert Signature.fetch_public_key(make_fake_conn(user.ap_id)) == {:error, :error}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,11 +2,21 @@
|
|||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.StateTest do
|
||||
defmodule Pleroma.StatsTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
describe "user count" do
|
||||
test "it ignores internal users" do
|
||||
_user = insert(:user, local: true)
|
||||
_internal = insert(:user, local: true, nickname: nil)
|
||||
_internal = Pleroma.Web.ActivityPub.Relay.get_actor()
|
||||
|
||||
assert match?(%{stats: %{user_count: 1}}, Pleroma.Stats.calculate_stat_data())
|
||||
end
|
||||
end
|
||||
|
||||
describe "status visibility count" do
|
||||
test "on new status" do
|
||||
user = insert(:user)
|
||||
57
test/support/api_spec_helpers.ex
Normal file
57
test/support/api_spec_helpers.ex
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Tests.ApiSpecHelpers do
|
||||
@moduledoc """
|
||||
OpenAPI spec test helpers
|
||||
"""
|
||||
|
||||
import ExUnit.Assertions
|
||||
|
||||
alias OpenApiSpex.Cast.Error
|
||||
alias OpenApiSpex.Reference
|
||||
alias OpenApiSpex.Schema
|
||||
|
||||
def assert_schema(value, schema) do
|
||||
api_spec = Pleroma.Web.ApiSpec.spec()
|
||||
|
||||
case OpenApiSpex.cast_value(value, schema, api_spec) do
|
||||
{:ok, data} ->
|
||||
data
|
||||
|
||||
{:error, errors} ->
|
||||
errors =
|
||||
Enum.map(errors, fn error ->
|
||||
message = Error.message(error)
|
||||
path = Error.path_to_string(error)
|
||||
"#{message} at #{path}"
|
||||
end)
|
||||
|
||||
flunk(
|
||||
"Value does not conform to schema #{schema.title}: #{Enum.join(errors, "\n")}\n#{
|
||||
inspect(value)
|
||||
}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def resolve_schema(%Schema{} = schema), do: schema
|
||||
|
||||
def resolve_schema(%Reference{} = ref) do
|
||||
schemas = Pleroma.Web.ApiSpec.spec().components.schemas
|
||||
Reference.resolve_schema(ref, schemas)
|
||||
end
|
||||
|
||||
def api_operations do
|
||||
paths = Pleroma.Web.ApiSpec.spec().paths
|
||||
|
||||
Enum.flat_map(paths, fn {_, path_item} ->
|
||||
path_item
|
||||
|> Map.take([:delete, :get, :head, :options, :patch, :post, :put, :trace])
|
||||
|> Map.values()
|
||||
|> Enum.reject(&is_nil/1)
|
||||
|> Enum.uniq()
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
|
@ -51,6 +51,60 @@ defmodule Pleroma.Web.ConnCase do
|
|||
%{user: user, token: token, conn: conn}
|
||||
end
|
||||
|
||||
defp request_content_type(%{conn: conn}) do
|
||||
conn = put_req_header(conn, "content-type", "multipart/form-data")
|
||||
[conn: conn]
|
||||
end
|
||||
|
||||
defp json_response_and_validate_schema(
|
||||
%{
|
||||
private: %{
|
||||
open_api_spex: %{operation_id: op_id, operation_lookup: lookup, spec: spec}
|
||||
}
|
||||
} = conn,
|
||||
status
|
||||
) do
|
||||
content_type =
|
||||
conn
|
||||
|> Plug.Conn.get_resp_header("content-type")
|
||||
|> List.first()
|
||||
|> String.split(";")
|
||||
|> List.first()
|
||||
|
||||
status = Plug.Conn.Status.code(status)
|
||||
|
||||
unless lookup[op_id].responses[status] do
|
||||
err = "Response schema not found for #{conn.status} #{conn.method} #{conn.request_path}"
|
||||
flunk(err)
|
||||
end
|
||||
|
||||
schema = lookup[op_id].responses[status].content[content_type].schema
|
||||
json = json_response(conn, status)
|
||||
|
||||
case OpenApiSpex.cast_value(json, schema, spec) do
|
||||
{:ok, _data} ->
|
||||
json
|
||||
|
||||
{:error, errors} ->
|
||||
errors =
|
||||
Enum.map(errors, fn error ->
|
||||
message = OpenApiSpex.Cast.Error.message(error)
|
||||
path = OpenApiSpex.Cast.Error.path_to_string(error)
|
||||
"#{message} at #{path}"
|
||||
end)
|
||||
|
||||
flunk(
|
||||
"Response does not conform to schema of #{op_id} operation: #{
|
||||
Enum.join(errors, "\n")
|
||||
}\n#{inspect(json)}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
defp json_response_and_validate_schema(conn, _status) do
|
||||
flunk("Response schema not found for #{conn.method} #{conn.request_path} #{conn.status}")
|
||||
end
|
||||
|
||||
defp ensure_federating_or_authenticated(conn, url, user) do
|
||||
initial_setting = Config.get([:instance, :federating])
|
||||
on_exit(fn -> Config.put([:instance, :federating], initial_setting) end)
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ defmodule Pleroma.Factory do
|
|||
|
||||
def oauth_app_factory do
|
||||
%Pleroma.Web.OAuth.App{
|
||||
client_name: "Some client",
|
||||
client_name: sequence(:client_name, &"Some client #{&1}"),
|
||||
redirect_uris: "https://example.com/callback",
|
||||
scopes: ["read", "write", "follow", "push", "admin"],
|
||||
website: "https://example.com",
|
||||
|
|
|
|||
65
test/tasks/app_test.exs
Normal file
65
test/tasks/app_test.exs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# 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.AppTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
setup_all do
|
||||
Mix.shell(Mix.Shell.Process)
|
||||
|
||||
on_exit(fn ->
|
||||
Mix.shell(Mix.Shell.IO)
|
||||
end)
|
||||
end
|
||||
|
||||
describe "creates new app" do
|
||||
test "with default scopes" do
|
||||
name = "Some name"
|
||||
redirect = "https://example.com"
|
||||
Mix.Tasks.Pleroma.App.run(["create", "-n", name, "-r", redirect])
|
||||
|
||||
assert_app(name, redirect, ["read", "write", "follow", "push"])
|
||||
end
|
||||
|
||||
test "with custom scopes" do
|
||||
name = "Another name"
|
||||
redirect = "https://example.com"
|
||||
|
||||
Mix.Tasks.Pleroma.App.run([
|
||||
"create",
|
||||
"-n",
|
||||
name,
|
||||
"-r",
|
||||
redirect,
|
||||
"-s",
|
||||
"read,write,follow,push,admin"
|
||||
])
|
||||
|
||||
assert_app(name, redirect, ["read", "write", "follow", "push", "admin"])
|
||||
end
|
||||
end
|
||||
|
||||
test "with errors" do
|
||||
Mix.Tasks.Pleroma.App.run(["create"])
|
||||
{:mix_shell, :error, ["Creating failed:"]}
|
||||
{:mix_shell, :error, ["name: can't be blank"]}
|
||||
{:mix_shell, :error, ["redirect_uris: can't be blank"]}
|
||||
end
|
||||
|
||||
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 message == "#{name} successfully created:"
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert message == "App client_id: #{app.client_id}"
|
||||
|
||||
assert_received {:mix_shell, :info, [message]}
|
||||
assert message == "App client_secret: #{app.client_secret}"
|
||||
|
||||
assert app.scopes == scopes
|
||||
assert app.redirect_uris == redirect
|
||||
end
|
||||
end
|
||||
|
|
@ -38,7 +38,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
on_exit(fn -> Application.put_env(:quack, :level, initial) end)
|
||||
end
|
||||
|
||||
test "settings are migrated to db" do
|
||||
test "filtered settings are migrated to db" do
|
||||
assert Repo.all(ConfigDB) == []
|
||||
|
||||
Mix.Tasks.Pleroma.Config.migrate_to_db("test/fixtures/config/temp.secret.exs")
|
||||
|
|
@ -47,6 +47,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
config2 = ConfigDB.get_by_params(%{group: ":pleroma", key: ":second_setting"})
|
||||
config3 = ConfigDB.get_by_params(%{group: ":quack", key: ":level"})
|
||||
refute ConfigDB.get_by_params(%{group: ":pleroma", key: "Pleroma.Repo"})
|
||||
refute ConfigDB.get_by_params(%{group: ":postgrex", key: ":json_library"})
|
||||
|
||||
assert ConfigDB.from_binary(config1.value) == [key: "value", key2: [Repo]]
|
||||
assert ConfigDB.from_binary(config2.value) == [key: "value2", key2: ["Activity"]]
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
|
||||
assert user.source_data["endpoints"]
|
||||
assert user.inbox
|
||||
|
||||
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
||||
end
|
||||
|
|
@ -610,7 +610,7 @@ defmodule Pleroma.UserTest do
|
|||
) <> "/followers"
|
||||
end
|
||||
|
||||
describe "remote user creation changeset" do
|
||||
describe "remote user changeset" do
|
||||
@valid_remote %{
|
||||
bio: "hello",
|
||||
name: "Someone",
|
||||
|
|
@ -622,28 +622,28 @@ defmodule Pleroma.UserTest do
|
|||
setup do: clear_config([:instance, :user_name_length])
|
||||
|
||||
test "it confirms validity" do
|
||||
cs = User.remote_user_creation(@valid_remote)
|
||||
cs = User.remote_user_changeset(@valid_remote)
|
||||
assert cs.valid?
|
||||
end
|
||||
|
||||
test "it sets the follower_adress" do
|
||||
cs = User.remote_user_creation(@valid_remote)
|
||||
cs = User.remote_user_changeset(@valid_remote)
|
||||
# remote users get a fake local follower address
|
||||
assert cs.changes.follower_address ==
|
||||
User.ap_followers(%User{nickname: @valid_remote[:nickname]})
|
||||
end
|
||||
|
||||
test "it enforces the fqn format for nicknames" do
|
||||
cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
|
||||
cs = User.remote_user_changeset(%{@valid_remote | nickname: "bla"})
|
||||
assert Ecto.Changeset.get_field(cs, :local) == false
|
||||
assert cs.changes.avatar
|
||||
refute cs.valid?
|
||||
end
|
||||
|
||||
test "it has required fields" do
|
||||
[:name, :ap_id]
|
||||
[:ap_id]
|
||||
|> Enum.each(fn field ->
|
||||
cs = User.remote_user_creation(Map.delete(@valid_remote, field))
|
||||
cs = User.remote_user_changeset(Map.delete(@valid_remote, field))
|
||||
refute cs.valid?
|
||||
end)
|
||||
end
|
||||
|
|
@ -756,8 +756,8 @@ defmodule Pleroma.UserTest do
|
|||
]
|
||||
|
||||
{:ok, job} = User.follow_import(user1, identifiers)
|
||||
result = ObanHelpers.perform(job)
|
||||
|
||||
assert {:ok, result} = ObanHelpers.perform(job)
|
||||
assert is_list(result)
|
||||
assert result == [user2, user3]
|
||||
end
|
||||
|
|
@ -979,14 +979,26 @@ defmodule Pleroma.UserTest do
|
|||
]
|
||||
|
||||
{:ok, job} = User.blocks_import(user1, identifiers)
|
||||
result = ObanHelpers.perform(job)
|
||||
|
||||
assert {:ok, result} = ObanHelpers.perform(job)
|
||||
assert is_list(result)
|
||||
assert result == [user2, user3]
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_recipients_from_activity" do
|
||||
test "works for announces" do
|
||||
actor = insert(:user)
|
||||
user = insert(:user, local: true)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(actor, %{"status" => "hello"})
|
||||
{:ok, announce, _} = CommonAPI.repeat(activity.id, user)
|
||||
|
||||
recipients = User.get_recipients_from_activity(announce)
|
||||
|
||||
assert user in recipients
|
||||
end
|
||||
|
||||
test "get recipients" do
|
||||
actor = insert(:user)
|
||||
user = insert(:user, local: true)
|
||||
|
|
@ -1199,58 +1211,6 @@ defmodule Pleroma.UserTest do
|
|||
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
|
||||
end
|
||||
|
||||
describe "insert or update a user from given data" do
|
||||
test "with normal data" do
|
||||
user = insert(:user, %{nickname: "nick@name.de"})
|
||||
data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
|
||||
|
||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||
end
|
||||
|
||||
test "with overly long fields" do
|
||||
current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
|
||||
user = insert(:user, nickname: "nickname@supergood.domain")
|
||||
|
||||
data = %{
|
||||
ap_id: user.ap_id,
|
||||
name: user.name,
|
||||
nickname: user.nickname,
|
||||
fields: [
|
||||
%{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
|
||||
]
|
||||
}
|
||||
|
||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||
end
|
||||
|
||||
test "with an overly long bio" do
|
||||
current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
|
||||
user = insert(:user, nickname: "nickname@supergood.domain")
|
||||
|
||||
data = %{
|
||||
ap_id: user.ap_id,
|
||||
name: user.name,
|
||||
nickname: user.nickname,
|
||||
bio: String.duplicate("h", current_max_length + 1)
|
||||
}
|
||||
|
||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||
end
|
||||
|
||||
test "with an overly long display name" do
|
||||
current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
|
||||
user = insert(:user, nickname: "nickname@supergood.domain")
|
||||
|
||||
data = %{
|
||||
ap_id: user.ap_id,
|
||||
name: String.duplicate("h", current_max_length + 1),
|
||||
nickname: user.nickname
|
||||
}
|
||||
|
||||
assert {:ok, %User{}} = User.insert_or_update_user(data)
|
||||
end
|
||||
end
|
||||
|
||||
describe "per-user rich-text filtering" do
|
||||
test "html_filter_policy returns default policies, when rich-text is enabled" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -765,51 +765,87 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /users/:nickname/outbox" do
|
||||
test "it rejects posts from other users / unauuthenticated users", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
describe "POST /users/:nickname/outbox (C2S)" do
|
||||
setup do
|
||||
[
|
||||
activity: %{
|
||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||
"type" => "Create",
|
||||
"object" => %{"type" => "Note", "content" => "AP C2S test"},
|
||||
"to" => "https://www.w3.org/ns/activitystreams#Public",
|
||||
"cc" => []
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
test "it rejects posts from other users / unauthenticated users", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
conn = put_req_header(conn, "content-type", "application/activity+json")
|
||||
|
||||
conn
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(403)
|
||||
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "it inserts an incoming create activity into the database", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
test "it inserts an incoming create activity into the database", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|
||||
result = json_response(conn, 201)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(201)
|
||||
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
assert result["object"]
|
||||
assert %Object{data: object} = Object.normalize(result["object"])
|
||||
assert object["content"] == activity["object"]["content"]
|
||||
end
|
||||
|
||||
test "it rejects an incoming activity with bogus type", %{conn: conn} do
|
||||
data = File.read!("test/fixtures/activitypub-client-post-activity.json") |> Poison.decode!()
|
||||
test "it inserts an incoming sensitive activity into the database", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
user = insert(:user)
|
||||
object = Map.put(activity["object"], "sensitive", true)
|
||||
activity = Map.put(activity, "object", object)
|
||||
|
||||
data =
|
||||
data
|
||||
|> Map.put("type", "BadType")
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|> json_response(201)
|
||||
|
||||
assert Activity.get_by_ap_id(result["id"])
|
||||
assert result["object"]
|
||||
assert %Object{data: object} = Object.normalize(result["object"])
|
||||
assert object["sensitive"] == activity["object"]["sensitive"]
|
||||
assert object["content"] == activity["object"]["content"]
|
||||
end
|
||||
|
||||
test "it rejects an incoming activity with bogus type", %{conn: conn, activity: activity} do
|
||||
user = insert(:user)
|
||||
activity = Map.put(activity, "type", "BadType")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> put_req_header("content-type", "application/activity+json")
|
||||
|> post("/users/#{user.nickname}/outbox", data)
|
||||
|> post("/users/#{user.nickname}/outbox", activity)
|
||||
|
||||
assert json_response(conn, 400)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -180,7 +180,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||
assert user.ap_id == user_id
|
||||
assert user.nickname == "admin@mastodon.example.org"
|
||||
assert user.source_data
|
||||
assert user.ap_enabled
|
||||
assert user.follower_address == "http://mastodon.example.org/users/admin/followers"
|
||||
end
|
||||
|
|
@ -995,72 +994,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "like an object" do
|
||||
test_with_mock "sends an activity to federation", Federator, [:passthrough], [] do
|
||||
Config.put([:instance, :federating], true)
|
||||
note_activity = insert(:note_activity)
|
||||
assert object_activity = Object.normalize(note_activity)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object_activity)
|
||||
assert called(Federator.publish(like_activity))
|
||||
end
|
||||
|
||||
test "returns exist activity if object already liked" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object_activity = Object.normalize(note_activity)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object_activity)
|
||||
|
||||
{:ok, like_activity_exist, _object} = ActivityPub.like(user, object_activity)
|
||||
assert like_activity == like_activity_exist
|
||||
end
|
||||
|
||||
test "reverts like activity on error" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
assert {:error, :reverted} = ActivityPub.like(user, object)
|
||||
end
|
||||
|
||||
assert Repo.aggregate(Activity, :count, :id) == 1
|
||||
assert Repo.get(Object, object.id) == object
|
||||
end
|
||||
|
||||
test "adds a like activity to the db" do
|
||||
note_activity = insert(:note_activity)
|
||||
assert object = Object.normalize(note_activity)
|
||||
|
||||
user = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||
|
||||
assert like_activity.data["actor"] == user.ap_id
|
||||
assert like_activity.data["type"] == "Like"
|
||||
assert like_activity.data["object"] == object.data["id"]
|
||||
assert like_activity.data["to"] == [User.ap_followers(user), note_activity.data["actor"]]
|
||||
assert like_activity.data["context"] == object.data["context"]
|
||||
assert object.data["like_count"] == 1
|
||||
assert object.data["likes"] == [user.ap_id]
|
||||
|
||||
# Just return the original activity if the user already liked it.
|
||||
{:ok, same_like_activity, object} = ActivityPub.like(user, object)
|
||||
|
||||
assert like_activity == same_like_activity
|
||||
assert object.data["likes"] == [user.ap_id]
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, _like_activity, object} = ActivityPub.like(user_two, object)
|
||||
assert object.data["like_count"] == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "unliking" do
|
||||
test_with_mock "sends an activity to federation", Federator, [:passthrough], [] do
|
||||
Config.put([:instance, :federating], true)
|
||||
|
|
@ -1072,7 +1005,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
refute called(Federator.publish())
|
||||
|
||||
{:ok, _like_activity, object} = ActivityPub.like(user, object)
|
||||
{:ok, _like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
object = Object.get_by_id(object.id)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
|
|
@ -1083,10 +1017,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
test "reverts unliking on error" do
|
||||
note_activity = insert(:note_activity)
|
||||
object = Object.normalize(note_activity)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
object = Object.normalize(note_activity)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do
|
||||
|
|
@ -1107,7 +1041,9 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
{:ok, object} = ActivityPub.unlike(user, object)
|
||||
assert object.data["like_count"] == 0
|
||||
|
||||
{:ok, like_activity, object} = ActivityPub.like(user, object)
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
|
||||
object = Object.get_by_id(object.id)
|
||||
assert object.data["like_count"] == 1
|
||||
|
||||
{:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
|
||||
|
|
@ -1974,4 +1910,497 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
ActivityPub.move(old_user, new_user)
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't retrieve replies activities with exclude_replies" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"})
|
||||
|
||||
{:ok, _reply} =
|
||||
CommonAPI.post(user, %{"status" => "yeah", "in_reply_to_status_id" => activity.id})
|
||||
|
||||
[result] = ActivityPub.fetch_public_activities(%{"exclude_replies" => "true"})
|
||||
|
||||
assert result.id == activity.id
|
||||
|
||||
assert length(ActivityPub.fetch_public_activities()) == 2
|
||||
end
|
||||
|
||||
describe "replies filtering with public messages" do
|
||||
setup :public_messages
|
||||
|
||||
test "public timeline", %{users: %{u1: user}} do
|
||||
activities_ids =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("local_only", false)
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 16
|
||||
end
|
||||
|
||||
test "public timeline with reply_visibility `following`", %{
|
||||
users: %{u1: user},
|
||||
u1: u1,
|
||||
u2: u2,
|
||||
u3: u3,
|
||||
u4: u4,
|
||||
activities: activities
|
||||
} do
|
||||
activities_ids =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("local_only", false)
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("reply_visibility", "following")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 14
|
||||
|
||||
visible_ids =
|
||||
Map.values(u1) ++ Map.values(u2) ++ Map.values(u4) ++ Map.values(activities) ++ [u3[:r1]]
|
||||
|
||||
assert Enum.all?(visible_ids, &(&1 in activities_ids))
|
||||
end
|
||||
|
||||
test "public timeline with reply_visibility `self`", %{
|
||||
users: %{u1: user},
|
||||
u1: u1,
|
||||
u2: u2,
|
||||
u3: u3,
|
||||
u4: u4,
|
||||
activities: activities
|
||||
} do
|
||||
activities_ids =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("local_only", false)
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("reply_visibility", "self")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 10
|
||||
visible_ids = Map.values(u1) ++ [u2[:r1], u3[:r1], u4[:r1]] ++ Map.values(activities)
|
||||
assert Enum.all?(visible_ids, &(&1 in activities_ids))
|
||||
end
|
||||
|
||||
test "home timeline", %{
|
||||
users: %{u1: user},
|
||||
activities: activities,
|
||||
u1: u1,
|
||||
u2: u2,
|
||||
u3: u3,
|
||||
u4: u4
|
||||
} do
|
||||
params =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|
||||
activities_ids =
|
||||
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 13
|
||||
|
||||
visible_ids =
|
||||
Map.values(u1) ++
|
||||
Map.values(u3) ++
|
||||
[
|
||||
activities[:a1],
|
||||
activities[:a2],
|
||||
activities[:a4],
|
||||
u2[:r1],
|
||||
u2[:r3],
|
||||
u4[:r1],
|
||||
u4[:r2]
|
||||
]
|
||||
|
||||
assert Enum.all?(visible_ids, &(&1 in activities_ids))
|
||||
end
|
||||
|
||||
test "home timeline with reply_visibility `following`", %{
|
||||
users: %{u1: user},
|
||||
activities: activities,
|
||||
u1: u1,
|
||||
u2: u2,
|
||||
u3: u3,
|
||||
u4: u4
|
||||
} do
|
||||
params =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> Map.put("reply_visibility", "following")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|
||||
activities_ids =
|
||||
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 11
|
||||
|
||||
visible_ids =
|
||||
Map.values(u1) ++
|
||||
[
|
||||
activities[:a1],
|
||||
activities[:a2],
|
||||
activities[:a4],
|
||||
u2[:r1],
|
||||
u2[:r3],
|
||||
u3[:r1],
|
||||
u4[:r1],
|
||||
u4[:r2]
|
||||
]
|
||||
|
||||
assert Enum.all?(visible_ids, &(&1 in activities_ids))
|
||||
end
|
||||
|
||||
test "home timeline with reply_visibility `self`", %{
|
||||
users: %{u1: user},
|
||||
activities: activities,
|
||||
u1: u1,
|
||||
u2: u2,
|
||||
u3: u3,
|
||||
u4: u4
|
||||
} do
|
||||
params =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> Map.put("reply_visibility", "self")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|
||||
activities_ids =
|
||||
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 9
|
||||
|
||||
visible_ids =
|
||||
Map.values(u1) ++
|
||||
[
|
||||
activities[:a1],
|
||||
activities[:a2],
|
||||
activities[:a4],
|
||||
u2[:r1],
|
||||
u3[:r1],
|
||||
u4[:r1]
|
||||
]
|
||||
|
||||
assert Enum.all?(visible_ids, &(&1 in activities_ids))
|
||||
end
|
||||
end
|
||||
|
||||
describe "replies filtering with private messages" do
|
||||
setup :private_messages
|
||||
|
||||
test "public timeline", %{users: %{u1: user}} do
|
||||
activities_ids =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("local_only", false)
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert activities_ids == []
|
||||
end
|
||||
|
||||
test "public timeline with default reply_visibility `following`", %{users: %{u1: user}} do
|
||||
activities_ids =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("local_only", false)
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("reply_visibility", "following")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert activities_ids == []
|
||||
end
|
||||
|
||||
test "public timeline with default reply_visibility `self`", %{users: %{u1: user}} do
|
||||
activities_ids =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("local_only", false)
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("reply_visibility", "self")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> ActivityPub.fetch_public_activities()
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert activities_ids == []
|
||||
end
|
||||
|
||||
test "home timeline", %{users: %{u1: user}} do
|
||||
params =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|
||||
activities_ids =
|
||||
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 12
|
||||
end
|
||||
|
||||
test "home timeline with default reply_visibility `following`", %{users: %{u1: user}} do
|
||||
params =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> Map.put("reply_visibility", "following")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|
||||
activities_ids =
|
||||
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 12
|
||||
end
|
||||
|
||||
test "home timeline with default reply_visibility `self`", %{
|
||||
users: %{u1: user},
|
||||
activities: activities,
|
||||
u1: u1,
|
||||
u2: u2,
|
||||
u3: u3,
|
||||
u4: u4
|
||||
} do
|
||||
params =
|
||||
%{}
|
||||
|> Map.put("type", ["Create", "Announce"])
|
||||
|> Map.put("blocking_user", user)
|
||||
|> Map.put("muting_user", user)
|
||||
|> Map.put("user", user)
|
||||
|> Map.put("reply_visibility", "self")
|
||||
|> Map.put("reply_filtering_user", user)
|
||||
|
||||
activities_ids =
|
||||
ActivityPub.fetch_activities([user.ap_id | User.following(user)], params)
|
||||
|> Enum.map(& &1.id)
|
||||
|
||||
assert length(activities_ids) == 10
|
||||
|
||||
visible_ids =
|
||||
Map.values(u1) ++ Map.values(u4) ++ [u2[:r1], u3[:r1]] ++ Map.values(activities)
|
||||
|
||||
assert Enum.all?(visible_ids, &(&1 in activities_ids))
|
||||
end
|
||||
end
|
||||
|
||||
defp public_messages(_) do
|
||||
[u1, u2, u3, u4] = insert_list(4, :user)
|
||||
{:ok, u1} = User.follow(u1, u2)
|
||||
{:ok, u2} = User.follow(u2, u1)
|
||||
{:ok, u1} = User.follow(u1, u4)
|
||||
{:ok, u4} = User.follow(u4, u1)
|
||||
|
||||
{:ok, u2} = User.follow(u2, u3)
|
||||
{:ok, u3} = User.follow(u3, u2)
|
||||
|
||||
{:ok, a1} = CommonAPI.post(u1, %{"status" => "Status"})
|
||||
|
||||
{:ok, r1_1} =
|
||||
CommonAPI.post(u2, %{
|
||||
"status" => "@#{u1.nickname} reply from u2 to u1",
|
||||
"in_reply_to_status_id" => a1.id
|
||||
})
|
||||
|
||||
{:ok, r1_2} =
|
||||
CommonAPI.post(u3, %{
|
||||
"status" => "@#{u1.nickname} reply from u3 to u1",
|
||||
"in_reply_to_status_id" => a1.id
|
||||
})
|
||||
|
||||
{:ok, r1_3} =
|
||||
CommonAPI.post(u4, %{
|
||||
"status" => "@#{u1.nickname} reply from u4 to u1",
|
||||
"in_reply_to_status_id" => a1.id
|
||||
})
|
||||
|
||||
{:ok, a2} = CommonAPI.post(u2, %{"status" => "Status"})
|
||||
|
||||
{:ok, r2_1} =
|
||||
CommonAPI.post(u1, %{
|
||||
"status" => "@#{u2.nickname} reply from u1 to u2",
|
||||
"in_reply_to_status_id" => a2.id
|
||||
})
|
||||
|
||||
{:ok, r2_2} =
|
||||
CommonAPI.post(u3, %{
|
||||
"status" => "@#{u2.nickname} reply from u3 to u2",
|
||||
"in_reply_to_status_id" => a2.id
|
||||
})
|
||||
|
||||
{:ok, r2_3} =
|
||||
CommonAPI.post(u4, %{
|
||||
"status" => "@#{u2.nickname} reply from u4 to u2",
|
||||
"in_reply_to_status_id" => a2.id
|
||||
})
|
||||
|
||||
{:ok, a3} = CommonAPI.post(u3, %{"status" => "Status"})
|
||||
|
||||
{:ok, r3_1} =
|
||||
CommonAPI.post(u1, %{
|
||||
"status" => "@#{u3.nickname} reply from u1 to u3",
|
||||
"in_reply_to_status_id" => a3.id
|
||||
})
|
||||
|
||||
{:ok, r3_2} =
|
||||
CommonAPI.post(u2, %{
|
||||
"status" => "@#{u3.nickname} reply from u2 to u3",
|
||||
"in_reply_to_status_id" => a3.id
|
||||
})
|
||||
|
||||
{:ok, r3_3} =
|
||||
CommonAPI.post(u4, %{
|
||||
"status" => "@#{u3.nickname} reply from u4 to u3",
|
||||
"in_reply_to_status_id" => a3.id
|
||||
})
|
||||
|
||||
{:ok, a4} = CommonAPI.post(u4, %{"status" => "Status"})
|
||||
|
||||
{:ok, r4_1} =
|
||||
CommonAPI.post(u1, %{
|
||||
"status" => "@#{u4.nickname} reply from u1 to u4",
|
||||
"in_reply_to_status_id" => a4.id
|
||||
})
|
||||
|
||||
{:ok, r4_2} =
|
||||
CommonAPI.post(u2, %{
|
||||
"status" => "@#{u4.nickname} reply from u2 to u4",
|
||||
"in_reply_to_status_id" => a4.id
|
||||
})
|
||||
|
||||
{:ok, r4_3} =
|
||||
CommonAPI.post(u3, %{
|
||||
"status" => "@#{u4.nickname} reply from u3 to u4",
|
||||
"in_reply_to_status_id" => a4.id
|
||||
})
|
||||
|
||||
{:ok,
|
||||
users: %{u1: u1, u2: u2, u3: u3, u4: u4},
|
||||
activities: %{a1: a1.id, a2: a2.id, a3: a3.id, a4: a4.id},
|
||||
u1: %{r1: r1_1.id, r2: r1_2.id, r3: r1_3.id},
|
||||
u2: %{r1: r2_1.id, r2: r2_2.id, r3: r2_3.id},
|
||||
u3: %{r1: r3_1.id, r2: r3_2.id, r3: r3_3.id},
|
||||
u4: %{r1: r4_1.id, r2: r4_2.id, r3: r4_3.id}}
|
||||
end
|
||||
|
||||
defp private_messages(_) do
|
||||
[u1, u2, u3, u4] = insert_list(4, :user)
|
||||
{:ok, u1} = User.follow(u1, u2)
|
||||
{:ok, u2} = User.follow(u2, u1)
|
||||
{:ok, u1} = User.follow(u1, u3)
|
||||
{:ok, u3} = User.follow(u3, u1)
|
||||
{:ok, u1} = User.follow(u1, u4)
|
||||
{:ok, u4} = User.follow(u4, u1)
|
||||
|
||||
{:ok, u2} = User.follow(u2, u3)
|
||||
{:ok, u3} = User.follow(u3, u2)
|
||||
|
||||
{:ok, a1} = CommonAPI.post(u1, %{"status" => "Status", "visibility" => "private"})
|
||||
|
||||
{:ok, r1_1} =
|
||||
CommonAPI.post(u2, %{
|
||||
"status" => "@#{u1.nickname} reply from u2 to u1",
|
||||
"in_reply_to_status_id" => a1.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, r1_2} =
|
||||
CommonAPI.post(u3, %{
|
||||
"status" => "@#{u1.nickname} reply from u3 to u1",
|
||||
"in_reply_to_status_id" => a1.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, r1_3} =
|
||||
CommonAPI.post(u4, %{
|
||||
"status" => "@#{u1.nickname} reply from u4 to u1",
|
||||
"in_reply_to_status_id" => a1.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, a2} = CommonAPI.post(u2, %{"status" => "Status", "visibility" => "private"})
|
||||
|
||||
{:ok, r2_1} =
|
||||
CommonAPI.post(u1, %{
|
||||
"status" => "@#{u2.nickname} reply from u1 to u2",
|
||||
"in_reply_to_status_id" => a2.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, r2_2} =
|
||||
CommonAPI.post(u3, %{
|
||||
"status" => "@#{u2.nickname} reply from u3 to u2",
|
||||
"in_reply_to_status_id" => a2.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, a3} = CommonAPI.post(u3, %{"status" => "Status", "visibility" => "private"})
|
||||
|
||||
{:ok, r3_1} =
|
||||
CommonAPI.post(u1, %{
|
||||
"status" => "@#{u3.nickname} reply from u1 to u3",
|
||||
"in_reply_to_status_id" => a3.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, r3_2} =
|
||||
CommonAPI.post(u2, %{
|
||||
"status" => "@#{u3.nickname} reply from u2 to u3",
|
||||
"in_reply_to_status_id" => a3.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok, a4} = CommonAPI.post(u4, %{"status" => "Status", "visibility" => "private"})
|
||||
|
||||
{:ok, r4_1} =
|
||||
CommonAPI.post(u1, %{
|
||||
"status" => "@#{u4.nickname} reply from u1 to u4",
|
||||
"in_reply_to_status_id" => a4.id,
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
{:ok,
|
||||
users: %{u1: u1, u2: u2, u3: u3, u4: u4},
|
||||
activities: %{a1: a1.id, a2: a2.id, a3: a3.id, a4: a4.id},
|
||||
u1: %{r1: r1_1.id, r2: r1_2.id, r3: r1_3.id},
|
||||
u2: %{r1: r2_1.id, r2: r2_2.id},
|
||||
u3: %{r1: r3_1.id, r2: r3_2.id},
|
||||
u4: %{r1: r4_1.id}}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,26 +20,38 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
defp get_old_message do
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
end
|
||||
|
||||
defp get_new_message do
|
||||
old_message = get_old_message()
|
||||
|
||||
new_object =
|
||||
old_message
|
||||
|> Map.get("object")
|
||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
||||
|
||||
old_message
|
||||
|> Map.put("object", new_object)
|
||||
end
|
||||
|
||||
describe "with reject action" do
|
||||
test "it rejects an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
data = get_old_message()
|
||||
|
||||
{:reject, _} = ObjectAgePolicy.filter(data)
|
||||
assert match?({:reject, _}, ObjectAgePolicy.filter(data))
|
||||
end
|
||||
|
||||
test "it allows a new post" do
|
||||
Config.put([:mrf_object_age, :actions], [:reject])
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
||||
data = get_new_message()
|
||||
|
||||
{:ok, _} = ObjectAgePolicy.filter(data)
|
||||
assert match?({:ok, _}, ObjectAgePolicy.filter(data))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -47,9 +59,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
test "it delists an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
data = get_old_message()
|
||||
|
||||
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||
|
||||
|
|
@ -61,14 +71,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
test "it allows a new post" do
|
||||
Config.put([:mrf_object_age, :actions], [:delist])
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
||||
data = get_new_message()
|
||||
|
||||
{:ok, _user} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||
|
||||
{:ok, ^data} = ObjectAgePolicy.filter(data)
|
||||
assert match?({:ok, ^data}, ObjectAgePolicy.filter(data))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -76,9 +83,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
test "it strips followers collections from an old post" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
data = get_old_message()
|
||||
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||
|
||||
|
|
@ -91,14 +96,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.ObjectAgePolicyTest do
|
|||
test "it allows a new post" do
|
||||
Config.put([:mrf_object_age, :actions], [:strip_followers])
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-post-activity.json")
|
||||
|> Poison.decode!()
|
||||
|> Map.put("published", DateTime.utc_now() |> DateTime.to_iso8601())
|
||||
data = get_new_message()
|
||||
|
||||
{:ok, _u} = User.get_or_fetch_by_ap_id(data["actor"])
|
||||
|
||||
{:ok, ^data} = ObjectAgePolicy.filter(data)
|
||||
assert match?({:ok, ^data}, ObjectAgePolicy.filter(data))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
reject: [],
|
||||
accept: [],
|
||||
avatar_removal: [],
|
||||
banner_removal: []
|
||||
banner_removal: [],
|
||||
reject_deletes: []
|
||||
)
|
||||
|
||||
describe "when :media_removal" do
|
||||
|
|
@ -382,6 +383,66 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "when :reject_deletes is empty" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], [])
|
||||
|
||||
test "it accepts deletions even from rejected servers" do
|
||||
Config.put([:mrf_simple, :reject], ["remote.instance"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
assert SimplePolicy.filter(deletion_message) == {:ok, deletion_message}
|
||||
end
|
||||
|
||||
test "it accepts deletions even from non-whitelisted servers" do
|
||||
Config.put([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
assert SimplePolicy.filter(deletion_message) == {:ok, deletion_message}
|
||||
end
|
||||
end
|
||||
|
||||
describe "when :reject_deletes is not empty but it doesn't have a matching host" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], ["non.matching.remote"])
|
||||
|
||||
test "it accepts deletions even from rejected servers" do
|
||||
Config.put([:mrf_simple, :reject], ["remote.instance"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
assert SimplePolicy.filter(deletion_message) == {:ok, deletion_message}
|
||||
end
|
||||
|
||||
test "it accepts deletions even from non-whitelisted servers" do
|
||||
Config.put([:mrf_simple, :accept], ["non.matching.remote"])
|
||||
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
assert SimplePolicy.filter(deletion_message) == {:ok, deletion_message}
|
||||
end
|
||||
end
|
||||
|
||||
describe "when :reject_deletes has a matching host" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], ["remote.instance"])
|
||||
|
||||
test "it rejects the deletion" do
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
assert SimplePolicy.filter(deletion_message) == {:reject, nil}
|
||||
end
|
||||
end
|
||||
|
||||
describe "when :reject_deletes match with wildcard domain" do
|
||||
setup do: Config.put([:mrf_simple, :reject_deletes], ["*.remote.instance"])
|
||||
|
||||
test "it rejects the deletion" do
|
||||
deletion_message = build_remote_deletion_message()
|
||||
|
||||
assert SimplePolicy.filter(deletion_message) == {:reject, nil}
|
||||
end
|
||||
end
|
||||
|
||||
defp build_local_message do
|
||||
%{
|
||||
"actor" => "#{Pleroma.Web.base_url()}/users/alice",
|
||||
|
|
@ -408,4 +469,11 @@ defmodule Pleroma.Web.ActivityPub.MRF.SimplePolicyTest do
|
|||
"type" => "Person"
|
||||
}
|
||||
end
|
||||
|
||||
defp build_remote_deletion_message do
|
||||
%{
|
||||
"type" => "Delete",
|
||||
"actor" => "https://remote.instance/users/bob"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -48,10 +48,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
describe "determine_inbox/2" do
|
||||
test "it returns sharedInbox for messages involving as:Public in to" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
user = insert(:user, %{shared_inbox: "http://example.com/inbox"})
|
||||
|
||||
activity = %Activity{
|
||||
data: %{"to" => [@as_public], "cc" => [user.follower_address]}
|
||||
|
|
@ -61,10 +58,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
test "it returns sharedInbox for messages involving as:Public in cc" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
user = insert(:user, %{shared_inbox: "http://example.com/inbox"})
|
||||
|
||||
activity = %Activity{
|
||||
data: %{"cc" => [@as_public], "to" => [user.follower_address]}
|
||||
|
|
@ -74,11 +68,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
test "it returns sharedInbox for messages involving multiple recipients in to" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
|
||||
user = insert(:user, %{shared_inbox: "http://example.com/inbox"})
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
|
|
@ -90,11 +80,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
end
|
||||
|
||||
test "it returns sharedInbox for messages involving multiple recipients in cc" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}
|
||||
})
|
||||
|
||||
user = insert(:user, %{shared_inbox: "http://example.com/inbox"})
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
|
|
@ -107,12 +93,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
test "it returns sharedInbox for messages involving multiple recipients in total" do
|
||||
user =
|
||||
insert(:user,
|
||||
source_data: %{
|
||||
"inbox" => "http://example.com/personal-inbox",
|
||||
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
|
||||
}
|
||||
)
|
||||
insert(:user, %{
|
||||
shared_inbox: "http://example.com/inbox",
|
||||
inbox: "http://example.com/personal-inbox"
|
||||
})
|
||||
|
||||
user_two = insert(:user)
|
||||
|
||||
|
|
@ -125,12 +109,10 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
|
||||
test "it returns inbox for messages involving single recipients in total" do
|
||||
user =
|
||||
insert(:user,
|
||||
source_data: %{
|
||||
"inbox" => "http://example.com/personal-inbox",
|
||||
"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
|
||||
}
|
||||
)
|
||||
insert(:user, %{
|
||||
shared_inbox: "http://example.com/inbox",
|
||||
inbox: "http://example.com/personal-inbox"
|
||||
})
|
||||
|
||||
activity = %Activity{
|
||||
data: %{"to" => [user.ap_id], "cc" => []}
|
||||
|
|
@ -258,11 +240,11 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
[:passthrough],
|
||||
[] do
|
||||
follower =
|
||||
insert(:user,
|
||||
insert(:user, %{
|
||||
local: false,
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"},
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
ap_enabled: true
|
||||
)
|
||||
})
|
||||
|
||||
actor = insert(:user, follower_address: follower.ap_id)
|
||||
user = insert(:user)
|
||||
|
|
@ -295,14 +277,14 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
|
|||
fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
source_data: %{"inbox" => "https://domain.com/users/nick1/inbox"},
|
||||
inbox: "https://domain.com/users/nick1/inbox",
|
||||
ap_enabled: true
|
||||
)
|
||||
|
||||
another_fetcher =
|
||||
insert(:user,
|
||||
local: false,
|
||||
source_data: %{"inbox" => "https://domain2.com/users/nick1/inbox"},
|
||||
inbox: "https://domain2.com/users/nick1/inbox",
|
||||
ap_enabled: true
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.SideEffects
|
||||
|
|
@ -15,13 +17,14 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
|
||||
describe "like objects" do
|
||||
setup do
|
||||
poster = insert(:user)
|
||||
user = insert(:user)
|
||||
{:ok, post} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
{:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})
|
||||
|
||||
{:ok, like_data, _meta} = Builder.like(user, post.object)
|
||||
{:ok, like, _meta} = ActivityPub.persist(like_data, local: true)
|
||||
|
||||
%{like: like, user: user}
|
||||
%{like: like, user: user, poster: poster}
|
||||
end
|
||||
|
||||
test "add the like to the original object", %{like: like, user: user} do
|
||||
|
|
@ -30,5 +33,10 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
assert object.data["like_count"] == 1
|
||||
assert user.ap_id in object.data["likes"]
|
||||
end
|
||||
|
||||
test "creates a notification", %{like: like, poster: poster} do
|
||||
{:ok, like, _} = SideEffects.handle(like)
|
||||
assert Repo.get_by(Notification, user_id: poster.id, activity_id: like.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -746,7 +746,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(activity.actor)
|
||||
|
||||
assert User.fields(user) == [
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "foo1", "value" => "bar1"}
|
||||
]
|
||||
|
|
@ -767,7 +767,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.fields(user) == [
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
|
@ -785,7 +785,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.fields(user) == [
|
||||
assert user.fields == [
|
||||
%{"name" => "foo", "value" => "updated"},
|
||||
%{"name" => "foo1", "value" => "updated"}
|
||||
]
|
||||
|
|
@ -796,7 +796,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert User.fields(user) == []
|
||||
assert user.fields == []
|
||||
end
|
||||
|
||||
test "it works for incoming update activities which lock the account" do
|
||||
|
|
@ -2162,4 +2162,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
Transmogrifier.set_replies(object.data)["replies"]
|
||||
end
|
||||
end
|
||||
|
||||
test "take_emoji_tags/1" do
|
||||
user = insert(:user, %{emoji: %{"firefox" => "https://example.org/firefox.png"}})
|
||||
|
||||
assert Transmogrifier.take_emoji_tags(user) == [
|
||||
%{
|
||||
"icon" => %{"type" => "Image", "url" => "https://example.org/firefox.png"},
|
||||
"id" => "https://example.org/firefox.png",
|
||||
"name" => ":firefox:",
|
||||
"type" => "Emoji",
|
||||
"updated" => "1970-01-01T00:00:00Z"
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -224,8 +224,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
object = Object.normalize(activity)
|
||||
{:ok, [vote], object} = CommonAPI.vote(other_user, object, [0])
|
||||
vote_object = Object.normalize(vote)
|
||||
{:ok, _activity, _object} = ActivityPub.like(user, vote_object)
|
||||
{:ok, _activity} = CommonAPI.favorite(user, activity.id)
|
||||
[fetched_vote] = Utils.get_existing_votes(other_user.ap_id, object)
|
||||
assert fetched_vote.id == vote.id
|
||||
end
|
||||
|
|
@ -346,7 +345,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
|
|||
|
||||
user = insert(:user)
|
||||
refute Utils.get_existing_like(user.ap_id, object)
|
||||
{:ok, like_activity, _object} = ActivityPub.like(user, object)
|
||||
{:ok, like_activity} = CommonAPI.favorite(user, note_activity.id)
|
||||
|
||||
assert ^like_activity = Utils.get_existing_like(user.ap_id, object)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
|
||||
{:ok, user} =
|
||||
insert(:user)
|
||||
|> User.upgrade_changeset(%{fields: fields})
|
||||
|> User.update_changeset(%{fields: fields})
|
||||
|> User.update_and_set_cache()
|
||||
|
||||
assert %{
|
||||
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest do
|
|||
end
|
||||
|
||||
test "Renders with emoji tags" do
|
||||
user = insert(:user, emoji: [%{"bib" => "/test"}])
|
||||
user = insert(:user, emoji: %{"bib" => "/test"})
|
||||
|
||||
assert %{
|
||||
"tag" => [
|
||||
|
|
|
|||
|
|
@ -2110,7 +2110,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> get("/api/pleroma/admin/config")
|
||||
|> json_response(200)
|
||||
|
||||
refute Map.has_key?(configs, "need_reboot")
|
||||
assert configs["need_reboot"] == false
|
||||
end
|
||||
|
||||
test "update setting which need reboot, don't change reboot flag until reboot", %{conn: conn} do
|
||||
|
|
@ -2166,7 +2166,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
|> get("/api/pleroma/admin/config")
|
||||
|> json_response(200)
|
||||
|
||||
refute Map.has_key?(configs, "need_reboot")
|
||||
assert configs["need_reboot"] == false
|
||||
end
|
||||
|
||||
test "saving config with nested merge", %{conn: conn} do
|
||||
|
|
@ -2861,6 +2861,20 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "need_reboot flag", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/api/pleroma/admin/need_reboot")
|
||||
|> json_response(200) == %{"need_reboot" => false}
|
||||
|
||||
Restarter.Pleroma.need_reboot()
|
||||
|
||||
assert conn
|
||||
|> get("/api/pleroma/admin/need_reboot")
|
||||
|> json_response(200) == %{"need_reboot" => true}
|
||||
|
||||
on_exit(fn -> Restarter.Pleroma.refresh() end)
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/statuses" do
|
||||
test "returns all public and unlisted statuses", %{conn: conn, admin: admin} do
|
||||
blocked = insert(:user)
|
||||
|
|
@ -3503,6 +3517,191 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
response["status_visibility"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/admin/oauth_app" do
|
||||
test "errors", %{conn: conn} do
|
||||
response = conn |> post("/api/pleroma/admin/oauth_app", %{}) |> json_response(200)
|
||||
|
||||
assert response == %{"name" => "can't be blank", "redirect_uris" => "can't be blank"}
|
||||
end
|
||||
|
||||
test "success", %{conn: conn} do
|
||||
base_url = Pleroma.Web.base_url()
|
||||
app_name = "Trusted app"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/api/pleroma/admin/oauth_app", %{
|
||||
name: app_name,
|
||||
redirect_uris: base_url
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{
|
||||
"client_id" => _,
|
||||
"client_secret" => _,
|
||||
"name" => ^app_name,
|
||||
"redirect_uri" => ^base_url,
|
||||
"trusted" => false
|
||||
} = response
|
||||
end
|
||||
|
||||
test "with trusted", %{conn: conn} do
|
||||
base_url = Pleroma.Web.base_url()
|
||||
app_name = "Trusted app"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/api/pleroma/admin/oauth_app", %{
|
||||
name: app_name,
|
||||
redirect_uris: base_url,
|
||||
trusted: true
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{
|
||||
"client_id" => _,
|
||||
"client_secret" => _,
|
||||
"name" => ^app_name,
|
||||
"redirect_uri" => ^base_url,
|
||||
"trusted" => true
|
||||
} = response
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/oauth_app" do
|
||||
setup do
|
||||
app = insert(:oauth_app)
|
||||
{:ok, app: app}
|
||||
end
|
||||
|
||||
test "list", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/oauth_app")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"apps" => apps, "count" => count, "page_size" => _} = response
|
||||
|
||||
assert length(apps) == count
|
||||
end
|
||||
|
||||
test "with page size", %{conn: conn} do
|
||||
insert(:oauth_app)
|
||||
page_size = 1
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/oauth_app", %{page_size: to_string(page_size)})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"apps" => apps, "count" => _, "page_size" => ^page_size} = response
|
||||
|
||||
assert length(apps) == page_size
|
||||
end
|
||||
|
||||
test "search by client name", %{conn: conn, app: app} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/oauth_app", %{name: app.client_name})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"apps" => [returned], "count" => _, "page_size" => _} = response
|
||||
|
||||
assert returned["client_id"] == app.client_id
|
||||
assert returned["name"] == app.client_name
|
||||
end
|
||||
|
||||
test "search by client id", %{conn: conn, app: app} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/oauth_app", %{client_id: app.client_id})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"apps" => [returned], "count" => _, "page_size" => _} = response
|
||||
|
||||
assert returned["client_id"] == app.client_id
|
||||
assert returned["name"] == app.client_name
|
||||
end
|
||||
|
||||
test "only trusted", %{conn: conn} do
|
||||
app = insert(:oauth_app, trusted: true)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/pleroma/admin/oauth_app", %{trusted: true})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"apps" => [returned], "count" => _, "page_size" => _} = response
|
||||
|
||||
assert returned["client_id"] == app.client_id
|
||||
assert returned["name"] == app.client_name
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /api/pleroma/admin/oauth_app/:id" do
|
||||
test "with id", %{conn: conn} do
|
||||
app = insert(:oauth_app)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> delete("/api/pleroma/admin/oauth_app/" <> to_string(app.id))
|
||||
|> json_response(:no_content)
|
||||
|
||||
assert response == ""
|
||||
end
|
||||
|
||||
test "with non existance id", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> delete("/api/pleroma/admin/oauth_app/0")
|
||||
|> json_response(:bad_request)
|
||||
|
||||
assert response == ""
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /api/pleroma/admin/oauth_app/:id" do
|
||||
test "with id", %{conn: conn} do
|
||||
app = insert(:oauth_app)
|
||||
|
||||
name = "another name"
|
||||
url = "https://example.com"
|
||||
scopes = ["admin"]
|
||||
id = app.id
|
||||
website = "http://website.com"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> patch("/api/pleroma/admin/oauth_app/" <> to_string(app.id), %{
|
||||
name: name,
|
||||
trusted: true,
|
||||
redirect_uris: url,
|
||||
scopes: scopes,
|
||||
website: website
|
||||
})
|
||||
|> json_response(200)
|
||||
|
||||
assert %{
|
||||
"client_id" => _,
|
||||
"client_secret" => _,
|
||||
"id" => ^id,
|
||||
"name" => ^name,
|
||||
"redirect_uri" => ^url,
|
||||
"trusted" => true,
|
||||
"website" => ^website
|
||||
} = response
|
||||
end
|
||||
|
||||
test "without id", %{conn: conn} do
|
||||
response =
|
||||
conn
|
||||
|> patch("/api/pleroma/admin/oauth_app/0")
|
||||
|> json_response(:bad_request)
|
||||
|
||||
assert response == ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Needed for testing
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.AppOperationTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
alias Pleroma.Web.ApiSpec
|
||||
alias Pleroma.Web.ApiSpec.Schemas.AppCreateRequest
|
||||
alias Pleroma.Web.ApiSpec.Schemas.AppCreateResponse
|
||||
|
||||
import OpenApiSpex.TestAssertions
|
||||
import Pleroma.Factory
|
||||
|
||||
test "AppCreateRequest example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = AppCreateRequest.schema()
|
||||
assert_schema(schema.example, "AppCreateRequest", api_spec)
|
||||
end
|
||||
|
||||
test "AppCreateResponse example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = AppCreateResponse.schema()
|
||||
assert_schema(schema.example, "AppCreateResponse", api_spec)
|
||||
end
|
||||
|
||||
test "AppController produces a AppCreateResponse", %{conn: conn} do
|
||||
api_spec = ApiSpec.spec()
|
||||
app_attrs = build(:oauth_app)
|
||||
|
||||
json =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post(
|
||||
"/api/v1/apps",
|
||||
Jason.encode!(%{
|
||||
client_name: app_attrs.client_name,
|
||||
redirect_uris: app_attrs.redirect_uris
|
||||
})
|
||||
)
|
||||
|> json_response(200)
|
||||
|
||||
assert_schema(json, "AppCreateResponse", api_spec)
|
||||
end
|
||||
end
|
||||
43
test/web/api_spec/schema_examples_test.exs
Normal file
43
test/web/api_spec/schema_examples_test.exs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.SchemaExamplesTest do
|
||||
use ExUnit.Case, async: true
|
||||
import Pleroma.Tests.ApiSpecHelpers
|
||||
|
||||
@content_type "application/json"
|
||||
|
||||
for operation <- api_operations() do
|
||||
describe operation.operationId <> " Request Body" do
|
||||
if operation.requestBody do
|
||||
@media_type operation.requestBody.content[@content_type]
|
||||
@schema resolve_schema(@media_type.schema)
|
||||
|
||||
if @media_type.example do
|
||||
test "request body media type example matches schema" do
|
||||
assert_schema(@media_type.example, @schema)
|
||||
end
|
||||
end
|
||||
|
||||
if @schema.example do
|
||||
test "request body schema example matches schema" do
|
||||
assert_schema(@schema.example, @schema)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for {status, response} <- operation.responses do
|
||||
describe "#{operation.operationId} - #{status} Response" do
|
||||
@schema resolve_schema(response.content[@content_type].schema)
|
||||
|
||||
if @schema.example do
|
||||
test "example matches schema" do
|
||||
assert_schema(@schema.example, @schema)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
242
test/web/auth/auth_test_controller_test.exs
Normal file
242
test/web/auth/auth_test_controller_test.exs
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Tests.AuthTestControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "do_oauth_check" do
|
||||
test "serves with proper OAuth token (fulfilling requested scopes)" do
|
||||
%{conn: good_token_conn, user: user} = oauth_access(["read"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/do_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
# Unintended usage (:api) — use with :authenticated_api instead
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/api/do_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "fails on no token / missing scope(s)" do
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/do_oauth_check")
|
||||
|> json_response(403)
|
||||
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/do_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fallback_oauth_check" do
|
||||
test "serves with proper OAuth token (fulfilling requested scopes)" do
|
||||
%{conn: good_token_conn, user: user} = oauth_access(["read"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
# Unintended usage (:authenticated_api) — use with :api instead
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api on public instance, drops :user and renders on no token / missing scope(s)" do
|
||||
clear_config([:instance, :public], true)
|
||||
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api on private instance, fails on no token / missing scope(s)" do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
bad_token_conn
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(403)
|
||||
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/fallback_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "skip_oauth_check" do
|
||||
test "for :authenticated_api, serves if :user is set (regardless of token / token scopes)" do
|
||||
user = insert(:user)
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
%{conn: bad_token_conn, user: user} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "serves via :api on public instance if :user is not set" do
|
||||
clear_config([:instance, :public], true)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
build_conn()
|
||||
|> get("/test/api/skip_oauth_check")
|
||||
|> json_response(200)
|
||||
|
||||
build_conn()
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "fails on private instance if :user is not set" do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
build_conn()
|
||||
|> get("/test/api/skip_oauth_check")
|
||||
|> json_response(403)
|
||||
|
||||
build_conn()
|
||||
|> get("/test/authenticated_api/skip_oauth_check")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fallback_oauth_skip_publicity_check" do
|
||||
test "serves with proper OAuth token (fulfilling requested scopes)" do
|
||||
%{conn: good_token_conn, user: user} = oauth_access(["read"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
# Unintended usage (:authenticated_api)
|
||||
assert %{"user_id" => user.id} ==
|
||||
good_token_conn
|
||||
|> get("/test/authenticated_api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api on private / public instance, drops :user and renders on token issue" do
|
||||
%{conn: bad_token_conn} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
for is_public <- [true, false] do
|
||||
clear_config([:instance, :public], is_public)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> get("/test/api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
bad_token_conn
|
||||
|> assign(:token, nil)
|
||||
|> get("/test/api/fallback_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "skip_oauth_skip_publicity_check" do
|
||||
test "for :authenticated_api, serves if :user is set (regardless of token / token scopes)" do
|
||||
user = insert(:user)
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/test/authenticated_api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
%{conn: bad_token_conn, user: user} = oauth_access(["irrelevant_scope"])
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
bad_token_conn
|
||||
|> get("/test/authenticated_api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "for :api, serves on private and public instances regardless of whether :user is set" do
|
||||
user = insert(:user)
|
||||
|
||||
for is_public <- [true, false] do
|
||||
clear_config([:instance, :public], is_public)
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
build_conn()
|
||||
|> get("/test/api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
|
||||
assert %{"user_id" => user.id} ==
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|> get("/test/api/skip_oauth_skip_publicity_check")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "missing_oauth_check_definition" do
|
||||
def test_missing_oauth_check_definition_failure(endpoint, expected_error) do
|
||||
%{conn: conn} = oauth_access(["read", "write", "follow", "push", "admin"])
|
||||
|
||||
assert %{"error" => expected_error} ==
|
||||
conn
|
||||
|> get(endpoint)
|
||||
|> json_response(403)
|
||||
end
|
||||
|
||||
test "fails if served via :authenticated_api" do
|
||||
test_missing_oauth_check_definition_failure(
|
||||
"/test/authenticated_api/missing_oauth_check_definition",
|
||||
"Security violation: OAuth scopes check was neither handled nor explicitly skipped."
|
||||
)
|
||||
end
|
||||
|
||||
test "fails if served via :api and the instance is private" do
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
test_missing_oauth_check_definition_failure(
|
||||
"/test/api/missing_oauth_check_definition",
|
||||
"This resource requires authentication."
|
||||
)
|
||||
end
|
||||
|
||||
test "succeeds with dropped :user if served via :api on public instance" do
|
||||
%{conn: conn} = oauth_access(["read", "write", "follow", "push", "admin"])
|
||||
|
||||
assert %{"user_id" => nil} ==
|
||||
conn
|
||||
|> get("/test/api/missing_oauth_check_definition")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
46
test/web/auth/basic_auth_test.exs
Normal file
46
test/web/auth/basic_auth_test.exs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Auth.BasicAuthTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "with HTTP Basic Auth used, grants access to OAuth scope-restricted endpoints", %{
|
||||
conn: conn
|
||||
} do
|
||||
user = insert(:user)
|
||||
assert Comeonin.Pbkdf2.checkpw("test", user.password_hash)
|
||||
|
||||
basic_auth_contents =
|
||||
(URI.encode_www_form(user.nickname) <> ":" <> URI.encode_www_form("test"))
|
||||
|> Base.encode64()
|
||||
|
||||
# Succeeds with HTTP Basic Auth
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("authorization", "Basic " <> basic_auth_contents)
|
||||
|> get("/api/v1/accounts/verify_credentials")
|
||||
|> json_response(200)
|
||||
|
||||
user_nickname = user.nickname
|
||||
assert %{"username" => ^user_nickname} = response
|
||||
|
||||
# Succeeds with a properly scoped OAuth token
|
||||
valid_token = insert(:oauth_token, scopes: ["read:accounts"])
|
||||
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{valid_token.token}")
|
||||
|> get("/api/v1/accounts/verify_credentials")
|
||||
|> json_response(200)
|
||||
|
||||
# Fails with a wrong-scoped OAuth token (proof of restriction)
|
||||
invalid_token = insert(:oauth_token, scopes: ["read:something"])
|
||||
|
||||
conn
|
||||
|> put_req_header("authorization", "Bearer #{invalid_token.token}")
|
||||
|> get("/api/v1/accounts/verify_credentials")
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
|
@ -21,6 +21,60 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
test "favoriting race condition" do
|
||||
user = insert(:user)
|
||||
users_serial = insert_list(10, :user)
|
||||
users = insert_list(10, :user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "."})
|
||||
|
||||
users_serial
|
||||
|> Enum.map(fn user ->
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
end)
|
||||
|
||||
object = Object.get_by_ap_id(activity.data["object"])
|
||||
assert object.data["like_count"] == 10
|
||||
|
||||
users
|
||||
|> Enum.map(fn user ->
|
||||
Task.async(fn ->
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
end)
|
||||
end)
|
||||
|> Enum.map(&Task.await/1)
|
||||
|
||||
object = Object.get_by_ap_id(activity.data["object"])
|
||||
assert object.data["like_count"] == 20
|
||||
end
|
||||
|
||||
test "repeating race condition" do
|
||||
user = insert(:user)
|
||||
users_serial = insert_list(10, :user)
|
||||
users = insert_list(10, :user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "."})
|
||||
|
||||
users_serial
|
||||
|> Enum.map(fn user ->
|
||||
CommonAPI.repeat(activity.id, user)
|
||||
end)
|
||||
|
||||
object = Object.get_by_ap_id(activity.data["object"])
|
||||
assert object.data["announcement_count"] == 10
|
||||
|
||||
users
|
||||
|> Enum.map(fn user ->
|
||||
Task.async(fn ->
|
||||
CommonAPI.repeat(activity.id, user)
|
||||
end)
|
||||
end)
|
||||
|> Enum.map(&Task.await/1)
|
||||
|
||||
object = Object.get_by_ap_id(activity.data["object"])
|
||||
assert object.data["announcement_count"] == 20
|
||||
end
|
||||
|
||||
test "when replying to a conversation / participation, it will set the correct context id even if no explicit reply_to is given" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})
|
||||
|
|
@ -97,18 +151,6 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert Object.normalize(activity).data["emoji"]["firefox"]
|
||||
end
|
||||
|
||||
test "it adds emoji when updating profiles" do
|
||||
user = insert(:user, %{name: ":firefox:"})
|
||||
|
||||
{:ok, activity} = CommonAPI.update(user)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
[firefox] = user.source_data["tag"]
|
||||
|
||||
assert firefox["name"] == ":firefox:"
|
||||
|
||||
assert Pleroma.Constants.as_public() in activity.recipients
|
||||
end
|
||||
|
||||
describe "posting" do
|
||||
test "it supports explicit addressing" do
|
||||
user = insert(:user)
|
||||
|
|
@ -268,6 +310,16 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
{:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
|
||||
end
|
||||
|
||||
test "can't repeat a repeat" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
|
||||
{:ok, %Activity{} = announce, _} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
refute match?({:ok, %Activity{}, _}, CommonAPI.repeat(announce.id, user))
|
||||
end
|
||||
|
||||
test "repeating a status privately" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
|
@ -297,8 +349,8 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
|
||||
{:ok, %Activity{} = activity, object} = CommonAPI.repeat(activity.id, user)
|
||||
{:ok, ^activity, ^object} = CommonAPI.repeat(activity.id, user)
|
||||
{:ok, %Activity{} = announce, object} = CommonAPI.repeat(activity.id, user)
|
||||
{:ok, ^announce, ^object} = CommonAPI.repeat(activity.id, user)
|
||||
end
|
||||
|
||||
test "favoriting a status twice returns ok, but without the like activity" do
|
||||
|
|
@ -372,7 +424,9 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
user = refresh_record(user)
|
||||
|
||||
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
|
||||
id = activity.id
|
||||
|
||||
assert match?({:ok, %{id: ^id}}, CommonAPI.unpin(activity.id, user))
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.CommonAPI.Utils
|
||||
alias Pleroma.Web.Endpoint
|
||||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
|
@ -42,28 +41,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "parses emoji from name and bio" do
|
||||
{:ok, user} = UserBuilder.insert(%{name: ":blank:", bio: ":firefox:"})
|
||||
|
||||
expected = [
|
||||
%{
|
||||
"type" => "Emoji",
|
||||
"icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/emoji/Firefox.gif"},
|
||||
"name" => ":firefox:"
|
||||
},
|
||||
%{
|
||||
"type" => "Emoji",
|
||||
"icon" => %{
|
||||
"type" => "Image",
|
||||
"url" => "#{Endpoint.url()}/emoji/blank.png"
|
||||
},
|
||||
"name" => ":blank:"
|
||||
}
|
||||
]
|
||||
|
||||
assert expected == Utils.emoji_from_profile(user)
|
||||
end
|
||||
|
||||
describe "format_input/3" do
|
||||
test "works for bare text/plain" do
|
||||
text = "hello world!"
|
||||
|
|
@ -358,26 +335,6 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "get_by_id_or_ap_id/1" do
|
||||
test "get activity by id" do
|
||||
activity = insert(:note_activity)
|
||||
%Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.id)
|
||||
assert note.id == activity.id
|
||||
end
|
||||
|
||||
test "get activity by ap_id" do
|
||||
activity = insert(:note_activity)
|
||||
%Pleroma.Activity{} = note = Utils.get_by_id_or_ap_id(activity.data["object"])
|
||||
assert note.id == activity.id
|
||||
end
|
||||
|
||||
test "get activity by object when type isn't `Create` " do
|
||||
activity = insert(:like_activity)
|
||||
%Pleroma.Activity{} = like = Utils.get_by_id_or_ap_id(activity.id)
|
||||
assert like.data["object"] == activity.data["object"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "to_master_date/1" do
|
||||
test "removes microseconds from date (NaiveDateTime)" do
|
||||
assert Utils.to_masto_date(~N[2015-01-23 23:50:07.123]) == "2015-01-23T23:50:07.000Z"
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
local: false,
|
||||
nickname: "nick1@domain.com",
|
||||
ap_id: "https://domain.com/users/nick1",
|
||||
source_data: %{"inbox" => inbox1},
|
||||
inbox: inbox1,
|
||||
ap_enabled: true
|
||||
})
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
local: false,
|
||||
nickname: "nick2@domain2.com",
|
||||
ap_id: "https://domain2.com/users/nick2",
|
||||
source_data: %{"inbox" => inbox2},
|
||||
inbox: inbox2,
|
||||
ap_enabled: true
|
||||
})
|
||||
|
||||
|
|
@ -130,6 +130,9 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert {:ok, _activity} = ObanHelpers.perform(job)
|
||||
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert {:error, :already_present} = ObanHelpers.perform(job)
|
||||
end
|
||||
|
||||
test "rejects incoming AP docs with incorrect origin" do
|
||||
|
|
@ -148,7 +151,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
}
|
||||
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert :error = ObanHelpers.perform(job)
|
||||
assert {:error, :origin_containment_failed} = ObanHelpers.perform(job)
|
||||
end
|
||||
|
||||
test "it does not crash if MRF rejects the post" do
|
||||
|
|
@ -164,7 +167,7 @@ defmodule Pleroma.Web.FederatorTest do
|
|||
|> Poison.decode!()
|
||||
|
||||
assert {:ok, job} = Federator.incoming_ap_doc(params)
|
||||
assert :error = ObanHelpers.perform(job)
|
||||
assert {:error, _} = ObanHelpers.perform(job)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -150,8 +150,8 @@ defmodule Pleroma.Web.Feed.TagControllerTest do
|
|||
obj2 = Object.normalize(activity2)
|
||||
|
||||
assert xpath(xml, ~x"//channel/item/description/text()"sl) == [
|
||||
HtmlEntities.decode(FeedView.activity_content(obj2)),
|
||||
HtmlEntities.decode(FeedView.activity_content(obj1))
|
||||
HtmlEntities.decode(FeedView.activity_content(obj2.data)),
|
||||
HtmlEntities.decode(FeedView.activity_content(obj1.data))
|
||||
]
|
||||
|
||||
response =
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
describe "updating credentials" do
|
||||
setup do: oauth_access(["write:accounts"])
|
||||
setup :request_content_type
|
||||
|
||||
test "sets user settings in a generic way", %{conn: conn} do
|
||||
res_conn =
|
||||
|
|
@ -25,7 +26,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
}
|
||||
})
|
||||
|
||||
assert user_data = json_response(res_conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||
assert user_data["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
|
||||
|
||||
user = Repo.get(User, user_data["id"])
|
||||
|
|
@ -41,7 +42,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
}
|
||||
})
|
||||
|
||||
assert user_data = json_response(res_conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
assert user_data["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
|
|
@ -62,7 +63,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
}
|
||||
})
|
||||
|
||||
assert user_data = json_response(res_conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(res_conn, 200)
|
||||
|
||||
assert user_data["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
|
|
@ -79,7 +80,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
"note" => "I drink #cofe with @#{user2.nickname}\n\nsuya.."
|
||||
})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert user_data["note"] ==
|
||||
~s(I drink <a class="hashtag" data-tag="cofe" href="http://localhost:4001/tag/cofe">#cofe</a> with <span class="h-card"><a class="u-url mention" data-user="#{
|
||||
|
|
@ -90,7 +91,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
test "updates the user's locking status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{locked: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["locked"] == true
|
||||
end
|
||||
|
||||
|
|
@ -100,21 +101,21 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{allow_following_move: "false"})
|
||||
|
||||
assert refresh_record(user).allow_following_move == false
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["allow_following_move"] == false
|
||||
end
|
||||
|
||||
test "updates the user's default scope", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "cofe"})
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{default_scope: "unlisted"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data["source"]["privacy"] == "cofe"
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["source"]["privacy"] == "unlisted"
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_followers: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_followers"] == true
|
||||
end
|
||||
|
||||
|
|
@ -122,12 +123,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "updates the user's hide_followers_count and hide_follows_count", %{conn: conn} do
|
||||
|
|
@ -137,7 +138,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
hide_follows_count: "true"
|
||||
})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_followers_count"] == true
|
||||
assert user_data["pleroma"]["hide_follows_count"] == true
|
||||
end
|
||||
|
|
@ -146,7 +147,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
response =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{skip_thread_containment: "true"})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert response["pleroma"]["skip_thread_containment"] == true
|
||||
assert refresh_record(user).skip_thread_containment
|
||||
|
|
@ -155,28 +156,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
test "updates the user's hide_follows status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_follows: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_follows"] == true
|
||||
end
|
||||
|
||||
test "updates the user's hide_favorites status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{hide_favorites: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["pleroma"]["hide_favorites"] == true
|
||||
end
|
||||
|
||||
test "updates the user's show_role status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{show_role: "false"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["source"]["pleroma"]["show_role"] == false
|
||||
end
|
||||
|
||||
test "updates the user's no_rich_text status", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{no_rich_text: "true"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["source"]["pleroma"]["no_rich_text"] == true
|
||||
end
|
||||
|
||||
|
|
@ -184,7 +185,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
conn =
|
||||
patch(conn, "/api/v1/accounts/update_credentials", %{"display_name" => "markorepairs"})
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
assert user_data["display_name"] == "markorepairs"
|
||||
end
|
||||
|
||||
|
|
@ -197,7 +198,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
|
||||
|
||||
assert user_response = json_response(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response["avatar"] != User.avatar_url(user)
|
||||
end
|
||||
|
||||
|
|
@ -210,7 +211,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{"header" => new_header})
|
||||
|
||||
assert user_response = json_response(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response["header"] != User.banner_url(user)
|
||||
end
|
||||
|
||||
|
|
@ -226,7 +227,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
"pleroma_background_image" => new_header
|
||||
})
|
||||
|
||||
assert user_response = json_response(conn, 200)
|
||||
assert user_response = json_response_and_validate_schema(conn, 200)
|
||||
assert user_response["pleroma"]["background_image"]
|
||||
end
|
||||
|
||||
|
|
@ -237,14 +238,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
for token <- [token1, token2] do
|
||||
conn =
|
||||
build_conn()
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put_req_header("authorization", "Bearer #{token.token}")
|
||||
|> patch("/api/v1/accounts/update_credentials", %{})
|
||||
|
||||
if token == token1 do
|
||||
assert %{"error" => "Insufficient permissions: write:accounts."} ==
|
||||
json_response(conn, 403)
|
||||
json_response_and_validate_schema(conn, 403)
|
||||
else
|
||||
assert json_response(conn, 200)
|
||||
assert json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -259,11 +261,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
"display_name" => name
|
||||
})
|
||||
|
||||
assert json_response(ret_conn, 200)
|
||||
assert json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
conn = get(conn, "/api/v1/accounts/#{user.id}")
|
||||
|
||||
assert user_data = json_response(conn, 200)
|
||||
assert user_data = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert user_data["note"] == note
|
||||
assert user_data["display_name"] == name
|
||||
|
|
@ -279,7 +281,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
account_data =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account_data["fields"] == [
|
||||
%{"name" => "<a href=\"http://google.com\">foo</a>", "value" => "bar"},
|
||||
|
|
@ -312,7 +314,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
conn
|
||||
|> put_req_header("content-type", "application/x-www-form-urlencoded")
|
||||
|> patch("/api/v1/accounts/update_credentials", fields)
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
|
|
@ -337,7 +339,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
account =
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => ""}
|
||||
|
|
@ -356,14 +358,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
|
||||
fields = [%{"name" => long_name, "value" => "bar"}]
|
||||
|
||||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
|
||||
Pleroma.Config.put([:instance, :max_account_fields], 1)
|
||||
|
||||
|
|
@ -375,7 +377,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|> json_response_and_validate_schema(403)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -27,7 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
|
|||
"vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
|
||||
}
|
||||
|
||||
assert expected == json_response(conn, 200)
|
||||
assert expected == json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "creates an oauth app", %{conn: conn} do
|
||||
|
|
@ -55,6 +55,6 @@ defmodule Pleroma.Web.MastodonAPI.AppControllerTest do
|
|||
"vapid_key" => Push.vapid_config() |> Keyword.get(:public_key)
|
||||
}
|
||||
|
||||
assert expected == json_response(conn, 200)
|
||||
assert expected == json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ defmodule Pleroma.Web.MastodonAPI.CustomEmojiControllerTest do
|
|||
use Pleroma.Web.ConnCase, async: true
|
||||
|
||||
test "with tags", %{conn: conn} do
|
||||
[emoji | _body] =
|
||||
conn
|
||||
|> get("/api/v1/custom_emojis")
|
||||
|> json_response(200)
|
||||
assert resp =
|
||||
conn
|
||||
|> get("/api/v1/custom_emojis")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert [emoji | _body] = resp
|
||||
assert Map.has_key?(emoji, "shortcode")
|
||||
assert Map.has_key?(emoji, "static_url")
|
||||
assert Map.has_key?(emoji, "tags")
|
||||
|
|
|
|||
|
|
@ -6,11 +6,8 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ApiSpec
|
||||
alias Pleroma.Web.ApiSpec.Schemas.DomainBlocksResponse
|
||||
|
||||
import Pleroma.Factory
|
||||
import OpenApiSpex.TestAssertions
|
||||
|
||||
test "blocking / unblocking a domain" do
|
||||
%{user: user, conn: conn} = oauth_access(["write:blocks"])
|
||||
|
|
@ -21,7 +18,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
|||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
||||
|
||||
assert %{} = json_response(ret_conn, 200)
|
||||
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)
|
||||
|
||||
|
|
@ -30,7 +27,7 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
|||
|> put_req_header("content-type", "application/json")
|
||||
|> delete("/api/v1/domain_blocks", %{"domain" => "dogwhistle.zone"})
|
||||
|
||||
assert %{} = json_response(ret_conn, 200)
|
||||
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
|
||||
|
|
@ -41,21 +38,10 @@ defmodule Pleroma.Web.MastodonAPI.DomainBlockControllerTest do
|
|||
{:ok, user} = User.block_domain(user, "bad.site")
|
||||
{:ok, user} = User.block_domain(user, "even.worse.site")
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/domain_blocks")
|
||||
|
||||
domain_blocks = json_response(conn, 200)
|
||||
|
||||
assert "bad.site" in domain_blocks
|
||||
assert "even.worse.site" in domain_blocks
|
||||
assert_schema(domain_blocks, "DomainBlocksResponse", ApiSpec.spec())
|
||||
end
|
||||
|
||||
test "DomainBlocksResponse example matches schema" do
|
||||
api_spec = ApiSpec.spec()
|
||||
schema = DomainBlocksResponse.schema()
|
||||
assert_schema(schema.example, "DomainBlocksResponse", api_spec)
|
||||
assert ["even.worse.site", "bad.site"] ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/domain_blocks")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -302,6 +302,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert [] == Repo.all(Activity)
|
||||
end
|
||||
|
||||
test "ignores nil values", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/v1/statuses", %{
|
||||
"status" => "not scheduled",
|
||||
"scheduled_at" => nil
|
||||
})
|
||||
|
||||
assert result = json_response(conn, 200)
|
||||
assert Activity.get_by_id(result["id"])
|
||||
end
|
||||
|
||||
test "creates a scheduled activity with a media attachment", %{user: user, conn: conn} do
|
||||
scheduled_at = NaiveDateTime.add(NaiveDateTime.utc_now(), :timer.minutes(120), :millisecond)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,10 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
|||
quote do
|
||||
vapid_details = Application.get_env(:web_push_encryption, :vapid_details, [])
|
||||
Application.put_env(:web_push_encryption, :vapid_details, [])
|
||||
assert "Something went wrong" == unquote(yield)
|
||||
|
||||
assert %{"error" => "Web push subscription is disabled on this Pleroma instance"} ==
|
||||
unquote(yield)
|
||||
|
||||
Application.put_env(:web_push_encryption, :vapid_details, vapid_details)
|
||||
end
|
||||
end
|
||||
|
|
@ -45,7 +48,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
|||
assert_error_when_disable_push do
|
||||
conn
|
||||
|> post("/api/v1/push/subscription", %{})
|
||||
|> json_response(500)
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -74,7 +77,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
|||
assert_error_when_disable_push do
|
||||
conn
|
||||
|> get("/api/v1/push/subscription", %{})
|
||||
|> json_response(500)
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -127,7 +130,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
|||
assert_error_when_disable_push do
|
||||
conn
|
||||
|> put("/api/v1/push/subscription", %{data: %{"alerts" => %{"mention" => false}}})
|
||||
|> json_response(500)
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -155,7 +158,7 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
|
|||
assert_error_when_disable_push do
|
||||
conn
|
||||
|> delete("/api/v1/push/subscription", %{})
|
||||
|> json_response(500)
|
||||
|> json_response(403)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,34 +7,8 @@ defmodule Pleroma.Web.MastodonAPI.SuggestionControllerTest do
|
|||
|
||||
alias Pleroma.Config
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
setup do: oauth_access(["read"])
|
||||
|
||||
setup %{user: user} do
|
||||
other_user = insert(:user)
|
||||
host = Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||
url500 = "http://test500?#{host}&#{user.nickname}"
|
||||
url200 = "http://test200?#{host}&#{user.nickname}"
|
||||
|
||||
mock(fn
|
||||
%{method: :get, url: ^url500} ->
|
||||
%Tesla.Env{status: 500, body: "bad request"}
|
||||
|
||||
%{method: :get, url: ^url200} ->
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body:
|
||||
~s([{"acct":"yj455","avatar":"https://social.heldscal.la/avatar/201.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/201.jpeg"}, {"acct":"#{
|
||||
other_user.ap_id
|
||||
}","avatar":"https://social.heldscal.la/avatar/202.jpeg","avatar_static":"https://social.heldscal.la/avatar/s/202.jpeg"}])
|
||||
}
|
||||
end)
|
||||
|
||||
[other_user: other_user]
|
||||
end
|
||||
|
||||
test "returns empty result", %{conn: conn} do
|
||||
res =
|
||||
conn
|
||||
|
|
|
|||
|
|
@ -7,35 +7,28 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
describe "empty_array/2 (stubs)" do
|
||||
test "GET /api/v1/accounts/:id/identity_proofs" do
|
||||
%{user: user, conn: conn} = oauth_access(["n/a"])
|
||||
%{user: user, conn: conn} = oauth_access(["read:accounts"])
|
||||
|
||||
res =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/#{user.id}/identity_proofs")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/accounts/#{user.id}/identity_proofs")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "GET /api/v1/endorsements" do
|
||||
%{conn: conn} = oauth_access(["read:accounts"])
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/endorsements")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/endorsements")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "GET /api/v1/trends", %{conn: conn} do
|
||||
res =
|
||||
conn
|
||||
|> get("/api/v1/trends")
|
||||
|> json_response(200)
|
||||
|
||||
assert res == []
|
||||
assert [] ==
|
||||
conn
|
||||
|> get("/api/v1/trends")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,16 +19,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
|
||||
test "Represent a user account" do
|
||||
source_data = %{
|
||||
"tag" => [
|
||||
%{
|
||||
"type" => "Emoji",
|
||||
"icon" => %{"url" => "/file.png"},
|
||||
"name" => ":karjalanpiirakka:"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
background_image = %{
|
||||
"url" => [%{"href" => "https://example.com/images/asuka_hospital.png"}]
|
||||
}
|
||||
|
|
@ -37,13 +27,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
insert(:user, %{
|
||||
follower_count: 3,
|
||||
note_count: 5,
|
||||
source_data: source_data,
|
||||
background: background_image,
|
||||
nickname: "shp@shitposter.club",
|
||||
name: ":karjalanpiirakka: shp",
|
||||
bio:
|
||||
"<script src=\"invalid-html\"></script><span>valid html</span>. a<br>b<br/>c<br >d<br />f",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036],
|
||||
emoji: %{"karjalanpiirakka" => "/file.png"}
|
||||
})
|
||||
|
||||
expected = %{
|
||||
|
|
@ -117,7 +107,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
insert(:user, %{
|
||||
follower_count: 3,
|
||||
note_count: 5,
|
||||
source_data: %{},
|
||||
actor_type: "Service",
|
||||
nickname: "shp@shitposter.club",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
|
|
@ -311,7 +300,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
insert(:user, %{
|
||||
follower_count: 0,
|
||||
note_count: 5,
|
||||
source_data: %{},
|
||||
actor_type: "Service",
|
||||
nickname: "shp@shitposter.club",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
|
|
|
|||
|
|
@ -43,7 +43,8 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
|||
%{title: "why are you even asking?", votes_count: 0}
|
||||
],
|
||||
voted: false,
|
||||
votes_count: 0
|
||||
votes_count: 0,
|
||||
voters_count: nil
|
||||
}
|
||||
|
||||
result = PollView.render("show.json", %{object: object})
|
||||
|
|
@ -69,9 +70,20 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do
|
|||
}
|
||||
})
|
||||
|
||||
voter = insert(:user)
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
assert %{multiple: true} = PollView.render("show.json", %{object: object})
|
||||
{:ok, _votes, object} = CommonAPI.vote(voter, object, [0, 1])
|
||||
|
||||
assert match?(
|
||||
%{
|
||||
multiple: true,
|
||||
voters_count: 1,
|
||||
votes_count: 2
|
||||
},
|
||||
PollView.render("show.json", %{object: object})
|
||||
)
|
||||
end
|
||||
|
||||
test "detects emoji" do
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do
|
||||
defmodule Pleroma.Web.MastodonAPI.SubscriptionViewTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Web.MastodonAPI.PushSubscriptionView, as: View
|
||||
alias Pleroma.Web.MastodonAPI.SubscriptionView, as: View
|
||||
alias Pleroma.Web.Push
|
||||
|
||||
test "Represent a subscription" do
|
||||
|
|
@ -18,6 +18,6 @@ defmodule Pleroma.Web.MastodonAPI.PushSubscriptionViewTest do
|
|||
server_key: Keyword.get(Push.vapid_config(), :public_key)
|
||||
}
|
||||
|
||||
assert expected == View.render("push_subscription.json", %{subscription: subscription})
|
||||
assert expected == View.render("show.json", %{subscription: subscription})
|
||||
end
|
||||
end
|
||||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.MongooseIMController do
|
|||
test "/user_exists", %{conn: conn} do
|
||||
_user = insert(:user, nickname: "lain")
|
||||
_remote_user = insert(:user, nickname: "alice", local: false)
|
||||
_deactivated_user = insert(:user, nickname: "konata", deactivated: true)
|
||||
|
||||
res =
|
||||
conn
|
||||
|
|
@ -30,11 +31,25 @@ defmodule Pleroma.Web.MongooseIMController do
|
|||
|> json_response(404)
|
||||
|
||||
assert res == false
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get(mongoose_im_path(conn, :user_exists), user: "konata")
|
||||
|> json_response(404)
|
||||
|
||||
assert res == false
|
||||
end
|
||||
|
||||
test "/check_password", %{conn: conn} do
|
||||
user = insert(:user, password_hash: Comeonin.Pbkdf2.hashpwsalt("cool"))
|
||||
|
||||
_deactivated_user =
|
||||
insert(:user,
|
||||
nickname: "konata",
|
||||
deactivated: true,
|
||||
password_hash: Comeonin.Pbkdf2.hashpwsalt("cool")
|
||||
)
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "cool")
|
||||
|
|
@ -49,6 +64,13 @@ defmodule Pleroma.Web.MongooseIMController do
|
|||
|
||||
assert res == false
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "cool")
|
||||
|> json_response(404)
|
||||
|
||||
assert res == false
|
||||
|
||||
res =
|
||||
conn
|
||||
|> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool")
|
||||
|
|
|
|||
|
|
@ -151,15 +151,18 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
assert like["id"] == activity.id
|
||||
end
|
||||
|
||||
test "does not return favorites for specified user_id when user is not logged in", %{
|
||||
test "returns favorites for specified user_id when requester is not logged in", %{
|
||||
user: user
|
||||
} do
|
||||
activity = insert(:note_activity)
|
||||
CommonAPI.favorite(user, activity.id)
|
||||
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(403)
|
||||
response =
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(response) == 1
|
||||
end
|
||||
|
||||
test "returns favorited DM only when user is logged in and he is one of recipients", %{
|
||||
|
|
@ -185,9 +188,12 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
assert length(response) == 1
|
||||
end
|
||||
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(403)
|
||||
response =
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(200)
|
||||
|
||||
assert length(response) == 0
|
||||
end
|
||||
|
||||
test "does not return others' favorited DM when user is not one of recipients", %{
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -220,7 +220,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
|
||||
test "POST /api/v1/pleroma/conversations/read" do
|
||||
user = insert(:user)
|
||||
%{user: other_user, conn: conn} = oauth_access(["write:notifications"])
|
||||
%{user: other_user, conn: conn} = oauth_access(["write:conversations"])
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}", "visibility" => "direct"})
|
||||
|
|
|
|||
|
|
@ -63,12 +63,12 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
activity: activity
|
||||
)
|
||||
|
||||
assert Impl.perform(notif) == [:ok, :ok]
|
||||
assert Impl.perform(notif) == {:ok, [:ok, :ok]}
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
test "returns error if notif does not match " do
|
||||
assert Impl.perform(%{}) == :error
|
||||
assert Impl.perform(%{}) == {:error, :unknown_type}
|
||||
end
|
||||
|
||||
test "successful message sending" do
|
||||
|
|
|
|||
|
|
@ -28,6 +28,42 @@ defmodule Pleroma.Web.StreamerTest do
|
|||
{:ok, %{user: user, notify: notify}}
|
||||
end
|
||||
|
||||
test "it streams the user's post in the 'user' stream", %{user: user} do
|
||||
task =
|
||||
Task.async(fn ->
|
||||
assert_receive {:text, _}, @streamer_timeout
|
||||
end)
|
||||
|
||||
Streamer.add_socket(
|
||||
"user",
|
||||
%{transport_pid: task.pid, assigns: %{user: user}}
|
||||
)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
|
||||
Streamer.stream("user", activity)
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it streams boosts of the user in the 'user' stream", %{user: user} do
|
||||
task =
|
||||
Task.async(fn ->
|
||||
assert_receive {:text, _}, @streamer_timeout
|
||||
end)
|
||||
|
||||
Streamer.add_socket(
|
||||
"user",
|
||||
%{transport_pid: task.pid, assigns: %{user: user}}
|
||||
)
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hey"})
|
||||
{:ok, announce, _} = CommonAPI.repeat(activity.id, user)
|
||||
|
||||
Streamer.stream("user", announce)
|
||||
Task.await(task)
|
||||
end
|
||||
|
||||
test "it sends notify to in the 'user' stream", %{user: user, notify: notify} do
|
||||
task =
|
||||
Task.async(fn ->
|
||||
|
|
|
|||
|
|
@ -19,13 +19,9 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
|
||||
test "with credentials, without any params" do
|
||||
%{user: current_user, conn: conn} =
|
||||
oauth_access(["read:notifications", "write:notifications"])
|
||||
%{conn: conn} = oauth_access(["write:notifications"])
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, current_user)
|
||||
|> post("/api/qvitter/statuses/notifications/read")
|
||||
conn = post(conn, "/api/qvitter/statuses/notifications/read")
|
||||
|
||||
assert json_response(conn, 400) == %{
|
||||
"error" => "You need to specify latest_id",
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user and returns the user." do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:nickname => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -35,12 +35,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user with empty string in bio and returns the user." do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:nickname => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -60,12 +60,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
end
|
||||
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:nickname => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -87,23 +87,23 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it registers a new user and parses mentions in the bio" do
|
||||
data1 = %{
|
||||
"nickname" => "john",
|
||||
"email" => "john@gmail.com",
|
||||
"fullname" => "John Doe",
|
||||
"bio" => "test",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:nickname => "john",
|
||||
:email => "john@gmail.com",
|
||||
:fullname => "John Doe",
|
||||
:bio => "test",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user1} = TwitterAPI.register_user(data1)
|
||||
|
||||
data2 = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "@john test",
|
||||
"password" => "bear",
|
||||
"confirm" => "bear"
|
||||
:nickname => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "@john test",
|
||||
:password => "bear",
|
||||
:confirm => "bear"
|
||||
}
|
||||
|
||||
{:ok, user2} = TwitterAPI.register_user(data2)
|
||||
|
|
@ -123,13 +123,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, invite} = UserInviteToken.create_invite()
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:nickname => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -145,13 +145,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "returns error on invalid token" do
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => "DudeLetMeInImAFairy"
|
||||
:nickname => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => "DudeLetMeInImAFairy"
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -165,13 +165,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, used: true)
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:nickname => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -186,16 +186,16 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
setup do
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees"
|
||||
:nickname => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees"
|
||||
}
|
||||
|
||||
check_fn = fn invite ->
|
||||
data = Map.put(data, "token", invite.token)
|
||||
data = Map.put(data, :token, invite.token)
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
fetched_user = User.get_cached_by_nickname("vinny")
|
||||
|
||||
|
|
@ -250,13 +250,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 99)
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:nickname => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -269,13 +269,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:nickname => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -292,13 +292,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
{:ok, invite} = UserInviteToken.create_invite(%{expires_at: Date.utc_today(), max_use: 100})
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:nickname => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -317,13 +317,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 99)
|
||||
|
||||
data = %{
|
||||
"nickname" => "vinny",
|
||||
"email" => "pasta@pizza.vs",
|
||||
"fullname" => "Vinny Vinesauce",
|
||||
"bio" => "streamer",
|
||||
"password" => "hiptofbees",
|
||||
"confirm" => "hiptofbees",
|
||||
"token" => invite.token
|
||||
:nickname => "vinny",
|
||||
:email => "pasta@pizza.vs",
|
||||
:fullname => "Vinny Vinesauce",
|
||||
:bio => "streamer",
|
||||
:password => "hiptofbees",
|
||||
:confirm => "hiptofbees",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:ok, user} = TwitterAPI.register_user(data)
|
||||
|
|
@ -335,13 +335,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
AccountView.render("show.json", %{user: fetched_user})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:nickname => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -355,13 +355,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.create_invite(%{expires_at: Date.add(Date.utc_today(), -1), max_use: 100})
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:nickname => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -377,13 +377,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
UserInviteToken.update_invite!(invite, uses: 100)
|
||||
|
||||
data = %{
|
||||
"nickname" => "GrimReaper",
|
||||
"email" => "death@reapers.afterlife",
|
||||
"fullname" => "Reaper Grim",
|
||||
"bio" => "Your time has come",
|
||||
"password" => "scythe",
|
||||
"confirm" => "scythe",
|
||||
"token" => invite.token
|
||||
:nickname => "GrimReaper",
|
||||
:email => "death@reapers.afterlife",
|
||||
:fullname => "Reaper Grim",
|
||||
:bio => "Your time has come",
|
||||
:password => "scythe",
|
||||
:confirm => "scythe",
|
||||
:token => invite.token
|
||||
}
|
||||
|
||||
{:error, msg} = TwitterAPI.register_user(data)
|
||||
|
|
@ -395,11 +395,11 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
|
||||
test "it returns the error on registration problems" do
|
||||
data = %{
|
||||
"nickname" => "lain",
|
||||
"email" => "lain@wired.jp",
|
||||
"fullname" => "lain iwakura",
|
||||
"bio" => "close the world.",
|
||||
"password" => "bear"
|
||||
:nickname => "lain",
|
||||
:email => "lain@wired.jp",
|
||||
:fullname => "lain iwakura",
|
||||
:bio => "close the world.",
|
||||
:password => "bear"
|
||||
}
|
||||
|
||||
{:error, error_object} = TwitterAPI.register_user(data)
|
||||
|
|
|
|||
|
|
@ -95,6 +95,30 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports follows with different nickname variations", %{conn: conn} do
|
||||
[user2, user3, user4, user5, user6] = insert_list(5, :user)
|
||||
|
||||
identifiers =
|
||||
[
|
||||
user2.ap_id,
|
||||
user3.nickname,
|
||||
" ",
|
||||
"@" <> user4.nickname,
|
||||
user5.nickname <> "@localhost",
|
||||
"@" <> user6.nickname <> "@localhost"
|
||||
]
|
||||
|> Enum.join("\n")
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/api/pleroma/follow_import", %{"list" => identifiers})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response == "job started"
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == [user2, user3, user4, user5, user6]
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /api/pleroma/blocks_import" do
|
||||
|
|
@ -136,6 +160,29 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
test "it imports blocks with different nickname variations", %{conn: conn} do
|
||||
[user2, user3, user4, user5, user6] = insert_list(5, :user)
|
||||
|
||||
identifiers =
|
||||
[
|
||||
user2.ap_id,
|
||||
user3.nickname,
|
||||
"@" <> user4.nickname,
|
||||
user5.nickname <> "@localhost",
|
||||
"@" <> user6.nickname <> "@localhost"
|
||||
]
|
||||
|> Enum.join(" ")
|
||||
|
||||
response =
|
||||
conn
|
||||
|> post("/api/pleroma/blocks_import", %{"list" => identifiers})
|
||||
|> json_response(:ok)
|
||||
|
||||
assert response == "job started"
|
||||
assert [{:ok, job_result}] = ObanHelpers.perform_all()
|
||||
assert job_result == [user2, user3, user4, user5, user6]
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /api/pleroma/notification_settings" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue