aboutsummaryrefslogtreecommitdiff
path: root/test/http/hackney_test.exs
blob: 492eb511e32103c25f4375a4dce619ad8bebe956 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Pleroma: A lightweight social networking server
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.HTTP.HackneyTest do
  use ExUnit.Case, async: true
  use Pleroma.Tests.Helpers

  alias Pleroma.HTTP.Hackney

  setup_all do
    uri = URI.parse("http://domain.com")
    {:ok, uri: uri}
  end

  describe "options/2" do
    setup do: clear_config([:http, :adapter], a: 1, b: 2)

    test "add proxy and opts from config", %{uri: uri} do
      opts = Hackney.options([proxy: "localhost:8123"], uri)

      assert opts[:a] == 1
      assert opts[:b] == 2
      assert opts[:proxy] == "localhost:8123"
    end

    test "respect connection opts and no proxy", %{uri: uri} do
      opts = Hackney.options([a: 2, b: 1], uri)

      assert opts[:a] == 2
      assert opts[:b] == 1
      refute Keyword.has_key?(opts, :proxy)
    end

    test "add opts for https" do
      uri = URI.parse("https://domain.com")

      opts = Hackney.options(uri)

      assert opts[:ssl_options] == [
               partial_chain: &:hackney_connect.partial_chain/1,
               versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"],
               server_name_indication: 'domain.com'
             ]
    end
  end
end