logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

gun_test.exs (2361B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.HTTP.AdapterHelper.GunTest do
  5. use ExUnit.Case
  6. use Pleroma.Tests.Helpers
  7. import Mox
  8. alias Pleroma.HTTP.AdapterHelper.Gun
  9. setup :verify_on_exit!
  10. describe "options/1" do
  11. setup do: clear_config([:http, :adapter], a: 1, b: 2)
  12. test "https url with default port" do
  13. uri = URI.parse("https://example.com")
  14. opts = Gun.options([receive_conn: false], uri)
  15. assert opts[:certificates_verification]
  16. end
  17. test "https ipv4 with default port" do
  18. uri = URI.parse("https://127.0.0.1")
  19. opts = Gun.options([receive_conn: false], uri)
  20. assert opts[:certificates_verification]
  21. end
  22. test "https ipv6 with default port" do
  23. uri = URI.parse("https://[2a03:2880:f10c:83:face:b00c:0:25de]")
  24. opts = Gun.options([receive_conn: false], uri)
  25. assert opts[:certificates_verification]
  26. end
  27. test "https url with non-standard port" do
  28. uri = URI.parse("https://example.com:115")
  29. opts = Gun.options([receive_conn: false], uri)
  30. assert opts[:certificates_verification]
  31. end
  32. test "merges with default http adapter config" do
  33. defaults = Gun.options([receive_conn: false], URI.parse("https://example.com"))
  34. assert Keyword.has_key?(defaults, :a)
  35. assert Keyword.has_key?(defaults, :b)
  36. end
  37. test "parses string proxy host & port" do
  38. clear_config([:http, :proxy_url], "localhost:8123")
  39. uri = URI.parse("https://some-domain.com")
  40. opts = Gun.options([receive_conn: false], uri)
  41. assert opts[:proxy] == {'localhost', 8123}
  42. end
  43. test "parses tuple proxy scheme host and port" do
  44. clear_config([:http, :proxy_url], {:socks, 'localhost', 1234})
  45. uri = URI.parse("https://some-domain.com")
  46. opts = Gun.options([receive_conn: false], uri)
  47. assert opts[:proxy] == {:socks, 'localhost', 1234}
  48. end
  49. test "passed opts have more weight than defaults" do
  50. clear_config([:http, :proxy_url], {:socks5, 'localhost', 1234})
  51. uri = URI.parse("https://some-domain.com")
  52. opts = Gun.options([receive_conn: false, proxy: {'example.com', 4321}], uri)
  53. assert opts[:proxy] == {'example.com', 4321}
  54. end
  55. end
  56. end