1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.HTTP.AdapterTest do
6 use ExUnit.Case, async: true
8 alias Pleroma.HTTP.Adapter
10 describe "domain_or_ip/1" do
12 assert Adapter.domain_or_ip("example.com") == {:domain, 'example.com'}
15 test "with idna domain" do
16 assert Adapter.domain_or_ip("ですexample.com") == {:domain, 'xn--example-183fne.com'}
20 assert Adapter.domain_or_ip("127.0.0.1") == {:ip, {127, 0, 0, 1}}
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}}
29 describe "domain_or_fallback/1" do
31 assert Adapter.domain_or_fallback("example.com") == 'example.com'
34 test "with idna domain" do
35 assert Adapter.domain_or_fallback("ですexample.com") == 'xn--example-183fne.com'
39 assert Adapter.domain_or_fallback("127.0.0.1") == '127.0.0.1'
43 assert Adapter.domain_or_fallback("2a03:2880:f10c:83:face:b00c:0:25de") ==
44 '2a03:2880:f10c:83:face:b00c:0:25de'
48 describe "format_proxy/1" do
50 assert Adapter.format_proxy(nil) == nil
54 assert Adapter.format_proxy("127.0.0.1:8123") == {{127, 0, 0, 1}, 8123}
57 test "localhost with port" do
58 assert Adapter.format_proxy("localhost:8123") == {'localhost', 8123}
62 assert Adapter.format_proxy({:socks4, :localhost, 9050}) == {:socks4, 'localhost', 9050}