mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Merge commit 'db074fc3e2b671e28a44ae379e6df1fcbdbbce53' into glitch-soc/merge-upstream
This commit is contained in:
@@ -3,45 +3,72 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Webfinger do
|
||||
describe 'self link' do
|
||||
describe '#initialize' do
|
||||
subject { described_class.new(uri) }
|
||||
|
||||
context 'when called with local account' do
|
||||
let(:uri) { 'acct:alice' }
|
||||
|
||||
it 'handles value and raises error' do
|
||||
expect { subject }.to raise_error(ArgumentError, /for local account/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when called with remote account' do
|
||||
let(:uri) { 'acct:alice@host.example' }
|
||||
|
||||
it 'handles value and sets attributes' do
|
||||
expect { subject }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
subject { described_class.new('acct:alice@example.com').perform }
|
||||
|
||||
context 'when self link is specified with type application/activity+json' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
|
||||
let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/activity+json' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'correctly parses the response' do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
|
||||
expect(subject.self_link_href).to eq 'https://example.com/alice'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when self link is specified with type application/ld+json' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } }
|
||||
let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'correctly parses the response' do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
|
||||
expect(subject.self_link_href).to eq 'https://example.com/alice'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when self link is specified with incorrect type' do
|
||||
let!(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } }
|
||||
let(:webfinger) { { subject: 'acct:alice@example.com', links: [{ rel: 'self', href: 'https://example.com/alice', type: 'application/json"' }] } }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
|
||||
expect { subject }
|
||||
.to raise_error(Webfinger::Error)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when response body is not parsable' do
|
||||
it 'raises an error' do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com')
|
||||
.to_return(body: 'XXX', headers: { 'Content-Type': 'application/jrd+json' })
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:alice@example.com').to_return(body: 'XXX', headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'raises an error' do
|
||||
expect { subject }
|
||||
.to raise_error(Webfinger::Error)
|
||||
end
|
||||
@@ -63,7 +90,7 @@ RSpec.describe Webfinger do
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(body: host_meta, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://example.com/.well-known/nonStandardWebfinger?resource=acct:alice@example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://example.com/.well-known/nonStandardWebfinger?resource=acct:alice@example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'uses host meta details' do
|
||||
|
||||
@@ -103,7 +103,7 @@ RSpec.describe ResolveAccountService do
|
||||
context 'with a legitimate webfinger redirection' do
|
||||
before do
|
||||
webfinger = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
|
||||
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'returns new remote account' do
|
||||
@@ -121,7 +121,7 @@ RSpec.describe ResolveAccountService do
|
||||
context 'with a misconfigured redirection' do
|
||||
before do
|
||||
webfinger = { subject: 'acct:Foo@redirected.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
|
||||
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'returns new remote account' do
|
||||
@@ -139,9 +139,9 @@ RSpec.describe ResolveAccountService do
|
||||
context 'with too many webfinger redirections' do
|
||||
before do
|
||||
webfinger = { subject: 'acct:foo@evil.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
|
||||
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: JSON.generate(webfinger), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://redirected.example.com/.well-known/webfinger?resource=acct:Foo@redirected.example.com').to_return(body: webfinger.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
webfinger2 = { subject: 'acct:foo@ap.example.com', links: [{ rel: 'self', href: 'https://ap.example.com/users/foo', type: 'application/activity+json' }] }
|
||||
stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: JSON.generate(webfinger2), headers: { 'Content-Type': 'application/jrd+json' })
|
||||
stub_request(:get, 'https://evil.example.com/.well-known/webfinger?resource=acct:foo@evil.example.com').to_return(body: webfinger2.to_json, headers: { 'Content-Type': 'application/jrd+json' })
|
||||
end
|
||||
|
||||
it 'does not return a new remote account' do
|
||||
|
||||
@@ -44,12 +44,3 @@ def serialized_record_json(record, serializer, adapter: nil, options: {})
|
||||
).to_json
|
||||
)
|
||||
end
|
||||
|
||||
def expect_push_bulk_to_match(klass, matcher)
|
||||
allow(Sidekiq::Client).to receive(:push_bulk)
|
||||
yield
|
||||
expect(Sidekiq::Client).to have_received(:push_bulk).with(hash_including({
|
||||
'class' => klass,
|
||||
'args' => matcher,
|
||||
}))
|
||||
end
|
||||
|
||||
@@ -16,9 +16,10 @@ RSpec.describe ActivityPub::DistributePollUpdateWorker do
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Update'), account.id, 'http://example.com']]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
subject.perform(status.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Update'), account.id, 'http://example.com')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,9 +19,10 @@ RSpec.describe ActivityPub::DistributionWorker do
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
subject.perform(status.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,9 +32,10 @@ RSpec.describe ActivityPub::DistributionWorker do
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
subject.perform(status.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Create'), status.account.id, 'http://example.com', anything)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -46,9 +48,10 @@ RSpec.describe ActivityPub::DistributionWorker do
|
||||
end
|
||||
|
||||
it 'delivers to mentioned accounts' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Create'), status.account.id, 'https://foo.bar/inbox', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
subject.perform(status.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Create'), status.account.id, 'https://foo.bar/inbox', anything)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,9 +70,10 @@ RSpec.describe ActivityPub::DistributionWorker do
|
||||
object: ActivityPub::TagManager.instance.uri_for(status),
|
||||
}
|
||||
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(expected_json), reblog.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(reblog.id)
|
||||
end
|
||||
subject.perform(reblog.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(expected_json), reblog.account.id, 'http://example.com', anything)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,9 +90,10 @@ RSpec.describe ActivityPub::DistributionWorker do
|
||||
}),
|
||||
}
|
||||
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(expected_json), reblog.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(reblog.id)
|
||||
end
|
||||
subject.perform(reblog.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(expected_json), reblog.account.id, 'http://example.com', anything)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,16 +16,11 @@ RSpec.describe ActivityPub::MoveDistributionWorker do
|
||||
end
|
||||
|
||||
it 'delivers to followers and known blockers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, expected_migration_deliveries) do
|
||||
subject.perform(migration.id)
|
||||
end
|
||||
end
|
||||
subject.perform(migration.id)
|
||||
|
||||
def expected_migration_deliveries
|
||||
[
|
||||
[match_json_values(type: 'Move'), migration.account.id, 'http://example.com'],
|
||||
[match_json_values(type: 'Move'), migration.account.id, 'http://example2.com'],
|
||||
]
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Move'), migration.account.id, 'http://example.com')
|
||||
.and have_enqueued_sidekiq_job(match_json_values(type: 'Move'), migration.account.id, 'http://example2.com')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,9 +14,10 @@ RSpec.describe ActivityPub::UpdateDistributionWorker do
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[match_json_values(type: 'Update'), account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(account.id)
|
||||
end
|
||||
subject.perform(account.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Update'), account.id, 'http://example.com', anything)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,6 +39,8 @@ RSpec.describe Scheduler::SelfDestructScheduler do
|
||||
end
|
||||
|
||||
context 'when sidekiq is operational' do
|
||||
let!(:other_account) { Fabricate :account, inbox_url: 'https://host.example/inbox', domain: 'host.example', protocol: :activitypub }
|
||||
|
||||
it 'suspends local non-suspended accounts' do
|
||||
worker.perform
|
||||
|
||||
@@ -51,6 +53,9 @@ RSpec.describe Scheduler::SelfDestructScheduler do
|
||||
|
||||
worker.perform
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(match_json_values(type: 'Delete', signature: be_present), account.id, other_account.inbox_url)
|
||||
|
||||
expect(account.reload.suspended_at).to be > 1.day.ago
|
||||
expect { deletion_request.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user