mirror of
https://github.com/plausible/analytics.git
synced 2024-11-25 07:06:11 +03:00
Decouple tests from specific routes
This commit is contained in:
parent
d8fd6ac575
commit
55e4a612d3
@ -84,6 +84,7 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccess do
|
|||||||
|
|
||||||
defp get_domain(conn, site_param) do
|
defp get_domain(conn, site_param) do
|
||||||
domain = conn.params[site_param]
|
domain = conn.params[site_param]
|
||||||
|
|
||||||
if is_binary(domain) do
|
if is_binary(domain) do
|
||||||
{:ok, domain}
|
{:ok, domain}
|
||||||
else
|
else
|
||||||
|
@ -32,26 +32,22 @@ defmodule PlausibleWeb.Router do
|
|||||||
plug :accepts, ["json"]
|
plug :accepts, ["json"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
pipeline :api_base do
|
||||||
|
plug :accepts, ["json"]
|
||||||
|
plug :fetch_session
|
||||||
|
plug PlausibleWeb.AuthPlug
|
||||||
|
end
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
plug :accepts, ["json"]
|
plug :api_base
|
||||||
plug :fetch_session
|
|
||||||
plug PlausibleWeb.AuthPlug
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :internal_stats_api do
|
pipeline :stats_internal_api_site_access do
|
||||||
plug :accepts, ["json"]
|
|
||||||
plug :fetch_session
|
|
||||||
plug PlausibleWeb.AuthPlug
|
|
||||||
plug PlausibleWeb.Plugs.AuthorizeSiteAccess
|
plug PlausibleWeb.Plugs.AuthorizeSiteAccess
|
||||||
plug PlausibleWeb.Plugs.NoRobots
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :docs_stats_api do
|
pipeline :docs_internal_api_site_access do
|
||||||
plug :accepts, ["json"]
|
|
||||||
plug :fetch_session
|
|
||||||
plug PlausibleWeb.AuthPlug
|
|
||||||
plug PlausibleWeb.Plugs.AuthorizeSiteAccess, {[:admin, :super_admin, :owner], "site_id"}
|
plug PlausibleWeb.Plugs.AuthorizeSiteAccess, {[:admin, :super_admin, :owner], "site_id"}
|
||||||
plug PlausibleWeb.Plugs.NoRobots
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :public_api do
|
pipeline :public_api do
|
||||||
@ -146,7 +142,7 @@ defmodule PlausibleWeb.Router do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scope "/api/stats", PlausibleWeb.Api do
|
scope "/api/stats", PlausibleWeb.Api do
|
||||||
pipe_through :internal_stats_api
|
pipe_through([:api_base, :stats_internal_api_site_access, PlausibleWeb.Plugs.NoRobots])
|
||||||
|
|
||||||
on_ee do
|
on_ee do
|
||||||
get "/:domain/funnels/:id", StatsController, :funnel
|
get "/:domain/funnels/:id", StatsController, :funnel
|
||||||
@ -198,7 +194,7 @@ defmodule PlausibleWeb.Router do
|
|||||||
get "/query/schema.json", ExternalQueryApiController, :schema
|
get "/query/schema.json", ExternalQueryApiController, :schema
|
||||||
|
|
||||||
scope [] do
|
scope [] do
|
||||||
pipe_through :docs_stats_api
|
pipe_through([:api_base, :docs_internal_api_site_access, PlausibleWeb.Plugs.NoRobots])
|
||||||
|
|
||||||
post "/query", ExternalQueryApiController, :query
|
post "/query", ExternalQueryApiController, :query
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
defmodule PlausibleWeb.Api.InternalController.DocsQueryTest do
|
defmodule PlausibleWeb.Api.InternalController.DocsQueryTest do
|
||||||
use PlausibleWeb.ConnCase, async: true
|
use PlausibleWeb.ConnCase, async: false
|
||||||
use Plausible.Repo
|
use Plausible.Repo
|
||||||
@user_id Enum.random(1000..9999)
|
@user_id Enum.random(1000..9999)
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest do
|
|||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> bypass_through(PlausibleWeb.Router)
|
|> bypass_through(PlausibleWeb.Router, [:api_base])
|
||||||
|> get("/api/docs/query/schema.json", %{"wrong_key" => site.domain})
|
|> get("/", %{"wrong_key" => site.domain})
|
||||||
|> AuthorizeSiteAccess.call(opts)
|
|> AuthorizeSiteAccess.call(opts)
|
||||||
|
|
||||||
assert conn.halted
|
assert conn.halted
|
||||||
@ -81,11 +81,11 @@ defmodule PlausibleWeb.Plugs.AuthorizeSiteAccessTest do
|
|||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> bypass_through(PlausibleWeb.Router)
|
|> bypass_through(PlausibleWeb.Router, [:api_base])
|
||||||
|> get("/api/docs/query/schema.json", %{"some_key" => site.domain})
|
|> post("/api/docs/query", %{"some_key" => site.domain})
|
||||||
|> AuthorizeSiteAccess.call(opts)
|
|> AuthorizeSiteAccess.call(opts)
|
||||||
|
|
||||||
assert conn.status == 200
|
refute conn.halted
|
||||||
assert conn.assigns.site.id == site.id
|
assert conn.assigns.site.id == site.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user