Switch to verified routes inside tests

This commit is contained in:
FloatingGhost 2023-08-14 10:47:07 +01:00
parent 0c9883a033
commit bb6f367d39
37 changed files with 125 additions and 175 deletions

View file

@ -11,6 +11,7 @@ defmodule Mix.Tasks.Pleroma.User do
alias Pleroma.UserInviteToken alias Pleroma.UserInviteToken
alias Pleroma.Web.ActivityPub.Builder alias Pleroma.Web.ActivityPub.Builder
alias Pleroma.Web.ActivityPub.Pipeline alias Pleroma.Web.ActivityPub.Pipeline
use Pleroma.Web, :verified_routes
@shortdoc "Manages Pleroma users" @shortdoc "Manages Pleroma users"
@moduledoc File.read!("docs/docs/administration/CLI_tasks/user.md") @moduledoc File.read!("docs/docs/administration/CLI_tasks/user.md")
@ -113,11 +114,7 @@ def run(["reset_password", nickname]) do
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do {:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
shell_info("Generated password reset token for #{user.nickname}") shell_info("Generated password reset token for #{user.nickname}")
IO.puts( IO.puts("URL: #{~p[/api/v1/pleroma/password_reset/#{token.token}]}")
"URL: #{Pleroma.Web.Router.Helpers.reset_password_url(Pleroma.Web.Endpoint,
:reset,
token.token)}"
)
else else
_ -> _ ->
shell_error("No local user #{nickname}") shell_error("No local user #{nickname}")
@ -303,13 +300,7 @@ def run(["invite" | rest]) do
{:ok, invite} <- UserInviteToken.create_invite(options) do {:ok, invite} <- UserInviteToken.create_invite(options) do
shell_info("Generated user invite token " <> String.replace(invite.invite_type, "_", " ")) shell_info("Generated user invite token " <> String.replace(invite.invite_type, "_", " "))
url = url = ~p[/registration/#{invite.token}]
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
invite.token
)
IO.puts(url) IO.puts(url)
else else
error -> error ->

View file

@ -6,10 +6,13 @@ defmodule Pleroma.Emails.AdminEmail do
@moduledoc "Admin emails" @moduledoc "Admin emails"
import Swoosh.Email import Swoosh.Email
use Pleroma.Web, :mailer
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.HTML alias Pleroma.HTML
alias Pleroma.Web.Router.Helpers
use Phoenix.VerifiedRoutes,
endpoint: Pleroma.Web.Endpoint,
router: Pleroma.Web.Router
defp instance_config, do: Config.get(:instance) defp instance_config, do: Config.get(:instance)
defp instance_name, do: instance_config()[:name] defp instance_name, do: instance_config()[:name]
@ -45,7 +48,7 @@ def report(to, reporter, account, statuses, comment) do
statuses statuses
|> Enum.map(fn |> Enum.map(fn
%{id: id} -> %{id: id} ->
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, id) status_url = url(~p[/notice/#{id}])
"<li><a href=\"#{status_url}\">#{status_url}</li>" "<li><a href=\"#{status_url}\">#{status_url}</li>"
%{"id" => id} when is_binary(id) -> %{"id" => id} when is_binary(id) ->

View file

@ -6,12 +6,11 @@ defmodule Pleroma.Emails.UserEmail do
@moduledoc "User emails" @moduledoc "User emails"
require Pleroma.Web.Gettext require Pleroma.Web.Gettext
use Pleroma.Web, :mailer
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Gettext alias Pleroma.Web.Gettext
alias Pleroma.Web.Router
import Swoosh.Email import Swoosh.Email
import Phoenix.Swoosh, except: [render_body: 3] import Phoenix.Swoosh, except: [render_body: 3]
@ -75,7 +74,7 @@ def welcome(user, opts \\ %{}) do
def password_reset_email(user, token) when is_binary(token) do def password_reset_email(user, token) when is_binary(token) do
Gettext.with_locale_or_default user.language do Gettext.with_locale_or_default user.language do
password_reset_url = Router.Helpers.reset_password_url(Endpoint, :reset, token) password_reset_url = ~p[/api/v1/pleroma/password_reset/#{token}]
html_body = html_body =
Gettext.dpgettext( Gettext.dpgettext(
@ -108,12 +107,7 @@ def user_invitation_email(
to_name \\ nil to_name \\ nil
) do ) do
Gettext.with_locale_or_default user.language do Gettext.with_locale_or_default user.language do
registration_url = registration_url = ~p[/registration/#{user_invite_token.token}]
Router.Helpers.redirect_url(
Endpoint,
:registration_page,
user_invite_token.token
)
html_body = html_body =
Gettext.dpgettext( Gettext.dpgettext(
@ -146,13 +140,7 @@ def user_invitation_email(
def account_confirmation_email(user) do def account_confirmation_email(user) do
Gettext.with_locale_or_default user.language do Gettext.with_locale_or_default user.language do
confirmation_url = confirmation_url = ~p[/api/account/confirm_email/#{user.id}/#{user.confirmation_token}]
Router.Helpers.confirm_email_url(
Endpoint,
:confirm_email,
user.id,
to_string(user.confirmation_token)
)
html_body = html_body =
Gettext.dpgettext( Gettext.dpgettext(
@ -342,7 +330,7 @@ def unsubscribe_url(user, notifications_type) do
|> Pleroma.JWT.generate_and_sign!() |> Pleroma.JWT.generate_and_sign!()
|> Base.encode64() |> Base.encode64()
Router.Helpers.subscription_url(Endpoint, :unsubscribe, token) ~p[/mailer/unsubscribe/#{token}]
end end
def backup_is_ready_email(backup, admin_user_id \\ nil) do def backup_is_ready_email(backup, admin_user_id \\ nil) do

View file

@ -44,6 +44,8 @@ defmodule Pleroma.User do
alias Pleroma.Web.RelMe alias Pleroma.Web.RelMe
alias Pleroma.Workers.BackgroundWorker alias Pleroma.Workers.BackgroundWorker
use Pleroma.Web, :verified_routes
require Logger require Logger
@type t :: %__MODULE__{} @type t :: %__MODULE__{}
@ -2447,12 +2449,7 @@ defp validate_rel_me_field(changeset, fields, raw_fields, %User{
end end
if is_url(raw_value) do if is_url(raw_value) do
frontend_url = frontend_url = ~p[/#{nickname}]
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:redirector_with_meta,
nickname
)
possible_urls = [ap_id, frontend_url] possible_urls = [ap_id, frontend_url]

View file

@ -38,8 +38,6 @@ def controller do
import Pleroma.Web.Gettext import Pleroma.Web.Gettext
import Pleroma.Web.TranslationHelpers import Pleroma.Web.TranslationHelpers
alias Pleroma.Web.Router.Helpers, as: Routes
unquote(verified_routes()) unquote(verified_routes())
plug(:set_put_layout) plug(:set_put_layout)
@ -224,7 +222,7 @@ def component do
def router do def router do
quote do quote do
use Phoenix.Router use Phoenix.Router, helpers: false
import Plug.Conn import Plug.Conn
import Phoenix.Controller import Phoenix.Controller
@ -252,7 +250,6 @@ defp view_helpers do
import Pleroma.Web.ErrorHelpers import Pleroma.Web.ErrorHelpers
import Pleroma.Web.Gettext import Pleroma.Web.Gettext
alias Pleroma.Web.Router.Helpers, as: Routes
unquote(verified_routes()) unquote(verified_routes())
end end
end end
@ -268,6 +265,12 @@ def verified_routes do
end end
end end
def mailer do
quote do
unquote(verified_routes())
end
end
@doc """ @doc """
When used, dispatch to the appropriate controller/view/etc. When used, dispatch to the appropriate controller/view/etc.
""" """

View file

@ -18,6 +18,8 @@ defmodule Pleroma.Web.ActivityPub.Builder do
alias Pleroma.Web.CommonAPI.ActivityDraft alias Pleroma.Web.CommonAPI.ActivityDraft
alias Pleroma.Web.Endpoint alias Pleroma.Web.Endpoint
use Pleroma.Web, :verified_routes
require Pleroma.Constants require Pleroma.Constants
def accept_or_reject(actor, activity, type) do def accept_or_reject(actor, activity, type) do
@ -402,6 +404,6 @@ def unpin(%User{} = user, object) do
end end
defp pinned_url(nickname) when is_binary(nickname) do defp pinned_url(nickname) when is_binary(nickname) do
Pleroma.Web.Router.Helpers.activity_pub_url(Pleroma.Web.Endpoint, :pinned, nickname) url(~p[/users/#{nickname}/collections/featured])
end end
end end

View file

@ -16,10 +16,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.Endpoint alias Pleroma.Web.Endpoint
alias Pleroma.Web.Router.Helpers
import Ecto.Query import Ecto.Query
use Pleroma.Web, :verified_routes
require Logger require Logger
require Pleroma.Constants require Pleroma.Constants
@ -124,19 +125,15 @@ def make_date do
end end
def generate_activity_id do def generate_activity_id do
generate_id("activities") url(~p[/activities/#{UUID.generate()}])
end end
def generate_context_id do def generate_context_id do
generate_id("contexts") url(~p[/contexts/#{UUID.generate()}])
end end
def generate_object_id do def generate_object_id do
Helpers.o_status_url(Endpoint, :object, UUID.generate()) url(~p[/objects/#{UUID.generate()}])
end
def generate_id(type) do
"#{Endpoint.url()}/#{type}/#{UUID.generate()}"
end end
def get_notified_from_object(%{"type" => type} = object) when type in @supported_object_types do def get_notified_from_object(%{"type" => type} = object) when type in @supported_object_types do
@ -154,7 +151,7 @@ def get_notified_from_object(object) do
Notification.get_notified_from_activity(%Activity{data: object}, false) Notification.get_notified_from_activity(%Activity{data: object}, false)
end end
def maybe_create_context(context), do: context || generate_id("contexts") def maybe_create_context(context), do: context || generate_context_id()
@doc """ @doc """
Enqueues an activity for federation if it's local Enqueues an activity for federation if it's local

View file

@ -12,24 +12,22 @@ defmodule Pleroma.Web.ActivityPub.UserView do
alias Pleroma.Web.ActivityPub.ObjectView alias Pleroma.Web.ActivityPub.ObjectView
alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Router.Helpers
require Pleroma.Web.ActivityPub.Transmogrifier require Pleroma.Web.ActivityPub.Transmogrifier
import Ecto.Query import Ecto.Query
def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do
%{"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)} %{"sharedInbox" => ~p"/inbox"}
end end
def render("endpoints.json", %{user: %User{local: true} = _user}) do def render("endpoints.json", %{user: %User{local: true} = _user}) do
%{ %{
"oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize), "oauthAuthorizationEndpoint" => ~p"/oauth/authorize",
"oauthRegistrationEndpoint" => Helpers.app_url(Endpoint, :create), "oauthRegistrationEndpoint" => ~p"/api/v1/apps",
"oauthTokenEndpoint" => Helpers.o_auth_url(Endpoint, :token_exchange), "oauthTokenEndpoint" => ~p"/oauth/token",
"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox), "sharedInbox" => ~p"/inbox",
"uploadMedia" => Helpers.activity_pub_url(Endpoint, :upload_media) "uploadMedia" => ~p"/api/ap/upload_media"
} }
end end

View file

@ -17,9 +17,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIController do
alias Pleroma.Web.AdminAPI alias Pleroma.Web.AdminAPI
alias Pleroma.Web.AdminAPI.AccountView alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.AdminAPI.ModerationLogView alias Pleroma.Web.AdminAPI.ModerationLogView
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug
alias Pleroma.Web.Router
@users_page_size 50 @users_page_size 50
@ -256,7 +254,7 @@ def get_password_reset(conn, %{"nickname" => nickname}) do
conn conn
|> json(%{ |> json(%{
token: token.token, token: token.token,
link: Router.Helpers.reset_password_url(Endpoint, :reset, token.token) link: ~p[/api/v1/pleroma/password_reset/#{token.token}]
}) })
end end

View file

@ -54,12 +54,7 @@ def login(conn, params) do
defp redirect_to_oauth_form(conn, _params) do defp redirect_to_oauth_form(conn, _params) do
with {:ok, app} <- local_mastofe_app() do with {:ok, app} <- local_mastofe_app() do
path = path =
Routes.o_auth_path(conn, :authorize, ~p[/oauth/authorize?#{[response_type: "code", client_id: app.client_id, redirect_uri: ".", scope: Enum.join(app.scopes, " ")]}]
response_type: "code",
client_id: app.client_id,
redirect_uri: ".",
scope: Enum.join(app.scopes, " ")
)
redirect(conn, to: path) redirect(conn, to: path)
end end

View file

@ -322,7 +322,7 @@ def render("show.json", %{activity: %{id: id, data: %{"object" => _object}} = ac
url = url =
if user.local do if user.local do
Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity) url(~p[/notice/#{activity}])
else else
object.data["url"] || object.data["external_url"] || object.data["id"] object.data["url"] || object.data["external_url"] || object.data["id"]
end end

View file

@ -1,7 +1,6 @@
defmodule Pleroma.Web.MastodonAPI.TagView do defmodule Pleroma.Web.MastodonAPI.TagView do
use Pleroma.Web, :view use Pleroma.Web, :view
alias Pleroma.User alias Pleroma.User
alias Pleroma.Web.Router.Helpers
def render("index.json", %{tags: tags, for_user: user}) do def render("index.json", %{tags: tags, for_user: user}) do
render_many(tags, __MODULE__, "show.json", %{for_user: user}) render_many(tags, __MODULE__, "show.json", %{for_user: user})
@ -17,7 +16,7 @@ def render("show.json", %{tag: tag, for_user: user}) do
%{ %{
name: tag.name, name: tag.name,
url: Helpers.tag_feed_url(Pleroma.Web.Endpoint, :feed, tag.name), url: url(~p[/tags/#{tag.name}]),
history: [], history: [],
following: following following: following
} }

View file

@ -3,9 +3,9 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.Feed do defmodule Pleroma.Web.Metadata.Providers.Feed do
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Metadata.Providers.Provider alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.Router.Helpers
use Pleroma.Web, :verified_routes
@behaviour Provider @behaviour Provider
@ -16,7 +16,7 @@ def build_tags(%{user: user}) do
[ [
rel: "alternate", rel: "alternate",
type: "application/atom+xml", type: "application/atom+xml",
href: Helpers.user_feed_path(Endpoint, :feed, user.nickname) <> ".atom" href: ~p[/users/#{user.nickname}/feed.atom]
], []} ], []}
] ]
end end

View file

@ -10,6 +10,8 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
alias Pleroma.Web.Metadata.Providers.Provider alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.Metadata.Utils alias Pleroma.Web.Metadata.Utils
use Pleroma.Web, :verified_routes
@behaviour Provider @behaviour Provider
@media_types ["image", "audio", "video"] @media_types ["image", "audio", "video"]
@ -112,7 +114,7 @@ defp build_attachments(id, %{data: %{"attachment" => attachments}}) do
defp build_attachments(_id, _object), do: [] defp build_attachments(_id, _object), do: []
defp player_url(id) do defp player_url(id) do
Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice_player, id) url(~p[/notice/#{id}/embed_player])
end end
# Videos have problems without dimensions, but we used to not provide WxH for images. # Videos have problems without dimensions, but we used to not provide WxH for images.

View file

@ -14,7 +14,6 @@ defmodule Pleroma.Web.OStatus.OStatusController do
alias Pleroma.Web.Fallback.RedirectController alias Pleroma.Web.Fallback.RedirectController
alias Pleroma.Web.Metadata.PlayerView alias Pleroma.Web.Metadata.PlayerView
alias Pleroma.Web.Plugs.RateLimiter alias Pleroma.Web.Plugs.RateLimiter
alias Pleroma.Web.Router
plug( plug(
RateLimiter, RateLimiter,
@ -87,7 +86,7 @@ def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
%{ %{
activity_id: activity.id, activity_id: activity.id,
object: object, object: object,
url: Router.Helpers.o_status_url(Endpoint, :notice, activity.id), url: url(~p[/notice/#{activity.id}]),
user: user user: user
} }
) )

View file

@ -5,8 +5,9 @@
defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
import Plug.Conn import Plug.Conn
import Phoenix.Controller, only: [get_format: 1] import Phoenix.Controller, only: [get_format: 1]
use Pleroma.Web, :verified_routes
alias Pleroma.Activity alias Pleroma.Activity
alias Pleroma.Web.Router
alias Pleroma.Signature alias Pleroma.Signature
alias Pleroma.Instances alias Pleroma.Instances
require Logger require Logger
@ -32,7 +33,7 @@ def call(conn, _opts) do
end end
def route_aliases(%{path_info: ["objects", id], query_string: query_string}) do def route_aliases(%{path_info: ["objects", id], query_string: query_string}) do
ap_id = Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :object, id) ap_id = ~p[/objects/#{id}]
with %Activity{} = activity <- Activity.get_by_object_ap_id_with_object(ap_id) do with %Activity{} = activity <- Activity.get_by_object_ap_id_with_object(ap_id) do
["/notice/#{activity.id}", "/notice/#{activity.id}?#{query_string}"] ["/notice/#{activity.id}", "/notice/#{activity.id}?#{query_string}"]

View file

@ -11,7 +11,6 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Visibility alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.Metadata alias Pleroma.Web.Metadata
alias Pleroma.Web.Router.Helpers
plug(:put_layout, :static_fe) plug(:put_layout, :static_fe)
plug(:assign_id) plug(:assign_id)
@ -111,11 +110,11 @@ def show(%{assigns: %{username_or_id: username_or_id, tab: tab}} = conn, params)
end end
def show(%{assigns: %{object_id: _}} = conn, _params) do def show(%{assigns: %{object_id: _}} = conn, _params) do
url = Helpers.url(conn) <> conn.request_path url = conn.url <> conn.request_path
case Activity.get_create_by_object_ap_id_with_object(url) do case Activity.get_create_by_object_ap_id_with_object(url) do
%Activity{} = activity -> %Activity{} = activity ->
to = Helpers.o_status_path(Pleroma.Web.Endpoint, :notice, activity) to = ~p[/notice/#{activity}]
redirect(conn, to: to) redirect(conn, to: to)
_ -> _ ->
@ -124,11 +123,11 @@ def show(%{assigns: %{object_id: _}} = conn, _params) do
end end
def show(%{assigns: %{activity_id: _}} = conn, _params) do def show(%{assigns: %{activity_id: _}} = conn, _params) do
url = Helpers.url(conn) <> conn.request_path url = conn.url <> conn.request_path
case Activity.get_by_ap_id(url) do case Activity.get_by_ap_id(url) do
%Activity{} = activity -> %Activity{} = activity ->
to = Helpers.o_status_path(Pleroma.Web.Endpoint, :notice, activity) to = ~p[/notice/#{activity}]
redirect(conn, to: to) redirect(conn, to: to)
_ -> _ ->
@ -167,7 +166,7 @@ defp represent(%Activity{object: %Object{data: data}} = activity, selected) do
link = link =
case user.local do case user.local do
true -> Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity) true -> ~p[/notice/#{activity}]
_ -> data["url"] || data["external_url"] || data["id"] _ -> data["url"] || data["external_url"] || data["id"]
end end

View file

@ -11,7 +11,6 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
alias Pleroma.Web.Gettext alias Pleroma.Web.Gettext
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
alias Pleroma.Web.Metadata.Utils alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router.Helpers
use Phoenix.HTML use Phoenix.HTML

View file

@ -36,7 +36,7 @@
</div> </div>
</div> </div>
<div class="remote-follow"> <div class="remote-follow">
<form method="POST" action="<%= Helpers.util_path(@conn, :remote_subscribe) %>"> <form method="POST" action="<%= ~p"/main/ostatus" %>">
<input type="hidden" name="nickname" value="<%= @user.nickname %>"> <input type="hidden" name="nickname" value="<%= @user.nickname %>">
<input type="hidden" name="profile" value=""> <input type="hidden" name="profile" value="">
<button type="submit" class="button-default"><%= Gettext.dpgettext("static_pages", "static fe profile page remote follow button", "Remote follow") %></button> <button type="submit" class="button-default"><%= Gettext.dpgettext("static_pages", "static fe profile page remote follow button", "Remote follow") %></button>

View file

@ -13,7 +13,6 @@ defmodule Pleroma.Web.EmbedView do
alias Pleroma.Web.Gettext alias Pleroma.Web.Gettext
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
alias Pleroma.Web.Metadata.Utils alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router.Helpers
import Phoenix.HTML import Phoenix.HTML
@ -48,7 +47,7 @@ defp activity_content(%Activity{object: %Object{data: %{"content" => content}}})
defp activity_content(_), do: nil defp activity_content(_), do: nil
defp activity_url(%User{local: true}, activity) do defp activity_url(%User{local: true}, activity) do
Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity) ~p[/notice/#{activity}]
end end
defp activity_url(%User{local: false}, %Activity{object: %Object{data: data}}) do defp activity_url(%User{local: false}, %Activity{object: %Object{data: data}}) do

View file

@ -7,7 +7,6 @@ defmodule Pleroma.Emails.AdminEmailTest do
import Pleroma.Factory import Pleroma.Factory
alias Pleroma.Emails.AdminEmail alias Pleroma.Emails.AdminEmail
alias Pleroma.Web.Router.Helpers
test "build report email" do test "build report email" do
config = Pleroma.Config.get(:instance) config = Pleroma.Config.get(:instance)
@ -18,7 +17,7 @@ test "build report email" do
res = res =
AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment") AdminEmail.report(to_user, reporter, account, [%{name: "Test", id: "12"}], "Test comment")
status_url = Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, "12") status_url = url(~p[/notice/12])
reporter_url = reporter.ap_id reporter_url = reporter.ap_id
account_url = account.ap_id account_url = account.ap_id

View file

@ -6,8 +6,6 @@ defmodule Pleroma.Emails.UserEmailTest do
use Pleroma.DataCase, async: true use Pleroma.DataCase, async: true
alias Pleroma.Emails.UserEmail alias Pleroma.Emails.UserEmail
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Router
import Pleroma.Factory import Pleroma.Factory
@ -18,7 +16,7 @@ test "build password reset email" do
assert email.from == {config[:name], config[:notify_email]} assert email.from == {config[:name], config[:notify_email]}
assert email.to == [{user.name, user.email}] assert email.to == [{user.name, user.email}]
assert email.subject == "Password reset" assert email.subject == "Password reset"
assert email.html_body =~ Router.Helpers.reset_password_url(Endpoint, :reset, "test_token") assert email.html_body =~ ~p"/api/v1/pleroma/password_reset/test_token"
end end
test "build user invitation email" do test "build user invitation email" do
@ -30,8 +28,7 @@ test "build user invitation email" do
assert email.subject == "Invitation to Akkoma" assert email.subject == "Invitation to Akkoma"
assert email.to == [{"Jonh", "test@test.com"}] assert email.to == [{"Jonh", "test@test.com"}]
assert email.html_body =~ assert email.html_body =~ ~p[/registration/#{token.token}]
Router.Helpers.redirect_url(Endpoint, :registration_page, token.token)
end end
test "build account confirmation email" do test "build account confirmation email" do
@ -42,8 +39,7 @@ test "build account confirmation email" do
assert email.to == [{user.name, user.email}] assert email.to == [{user.name, user.email}]
assert email.subject == "#{config[:name]} account confirmation" assert email.subject == "#{config[:name]} account confirmation"
assert email.html_body =~ assert email.html_body =~ ~p[/account/confirm_email/#{user.id}/conf-token]
Router.Helpers.confirm_email_url(Endpoint, :confirm_email, user.id, "conf-token")
end end
test "build approval pending email" do test "build approval pending email" do

View file

@ -31,10 +31,9 @@ test "within/2 captures local bindings and executes block on remote node" do
test "runs webserver on customized port" do test "runs webserver on customized port" do
{nickname, url, url_404} = {nickname, url, url_404} =
within @federated1 do within @federated1 do
import Pleroma.Web.Router.Helpers
user = Pleroma.Factory.insert(:user) user = Pleroma.Factory.insert(:user)
user_url = account_url(Pleroma.Web.Endpoint, :show, user) user_url = ~p[/api/v1/accounts/#{user}]
url_404 = account_url(Pleroma.Web.Endpoint, :show, "not-exists") url_404 = ~p"/api/v1/accounts/not-exists"
{user.nickname, user_url, url_404} {user.nickname, user_url, url_404}
end end

View file

@ -1004,23 +1004,13 @@ test "it doesn't fail on invalid alsoKnownAs entries" do
test "returns an ap_id for a user" do test "returns an ap_id for a user" do
user = insert(:user) user = insert(:user)
assert User.ap_id(user) == assert User.ap_id(user) == url(@endpoint, ~p[/users/#{user.nickname}])
Pleroma.Web.Router.Helpers.user_feed_url(
Pleroma.Web.Endpoint,
:feed_redirect,
user.nickname
)
end end
test "returns an ap_followers link for a user" do test "returns an ap_followers link for a user" do
user = insert(:user) user = insert(:user)
assert User.ap_followers(user) == assert User.ap_followers(user) == url(@endpoint, ~p[/users/#{user.nickname}/followers])
Pleroma.Web.Router.Helpers.user_feed_url(
Pleroma.Web.Endpoint,
:feed_redirect,
user.nickname
) <> "/followers"
end end
describe "remote user changeset" do describe "remote user changeset" do

View file

@ -39,7 +39,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "with the relay active, it returns the relay user", %{conn: conn} do test "with the relay active, it returns the relay user", %{conn: conn} do
res = res =
conn conn
|> get(activity_pub_path(conn, :relay)) |> get(~p"/relay")
|> json_response(200) |> json_response(200)
assert res["id"] =~ "/relay" assert res["id"] =~ "/relay"
@ -49,7 +49,7 @@ test "with the relay disabled, it returns 404", %{conn: conn} do
clear_config([:instance, :allow_relay], false) clear_config([:instance, :allow_relay], false)
conn conn
|> get(activity_pub_path(conn, :relay)) |> get(~p"/relay")
|> json_response(404) |> json_response(404)
end end
@ -59,7 +59,7 @@ test "on non-federating instance, it returns 404", %{conn: conn} do
conn conn
|> assign(:user, user) |> assign(:user, user)
|> get(activity_pub_path(conn, :relay)) |> get(~p"/relay")
|> json_response(404) |> json_response(404)
end end
end end
@ -68,7 +68,7 @@ test "on non-federating instance, it returns 404", %{conn: conn} do
test "it returns the internal fetch user", %{conn: conn} do test "it returns the internal fetch user", %{conn: conn} do
res = res =
conn conn
|> get(activity_pub_path(conn, :internal_fetch)) |> get(~p"/internal/fetch")
|> json_response(200) |> json_response(200)
assert res["id"] =~ "/fetch" assert res["id"] =~ "/fetch"
@ -80,7 +80,7 @@ test "on non-federating instance, it returns 404", %{conn: conn} do
conn conn
|> assign(:user, user) |> assign(:user, user)
|> get(activity_pub_path(conn, :internal_fetch)) |> get(~p"/internal/fetch")
|> json_response(404) |> json_response(404)
end end
end end

View file

@ -212,7 +212,7 @@ test "updates state of multiple reports", %{
test "returns empty response when no reports created", %{conn: conn} do test "returns empty response when no reports created", %{conn: conn} do
response = response =
conn conn
|> get(report_path(conn, :index)) |> get(~p"/api/v1/pleroma/admin/reports")
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
assert Enum.empty?(response["reports"]) assert Enum.empty?(response["reports"])
@ -232,7 +232,7 @@ test "returns reports", %{conn: conn} do
response = response =
conn conn
|> get(report_path(conn, :index)) |> get(~p"/api/v1/pleroma/admin/reports")
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
[report] = response["reports"] [report] = response["reports"]
@ -264,7 +264,7 @@ test "returns reports with specified state", %{conn: conn} do
response = response =
conn conn
|> get(report_path(conn, :index, %{state: "open"})) |> get(~p[/api/v1/pleroma/admin/reports?#{[state: "open"]}])
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
assert [open_report] = response["reports"] assert [open_report] = response["reports"]
@ -276,7 +276,7 @@ test "returns reports with specified state", %{conn: conn} do
response = response =
conn conn
|> get(report_path(conn, :index, %{state: "closed"})) |> get(~p[/api/v1/pleroma/admin/reports?#{[state: "closed"]}])
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
assert [closed_report] = response["reports"] assert [closed_report] = response["reports"]
@ -288,7 +288,7 @@ test "returns reports with specified state", %{conn: conn} do
assert %{"total" => 0, "reports" => []} == assert %{"total" => 0, "reports" => []} ==
conn conn
|> get(report_path(conn, :index, %{state: "resolved"})) |> get(~p[/api/v1/pleroma/admin/reports?#{[state: "resolved"]}])
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
end end

View file

@ -685,7 +685,7 @@ test "load users with actor_type is Person", %{admin: admin, conn: conn} do
response = response =
conn conn
|> get(user_path(conn, :index), %{actor_types: ["Person"]}) |> get(~p"/api/v1/pleroma/admin/users", %{actor_types: ["Person"]})
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
users = [ users = [
@ -706,7 +706,7 @@ test "load users with actor_type is Person and Service", %{admin: admin, conn: c
response = response =
conn conn
|> get(user_path(conn, :index), %{actor_types: ["Person", "Service"]}) |> get(~p"/api/v1/pleroma/admin/users", %{actor_types: ["Person", "Service"]})
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
users = [ users = [
@ -727,7 +727,7 @@ test "load users with actor_type is Service", %{conn: conn} do
response = response =
conn conn
|> get(user_path(conn, :index), %{actor_types: ["Service"]}) |> get(~p"/api/v1/pleroma/admin/users", %{actor_types: ["Service"]})
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
users = [user_response(user_service, %{"actor_type" => "Service"})] users = [user_response(user_service, %{"actor_type" => "Service"})]

View file

@ -50,7 +50,7 @@ test "gets a feed (ATOM)", %{conn: conn} do
response = response =
conn conn
|> put_req_header("accept", "application/atom+xml") |> put_req_header("accept", "application/atom+xml")
|> get(tag_feed_path(conn, :feed, "pleromaart.atom")) |> get(~p"/tags/pleromaart.atom")
|> response(200) |> response(200)
xml = parse(response) xml = parse(response)
@ -117,7 +117,7 @@ test "gets a feed (RSS)", %{conn: conn} do
response = response =
conn conn
|> put_req_header("accept", "application/rss+xml") |> put_req_header("accept", "application/rss+xml")
|> get(tag_feed_path(conn, :feed, "pleromaart.rss")) |> get(~p"/tags/pleromaart.rss")
|> response(200) |> response(200)
xml = parse(response) xml = parse(response)
@ -157,7 +157,7 @@ test "gets a feed (RSS)", %{conn: conn} do
response = response =
conn conn
|> put_req_header("accept", "application/rss+xml") |> put_req_header("accept", "application/rss+xml")
|> get(tag_feed_path(conn, :feed, "pleromaart.rss")) |> get(~p"/tags/pleromaart.rss")
|> response(200) |> response(200)
xml = parse(response) xml = parse(response)
@ -188,7 +188,7 @@ test "gets a feed (RSS)", %{conn: conn} do
test "returns 404 for tags feed", %{conn: conn} do test "returns 404 for tags feed", %{conn: conn} do
conn conn
|> put_req_header("accept", "application/rss+xml") |> put_req_header("accept", "application/rss+xml")
|> get(tag_feed_path(conn, :feed, "pleromaart.rss")) |> get(~p"/tags/pleromaart.rss")
|> response(404) |> response(404)
end end
end end

View file

@ -66,7 +66,7 @@ test "gets an atom feed", %{conn: conn, user: user, object: object, max_id: max_
resp = resp =
conn conn
|> put_req_header("accept", "application/atom+xml") |> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname)) |> get(~p[/users/#{user.nickname}/feed])
|> response(200) |> response(200)
activity_titles = activity_titles =
@ -128,7 +128,7 @@ test "returns 404 for a missing feed", %{conn: conn} do
conn = conn =
conn conn
|> put_req_header("accept", "application/atom+xml") |> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, "nonexisting")) |> get(~p"/users/nonexisting/feed")
assert response(conn, 404) assert response(conn, 404)
end end
@ -144,7 +144,7 @@ test "returns feed with public and unlisted activities", %{conn: conn} do
resp = resp =
conn conn
|> put_req_header("accept", "application/atom+xml") |> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname)) |> get(~p[/users/#{user.nickname}/feed])
|> response(200) |> response(200)
activity_titles = activity_titles =
@ -163,7 +163,7 @@ test "returns 404 when the user is remote", %{conn: conn} do
assert conn assert conn
|> put_req_header("accept", "application/atom+xml") |> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname)) |> get(~p[/users/#{user.nickname}/feed])
|> response(404) |> response(404)
end end
@ -240,7 +240,7 @@ test "with non-html / non-json format, it returns error when user is not found",
response = response =
conn conn
|> put_req_header("accept", "application/xml") |> put_req_header("accept", "application/xml")
|> get(user_feed_path(conn, :feed, "jimm")) |> get(~p"/users/jimm/feed")
|> response(404) |> response(404)
assert response == ~S({"error":"Not found"}) assert response == ~S({"error":"Not found"})
@ -258,7 +258,7 @@ test "returns 404 for user feed", %{conn: conn} do
assert conn assert conn
|> put_req_header("accept", "application/atom+xml") |> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname)) |> get(~p[/users/#{user.nickname}/feed])
|> response(404) |> response(404)
end end
end end

View file

@ -258,7 +258,7 @@ test "a note activity" do
expected = %{ expected = %{
id: to_string(note.id), id: to_string(note.id),
uri: object_data["id"], uri: object_data["id"],
url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note), url: ~p[/notice/#{note}],
account: AccountView.render("show.json", %{user: user, skip_visibility_check: true}), account: AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
in_reply_to_id: nil, in_reply_to_id: nil,
in_reply_to_account_id: nil, in_reply_to_account_id: nil,

View file

@ -12,7 +12,6 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
alias Pleroma.Web.Metadata.Providers.TwitterCard alias Pleroma.Web.Metadata.Providers.TwitterCard
alias Pleroma.Web.Metadata.Utils alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw]) setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
@ -189,7 +188,7 @@ test "it renders supported types of attachments and skips unknown types" do
{:meta, {:meta,
[ [
name: "twitter:player", name: "twitter:player",
content: Router.Helpers.o_status_url(Endpoint, :notice_player, activity.id) content: url(Endpoint, ~p[/notice/#{activity.id}/embed_player])
], []}, ], []},
{:meta, [name: "twitter:player:width", content: "800"], []}, {:meta, [name: "twitter:player:width", content: "800"], []},
{:meta, [name: "twitter:player:height", content: "600"], []}, {:meta, [name: "twitter:player:height", content: "600"], []},

View file

@ -13,28 +13,28 @@ test "/user_exists", %{conn: conn} do
res = res =
conn conn
|> get(mongoose_im_path(conn, :user_exists), user: "lain") |> get(~p"/user_exists", user: "lain")
|> json_response(200) |> json_response(200)
assert res == true assert res == true
res = res =
conn conn
|> get(mongoose_im_path(conn, :user_exists), user: "alice") |> get(~p"/user_exists", user: "alice")
|> json_response(404) |> json_response(404)
assert res == false assert res == false
res = res =
conn conn
|> get(mongoose_im_path(conn, :user_exists), user: "bob") |> get(~p"/user_exists", user: "bob")
|> json_response(404) |> json_response(404)
assert res == false assert res == false
res = res =
conn conn
|> get(mongoose_im_path(conn, :user_exists), user: "konata") |> get(~p"/user_exists", user: "konata")
|> json_response(404) |> json_response(404)
assert res == false assert res == false
@ -52,28 +52,28 @@ test "/check_password", %{conn: conn} do
res = res =
conn conn
|> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "cool") |> get(~p"/check_password", user: user.nickname, pass: "cool")
|> json_response(200) |> json_response(200)
assert res == true assert res == true
res = res =
conn conn
|> get(mongoose_im_path(conn, :check_password), user: user.nickname, pass: "uncool") |> get(~p"/check_password", user: user.nickname, pass: "uncool")
|> json_response(403) |> json_response(403)
assert res == false assert res == false
res = res =
conn conn
|> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "cool") |> get(~p"/check_password", user: "konata", pass: "cool")
|> json_response(404) |> json_response(404)
assert res == false assert res == false
res = res =
conn conn
|> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool") |> get(~p"/check_password", user: "nobody", pass: "cool")
|> json_response(404) |> json_response(404)
assert res == false assert res == false

View file

@ -57,7 +57,7 @@ test "GET /oauth/authorize renders auth forms, including OAuth consumer form", %
assert response = html_response(conn, 200) assert response = html_response(conn, 200)
assert response =~ "Sign in with Twitter" assert response =~ "Sign in with Twitter"
assert response =~ o_auth_path(conn, :prepare_request) assert response =~ ~p"/prepare_request"
end end
test "GET /oauth/prepare_request encodes parameters as `state` and redirects", %{ test "GET /oauth/prepare_request encodes parameters as `state` and redirects", %{

View file

@ -48,9 +48,7 @@ test "adds status to pleroma instance if the `acct` is a status", %{conn: conn}
assert conn assert conn
|> get( |> get(
remote_follow_path(conn, :follow, %{ ~p[/ostatus_subscribe?#{[acct: "https://mastodon.social/users/emelie/statuses/101849165031453009"]}]
acct: "https://mastodon.social/users/emelie/statuses/101849165031453009"
})
) )
|> redirected_to() =~ "/notice/" |> redirected_to() =~ "/notice/"
end end
@ -77,7 +75,7 @@ test "show follow account page if the `acct` is a account link", %{conn: conn} d
response = response =
conn conn
|> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"})) |> get(~p[/ostatus_subscribe?#{[acct: "https://mastodon.social/users/emelie"]}])
|> html_response(200) |> html_response(200)
assert response =~ "Log in to follow" assert response =~ "Log in to follow"
@ -108,7 +106,7 @@ test "show follow page if the `acct` is a account link", %{conn: conn} do
response = response =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> get(remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"})) |> get(~p[/ostatus_subscribe?#{[acct: "https://mastodon.social/users/emelie"]}])
|> html_response(200) |> html_response(200)
assert response =~ "Remote follow" assert response =~ "Remote follow"
@ -129,9 +127,7 @@ test "show follow page with error when user can not be fetched by `acct` link",
conn conn
|> assign(:user, user) |> assign(:user, user)
|> get( |> get(
remote_follow_path(conn, :follow, %{ ~p[/ostatus_subscribe?#{[acct: "https://mastodon.social/users/not_found"]}]
acct: "https://mastodon.social/users/not_found"
})
) )
|> html_response(200) |> html_response(200)
@ -151,7 +147,7 @@ test "required `follow | write:follows` scope", %{conn: conn} do
conn conn
|> assign(:user, user) |> assign(:user, user)
|> assign(:token, read_token) |> assign(:token, read_token)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) |> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|> response(200) |> response(200)
assert response =~ "Error following account" assert response =~ "Error following account"
@ -166,7 +162,7 @@ test "follows user", %{conn: conn} do
conn conn
|> assign(:user, user) |> assign(:user, user)
|> assign(:token, insert(:oauth_token, user: user, scopes: ["write:follows"])) |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:follows"]))
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) |> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
assert redirected_to(conn) == "/users/#{user2.id}" assert redirected_to(conn) == "/users/#{user2.id}"
end end
@ -178,7 +174,7 @@ test "returns error when user is deactivated", %{conn: conn} do
response = response =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) |> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|> response(200) |> response(200)
assert response =~ "Error following account" assert response =~ "Error following account"
@ -194,7 +190,7 @@ test "returns error when user is blocked", %{conn: conn} do
response = response =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) |> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|> response(200) |> response(200)
assert response =~ "Error following account" assert response =~ "Error following account"
@ -206,7 +202,7 @@ test "returns error when followee not found", %{conn: conn} do
response = response =
conn conn
|> assign(:user, user) |> assign(:user, user)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => "jimm"}}) |> post(~p"/ostatus_subscribe", %{"user" => %{"id" => "jimm"}})
|> response(200) |> response(200)
assert response =~ "Error following account" assert response =~ "Error following account"
@ -221,7 +217,7 @@ test "returns success result when user already in followers", %{conn: conn} do
conn conn
|> assign(:user, refresh_record(user)) |> assign(:user, refresh_record(user))
|> assign(:token, insert(:oauth_token, user: user, scopes: ["write:follows"])) |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:follows"]))
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}}) |> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
assert redirected_to(conn) == "/users/#{user2.id}" assert redirected_to(conn) == "/users/#{user2.id}"
end end
@ -243,7 +239,7 @@ test "render the MFA login form", %{conn: conn} do
response = response =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id} "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
}) })
|> response(200) |> response(200)
@ -271,7 +267,7 @@ test "returns error when password is incorrect", %{conn: conn} do
response = response =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test1", "id" => user2.id} "authorization" => %{"name" => user.nickname, "password" => "test1", "id" => user2.id}
}) })
|> response(200) |> response(200)
@ -299,7 +295,7 @@ test "follows", %{conn: conn} do
conn = conn =
conn conn
|> post( |> post(
remote_follow_path(conn, :do_follow), ~p"/ostatus_subscribe",
%{ %{
"mfa" => %{"code" => otp_token, "token" => token, "id" => user2.id} "mfa" => %{"code" => otp_token, "token" => token, "id" => user2.id}
} }
@ -328,7 +324,7 @@ test "returns error when auth code is incorrect", %{conn: conn} do
response = response =
conn conn
|> post( |> post(
remote_follow_path(conn, :do_follow), ~p"/ostatus_subscribe",
%{ %{
"mfa" => %{"code" => otp_token, "token" => token, "id" => user2.id} "mfa" => %{"code" => otp_token, "token" => token, "id" => user2.id}
} }
@ -347,7 +343,7 @@ test "follows", %{conn: conn} do
conn = conn =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id} "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
}) })
@ -360,7 +356,7 @@ test "returns error when followee not found", %{conn: conn} do
response = response =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => "jimm"} "authorization" => %{"name" => user.nickname, "password" => "test", "id" => "jimm"}
}) })
|> response(200) |> response(200)
@ -373,7 +369,7 @@ test "returns error when login invalid", %{conn: conn} do
response = response =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => "jimm", "password" => "test", "id" => user.id} "authorization" => %{"name" => "jimm", "password" => "test", "id" => user.id}
}) })
|> response(200) |> response(200)
@ -387,7 +383,7 @@ test "returns error when password invalid", %{conn: conn} do
response = response =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "42", "id" => user2.id} "authorization" => %{"name" => user.nickname, "password" => "42", "id" => user2.id}
}) })
|> response(200) |> response(200)
@ -403,7 +399,7 @@ test "returns error when user is blocked", %{conn: conn} do
response = response =
conn conn
|> post(remote_follow_path(conn, :do_follow), %{ |> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id} "authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
}) })
|> response(200) |> response(200)

View file

@ -10,7 +10,7 @@ defmodule Pleroma.Web.UploaderControllerTest do
test "it returns 400 response when process callback isn't alive", %{conn: conn} do test "it returns 400 response when process callback isn't alive", %{conn: conn} do
res = res =
conn conn
|> post(uploader_path(conn, :callback, "test-path")) |> post(~p"/api/v1/pleroma/uploader_callback/test-path")
assert res.status == 400 assert res.status == 400
assert res.resp_body == "{\"error\":\"bad request\"}" assert res.resp_body == "{\"error\":\"bad request\"}"
@ -34,7 +34,7 @@ test "it returns success result", %{conn: conn} do
res = res =
conn conn
|> post(uploader_path(conn, :callback, "test-path")) |> post(~p"/api/v1/pleroma/uploader_callback/test-path")
|> json_response(200) |> json_response(200)
assert res == %{"upload_path" => "test-path"} assert res == %{"upload_path" => "test-path"}

View file

@ -27,7 +27,6 @@ defmodule Pleroma.Web.ConnCase do
import Plug.Conn import Plug.Conn
import Phoenix.ConnTest import Phoenix.ConnTest
use Pleroma.Tests.Helpers use Pleroma.Tests.Helpers
import Pleroma.Web.Router.Helpers
alias Pleroma.Config alias Pleroma.Config

View file

@ -23,12 +23,14 @@ defmodule Pleroma.DataCase do
using do using do
quote do quote do
alias Pleroma.Repo alias Pleroma.Repo
@endpoint Pleroma.Web.Endpoint
import Ecto import Ecto
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
import Pleroma.DataCase import Pleroma.DataCase
use Pleroma.Tests.Helpers use Pleroma.Tests.Helpers
use Pleroma.Web, :verified_routes
# Sets up OAuth access with specified scopes # Sets up OAuth access with specified scopes
defp oauth_access(scopes, opts \\ []) do defp oauth_access(scopes, opts \\ []) do