Add focused tests across many modules to push overall coverage from 75.45% to ~77%. New test files: - test/towerops/snmp/topology_test.exs - test/towerops/vault_test.exs - test/towerops/workers/check_worker_test.exs - test/towerops_web/graphql/resolvers/happy_path_test.exs - test/towerops_web/graphql/schema_test.exs - test/towerops_web/live/reports_live_test.exs Expanded existing tests for: Airos vendor, ProfileWatcher, StormDetector, LLDP, GpsSync, MikrotikBackupWorker, AdminController, MibController, MobileController, GeoipController, OnboardingLive, UserResetPasswordLive, SessionManager, Telemetry, CoverageLive.Show. Also fix a pre-existing dead test in ApplicationSettingTest where the schema default for value_type made the 'invalid without value_type' test unreachable.
44 lines
1.3 KiB
Elixir
44 lines
1.3 KiB
Elixir
defmodule Towerops.VaultTest do
|
|
use ExUnit.Case, async: false
|
|
|
|
alias Towerops.Vault
|
|
|
|
describe "init/1" do
|
|
test "preserves config when CLOAK_KEY env is unset" do
|
|
original = System.get_env("CLOAK_KEY")
|
|
System.delete_env("CLOAK_KEY")
|
|
|
|
try do
|
|
assert {:ok, config} = Vault.init(ciphers: [])
|
|
assert config[:ciphers] == []
|
|
after
|
|
if original, do: System.put_env("CLOAK_KEY", original)
|
|
end
|
|
end
|
|
|
|
test "overrides ciphers when CLOAK_KEY env is set" do
|
|
original = System.get_env("CLOAK_KEY")
|
|
key = 32 |> :crypto.strong_rand_bytes() |> Base.encode64()
|
|
System.put_env("CLOAK_KEY", key)
|
|
|
|
try do
|
|
assert {:ok, config} = Vault.init([])
|
|
assert {Cloak.Ciphers.AES.GCM, opts} = config[:ciphers][:default]
|
|
assert opts[:tag] == "AES.GCM.V1"
|
|
assert is_binary(opts[:key])
|
|
assert byte_size(opts[:key]) == 32
|
|
after
|
|
if original, do: System.put_env("CLOAK_KEY", original), else: System.delete_env("CLOAK_KEY")
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "encryption round-trip" do
|
|
test "encrypts and decrypts a binary using the configured key" do
|
|
assert {:ok, ciphertext} = Vault.encrypt("hello")
|
|
assert is_binary(ciphertext)
|
|
assert ciphertext != "hello"
|
|
assert {:ok, "hello"} = Vault.decrypt(ciphertext)
|
|
end
|
|
end
|
|
end
|