mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
Minor test improvements (#644)
* Minor test improvements * Don't hardcode MIX_ENV; clarify .env file usage * Spruce up fz_common tests
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
MIX_ENV=dev
|
||||
# This is a sample .env file. Update and add variables in here as needed, and
|
||||
# rename to `.env`
|
||||
# rename to `.env`. These are mostly used in dev and test environments -- prod
|
||||
# variables are loaded at runtime from the Omnibus package.
|
||||
|
||||
# Set the EXTERNAL_URL
|
||||
EXTERNAL_URL=http://localhost:4000
|
||||
|
||||
# Enable local authentication
|
||||
LOCAL_AUTH_ENABLED=true
|
||||
|
||||
# Set PROXY_FORWARDED to true if you're running this behind a proxy or using
|
||||
@@ -12,4 +13,6 @@ LOCAL_AUTH_ENABLED=true
|
||||
PROXY_FORWARDED=true
|
||||
|
||||
# Generated with `jq @json < .oidc_env.json`
|
||||
# Set AUTH_OIDC to a JSON configuration string to enable
|
||||
# generic OIDC auth.
|
||||
# export AUTH_OIDC="{\"google\":{\"discovery_document_uri\":\"https://accounts.google.com/.well-known/openid-configuration\",\"client_id\":\"1032390727302-u0lg90d3i1ive15lv7qgtbkka0hnsmgr.apps.googleusercontent.com\",\"client_secret\":\"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\",\"redirect_uri\":\"https://example.com/session\",\"response_type\":\"code\",\"scope\":\"openid email profile\",\"label\":\"Google\"},\"okta\":{\"discovery_document_uri\":\"https://accounts.google.com/.well-known/openid-configuration\",\"client_id\":\"CLIENT_ID\",\"client_secret\":\"CLIENT_SECRET\",\"redirect_uri\":\"https://example.com/session\",\"response_type\":\"code\",\"scope\":\"openid email profile\",\"label\":\"Okta\"}}"
|
||||
|
||||
7
.github/workflows/ci.yml
vendored
7
.github/workflows/ci.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
||||
markdownlint .
|
||||
|
||||
static-analysis:
|
||||
runs-on: ubuntu-18.04
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MIX_ENV: dev
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -121,9 +121,8 @@ jobs:
|
||||
mix ecto.migrate
|
||||
- name: Run Tests and Upload Coverage Report
|
||||
run: |
|
||||
# Sometimes coveralls goes down for maintenance, so just run tests if
|
||||
# coveralls fails
|
||||
mix coveralls.github --umbrella || mix test
|
||||
# XXX: This can fail when coveralls is down
|
||||
mix coveralls.github --umbrella
|
||||
|
||||
draft-release:
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
5
apps/fz_common/coveralls.json
Normal file
5
apps/fz_common/coveralls.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"skip_files": [
|
||||
"test"
|
||||
]
|
||||
}
|
||||
@@ -5,13 +5,11 @@ defmodule FzCommon.FzInteger do
|
||||
|
||||
# Postgres max int size is 4 bytes
|
||||
@max_integer 2_147_483_647
|
||||
@byte_multiple 1_024
|
||||
@kib_range @byte_multiple..(@byte_multiple * 1_000 - 1)
|
||||
@mib_range (@byte_multiple * 1_000)..(@byte_multiple ** 2 * 1_000 - 1)
|
||||
@gib_range (@byte_multiple ** 2 * 1_000)..(@byte_multiple ** 3 * 1_000 - 1)
|
||||
@tib_range (@byte_multiple ** 3 * 1_000)..(@byte_multiple ** 4 * 1_000 - 1)
|
||||
@pib_range (@byte_multiple ** 4 * 1_000)..(@byte_multiple ** 5 * 1_000 - 1)
|
||||
@eib_range (@byte_multiple ** 5 * 1_000)..(@byte_multiple ** 6 * 1_000 - 1)
|
||||
|
||||
@byte_size_opts [
|
||||
precision: 2,
|
||||
delimiter: ""
|
||||
]
|
||||
|
||||
def clamp(num, min, _max) when is_integer(num) and num < min, do: min
|
||||
def clamp(num, _min, max) when is_integer(num) and num > max, do: max
|
||||
@@ -24,34 +22,7 @@ defmodule FzCommon.FzInteger do
|
||||
def to_human_bytes(nil), do: to_human_bytes(0)
|
||||
|
||||
def to_human_bytes(bytes) when is_integer(bytes) do
|
||||
case bytes do
|
||||
# KiB
|
||||
b when b in @kib_range ->
|
||||
"#{Float.round(b / @byte_multiple, 2)} KiB"
|
||||
|
||||
# MiB
|
||||
b when b in @mib_range ->
|
||||
"#{Float.round(b / @byte_multiple ** 2, 2)} MiB"
|
||||
|
||||
# GiB
|
||||
b when b in @gib_range ->
|
||||
"#{Float.round(b / @byte_multiple ** 3, 2)} GiB"
|
||||
|
||||
# TiB
|
||||
b when b in @tib_range ->
|
||||
"#{Float.round(b / @byte_multiple ** 4, 2)} TiB"
|
||||
|
||||
# PiB
|
||||
b when b in @pib_range ->
|
||||
"#{Float.round(b / @byte_multiple ** 5, 2)} PiB"
|
||||
|
||||
# EiB
|
||||
b when b in @eib_range ->
|
||||
"#{Float.round(b / @byte_multiple ** 6, 2)} EiB"
|
||||
|
||||
# Fallback to plain B
|
||||
_ ->
|
||||
"#{bytes} B"
|
||||
end
|
||||
FileSize.from_bytes(bytes, scale: :iec)
|
||||
|> FileSize.format(@byte_size_opts)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,7 @@ defmodule FzCommon.MixProject do
|
||||
lockfile: "../../mix.lock",
|
||||
elixir: "~> 1.12",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
@@ -30,6 +31,7 @@ defmodule FzCommon.MixProject do
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
{:file_size, "~> 3.0.1"},
|
||||
{:posthog, "~> 0.1"},
|
||||
{:jason, "~> 1.2"},
|
||||
{:inet_cidr, "~> 1.0.0"}
|
||||
|
||||
@@ -3,6 +3,12 @@ defmodule FzCommon.FzCryptoTest do
|
||||
|
||||
alias FzCommon.FzCrypto
|
||||
|
||||
describe "psk/0" do
|
||||
test "it returns a string of proper length" do
|
||||
assert 44 == String.length(FzCrypto.psk())
|
||||
end
|
||||
end
|
||||
|
||||
describe "rand_string/1" do
|
||||
test "it returns a string of default length" do
|
||||
assert 16 == String.length(FzCrypto.rand_string())
|
||||
|
||||
@@ -3,6 +3,12 @@ defmodule FzCommon.FzIntegerTest do
|
||||
|
||||
alias FzCommon.FzInteger
|
||||
|
||||
describe "max_pg_integer/0" do
|
||||
test "returns max integer for postgres" do
|
||||
assert 2_147_483_647 == FzInteger.max_pg_integer()
|
||||
end
|
||||
end
|
||||
|
||||
describe "clamp/3" do
|
||||
test "clamps to min" do
|
||||
min = 1
|
||||
@@ -31,19 +37,11 @@ defmodule FzCommon.FzIntegerTest do
|
||||
|
||||
describe "to_human_bytes/1" do
|
||||
@expected [
|
||||
{1_023, "1023 B"},
|
||||
{1_023_999, "1024 KiB"},
|
||||
{1_023_999_999, "1024 MiB"},
|
||||
{1_023_999_999_999, "1024 GiB"},
|
||||
{1_023_999_999_999_999, "1024 TiB"},
|
||||
{1_023_999_999_999_999_999, "1024 PiB"},
|
||||
{1_023_999_999_999_999_999_999, "1024 EiB"},
|
||||
{1_000, "1000 B"},
|
||||
{nil, "0.00 B"},
|
||||
{1_023, "1023.00 B"},
|
||||
{1_023_999_999_999_999_999_999, "888.18 EiB"},
|
||||
{1_000, "1000.00 B"},
|
||||
{1_115, "1.09 KiB"},
|
||||
{1_000_115, "1.09 MiB"},
|
||||
{1_123_456_789, "1.05 GiB"},
|
||||
{1_123_456_789_123, "1.02 TiB"},
|
||||
{9_123_456_789_123_456, "8.1 PiB"},
|
||||
{987_654_321_123_456_789_987, "856.65 EiB"}
|
||||
]
|
||||
|
||||
@@ -82,4 +82,14 @@ defmodule FzCommon.FzNetTest do
|
||||
assert FzNet.valid_cidr?("::/0")
|
||||
end
|
||||
end
|
||||
|
||||
describe "standardized_inet/1" do
|
||||
test "formats CIDRs" do
|
||||
assert "::/0" == FzNet.standardized_inet("::0/0")
|
||||
end
|
||||
|
||||
test "formats IP address" do
|
||||
assert "fd00:3::1" == FzNet.standardized_inet("fd00:3:0000::1")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
17
apps/fz_common/test/mock_telemetry_test.exs
Normal file
17
apps/fz_common/test/mock_telemetry_test.exs
Normal file
@@ -0,0 +1,17 @@
|
||||
defmodule FzCommon.MockTelemetryTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias FzCommon.MockTelemetry
|
||||
|
||||
describe "capture/2" do
|
||||
test "returns tuple" do
|
||||
assert is_tuple(MockTelemetry.capture(:noop, :noop))
|
||||
end
|
||||
end
|
||||
|
||||
describe "batch/1" do
|
||||
test "returns tuple" do
|
||||
assert is_tuple(MockTelemetry.batch([:noop]))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -24,7 +24,10 @@ defmodule FzVpn.StatsPushService do
|
||||
|
||||
@impl GenServer
|
||||
def init(state) do
|
||||
:timer.send_interval(@interval, :perform)
|
||||
if enabled?() do
|
||||
:timer.send_interval(@interval, :perform)
|
||||
end
|
||||
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
@@ -58,4 +61,8 @@ defmodule FzVpn.StatsPushService do
|
||||
end)
|
||||
|> Map.new()
|
||||
end
|
||||
|
||||
defp enabled? do
|
||||
Application.fetch_env!(:fz_vpn, :stats_push_service_enabled)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -91,6 +91,7 @@ config :hammer,
|
||||
|
||||
# This will be changed per-env
|
||||
config :fz_vpn,
|
||||
stats_push_service_enabled: true,
|
||||
wireguard_psk_dir: "/tmp",
|
||||
wireguard_public_key: "cB2yQeCxHO/qCH8APoM2D2Anf4Yd7sRLyfS7su71K3M=",
|
||||
wireguard_interface_name: "wg-firezone",
|
||||
|
||||
@@ -255,7 +255,7 @@ end
|
||||
# OIDC Auth
|
||||
auth_oidc_env = System.get_env("AUTH_OIDC")
|
||||
|
||||
if auth_oidc_env do
|
||||
if config_env() != :test && auth_oidc_env do
|
||||
auth_oidc =
|
||||
Jason.decode!(auth_oidc_env)
|
||||
# Convert Map to something openid_connect expects, atomic keyed configs
|
||||
|
||||
@@ -75,3 +75,7 @@ config :fz_http, :openid_connect_providers, %{
|
||||
config :fz_http, :openid_connect, OpenIDConnect.Mock
|
||||
|
||||
config :fz_http, FzHttp.Mailer, adapter: Swoosh.Adapters.Test, from_email: "test@firez.one"
|
||||
|
||||
config :fz_vpn,
|
||||
# XXX: Bump test coverage by replacing this with a stubbed out module
|
||||
stats_push_service_enabled: false
|
||||
|
||||
2
mix.lock
2
mix.lock
@@ -22,6 +22,7 @@
|
||||
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
|
||||
"ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"},
|
||||
"excoveralls": {:hex, :excoveralls, "0.14.5", "5c685449596e962c779adc8f4fb0b4de3a5b291c6121097572a3aa5400c386d3", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9b4a9bf10e9a6e48b94159e13b4b8a1b05400f17ac16cc363ed8734f26e1f4e"},
|
||||
"file_size": {:hex, :file_size, "3.0.1", "ad447a69442a82fc701765a73992d7b1110136fa0d4a9d3190ea685d60034dcd", [:mix], [{:decimal, ">= 1.0.0 and < 3.0.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:number, "~> 1.0", [hex: :number, repo: "hexpm", optional: false]}], "hexpm", "64dd665bc37920480c249785788265f5d42e98830d757c6a477b3246703b8e20"},
|
||||
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
|
||||
"floki": {:hex, :floki, "0.32.1", "dfe3b8db3b793939c264e6f785bca01753d17318d144bd44b407fb3493acaa87", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "d4b91c713e4a784a3f7b1e3cc016eefc619f6b1c3898464222867cafd3c681a3"},
|
||||
"gen_smtp": {:hex, :gen_smtp, "1.2.0", "9cfc75c72a8821588b9b9fe947ae5ab2aed95a052b81237e0928633a13276fd3", [:rebar3], [{:ranch, ">= 1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "5ee0375680bca8f20c4d85f58c2894441443a743355430ff33a783fe03296779"},
|
||||
@@ -47,6 +48,7 @@
|
||||
"mix_test_watch": {:hex, :mix_test_watch, "1.1.0", "330bb91c8ed271fe408c42d07e0773340a7938d8a0d281d57a14243eae9dc8c3", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "52b6b1c476cbb70fd899ca5394506482f12e5f6b0d6acff9df95c7f1e0812ec3"},
|
||||
"mox": {:hex, :mox, "1.0.1", "b651bf0113265cda0ba3a827fcb691f848b683c373b77e7d7439910a8d754d6e", [:mix], [], "hexpm", "35bc0dea5499d18db4ef7fe4360067a59b06c74376eb6ab3bd67e6295b133469"},
|
||||
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
|
||||
"number": {:hex, :number, "1.0.3", "932c8a2d478a181c624138958ca88a78070332191b8061717270d939778c9857", [:mix], [{:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "dd397bbc096b2ca965a6a430126cc9cf7b9ef7421130def69bcf572232ca0f18"},
|
||||
"oauth2": {:hex, :oauth2, "2.0.0", "338382079fe16c514420fa218b0903f8ad2d4bfc0ad0c9f988867dfa246731b0", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "881b8364ac7385f9fddc7949379cbe3f7081da37233a1aa7aab844670a91e7e7"},
|
||||
"openid_connect": {:hex, :openid_connect, "0.2.2", "c05055363330deab39ffd89e609db6b37752f255a93802006d83b45596189c0b", [:mix], [{:httpoison, "~> 1.2", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: false]}, {:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "735769b6d592124b58edd0582554ce638524c0214cd783d8903d33357d74cc13"},
|
||||
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
|
||||
|
||||
Reference in New Issue
Block a user