diff options
author | Ariadne Conill <ariadne@dereferenced.org> | 2019-08-25 21:00:58 +0000 |
---|---|---|
committer | Ariadne Conill <ariadne@dereferenced.org> | 2019-08-25 21:00:58 +0000 |
commit | 361940e119321900deca49e7b1d547b779813490 (patch) | |
tree | 10a82fafa65d9d4d6dcf4336ebbfeccdd8dae93a /test/http | |
parent | 6dc24422dc403663f6385272f071e2223c24b2ce (diff) | |
parent | c19d4eeaeebec3d938324fe24b67182fc5d2be4e (diff) | |
download | pleroma-integration/alex.s/gun.tar.gz |
Merge branch 'gun' of git.pleroma.social:alex.s/pleroma into integration/alex.s/gunintegration/alex.s/gun
Diffstat (limited to 'test/http')
-rw-r--r-- | test/http/connection_test.exs | 65 | ||||
-rw-r--r-- | test/http/request_builder_test.exs | 4 |
2 files changed, 67 insertions, 2 deletions
diff --git a/test/http/connection_test.exs b/test/http/connection_test.exs new file mode 100644 index 000000000..99eab4026 --- /dev/null +++ b/test/http/connection_test.exs @@ -0,0 +1,65 @@ +defmodule Pleroma.HTTP.ConnectionTest do + use ExUnit.Case, async: true + import ExUnit.CaptureLog + alias Pleroma.HTTP.Connection + + describe "parse_host/1" do + test "as atom" do + assert Connection.parse_host(:localhost) == 'localhost' + end + + test "as string" do + assert Connection.parse_host("localhost.com") == 'localhost.com' + end + + test "as string ip" do + assert Connection.parse_host("127.0.0.1") == {127, 0, 0, 1} + end + end + + describe "parse_proxy/1" do + test "ip with port" do + assert Connection.parse_proxy("127.0.0.1:8123") == {:ok, {127, 0, 0, 1}, 8123} + end + + test "host with port" do + assert Connection.parse_proxy("localhost:8123") == {:ok, 'localhost', 8123} + end + + test "as tuple" do + assert Connection.parse_proxy({:socks5, :localhost, 9050}) == {:ok, 'localhost', 9050} + end + + test "as tuple with string host" do + assert Connection.parse_proxy({:socks5, "localhost", 9050}) == {:ok, 'localhost', 9050} + end + + test "ip without port" do + capture_log(fn -> + assert Connection.parse_proxy("127.0.0.1") == {:error, :error_parsing_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} + 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} + end) =~ "parsing port in proxy fail \"localhost:port\"" + end + + test "as tuple without port" do + capture_log(fn -> + assert Connection.parse_proxy({:socks5, :localhost}) == {:error, :error_parsing_proxy} + end) =~ "parsing proxy fail {:socks5, :localhost}" + end + + test "with nil" do + assert Connection.parse_proxy(nil) == nil + end + end +end diff --git a/test/http/request_builder_test.exs b/test/http/request_builder_test.exs index 170ca916f..77a1e870a 100644 --- a/test/http/request_builder_test.exs +++ b/test/http/request_builder_test.exs @@ -3,7 +3,7 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.HTTP.RequestBuilderTest do - use ExUnit.Case, async: true + use ExUnit.Case use Pleroma.Tests.Helpers alias Pleroma.HTTP.RequestBuilder @@ -18,7 +18,7 @@ defmodule Pleroma.HTTP.RequestBuilderTest do Pleroma.Config.put([:http, :send_user_agent], true) assert RequestBuilder.headers(%{}, []) == %{ - headers: [{"User-Agent", Pleroma.Application.user_agent()}] + headers: [{"user-agent", Pleroma.Application.user_agent()}] } end end |