Merge branch 'develop' into gun
[akkoma] / test / http / adapter_test.exs
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.AdapterTest do
6 use ExUnit.Case, async: true
7
8 alias Pleroma.HTTP.Adapter
9
10 describe "domain_or_ip/1" do
11 test "with domain" do
12 assert Adapter.domain_or_ip("example.com") == {:domain, 'example.com'}
13 end
14
15 test "with idna domain" do
16 assert Adapter.domain_or_ip("ですexample.com") == {:domain, 'xn--example-183fne.com'}
17 end
18
19 test "with ipv4" do
20 assert Adapter.domain_or_ip("127.0.0.1") == {:ip, {127, 0, 0, 1}}
21 end
22
23 test "with ipv6" do
24 assert Adapter.domain_or_ip("2a03:2880:f10c:83:face:b00c:0:25de") ==
25 {:ip, {10_755, 10_368, 61_708, 131, 64_206, 45_068, 0, 9_694}}
26 end
27 end
28
29 describe "domain_or_fallback/1" do
30 test "with domain" do
31 assert Adapter.domain_or_fallback("example.com") == 'example.com'
32 end
33
34 test "with idna domain" do
35 assert Adapter.domain_or_fallback("ですexample.com") == 'xn--example-183fne.com'
36 end
37
38 test "with ipv4" do
39 assert Adapter.domain_or_fallback("127.0.0.1") == '127.0.0.1'
40 end
41
42 test "with ipv6" do
43 assert Adapter.domain_or_fallback("2a03:2880:f10c:83:face:b00c:0:25de") ==
44 '2a03:2880:f10c:83:face:b00c:0:25de'
45 end
46 end
47
48 describe "format_proxy/1" do
49 test "with nil" do
50 assert Adapter.format_proxy(nil) == nil
51 end
52
53 test "with string" do
54 assert Adapter.format_proxy("127.0.0.1:8123") == {{127, 0, 0, 1}, 8123}
55 end
56
57 test "localhost with port" do
58 assert Adapter.format_proxy("localhost:8123") == {'localhost', 8123}
59 end
60
61 test "tuple" do
62 assert Adapter.format_proxy({:socks4, :localhost, 9050}) == {:socks4, 'localhost', 9050}
63 end
64 end
65 end