Update functions in object fetcher for tesla and set up a proper mock for tests
This commit is contained in:
parent
b09ae02c04
commit
e7c3c36766
4 changed files with 14 additions and 12 deletions
|
@ -27,7 +27,7 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
},
|
},
|
||||||
:ok <- Containment.contain_origin(id, params),
|
:ok <- Containment.contain_origin(id, params),
|
||||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||||
{:ok, Object.normalize(activity.data["object"], false)}
|
{:ok, Object.normalize(activity, false)}
|
||||||
else
|
else
|
||||||
{:error, {:reject, nil}} ->
|
{:error, {:reject, nil}} ->
|
||||||
{:reject, nil}
|
{:reject, nil}
|
||||||
|
@ -56,16 +56,13 @@ defmodule Pleroma.Object.Fetcher do
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_and_contain_remote_object_from_id(id) do
|
def fetch_and_contain_remote_object_from_id(id) do
|
||||||
Logger.info("Fetching #{id} via AP")
|
Logger.info("Fetching object #{id} via AP")
|
||||||
|
|
||||||
with true <- String.starts_with?(id, "http"),
|
with true <- String.starts_with?(id, "http"),
|
||||||
{:ok, %{body: body, status_code: code}} when code in 200..299 <-
|
{:ok, %{body: body, status: code}} when code in 200..299 <-
|
||||||
@httpoison.get(
|
@httpoison.get(
|
||||||
id,
|
id,
|
||||||
[Accept: "application/activity+json"],
|
[{:Accept, "application/activity+json"}]
|
||||||
follow_redirect: true,
|
|
||||||
timeout: 10000,
|
|
||||||
recv_timeout: 20000
|
|
||||||
),
|
),
|
||||||
{:ok, data} <- Jason.decode(body),
|
{:ok, data} <- Jason.decode(body),
|
||||||
:ok <- Containment.contain_origin_from_id(id, data) do
|
:ok <- Containment.contain_origin_from_id(id, data) do
|
||||||
|
|
|
@ -4,6 +4,12 @@ defmodule Pleroma.Object.FetcherTest do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Object.Fetcher
|
alias Pleroma.Object.Fetcher
|
||||||
|
import Tesla.Mock
|
||||||
|
|
||||||
|
setup do
|
||||||
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
|
||||||
describe "actor origin containment" do
|
describe "actor origin containment" do
|
||||||
test "it rejects objects with a bogus origin" do
|
test "it rejects objects with a bogus origin" do
|
||||||
|
@ -24,7 +30,7 @@ defmodule Pleroma.Object.FetcherTest do
|
||||||
{:ok, object} =
|
{:ok, object} =
|
||||||
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
Fetcher.fetch_object_from_id("http://mastodon.example.org/@admin/99541947525187367")
|
||||||
|
|
||||||
assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
|
assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||||
assert activity.data["id"]
|
assert activity.data["id"]
|
||||||
|
|
||||||
{:ok, object_again} =
|
{:ok, object_again} =
|
||||||
|
@ -38,7 +44,7 @@ defmodule Pleroma.Object.FetcherTest do
|
||||||
|
|
||||||
test "it works with objects only available via Ostatus" do
|
test "it works with objects only available via Ostatus" do
|
||||||
{:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
|
{:ok, object} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
|
||||||
assert activity = Activity.get_create_activity_by_object_ap_id(object.data["id"])
|
assert activity = Activity.get_create_by_object_ap_id(object.data["id"])
|
||||||
assert activity.data["id"]
|
assert activity.data["id"]
|
||||||
|
|
||||||
{:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
|
{:ok, object_again} = Fetcher.fetch_object_from_id("https://shitposter.club/notice/2827873")
|
||||||
|
|
|
@ -9,7 +9,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.CommonAPI.Utils
|
alias Pleroma.Web.CommonAPI.Utils
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
|
@ -232,7 +231,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, object} =
|
{:ok, object} =
|
||||||
ActivityPub.fetch_object_from_id(
|
Pleroma.Object.Fetcher.fetch_object_from_id(
|
||||||
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -360,7 +360,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
|
||||||
|
|
||||||
test "a peertube video" do
|
test "a peertube video" do
|
||||||
{:ok, object} =
|
{:ok, object} =
|
||||||
ActivityPub.fetch_object_from_id(
|
Pleroma.Object.Fetcher.fetch_object_from_id(
|
||||||
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue