From 78c5762761c5f4771d01ebb740714f685cd4898c Mon Sep 17 00:00:00 2001 From: hq1 Date: Mon, 27 May 2024 10:52:22 +0200 Subject: [PATCH] Verification: prioritize domain mismatch over multiple snippets (#4146) --- lib/plausible/verification/diagnostics.ex | 8 +++---- .../site/verification/checks_test.exs | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/plausible/verification/diagnostics.ex b/lib/plausible/verification/diagnostics.ex index 907d501ff..dc5477af4 100644 --- a/lib/plausible/verification/diagnostics.ex +++ b/lib/plausible/verification/diagnostics.ex @@ -187,6 +187,10 @@ defmodule Plausible.Verification.Diagnostics do error(@errors.proxy_general) end + def interpret(%__MODULE__{data_domain_mismatch?: true}, "https://" <> domain) do + error(@errors.different_data_domain, domain: domain) + end + def interpret( %__MODULE__{snippets_found_in_head: count_head, snippets_found_in_body: count_body}, _url @@ -238,10 +242,6 @@ defmodule Plausible.Verification.Diagnostics do error(@errors.snippet_in_body) end - def interpret(%__MODULE__{data_domain_mismatch?: true}, "https://" <> domain) do - error(@errors.different_data_domain, domain: domain) - end - def interpret( %__MODULE__{ plausible_installed?: false, diff --git a/test/plausible/site/verification/checks_test.exs b/test/plausible/site/verification/checks_test.exs index 3838b9860..014395289 100644 --- a/test/plausible/site/verification/checks_test.exs +++ b/test/plausible/site/verification/checks_test.exs @@ -671,6 +671,27 @@ defmodule Plausible.Verification.ChecksTest do assert_receive :redirect_sent end + + @many_snippets_with_domain_mismatch """ + + + + + + + Hello + + + """ + + test "prioritizes data-domain mismatch over multiple snippets" do + stub_fetch_body(200, @many_snippets_with_domain_mismatch) + stub_installation() + + run_checks() + |> Checks.interpret_diagnostics() + |> assert_error(@errors.different_data_domain, domain: "example.com") + end end defp run_checks(extra_opts \\ []) do