X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fhttp%2Fconnection_test.exs;h=7c94a50b242a6701652254770d8e4ed0ff05ab9c;hb=59cf78e41236a527b21befaadd329e882a62b40a;hp=c1ff0cc21aaff52f74b09aa12d1fc8d3e9bb3f3d;hpb=13918cb545d583decfb728300850b307c59e2031;p=akkoma
diff --git a/test/http/connection_test.exs b/test/http/connection_test.exs
index c1ff0cc21..7c94a50b2 100644
--- a/test/http/connection_test.exs
+++ b/test/http/connection_test.exs
@@ -1,19 +1,16 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.HTTP.ConnectionTest do
use ExUnit.Case
use Pleroma.Tests.Helpers
+
import ExUnit.CaptureLog
+
alias Pleroma.Config
alias Pleroma.HTTP.Connection
- setup_all do
- {:ok, _} = Registry.start_link(keys: :unique, name: Pleroma.Gun.API.Mock)
- :ok
- end
-
describe "parse_host/1" do
test "as atom to charlist" do
assert Connection.parse_host(:localhost) == 'localhost'
@@ -51,31 +48,31 @@ defmodule Pleroma.HTTP.ConnectionTest do
describe "parse_proxy/1 errors" do
test "ip without port" do
capture_log(fn ->
- assert Connection.parse_proxy("127.0.0.1") == {:error, :error_parsing_proxy}
+ assert Connection.parse_proxy("127.0.0.1") == {:error, :invalid_proxy}
end) =~ "parsing proxy fail \"127.0.0.1\""
end
test "host without port" do
capture_log(fn ->
- assert Connection.parse_proxy("localhost") == {:error, :error_parsing_proxy}
+ assert Connection.parse_proxy("localhost") == {:error, :invalid_proxy}
end) =~ "parsing proxy fail \"localhost\""
end
test "host with bad port" do
capture_log(fn ->
- assert Connection.parse_proxy("localhost:port") == {:error, :error_parsing_port_in_proxy}
+ assert Connection.parse_proxy("localhost:port") == {:error, :invalid_proxy_port}
end) =~ "parsing port in proxy fail \"localhost:port\""
end
test "ip with bad port" do
capture_log(fn ->
- assert Connection.parse_proxy("127.0.0.1:15.9") == {:error, :error_parsing_port_in_proxy}
+ assert Connection.parse_proxy("127.0.0.1:15.9") == {:error, :invalid_proxy_port}
end) =~ "parsing port in proxy fail \"127.0.0.1:15.9\""
end
test "as tuple without port" do
capture_log(fn ->
- assert Connection.parse_proxy({:socks5, :localhost}) == {:error, :error_parsing_proxy}
+ assert Connection.parse_proxy({:socks5, :localhost}) == {:error, :invalid_proxy}
end) =~ "parsing proxy fail {:socks5, :localhost}"
end
@@ -85,7 +82,7 @@ defmodule Pleroma.HTTP.ConnectionTest do
end
describe "options/3" do
- clear_config([:http, :proxy_url])
+ setup do: clear_config([:http, :proxy_url])
test "without proxy_url in config" do
Config.delete([:http, :proxy_url])
@@ -115,28 +112,24 @@ defmodule Pleroma.HTTP.ConnectionTest do
assert opts[:proxy] == {'example.com', 4321}
end
+ end
- test "default ssl adapter opts with connection" do
- adapter = Application.get_env(:tesla, :adapter)
- Application.put_env(:tesla, :adapter, Tesla.Adapter.Gun)
- on_exit(fn -> Application.put_env(:tesla, :adapter, adapter) end)
-
- uri = URI.parse("https://some-domain.com")
-
- pid = Process.whereis(:federation)
- :ok = Pleroma.Pool.Connections.open_conn(uri, :gun_connections, genserver_pid: pid)
+ describe "format_host/1" do
+ test "with domain" do
+ assert Connection.format_host("example.com") == 'example.com'
+ end
- opts = Connection.options(uri)
+ test "with idna domain" do
+ assert Connection.format_host("ã§ãexample.com") == 'xn--example-183fne.com'
+ end
- assert opts[:certificates_verification]
- tls_opts = opts[:tls_opts]
- assert tls_opts[:verify] == :verify_peer
- assert tls_opts[:depth] == 20
- assert tls_opts[:reuse_sessions] == false
+ test "with ipv4" do
+ assert Connection.format_host("127.0.0.1") == '127.0.0.1'
+ end
- assert opts[:original] == "some-domain.com:443"
- assert opts[:close_conn] == false
- assert is_pid(opts[:conn])
+ test "with ipv6" do
+ assert Connection.format_host("2a03:2880:f10c:83:face:b00c:0:25de") ==
+ '2a03:2880:f10c:83:face:b00c:0:25de'
end
end
end