Merge branch 'fix/api-fallback' into 'develop'
Do not fallback to index.html for /api/* routes Closes #920 See merge request pleroma/pleroma!1182
This commit is contained in:
commit
ab6e15622b
@ -74,6 +74,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
- Hide deactivated users and their statuses
|
- Hide deactivated users and their statuses
|
||||||
- Posts which are marked sensitive or tagged nsfw no longer have link previews.
|
- Posts which are marked sensitive or tagged nsfw no longer have link previews.
|
||||||
- HTTP connection timeout is now set to 10 seconds.
|
- HTTP connection timeout is now set to 10 seconds.
|
||||||
|
- Respond with a 404 Not implemented JSON error message when requested API is not implemented
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Added an FTS index on objects. Running `vacuum analyze` and setting a larger `work_mem` is recommended.
|
- Added an FTS index on objects. Running `vacuum analyze` and setting a larger `work_mem` is recommended.
|
||||||
|
@ -710,6 +710,7 @@ defmodule Pleroma.Web.Router do
|
|||||||
scope "/", Fallback do
|
scope "/", Fallback do
|
||||||
get("/registration/:token", RedirectController, :registration_page)
|
get("/registration/:token", RedirectController, :registration_page)
|
||||||
get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
|
get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
|
||||||
|
get("/api*path", RedirectController, :api_not_implemented)
|
||||||
get("/*path", RedirectController, :redirector)
|
get("/*path", RedirectController, :redirector)
|
||||||
|
|
||||||
options("/*path", RedirectController, :empty)
|
options("/*path", RedirectController, :empty)
|
||||||
@ -721,6 +722,12 @@ defmodule Fallback.RedirectController do
|
|||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.Metadata
|
alias Pleroma.Web.Metadata
|
||||||
|
|
||||||
|
def api_not_implemented(conn, _params) do
|
||||||
|
conn
|
||||||
|
|> put_status(404)
|
||||||
|
|> json(%{error: "Not implemented"})
|
||||||
|
end
|
||||||
|
|
||||||
def redirector(conn, _params, code \\ 200) do
|
def redirector(conn, _params, code \\ 200) do
|
||||||
conn
|
conn
|
||||||
|> put_resp_content_type("text/html")
|
|> put_resp_content_type("text/html")
|
||||||
|
@ -397,14 +397,14 @@ test "it returns 500 if `registrations_open` is enabled", %{conn: conn, user: us
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "/api/pleroma/admin/invite_token" do
|
test "/api/pleroma/admin/users/invite_token" do
|
||||||
admin = insert(:user, info: %{is_admin: true})
|
admin = insert(:user, info: %{is_admin: true})
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
build_conn()
|
build_conn()
|
||||||
|> assign(:user, admin)
|
|> assign(:user, admin)
|
||||||
|> put_req_header("accept", "application/json")
|
|> put_req_header("accept", "application/json")
|
||||||
|> get("/api/pleroma/admin/invite_token")
|
|> get("/api/pleroma/admin/users/invite_token")
|
||||||
|
|
||||||
assert conn.status == 200
|
assert conn.status == 200
|
||||||
end
|
end
|
||||||
|
52
test/web/fallback_test.exs
Normal file
52
test/web/fallback_test.exs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Web.FallbackTest do
|
||||||
|
use Pleroma.Web.ConnCase
|
||||||
|
import Pleroma.Factory
|
||||||
|
|
||||||
|
test "GET /registration/:token", %{conn: conn} do
|
||||||
|
assert conn
|
||||||
|
|> get("/registration/foo")
|
||||||
|
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "GET /:maybe_nickname_or_id", %{conn: conn} do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> get("/foo")
|
||||||
|
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||||
|
|
||||||
|
refute conn
|
||||||
|
|> get("/" <> user.nickname)
|
||||||
|
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "GET /api*path", %{conn: conn} do
|
||||||
|
assert conn
|
||||||
|
|> get("/api/foo")
|
||||||
|
|> json_response(404) == %{"error" => "Not implemented"}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "GET /*path", %{conn: conn} do
|
||||||
|
assert conn
|
||||||
|
|> get("/foo")
|
||||||
|
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> get("/foo/bar")
|
||||||
|
|> html_response(200) =~ "<!--server-generated-meta-->"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "OPTIONS /*path", %{conn: conn} do
|
||||||
|
assert conn
|
||||||
|
|> options("/foo")
|
||||||
|
|> response(204) == ""
|
||||||
|
|
||||||
|
assert conn
|
||||||
|
|> options("/foo/bar")
|
||||||
|
|> response(204) == ""
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user