Remove tests for old pool
[akkoma] / test / http / adapter_helper / gun_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.HTTP.AdapterHelper.GunTest do
6 use ExUnit.Case, async: true
7 use Pleroma.Tests.Helpers
8
9 import Mox
10
11 alias Pleroma.Config
12 alias Pleroma.HTTP.AdapterHelper.Gun
13
14 setup :verify_on_exit!
15
16 describe "options/1" do
17 setup do: clear_config([:http, :adapter], a: 1, b: 2)
18
19 test "https url with default port" do
20 uri = URI.parse("https://example.com")
21
22 opts = Gun.options([receive_conn: false], uri)
23 assert opts[:certificates_verification]
24 assert opts[:tls_opts][:log_level] == :warning
25 end
26
27 test "https ipv4 with default port" do
28 uri = URI.parse("https://127.0.0.1")
29
30 opts = Gun.options([receive_conn: false], uri)
31 assert opts[:certificates_verification]
32 assert opts[:tls_opts][:log_level] == :warning
33 end
34
35 test "https ipv6 with default port" do
36 uri = URI.parse("https://[2a03:2880:f10c:83:face:b00c:0:25de]")
37
38 opts = Gun.options([receive_conn: false], uri)
39 assert opts[:certificates_verification]
40 assert opts[:tls_opts][:log_level] == :warning
41 end
42
43 test "https url with non standart port" do
44 uri = URI.parse("https://example.com:115")
45
46 opts = Gun.options([receive_conn: false], uri)
47
48 assert opts[:certificates_verification]
49 end
50
51 test "merges with defaul http adapter config" do
52 defaults = Gun.options([receive_conn: false], URI.parse("https://example.com"))
53 assert Keyword.has_key?(defaults, :a)
54 assert Keyword.has_key?(defaults, :b)
55 end
56
57 test "parses string proxy host & port" do
58 proxy = Config.get([:http, :proxy_url])
59 Config.put([:http, :proxy_url], "localhost:8123")
60 on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
61
62 uri = URI.parse("https://some-domain.com")
63 opts = Gun.options([receive_conn: false], uri)
64 assert opts[:proxy] == {'localhost', 8123}
65 end
66
67 test "parses tuple proxy scheme host and port" do
68 proxy = Config.get([:http, :proxy_url])
69 Config.put([:http, :proxy_url], {:socks, 'localhost', 1234})
70 on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
71
72 uri = URI.parse("https://some-domain.com")
73 opts = Gun.options([receive_conn: false], uri)
74 assert opts[:proxy] == {:socks, 'localhost', 1234}
75 end
76
77 test "passed opts have more weight than defaults" do
78 proxy = Config.get([:http, :proxy_url])
79 Config.put([:http, :proxy_url], {:socks5, 'localhost', 1234})
80 on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
81 uri = URI.parse("https://some-domain.com")
82 opts = Gun.options([receive_conn: false, proxy: {'example.com', 4321}], uri)
83
84 assert opts[:proxy] == {'example.com', 4321}
85 end
86 end
87 end