Delete test/plausible/installation_support/detection/checks_test.exs with huggingface_hub
Browse files
test/plausible/installation_support/detection/checks_test.exs
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 1 |
-
defmodule Plausible.InstallationSupport.Detection.ChecksTest do
|
| 2 |
-
use PlausibleWeb.ConnCase, async: true
|
| 3 |
-
|
| 4 |
-
@moduletag :ee_only
|
| 5 |
-
|
| 6 |
-
on_ee do
|
| 7 |
-
use Plausible.Test.Support.DNS
|
| 8 |
-
import Plausible.AssertMatches
|
| 9 |
-
alias Plausible.InstallationSupport.Detection.Checks
|
| 10 |
-
alias Plausible.InstallationSupport.Result
|
| 11 |
-
|
| 12 |
-
@moduletag :capture_log
|
| 13 |
-
|
| 14 |
-
@expected_domain "example.com"
|
| 15 |
-
|
| 16 |
-
describe "running detection" do
|
| 17 |
-
test "handles wordpress detection, retrying on 429" do
|
| 18 |
-
url_to_verify = nil
|
| 19 |
-
test = self()
|
| 20 |
-
stub_lookup_a_records(@expected_domain)
|
| 21 |
-
|
| 22 |
-
get_context_from_body = fn conn ->
|
| 23 |
-
{:ok, body, _conn} = Plug.Conn.read_body(conn)
|
| 24 |
-
JSON.decode!(body)["context"]
|
| 25 |
-
end
|
| 26 |
-
|
| 27 |
-
detection_counter =
|
| 28 |
-
stub_detection_result_with_counter(fn conn, request_i ->
|
| 29 |
-
send(test, get_context_from_body.(conn))
|
| 30 |
-
|
| 31 |
-
case request_i do
|
| 32 |
-
1 ->
|
| 33 |
-
conn |> send_resp(429, "Too Many Requests")
|
| 34 |
-
|
| 35 |
-
_ ->
|
| 36 |
-
conn
|
| 37 |
-
|> put_resp_content_type("application/json")
|
| 38 |
-
|> send_resp(
|
| 39 |
-
200,
|
| 40 |
-
JSON.encode!(%{
|
| 41 |
-
"data" => %{
|
| 42 |
-
"completed" => true,
|
| 43 |
-
"v1Detected" => nil,
|
| 44 |
-
"gtmLikely" => false,
|
| 45 |
-
"npm" => false,
|
| 46 |
-
"wordpressLikely" => true,
|
| 47 |
-
"wordpressPlugin" => false
|
| 48 |
-
}
|
| 49 |
-
})
|
| 50 |
-
)
|
| 51 |
-
end
|
| 52 |
-
end)
|
| 53 |
-
|
| 54 |
-
assert %Result{
|
| 55 |
-
ok?: true,
|
| 56 |
-
data: %{
|
| 57 |
-
v1_detected: nil,
|
| 58 |
-
wordpress_plugin: false,
|
| 59 |
-
npm: false,
|
| 60 |
-
suggested_technology: "wordpress"
|
| 61 |
-
}
|
| 62 |
-
} ==
|
| 63 |
-
Checks.run(url_to_verify, @expected_domain,
|
| 64 |
-
report_to: nil,
|
| 65 |
-
async?: false,
|
| 66 |
-
slowdown: 0
|
| 67 |
-
)
|
| 68 |
-
|> Checks.interpret_diagnostics()
|
| 69 |
-
|
| 70 |
-
assert_receive context
|
| 71 |
-
|
| 72 |
-
assert_matches ^strict_map(%{
|
| 73 |
-
"debug" => false,
|
| 74 |
-
"detectV1" => false,
|
| 75 |
-
"timeoutMs" => 1500,
|
| 76 |
-
"url" =>
|
| 77 |
-
^any(
|
| 78 |
-
:string,
|
| 79 |
-
~r/https:\/\/#{@expected_domain}\?plausible_verification=\d+$/
|
| 80 |
-
),
|
| 81 |
-
"userAgent" =>
|
| 82 |
-
"Plausible Verification Agent - if abused, contact support@plausible.io"
|
| 83 |
-
}) = context
|
| 84 |
-
|
| 85 |
-
assert 2 == :atomics.get(detection_counter, 1)
|
| 86 |
-
end
|
| 87 |
-
end
|
| 88 |
-
|
| 89 |
-
defp stub_detection_result_with_counter(handler) do
|
| 90 |
-
counter = :atomics.new(1, [])
|
| 91 |
-
|
| 92 |
-
Req.Test.stub(Plausible.InstallationSupport.Checks.Detection, fn conn ->
|
| 93 |
-
request_i = :atomics.add_get(counter, 1, 1)
|
| 94 |
-
|
| 95 |
-
handler.(conn, request_i)
|
| 96 |
-
end)
|
| 97 |
-
|
| 98 |
-
counter
|
| 99 |
-
end
|
| 100 |
-
end
|
| 101 |
-
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|