Merge remote-tracking branch 'origin/develop' into explicit-addressing
This commit is contained in:
commit
4cab98b7bf
23 changed files with 344 additions and 40 deletions
|
|
@ -6,6 +6,11 @@ defmodule Pleroma.Object.ContainmentTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
setup_all do
|
||||
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||
:ok
|
||||
end
|
||||
|
||||
describe "general origin containment" do
|
||||
test "contain_origin_from_id() catches obvious spoofing attempts" do
|
||||
data = %{
|
||||
|
|
|
|||
|
|
@ -243,6 +243,14 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://n1u.moe/users/rye", _, _, Accept: "application/activity+json") do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/httpoison_mock/rye.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/users/admin/statuses/100787282858396771", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -302,6 +310,10 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/users/gargron", _, _, Accept: "application/activity+json") do
|
||||
{:error, :nxdomain}
|
||||
end
|
||||
|
||||
def get(
|
||||
"http://mastodon.example.org/@admin/99541947525187367",
|
||||
_,
|
||||
|
|
@ -546,6 +558,15 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get(
|
||||
"http://gs.example.org:4040/index.php/user/1",
|
||||
_,
|
||||
_,
|
||||
Accept: "application/activity+json"
|
||||
) do
|
||||
{:ok, %Tesla.Env{status: 406, body: ""}}
|
||||
end
|
||||
|
||||
def get("http://gs.example.org/index.php/api/statuses/user_timeline/1.atom", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
|
|||
32
test/web/activity_pub/mrf/subchain_policy_test.exs
Normal file
32
test/web/activity_pub/mrf/subchain_policy_test.exs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ActivityPub.MRF.SubchainPolicyTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.ActivityPub.MRF.DropPolicy
|
||||
alias Pleroma.Web.ActivityPub.MRF.SubchainPolicy
|
||||
|
||||
@message %{
|
||||
"actor" => "https://banned.com",
|
||||
"type" => "Create",
|
||||
"object" => %{"content" => "hi"}
|
||||
}
|
||||
|
||||
test "it matches and processes subchains when the actor matches a configured target" do
|
||||
Pleroma.Config.put([:mrf_subchain, :match_actor], %{
|
||||
~r/^https:\/\/banned.com/s => [DropPolicy]
|
||||
})
|
||||
|
||||
{:reject, _} = SubchainPolicy.filter(@message)
|
||||
end
|
||||
|
||||
test "it doesn't match and process subchains when the actor doesn't match a configured target" do
|
||||
Pleroma.Config.put([:mrf_subchain, :match_actor], %{
|
||||
~r/^https:\/\/borked.com/s => [DropPolicy]
|
||||
})
|
||||
|
||||
{:ok, _message} = SubchainPolicy.filter(@message)
|
||||
end
|
||||
end
|
||||
|
|
@ -239,4 +239,19 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
|
||||
assert expected == AccountView.render("account.json", %{user: user, for: other_user})
|
||||
end
|
||||
|
||||
test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
|
||||
user = insert(:user, %{info: %User.Info{pleroma_settings_store: %{fe: "test"}}})
|
||||
|
||||
result =
|
||||
AccountView.render("account.json", %{user: user, for: user, with_pleroma_settings: true})
|
||||
|
||||
assert result.pleroma.settings_store == %{:fe => "test"}
|
||||
|
||||
result = AccountView.render("account.json", %{user: user, with_pleroma_settings: true})
|
||||
assert result.pleroma[:settings_store] == nil
|
||||
|
||||
result = AccountView.render("account.json", %{user: user, for: user})
|
||||
assert result.pleroma[:settings_store] == nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2423,6 +2423,66 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
|
||||
describe "updating credentials" do
|
||||
test "sets user settings in a generic way", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
"pleroma_settings_store" => %{
|
||||
pleroma_fe: %{
|
||||
theme: "bla"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
assert user = json_response(res_conn, 200)
|
||||
assert user["pleroma"]["settings_store"] == %{"pleroma_fe" => %{"theme" => "bla"}}
|
||||
|
||||
user = Repo.get(User, user["id"])
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
"pleroma_settings_store" => %{
|
||||
masto_fe: %{
|
||||
theme: "bla"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
assert user = json_response(res_conn, 200)
|
||||
|
||||
assert user["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
"pleroma_fe" => %{"theme" => "bla"},
|
||||
"masto_fe" => %{"theme" => "bla"}
|
||||
}
|
||||
|
||||
user = Repo.get(User, user["id"])
|
||||
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{
|
||||
"pleroma_settings_store" => %{
|
||||
masto_fe: %{
|
||||
theme: "blub"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
assert user = json_response(res_conn, 200)
|
||||
|
||||
assert user["pleroma"]["settings_store"] ==
|
||||
%{
|
||||
"pleroma_fe" => %{"theme" => "bla"},
|
||||
"masto_fe" => %{"theme" => "blub"}
|
||||
}
|
||||
end
|
||||
|
||||
test "updates the user's bio", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue