logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

hackney_test.exs (1466B)


      1 # Pleroma: A lightweight social networking server
      2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
      3 # SPDX-License-Identifier: AGPL-3.0-only
      4 
      5 defmodule Pleroma.HTTP.Adapter.HackneyTest do
      6   use ExUnit.Case
      7   use Pleroma.Tests.Helpers
      8 
      9   alias Pleroma.Config
     10   alias Pleroma.HTTP.Adapter.Hackney
     11 
     12   setup_all do
     13     uri = URI.parse("http://domain.com")
     14     {:ok, uri: uri}
     15   end
     16 
     17   describe "options/2" do
     18     clear_config([:http, :adapter]) do
     19       Config.put([:http, :adapter], a: 1, b: 2)
     20     end
     21 
     22     test "add proxy and opts from config", %{uri: uri} do
     23       proxy = Config.get([:http, :proxy_url])
     24       Config.put([:http, :proxy_url], "localhost:8123")
     25       on_exit(fn -> Config.put([:http, :proxy_url], proxy) end)
     26 
     27       opts = Hackney.options(uri)
     28 
     29       assert opts[:a] == 1
     30       assert opts[:b] == 2
     31       assert opts[:proxy] == "localhost:8123"
     32     end
     33 
     34     test "respect connection opts and no proxy", %{uri: uri} do
     35       opts = Hackney.options([a: 2, b: 1], uri)
     36 
     37       assert opts[:a] == 2
     38       assert opts[:b] == 1
     39       refute Keyword.has_key?(opts, :proxy)
     40     end
     41 
     42     test "add opts for https" do
     43       uri = URI.parse("https://domain.com")
     44 
     45       opts = Hackney.options(uri)
     46 
     47       assert opts[:ssl_options] == [
     48                partial_chain: &:hackney_connect.partial_chain/1,
     49                versions: [:tlsv1, :"tlsv1.1", :"tlsv1.2"],
     50                server_name_indication: 'domain.com'
     51              ]
     52     end
     53   end
     54 end