...
 
Commits (2)
......@@ -25,13 +25,13 @@ defmodule Pleroma.Web.RelMe do
def parse(_), do: {:error, "No URL provided"}
defp parse_url(url) do
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter: @hackney_options)
data =
Floki.attribute(html, "link[rel~=me]", "href") ++
Floki.attribute(html, "a[rel~=me]", "href")
{:ok, data}
with {:ok, %Tesla.Env{body: html, status: status}} when status in 200..299 <-
Pleroma.HTTP.get(url, [], adapter: @hackney_options),
data <-
Floki.attribute(html, "link[rel~=me]", "href") ++
Floki.attribute(html, "a[rel~=me]", "href") do
{:ok, data}
end
rescue
e -> {:error, "Parsing error: #{inspect(e)}"}
end
......
......@@ -39,7 +39,11 @@ defmodule HttpRequestMock do
end
def get("http://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
{:ok, %Tesla.Env{status: 404, body: ""}}
end
def get("https://osada.macgirvin.com/.well-known/host-meta", _, _, _) do
{:ok, %Tesla.Env{status: 404, body: ""}}
end
def get("https://mastodon.social/users/emelie/statuses/101849165031453009", _, _, _) do
......@@ -429,10 +433,6 @@ defmodule HttpRequestMock do
}}
end
def get("https://shitposter.club/notice/2827849", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://shitposter.club/notice/2827873", _, _, _) do
{:ok,
%Tesla.Env{
......@@ -1012,10 +1012,6 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: File.read!("test/fixtures/tesla_mock/sjw.json")}}
end
def get("http://mastodon.example.org/@admin/99541947525187367", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://info.pleroma.site/activity4.json", _, _, _) do
{:ok, %Tesla.Env{status: 500, body: "Error occurred"}}
end
......@@ -1040,14 +1036,6 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://gs.archae.me/notice/778260", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://mamot.fr/users/Skruyb/updates/176041", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("http://pleroma.example.org:4000/objects/" <> _scheme, _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
......@@ -1080,31 +1068,6 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://mastodon.social/@lambadalambda/5582979", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get(
"https://mastodon.sdf.org/.well-known/webfinger?resource=acct:https://mastodon.sdf.org/users/snowdusk",
_,
_,
_
) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://10.111.10.1/notice/9kCP7V", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://172.16.32.40/notice/9kCP7V", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("https://192.168.10.40/notice/9kCP7V", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def get("http://mstdn.jp/.well-known/host-meta", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
......@@ -1119,7 +1082,7 @@ defmodule HttpRequestMock do
end
def get("http://example.com/rel_me/error", _, _, _) do
{:error, "some error"}
{:ok, %Tesla.Env{status: 404, body: ""}}
end
def get(nil, _, _, _), do: nil
......@@ -1192,18 +1155,6 @@ defmodule HttpRequestMock do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def post("https://pleroma2.soykaf.com/cb", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def post("https://domain2.com/salmon", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def post("http://test-example.org/salmon", _, _, _) do
{:ok, %Tesla.Env{status: 200, body: ""}}
end
def post(url, query, body, headers) do
{:error,
"Mock response not implemented for POST #{inspect(url)}, #{query}, #{inspect(body)}, #{
......
......@@ -4,7 +4,6 @@
defmodule Pleroma.Web.RelMeTest do
use ExUnit.Case, async: true
import ExUnit.CaptureLog
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
......@@ -16,9 +15,7 @@ defmodule Pleroma.Web.RelMeTest do
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/null") == {:ok, []}
assert capture_log(fn ->
assert {:error, _} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
end) =~ "some error"
assert {:ok, %{status: 404}} = Pleroma.Web.RelMe.parse("http://example.com/rel_me/error")
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/link") == {:ok, hrefs}
assert Pleroma.Web.RelMe.parse("http://example.com/rel_me/anchor") == {:ok, hrefs}
......@@ -33,13 +30,11 @@ defmodule Pleroma.Web.RelMeTest do
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/null", profile_urls) ==
fallback
assert capture_log(fn ->
assert Pleroma.Web.RelMe.maybe_put_rel_me(
"http://example.com/rel_me/error",
profile_urls
) ==
fallback
end) =~ "some error"
assert Pleroma.Web.RelMe.maybe_put_rel_me(
"http://example.com/rel_me/error",
profile_urls
) ==
fallback
assert Pleroma.Web.RelMe.maybe_put_rel_me("http://example.com/rel_me/anchor", profile_urls) ==
attr
......