Skip to content

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

Dialyzer and Credo checks (#558)

Oliver Kriskaae42b86792dc
diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml
index 6cd27f5911..328feee941 100644
--- a/.github/workflows/elixir.yml
+++ b/.github/workflows/elixir.yml
@@ -2,9 +2,9 @@ name: Elixir CI
on:
push:
- branches: [ master, stable ]
+ branches: [master, stable]
pull_request:
- branches: [ master, stable ]
+ branches: [master, stable]
jobs:
build:
@@ -36,26 +36,35 @@ jobs:
--health-retries 5
steps:
- - uses: actions/checkout@v2
- - name: Read .tool-versions
- uses: marocchino/tool-versions-action@v1
- id: versions
- - name: Set up Elixir
- uses: actions/setup-elixir@v1
- with:
- elixir-version: ${{steps.versions.outputs.elixir}}
- otp-version: ${{ steps.versions.outputs.erlang}}
- - name: Restore dependencies cache
- uses: actions/cache@v2
- with:
- path: deps
- key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
- restore-keys: ${{ runner.os }}-mix-
- - name: Install dependencies
- run: mix deps.get
- - name: Check Formatting
- run: mix format --check-formatted
- - name: Run tests
- run: mix test
+ - uses: actions/checkout@v2
+ - name: Read .tool-versions
+ uses: marocchino/tool-versions-action@v1
+ id: versions
+ - name: Set up Elixir
+ uses: actions/setup-elixir@v1
+ with:
+ elixir-version: ${{steps.versions.outputs.elixir}}
+ otp-version: ${{ steps.versions.outputs.erlang}}
+ - name: Restore dependencies cache
+ uses: actions/cache@v2
+ with:
+ path: |
+ deps
+ _build
+ priv/plts
+ key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
+ restore-keys: ${{ runner.os }}-mix-
+ - name: Install dependencies
+ run: mix deps.get
+ - name: Check Formatting
+ run: mix format --check-formatted
+ - name: Check Compile Warnings
+ run: mix compile --warnings-as-errors --all-warnings
+ - name: Run tests
+ run: mix test
+ - name: Check Dialyzer
+ run: mix dialyzer
+ - name: Check Credo Warnings
+ run: mix credo --strict --only warning --ignore Consistency
env:
MIX_ENV: test
diff --git a/.gitignore b/.gitignore
index 606074d1df..9a60ff83f5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,4 +54,8 @@ plausible-report.xml
.idea
*.iml
*.log
-*.code-workspace
\ No newline at end of file
+*.code-workspace
+
+# Dializer
+/priv/plts/*.plt
+/priv/plts/*.plt.hash
\ No newline at end of file
diff --git a/lib/plausible/application.ex b/lib/plausible/application.ex
index 6ca73f49b2..37db3dd912 100644
--- a/lib/plausible/application.ex
+++ b/lib/plausible/application.ex
@@ -3,6 +3,8 @@ defmodule Plausible.Application do
use Application
+ require Logger
+
def start(_type, _args) do
children = [
Plausible.Repo,
@@ -40,8 +42,7 @@ defmodule Plausible.Application do
def report_cache_stats() do
case Cachex.stats(:user_agents) do
{:ok, stats} ->
- IO.puts("User agent cache stats:")
- IO.inspect(stats, pretty: true)
+ Logger.info("User agent cache stats: #{inspect(stats)}")
e ->
IO.puts("Unable to show cache stats: #{inspect(e)}")
diff --git a/lib/plausible/auth/token.ex b/lib/plausible/auth/token.ex
index cbf0ecfeb5..f53123f8c0 100644
--- a/lib/plausible/auth/token.ex
+++ b/lib/plausible/auth/token.ex
@@ -1,5 +1,4 @@
defmodule Plausible.Auth.Token do
- @one_day_in_seconds 30 * 60 * 24
@one_hour_in_seconds 30 * 60
def sign_password_reset(email) do
diff --git a/lib/plausible/billing/billing.ex b/lib/plausible/billing/billing.ex
index f84eee8fe8..97c65de5c8 100644
--- a/lib/plausible/billing/billing.ex
+++ b/lib/plausible/billing/billing.ex
@@ -1,7 +1,6 @@
defmodule Plausible.Billing do
use Plausible.Repo
alias Plausible.Billing.{Subscription, PaddleApi}
- @paddle_api Application.fetch_env!(:plausible, :paddle_api)
def active_subscription_for(user_id) do
Repo.get_by(Subscription, user_id: user_id, status: "active")
@@ -58,7 +57,7 @@ defmodule Plausible.Billing do
subscription = Repo.get_by(Subscription, paddle_subscription_id: params["subscription_id"])
if subscription do
- {:ok, api_subscription} = @paddle_api.get_subscription(subscription.paddle_subscription_id)
+ {:ok, api_subscription} = paddle_api().get_subscription(subscription.paddle_subscription_id)
amount =
:erlang.float_to_binary(api_subscription["next_payment"]["amount"] / 1, decimals: 2)
@@ -79,7 +78,7 @@ defmodule Plausible.Billing do
subscription = active_subscription_for(user.id)
res =
- @paddle_api.update_subscription(subscription.paddle_subscription_id, %{
+ paddle_api().update_subscription(subscription.paddle_subscription_id, %{
plan_id: new_plan_id
})
@@ -158,4 +157,6 @@ defmodule Plausible.Billing do
defp present?(""), do: false
defp present?(nil), do: false
defp present?(_), do: true
+
+ defp paddle_api(), do: Application.fetch_env!(:plausible, :paddle_api)
end
diff --git a/lib/plausible/mailer.ex b/lib/plausible/mailer.ex
index 220a655f53..908d05bc0f 100644
--- a/lib/plausible/mailer.ex
+++ b/lib/plausible/mailer.ex
@@ -11,7 +11,7 @@ defmodule Plausible.Mailer do
extra: %{extra: "Error while sending email"}
)
- raise error
+ reraise error, __STACKTRACE__
end
end
end
diff --git a/lib/plausible/session/store.ex b/lib/plausible/session/store.ex
index 1b94103561..e7d91a56cc 100644
--- a/lib/plausible/session/store.ex
+++ b/lib/plausible/session/store.ex
@@ -5,8 +5,6 @@ defmodule Plausible.Session.Store do
import Ecto.Query, only: [from: 2]
require Logger
- @session_length_seconds Application.get_env(:plausible, :session_length_minutes) * 60
- @forget_session_after @session_length_seconds * 2
@garbage_collect_interval_milliseconds 60 * 1000
def start_link(opts) do
@@ -19,7 +17,7 @@ defmodule Plausible.Session.Store do
latest_sessions =
from(
s in "sessions",
- where: s.timestamp >= fragment("now() - INTERVAL ? SECOND", @forget_session_after),
+ where: s.timestamp >= fragment("now() - INTERVAL ? SECOND", ^forget_session_after()),
group_by: s.session_id,
select: %{session_id: s.session_id, timestamp: max(s.timestamp)}
)
@@ -72,7 +70,7 @@ defmodule Plausible.Session.Store do
end
defp is_active?(session, event) do
- session && Timex.diff(event.timestamp, session.timestamp, :second) < @session_length_seconds
+ session && Timex.diff(event.timestamp, session.timestamp, :second) < session_length_seconds()
end
defp update_session(session, event) do
@@ -125,7 +123,7 @@ defmodule Plausible.Session.Store do
new_sessions =
Enum.reduce(state[:sessions], %{}, fn {key, session}, acc ->
- if Timex.diff(now, session.timestamp, :second) <= @forget_session_after do
+ if Timex.diff(now, session.timestamp, :second) <= forget_session_after() do
Map.put(acc, key, session)
else
# forget the session
@@ -146,4 +144,7 @@ defmodule Plausible.Session.Store do
{:noreply, %{state | sessions: new_sessions, timer: new_timer}}
end
+
+ defp session_length_seconds(), do: Application.get_env(:plausible, :session_length_minutes) * 60
+ defp forget_session_after(), do: session_length_seconds() * 2
end
diff --git a/lib/plausible_web/controllers/api/external_controller.ex b/lib/plausible_web/controllers/api/external_controller.ex
index a1b710e4a9..62faa8315f 100644
--- a/lib/plausible_web/controllers/api/external_controller.ex
+++ b/lib/plausible_web/controllers/api/external_controller.ex
@@ -195,7 +195,7 @@ defmodule PlausibleWeb.Api.ExternalController do
defp clean_referrer(ref) do
uri = URI.parse(ref.referer)
- if uri && uri.host && uri.scheme in ["http", "https"] do
+ if right_uri?(uri) do
host = String.replace_prefix(uri.host, "www.", "")
path = uri.path || ""
host <> String.trim_trailing(path, "/")
@@ -279,8 +279,16 @@ defmodule PlausibleWeb.Api.ExternalController do
defp clean_uri(uri) do
uri = URI.parse(String.trim(uri))
- if uri && uri.host && uri.scheme in ["http", "https"] do
+ if right_uri?(uri) do
String.replace_leading(uri.host, "www.", "")
end
end
+
+ defp right_uri?(%URI{host: nil}), do: false
+
+ defp right_uri?(%URI{host: host, scheme: scheme})
+ when scheme in ["http", "https"] and byte_size(host) > 0,
+ do: true
+
+ defp right_uri?(_), do: false
end
diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex
index 643858c62a..a949551790 100644
--- a/lib/plausible_web/controllers/api/stats_controller.ex
+++ b/lib/plausible_web/controllers/api/stats_controller.ex
@@ -163,15 +163,13 @@ defmodule PlausibleWeb.Api.StatsController do
json(conn, Stats.utm_sources(site, query, limit || 9, page || 1, show_noref))
end
- @google_api Application.fetch_env!(:plausible, :google_api)
-
def referrer_drilldown(conn, %{"referrer" => "Google"} = params) do
site = conn.assigns[:site] |> Repo.preload(:google_auth)
query = Query.from(site.timezone, params)
search_terms =
if site.google_auth && site.google_auth.property && !query.filters["goal"] do
- @google_api.fetch_stats(site, query, params["limit"] || 9)
+ google_api().fetch_stats(site, query, params["limit"] || 9)
end
case search_terms do
@@ -317,4 +315,6 @@ defmodule PlausibleWeb.Api.StatsController do
query = Query.from(site.timezone, %{"period" => "realtime"})
json(conn, Stats.current_visitors(site, query))
end
+
+ defp google_api(), do: Application.fetch_env!(:plausible, :google_api)
end
diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex
index 01f38bdd9e..1ada071e37 100644
--- a/lib/plausible_web/controllers/site_controller.ex
+++ b/lib/plausible_web/controllers/site_controller.ex
@@ -283,7 +283,7 @@ defmodule PlausibleWeb.SiteController do
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/settings/general")
{:error, changeset} ->
- render("settings_general.html", site: site, changeset: changeset)
+ render(conn, "settings_general.html", site: site, changeset: changeset)
end
end
diff --git a/lib/plausible_web/plugs/crm_auth_plug.ex b/lib/plausible_web/plugs/crm_auth_plug.ex
index 1411387606..7f28539981 100644
--- a/lib/plausible_web/plugs/crm_auth_plug.ex
+++ b/lib/plausible_web/plugs/crm_auth_plug.ex
@@ -1,7 +1,6 @@
defmodule PlausibleWeb.CRMAuthPlug do
import Plug.Conn
use Plausible.Repo
- @admin_emails Application.get_env(:plausible, :admin_emails)
def init(options) do
options
@@ -15,11 +14,13 @@ defmodule PlausibleWeb.CRMAuthPlug do
id ->
user = Repo.get_by(Plausible.Auth.User, id: id)
- if user && user.email in @admin_emails do
+ if user && user.email in admin_emails() do
assign(conn, :current_user, user)
else
conn |> send_resp(403, "Not allowed") |> halt
end
end
end
+
+ defp admin_emails(), do: Application.get_env(:plausible, :admin_emails)
end
diff --git a/lib/workers/send_site_setup_emails.ex b/lib/workers/send_site_setup_emails.ex
index 03b2e2ce5f..9fc928ed93 100644
--- a/lib/workers/send_site_setup_emails.ex
+++ b/lib/workers/send_site_setup_emails.ex
@@ -26,7 +26,7 @@ defmodule Plausible.Workers.SendSiteSetupEmails do
)
for user <- Repo.all(q) do
- if Enum.count(user.sites) == 0 do
+ if Enum.empty?(user.sites) do
send_create_site_email(user)
end
end
diff --git a/mix.exs b/mix.exs
index 49a9383d50..3a7a9b1bdb 100644
--- a/mix.exs
+++ b/mix.exs
@@ -20,6 +20,10 @@ defmodule Plausible.MixProject do
applications: [plausible: :permanent],
steps: [:assemble, :tar]
]
+ ],
+ dialyzer: [
+ plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
+ plt_add_apps: [:mix, :ex_unit]
]
]
end
@@ -95,6 +99,8 @@ defmodule Plausible.MixProject do
{:geolix_adapter_mmdb2, "~> 0.5.0"},
{:mix_test_watch, "~> 1.0", only: :dev, runtime: false},
{:cachex, "~> 3.3"},
+ {:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
+ {:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:kaffy, "~> 0.9.0"}
]
end
diff --git a/mix.lock b/mix.lock
index 8627054b3f..ed08b665b6 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,5 +1,5 @@
%{
- "appsignal": {:hex, :appsignal, "2.0.5", "4438b57e96e17b4d76e297ae2bc1a646bfe0a323e2d7128f4af26fc36170c8d8", [:make, :mix], [{:decorator, "~> 1.2.3 or ~> 1.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "25ab92647dc4756861a302d092dc6fb7f8358e0dab6587538fa27e958bc77803"},
+ "appsignal": {:hex, :appsignal, "2.0.7", "54da8dd1c315c9cd7b55aca13af29455d5394c4157a0fee6766320b331e7d97d", [:make, :mix], [{:decorator, "~> 1.2.3 or ~> 1.3", [hex: :decorator, repo: "hexpm", optional: false]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, ">= 1.3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e314e89d817e91afc4f1e60f9f32022e64e348ce4deb84d3453de9b4fb23a7a9"},
"appsignal_phoenix": {:hex, :appsignal_phoenix, "2.0.2", "17d58f3ddfbc7dd78177f83cf6c5e7531c78742d9d46ff6db33a712ccd2ec098", [:mix], [{:appsignal_plug, "~> 2.0.0", [hex: :appsignal_plug, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.11", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_live_view, "~> 0.9", [hex: :phoenix_live_view, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d41e3892f1cbbdc1762722ea36ff224b087a5fc564fa312ef4c8327391326b96"},
"appsignal_plug": {:hex, :appsignal_plug, "2.0.2", "18363dfa34c5e6aef7c0c71ea38a6e0dcf2d16e06c47bb53a125fc8d9de09a32", [:mix], [{:appsignal, "~> 2.0.0", [hex: :appsignal, repo: "hexpm", optional: false]}, {:plug, ">= 1.1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "bd36e4232973de1e3b537cd8c96e1514ee43a5f58a02702b6d03f7d70d0ce17d"},
"bamboo": {:hex, :bamboo, "1.6.0", "adfb583bef028923aae6f22deaea6667290561da1246058556ecaeb0fec5a175", [:mix], [{:hackney, ">= 1.13.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "454e67feacbc9b6e00553ce1d2fba003c861e0035600d59b09d6159985b17f9b"},
@@ -8,8 +8,9 @@
"bcrypt_elixir": {:hex, :bcrypt_elixir, "2.2.0", "3df902b81ce7fa8867a2ae30d20a1da6877a2c056bfb116fd0bc8a5f0190cea4", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "762be3fcb779f08207531bc6612cca480a338e4b4357abb49f5ce00240a77d1e"},
"bertex": {:hex, :bertex, "1.3.0", "0ad0df9159b5110d9d2b6654f72fbf42a54884ef43b6b651e6224c0af30ba3cb", [:mix], [], "hexpm", "0a5d5e478bb5764b7b7bae37cae1ca491200e58b089df121a2fe1c223d8ee57a"},
"browser": {:hex, :browser, "0.4.4", "bd6436961a6b2299c6cb38d0e49761c1161d869cd0db46369cef2bf6b77c3665", [:mix], [{:plug, "~> 1.2", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "d476ca309d4a4b19742b870380390aabbcb323c1f6f8745e2da2dfd079b4f8d7"},
+ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"cachex": {:hex, :cachex, "3.3.0", "6f2ebb8f27491fe39121bd207c78badc499214d76c695658b19d6079beeca5c2", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "d90e5ee1dde14cef33f6b187af4335b88748b72b30c038969176cd4e6ccc31a1"},
- "certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"},
+ "certifi": {:hex, :certifi, "2.5.3", "70bdd7e7188c804f3a30ee0e7c99655bc35d8ac41c23e12325f36ab449b70651", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "ed516acb3929b101208a9d700062d520f3953da3b6b918d866106ffa980e1c10"},
"clickhouse_ecto": {:git, "https://github.com/plausible/clickhouse_ecto.git", "918e84e55072948170b5c8a2207ba394aaeb8e5b", []},
"clickhousex": {:git, "https://github.com/plausible/clickhousex", "0832dd4b1af1f0eba1d1018c231bf0d8d281f031", []},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"},
@@ -18,15 +19,18 @@
"cors_plug": {:hex, :cors_plug, "1.5.2", "72df63c87e4f94112f458ce9d25800900cc88608c1078f0e4faddf20933eda6e", [:mix], [{:plug, "~> 1.3 or ~> 1.4 or ~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9af027d20dc12dd0c4345a6b87247e0c62965871feea0bfecf9764648b02cc69"},
"cowboy": {:hex, :cowboy, "2.7.0", "91ed100138a764355f43316b1d23d7ff6bdb0de4ea618cb5d8677c93a7a2f115", [:rebar3], [{:cowlib, "~> 2.8.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "04fd8c6a39edc6aaa9c26123009200fc61f92a3a94f3178c527b70b767c6e605"},
"cowlib": {:hex, :cowlib, "2.8.0", "fd0ff1787db84ac415b8211573e9a30a3ebe71b5cbff7f720089972b2319c8a4", [:rebar3], [], "hexpm", "79f954a7021b302186a950a32869dbc185523d99d3e44ce430cd1f3289f41ed4"},
+ "credo": {:hex, :credo, "1.5.4", "9914180105b438e378e94a844ec3a5088ae5875626fc945b7c1462b41afc3198", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "cf51af45eadc0a3f39ba13b56fdac415c91b34f7b7533a13dc13550277141bc4"},
"csv": {:hex, :csv, "2.3.1", "9ce11eff5a74a07baf3787b2b19dd798724d29a9c3a492a41df39f6af686da0e", [:mix], [{:parallel_stream, "~> 1.0.4", [hex: :parallel_stream, repo: "hexpm", optional: false]}], "hexpm", "86626e1c89a4ad9a96d0d9c638f9e88c2346b89b4ba1611988594ebe72b5d5ee"},
"db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"},
"decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"},
"decorator": {:hex, :decorator, "1.3.2", "63b8ac9e23b28053390abdda33bb9e1f3dd9e8f9a981f47a06fc2f2fe2e2f772", [:mix], [], "hexpm", "b80bd089e3c8579e6d9ea84eed307b1597a0d94af25331e424a209477ad1a7fc"},
+ "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"double": {:hex, :double, "0.7.0", "a7ee4c3488a0acc6d2ad9b69b6c7d3ddf3da2b54488d0f7c2d6ceb3a995887ca", [:mix], [], "hexpm", "f0c387a2266b4452da7bab03598feec11aef8b2acab061ea947dae81bb257329"},
"ecto": {:hex, :ecto, "3.4.6", "08f7afad3257d6eb8613309af31037e16c36808dfda5a3cd0cb4e9738db030e4", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6f13a9e2a62e75c2dcfc7207bfc65645ab387af8360db4c89fee8b5a4bf3f70b"},
"ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"},
"elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
+ "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"eternal": {:hex, :eternal, "1.2.2", "d1641c86368de99375b98d183042dd6c2b234262b8d08dfd72b9eeaafc2a1abd", [:mix], [], "hexpm", "2c9fe32b9c3726703ba5e1d43a1d255a4f3f2d8f8f9bc19f094c7cb1a7a9e782"},
"ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"},
"excoveralls": {:hex, :excoveralls, "0.12.3", "2142be7cb978a3ae78385487edda6d1aff0e482ffc6123877bb7270a8ffbcfe0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "568a3e616c264283f5dea5b020783ae40eef3f7ee2163f7a67cbd7b35bcadada"},
@@ -35,9 +39,9 @@
"geolix": {:hex, :geolix, "1.1.0", "8b0fe847fef486d9e8b7c21eae6cbc2d998fb249e61d3f4f136f8016b9c1c833", [:mix], [{:poolboy, "~> 1.0", [hex: :poolboy, repo: "hexpm", optional: false]}], "hexpm", "980854f2aef30c288dc79e86c5267806d704c4525fde1b75de9a92f67fb16300"},
"geolix_adapter_mmdb2": {:hex, :geolix_adapter_mmdb2, "0.5.0", "5912723d9538ecddc6b29b1d8041b917b735a78fd3c122bfea8c44aa782e3369", [:mix], [{:geolix, "~> 1.1", [hex: :geolix, repo: "hexpm", optional: false]}, {:mmdb2_decoder, "~> 3.0", [hex: :mmdb2_decoder, repo: "hexpm", optional: false]}], "hexpm", "cb1485b6a0a2d3e541949207428a245718dbf1258453a0df0e5fdd925bcecd3e"},
"gettext": {:hex, :gettext, "0.18.0", "406d6b9e0e3278162c2ae1de0a60270452c553536772167e2d701f028116f870", [:mix], [], "hexpm", "c3f850be6367ebe1a08616c2158affe4a23231c70391050bf359d5f92f66a571"},
- "hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"},
+ "hackney": {:hex, :hackney, "1.17.0", "717ea195fd2f898d9fe9f1ce0afcc2621a41ecfe137fae57e7fe6e9484b9aa99", [:rebar3], [{:certifi, "~>2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "64c22225f1ea8855f584720c0e5b3cd14095703af1c9fbc845ba042811dc671c"},
"httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "aa2c74bd271af34239a3948779612f87df2422c2fdcfdbcec28d9c105f0773fe"},
- "idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"},
+ "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"},
"jumper": {:hex, :jumper, "1.0.1", "3c00542ef1a83532b72269fab9f0f0c82bf23a35e27d278bfd9ed0865cecabff", [:mix], [], "hexpm", "318c59078ac220e966d27af3646026db9b5a5e6703cb2aa3e26bcfaba65b7433"},
"junit_formatter": {:hex, :junit_formatter, "3.1.0", "3f69c61c5413750f9c45e367d77aabbeac9b395acf478d8e70b4ee9d1989c709", [:mix], [], "hexpm", "da52401a93f711fc4f77ffabdda68f9a16fcad5d96f5fce4ae606ab1d73b72f4"},
@@ -51,7 +55,7 @@
"oauther": {:hex, :oauther, "1.1.1", "7d8b16167bb587ecbcddd3f8792beb9ec3e7b65c1f8ebd86b8dd25318d535752", [:mix], [], "hexpm", "9374f4302045321874cccdc57eb975893643bd69c3b22bf1312dab5f06e5788e"},
"oban": {:hex, :oban, "1.2.0", "7cca94d341be43d220571e28f69131c4afc21095b25257397f50973d3fc59b07", [:mix], [{:ecto_sql, "~> 3.1", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.14", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ba5f8b3f7d76967b3e23cf8014f6a13e4ccb33431e4808f036709a7f822362ee"},
"parallel_stream": {:hex, :parallel_stream, "1.0.6", "b967be2b23f0f6787fab7ed681b4c45a215a81481fb62b01a5b750fa8f30f76c", [:mix], [], "hexpm", "639b2e8749e11b87b9eb42f2ad325d161c170b39b288ac8d04c4f31f8f0823eb"},
- "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
+ "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"phoenix": {:hex, :phoenix, "1.4.17", "1b1bd4cff7cfc87c94deaa7d60dd8c22e04368ab95499483c50640ef3bd838d8", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a8e5d7a3d76d452bb5fb86e8b7bd115f737e4f8efe202a463d4aeb4a5809611"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.1.0", "a044d0756d0464c5a541b4a0bf4bcaf89bffcaf92468862408290682c73ae50d", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.9", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c5e666a341ff104d0399d8f0e4ff094559b2fde13a5985d4cb5023b2c2ac558b"},
"phoenix_html": {:hex, :phoenix_html, "2.14.2", "b8a3899a72050f3f48a36430da507dd99caf0ac2d06c77529b1646964f3d563e", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "58061c8dfd25da5df1ea0ca47c972f161beb6c875cd293917045b92ffe1bf617"},
@@ -75,7 +79,7 @@
"timex": {:hex, :timex, "3.6.2", "845cdeb6119e2fef10751c0b247b6c59d86d78554c83f78db612e3290f819bc2", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5 or ~> 1.0.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "26030b46199d02a590be61c2394b37ea25a3664c02fafbeca0b24c972025d47a"},
"tzdata": {:hex, :tzdata, "1.0.3", "73470ad29dde46e350c60a66e6b360d3b99d2d18b74c4c349dbebbc27a09a3eb", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a6e1ee7003c4d04ecbd21dd3ec690d4c6662db5d3bbdd7262d53cdf5e7c746c1"},
"ua_inspector": {:hex, :ua_inspector, "0.20.0", "01939baf5706f7d6c2dc0affbbd7f5e14309ba43ebf8967aa6479ee2204f23bc", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.0", [hex: :poolboy, repo: "hexpm", optional: false]}, {:yamerl, "~> 0.7", [hex: :yamerl, repo: "hexpm", optional: false]}], "hexpm", "30e8623b9f55e7d58be12fc2afd50be8792ec14192c289701d3cc93ad6027f26"},
- "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"},
+ "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"},
"yamerl": {:hex, :yamerl, "0.8.0", "8214cfe16bbabe5d1d6c14a14aea11c784b9a21903dd6a7c74f8ce180adae5c7", [:rebar3], [], "hexpm", "010634477bf9c208a0767dcca89116c2442cf0b5e87f9c870f85cd1c3e0c2aab"},
}
diff --git a/test/support/factory.ex b/test/support/factory.ex
index cf6580d98a..3b35981930 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -1,12 +1,6 @@
defmodule Plausible.Factory do
use ExMachina.Ecto, repo: Plausible.Repo
- @hash_key Keyword.fetch!(
- Application.get_env(:plausible, PlausibleWeb.Endpoint),
- :secret_key_base
- )
- |> binary_part(0, 16)
-
def user_factory(attrs) do
pw = Map.get(attrs, :password, "password")
@@ -41,8 +35,8 @@ defmodule Plausible.Factory do
%Plausible.ClickhouseSession{
sign: 1,
- session_id: SipHash.hash!(@hash_key, UUID.uuid4()),
- user_id: SipHash.hash!(@hash_key, UUID.uuid4()),
+ session_id: SipHash.hash!(hash_key(), UUID.uuid4()),
+ user_id: SipHash.hash!(hash_key(), UUID.uuid4()),
hostname: hostname,
domain: hostname,
referrer: "",
@@ -83,8 +77,8 @@ defmodule Plausible.Factory do
domain: hostname,
pathname: "/",
timestamp: Timex.now(),
- user_id: SipHash.hash!(@hash_key, UUID.uuid4()),
- session_id: SipHash.hash!(@hash_key, UUID.uuid4()),
+ user_id: SipHash.hash!(hash_key(), UUID.uuid4()),
+ session_id: SipHash.hash!(hash_key(), UUID.uuid4()),
referrer: "",
referrer_source: "",
utm_medium: "",
@@ -156,4 +150,12 @@ defmodule Plausible.Factory do
slug: Nanoid.generate()
}
end
+
+ defp hash_key() do
+ Keyword.fetch!(
+ Application.get_env(:plausible, PlausibleWeb.Endpoint),
+ :secret_key_base
+ )
+ |> binary_part(0, 16)
+ end
end
diff --git a/test/workers/schedule_email_reports_test.exs b/test/workers/schedule_email_reports_test.exs
index 36b2dcccd7..2554eda6c4 100644
--- a/test/workers/schedule_email_reports_test.exs
+++ b/test/workers/schedule_email_reports_test.exs
@@ -38,7 +38,7 @@ defmodule Plausible.Workers.ScheduleEmailReportsTest do
perform(%{})
Repo.update_all("oban_jobs", set: [state: "completed"])
- assert Enum.count(all_enqueued(worker: SendEmailReport)) == 0
+ assert Enum.empty?(all_enqueued(worker: SendEmailReport))
perform(%{})
assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1
end
@@ -74,7 +74,7 @@ defmodule Plausible.Workers.ScheduleEmailReportsTest do
perform(%{})
Repo.update_all("oban_jobs", set: [state: "completed"])
- assert Enum.count(all_enqueued(worker: SendEmailReport)) == 0
+ assert Enum.empty?(all_enqueued(worker: SendEmailReport))
perform(%{})
assert Enum.count(all_enqueued(worker: SendEmailReport)) == 1
end