1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTTP.AdapterHelper.GunTest do
7 use Pleroma.Tests.Helpers
11 alias Pleroma.HTTP.AdapterHelper.Gun
13 setup :verify_on_exit!
15 describe "options/1" do
16 setup do: clear_config([:http, :adapter], a: 1, b: 2)
18 test "https url with default port" do
19 uri = URI.parse("https://example.com")
21 opts = Gun.options([receive_conn: false], uri)
22 assert opts[:certificates_verification]
25 test "https ipv4 with default port" do
26 uri = URI.parse("https://127.0.0.1")
28 opts = Gun.options([receive_conn: false], uri)
29 assert opts[:certificates_verification]
32 test "https ipv6 with default port" do
33 uri = URI.parse("https://[2a03:2880:f10c:83:face:b00c:0:25de]")
35 opts = Gun.options([receive_conn: false], uri)
36 assert opts[:certificates_verification]
39 test "https url with non-standard port" do
40 uri = URI.parse("https://example.com:115")
42 opts = Gun.options([receive_conn: false], uri)
44 assert opts[:certificates_verification]
47 test "merges with default http adapter config" do
48 defaults = Gun.options([receive_conn: false], URI.parse("https://example.com"))
49 assert Keyword.has_key?(defaults, :a)
50 assert Keyword.has_key?(defaults, :b)
53 test "parses string proxy host & port" do
54 clear_config([:http, :proxy_url], "localhost:8123")
56 uri = URI.parse("https://some-domain.com")
57 opts = Gun.options([receive_conn: false], uri)
58 assert opts[:proxy] == {'localhost', 8123}
61 test "parses tuple proxy scheme host and port" do
62 clear_config([:http, :proxy_url], {:socks, 'localhost', 1234})
64 uri = URI.parse("https://some-domain.com")
65 opts = Gun.options([receive_conn: false], uri)
66 assert opts[:proxy] == {:socks, 'localhost', 1234}
69 test "passed opts have more weight than defaults" do
70 clear_config([:http, :proxy_url], {:socks5, 'localhost', 1234})
71 uri = URI.parse("https://some-domain.com")
72 opts = Gun.options([receive_conn: false, proxy: {'example.com', 4321}], uri)
74 assert opts[:proxy] == {'example.com', 4321}