Adds ~800 new tests (incl. 27 StreamData properties) across 22 modules that previously had little or no coverage. Highlights: - Pure utility modules (LogSanitizer, PacketFieldWhitelist, PacketSanitizer, DeviceParser, CoordinateUtils, BoundsUtils, ParamUtils, Convert, WeatherUnits) get thorough unit + property coverage including UTF-8 truncation boundaries, antimeridian longitude wrap, Haversine symmetry, and unit-conversion inverses. - JSON view modules (CallsignJSON, ErrorJSON, ChangesetJSON) verified for envelope shape and error templating. - Plugs (HealthCheck, RateLimiter, ApiCSRF) exercised for happy-path and halt paths. - GenServer modules (RegexCache, CleanupScheduler, DeploymentNotifier) tested without touching the supervised singleton where possible. - Drops the orphaned map_live/map_helpers_test.exs whose module name collided with the new live/shared/coordinate_utils_test.exs.
156 lines
5.4 KiB
Elixir
156 lines
5.4 KiB
Elixir
defmodule Aprsme.PacketSanitizerTest do
|
||
use ExUnit.Case, async: true
|
||
use ExUnitProperties
|
||
|
||
alias Aprsme.PacketSanitizer
|
||
|
||
describe "sanitize_packet/1" do
|
||
test "leaves short strings alone" do
|
||
packet = %{sender: "K5ABC", base_callsign: "K5ABC"}
|
||
assert PacketSanitizer.sanitize_packet(packet) == packet
|
||
end
|
||
|
||
test "truncates oversized sender to 20 bytes" do
|
||
long = String.duplicate("A", 50)
|
||
result = PacketSanitizer.sanitize_packet(%{sender: long})
|
||
assert byte_size(result.sender) == 20
|
||
end
|
||
|
||
test "truncates oversized base_callsign to 20 bytes" do
|
||
long = String.duplicate("B", 100)
|
||
result = PacketSanitizer.sanitize_packet(%{base_callsign: long})
|
||
assert byte_size(result.base_callsign) == 20
|
||
end
|
||
|
||
test "truncates raw_packet to 5000 bytes" do
|
||
long = String.duplicate("x", 6000)
|
||
result = PacketSanitizer.sanitize_packet(%{raw_packet: long})
|
||
assert byte_size(result.raw_packet) == 5000
|
||
end
|
||
|
||
test "leaves non-binary values unchanged" do
|
||
packet = %{lat: 30.5, lon: -95.0, has_position: true, altitude: 100}
|
||
assert PacketSanitizer.sanitize_packet(packet) == packet
|
||
end
|
||
|
||
test "leaves keys without length limits alone" do
|
||
long = String.duplicate("y", 10_000)
|
||
result = PacketSanitizer.sanitize_packet(%{some_field_nobody_limits: long})
|
||
assert result.some_field_nobody_limits == long
|
||
end
|
||
|
||
test "strips null bytes from values inside the data map" do
|
||
packet = %{data: %{"information_field" => "hello |