Protect the API endpoint from creating too many sites

pull/994/head
Uku Taht 6 years ago
parent 119b9514b2
commit 7f9057818d

@ -16,6 +16,14 @@ defmodule PlausibleWeb.Api.ExternalSitesController do
conn
|> put_status(400)
|> json(serialize_errors(changeset))
{:error, :limit, limit} ->
conn
|> put_status(403)
|> json(%{
error:
"Your account has reached the limit of #{limit} sites per account. Please contact hello@plausible.io to unlock more sites."
})
end
end

@ -43,6 +43,24 @@ defmodule PlausibleWeb.Api.ExternalSitesControllerTest do
}
end
test "does not allow creating more sites than the limit", %{conn: conn, user: user} do
Application.put_env(:plausible, :site_limit, 3)
insert(:site, members: [user])
insert(:site, members: [user])
insert(:site, members: [user])
conn =
post(conn, "/api/v1/sites", %{
"domain" => "some-site.domain",
"timezone" => "Europe/Tallinn"
})
assert json_response(conn, 403) == %{
"error" =>
"Your account has reached the limit of 3 sites per account. Please contact hello@plausible.io to unlock more sites."
}
end
test "cannot access with a bad API key scope", %{conn: conn, user: user} do
api_key = insert(:api_key, user: user, scopes: ["stats:read:*"])

Loading…
Cancel
Save