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

View File

@ -6,10 +6,13 @@ defmodule Pleroma.Emails.AdminEmail do
@moduledoc "Admin emails"
import Swoosh.Email
use Pleroma.Web, :mailer
alias Pleroma.Config
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_name, do: instance_config()[:name]
@ -45,7 +48,7 @@ defmodule Pleroma.Emails.AdminEmail do
statuses
|> Enum.map(fn
%{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>"
%{"id" => id} when is_binary(id) ->

View File

@ -6,12 +6,11 @@ defmodule Pleroma.Emails.UserEmail do
@moduledoc "User emails"
require Pleroma.Web.Gettext
use Pleroma.Web, :mailer
alias Pleroma.Config
alias Pleroma.User
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Gettext
alias Pleroma.Web.Router
import Swoosh.Email
import Phoenix.Swoosh, except: [render_body: 3]
@ -75,7 +74,7 @@ defmodule Pleroma.Emails.UserEmail do
def password_reset_email(user, token) when is_binary(token) 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 =
Gettext.dpgettext(
@ -108,12 +107,7 @@ defmodule Pleroma.Emails.UserEmail do
to_name \\ nil
) do
Gettext.with_locale_or_default user.language do
registration_url =
Router.Helpers.redirect_url(
Endpoint,
:registration_page,
user_invite_token.token
)
registration_url = ~p[/registration/#{user_invite_token.token}]
html_body =
Gettext.dpgettext(
@ -146,13 +140,7 @@ defmodule Pleroma.Emails.UserEmail do
def account_confirmation_email(user) do
Gettext.with_locale_or_default user.language do
confirmation_url =
Router.Helpers.confirm_email_url(
Endpoint,
:confirm_email,
user.id,
to_string(user.confirmation_token)
)
confirmation_url = ~p[/api/account/confirm_email/#{user.id}/#{user.confirmation_token}]
html_body =
Gettext.dpgettext(
@ -342,7 +330,7 @@ defmodule Pleroma.Emails.UserEmail do
|> Pleroma.JWT.generate_and_sign!()
|> Base.encode64()
Router.Helpers.subscription_url(Endpoint, :unsubscribe, token)
~p[/mailer/unsubscribe/#{token}]
end
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.Workers.BackgroundWorker
use Pleroma.Web, :verified_routes
require Logger
@type t :: %__MODULE__{}
@ -2447,12 +2449,7 @@ defmodule Pleroma.User do
end
if is_url(raw_value) do
frontend_url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:redirector_with_meta,
nickname
)
frontend_url = ~p[/#{nickname}]
possible_urls = [ap_id, frontend_url]

View File

@ -38,8 +38,6 @@ defmodule Pleroma.Web do
import Pleroma.Web.Gettext
import Pleroma.Web.TranslationHelpers
alias Pleroma.Web.Router.Helpers, as: Routes
unquote(verified_routes())
plug(:set_put_layout)
@ -224,7 +222,7 @@ defmodule Pleroma.Web do
def router do
quote do
use Phoenix.Router
use Phoenix.Router, helpers: false
import Plug.Conn
import Phoenix.Controller
@ -252,7 +250,6 @@ defmodule Pleroma.Web do
import Pleroma.Web.ErrorHelpers
import Pleroma.Web.Gettext
alias Pleroma.Web.Router.Helpers, as: Routes
unquote(verified_routes())
end
end
@ -268,6 +265,12 @@ defmodule Pleroma.Web do
end
end
def mailer do
quote do
unquote(verified_routes())
end
end
@doc """
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.Endpoint
use Pleroma.Web, :verified_routes
require Pleroma.Constants
def accept_or_reject(actor, activity, type) do
@ -402,6 +404,6 @@ defmodule Pleroma.Web.ActivityPub.Builder do
end
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

View File

@ -16,10 +16,11 @@ defmodule Pleroma.Web.ActivityPub.Utils do
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.AdminAPI.AccountView
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Router.Helpers
import Ecto.Query
use Pleroma.Web, :verified_routes
require Logger
require Pleroma.Constants
@ -124,19 +125,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
end
def generate_activity_id do
generate_id("activities")
url(~p[/activities/#{UUID.generate()}])
end
def generate_context_id do
generate_id("contexts")
url(~p[/contexts/#{UUID.generate()}])
end
def generate_object_id do
Helpers.o_status_url(Endpoint, :object, UUID.generate())
end
def generate_id(type) do
"#{Endpoint.url()}/#{type}/#{UUID.generate()}"
url(~p[/objects/#{UUID.generate()}])
end
def get_notified_from_object(%{"type" => type} = object) when type in @supported_object_types do
@ -154,7 +151,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
Notification.get_notified_from_activity(%Activity{data: object}, false)
end
def maybe_create_context(context), do: context || generate_id("contexts")
def maybe_create_context(context), do: context || generate_context_id()
@doc """
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.Transmogrifier
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.Endpoint
alias Pleroma.Web.Router.Helpers
require Pleroma.Web.ActivityPub.Transmogrifier
import Ecto.Query
def render("endpoints.json", %{user: %User{nickname: nil, local: true} = _user}) do
%{"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox)}
%{"sharedInbox" => ~p"/inbox"}
end
def render("endpoints.json", %{user: %User{local: true} = _user}) do
%{
"oauthAuthorizationEndpoint" => Helpers.o_auth_url(Endpoint, :authorize),
"oauthRegistrationEndpoint" => Helpers.app_url(Endpoint, :create),
"oauthTokenEndpoint" => Helpers.o_auth_url(Endpoint, :token_exchange),
"sharedInbox" => Helpers.activity_pub_url(Endpoint, :inbox),
"uploadMedia" => Helpers.activity_pub_url(Endpoint, :upload_media)
"oauthAuthorizationEndpoint" => ~p"/oauth/authorize",
"oauthRegistrationEndpoint" => ~p"/api/v1/apps",
"oauthTokenEndpoint" => ~p"/oauth/token",
"sharedInbox" => ~p"/inbox",
"uploadMedia" => ~p"/api/ap/upload_media"
}
end

View File

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

View File

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

View File

@ -322,7 +322,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
url =
if user.local do
Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
url(~p[/notice/#{activity}])
else
object.data["url"] || object.data["external_url"] || object.data["id"]
end

View File

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

View File

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

View File

@ -10,6 +10,8 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
alias Pleroma.Web.Metadata.Providers.Provider
alias Pleroma.Web.Metadata.Utils
use Pleroma.Web, :verified_routes
@behaviour Provider
@media_types ["image", "audio", "video"]
@ -112,7 +114,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCard do
defp build_attachments(_id, _object), 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
# 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.Metadata.PlayerView
alias Pleroma.Web.Plugs.RateLimiter
alias Pleroma.Web.Router
plug(
RateLimiter,
@ -87,7 +86,7 @@ defmodule Pleroma.Web.OStatus.OStatusController do
%{
activity_id: activity.id,
object: object,
url: Router.Helpers.o_status_url(Endpoint, :notice, activity.id),
url: url(~p[/notice/#{activity.id}]),
user: user
}
)

View File

@ -5,8 +5,9 @@
defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
import Plug.Conn
import Phoenix.Controller, only: [get_format: 1]
use Pleroma.Web, :verified_routes
alias Pleroma.Activity
alias Pleroma.Web.Router
alias Pleroma.Signature
alias Pleroma.Instances
require Logger
@ -32,7 +33,7 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do
end
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
["/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.Visibility
alias Pleroma.Web.Metadata
alias Pleroma.Web.Router.Helpers
plug(:put_layout, :static_fe)
plug(:assign_id)
@ -111,11 +110,11 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
end
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
%Activity{} = activity ->
to = Helpers.o_status_path(Pleroma.Web.Endpoint, :notice, activity)
to = ~p[/notice/#{activity}]
redirect(conn, to: to)
_ ->
@ -124,11 +123,11 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
end
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
%Activity{} = activity ->
to = Helpers.o_status_path(Pleroma.Web.Endpoint, :notice, activity)
to = ~p[/notice/#{activity}]
redirect(conn, to: to)
_ ->
@ -167,7 +166,7 @@ defmodule Pleroma.Web.StaticFE.StaticFEController do
link =
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"]
end

View File

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

View File

@ -36,7 +36,7 @@
</div>
</div>
<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="profile" value="">
<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.MediaProxy
alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router.Helpers
import Phoenix.HTML
@ -48,7 +47,7 @@ defmodule Pleroma.Web.EmbedView do
defp activity_content(_), do: nil
defp activity_url(%User{local: true}, activity) do
Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity)
~p[/notice/#{activity}]
end
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
alias Pleroma.Emails.AdminEmail
alias Pleroma.Web.Router.Helpers
test "build report email" do
config = Pleroma.Config.get(:instance)
@ -18,7 +17,7 @@ defmodule Pleroma.Emails.AdminEmailTest do
res =
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
account_url = account.ap_id

View File

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

View File

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

View File

@ -1004,23 +1004,13 @@ defmodule Pleroma.UserTest do
test "returns an ap_id for a user" do
user = insert(:user)
assert User.ap_id(user) ==
Pleroma.Web.Router.Helpers.user_feed_url(
Pleroma.Web.Endpoint,
:feed_redirect,
user.nickname
)
assert User.ap_id(user) == url(@endpoint, ~p[/users/#{user.nickname}])
end
test "returns an ap_followers link for a user" do
user = insert(:user)
assert User.ap_followers(user) ==
Pleroma.Web.Router.Helpers.user_feed_url(
Pleroma.Web.Endpoint,
:feed_redirect,
user.nickname
) <> "/followers"
assert User.ap_followers(user) == url(@endpoint, ~p[/users/#{user.nickname}/followers])
end
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
res =
conn
|> get(activity_pub_path(conn, :relay))
|> get(~p"/relay")
|> json_response(200)
assert res["id"] =~ "/relay"
@ -49,7 +49,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
clear_config([:instance, :allow_relay], false)
conn
|> get(activity_pub_path(conn, :relay))
|> get(~p"/relay")
|> json_response(404)
end
@ -59,7 +59,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn
|> assign(:user, user)
|> get(activity_pub_path(conn, :relay))
|> get(~p"/relay")
|> json_response(404)
end
end
@ -68,7 +68,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
test "it returns the internal fetch user", %{conn: conn} do
res =
conn
|> get(activity_pub_path(conn, :internal_fetch))
|> get(~p"/internal/fetch")
|> json_response(200)
assert res["id"] =~ "/fetch"
@ -80,7 +80,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
conn
|> assign(:user, user)
|> get(activity_pub_path(conn, :internal_fetch))
|> get(~p"/internal/fetch")
|> json_response(404)
end
end

View File

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

View File

@ -685,7 +685,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
response =
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)
users = [
@ -706,7 +706,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
response =
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)
users = [
@ -727,7 +727,7 @@ defmodule Pleroma.Web.AdminAPI.UserControllerTest do
response =
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)
users = [user_response(user_service, %{"actor_type" => "Service"})]

View File

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

View File

@ -66,7 +66,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
resp =
conn
|> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname))
|> get(~p[/users/#{user.nickname}/feed])
|> response(200)
activity_titles =
@ -128,7 +128,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
conn =
conn
|> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, "nonexisting"))
|> get(~p"/users/nonexisting/feed")
assert response(conn, 404)
end
@ -144,7 +144,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
resp =
conn
|> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname))
|> get(~p[/users/#{user.nickname}/feed])
|> response(200)
activity_titles =
@ -163,7 +163,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
assert conn
|> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname))
|> get(~p[/users/#{user.nickname}/feed])
|> response(404)
end
@ -240,7 +240,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
response =
conn
|> put_req_header("accept", "application/xml")
|> get(user_feed_path(conn, :feed, "jimm"))
|> get(~p"/users/jimm/feed")
|> response(404)
assert response == ~S({"error":"Not found"})
@ -258,7 +258,7 @@ defmodule Pleroma.Web.Feed.UserControllerTest do
assert conn
|> put_req_header("accept", "application/atom+xml")
|> get(user_feed_path(conn, :feed, user.nickname))
|> get(~p[/users/#{user.nickname}/feed])
|> response(404)
end
end

View File

@ -258,7 +258,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
expected = %{
id: to_string(note.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}),
in_reply_to_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.Metadata.Providers.TwitterCard
alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router
setup do: clear_config([Pleroma.Web.Metadata, :unfurl_nsfw])
@ -189,7 +188,7 @@ defmodule Pleroma.Web.Metadata.Providers.TwitterCardTest do
{:meta,
[
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:height", content: "600"], []},

View File

@ -13,28 +13,28 @@ defmodule Pleroma.Web.MongooseIMControllerTest do
res =
conn
|> get(mongoose_im_path(conn, :user_exists), user: "lain")
|> get(~p"/user_exists", user: "lain")
|> json_response(200)
assert res == true
res =
conn
|> get(mongoose_im_path(conn, :user_exists), user: "alice")
|> get(~p"/user_exists", user: "alice")
|> json_response(404)
assert res == false
res =
conn
|> get(mongoose_im_path(conn, :user_exists), user: "bob")
|> get(~p"/user_exists", user: "bob")
|> json_response(404)
assert res == false
res =
conn
|> get(mongoose_im_path(conn, :user_exists), user: "konata")
|> get(~p"/user_exists", user: "konata")
|> json_response(404)
assert res == false
@ -52,28 +52,28 @@ defmodule Pleroma.Web.MongooseIMControllerTest do
res =
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)
assert res == true
res =
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)
assert res == false
res =
conn
|> get(mongoose_im_path(conn, :check_password), user: "konata", pass: "cool")
|> get(~p"/check_password", user: "konata", pass: "cool")
|> json_response(404)
assert res == false
res =
conn
|> get(mongoose_im_path(conn, :check_password), user: "nobody", pass: "cool")
|> get(~p"/check_password", user: "nobody", pass: "cool")
|> json_response(404)
assert res == false

View File

@ -57,7 +57,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
assert response = html_response(conn, 200)
assert response =~ "Sign in with Twitter"
assert response =~ o_auth_path(conn, :prepare_request)
assert response =~ ~p"/prepare_request"
end
test "GET /oauth/prepare_request encodes parameters as `state` and redirects", %{

View File

@ -48,9 +48,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
assert conn
|> get(
remote_follow_path(conn, :follow, %{
acct: "https://mastodon.social/users/emelie/statuses/101849165031453009"
})
~p[/ostatus_subscribe?#{[acct: "https://mastodon.social/users/emelie/statuses/101849165031453009"]}]
)
|> redirected_to() =~ "/notice/"
end
@ -77,7 +75,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
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)
assert response =~ "Log in to follow"
@ -108,7 +106,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> 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)
assert response =~ "Remote follow"
@ -129,9 +127,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
conn
|> assign(:user, user)
|> get(
remote_follow_path(conn, :follow, %{
acct: "https://mastodon.social/users/not_found"
})
~p[/ostatus_subscribe?#{[acct: "https://mastodon.social/users/not_found"]}]
)
|> html_response(200)
@ -151,7 +147,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
conn
|> assign(:user, user)
|> 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)
assert response =~ "Error following account"
@ -166,7 +162,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
conn
|> assign(:user, user)
|> 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}"
end
@ -178,7 +174,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> assign(:user, user)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}})
|> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|> response(200)
assert response =~ "Error following account"
@ -194,7 +190,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> assign(:user, user)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => user2.id}})
|> post(~p"/ostatus_subscribe", %{"user" => %{"id" => user2.id}})
|> response(200)
assert response =~ "Error following account"
@ -206,7 +202,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> assign(:user, user)
|> post(remote_follow_path(conn, :do_follow), %{"user" => %{"id" => "jimm"}})
|> post(~p"/ostatus_subscribe", %{"user" => %{"id" => "jimm"}})
|> response(200)
assert response =~ "Error following account"
@ -221,7 +217,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
conn
|> assign(:user, refresh_record(user))
|> 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}"
end
@ -243,7 +239,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> post(remote_follow_path(conn, :do_follow), %{
|> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
})
|> response(200)
@ -271,7 +267,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> post(remote_follow_path(conn, :do_follow), %{
|> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test1", "id" => user2.id}
})
|> response(200)
@ -299,7 +295,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
conn =
conn
|> post(
remote_follow_path(conn, :do_follow),
~p"/ostatus_subscribe",
%{
"mfa" => %{"code" => otp_token, "token" => token, "id" => user2.id}
}
@ -328,7 +324,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> post(
remote_follow_path(conn, :do_follow),
~p"/ostatus_subscribe",
%{
"mfa" => %{"code" => otp_token, "token" => token, "id" => user2.id}
}
@ -347,7 +343,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
conn =
conn
|> post(remote_follow_path(conn, :do_follow), %{
|> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => user2.id}
})
@ -360,7 +356,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> post(remote_follow_path(conn, :do_follow), %{
|> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => user.nickname, "password" => "test", "id" => "jimm"}
})
|> response(200)
@ -373,7 +369,7 @@ defmodule Pleroma.Web.TwitterAPI.RemoteFollowControllerTest do
response =
conn
|> post(remote_follow_path(conn, :do_follow), %{
|> post(~p"/ostatus_subscribe", %{
"authorization" => %{"name" => "jimm", "password" => "test", "id" => user.id}
})
|> response(200)