1.1 KiB · text History 4b6fe3b
defmodule OhMyExOhIrcd.IRC.VhostTest do
  use ExUnit.Case, async: true

  alias OhMyExOhIrcd.IRC.Vhost

  describe "valid_host?/1" do
    test "accepts hostname-like values" do
      assert Vhost.valid_host?("irc.skyjeep.club")
      assert Vhost.valid_host?("staff/admin")
      assert Vhost.valid_host?("my-host_1.example.com")
    end

    test "rejects anything that would corrupt the nick!user@host prefix" do
      refute Vhost.valid_host?("has space")
      refute Vhost.valid_host?("at@sign")
      refute Vhost.valid_host?("bang!")
      refute Vhost.valid_host?("colon:1")
      refute Vhost.valid_host?("")
    end

    test "rejects over-long hosts" do
      refute Vhost.valid_host?(String.duplicate("a", 65))
      assert Vhost.valid_host?(String.duplicate("a", 64))
    end

    test "rejects non-binaries" do
      refute Vhost.valid_host?(nil)
      refute Vhost.valid_host?(123)
    end
  end

  describe "set_live/3" do
    test "returns {:error, :no_such_nick} when the nick is offline" do
      assert {:error, :no_such_nick} = Vhost.set_live("definitely-not-connected", "x.host", "oper")
    end
  end
end