Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.8KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.HTTP.AdapterTest do
  5. use ExUnit.Case, async: true
  6. alias Pleroma.HTTP.Adapter
  7. describe "domain_or_ip/1" do
  8. test "with domain" do
  9. assert Adapter.domain_or_ip("example.com") == {:domain, 'example.com'}
  10. end
  11. test "with idna domain" do
  12. assert Adapter.domain_or_ip("ですexample.com") == {:domain, 'xn--example-183fne.com'}
  13. end
  14. test "with ipv4" do
  15. assert Adapter.domain_or_ip("127.0.0.1") == {:ip, {127, 0, 0, 1}}
  16. end
  17. test "with ipv6" do
  18. assert Adapter.domain_or_ip("2a03:2880:f10c:83:face:b00c:0:25de") ==
  19. {:ip, {10_755, 10_368, 61_708, 131, 64_206, 45_068, 0, 9_694}}
  20. end
  21. end
  22. describe "domain_or_fallback/1" do
  23. test "with domain" do
  24. assert Adapter.domain_or_fallback("example.com") == 'example.com'
  25. end
  26. test "with idna domain" do
  27. assert Adapter.domain_or_fallback("ですexample.com") == 'xn--example-183fne.com'
  28. end
  29. test "with ipv4" do
  30. assert Adapter.domain_or_fallback("127.0.0.1") == '127.0.0.1'
  31. end
  32. test "with ipv6" do
  33. assert Adapter.domain_or_fallback("2a03:2880:f10c:83:face:b00c:0:25de") ==
  34. '2a03:2880:f10c:83:face:b00c:0:25de'
  35. end
  36. end
  37. describe "format_proxy/1" do
  38. test "with nil" do
  39. assert Adapter.format_proxy(nil) == nil
  40. end
  41. test "with string" do
  42. assert Adapter.format_proxy("127.0.0.1:8123") == {{127, 0, 0, 1}, 8123}
  43. end
  44. test "localhost with port" do
  45. assert Adapter.format_proxy("localhost:8123") == {'localhost', 8123}
  46. end
  47. test "tuple" do
  48. assert Adapter.format_proxy({:socks4, :localhost, 9050}) == {:socks4, 'localhost', 9050}
  49. end
  50. end
  51. end