Disallow site creation with insufficient input (#2741)

This commit is contained in:
Adam 2023-03-10 20:32:10 +01:00 committed by GitHub
parent ad3edbfb9a
commit 3417b2dd0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -43,8 +43,8 @@ defmodule Plausible.Site do
def changeset(site, attrs \\ %{}) do
site
|> cast(attrs, [:domain, :timezone])
|> validate_required([:domain, :timezone])
|> clean_domain()
|> validate_required([:domain, :timezone])
|> validate_format(:domain, ~r/^[-\.\\\/:\p{L}\d]*$/u,
message: "only letters, numbers, slashes and period allowed"
)

View File

@ -108,6 +108,18 @@ defmodule PlausibleWeb.SiteControllerTest do
assert Repo.get_by(Plausible.Site, domain: "example.com")
end
test "fails to create the site if only http:// provided", %{conn: conn} do
conn =
post(conn, "/sites", %{
"site" => %{
"domain" => "http://",
"timezone" => "Europe/London"
}
})
assert html_response(conn, 200) =~ "can't be blank"
end
test "starts trial if user does not have trial yet", %{conn: conn, user: user} do
Plausible.Auth.User.remove_trial_expiry(user) |> Repo.update!()