Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Improve SSO naming and setup (#5558)

Adrian Gruntkowski832c767d91b7
diff --git a/extra/lib/plausible/auth/sso.ex b/extra/lib/plausible/auth/sso.ex
index e5c2d2b52d..b48bbbfc56 100644
--- a/extra/lib/plausible/auth/sso.ex
+++ b/extra/lib/plausible/auth/sso.ex
@@ -134,7 +134,7 @@ defmodule Plausible.Auth.SSO do
:no_integration
| :no_domain
| :no_verified_domain
- | :owner_mfa_disabled
+ | :owner_2fa_disabled
| :no_sso_user}
def set_force_sso(team, mode) do
with :ok <- check_force_sso(team, mode) do
@@ -153,14 +153,14 @@ defmodule Plausible.Auth.SSO do
:no_integration
| :no_domain
| :no_verified_domain
- | :owner_mfa_disabled
+ | :owner_2fa_disabled
| :no_sso_user}
def check_force_sso(_team, :none), do: :ok
def check_force_sso(team, :all_but_owners) do
with :ok <- check_integration_configured(team),
:ok <- check_sso_user_present(team) do
- check_owners_mfa_enabled(team)
+ check_owners_2fa_enabled(team)
end
end
@@ -300,8 +300,8 @@ defmodule Plausible.Auth.SSO do
end
end
- defp check_owners_mfa_enabled(team) do
- disabled_mfa_count =
+ defp check_owners_2fa_enabled(team) do
+ disabled_2fa_count =
Repo.aggregate(
from(
tm in Teams.Membership,
@@ -313,10 +313,10 @@ defmodule Plausible.Auth.SSO do
:count
)
- if disabled_mfa_count == 0 do
+ if disabled_2fa_count == 0 do
:ok
else
- {:error, :owner_mfa_disabled}
+ {:error, :owner_2fa_disabled}
end
end
diff --git a/extra/lib/plausible/auth/sso/saml_config.ex b/extra/lib/plausible/auth/sso/saml_config.ex
index 7775e112a7..af9c33ed22 100644
--- a/extra/lib/plausible/auth/sso/saml_config.ex
+++ b/extra/lib/plausible/auth/sso/saml_config.ex
@@ -85,11 +85,19 @@ defmodule Plausible.Auth.SSO.SAMLConfig do
end
defp clean_pem(pem) do
- pem
- |> String.split("\n")
- |> Enum.map(&String.trim/1)
- |> Enum.reject(&(&1 == ""))
- |> Enum.join("\n")
- |> String.trim()
+ cleaned =
+ pem
+ |> String.split("\n")
+ |> Enum.map(&String.trim/1)
+ |> Enum.reject(&(&1 == ""))
+ |> Enum.join("\n")
+ |> String.trim()
+
+ # Trying to account for PEM certificates without markers
+ if String.starts_with?(cleaned, "-----BEGIN CERTIFICATE-----") do
+ cleaned
+ else
+ "-----BEGIN CERTIFICATE-----\n" <> cleaned <> "\n-----END CERTIFICATE-----"
+ end
end
end
diff --git a/extra/lib/plausible_web/controllers/sso_controller.ex b/extra/lib/plausible_web/controllers/sso_controller.ex
index 49772f92a8..63c231fcf7 100644
--- a/extra/lib/plausible_web/controllers/sso_controller.ex
+++ b/extra/lib/plausible_web/controllers/sso_controller.ex
@@ -29,23 +29,32 @@ defmodule PlausibleWeb.SSOController do
end
def login(conn, %{"email" => email} = params) do
- case SSO.Domains.lookup(email) do
- {:ok, %{sso_integration: integration}} ->
- redirect(conn,
- to:
- Routes.sso_path(
- conn,
- :saml_signin,
- integration.identifier,
- email: email,
- return_to: params["return_to"]
- )
- )
-
+ with :ok <- Auth.rate_limit(:login_ip, conn),
+ {:ok, %{sso_integration: integration}} <- SSO.Domains.lookup(email) do
+ redirect(conn,
+ to:
+ Routes.sso_path(
+ conn,
+ :saml_signin,
+ integration.identifier,
+ email: email,
+ return_to: params["return_to"]
+ )
+ )
+ else
{:error, :not_found} ->
conn
|> put_flash(:login_error, "Wrong email.")
|> redirect(to: Routes.sso_path(conn, :login_form))
+
+ {:error, {:rate_limit, _}} ->
+ Auth.log_failed_login_attempt("too many login attempts for #{email}")
+
+ render_error(
+ conn,
+ 429,
+ "Too many login attempts. Wait a minute before trying again."
+ )
end
end
diff --git a/extra/lib/plausible_web/live/sso_management.ex b/extra/lib/plausible_web/live/sso_management.ex
index 79cb679b2e..83302f9aae 100644
--- a/extra/lib/plausible_web/live/sso_management.ex
+++ b/extra/lib/plausible_web/live/sso_management.ex
@@ -26,7 +26,10 @@ defmodule PlausibleWeb.Live.SSOManagement do
~H"""
<.flash_messages flash={@flash} />
- <.tile :if={@mode != :manage} docs="sso">
+ <.tile
+ :if={@mode != :manage}
+ docs={if @mode in [:domain_setup, :domain_verify], do: "sso#sso-domains", else: "sso"}
+ >
<:title>
<a id="sso-config">Single Sign-On</a>
</:title>
@@ -73,7 +76,10 @@ defmodule PlausibleWeb.Live.SSOManagement do
def init_view(assigns) do
~H"""
<form id="sso-init" for={} phx-submit="init-sso">
- <p class="text-sm">Click below to start setting up Single Sign-On for your team.</p>
+ <p class="text-sm">
+ Single Sign-On (SSO) enables team members to sign in without having to register an account. For more details,
+ <.styled_link href="https://plausible.io/docs/sso">see our documentation</.styled_link>.
+ </p>
<.button type="submit">Start Configuring SSO</.button>
</form>
@@ -87,24 +93,24 @@ defmodule PlausibleWeb.Live.SSOManagement do
Use the following parameters when configuring your Identity Provider of choice:
</p>
+ <.input_with_clipboard
+ id="sp-acs-url"
+ name="sp-acs-url"
+ label="ACS URL / Single Sign-On URL / Reply URL"
+ value={saml_acs_url(@integration)}
+ />
+
<.form id="sso-sp-config" for={} class="flex-col space-y-4">
<.input_with_clipboard
id="sp-entity-id"
name="sp-entity-id"
- label="Entity ID"
+ label="Entity ID / Audience URI / Identifier"
value={SSO.SAMLConfig.entity_id(@integration)}
/>
-
- <.input_with_clipboard
- id="sp-acs-url"
- name="sp-acs-url"
- label="ACS URL"
- value={saml_acs_url(@integration)}
- />
</.form>
<div class="flex-col space-y-3">
- <p class="text-sm">Following attribute mappings must be setup at Identity Provider:</p>
+ <p class="text-sm">Following attribute mappings must be set up at Identity Provider:</p>
<ul role="list" class="list-disc leading-6 text-sm ml-8">
<li :for={param <- ["email", "first_name", "last_name"]}>
@@ -136,11 +142,19 @@ defmodule PlausibleWeb.Live.SSOManagement do
class="flex-col space-y-4"
phx-submit="update-integration"
>
- <.input field={f[:idp_signin_url]} label="Sign-in URL" placeholder="<URL>" />
+ <.input
+ field={f[:idp_signin_url]}
+ label="SSO URL / Sign-on URL / Login URL"
+ placeholder="<URL>"
+ />
- <.input field={f[:idp_entity_id]} label="Entity ID" placeholder="<Entity ID>" />
+ <.input
+ field={f[:idp_entity_id]}
+ label="Entity ID / Issuer / Identifier"
+ placeholder="<Entity ID>"
+ />
- <.input field={f[:idp_cert_pem]} type="textarea" label="Certificate in PEM format" />
+ <.input field={f[:idp_cert_pem]} type="textarea" label="Signing Certificate in PEM format" />
<.button type="submit">Save</.button>
</.form>
@@ -214,7 +228,7 @@ defmodule PlausibleWeb.Live.SSOManagement do
:if={@domain.status in [Status.in_progress(), Status.unverified(), Status.verified()]}
type="submit"
>
- Run verification now
+ Run Verification Now
</.button>
<.button :if={@domain.status == Status.pending()} type="submit">Continue</.button>
@@ -239,19 +253,19 @@ defmodule PlausibleWeb.Live.SSOManagement do
</p>
<form id="sso-sp-config" for={} class="flex-col space-y-4">
- <.input_with_clipboard
- id="sp-entity-id"
- name="sp-entity-id"
- label="Entity ID"
- value={SSO.SAMLConfig.entity_id(@integration)}
- />
-
<.input_with_clipboard
id="sp-acs-url"
name="sp-acs-url"
- label="ACS URL"
+ label="ACS URL / Single Sign-On URL / Reply URL"
value={saml_acs_url(@integration)}
/>
+
+ <.input_with_clipboard
+ id="sp-entity-id"
+ name="sp-entity-id"
+ label="Entity ID / Audience URI / Identifier"
+ value={SSO.SAMLConfig.entity_id(@integration)}
+ />
</form>
<div class="flex-col space-y-3">
@@ -273,21 +287,21 @@ defmodule PlausibleWeb.Live.SSOManagement do
<.input
field={f[:idp_signin_url]}
value={@integration.config.idp_signin_url}
- label="Sign-in URL"
+ label="SSO URL / Sign-on URL / Login URL"
readonly={true}
/>
<.input
field={f[:idp_entity_id]}
value={@integration.config.idp_entity_id}
- label="Entity ID"
+ label="Entity ID / Issuer / Identifier"
readonly={true}
/>
<.input
field={f[:idp_cert_pem]}
type="textarea"
- label="Certificate in PEM format"
+ label="Signing Certificate in PEM format"
value={@integration.config.idp_cert_pem}
readonly={true}
/>
@@ -300,7 +314,7 @@ defmodule PlausibleWeb.Live.SSOManagement do
</div>
</.tile>
- <.tile docs="sso">
+ <.tile docs="sso#sso-domains">
<:title>
<a id="sso-domains-config">SSO Domains</a>
</:title>
@@ -368,7 +382,7 @@ defmodule PlausibleWeb.Live.SSOManagement do
</div>
</.tile>
- <.tile docs="sso">
+ <.tile docs="sso#sso-policy">
<:title>
<a id="sso-policy-config">SSO Policy</a>
</:title>
@@ -670,7 +684,7 @@ defmodule PlausibleWeb.Live.SSOManagement do
{false, "you must be logged in via SSO"}
{{:error, :no_integration}, _} ->
- {false, "you must first setup Single Sign-on"}
+ {false, "you must first setup Single Sign-On"}
{{:error, :no_domain}, _} ->
{false, "you must add a domain"}
@@ -678,8 +692,8 @@ defmodule PlausibleWeb.Live.SSOManagement do
{{:error, :no_verified_domain}, _} ->
{false, "you must verify a domain"}
- {{:error, :owner_mfa_disabled}, _} ->
- {false, "all Owners must have MFA enabled"}
+ {{:error, :owner_2fa_disabled}, _} ->
+ {false, "all Owners must have 2FA enabled"}
{{:error, :no_sso_user}, _} ->
{false, "at least one SSO user must log in successfully"}
diff --git a/extra/lib/plausible_web/templates/sso/login_form.html.heex b/extra/lib/plausible_web/templates/sso/login_form.html.heex
index 14c4a08bdf..505d5ef94e 100644
--- a/extra/lib/plausible_web/templates/sso/login_form.html.heex
+++ b/extra/lib/plausible_web/templates/sso/login_form.html.heex
@@ -1,6 +1,6 @@
<.focus_box>
<:title>
- {Phoenix.Flash.get(@flash, :login_title) || "Enter your Single Sign-on email"}
+ {Phoenix.Flash.get(@flash, :login_title) || "Enter your Single Sign-On email"}
</:title>
<:subtitle>
<%= if Phoenix.Flash.get(@flash, :login_instructions) do %>
diff --git a/extra/lib/plausible_web/templates/sso/saml_signin.html.heex b/extra/lib/plausible_web/templates/sso/saml_signin.html.heex
index e30be282b4..e70be63538 100644
--- a/extra/lib/plausible_web/templates/sso/saml_signin.html.heex
+++ b/extra/lib/plausible_web/templates/sso/saml_signin.html.heex
@@ -12,7 +12,7 @@
</script>
<div>
<h1>
- Processing Single Sign-on request...
+ Processing Single Sign-On request...
</h1>
<noscript>
<p>
diff --git a/extra/lib/plausible_web/templates/sso/team_sessions.html.heex b/extra/lib/plausible_web/templates/sso/team_sessions.html.heex
index c9a20bd73f..0b9ac3a194 100644
--- a/extra/lib/plausible_web/templates/sso/team_sessions.html.heex
+++ b/extra/lib/plausible_web/templates/sso/team_sessions.html.heex
@@ -1,5 +1,5 @@
<.settings_tiles>
- <.tile docs="sso-login-management">
+ <.tile docs="sso#team-management">
<:title>
<a id="user-sessions">SSO Login Management</a>
</:title>
diff --git a/lib/plausible/auth/auth.ex b/lib/plausible/auth/auth.ex
index 4ea2b84cf9..a8b0fb0690 100644
--- a/lib/plausible/auth/auth.ex
+++ b/lib/plausible/auth/auth.ex
@@ -13,6 +13,8 @@ defmodule Plausible.Auth do
alias Plausible.RateLimit
alias Plausible.Teams
+ require Logger
+
@rate_limits %{
login_ip: %{
prefix: "login:ip",
@@ -52,6 +54,15 @@ defmodule Plausible.Auth do
end
end
+ @spec log_failed_login_attempt(String.t()) :: :ok
+ def log_failed_login_attempt(message) do
+ if Application.get_env(:plausible, :log_failed_login_attempts) do
+ Logger.warning("[login] #{message}")
+ end
+
+ :ok
+ end
+
@spec find_user_by(Keyword.t()) :: Auth.User.t() | nil
def find_user_by(opts) do
Repo.get_by(Auth.User, opts)
diff --git a/lib/plausible/teams/memberships/update_role.ex b/lib/plausible/teams/memberships/update_role.ex
index b505ef776d..e1aa9bcacd 100644
--- a/lib/plausible/teams/memberships/update_role.ex
+++ b/lib/plausible/teams/memberships/update_role.ex
@@ -51,7 +51,7 @@ defmodule Plausible.Teams.Memberships.UpdateRole do
on_ee do
defp check_can_promote_to_owner(team, user, :owner) do
if team.policy.force_sso == :all_but_owners and not Plausible.Auth.TOTP.enabled?(user) do
- {:error, :mfa_disabled}
+ {:error, :disabled_2fa}
else
:ok
end
@@ -66,7 +66,7 @@ defmodule Plausible.Teams.Memberships.UpdateRole do
if :erlang.phash2(1, 1) == 0 do
:ok
else
- {:error, :mfa_disabled}
+ {:error, :disabled_2fa}
end
end
end
diff --git a/lib/plausible_web/controllers/auth_controller.ex b/lib/plausible_web/controllers/auth_controller.ex
index c271c94663..c4fd3e5994 100644
--- a/lib/plausible_web/controllers/auth_controller.ex
+++ b/lib/plausible_web/controllers/auth_controller.ex
@@ -303,14 +303,14 @@ defmodule PlausibleWeb.AuthController do
|> UserAuth.log_in_user(user, redirect_path)
else
{:error, :wrong_password} ->
- maybe_log_failed_login_attempts("wrong password for #{email}")
+ Auth.log_failed_login_attempt("wrong password for #{email}")
conn
|> put_flash(:login_error, "Wrong email or password. Please try again.")
|> render("login_form.html")
{:error, :user_not_found} ->
- maybe_log_failed_login_attempts("user not found for #{email}")
+ Auth.log_failed_login_attempt("user not found for #{email}")
Plausible.Auth.Password.dummy_calculation()
conn
@@ -318,7 +318,7 @@ defmodule PlausibleWeb.AuthController do
|> render("login_form.html")
{:error, {:rate_limit, _}} ->
- maybe_log_failed_login_attempts("too many login attempts for #{email}")
+ Auth.log_failed_login_attempt("too many login attempts for #{email}")
render_error(
conn,
@@ -463,9 +463,7 @@ defmodule PlausibleWeb.AuthController do
|> UserAuth.log_in_user(user, params["return_to"])
{:error, :invalid_code} ->
- maybe_log_failed_login_attempts(
- "wrong 2FA verification code provided for #{user.email}"
- )
+ Auth.log_failed_login_attempt("wrong 2FA verification code provided for #{user.email}")
conn
|> put_flash(:error, "The provided code is invalid. Please try again")
@@ -500,7 +498,7 @@ defmodule PlausibleWeb.AuthController do
UserAuth.log_in_user(conn, user)
{:error, :invalid_code} ->
- maybe_log_failed_login_attempts("wrong 2FA recovery code provided for #{user.email}")
+ Auth.log_failed_login_attempt("wrong 2FA recovery code provided for #{user.email}")
conn
|> put_flash(:error, "The provided recovery code is invalid. Please try another one")
@@ -520,7 +518,7 @@ defmodule PlausibleWeb.AuthController do
{:ok, user}
else
{:error, {:rate_limit, _}} ->
- maybe_log_failed_login_attempts("too many login attempts for #{user.email}")
+ Auth.log_failed_login_attempt("too many login attempts for #{user.email}")
conn
|> TwoFactor.Session.clear_2fa_user()
@@ -657,10 +655,4 @@ defmodule PlausibleWeb.AuthController do
defp redirect_to_login(conn) do
redirect(conn, to: Routes.auth_path(conn, :login_form))
end
-
- defp maybe_log_failed_login_attempts(message) do
- if Application.get_env(:plausible, :log_failed_login_attempts) do
- Logger.warning("[login] #{message}")
- end
- end
end
diff --git a/lib/plausible_web/live/team_management.ex b/lib/plausible_web/live/team_management.ex
index 0fc7c44b5a..2cf03f980e 100644
--- a/lib/plausible_web/live/team_management.ex
+++ b/lib/plausible_web/live/team_management.ex
@@ -315,7 +315,7 @@ defmodule PlausibleWeb.Live.TeamManagement do
"The team has to have at least one owner"
)
- {{:error, :mfa_disabled}, _} ->
+ {{:error, :disabled_2fa}, _} ->
socket
|> put_live_flash(
:error,
diff --git a/test/plausible/auth/sso_test.exs b/test/plausible/auth/sso_test.exs
index ba3db6b678..7dfaa79ec1 100644
--- a/test/plausible/auth/sso_test.exs
+++ b/test/plausible/auth/sso_test.exs
@@ -111,6 +111,49 @@ defmodule Plausible.Auth.SSOTest do
X509.Certificate.from_pem(@cert_pem)
end
+ test "updates integration with PEM missing boundaries" do
+ boundless_pem =
+ "MIIDqjCCApKgAwIBAgIGAZfpTJclMA0GCSqGSIb3DQEBCwUAMIGVMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwET2t0YTEUMBIGA1UECwwLU1NPUHJvdmlkZXIxFjAUBgNVBAMMDXRyaWFsLTU1OTk4NzkxHDAaBgkqhkiG9w0BCQEWDWluZm9Ab2t0YS5jb20wHhcNMjUwNzA4MDkwOTAwWhcNMzUwNzA4MDkxMDAwWjCBlTELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoMBE9rdGExFDASB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6alqkHqlp2zxThOVvMW6
+ tz0X8hNnxrXmmZdp7WF6s/8/Pw9Dq691L0AIKnIL
+ -----END CERTIFICATE-----
+ """
+
+ team = new_site().team
+ integration = SSO.initiate_saml_integration(team)
+
+ assert {:ok, integration} =
+ SSO.update_integration(integration, %{
+ idp_signin_url: "https://example.com",
+ idp_entity_id: "some-entity",
+ idp_cert_pem: boundless_pem
+ })
+
+ assert integration.config.idp_signin_url == "https://example.com"
+ assert integration.config.idp_entity_id == "some-entity"
+
+ assert X509.Certificate.from_pem(integration.config.idp_cert_pem) ==
+ X509.Certificate.from_pem(pem)
+ end
+
test "optionally accepts metadata" do
team = new_site().team
integration = SSO.initiate_saml_integration(team)
@@ -540,7 +583,7 @@ defmodule Plausible.Auth.SSOTest do
describe "check_force_sso/2" do
test "returns ok when conditions are met for setting all_but_owners" do
- # Owner with MFA enabled
+ # Owner with 2FA enabled
owner = new_user()
{:ok, owner, _} = Auth.TOTP.initiate(owner)
{:ok, owner, _} = Auth.TOTP.enable(owner, :skip_verify)
@@ -561,13 +604,13 @@ defmodule Plausible.Auth.SSOTest do
assert :ok = SSO.check_force_sso(team, :all_but_owners)
end
- test "returns error when one owner does not have MFA configured" do
+ test "returns error when one owner does not have 2FA configured" do
owner = new_user()
{:ok, owner, _} = Auth.TOTP.initiate(owner)
{:ok, owner, _} = Auth.TOTP.enable(owner, :skip_verify)
team = new_site(owner: owner).team
- # Owner without MFA
+ # Owner without 2FA
another_owner = new_user()
add_member(team, user: another_owner, role: :owner)
@@ -583,11 +626,11 @@ defmodule Plausible.Auth.SSOTest do
identity = new_identity("Carrie Mower", "lance@" <> domain)
{:ok, _, _, _sso_user} = SSO.provision_user(identity)
- assert {:error, :owner_mfa_disabled} = SSO.check_force_sso(team, :all_but_owners)
+ assert {:error, :owner_2fa_disabled} = SSO.check_force_sso(team, :all_but_owners)
end
test "returns error when there's no provisioned SSO user present" do
- # Owner with MFA enabled
+ # Owner with 2FA enabled
owner = new_user()
{:ok, owner, _} = Auth.TOTP.initiate(owner)
{:ok, owner, _} = Auth.TOTP.enable(owner, :skip_verify)
@@ -604,7 +647,7 @@ defmodule Plausible.Auth.SSOTest do
end
test "returns error when there's no verified SSO domain present" do
- # Owner with MFA enabled
+ # Owner with 2FA enabled
owner = new_user()
{:ok, owner, _} = Auth.TOTP.initiate(owner)
{:ok, owner, _} = Auth.TOTP.enable(owner, :skip_verify)
@@ -621,7 +664,7 @@ defmodule Plausible.Auth.SSOTest do
end
test "returns error when there's no SSO domain present" do
- # Owner with MFA enabled
+ # Owner with 2FA enabled
owner = new_user()
{:ok, owner, _} = Auth.TOTP.initiate(owner)
{:ok, owner, _} = Auth.TOTP.enable(owner, :skip_verify)
@@ -634,7 +677,7 @@ defmodule Plausible.Auth.SSOTest do
end
test "returns error when there's no SSO integration present" do
- # Owner with MFA enabled
+ # Owner with 2FA enabled
owner = new_user()
{:ok, owner, _} = Auth.TOTP.initiate(owner)
{:ok, owner, _} = Auth.TOTP.enable(owner, :skip_verify)
diff --git a/test/plausible/teams/memberships/update_role_test.exs b/test/plausible/teams/memberships/update_role_test.exs
index 01ccc88848..2288c80b03 100644
--- a/test/plausible/teams/memberships/update_role_test.exs
+++ b/test/plausible/teams/memberships/update_role_test.exs
@@ -183,7 +183,7 @@ defmodule Plausible.Teams.Memberships.UpdateRoleTest do
new_identity(collaborator.name, collaborator.email)
|> Plausible.Auth.SSO.provision_user()
- assert {:error, :mfa_disabled} = UpdateRole.update(team, collaborator.id, "owner", user)
+ assert {:error, :disabled_2fa} = UpdateRole.update(team, collaborator.id, "owner", user)
end
end
end
diff --git a/test/plausible_web/controllers/sso_controller_test.exs b/test/plausible_web/controllers/sso_controller_test.exs
index 1668c2a3d2..8d2651deb1 100644
--- a/test/plausible_web/controllers/sso_controller_test.exs
+++ b/test/plausible_web/controllers/sso_controller_test.exs
@@ -61,7 +61,7 @@ defmodule PlausibleWeb.SSOControllerTest do
assert html = html_response(conn, 200)
- assert html =~ "Enter your Single Sign-on email"
+ assert html =~ "Enter your Single Sign-On email"
assert element_exists?(html, "input[name=email]")
assert text_of_attr(html, "input[name=return_to]", "value") == ""
end
@@ -79,7 +79,7 @@ defmodule PlausibleWeb.SSOControllerTest do
assert html = html_response(conn, 200)
- assert html =~ "Enter your Single Sign-on email"
+ assert html =~ "Enter your Single Sign-On email"
assert text_of_attr(html, "input[name=email]", "value") == "[email protected]"
assert html =~ ~s|document.getElementById("sso-login-form").submit()|
end
@@ -132,7 +132,7 @@ defmodule PlausibleWeb.SSOControllerTest do
domain: domain,
integration: integration
} do
- email = "paul@" <> domain
+ email = "claire@" <> domain
conn =
post(conn, Routes.sso_path(conn, :login), %{"email" => email, "return_to" => "/sites"})
@@ -155,11 +155,32 @@ defmodule PlausibleWeb.SSOControllerTest do
assert Phoenix.Flash.get(conn.assigns.flash, :login_error) == "Wrong email."
end
+
+ test "limits login attempts to 5 per minute", %{conn: conn} do
+ conn = put_req_header(conn, "x-forwarded-for", "1.2.3.9")
+ email = "[email protected]"
+
+ response =
+ eventually(
+ fn ->
+ Enum.each(1..5, fn _ ->
+ post(conn, Routes.sso_path(conn, :login), %{"email" => email})
+ end)
+
+ conn = post(conn, Routes.sso_path(conn, :login), %{"email" => email})
+
+ {conn.status == 429, conn}
+ end,
+ 500
+ )
+
+ assert html_response(response, 429) =~ "Too many login attempts"
+ end
end
describe "saml_signin/2 (fake SAML)" do
test "renders autosubmitted form", %{conn: conn, domain: domain, integration: integration} do
- email = "paul@" <> domain
+ email = "jesper@" <> domain
conn =
get(
@@ -172,7 +193,7 @@ defmodule PlausibleWeb.SSOControllerTest do
assert html = html_response(conn, 200)
- assert html =~ "Processing Single Sign-on request..."
+ assert html =~ "Processing Single Sign-On request..."
assert text_of_attr(html, "form#sso-req-form", "action") ==
Routes.sso_path(conn, :saml_consume, integration.identifier)
diff --git a/test/plausible_web/live/sso_management_test.exs b/test/plausible_web/live/sso_management_test.exs
index f6a000797b..6cc47e8546 100644
--- a/test/plausible_web/live/sso_management_test.exs
+++ b/test/plausible_web/live/sso_management_test.exs
@@ -78,8 +78,8 @@ defmodule PlausibleWeb.Live.SSOMangementTest do
text = text(render(lv))
- assert text =~ "Sign-in URL can't be blank"
- assert text =~ "Entity ID can't be blank"
+ assert text =~ "SSO URL / Sign-on URL / Login URL can't be blank"
+ assert text =~ "Entity ID / Issuer / Identifier can't be blank"
assert text =~ "Certificate in PEM format can't be blank"
lv
diff --git a/test/plausible_web/live/team_management_test.exs b/test/plausible_web/live/team_management_test.exs
index 7f549e3048..127267888a 100644
--- a/test/plausible_web/live/team_management_test.exs
+++ b/test/plausible_web/live/team_management_test.exs
@@ -61,7 +61,7 @@ defmodule PlausibleWeb.Live.TeamMangementTest do
:setup_team
]
- test "fails to save layout with SSO user updated to owner with Force SSO but without MFA",
+ test "fails to save layout with SSO user updated to owner with Force SSO but without 2FA",
%{
conn: conn,
team: team,