honkoma/test/pleroma/http/adapter_helper/gun_test.exs

78 lines
2.3 KiB
Elixir
Raw Normal View History

2020-02-11 07:12:57 +00:00
# Pleroma: A lightweight social networking server
2022-02-26 06:11:42 +00:00
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-02-11 07:12:57 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-03-03 15:53:44 +00:00
defmodule Pleroma.HTTP.AdapterHelper.GunTest do
2020-12-21 14:05:56 +00:00
use ExUnit.Case
2020-02-11 07:12:57 +00:00
use Pleroma.Tests.Helpers
2020-03-06 17:23:58 +00:00
import Mox
2020-03-03 15:53:44 +00:00
alias Pleroma.HTTP.AdapterHelper.Gun
2020-02-11 07:12:57 +00:00
2020-03-06 17:23:58 +00:00
setup :verify_on_exit!
2020-02-11 07:12:57 +00:00
describe "options/1" do
2020-03-20 17:58:47 +00:00
setup do: clear_config([:http, :adapter], a: 1, b: 2)
2020-02-11 07:12:57 +00:00
test "https url with default port" do
uri = URI.parse("https://example.com")
2020-03-06 17:23:58 +00:00
opts = Gun.options([receive_conn: false], uri)
2020-02-11 07:12:57 +00:00
assert opts[:certificates_verification]
end
test "https ipv4 with default port" do
uri = URI.parse("https://127.0.0.1")
2020-03-06 17:23:58 +00:00
opts = Gun.options([receive_conn: false], uri)
assert opts[:certificates_verification]
2020-02-11 07:12:57 +00:00
end
test "https ipv6 with default port" do
uri = URI.parse("https://[2a03:2880:f10c:83:face:b00c:0:25de]")
2020-03-06 17:23:58 +00:00
opts = Gun.options([receive_conn: false], uri)
assert opts[:certificates_verification]
2020-02-11 07:12:57 +00:00
end
test "https url with non standart port" do
uri = URI.parse("https://example.com:115")
2020-03-06 17:23:58 +00:00
opts = Gun.options([receive_conn: false], uri)
2020-02-11 07:12:57 +00:00
assert opts[:certificates_verification]
end
test "merges with defaul http adapter config" do
2020-03-06 17:23:58 +00:00
defaults = Gun.options([receive_conn: false], URI.parse("https://example.com"))
2020-02-11 07:12:57 +00:00
assert Keyword.has_key?(defaults, :a)
assert Keyword.has_key?(defaults, :b)
end
test "parses string proxy host & port" do
clear_config([:http, :proxy_url], "localhost:8123")
2020-02-11 07:12:57 +00:00
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false], uri)
assert opts[:proxy] == {'localhost', 8123}
end
test "parses tuple proxy scheme host and port" do
clear_config([:http, :proxy_url], {:socks, 'localhost', 1234})
2020-02-11 07:12:57 +00:00
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false], uri)
assert opts[:proxy] == {:socks, 'localhost', 1234}
end
test "passed opts have more weight than defaults" do
clear_config([:http, :proxy_url], {:socks5, 'localhost', 1234})
2020-02-11 07:12:57 +00:00
uri = URI.parse("https://some-domain.com")
opts = Gun.options([receive_conn: false, proxy: {'example.com', 4321}], uri)
assert opts[:proxy] == {'example.com', 4321}
end
end
end