aprs.me/test/test_helper.exs
Graham McIntire 0f2195ef9d
Some checks failed
Build and Push / Build and Push Docker Image (push) Failing after 2s
security: CSP nonces, RemoteIp CIDR gating, rate limiting, NetworkPolicies, deadlock fixes
- Content-Security-Policy: nonce-based per-request plug replacing unsafe-inline scripts
- RemoteIp: CIDR-based trust gating via InetCidr, skips forwarded headers from untrusted peers
- Rate limiting: auth pipeline (20/min), LiveView event handlers, existing mobile channel limits
- NetworkPolicy: 4 k8s policies (web ingress, cluster, metrics, egress) for least-privilege networking
- PartitionManager: deadlock retry with exponential backoff in drop_partition
- Tests: reduced parallelism (max_cases 4), packets_test async:false to prevent trigger contention
- k8s: APRS_PASSWORD -> APRS_PASSCODE secretRef, vendor/aprs submodule hardened
2026-07-26 14:04:56 -05:00

34 lines
1.2 KiB
Elixir

# Reduce parallelism when coverage is enabled to prevent file descriptor exhaustion
# Reduced from System.schedulers_online() * 4 to avoid trigger-based
# packet counter deadlocks under concurrent insert/delete workloads.
# The packet counter trigger serializes on a single row; high parallelism
# creates contention with no throughput benefit for insert-heavy tests.
max_cases =
if System.get_env("MIX_TEST_COVERAGE") do
2
else
4
end
ExUnit.start(
max_cases: max_cases,
timeout: 30_000,
capture_log: true,
exclude: [:integration]
)
Ecto.Adapters.SQL.Sandbox.mode(Aprsme.Repo, :manual)
# Configure Mox
Mox.defmock(Aprsme.PacketsMock, for: Aprsme.PacketsBehaviour)
Mox.defmock(PacketsMock, for: Aprsme.PacketsBehaviour)
# Set up default stubs for commonly used functions
Mox.stub(Aprsme.PacketsMock, :get_recent_packets, fn _opts -> [] end)
Mox.stub(Aprsme.PacketsMock, :get_nearby_stations, fn _lat, _lon, _exclude, _opts -> [] end)
# Ensure no external APRS connections during tests
Application.put_env(:aprsme, :aprs_is_server, "mock.aprs.test")
Application.put_env(:aprsme, :packets_module, Aprsme.PacketsMock)
# AprsIsMock is automatically loaded from test/support via elixirc_paths