fix: resolve typing violation and ETS cache race in tests

- Use pattern match assertion in towerops_native_test to satisfy type checker
- Clear ETS whitelist cache in brute_force_test setup to prevent cross-test leakage
This commit is contained in:
Graham McIntire 2026-02-14 12:32:43 -06:00
parent 146f5745cf
commit c59a852e22
No known key found for this signature in database
2 changed files with 15 additions and 8 deletions

View file

@ -4,6 +4,19 @@ defmodule Towerops.Security.BruteForceTest do
alias Towerops.Security.BruteForce
alias Towerops.Security.IpBlock
setup do
# Clear the global ETS whitelist cache so each test gets a fresh load
# from its own Ecto sandbox. Without this, stale entries from other
# async test processes can leak through the shared cache.
try do
:ets.delete(:brute_force_whitelist_cache)
rescue
ArgumentError -> :ok
end
:ok
end
describe "whitelist management" do
test "check_whitelist/1 returns false for non-whitelisted IP" do
refute BruteForce.check_whitelist("192.168.1.100")

View file

@ -104,14 +104,8 @@ defmodule ToweropsNativeTest do
test "handles MODULE::name format" do
# net-snmp natively supports MODULE::name format
oid1 = ToweropsNative.resolve_oid("SNMPv2-MIB::sysDescr")
oid2 = ToweropsNative.resolve_oid("sysDescr")
# Both should resolve to the same OID (dialyzer can't infer these always succeed)
assert is_binary(oid1)
assert is_binary(oid2)
assert oid1 == oid2
assert oid1 == "1.3.6.1.2.1.1.1"
assert "1.3.6.1.2.1.1.1" = ToweropsNative.resolve_oid("SNMPv2-MIB::sysDescr")
assert "1.3.6.1.2.1.1.1" = ToweropsNative.resolve_oid("sysDescr")
end
test "returns error tuple for invalid MIB names" do