Merge develop
This commit is contained in:
commit
9bca70b10a
51 changed files with 1157 additions and 213 deletions
|
|
@ -113,4 +113,30 @@ defmodule Pleroma.ListTest do
|
|||
assert owned_list in lists_2
|
||||
refute not_owned_list in lists_2
|
||||
end
|
||||
|
||||
test "get by ap_id" do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
assert Pleroma.List.get_by_ap_id(list.ap_id) == list
|
||||
end
|
||||
|
||||
test "memberships" do
|
||||
user = insert(:user)
|
||||
member = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, member)
|
||||
|
||||
assert Pleroma.List.memberships(member) == [list.ap_id]
|
||||
end
|
||||
|
||||
test "member?" do
|
||||
user = insert(:user)
|
||||
member = insert(:user)
|
||||
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, member)
|
||||
|
||||
assert Pleroma.List.member?(list, member)
|
||||
refute Pleroma.List.member?(list, user)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -68,4 +68,34 @@ defmodule Pleroma.Object.ContainmentTest do
|
|||
"[error] Could not decode user at fetch https://n1u.moe/users/rye, {:error, :error}"
|
||||
end
|
||||
end
|
||||
|
||||
describe "containment of children" do
|
||||
test "contain_child() catches spoofing attempts" do
|
||||
data = %{
|
||||
"id" => "http://example.com/whatever",
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"id" => "http://example.net/~alyssa/activities/1234",
|
||||
"attributedTo" => "http://example.org/~alyssa"
|
||||
},
|
||||
"actor" => "http://example.com/~bob"
|
||||
}
|
||||
|
||||
:error = Containment.contain_child(data)
|
||||
end
|
||||
|
||||
test "contain_child() allows correct origins" do
|
||||
data = %{
|
||||
"id" => "http://example.org/~alyssa/activities/5678",
|
||||
"type" => "Create",
|
||||
"object" => %{
|
||||
"id" => "http://example.org/~alyssa/activities/1234",
|
||||
"attributedTo" => "http://example.org/~alyssa"
|
||||
},
|
||||
"actor" => "http://example.org/~alyssa"
|
||||
}
|
||||
|
||||
:ok = Containment.contain_child(data)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.ReverseProxyTest do
|
||||
use Pleroma.Web.ConnCase, async: true
|
||||
import ExUnit.CaptureLog
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
alias Pleroma.ReverseProxy
|
||||
alias Pleroma.ReverseProxy.ClientMock
|
||||
|
|
|
|||
99
test/signature_test.exs
Normal file
99
test/signature_test.exs
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.SignatureTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
import Pleroma.Factory
|
||||
import Tesla.Mock
|
||||
|
||||
alias Pleroma.Signature
|
||||
|
||||
setup do
|
||||
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
@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"
|
||||
}
|
||||
|
||||
@rsa_public_key {
|
||||
:RSAPublicKey,
|
||||
24_650_000_183_914_698_290_885_268_529_673_621_967_457_234_469_123_179_408_466_269_598_577_505_928_170_923_974_132_111_403_341_217_239_999_189_084_572_368_839_502_170_501_850_920_051_662_384_964_248_315_257_926_552_945_648_828_895_432_624_227_029_881_278_113_244_073_644_360_744_504_606_177_648_469_825_063_267_913_017_309_199_785_535_546_734_904_379_798_564_556_494_962_268_682_532_371_146_333_972_821_570_577_277_375_020_977_087_539_994_500_097_107_935_618_711_808_260_846_821_077_839_605_098_669_707_417_692_791_905_543_116_911_754_774_323_678_879_466_618_738_207_538_013_885_607_095_203_516_030_057_611_111_308_904_599_045_146_148_350_745_339_208_006_497_478_057_622_336_882_506_112_530_056_970_653_403_292_123_624_453_213_574_011_183_684_739_084_105_206_483_178_943_532_208_537_215_396_831_110_268_758_639_826_369_857,
|
||||
# credo:disable-for-previous-line Credo.Check.Readability.MaxLineLength
|
||||
65_537
|
||||
}
|
||||
|
||||
describe "fetch_public_key/1" do
|
||||
test "it returns key" do
|
||||
expected_result = {:ok, @rsa_public_key}
|
||||
|
||||
user = insert(:user, %{info: %{source_data: %{"publicKey" => @public_key}}})
|
||||
|
||||
assert Signature.fetch_public_key(%Plug.Conn{params: %{"actor" => user.ap_id}}) ==
|
||||
expected_result
|
||||
end
|
||||
|
||||
test "it returns error when not found user" do
|
||||
assert Signature.fetch_public_key(%Plug.Conn{params: %{"actor" => "test-ap_id"}}) ==
|
||||
{:error, :error}
|
||||
end
|
||||
|
||||
test "it returns error if public key is empty" do
|
||||
user = insert(:user, %{info: %{source_data: %{"publicKey" => %{}}}})
|
||||
|
||||
assert Signature.fetch_public_key(%Plug.Conn{params: %{"actor" => user.ap_id}}) ==
|
||||
{:error, :error}
|
||||
end
|
||||
end
|
||||
|
||||
describe "refetch_public_key/1" do
|
||||
test "it returns key" do
|
||||
ap_id = "https://mastodon.social/users/lambadalambda"
|
||||
|
||||
assert Signature.refetch_public_key(%Plug.Conn{params: %{"actor" => ap_id}}) ==
|
||||
{:ok, @rsa_public_key}
|
||||
end
|
||||
|
||||
test "it returns error when not found user" do
|
||||
assert Signature.refetch_public_key(%Plug.Conn{params: %{"actor" => "test-ap_id"}}) ==
|
||||
{:error, {:error, :ok}}
|
||||
end
|
||||
end
|
||||
|
||||
describe "sign/2" do
|
||||
test "it returns signature headers" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
ap_id: "https://mastodon.social/users/lambadalambda",
|
||||
info: %{keys: @private_key}
|
||||
})
|
||||
|
||||
assert Signature.sign(
|
||||
user,
|
||||
%{
|
||||
host: "test.test",
|
||||
"content-length": 100
|
||||
}
|
||||
) ==
|
||||
"keyId=\"https://mastodon.social/users/lambadalambda#main-key\",algorithm=\"rsa-sha256\",headers=\"content-length host\",signature=\"sibUOoqsFfTDerquAkyprxzDjmJm6erYc42W5w1IyyxusWngSinq5ILTjaBxFvfarvc7ci1xAi+5gkBwtshRMWm7S+Uqix24Yg5EYafXRun9P25XVnYBEIH4XQ+wlnnzNIXQkU3PU9e6D8aajDZVp3hPJNeYt1gIPOA81bROI8/glzb1SAwQVGRbqUHHHKcwR8keiR/W2h7BwG3pVRy4JgnIZRSW7fQogKedDg02gzRXwUDFDk0pr2p3q6bUWHUXNV8cZIzlMK+v9NlyFbVYBTHctAR26GIAN6Hz0eV0mAQAePHDY1mXppbA8Gpp6hqaMuYfwifcXmcc+QFm4e+n3A==\""
|
||||
end
|
||||
|
||||
test "it returns error" do
|
||||
user =
|
||||
insert(:user, %{ap_id: "https://mastodon.social/users/lambadalambda", info: %{keys: ""}})
|
||||
|
||||
assert Signature.sign(
|
||||
user,
|
||||
%{host: "test.test", "content-length": 100}
|
||||
) == {:error, []}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -34,8 +34,8 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
|
||||
Mix.Tasks.Pleroma.Config.run(["migrate_to_db"])
|
||||
|
||||
first_db = Config.get_by_params(%{group: "pleroma", key: "first_setting"})
|
||||
second_db = Config.get_by_params(%{group: "pleroma", key: "second_setting"})
|
||||
first_db = Config.get_by_params(%{group: "pleroma", key: ":first_setting"})
|
||||
second_db = Config.get_by_params(%{group: "pleroma", key: ":second_setting"})
|
||||
refute Config.get_by_params(%{group: "pleroma", key: "Pleroma.Repo"})
|
||||
|
||||
assert Config.from_binary(first_db.value) == [key: "value", key2: [Pleroma.Repo]]
|
||||
|
|
@ -45,13 +45,13 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
test "settings are migrated to file and deleted from db", %{temp_file: temp_file} do
|
||||
Config.create(%{
|
||||
group: "pleroma",
|
||||
key: "setting_first",
|
||||
key: ":setting_first",
|
||||
value: [key: "value", key2: [Pleroma.Activity]]
|
||||
})
|
||||
|
||||
Config.create(%{
|
||||
group: "pleroma",
|
||||
key: "setting_second",
|
||||
key: ":setting_second",
|
||||
value: [key: "valu2", key2: [Pleroma.Repo]]
|
||||
})
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ defmodule Mix.Tasks.Pleroma.ConfigTest do
|
|||
assert File.exists?(temp_file)
|
||||
{:ok, file} = File.read(temp_file)
|
||||
|
||||
assert file =~ "config :pleroma, setting_first:"
|
||||
assert file =~ "config :pleroma, setting_second:"
|
||||
assert file =~ "config :pleroma, :setting_first,"
|
||||
assert file =~ "config :pleroma, :setting_second,"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1190,6 +1190,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "fetch_activities/2 returns activities addressed to a list " do
|
||||
user = insert(:user)
|
||||
member = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, member)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
|
||||
|
||||
activity = Repo.preload(activity, :bookmark)
|
||||
activity = %Activity{activity | thread_muted?: !!activity.thread_muted?}
|
||||
|
||||
assert ActivityPub.fetch_activities([], %{"user" => user}) == [activity]
|
||||
end
|
||||
|
||||
def data_uri do
|
||||
File.read!("test/fixtures/avatar_data_uri")
|
||||
end
|
||||
|
|
|
|||
|
|
@ -416,6 +416,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|> Map.put("attributedTo", user.ap_id)
|
||||
|> Map.put("to", ["https://www.w3.org/ns/activitystreams#Public"])
|
||||
|> Map.put("cc", [])
|
||||
|> Map.put("id", user.ap_id <> "/activities/12345678")
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
|
|
@ -439,6 +440,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|> Map.put("attributedTo", user.ap_id)
|
||||
|> Map.put("to", nil)
|
||||
|> Map.put("cc", nil)
|
||||
|> Map.put("id", user.ap_id <> "/activities/12345678")
|
||||
|
||||
data = Map.put(data, "object", object)
|
||||
|
||||
|
|
@ -1096,6 +1098,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
assert modified["directMessage"] == true
|
||||
end
|
||||
|
||||
test "it strips BCC field" do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
|
||||
|
||||
{:ok, modified} = Transmogrifier.prepare_outgoing(activity.data)
|
||||
|
||||
assert is_nil(modified["bcc"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "user upgrade" do
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
following = insert(:user)
|
||||
unrelated = insert(:user)
|
||||
{:ok, following} = Pleroma.User.follow(following, user)
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
|
||||
Pleroma.List.follow(list, unrelated)
|
||||
|
||||
{:ok, public} =
|
||||
CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "public"})
|
||||
|
|
@ -29,6 +32,12 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
{:ok, unlisted} =
|
||||
CommonAPI.post(user, %{"status" => "@#{mentioned.nickname}", "visibility" => "unlisted"})
|
||||
|
||||
{:ok, list} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "@#{mentioned.nickname}",
|
||||
"visibility" => "list:#{list.id}"
|
||||
})
|
||||
|
||||
%{
|
||||
public: public,
|
||||
private: private,
|
||||
|
|
@ -37,29 +46,65 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
user: user,
|
||||
mentioned: mentioned,
|
||||
following: following,
|
||||
unrelated: unrelated
|
||||
unrelated: unrelated,
|
||||
list: list
|
||||
}
|
||||
end
|
||||
|
||||
test "is_direct?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
|
||||
test "is_direct?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
assert Visibility.is_direct?(direct)
|
||||
refute Visibility.is_direct?(public)
|
||||
refute Visibility.is_direct?(private)
|
||||
refute Visibility.is_direct?(unlisted)
|
||||
assert Visibility.is_direct?(list)
|
||||
end
|
||||
|
||||
test "is_public?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
|
||||
test "is_public?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_public?(direct)
|
||||
assert Visibility.is_public?(public)
|
||||
refute Visibility.is_public?(private)
|
||||
assert Visibility.is_public?(unlisted)
|
||||
refute Visibility.is_public?(list)
|
||||
end
|
||||
|
||||
test "is_private?", %{public: public, private: private, direct: direct, unlisted: unlisted} do
|
||||
test "is_private?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_private?(direct)
|
||||
refute Visibility.is_private?(public)
|
||||
assert Visibility.is_private?(private)
|
||||
refute Visibility.is_private?(unlisted)
|
||||
refute Visibility.is_private?(list)
|
||||
end
|
||||
|
||||
test "is_list?", %{
|
||||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
refute Visibility.is_list?(direct)
|
||||
refute Visibility.is_list?(public)
|
||||
refute Visibility.is_list?(private)
|
||||
refute Visibility.is_list?(unlisted)
|
||||
assert Visibility.is_list?(list)
|
||||
end
|
||||
|
||||
test "visible_for_user?", %{
|
||||
|
|
@ -70,7 +115,8 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
user: user,
|
||||
mentioned: mentioned,
|
||||
following: following,
|
||||
unrelated: unrelated
|
||||
unrelated: unrelated,
|
||||
list: list
|
||||
} do
|
||||
# All visible to author
|
||||
|
||||
|
|
@ -78,6 +124,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
assert Visibility.visible_for_user?(private, user)
|
||||
assert Visibility.visible_for_user?(unlisted, user)
|
||||
assert Visibility.visible_for_user?(direct, user)
|
||||
assert Visibility.visible_for_user?(list, user)
|
||||
|
||||
# All visible to a mentioned user
|
||||
|
||||
|
|
@ -85,6 +132,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
assert Visibility.visible_for_user?(private, mentioned)
|
||||
assert Visibility.visible_for_user?(unlisted, mentioned)
|
||||
assert Visibility.visible_for_user?(direct, mentioned)
|
||||
assert Visibility.visible_for_user?(list, mentioned)
|
||||
|
||||
# DM not visible for just follower
|
||||
|
||||
|
|
@ -92,6 +140,7 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
assert Visibility.visible_for_user?(private, following)
|
||||
assert Visibility.visible_for_user?(unlisted, following)
|
||||
refute Visibility.visible_for_user?(direct, following)
|
||||
refute Visibility.visible_for_user?(list, following)
|
||||
|
||||
# Public and unlisted visible for unrelated user
|
||||
|
||||
|
|
@ -99,6 +148,9 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
assert Visibility.visible_for_user?(unlisted, unrelated)
|
||||
refute Visibility.visible_for_user?(private, unrelated)
|
||||
refute Visibility.visible_for_user?(direct, unrelated)
|
||||
|
||||
# Visible for a list member
|
||||
assert Visibility.visible_for_user?(list, unrelated)
|
||||
end
|
||||
|
||||
test "doesn't die when the user doesn't exist",
|
||||
|
|
@ -115,18 +167,24 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
|
|||
public: public,
|
||||
private: private,
|
||||
direct: direct,
|
||||
unlisted: unlisted
|
||||
unlisted: unlisted,
|
||||
list: list
|
||||
} do
|
||||
assert Visibility.get_visibility(public) == "public"
|
||||
assert Visibility.get_visibility(private) == "private"
|
||||
assert Visibility.get_visibility(direct) == "direct"
|
||||
assert Visibility.get_visibility(unlisted) == "unlisted"
|
||||
assert Visibility.get_visibility(list) == "list"
|
||||
end
|
||||
|
||||
test "get_visibility with directMessage flag" do
|
||||
assert Visibility.get_visibility(%{data: %{"directMessage" => true}}) == "direct"
|
||||
end
|
||||
|
||||
test "get_visibility with listMessage flag" do
|
||||
assert Visibility.get_visibility(%{data: %{"listMessage" => ""}}) == "list"
|
||||
end
|
||||
|
||||
describe "entire_thread_visible_for_user?/2" do
|
||||
test "returns false if not found activity", %{user: user} do
|
||||
refute Visibility.entire_thread_visible_for_user?(%Activity{}, user)
|
||||
|
|
|
|||
|
|
@ -1720,7 +1720,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
configs: [
|
||||
%{
|
||||
"group" => "pleroma",
|
||||
"key" => "key1",
|
||||
"key" => ":key1",
|
||||
"value" => [
|
||||
%{"tuple" => [":key2", "some_val"]},
|
||||
%{
|
||||
|
|
@ -1750,7 +1750,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"configs" => [
|
||||
%{
|
||||
"group" => "pleroma",
|
||||
"key" => "key1",
|
||||
"key" => ":key1",
|
||||
"value" => [
|
||||
%{"tuple" => [":key2", "some_val"]},
|
||||
%{
|
||||
|
|
@ -1782,7 +1782,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
configs: [
|
||||
%{
|
||||
"group" => "pleroma",
|
||||
"key" => "key1",
|
||||
"key" => ":key1",
|
||||
"value" => %{"key" => "some_val"}
|
||||
}
|
||||
]
|
||||
|
|
@ -1793,7 +1793,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"configs" => [
|
||||
%{
|
||||
"group" => "pleroma",
|
||||
"key" => "key1",
|
||||
"key" => ":key1",
|
||||
"value" => %{"key" => "some_val"}
|
||||
}
|
||||
]
|
||||
|
|
@ -1862,6 +1862,45 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
]
|
||||
}
|
||||
end
|
||||
|
||||
test "queues key as atom", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, "/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{
|
||||
"group" => "pleroma_job_queue",
|
||||
"key" => ":queues",
|
||||
"value" => [
|
||||
%{"tuple" => [":federator_incoming", 50]},
|
||||
%{"tuple" => [":federator_outgoing", 50]},
|
||||
%{"tuple" => [":web_push", 50]},
|
||||
%{"tuple" => [":mailer", 10]},
|
||||
%{"tuple" => [":transmogrifier", 20]},
|
||||
%{"tuple" => [":scheduled_activities", 10]},
|
||||
%{"tuple" => [":background", 5]}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
assert json_response(conn, 200) == %{
|
||||
"configs" => [
|
||||
%{
|
||||
"group" => "pleroma_job_queue",
|
||||
"key" => ":queues",
|
||||
"value" => [
|
||||
%{"tuple" => [":federator_incoming", 50]},
|
||||
%{"tuple" => [":federator_outgoing", 50]},
|
||||
%{"tuple" => [":web_push", 50]},
|
||||
%{"tuple" => [":mailer", 10]},
|
||||
%{"tuple" => [":transmogrifier", 20]},
|
||||
%{"tuple" => [":scheduled_activities", 10]},
|
||||
%{"tuple" => [":background", 5]}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -129,6 +129,37 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
})
|
||||
end)
|
||||
end
|
||||
|
||||
test "it allows to address a list" do
|
||||
user = insert(:user)
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
|
||||
|
||||
assert activity.data["bcc"] == [list.ap_id]
|
||||
assert activity.recipients == [list.ap_id, user.ap_id]
|
||||
assert activity.data["listMessage"] == list.ap_id
|
||||
end
|
||||
|
||||
test "it returns error when status is empty and no attachments" do
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "Cannot post an empty status without attachments"} =
|
||||
CommonAPI.post(user, %{"status" => ""})
|
||||
end
|
||||
|
||||
test "it returns error when character limit is exceeded" do
|
||||
limit = Pleroma.Config.get([:instance, :limit])
|
||||
Pleroma.Config.put([:instance, :limit], 5)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
assert {:error, "The status is over the character limit"} =
|
||||
CommonAPI.post(user, %{"status" => "foobar"})
|
||||
|
||||
Pleroma.Config.put([:instance, :limit], limit)
|
||||
end
|
||||
end
|
||||
|
||||
describe "reactions" do
|
||||
|
|
@ -346,6 +377,20 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "unfollow/2" do
|
||||
test "also unsubscribes a user" do
|
||||
[follower, followed] = insert_pair(:user)
|
||||
{:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
|
||||
{:ok, followed} = User.subscribe(follower, followed)
|
||||
|
||||
assert User.subscribed_to?(follower, followed)
|
||||
|
||||
{:ok, follower} = CommonAPI.unfollow(follower, followed)
|
||||
|
||||
refute User.subscribed_to?(follower, followed)
|
||||
end
|
||||
end
|
||||
|
||||
describe "accept_follow_request/2" do
|
||||
test "after acceptance, it sets all existing pending follow request states to 'accept'" do
|
||||
user = insert(:user, info: %{locked: true})
|
||||
|
|
@ -387,4 +432,23 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
assert Repo.get(Activity, follow_activity_three.id).data["state"] == "pending"
|
||||
end
|
||||
end
|
||||
|
||||
describe "vote/3" do
|
||||
test "does not allow to vote twice" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "Am I cute?",
|
||||
"poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
{:ok, _, object} = CommonAPI.vote(other_user, object, [0])
|
||||
|
||||
assert {:error, "Already voted"} == CommonAPI.vote(other_user, object, [1])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
alias Pleroma.Web.Endpoint
|
||||
use Pleroma.DataCase
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Pleroma.Factory
|
||||
|
||||
@public_address "https://www.w3.org/ns/activitystreams#Public"
|
||||
|
|
@ -202,7 +203,9 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
expected = ""
|
||||
|
||||
assert Utils.date_to_asctime(date) == expected
|
||||
assert capture_log(fn ->
|
||||
assert Utils.date_to_asctime(date) == expected
|
||||
end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
|
||||
end
|
||||
|
||||
test "when date is a Unix timestamp" do
|
||||
|
|
@ -210,13 +213,23 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
|
|||
|
||||
expected = ""
|
||||
|
||||
assert Utils.date_to_asctime(date) == expected
|
||||
assert capture_log(fn ->
|
||||
assert Utils.date_to_asctime(date) == expected
|
||||
end) =~ "[warn] Date #{date} in wrong format, must be ISO 8601"
|
||||
end
|
||||
|
||||
test "when date is nil" do
|
||||
expected = ""
|
||||
|
||||
assert Utils.date_to_asctime(nil) == expected
|
||||
assert capture_log(fn ->
|
||||
assert Utils.date_to_asctime(nil) == expected
|
||||
end) =~ "[warn] Date in wrong format, must be ISO 8601"
|
||||
end
|
||||
|
||||
test "when date is a random string" do
|
||||
assert capture_log(fn ->
|
||||
assert Utils.date_to_asctime("foo") == ""
|
||||
end) =~ "[warn] Date foo in wrong format, must be ISO 8601"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
|
||||
test "Represent a user account" do
|
||||
|
|
@ -152,6 +153,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert expected == AccountView.render("account.json", %{user: user})
|
||||
end
|
||||
|
||||
test "Represent a deactivated user for an admin" do
|
||||
admin = insert(:user, %{info: %{is_admin: true}})
|
||||
deactivated_user = insert(:user, %{info: %{deactivated: true}})
|
||||
represented = AccountView.render("account.json", %{user: deactivated_user, for: admin})
|
||||
assert represented[:pleroma][:deactivated] == true
|
||||
end
|
||||
|
||||
test "Represent a smaller mention" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -165,28 +173,90 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
assert expected == AccountView.render("mention.json", %{user: user})
|
||||
end
|
||||
|
||||
test "represent a relationship" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
describe "relationship" do
|
||||
test "represent a relationship for the following and followed user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, other_user)
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
{:ok, user} = User.follow(user, other_user)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
{:ok, other_user} = User.subscribe(user, other_user)
|
||||
{:ok, user} = User.mute(user, other_user, true)
|
||||
{:ok, user} = CommonAPI.hide_reblogs(user, other_user)
|
||||
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: true,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: true,
|
||||
followed_by: true,
|
||||
blocking: false,
|
||||
blocked_by: false,
|
||||
muting: true,
|
||||
muting_notifications: true,
|
||||
subscribing: true,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: false,
|
||||
endorsed: false
|
||||
}
|
||||
|
||||
assert expected == AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
assert expected ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
|
||||
test "represent a relationship for the blocking and blocked user" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.follow(user, other_user)
|
||||
{:ok, other_user} = User.subscribe(user, other_user)
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
{:ok, other_user} = User.block(other_user, user)
|
||||
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: true,
|
||||
blocked_by: true,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
|
||||
assert expected ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
|
||||
test "represent a relationship for the user with a pending follow request" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user, %{info: %User.Info{locked: true}})
|
||||
|
||||
{:ok, user, other_user, _} = CommonAPI.follow(user, other_user)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(other_user.id)
|
||||
|
||||
expected = %{
|
||||
id: to_string(other_user.id),
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: false,
|
||||
blocked_by: false,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
subscribing: false,
|
||||
requested: true,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
}
|
||||
|
||||
assert expected ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
end
|
||||
end
|
||||
|
||||
test "represent an embedded relationship" do
|
||||
|
|
@ -240,6 +310,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
following: false,
|
||||
followed_by: false,
|
||||
blocking: true,
|
||||
blocked_by: false,
|
||||
subscribing: false,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user = insert(:user)
|
||||
following = insert(:user)
|
||||
|
||||
{:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -58,7 +58,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
following = insert(:user)
|
||||
|
||||
capture_log(fn ->
|
||||
{:ok, _activity} = TwitterAPI.create_status(following, %{"status" => "test"})
|
||||
{:ok, _activity} = CommonAPI.post(following, %{"status" => "test"})
|
||||
|
||||
{:ok, [_activity]} =
|
||||
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
|
||||
|
|
@ -1004,8 +1004,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
test "list timeline", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, _activity_one} = TwitterAPI.create_status(user, %{"status" => "Marisa is cute."})
|
||||
{:ok, activity_two} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
|
||||
{:ok, _activity_one} = CommonAPI.post(user, %{"status" => "Marisa is cute."})
|
||||
{:ok, activity_two} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
{:ok, list} = Pleroma.List.follow(list, other_user)
|
||||
|
||||
|
|
@ -1022,10 +1022,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
test "list timeline does not leak non-public statuses for unfollowed users", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
{:ok, activity_one} = TwitterAPI.create_status(other_user, %{"status" => "Marisa is cute."})
|
||||
{:ok, activity_one} = CommonAPI.post(other_user, %{"status" => "Marisa is cute."})
|
||||
|
||||
{:ok, _activity_two} =
|
||||
TwitterAPI.create_status(other_user, %{
|
||||
CommonAPI.post(other_user, %{
|
||||
"status" => "Marisa is cute.",
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
|
@ -1049,8 +1049,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
|
|
@ -1072,8 +1071,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
|
|
@ -1095,8 +1093,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
|
|
@ -1112,8 +1109,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
TwitterAPI.create_status(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "hi @#{user.nickname}"})
|
||||
|
||||
{:ok, [_notification]} = Notification.create_notifications(activity)
|
||||
|
||||
|
|
@ -1395,6 +1391,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 400 error when activity is not exist", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/foo/reblog")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not repeat"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "unreblogging" do
|
||||
|
|
@ -1413,6 +1420,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 400 error when activity is not exist", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/foo/unreblog")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not unrepeat"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "favoriting" do
|
||||
|
|
@ -1431,16 +1449,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 500 for a wrong id", %{conn: conn} do
|
||||
test "returns 400 error for a wrong id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
resp =
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/1/favourite")
|
||||
|> json_response(500)
|
||||
|
||||
assert resp == "Something went wrong"
|
||||
assert json_response(conn, 400) == %{"error" => "Could not favorite"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -1461,6 +1478,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 400 error for a wrong id", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/1/unfavourite")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not unfavorite"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "user timelines" do
|
||||
|
|
@ -1531,10 +1559,10 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
media =
|
||||
TwitterAPI.upload(file, user, "json")
|
||||
|> Poison.decode!()
|
||||
|> Jason.decode!()
|
||||
|
||||
{:ok, image_post} =
|
||||
TwitterAPI.create_status(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
|
||||
CommonAPI.post(user, %{"status" => "cofe", "media_ids" => [media["media_id"]]})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|
|
@ -1857,7 +1885,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
following = insert(:user)
|
||||
|
||||
capture_log(fn ->
|
||||
{:ok, activity} = TwitterAPI.create_status(following, %{"status" => "test #2hu"})
|
||||
{:ok, activity} = CommonAPI.post(following, %{"status" => "test #2hu"})
|
||||
|
||||
{:ok, [_activity]} =
|
||||
OStatus.fetch_activity_from_url("https://shitposter.club/notice/2827873")
|
||||
|
|
@ -2616,7 +2644,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
insert(:user, %{local: false, nickname: "u@peer1.com"})
|
||||
insert(:user, %{local: false, nickname: "u@peer2.com"})
|
||||
|
||||
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
|
||||
{:ok, _} = CommonAPI.post(user, %{"status" => "cofe"})
|
||||
|
||||
# Stats should count users with missing or nil `info.deactivated` value
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
|
@ -2709,6 +2737,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "/pin: returns 400 error when activity is not public", %{conn: conn, user: user} do
|
||||
{:ok, dm} = CommonAPI.post(user, %{"status" => "test", "visibility" => "direct"})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{dm.id}/pin")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not pin"}
|
||||
end
|
||||
|
||||
test "unpin status", %{conn: conn, user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
|
|
@ -2728,6 +2767,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "/unpin: returns 400 error when activity is not exist", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/1/unpin")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not unpin"}
|
||||
end
|
||||
|
||||
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
|
||||
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||
|
||||
|
|
@ -2902,6 +2950,17 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "cannot mute already muted conversation", %{conn: conn, user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.add_mute(user, activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/mute")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "conversation is already muted"}
|
||||
end
|
||||
|
||||
test "unmute conversation", %{conn: conn, user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.add_mute(user, activity)
|
||||
|
||||
|
|
@ -2946,7 +3005,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> post("/api/v1/reports", %{
|
||||
"account_id" => target_user.id,
|
||||
"status_ids" => [activity.id],
|
||||
"comment" => "bad status!"
|
||||
"comment" => "bad status!",
|
||||
"forward" => "false"
|
||||
})
|
||||
|> json_response(200)
|
||||
end
|
||||
|
|
@ -2979,6 +3039,19 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> post("/api/v1/reports", %{"account_id" => target_user.id, "comment" => comment})
|
||||
|> json_response(400)
|
||||
end
|
||||
|
||||
test "returns error when account is not exist", %{
|
||||
conn: conn,
|
||||
reporter: reporter,
|
||||
activity: activity
|
||||
} do
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, reporter)
|
||||
|> post("/api/v1/reports", %{"status_ids" => [activity.id], "account_id" => "foo"})
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Account not found"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "link headers" do
|
||||
|
|
@ -3338,7 +3411,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
user2 = insert(:user)
|
||||
user3 = insert(:user)
|
||||
|
||||
{:ok, replied_to} = TwitterAPI.create_status(user1, %{"status" => "cofe"})
|
||||
{:ok, replied_to} = CommonAPI.post(user1, %{"status" => "cofe"})
|
||||
|
||||
# Reply to status from another user
|
||||
conn1 =
|
||||
|
|
@ -3503,7 +3576,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|> get("/api/v1/polls/#{object.id}")
|
||||
|
||||
response = json_response(conn, 200)
|
||||
id = object.id
|
||||
id = to_string(object.id)
|
||||
assert %{"id" => ^id, "expired" => false, "multiple" => false} = response
|
||||
end
|
||||
|
||||
|
|
@ -3603,5 +3676,135 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
total_items == 1
|
||||
end)
|
||||
end
|
||||
|
||||
test "does not allow choice index to be greater than options count", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "Am I cute?",
|
||||
"poll" => %{"options" => ["Yes", "No"], "expires_in" => 20}
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [2]})
|
||||
|
||||
assert json_response(conn, 422) == %{"error" => "Invalid indices"}
|
||||
end
|
||||
|
||||
test "returns 404 error when object is not exist", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/polls/1/votes", %{"choices" => [0]})
|
||||
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
|
||||
test "returns 404 when poll is private and not available for user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "Am I cute?",
|
||||
"poll" => %{"options" => ["Yes", "No"], "expires_in" => 20},
|
||||
"visibility" => "private"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, other_user)
|
||||
|> post("/api/v1/polls/#{object.id}/votes", %{"choices" => [0]})
|
||||
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/statuses/:id/favourited_by" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|
||||
[conn: conn, activity: activity]
|
||||
end
|
||||
|
||||
test "returns users who have favorited the status", %{conn: conn, activity: activity} do
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, other_user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
|
||||
|> json_response(:ok)
|
||||
|
||||
[%{"id" => id}] = response
|
||||
|
||||
assert id == other_user.id
|
||||
end
|
||||
|
||||
test "returns empty array when status has not been favorited yet", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}/favourited_by")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert Enum.empty?(response)
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/v1/statuses/:id/reblogged_by" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "test"})
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, user)
|
||||
|
||||
[conn: conn, activity: activity]
|
||||
end
|
||||
|
||||
test "returns users who have reblogged the status", %{conn: conn, activity: activity} do
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _} = CommonAPI.repeat(activity.id, other_user)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
|
||||
|> json_response(:ok)
|
||||
|
||||
[%{"id" => id}] = response
|
||||
|
||||
assert id == other_user.id
|
||||
end
|
||||
|
||||
test "returns empty array when status has not been reblogged yet", %{
|
||||
conn: conn,
|
||||
activity: activity
|
||||
} do
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{activity.id}/reblogged_by")
|
||||
|> json_response(:ok)
|
||||
|
||||
assert Enum.empty?(response)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
expected = %{
|
||||
emojis: [],
|
||||
expired: false,
|
||||
id: object.id,
|
||||
id: to_string(object.id),
|
||||
multiple: false,
|
||||
options: [
|
||||
%{title: "absolutely!", votes_count: 0},
|
||||
|
|
@ -541,4 +541,17 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
assert result[:reblog][:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: user, target: user})
|
||||
end
|
||||
|
||||
test "visibility/list" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, list} = Pleroma.List.create("foo", user)
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"})
|
||||
|
||||
status = StatusView.render("status.json", activity: activity)
|
||||
|
||||
assert status.visibility == "list"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
73
test/web/media_proxy/media_proxy_controller_test.exs
Normal file
73
test/web/media_proxy/media_proxy_controller_test.exs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
import Mock
|
||||
alias Pleroma.Config
|
||||
|
||||
setup do
|
||||
media_proxy_config = Config.get([:media_proxy]) || []
|
||||
on_exit(fn -> Config.put([:media_proxy], media_proxy_config) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], false)
|
||||
|
||||
assert %Plug.Conn{
|
||||
status: 404,
|
||||
resp_body: "Not Found"
|
||||
} = get(conn, "/proxy/hhgfh/eeeee")
|
||||
|
||||
assert %Plug.Conn{
|
||||
status: 404,
|
||||
resp_body: "Not Found"
|
||||
} = get(conn, "/proxy/hhgfh/eeee/fff")
|
||||
end
|
||||
|
||||
test "it returns 403 when signature invalidated", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], true)
|
||||
Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
|
||||
path = URI.parse(Pleroma.Web.MediaProxy.encode_url("https://google.fn")).path
|
||||
Config.put([Pleroma.Web.Endpoint, :secret_key_base], "000")
|
||||
|
||||
assert %Plug.Conn{
|
||||
status: 403,
|
||||
resp_body: "Forbidden"
|
||||
} = get(conn, path)
|
||||
|
||||
assert %Plug.Conn{
|
||||
status: 403,
|
||||
resp_body: "Forbidden"
|
||||
} = get(conn, "/proxy/hhgfh/eeee")
|
||||
|
||||
assert %Plug.Conn{
|
||||
status: 403,
|
||||
resp_body: "Forbidden"
|
||||
} = get(conn, "/proxy/hhgfh/eeee/fff")
|
||||
end
|
||||
|
||||
test "redirects on valid url when filename invalidated", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], true)
|
||||
Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
|
||||
url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
|
||||
invalid_url = String.replace(url, "test.png", "test-file.png")
|
||||
response = get(conn, invalid_url)
|
||||
html = "<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>"
|
||||
assert response.status == 302
|
||||
assert response.resp_body == html
|
||||
end
|
||||
|
||||
test "it performs ReverseProxy.call when signature valid", %{conn: conn} do
|
||||
Config.put([:media_proxy, :enabled], true)
|
||||
Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
|
||||
url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
|
||||
|
||||
with_mock Pleroma.ReverseProxy,
|
||||
call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do
|
||||
assert %Plug.Conn{status: :success} = get(conn, url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.MediaProxyTest do
|
||||
defmodule Pleroma.Web.MediaProxyTest do
|
||||
use ExUnit.Case
|
||||
import Pleroma.Web.MediaProxy
|
||||
alias Pleroma.Web.MediaProxy.MediaProxyController
|
||||
|
|
@ -90,22 +90,39 @@ defmodule Pleroma.MediaProxyTest do
|
|||
|
||||
test "filename_matches preserves the encoded or decoded path" do
|
||||
assert MediaProxyController.filename_matches(
|
||||
true,
|
||||
%{"filename" => "/Hello world.jpg"},
|
||||
"/Hello world.jpg",
|
||||
"http://pleroma.social/Hello world.jpg"
|
||||
) == :ok
|
||||
|
||||
assert MediaProxyController.filename_matches(
|
||||
true,
|
||||
%{"filename" => "/Hello%20world.jpg"},
|
||||
"/Hello%20world.jpg",
|
||||
"http://pleroma.social/Hello%20world.jpg"
|
||||
) == :ok
|
||||
|
||||
assert MediaProxyController.filename_matches(
|
||||
true,
|
||||
%{"filename" => "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"},
|
||||
"/my%2Flong%2Furl%2F2019%2F07%2FS.jpg",
|
||||
"http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
|
||||
) == :ok
|
||||
|
||||
assert MediaProxyController.filename_matches(
|
||||
%{"filename" => "/my%2Flong%2Furl%2F2019%2F07%2FS.jp"},
|
||||
"/my%2Flong%2Furl%2F2019%2F07%2FS.jp",
|
||||
"http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg"
|
||||
) == {:wrong_filename, "my%2Flong%2Furl%2F2019%2F07%2FS.jpg"}
|
||||
end
|
||||
|
||||
test "encoded url are tried to match for proxy as `conn.request_path` encodes the url" do
|
||||
# conn.request_path will return encoded url
|
||||
request_path = "/ANALYSE-DAI-_-LE-STABLECOIN-100-D%C3%89CENTRALIS%C3%89-BQ.jpg"
|
||||
|
||||
assert MediaProxyController.filename_matches(
|
||||
true,
|
||||
request_path,
|
||||
"https://mydomain.com/uploads/2019/07/ANALYSE-DAI-_-LE-STABLECOIN-100-DÉCENTRALISÉ-BQ.jpg"
|
||||
) == :ok
|
||||
end
|
||||
|
||||
test "uses the configured base_url" do
|
||||
Loading…
Add table
Add a link
Reference in a new issue