Apply Testing LiveView course patterns (live/2, has_element?, render_click, form/3). Add tests for MobileQRLive, WeathermapLive, StatusPageLive, controllers, plugs, and pure function modules. Expand proto decode coverage to 85.24%.
45 lines
1.4 KiB
Elixir
45 lines
1.4 KiB
Elixir
defmodule Towerops.URLValidatorTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Towerops.URLValidator
|
|
|
|
describe "validate/1" do
|
|
test "accepts valid https URL" do
|
|
assert :ok = URLValidator.validate("https://example.com")
|
|
end
|
|
|
|
test "accepts valid http URL" do
|
|
assert :ok = URLValidator.validate("http://example.com")
|
|
end
|
|
|
|
test "rejects non-string input" do
|
|
assert {:error, _} = URLValidator.validate(nil)
|
|
assert {:error, _} = URLValidator.validate(123)
|
|
assert {:error, _} = URLValidator.validate(:atom)
|
|
end
|
|
|
|
test "rejects URL without scheme" do
|
|
assert {:error, _} = URLValidator.validate("example.com")
|
|
end
|
|
|
|
test "rejects URL without host" do
|
|
assert {:error, _} = URLValidator.validate("http://")
|
|
end
|
|
|
|
test "rejects non-http scheme" do
|
|
assert {:error, _} = URLValidator.validate("ftp://example.com")
|
|
assert {:error, _} = URLValidator.validate("file:///etc/passwd")
|
|
end
|
|
|
|
test "rejects localhost" do
|
|
assert {:error, _} = URLValidator.validate("http://localhost")
|
|
assert {:error, _} = URLValidator.validate("http://LOCALHOST")
|
|
assert {:error, _} = URLValidator.validate("https://localhost:8080")
|
|
end
|
|
|
|
test "rejects .local domains" do
|
|
assert {:error, _} = URLValidator.validate("http://router.local")
|
|
assert {:error, _} = URLValidator.validate("https://device.local:8443")
|
|
end
|
|
end
|
|
end
|