Fix domains that start with UTF character (#3560)

* Avoid redirect in site settings

* Fix unicode in SiteController existing tests

* Fix various tests

* Add CHANGELOG

* Make sure test site is example.com

* Use Route helpers in site_controller

* Fix UTF redirect in change domain submit action

* Fix UTF site domain in reset stats action
pull/3588/head
Uku Taht 3 years ago committed by GitHub
parent c4eea9f8d5
commit 44d71c8c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -39,6 +39,7 @@ All notable changes to this project will be documented in this file.
- Improved the Goal Settings page (search, autcompletion etc.)
- Log mailer errors plausible/analytics#3336
- Allow custom event timeseries in stats API plausible/analytics#3505
- Fixes for sites with UTF characters in domain plausible/analytics#3560
## v2.0.0 - 2023-07-12

@ -164,7 +164,9 @@ export default class SiteSwitcher extends React.Component {
<React.Fragment>
<div className="py-1">
<a
href={`/${encodeURIComponent(this.props.site.domain)}/settings`}
href={`/${encodeURIComponent(
this.props.site.domain
)}/settings/general`}
className="group flex items-center px-4 py-2 md:text-sm leading-5 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-900 hover:text-gray-900 dark:hover:text-gray-100 focus:outline-none focus:bg-gray-100 dark:focus:bg-gray-900 focus:text-gray-900 dark:focus:text-gray-100"
role="menuitem"
>

@ -454,7 +454,7 @@ defmodule PlausibleWeb.AuthController do
:error,
"We were unable to authenticate your Google Analytics account. Please check that you have granted us permission to 'See and download your Google Analytics data' and try again."
)
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))
message when message in ["server_error", "temporarily_unavailable"] ->
conn
@ -462,7 +462,7 @@ defmodule PlausibleWeb.AuthController do
:error,
"We are unable to authenticate your Google Analytics account because Google's authentication service is temporarily unavailable. Please try again in a few moments."
)
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))
_any ->
Sentry.capture_message("Google OAuth callback failed. Reason: #{inspect(params)}")
@ -472,7 +472,7 @@ defmodule PlausibleWeb.AuthController do
:error,
"We were unable to authenticate your Google Analytics account. If the problem persists, please contact support for assistance."
)
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))
end
end
@ -485,7 +485,7 @@ defmodule PlausibleWeb.AuthController do
case redirect_to do
"import" ->
redirect(conn,
to:
external:
Routes.site_path(conn, :import_from_google_view_id_form, site.domain,
access_token: res["access_token"],
refresh_token: res["refresh_token"],
@ -510,7 +510,7 @@ defmodule PlausibleWeb.AuthController do
site = Repo.get(Plausible.Site, site_id)
redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings/integrations")
redirect(conn, external: "/#{URI.encode_www_form(site.domain)}/settings/integrations")
end
end
end

@ -10,7 +10,7 @@ defmodule PlausibleWeb.InvitationController do
{:ok, membership} ->
conn
|> put_flash(:success, "You now have access to #{membership.site.domain}")
|> redirect(to: "/#{URI.encode_www_form(membership.site.domain)}")
|> redirect(external: "/#{URI.encode_www_form(membership.site.domain)}")
{:error, :invitation_not_found} ->
conn
@ -43,12 +43,12 @@ defmodule PlausibleWeb.InvitationController do
{:ok, invitation} ->
conn
|> put_flash(:success, "You have removed the invitation for #{invitation.email}")
|> redirect(to: Routes.site_path(conn, :settings_people, invitation.site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, invitation.site.domain))
{:error, :invitation_not_found} ->
conn
|> put_flash(:error, "Invitation missing or already removed")
|> redirect(to: Routes.site_path(conn, :settings_people, conn.assigns.site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, conn.assigns.site.domain))
end
end
end

@ -55,7 +55,7 @@ defmodule PlausibleWeb.Site.MembershipController do
:success,
"#{email} has been invited to #{site_domain} as #{PlausibleWeb.SiteView.with_indefinite_article("#{invitation.role}")}"
)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
{:error, :already_a_member} ->
render(conn, "invite_member_form.html",
@ -86,7 +86,7 @@ defmodule PlausibleWeb.Site.MembershipController do
conn
|> put_flash(:error, error_msg)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end
@ -111,14 +111,14 @@ defmodule PlausibleWeb.Site.MembershipController do
{:ok, _invitation} ->
conn
|> put_flash(:success, "Site transfer request has been sent to #{email}")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
{:error, :transfer_to_self} ->
conn
|> put_flash(:ttl, :timer.seconds(5))
|> put_flash(:error_title, "Transfer error")
|> put_flash(:error, "Can't transfer ownership to existing owner")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
{:error, :upgrade_required} ->
conn
@ -128,7 +128,7 @@ defmodule PlausibleWeb.Site.MembershipController do
:error,
"The site you're trying to transfer exceeds the invitee's subscription plan. To proceed, please contact us at hello@plausible.io for further assistance."
)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
{:error, changeset} ->
errors = Plausible.ChangesetHelpers.traverse_errors(changeset)
@ -143,7 +143,7 @@ defmodule PlausibleWeb.Site.MembershipController do
|> put_flash(:ttl, :timer.seconds(5))
|> put_flash(:error_title, "Transfer error")
|> put_flash(:error, message)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end
@ -191,11 +191,11 @@ defmodule PlausibleWeb.Site.MembershipController do
:success,
"#{membership.user.name} is now #{PlausibleWeb.SiteView.with_indefinite_article(new_role_str)}"
)
|> redirect(to: redirect_target)
|> redirect(external: redirect_target)
else
conn
|> put_flash(:error, "You are not allowed to grant the #{new_role} role")
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end
@ -241,14 +241,14 @@ defmodule PlausibleWeb.Site.MembershipController do
:success,
"#{membership.user.name} has been removed from #{site.domain}"
)
|> redirect(to: redirect_target)
|> redirect(external: redirect_target)
else
conn
|> put_flash(
:error,
"Failed to find membership to remove"
)
|> redirect(to: Routes.site_path(conn, :settings_people, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_people, site.domain))
end
end
end

@ -38,7 +38,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_session(site.domain <> "_offer_email_report", true)
|> redirect(to: Routes.site_path(conn, :add_snippet, site.domain))
|> redirect(external: Routes.site_path(conn, :add_snippet, site.domain))
{:error, :limit, limit, _} ->
render(conn, "new.html",
@ -264,7 +264,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Google integration saved successfully")
|> redirect(to: Routes.site_path(conn, :settings_integrations, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_integrations, site.domain))
end
def delete_google_auth(conn, _params) do
@ -276,7 +276,7 @@ defmodule PlausibleWeb.SiteController do
conn = put_flash(conn, :success, "Google account unlinked from Plausible")
redirect(conn, to: Routes.site_path(conn, :settings_integrations, site.domain))
redirect(conn, external: Routes.site_path(conn, :settings_integrations, site.domain))
end
def update_settings(conn, %{"site" => site_params}) do
@ -290,7 +290,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_session(site_session_key, nil)
|> put_flash(:success, "Your site settings have been saved")
|> redirect(to: Routes.site_path(conn, :settings_general, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_general, site.domain))
{:error, changeset} ->
conn
@ -309,7 +309,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "#{site.domain} stats will be reset in a few minutes")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/danger-zone")
|> redirect(external: Routes.site_path(conn, :settings_danger_zone, site.domain))
end
def delete_site(conn, _params) do
@ -330,7 +330,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Stats for #{site.domain} are now public.")
|> redirect(to: Routes.site_path(conn, :settings_visibility, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_visibility, site.domain))
end
def make_private(conn, _params) do
@ -341,7 +341,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Stats for #{site.domain} are now private.")
|> redirect(to: Routes.site_path(conn, :settings_visibility, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_visibility, site.domain))
end
def enable_weekly_report(conn, _params) do
@ -358,7 +358,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "You will receive an email report every Monday going forward")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def disable_weekly_report(conn, _params) do
@ -367,7 +367,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "You will not receive weekly email reports going forward")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def add_weekly_report_recipient(conn, %{"recipient" => recipient}) do
@ -379,7 +379,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Added #{recipient} as a recipient for the weekly report")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def remove_weekly_report_recipient(conn, %{"recipient" => recipient}) do
@ -394,7 +394,7 @@ defmodule PlausibleWeb.SiteController do
:success,
"Removed #{recipient} as a recipient for the weekly report"
)
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def enable_monthly_report(conn, _params) do
@ -412,7 +412,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "You will receive an email report every month going forward")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def disable_monthly_report(conn, _params) do
@ -421,7 +421,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "You will not receive monthly email reports going forward")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def add_monthly_report_recipient(conn, %{"recipient" => recipient}) do
@ -433,7 +433,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Added #{recipient} as a recipient for the monthly report")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def remove_monthly_report_recipient(conn, %{"recipient" => recipient}) do
@ -448,7 +448,7 @@ defmodule PlausibleWeb.SiteController do
:success,
"Removed #{recipient} as a recipient for the monthly report"
)
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def enable_spike_notification(conn, _params) do
@ -466,12 +466,12 @@ defmodule PlausibleWeb.SiteController do
{:ok, _} ->
conn
|> put_flash(:success, "You will a notification with traffic spikes going forward")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
{:error, _} ->
conn
|> put_flash(:error, "Unable to create a spike notification")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
end
@ -481,7 +481,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Spike notification disabled")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def update_spike_notification(conn, %{"spike_notification" => params}) do
@ -493,7 +493,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Notification settings updated")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def add_spike_notification_recipient(conn, %{"recipient" => recipient}) do
@ -505,7 +505,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Added #{recipient} as a recipient for the traffic spike notification")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def remove_spike_notification_recipient(conn, %{"recipient" => recipient}) do
@ -520,7 +520,7 @@ defmodule PlausibleWeb.SiteController do
:success,
"Removed #{recipient} as a recipient for the monthly report"
)
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/email-reports")
|> redirect(external: Routes.site_path(conn, :settings_email_reports, site.domain))
end
def new_shared_link(conn, _params) do
@ -541,7 +541,7 @@ defmodule PlausibleWeb.SiteController do
case Sites.create_shared_link(site, link["name"], link["password"]) do
{:ok, _created} ->
redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
redirect(conn, external: Routes.site_path(conn, :settings_visibility, site.domain))
{:error, changeset} ->
conn
@ -575,7 +575,7 @@ defmodule PlausibleWeb.SiteController do
case Repo.update(changeset) do
{:ok, _created} ->
redirect(conn, to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
redirect(conn, external: Routes.site_path(conn, :settings_visibility, site.domain))
{:error, changeset} ->
conn
@ -600,12 +600,12 @@ defmodule PlausibleWeb.SiteController do
{1, _} ->
conn
|> put_flash(:success, "Shared Link deleted")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
|> redirect(external: Routes.site_path(conn, :settings_visibility, site.domain))
{0, _} ->
conn
|> put_flash(:error, "Could not find Shared Link")
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/visibility")
|> redirect(external: Routes.site_path(conn, :settings_visibility, site.domain))
end
end
@ -777,7 +777,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Import scheduled. An email will be sent when it completes.")
|> redirect(to: Routes.site_path(conn, :settings_integrations, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_integrations, site.domain))
end
def forget_imported(conn, _params) do
@ -800,12 +800,12 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Imported data has been cleared")
|> redirect(to: Routes.site_path(conn, :settings_integrations, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_integrations, site.domain))
true ->
conn
|> put_flash(:error, "No data has been imported")
|> redirect(to: Routes.site_path(conn, :settings_integrations, site.domain))
|> redirect(external: Routes.site_path(conn, :settings_integrations, site.domain))
end
end
@ -825,7 +825,7 @@ defmodule PlausibleWeb.SiteController do
conn
|> put_flash(:success, "Website domain changed successfully")
|> redirect(
to: Routes.site_path(conn, :add_snippet_after_domain_change, updated_site.domain)
external: Routes.site_path(conn, :add_snippet_after_domain_change, updated_site.domain)
)
{:error, changeset} ->

@ -283,7 +283,7 @@ defmodule PlausibleWeb.Live.Sites do
<div class="py-1 text-sm" role="none">
<.unstyled_link
:if={List.first(@site.memberships).role != :viewer}
href={"/#{URI.encode_www_form(@site.domain)}/settings"}
href={"/#{URI.encode_www_form(@site.domain)}/settings/general"}
class="text-gray-500 flex px-4 py-2 hover:bg-gray-100 hover:text-gray-800 dark:text-gray-500 dark:hover:text-gray-100 dark:hover:bg-indigo-900 cursor-pointer"
role="menuitem"
tabindex="-1"

@ -22,7 +22,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
assert Phoenix.Flash.get(conn.assigns.flash, :success) ==
"You now have access to #{site.domain}"
assert redirected_to(conn) == "/#{site.domain}"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}"
refute Repo.exists?(from(i in Plausible.Auth.Invitation, where: i.email == ^user.email))
@ -42,7 +42,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
)
c1 = post(conn, "/sites/invitations/#{invitation.invitation_id}/accept")
assert redirected_to(c1) == "/#{site.domain}"
assert redirected_to(c1) == "/#{URI.encode_www_form(site.domain)}"
assert Phoenix.Flash.get(c1.assigns.flash, :success) ==
"You now have access to #{site.domain}"
@ -126,7 +126,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
Routes.invitation_path(conn, :remove_invitation, site.domain, invitation.invitation_id)
)
assert redirected_to(conn, 302) == "/#{site.domain}/settings/people"
assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/settings/people"
refute Repo.reload(invitation)
end
@ -192,7 +192,7 @@ defmodule PlausibleWeb.Site.InvitationControllerTest do
conn = delete(conn, remove_invitation_path)
assert redirected_to(conn, 302) == "/#{site.domain}/settings/people"
assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/settings/people"
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
"Invitation missing or already removed"

@ -50,7 +50,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
invitation = Repo.get_by(Plausible.Auth.Invitation, email: "john.doe@example.com")
assert invitation.role == :admin
assert redirected_to(conn) == "/#{site.domain}/settings/people"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"
end
test "fails to create invitation when is over limit", %{conn: conn, user: user} do
@ -214,7 +214,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
invitation = Repo.get_by(Plausible.Auth.Invitation, email: "john.doe@example.com")
assert invitation.role == :owner
assert redirected_to(conn) == "/#{site.domain}/settings/people"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"
end
test "sends ownership transfer email for new user", %{conn: conn, user: user} do
@ -316,7 +316,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
membership = Repo.reload!(membership)
assert membership.role == :viewer
assert redirected_to(conn) == "/#{site.domain}"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}"
end
test "owner cannot make anyone else owner", %{
@ -384,7 +384,7 @@ defmodule PlausibleWeb.Site.MembershipControllerTest do
viewer_membership = Repo.reload!(viewer_membership)
assert viewer_membership.role == :admin
assert redirected_to(conn) == "/#{site.domain}/settings/people"
assert redirected_to(conn) == "/#{URI.encode_www_form(site.domain)}/settings/people"
end
test "admin can't make themselves an owner", %{conn: conn, user: user} do

@ -233,14 +233,13 @@ defmodule PlausibleWeb.SiteControllerTest do
conn =
post(conn, "/sites", %{
"site" => %{
"domain" => "example.com",
"domain" => "éxample.com",
"timezone" => "Europe/London"
}
})
assert redirected_to(conn) == "/example.com/snippet"
assert site = Repo.get_by(Plausible.Site, domain: "example.com")
assert site.domain == "example.com"
assert redirected_to(conn) == "/#{URI.encode_www_form("éxample.com")}/snippet"
assert site = Repo.get_by(Plausible.Site, domain: "éxample.com")
assert site.timezone == "Europe/London"
assert site.ingest_rate_limit_scale_seconds == 60
assert site.ingest_rate_limit_threshold == 1_000_000
@ -499,7 +498,7 @@ defmodule PlausibleWeb.SiteControllerTest do
updated = Repo.get(Plausible.Site, site.id)
assert updated.timezone == "Europe/London"
assert redirected_to(conn, 302) == "/#{site.domain}/settings/general"
assert redirected_to(conn, 302) == "/#{URI.encode_www_form(site.domain)}/settings/general"
end
end
@ -511,7 +510,9 @@ defmodule PlausibleWeb.SiteControllerTest do
updated = Repo.get(Plausible.Site, site.id)
assert updated.public
assert redirected_to(conn, 302) == "/#{site.domain}/settings/visibility"
assert redirected_to(conn, 302) ==
"/#{URI.encode_www_form(site.domain)}/settings/visibility"
end
test "fails to make site public with insufficient permissions", %{conn: conn, user: user} do
@ -543,7 +544,9 @@ defmodule PlausibleWeb.SiteControllerTest do
updated = Repo.get(Plausible.Site, site.id)
refute updated.public
assert redirected_to(conn, 302) == "/#{site.domain}/settings/visibility"
assert redirected_to(conn, 302) ==
"/#{URI.encode_www_form(site.domain)}/settings/visibility"
end
end
@ -601,7 +604,9 @@ defmodule PlausibleWeb.SiteControllerTest do
updated_auth = Repo.one(Plausible.Site.GoogleAuth)
assert updated_auth.property == "some-new-property.com"
assert redirected_to(conn, 302) == "/#{site.domain}/settings/integrations"
assert redirected_to(conn, 302) ==
"/#{URI.encode_www_form(site.domain)}/settings/integrations"
end
end
@ -613,7 +618,9 @@ defmodule PlausibleWeb.SiteControllerTest do
conn = delete(conn, "/#{site.domain}/settings/google-search")
refute Repo.exists?(Plausible.Site.GoogleAuth)
assert redirected_to(conn, 302) == "/#{site.domain}/settings/integrations"
assert redirected_to(conn, 302) ==
"/#{URI.encode_www_form(site.domain)}/settings/integrations"
end
test "fails to delete associated google auth from the outside", %{
@ -622,7 +629,7 @@ defmodule PlausibleWeb.SiteControllerTest do
} do
other_site = insert(:site)
insert(:google_auth, user: user, site: other_site)
conn = delete(conn, "/#{other_site.domain}/settings/google-search")
conn = delete(conn, "/#{URI.encode_www_form(other_site.domain)}/settings/google-search")
assert conn.status == 404
assert Repo.exists?(Plausible.Site.GoogleAuth)
@ -1211,7 +1218,7 @@ defmodule PlausibleWeb.SiteControllerTest do
conn = delete(conn, "/sites/#{site.domain}/shared-links/#{link.slug}")
refute Repo.one(Plausible.Site.SharedLink)
assert redirected_to(conn, 302) =~ "/#{site.domain}/settings"
assert redirected_to(conn, 302) =~ "/#{URI.encode_www_form(site.domain)}/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :success) == "Shared Link deleted"
end
@ -1222,7 +1229,7 @@ defmodule PlausibleWeb.SiteControllerTest do
conn = delete(conn, "/sites/#{site.domain}/shared-links/#{link.slug}")
assert Repo.one(Plausible.Site.SharedLink)
assert redirected_to(conn, 302) =~ "/#{site.domain}/settings"
assert redirected_to(conn, 302) =~ "/#{URI.encode_www_form(site.domain)}/settings"
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Could not find Shared Link"
end
end
@ -1420,17 +1427,18 @@ defmodule PlausibleWeb.SiteControllerTest do
site: site
} do
original_domain = site.domain
new_domain = "â-example.com"
conn =
put(conn, Routes.site_path(conn, :change_domain_submit, site.domain), %{
"site" => %{"domain" => "foo.example.com"}
"site" => %{"domain" => new_domain}
})
assert redirected_to(conn) ==
Routes.site_path(conn, :add_snippet_after_domain_change, "foo.example.com")
Routes.site_path(conn, :add_snippet_after_domain_change, new_domain)
site = Repo.reload!(site)
assert site.domain == "foo.example.com"
assert site.domain == new_domain
assert site.domain_changed_from == original_domain
end
@ -1453,4 +1461,17 @@ defmodule PlausibleWeb.SiteControllerTest do
"Your domain has been changed. You must update the JavaScript snippet on your site within 72 hours"
end
end
describe "reset stats" do
setup [:create_user, :log_in, :create_site]
test "resets native_stats_start_date", %{conn: conn, site: site} do
Plausible.Site.set_stats_start_date(site, ~D[2023-01-01])
|> Repo.update!()
delete(conn, Routes.site_path(conn, :reset_stats, site.domain))
assert Repo.reload(site).stats_start_date == nil
end
end
end

@ -14,7 +14,7 @@ defmodule PlausibleWeb.Live.GoalSettingsTest do
resp = html_response(conn, 200)
assert resp =~ "Define actions that you want your users to take"
assert resp =~ "compose Goals into Funnels"
assert resp =~ "/#{site.domain}/settings/funnels"
assert resp =~ "/#{URI.encode_www_form(site.domain)}/settings/funnels"
assert element_exists?(resp, ~s|a[href="https://plausible.io/docs/goal-conversions"]|)
assert resp =~ to_string(g1)

@ -53,7 +53,7 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinksTest do
|> assert_schema("SharedLink", spec())
assert resp.shared_link.href ==
"http://localhost:8000/share/#{site.domain}?auth=#{shared_link.slug}"
"http://localhost:8000/share/#{URI.encode_www_form(site.domain)}?auth=#{shared_link.slug}"
assert resp.shared_link.id == shared_link.id
assert resp.shared_link.password_protected == false
@ -107,7 +107,9 @@ defmodule PlausibleWeb.Plugins.API.Controllers.SharedLinksTest do
|> assert_schema("SharedLink", spec())
assert resp.shared_link.name == "My Shared Link"
assert resp.shared_link.href =~ "http://localhost:8000/share/#{site.domain}?auth="
assert resp.shared_link.href =~
"http://localhost:8000/share/#{URI.encode_www_form(site.domain)}?auth="
[location] = get_resp_header(conn, "location")

@ -24,7 +24,8 @@ defmodule Plausible.Factory do
end
def site_factory(attrs) do
domain = sequence(:domain, &"example-#{&1}.com")
# The é exercises unicode support in domain names
domain = sequence(:domain, &"é-#{&1}.example.com")
defined_memberships? =
Map.has_key?(attrs, :memberships) ||

Loading…
Cancel
Save