Merge remote-tracking branch 'parent/main' into upstream-20250403
This commit is contained in:
commit
32f5604499
265 changed files with 6227 additions and 3383 deletions
|
@ -13,13 +13,28 @@ RSpec.describe AccountReachFinder do
|
|||
let(:ap_mentioned_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-3', domain: 'example.com') }
|
||||
let(:ap_mentioned_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.org/inbox-4', domain: 'example.org') }
|
||||
|
||||
let(:ap_followed_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-5', domain: 'example.com') }
|
||||
let(:ap_followed_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-6', domain: 'example.org') }
|
||||
|
||||
let(:ap_requested_example_com) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-7', domain: 'example.com') }
|
||||
let(:ap_requested_example_org) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/inbox-8', domain: 'example.org') }
|
||||
|
||||
let(:unrelated_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/unrelated-inbox', domain: 'example.com') }
|
||||
let(:old_followed_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://example.com/old-followed-inbox', domain: 'example.com') }
|
||||
|
||||
before do
|
||||
travel_to(2.months.ago) { account.follow!(old_followed_account) }
|
||||
|
||||
ap_follower_example_com.follow!(account)
|
||||
ap_follower_example_org.follow!(account)
|
||||
ap_follower_with_shared.follow!(account)
|
||||
|
||||
account.follow!(ap_followed_example_com)
|
||||
account.follow!(ap_followed_example_org)
|
||||
|
||||
account.request_follow!(ap_requested_example_com)
|
||||
account.request_follow!(ap_requested_example_org)
|
||||
|
||||
Fabricate(:status, account: account).tap do |status|
|
||||
status.mentions << Mention.new(account: ap_follower_example_com)
|
||||
status.mentions << Mention.new(account: ap_mentioned_with_shared)
|
||||
|
@ -44,7 +59,10 @@ RSpec.describe AccountReachFinder do
|
|||
expect(subject)
|
||||
.to include(*follower_inbox_urls)
|
||||
.and include(*mentioned_account_inbox_urls)
|
||||
.and include(*recently_followed_inbox_urls)
|
||||
.and include(*recently_requested_inbox_urls)
|
||||
.and not_include(unrelated_account.preferred_inbox_url)
|
||||
.and not_include(old_followed_account.preferred_inbox_url)
|
||||
end
|
||||
|
||||
def follower_inbox_urls
|
||||
|
@ -56,5 +74,15 @@ RSpec.describe AccountReachFinder do
|
|||
[ap_mentioned_with_shared, ap_mentioned_example_com, ap_mentioned_example_org]
|
||||
.map(&:preferred_inbox_url)
|
||||
end
|
||||
|
||||
def recently_followed_inbox_urls
|
||||
[ap_followed_example_com, ap_followed_example_org]
|
||||
.map(&:preferred_inbox_url)
|
||||
end
|
||||
|
||||
def recently_requested_inbox_urls
|
||||
[ap_requested_example_com, ap_requested_example_org]
|
||||
.map(&:preferred_inbox_url)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -287,6 +287,23 @@ RSpec.describe ActivityPub::TagManager do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#uris_to_local_accounts' do
|
||||
it 'returns the expected local accounts' do
|
||||
account = Fabricate(:account)
|
||||
expect(subject.uris_to_local_accounts([subject.uri_for(account), instance_actor_url])).to contain_exactly(account, Account.representative)
|
||||
end
|
||||
|
||||
it 'does not return remote accounts' do
|
||||
account = Fabricate(:account, uri: 'https://example.com/123', domain: 'example.com')
|
||||
expect(subject.uris_to_local_accounts([subject.uri_for(account)])).to be_empty
|
||||
end
|
||||
|
||||
it 'does not return an account for a local post' do
|
||||
status = Fabricate(:status)
|
||||
expect(subject.uris_to_local_accounts([subject.uri_for(status)])).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe '#uri_to_resource' do
|
||||
it 'returns the local account' do
|
||||
account = Fabricate(:account)
|
||||
|
|
57
spec/lib/fasp/request_spec.rb
Normal file
57
spec/lib/fasp/request_spec.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
require 'securerandom'
|
||||
|
||||
RSpec.describe Fasp::Request do
|
||||
include ProviderRequestHelper
|
||||
|
||||
subject { described_class.new(provider) }
|
||||
|
||||
let(:provider) do
|
||||
Fabricate(:fasp_provider, base_url: 'https://reqprov.example.com/fasp')
|
||||
end
|
||||
|
||||
shared_examples 'a provider request' do |method|
|
||||
context 'when the response is signed by the provider' do
|
||||
before do
|
||||
stub_provider_request(provider, method:, path: '/test_path')
|
||||
end
|
||||
|
||||
it "performs a signed #{method.to_s.upcase} request relative to the base_path of the fasp" do
|
||||
subject.send(method, '/test_path')
|
||||
|
||||
expect(WebMock).to have_requested(method, 'https://reqprov.example.com/fasp/test_path')
|
||||
.with(headers: {
|
||||
'Signature' => /.+/,
|
||||
'Signature-Input' => /.+/,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the response is not signed' do
|
||||
before do
|
||||
stub_request(method, 'https://reqprov.example.com/fasp/test_path')
|
||||
.to_return(status: 200)
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
expect do
|
||||
subject.send(method, '/test_path')
|
||||
end.to raise_error(Mastodon::SignatureVerificationError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#get' do
|
||||
include_examples 'a provider request', :get
|
||||
end
|
||||
|
||||
describe '#post' do
|
||||
include_examples 'a provider request', :post
|
||||
end
|
||||
|
||||
describe '#delete' do
|
||||
include_examples 'a provider request', :delete
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue