From c59a852e22ef2412f4d0c17744e2be803322ab71 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 14 Feb 2026 12:32:43 -0600 Subject: [PATCH] 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 --- test/towerops/security/brute_force_test.exs | 13 +++++++++++++ test/towerops_native_test.exs | 10 ++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test/towerops/security/brute_force_test.exs b/test/towerops/security/brute_force_test.exs index 7fc1fa22..3f28206b 100644 --- a/test/towerops/security/brute_force_test.exs +++ b/test/towerops/security/brute_force_test.exs @@ -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") diff --git a/test/towerops_native_test.exs b/test/towerops_native_test.exs index 12e7f767..8e3833c7 100644 --- a/test/towerops_native_test.exs +++ b/test/towerops_native_test.exs @@ -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