Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into announce-validator
This commit is contained in:
commit
c7cdc553ff
579 changed files with 2556 additions and 2004 deletions
|
|
@ -140,6 +140,31 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "delete users with confirmation pending" do
|
||||
setup do
|
||||
user = insert(:user, confirmation_pending: true)
|
||||
{:ok, delete_user_data, _meta} = Builder.delete(user, user.ap_id)
|
||||
{:ok, delete_user, _meta} = ActivityPub.persist(delete_user_data, local: true)
|
||||
{:ok, delete: delete_user, user: user}
|
||||
end
|
||||
|
||||
test "when activation is not required", %{delete: delete, user: user} do
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
{:ok, _, _} = SideEffects.handle(delete)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
assert User.get_cached_by_id(user.id).deactivated
|
||||
end
|
||||
|
||||
test "when activation is required", %{delete: delete, user: user} do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
{:ok, _, _} = SideEffects.handle(delete)
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
refute User.get_cached_by_id(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Undo objects" do
|
||||
setup do
|
||||
poster = insert(:user)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Auth.TOTPAuthenticatorTest do
|
||||
|
|
|
|||
|
|
@ -841,10 +841,10 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 1",
|
||||
"album" => "lain radio",
|
||||
"artist" => "lain",
|
||||
"length" => 180_000
|
||||
title: "lain radio episode 1",
|
||||
album: "lain radio",
|
||||
artist: "lain",
|
||||
length: 180_000
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
|
@ -859,11 +859,11 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
{:ok, activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 1",
|
||||
"album" => "lain radio",
|
||||
"artist" => "lain",
|
||||
"length" => 180_000,
|
||||
"visibility" => "private"
|
||||
title: "lain radio episode 1",
|
||||
album: "lain radio",
|
||||
artist: "lain",
|
||||
length: 180_000,
|
||||
visibility: "private"
|
||||
})
|
||||
|
||||
object = Object.normalize(activity)
|
||||
|
|
|
|||
|
|
@ -112,6 +112,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert user_data["source"]["privacy"] == "unlisted"
|
||||
end
|
||||
|
||||
test "updates the user's privacy", %{conn: conn} do
|
||||
conn = patch(conn, "/api/v1/accounts/update_credentials", %{source: %{privacy: "unlisted"}})
|
||||
|
||||
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"})
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
"upload_limit" => _,
|
||||
"avatar_upload_limit" => _,
|
||||
"background_upload_limit" => _,
|
||||
"banner_upload_limit" => _
|
||||
"banner_upload_limit" => _,
|
||||
"background_image" => _
|
||||
} = result
|
||||
|
||||
assert result["pleroma"]["metadata"]["features"]
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> post("/api/v1/statuses", %{
|
||||
"status" => "cofe",
|
||||
"spoiler_text" => "2hu",
|
||||
"sensitive" => "false"
|
||||
"sensitive" => "0"
|
||||
})
|
||||
|
||||
{:ok, ttl} = Cachex.ttl(:idempotency_cache, idempotency_key)
|
||||
|
|
@ -81,7 +81,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> post("/api/v1/statuses", %{
|
||||
"status" => "cofe",
|
||||
"spoiler_text" => "2hu",
|
||||
"sensitive" => "false"
|
||||
"sensitive" => 0
|
||||
})
|
||||
|
||||
assert %{"id" => second_id} = json_response(conn_two, 200)
|
||||
|
|
@ -93,7 +93,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|> post("/api/v1/statuses", %{
|
||||
"status" => "cofe",
|
||||
"spoiler_text" => "2hu",
|
||||
"sensitive" => "false"
|
||||
"sensitive" => "False"
|
||||
})
|
||||
|
||||
assert %{"id" => third_id} = json_response_and_validate_schema(conn_three, 200)
|
||||
|
|
|
|||
|
|
@ -620,14 +620,4 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
assert status.visibility == "list"
|
||||
end
|
||||
|
||||
test "successfully renders a Listen activity (pleroma extension)" do
|
||||
listen_activity = insert(:listen)
|
||||
|
||||
status = StatusView.render("listen.json", activity: listen_activity)
|
||||
|
||||
assert status.length == listen_activity.data["object"]["length"]
|
||||
assert status.title == listen_activity.data["object"]["title"]
|
||||
assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())
|
||||
end
|
||||
end
|
||||
|
|
|
|||
35
test/web/media_proxy/invalidations/http_test.exs
Normal file
35
test/web/media_proxy/invalidations/http_test.exs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
defmodule Pleroma.Web.MediaProxy.Invalidation.HttpTest do
|
||||
use ExUnit.Case
|
||||
alias Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Tesla.Mock
|
||||
|
||||
test "logs hasn't error message when request is valid" do
|
||||
mock(fn
|
||||
%{method: :purge, url: "http://example.com/media/example.jpg"} ->
|
||||
%Tesla.Env{status: 200}
|
||||
end)
|
||||
|
||||
refute capture_log(fn ->
|
||||
assert Invalidation.Http.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
%{}
|
||||
) == {:ok, "success"}
|
||||
end) =~ "Error while cache purge"
|
||||
end
|
||||
|
||||
test "it write error message in logs when request invalid" do
|
||||
mock(fn
|
||||
%{method: :purge, url: "http://example.com/media/example1.jpg"} ->
|
||||
%Tesla.Env{status: 404}
|
||||
end)
|
||||
|
||||
assert capture_log(fn ->
|
||||
assert Invalidation.Http.purge(
|
||||
["http://example.com/media/example1.jpg"],
|
||||
%{}
|
||||
) == {:ok, "success"}
|
||||
end) =~ "Error while cache purge: url - http://example.com/media/example1.jpg"
|
||||
end
|
||||
end
|
||||
20
test/web/media_proxy/invalidations/script_test.exs
Normal file
20
test/web/media_proxy/invalidations/script_test.exs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
defmodule Pleroma.Web.MediaProxy.Invalidation.ScriptTest do
|
||||
use ExUnit.Case
|
||||
alias Pleroma.Web.MediaProxy.Invalidation
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
|
||||
test "it logger error when script not found" do
|
||||
assert capture_log(fn ->
|
||||
assert Invalidation.Script.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
%{script_path: "./example"}
|
||||
) == {:error, "\"%ErlangError{original: :enoent}\""}
|
||||
end) =~ "Error while cache purge: \"%ErlangError{original: :enoent}\""
|
||||
|
||||
assert Invalidation.Script.purge(
|
||||
["http://example.com/media/example.jpg"],
|
||||
%{}
|
||||
) == {:error, "not found script path"}
|
||||
end
|
||||
end
|
||||
|
|
@ -16,9 +16,12 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
filename: "sound.mp3"
|
||||
}
|
||||
|
||||
ret_conn = put(conn, "/api/v1/pleroma/mascot", %{"file" => non_image_file})
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put("/api/v1/pleroma/mascot", %{"file" => non_image_file})
|
||||
|
||||
assert json_response(ret_conn, 415)
|
||||
assert json_response_and_validate_schema(ret_conn, 415)
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
|
|
@ -26,9 +29,12 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
conn = put(conn, "/api/v1/pleroma/mascot", %{"file" => file})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put("/api/v1/pleroma/mascot", %{"file" => file})
|
||||
|
||||
assert %{"id" => _, "type" => image} = json_response(conn, 200)
|
||||
assert %{"id" => _, "type" => image} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "mascot retrieving" do
|
||||
|
|
@ -37,7 +43,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
# When user hasn't set a mascot, we should just get pleroma tan back
|
||||
ret_conn = get(conn, "/api/v1/pleroma/mascot")
|
||||
|
||||
assert %{"url" => url} = json_response(ret_conn, 200)
|
||||
assert %{"url" => url} = json_response_and_validate_schema(ret_conn, 200)
|
||||
assert url =~ "pleroma-fox-tan-smol"
|
||||
|
||||
# When a user sets their mascot, we should get that back
|
||||
|
|
@ -47,9 +53,12 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
ret_conn = put(conn, "/api/v1/pleroma/mascot", %{"file" => file})
|
||||
ret_conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put("/api/v1/pleroma/mascot", %{"file" => file})
|
||||
|
||||
assert json_response(ret_conn, 200)
|
||||
assert json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
|
|
@ -58,7 +67,7 @@ defmodule Pleroma.Web.PleromaAPI.MascotControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> get("/api/v1/pleroma/mascot")
|
||||
|
||||
assert %{"url" => url, "type" => "image"} = json_response(conn, 200)
|
||||
assert %{"url" => url, "type" => "image"} = json_response_and_validate_schema(conn, 200)
|
||||
assert url =~ "an_image"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,14 +12,16 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
|
|||
%{conn: conn} = oauth_access(["write"])
|
||||
|
||||
conn =
|
||||
post(conn, "/api/v1/pleroma/scrobble", %{
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/scrobble", %{
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio",
|
||||
"length" => "180000"
|
||||
})
|
||||
|
||||
assert %{"title" => "lain radio episode 1"} = json_response(conn, 200)
|
||||
assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -29,28 +31,28 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
|
|||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 1",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio"
|
||||
title: "lain radio episode 1",
|
||||
artist: "lain",
|
||||
album: "lain radio"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 2",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio"
|
||||
title: "lain radio episode 2",
|
||||
artist: "lain",
|
||||
album: "lain radio"
|
||||
})
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.listen(user, %{
|
||||
"title" => "lain radio episode 3",
|
||||
"artist" => "lain",
|
||||
"album" => "lain radio"
|
||||
title: "lain radio episode 3",
|
||||
artist: "lain",
|
||||
album: "lain radio"
|
||||
})
|
||||
|
||||
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")
|
||||
|
||||
result = json_response(conn, 200)
|
||||
result = json_response_and_validate_schema(conn, 200)
|
||||
|
||||
assert length(result) == 3
|
||||
end
|
||||
|
|
|
|||
20
test/web/pleroma_api/views/scrobble_view_test.exs
Normal file
20
test/web/pleroma_api/views/scrobble_view_test.exs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.PleromaAPI.StatusViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Web.PleromaAPI.ScrobbleView
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "successfully renders a Listen activity (pleroma extension)" do
|
||||
listen_activity = insert(:listen)
|
||||
|
||||
status = ScrobbleView.render("show.json", activity: listen_activity)
|
||||
|
||||
assert status.length == listen_activity.data["object"]["length"]
|
||||
assert status.title == listen_activity.data["object"]["title"]
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue