-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
186 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
defmodule ActivityPub.Federator.FetcherRecursionTest do | ||
use ActivityPub.DataCase, async: false | ||
import Tesla.Mock | ||
import Mock | ||
|
||
alias ActivityPub.Federator.Fetcher | ||
alias ActivityPub.Federator.WebFinger | ||
|
||
alias ActivityPub.Object, as: Activity | ||
alias ActivityPub.Instances | ||
alias ActivityPub.Object | ||
|
||
alias ActivityPub.Test.HttpRequestMock | ||
|
||
setup_all do | ||
mock_global(fn | ||
env -> | ||
HttpRequestMock.request(env) | ||
end) | ||
|
||
:ok | ||
end | ||
|
||
describe "max thread distance restriction" do | ||
@ap_id "https://mastodon.local/@admin/99512778738411822" | ||
@reply_ap_id "https://mastodon.local/users/admin/statuses/8511" | ||
@reply_2_ap_id "https://mocked.local/objects/eb3b1181-38cc-4eaf-ba1b-3f5431fa9779" | ||
|
||
setup do: clear_config([:instance, :federation_incoming_max_recursion]) | ||
|
||
test "it returns error if thread depth is exceeded" do | ||
clear_config([:instance, :federation_incoming_max_recursion], 0) | ||
|
||
assert {:error, "Stopping to avoid too much recursion"} = | ||
Fetcher.fetch_object_from_id(@ap_id, depth: 1) | ||
|
||
assert {:error, :not_found} = ActivityPub.Object.get_cached(ap_id: @ap_id) | ||
end | ||
|
||
test "it fetches object if max thread depth is restricted to 0 and depth is not specified" do | ||
clear_config([:instance, :federation_incoming_max_recursion], 0) | ||
|
||
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id) | ||
end | ||
|
||
test "it fetches object if requested depth does not exceed max thread depth" do | ||
clear_config([:instance, :federation_incoming_max_recursion], 10) | ||
|
||
assert {:ok, _} = Fetcher.fetch_object_from_id(@ap_id, depth: 10) | ||
end | ||
|
||
test "it fetches reply_to and replies if thread depth is not exceeded" do | ||
clear_config([:instance, :federation_incoming_max_recursion], 4) | ||
|
||
assert {:ok, _} = | ||
Fetcher.fetch_object_from_id(@reply_ap_id, depth: 1) | ||
|
||
Oban.drain_queue(queue: :remote_fetcher, with_recursion: true) | ||
|
||
assert {:ok, _} = ActivityPub.Object.get_cached(ap_id: @reply_ap_id) | ||
assert {:ok, _} = ActivityPub.Object.get_cached(ap_id: @ap_id) | ||
assert {:ok, _} = ActivityPub.Object.get_cached(ap_id: @reply_2_ap_id) | ||
end | ||
|
||
test "it fetches reply_to if thread depth is not exceeded" do | ||
clear_config([:instance, :federation_incoming_max_recursion], 2) | ||
|
||
assert {:ok, _} = | ||
Fetcher.fetch_object_from_id(@reply_ap_id, depth: 1) | ||
|
||
Oban.drain_queue(queue: :remote_fetcher, with_recursion: true) | ||
|
||
assert {:ok, _} = ActivityPub.Object.get_cached(ap_id: @reply_ap_id) | ||
assert {:ok, _} = ActivityPub.Object.get_cached(ap_id: @ap_id) | ||
assert {:error, :not_found} = ActivityPub.Object.get_cached(ap_id: @reply_2_ap_id) | ||
end | ||
|
||
test "it does not fetch reply_to if thread depth is exceeded" do | ||
clear_config([:instance, :federation_incoming_max_recursion], 3) | ||
|
||
assert {:ok, _} = | ||
Fetcher.fetch_object_from_id(@reply_ap_id, depth: 3) | ||
|
||
Oban.drain_queue(queue: :remote_fetcher, with_recursion: true) | ||
|
||
assert {:ok, _} = ActivityPub.Object.get_cached(ap_id: @reply_ap_id) | ||
assert {:error, :not_found} = ActivityPub.Object.get_cached(ap_id: @ap_id) | ||
assert {:error, :not_found} = ActivityPub.Object.get_cached(ap_id: @reply_2_ap_id) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"@context" : [ | ||
"https://www.w3.org/ns/activitystreams", | ||
"https://w3id.org/security/v1", | ||
{ | ||
"Emoji" : "toot:Emoji", | ||
"Hashtag" : "as:Hashtag", | ||
"atomUri" : "ostatus:atomUri", | ||
"conversation" : "ostatus:conversation", | ||
"inReplyToAtomUri" : "ostatus:inReplyToAtomUri", | ||
"manuallyApprovesFollowers" : "as:manuallyApprovesFollowers", | ||
"movedTo" : "as:movedTo", | ||
"ostatus" : "http://ostatus.org#", | ||
"sensitive" : "as:sensitive", | ||
"toot" : "http://joinmastodon.org/ns#" | ||
} | ||
], | ||
"atomUri" : "https://mastodon.local/users/admin/statuses/8511", | ||
"attachment" : [ | ||
{ | ||
"mediaType" : "image/jpeg", | ||
"name" : null, | ||
"type" : "Document", | ||
"url" : "https://mastodon.local/system/media_attachments/files/000/000/002/original/334ce029e7bfb920.jpg" | ||
} | ||
], | ||
"attributedTo" : "https://mastodon.local/users/admin", | ||
"cc" : [ | ||
"https://mastodon.local/users/admin/followers" | ||
], | ||
"content" : "<p>yeah.</p>", | ||
"conversation" : "tag:mastodon.local,2018-02-17:objectId=59:objectType=Conversation", | ||
"id" : "https://mastodon.local/users/admin/statuses/8511", | ||
"inReplyTo" : "https://mastodon.local/users/admin/statuses/99512778738411822", | ||
"inReplyToAtomUri" : null, | ||
"published" : "2018-02-17T17:46:20Z", | ||
"sensitive" : false, | ||
"summary" : null, | ||
"tag" : [], | ||
"to" : [ | ||
"https://www.w3.org/ns/activitystreams#Public" | ||
], | ||
"type" : "Note", | ||
"url" : "https://mastodon.local/@admin/8511" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters