Merge pull request 'Akkoma fixes: context, polls, media proxy, ConfigDB, API params' (#8047) from lambadalambda/pleroma:fix/akkoma-tier2 into develop
Reviewed-on: https://git.pleroma.social/pleroma/pleroma/pulls/8047
This commit is contained in:
commit
23f9484a76
19 changed files with 211 additions and 54 deletions
|
|
@ -96,6 +96,29 @@ defmodule Pleroma.Config.TransferTaskTest do
|
|||
assert Application.get_env(:pleroma, Pleroma.Search.ParadeDB.Repo)[:pool_size] == 2
|
||||
end
|
||||
|
||||
test "skips settings with an unknown module key" do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
Repo.insert_all("config", [
|
||||
%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Nowhere.Module",
|
||||
value: :erlang.term_to_binary(enabled: true),
|
||||
inserted_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
])
|
||||
|
||||
insert(:config, key: :test_key, value: [live: 2])
|
||||
on_exit(fn -> Application.delete_env(:pleroma, :test_key) end)
|
||||
|
||||
log = capture_log(fn -> assert :ok = TransferTask.load_and_update_env([], false) end)
|
||||
|
||||
assert log =~ "Pleroma.Nowhere.Module"
|
||||
assert Application.get_env(:pleroma, :test_key) == [live: 2]
|
||||
refute Application.get_env(:pleroma, :invalid_atom)
|
||||
end
|
||||
|
||||
describe "pleroma restart" do
|
||||
setup do
|
||||
on_exit(fn ->
|
||||
|
|
|
|||
|
|
@ -50,6 +50,22 @@ defmodule Pleroma.ConfigDBTest do
|
|||
assert config[:pleroma][:instance] == [name: "Pleroma"]
|
||||
end
|
||||
|
||||
test "loads a row with an unknown module key as :invalid_atom" do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
Repo.insert_all("config", [
|
||||
%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Nowhere.Module",
|
||||
value: :erlang.term_to_binary(enabled: true),
|
||||
inserted_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
])
|
||||
|
||||
assert [%ConfigDB{group: :pleroma, key: :invalid_atom}] = Repo.all(ConfigDB)
|
||||
end
|
||||
|
||||
describe "update_or_create/1" do
|
||||
test "common" do
|
||||
config = insert(:config)
|
||||
|
|
|
|||
|
|
@ -103,6 +103,25 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
|
|||
assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
|
||||
end
|
||||
|
||||
test "Question activity with a single, non-array tag" do
|
||||
tag = %{
|
||||
"href" => "https://gts.example/tags/caturday",
|
||||
"name" => "#caturday",
|
||||
"type" => "Hashtag"
|
||||
}
|
||||
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-question-activity.json")
|
||||
|> Jason.decode!()
|
||||
|> Kernel.put_in(["object", "tag"], tag)
|
||||
|
||||
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
||||
object = Object.normalize(activity, fetch: false)
|
||||
|
||||
assert tag in object.data["tag"]
|
||||
assert Object.hashtags(object) == ["caturday"]
|
||||
end
|
||||
|
||||
test "Mastodon Question activity with custom emojis" do
|
||||
options = [
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -60,6 +60,28 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
|
|||
assert key2 == inspect(config2.key)
|
||||
end
|
||||
|
||||
test "does not crash on a setting with an unknown module key", %{conn: conn} do
|
||||
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
|
||||
|
||||
Pleroma.Repo.insert_all("config", [
|
||||
%{
|
||||
group: ":pleroma",
|
||||
key: "Pleroma.Nowhere.Module",
|
||||
value: :erlang.term_to_binary(enabled: true),
|
||||
inserted_at: now,
|
||||
updated_at: now
|
||||
}
|
||||
])
|
||||
|
||||
capture_log(fn ->
|
||||
for path <- ["/api/pleroma/admin/config", "/api/pleroma/admin/config?only_db=true"] do
|
||||
conn
|
||||
|> get(path)
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
test "db is added to settings that are in db", %{conn: conn} do
|
||||
_config = insert(:config, key: ":instance", value: [name: "Some name"])
|
||||
|
||||
|
|
|
|||
24
test/pleroma/web/api_spec/cast_and_validate_test.exs
Normal file
24
test/pleroma/web/api_spec/cast_and_validate_test.exs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ApiSpec.CastAndValidateTest do
|
||||
use Pleroma.Web.ConnCase, async: false
|
||||
|
||||
describe "permissive mode" do
|
||||
setup do: clear_config([Pleroma.Web.ApiSpec.CastAndValidate, :strict], false)
|
||||
|
||||
test "drops several unexpected query params", %{conn: conn} do
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?foo=1&bar=2&baz=3&local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
end
|
||||
|
||||
test "still rejects an invalid known param", %{conn: conn} do
|
||||
assert %{"error" => _} =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?foo=1&bar=2&limit=lots")
|
||||
|> json_response(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -3093,6 +3093,30 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
} = response
|
||||
end
|
||||
|
||||
test "context shows local-only replies to local users only" do
|
||||
poster = insert(:user)
|
||||
replier = insert(:user)
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
%{conn: remote_conn} = oauth_access(["read:statuses"], user: insert(:user, local: false))
|
||||
|
||||
{:ok, %{id: id1}} = CommonAPI.post(poster, %{status: "1"})
|
||||
|
||||
{:ok, %{id: id2}} =
|
||||
CommonAPI.post(replier, %{status: "2", visibility: "local", in_reply_to_status_id: id1})
|
||||
|
||||
assert %{"descendants" => [%{"id" => ^id2}]} =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{id1}/context")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
for conn <- [build_conn(), remote_conn] do
|
||||
assert %{"descendants" => []} =
|
||||
conn
|
||||
|> get("/api/v1/statuses/#{id1}/context")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
end
|
||||
|
||||
test "context doesn't leak priv posts" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
stranger = insert(:user)
|
||||
|
|
|
|||
|
|
@ -252,22 +252,27 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do
|
|||
assert redirected_to(response, 301) == media_proxy_url
|
||||
end
|
||||
|
||||
test "with `static` param and non-GIF image preview requested, " <>
|
||||
"redirects to media preview proxy URI without `static` param",
|
||||
test "with `static` param and non-GIF image preview requested, responds with a preview",
|
||||
%{
|
||||
conn: conn,
|
||||
url: url,
|
||||
media_proxy_url: media_proxy_url
|
||||
} do
|
||||
assert_dependencies_installed()
|
||||
|
||||
Tesla.Mock.mock(fn
|
||||
%{method: :head, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: "", headers: [{"content-type", "image/jpeg"}]}
|
||||
|
||||
%{method: :get, url: ^media_proxy_url} ->
|
||||
%Tesla.Env{status: 200, body: File.read!("test/fixtures/image.jpg")}
|
||||
end)
|
||||
|
||||
response = get(conn, url <> "?static=true")
|
||||
|
||||
assert response.status == 302
|
||||
assert redirected_to(response) == url
|
||||
assert response.status == 200
|
||||
assert Conn.get_resp_header(response, "content-type") == ["image/jpeg"]
|
||||
assert response.resp_body != ""
|
||||
end
|
||||
|
||||
test "with :min_content_length setting not matched by Content-Length header, " <>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue