Revert "Upstream 20240517"
This commit is contained in:
parent
9c006fd893
commit
f6dec44e95
2347 changed files with 26470 additions and 87494 deletions
|
@ -6,7 +6,7 @@ describe ActivityPub::DistributionWorker do
|
|||
subject { described_class.new }
|
||||
|
||||
let(:status) { Fabricate(:status) }
|
||||
let(:follower) { Fabricate(:account, protocol: :activitypub, shared_inbox_url: 'http://example.com', inbox_url: 'http://example.com/follower/inbox', domain: 'example.com') }
|
||||
let(:follower) { Fabricate(:account, protocol: :activitypub, inbox_url: 'http://example.com', domain: 'example.com') }
|
||||
|
||||
describe '#perform' do
|
||||
before do
|
||||
|
@ -25,18 +25,6 @@ describe ActivityPub::DistributionWorker do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with unlisted status' do
|
||||
before do
|
||||
status.update(visibility: :unlisted)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private status' do
|
||||
before do
|
||||
status.update(visibility: :private)
|
||||
|
@ -49,52 +37,6 @@ describe ActivityPub::DistributionWorker do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with limited status' do
|
||||
before do
|
||||
status.update(visibility: :limited)
|
||||
status.capability_tokens.create!
|
||||
status.mentions.create!(account: follower, silent: true)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com/follower/inbox', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limited response status' do
|
||||
before do
|
||||
allow(ActivityPub::DeliveryWorker).to receive(:perform_async).with(kind_of(String), status.account.id, 'http://example.com/conversation/inbox', anything)
|
||||
status.update(visibility: :limited, thread: Fabricate(:status))
|
||||
status.conversation.update(uri: 'https://example.com/conversation', inbox_url: 'http://example.com/conversation/inbox')
|
||||
status.capability_tokens.create!
|
||||
status.mentions.create!(account: follower, silent: true)
|
||||
stub_request(:post, 'http://example.com/conversation/inbox')
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
subject.perform(status.id)
|
||||
expect(ActivityPub::DeliveryWorker).to have_received(:perform_async)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limited status for no-follower but non-mentioned follower' do
|
||||
let(:no_follower) { Fabricate(:account, domain: 'example.com', inbox_url: 'http://example.com/no_follower/inbox', shared_inbox_url: 'http://example.com') }
|
||||
|
||||
before do
|
||||
status.update(visibility: :limited)
|
||||
status.capability_tokens.create!
|
||||
status.mentions.create!(account: no_follower, silent: true)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com/no_follower/inbox', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with direct status' do
|
||||
let(:mentioned_account) { Fabricate(:account, protocol: :activitypub, inbox_url: 'https://foo.bar/inbox', domain: 'foo.bar') }
|
||||
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::FetchInstanceInfoWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:wellknown_nodeinfo) do
|
||||
{
|
||||
links: [
|
||||
{
|
||||
rel: 'http://nodeinfo.diaspora.software/ns/schema/2.0',
|
||||
href: 'https://example.com/nodeinfo/2.0',
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
|
||||
let(:nodeinfo) do
|
||||
{
|
||||
version: '2.0',
|
||||
software: {
|
||||
name: 'mastodon',
|
||||
version: '4.2.0-beta1',
|
||||
},
|
||||
protocols: ['activitypub'],
|
||||
}
|
||||
end
|
||||
|
||||
let(:wellknown_nodeinfo_json) { Oj.dump(wellknown_nodeinfo) }
|
||||
let(:nodeinfo_json) { Oj.dump(nodeinfo) }
|
||||
|
||||
context 'when success' do
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 200, body: wellknown_nodeinfo_json)
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: nodeinfo_json)
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
it 'performs a mastodon instance' do
|
||||
subject.perform('example.com')
|
||||
|
||||
info = InstanceInfo.find_by(domain: 'example.com')
|
||||
expect(info).to_not be_nil
|
||||
expect(info.software).to eq 'mastodon'
|
||||
expect(info.version).to eq '4.2.0-beta1'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when update' do
|
||||
let(:new_nodeinfo) do
|
||||
{
|
||||
version: '2.0',
|
||||
software: {
|
||||
name: 'mastodon',
|
||||
version: '4.2.0-beta3',
|
||||
},
|
||||
protocols: ['activitypub'],
|
||||
}
|
||||
end
|
||||
let(:new_nodeinfo_json) { Oj.dump(new_nodeinfo) }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 200, body: wellknown_nodeinfo_json)
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
it 'does not update immediately' do
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: nodeinfo_json)
|
||||
subject.perform('example.com')
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: new_nodeinfo_json)
|
||||
subject.perform('example.com')
|
||||
|
||||
info = InstanceInfo.find_by(domain: 'example.com')
|
||||
expect(info).to_not be_nil
|
||||
expect(info.software).to eq 'mastodon'
|
||||
expect(info.version).to eq '4.2.0-beta1'
|
||||
end
|
||||
|
||||
it 'performs a mastodon instance' do
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: nodeinfo_json)
|
||||
subject.perform('example.com')
|
||||
Rails.cache.delete('fetch_instance_info:example.com')
|
||||
stub_request(:get, 'https://example.com/nodeinfo/2.0').to_return(status: 200, body: new_nodeinfo_json)
|
||||
subject.perform('example.com')
|
||||
|
||||
info = InstanceInfo.find_by(domain: 'example.com')
|
||||
expect(info).to_not be_nil
|
||||
expect(info.software).to eq 'mastodon'
|
||||
expect(info.version).to eq '4.2.0-beta3'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when failed' do
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(status: 404)
|
||||
Fabricate(:account, domain: 'example.com')
|
||||
Instance.refresh
|
||||
end
|
||||
|
||||
it 'performs a mastodon instance' do
|
||||
expect(subject.perform('example.com')).to be true
|
||||
|
||||
info = InstanceInfo.find_by(domain: 'example.com')
|
||||
expect(info).to be_nil
|
||||
end
|
||||
|
||||
it 'does not fetch again immediately' do
|
||||
expect(subject.perform('example.com')).to be true
|
||||
expect(subject.perform('example.com')).to be true
|
||||
|
||||
expect(a_request(:get, 'https://example.com/.well-known/nodeinfo')).to have_been_made.once
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,41 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ActivityPub::FetchRemoteStatusWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:sender) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') }
|
||||
let(:payload) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'https://example.com/note',
|
||||
attributedTo: sender.uri,
|
||||
type: 'Note',
|
||||
content: 'Lorem ipsum',
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
tag: [
|
||||
{
|
||||
type: 'Mention',
|
||||
href: ActivityPub::TagManager.instance.uri_for(Fabricate(:account)),
|
||||
},
|
||||
],
|
||||
}
|
||||
end
|
||||
let(:json) { Oj.dump(payload) }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/note').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' })
|
||||
end
|
||||
|
||||
describe '#perform' do
|
||||
it 'original status is fetched' do
|
||||
subject.perform('https://example.com/note', sender.id, Fabricate(:account).id)
|
||||
|
||||
status = sender.statuses.first
|
||||
|
||||
expect(status).to_not be_nil
|
||||
expect(status.text).to eq 'Lorem ipsum'
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,7 +21,7 @@ describe ActivityPub::FetchRepliesWorker do
|
|||
|
||||
describe 'perform' do
|
||||
it 'performs a request if the collection URI is from the same host' do
|
||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 200, body: json, headers: { 'Content-Type': 'application/activity+json' })
|
||||
stub_request(:get, 'https://example.com/statuses_replies/1').to_return(status: 200, body: json)
|
||||
subject.perform(status.id, 'https://example.com/statuses_replies/1')
|
||||
expect(a_request(:get, 'https://example.com/statuses_replies/1')).to have_been_made.once
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
subject { described_class.new }
|
||||
|
||||
let(:status) { Fabricate(:status, text: 'foo') }
|
||||
let(:follower) { Fabricate(:account, protocol: :activitypub, shared_inbox_url: 'http://example.com', inbox_url: 'http://example.com/follower/inbox', domain: 'example.com') }
|
||||
let(:follower) { Fabricate(:account, protocol: :activitypub, inbox_url: 'http://example.com', domain: 'example.com') }
|
||||
|
||||
describe '#perform' do
|
||||
before do
|
||||
|
@ -31,18 +31,6 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with unlisted status' do
|
||||
before do
|
||||
status.update(visibility: :unlisted)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private status' do
|
||||
before do
|
||||
status.update(visibility: :private)
|
||||
|
@ -54,35 +42,5 @@ describe ActivityPub::StatusUpdateDistributionWorker do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limited status' do
|
||||
before do
|
||||
status.update(visibility: :limited)
|
||||
status.capability_tokens.create!
|
||||
status.mentions.create!(account: follower, silent: true)
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
expect_push_bulk_to_match(ActivityPub::DeliveryWorker, [[kind_of(String), status.account.id, 'http://example.com', anything]]) do
|
||||
subject.perform(status.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with limited response status' do
|
||||
before do
|
||||
allow(ActivityPub::DeliveryWorker).to receive(:perform_async).with(kind_of(String), status.account.id, 'http://example.com/conversation/inbox', anything)
|
||||
status.update(visibility: :limited, thread: Fabricate(:status))
|
||||
status.conversation.update(uri: 'https://example.com/conversation', inbox_url: 'http://example.com/conversation/inbox')
|
||||
status.capability_tokens.create!
|
||||
status.mentions.create!(account: follower, silent: true)
|
||||
stub_request(:post, 'http://example.com/conversation/inbox')
|
||||
end
|
||||
|
||||
it 'delivers to followers' do
|
||||
subject.perform(status.id)
|
||||
expect(ActivityPub::DeliveryWorker).to have_received(:perform_async)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,17 +15,12 @@ describe BackupWorker do
|
|||
let!(:other_backup) { Fabricate(:backup, user: backup.user) }
|
||||
|
||||
it 'sends the backup to the service and removes other backups', :sidekiq_inline do
|
||||
emails = capture_emails { worker.perform(backup.id) }
|
||||
expect do
|
||||
worker.perform(backup.id)
|
||||
end.to change(UserMailer.deliveries, :size).by(1)
|
||||
|
||||
expect(service).to have_received(:call).with(backup)
|
||||
expect { other_backup.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
expect(emails.size)
|
||||
.to eq(1)
|
||||
expect(emails.first)
|
||||
.to have_attributes(
|
||||
to: contain_exactly(backup.user.email),
|
||||
subject: I18n.t('user_mailer.backup_ready.subject')
|
||||
)
|
||||
end
|
||||
|
||||
context 'when sidekiq retries are exhausted' do
|
||||
|
|
|
@ -5,10 +5,6 @@ require 'rails_helper'
|
|||
describe FeedInsertWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
def notify?(account, type, activity_id)
|
||||
Notification.exists?(account: account, type: type, activity_id: activity_id)
|
||||
end
|
||||
|
||||
describe 'perform' do
|
||||
let(:follower) { Fabricate(:account) }
|
||||
let(:status) { Fabricate(:status) }
|
||||
|
@ -71,43 +67,5 @@ describe FeedInsertWorker do
|
|||
expect(instance).to have_received(:push_to_list).with(list, status, update: nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with notification' do
|
||||
it 'skips notification when unset', :sidekiq_inline do
|
||||
subject.perform(status.id, follower.id)
|
||||
expect(notify?(follower, 'status', status.id)).to be false
|
||||
end
|
||||
|
||||
it 'pushes notification when read status is set', :sidekiq_inline do
|
||||
Fabricate(:follow, account: follower, target_account: status.account, notify: true)
|
||||
|
||||
subject.perform(status.id, follower.id)
|
||||
expect(notify?(follower, 'status', status.id)).to be true
|
||||
end
|
||||
|
||||
it 'skips notification when the account is registered list but not notify', :sidekiq_inline do
|
||||
follower.follow!(status.account)
|
||||
list = Fabricate(:list, account: follower)
|
||||
Fabricate(:list_account, list: list, account: status.account)
|
||||
|
||||
subject.perform(status.id, list.id, 'list')
|
||||
|
||||
list_status = ListStatus.find_by(list: list, status: status)
|
||||
|
||||
expect(list_status).to be_nil
|
||||
end
|
||||
|
||||
it 'pushes notification when the account is registered list', :sidekiq_inline do
|
||||
follower.follow!(status.account)
|
||||
list = Fabricate(:list, account: follower, notify: true)
|
||||
Fabricate(:list_account, list: list, account: status.account)
|
||||
|
||||
subject.perform(status.id, list.id, 'list')
|
||||
list_status = ListStatus.find_by(list: list, status: status)
|
||||
|
||||
expect(list_status).to_not be_nil
|
||||
expect(notify?(follower, 'list_status', list_status.id)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ProcessReferencesWorker do
|
||||
let(:worker) { described_class.new }
|
||||
|
||||
describe 'perform' do
|
||||
it 'runs without error for simple call' do
|
||||
expect { worker.perform(1000, [], []) }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'runs without error with no_fetch_urls' do
|
||||
expect { worker.perform(1000, [], [], no_fetch_urls: []) }.to_not raise_error
|
||||
end
|
||||
end
|
||||
end
|
|
@ -41,7 +41,7 @@ describe RedownloadAvatarWorker do
|
|||
it 'reprocesses a remote avatar' do
|
||||
stub_request(:get, 'https://example.host/file').to_return request_fixture('avatar.txt')
|
||||
account = Fabricate(:account, avatar_remote_url: 'https://example.host/file')
|
||||
account.update_column(:avatar_file_name, nil)
|
||||
account.update_column(:avatar_file_name, nil) # rubocop:disable Rails/SkipsModelValidations
|
||||
|
||||
result = worker.perform(account.id)
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ describe RedownloadHeaderWorker do
|
|||
it 'reprocesses a remote header' do
|
||||
stub_request(:get, 'https://example.host/file').to_return request_fixture('avatar.txt')
|
||||
account = Fabricate(:account, header_remote_url: 'https://example.host/file')
|
||||
account.update_column(:header_file_name, nil)
|
||||
account.update_column(:header_file_name, nil) # rubocop:disable Rails/SkipsModelValidations
|
||||
|
||||
result = worker.perform(account.id)
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Scheduler::AutoCloseRegistrationsScheduler do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#perform' do
|
||||
let(:moderator_activity_date) { Time.now.utc }
|
||||
|
||||
before do
|
||||
Fabricate(:user, role: UserRole.find_by(name: 'Owner'), current_sign_in_at: 10.years.ago)
|
||||
Fabricate(:user, role: UserRole.find_by(name: 'Moderator'), current_sign_in_at: moderator_activity_date)
|
||||
end
|
||||
|
||||
context 'when registrations are open' do
|
||||
before do
|
||||
Setting.registrations_mode = 'open'
|
||||
end
|
||||
|
||||
context 'when a moderator has logged in recently' do
|
||||
let(:moderator_activity_date) { Time.now.utc }
|
||||
|
||||
it 'does not change registrations mode' do
|
||||
expect { subject.perform }.to_not change(Setting, :registrations_mode)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a moderator has not recently signed in' do
|
||||
let(:moderator_activity_date) { 1.year.ago }
|
||||
|
||||
it 'changes registrations mode from open to approved' do
|
||||
expect { subject.perform }.to change(Setting, :registrations_mode).from('open').to('approved')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when registrations are closed' do
|
||||
before do
|
||||
Setting.registrations_mode = 'none'
|
||||
end
|
||||
|
||||
context 'when a moderator has logged in recently' do
|
||||
let(:moderator_activity_date) { Time.now.utc }
|
||||
|
||||
it 'does not change registrations mode' do
|
||||
expect { subject.perform }.to_not change(Setting, :registrations_mode)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a moderator has not recently signed in' do
|
||||
let(:moderator_activity_date) { 1.year.ago }
|
||||
|
||||
it 'does not change registrations mode' do
|
||||
expect { subject.perform }.to_not change(Setting, :registrations_mode)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,7 +14,7 @@ describe Scheduler::UserCleanupScheduler do
|
|||
before do
|
||||
# Need to update the already-existing users because their initialization overrides confirmation_sent_at
|
||||
new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc)
|
||||
old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 10.days.ago)
|
||||
old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 1.week.ago)
|
||||
confirmed_user.update!(confirmed_at: 1.day.ago)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue