From 41c1aaf54d6b85738ffaad785eb7e4e3fe4ac5bf Mon Sep 17 00:00:00 2001 From: KMY Date: Sat, 7 Oct 2023 13:07:35 +0900 Subject: [PATCH] =?UTF-8?q?Add:=20=E3=83=97=E3=83=AD=E3=82=AD=E3=82=B7?= =?UTF-8?q?=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E3=82=92=E5=8B=95?= =?UTF-8?q?=E7=9A=84=E3=81=AB=E8=AD=98=E5=88=A5=E3=81=99=E3=82=8B=E7=B0=A1?= =?UTF-8?q?=E6=98=93=E7=9A=84=E3=81=AA=E4=BB=95=E7=B5=84=E3=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lib/activitypub/activity/follow.rb | 22 +++++++- spec/lib/activitypub/activity/follow_spec.rb | 51 ++++++++++++++++++- .../process_account_service_spec.rb | 1 + 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb index a586298eec..f19bd1f7c8 100644 --- a/app/lib/activitypub/activity/follow.rb +++ b/app/lib/activitypub/activity/follow.rb @@ -30,7 +30,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity follow_request = FollowRequest.create!(account: @account, target_account: target_account, uri: @json['id']) - if target_account.locked? || @account.silenced? || block_straight_follow? || (@account.bot? && target_account.user&.setting_lock_follow_from_bot) + if target_account.locked? || @account.silenced? || block_straight_follow? || ((@account.bot? || proxy_account?) && target_account.user&.setting_lock_follow_from_bot) LocalNotificationWorker.perform_async(target_account.id, follow_request.id, 'FollowRequest', 'follow_request') else AuthorizeFollowService.new.call(@account, target_account) @@ -50,4 +50,24 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity def block_new_follow? @block_new_follow ||= DomainBlock.reject_new_follow?(@account.domain) end + + def proxy_account? + (@account.username.downcase.include?('proxy') || + @account.username.downcase.include?('followbot') || + @account.display_name&.downcase&.include?('proxy') || + @account.display_name&.include?('プロキシ') || + @account.note&.downcase&.include?('proxy') || + @account.note&.include?('プロキシ')) && proxyable_software? + end + + def proxyable_software? + info = instance_info + return false if info.nil? + + %w(misskey calckey firefish meisskey cherrypick).include?(info.software) + end + + def instance_info + @instance_info ||= InstanceInfo.find_by(domain: @account.domain) + end end diff --git a/spec/lib/activitypub/activity/follow_spec.rb b/spec/lib/activitypub/activity/follow_spec.rb index 890ebe2750..2626c036a4 100644 --- a/spec/lib/activitypub/activity/follow_spec.rb +++ b/spec/lib/activitypub/activity/follow_spec.rb @@ -4,7 +4,8 @@ require 'rails_helper' RSpec.describe ActivityPub::Activity::Follow do let(:actor_type) { 'Person' } - let(:sender) { Fabricate(:account, domain: 'example.com', inbox_url: 'https://example.com/inbox', actor_type: actor_type) } + let(:note) { '' } + let(:sender) { Fabricate(:account, domain: 'example.com', inbox_url: 'https://example.com/inbox', actor_type: actor_type, note: note) } let(:recipient) { Fabricate(:account) } let(:json) do @@ -103,6 +104,54 @@ RSpec.describe ActivityPub::Activity::Follow do end end + context 'when unlocked misskey proxy account but locked from bot' do + let(:note) { 'i am proxy.' } + + before do + Fabricate(:instance_info, domain: 'example.com', software: 'misskey') + recipient.user.settings['lock_follow_from_bot'] = true + recipient.user.save! + subject.perform + end + + it 'does not create a follow from sender to recipient' do + expect(sender.following?(recipient)).to be false + end + + it 'creates a follow request' do + expect(sender.requested?(recipient)).to be true + expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo' + end + end + + context 'when unlocked mastodon proxy account but locked from bot' do + let(:note) { 'i am proxy.' } + + before do + Fabricate(:instance_info, domain: 'example.com', software: 'mastodon') + recipient.user.settings['lock_follow_from_bot'] = true + recipient.user.save! + subject.perform + end + + it 'does not create a follow from sender to recipient' do + expect(sender.following?(recipient)).to be true + end + end + + context 'when unlocked misskey normal account but locked from bot' do + before do + Fabricate(:instance_info, domain: 'example.com', software: 'misskey') + recipient.user.settings['lock_follow_from_bot'] = true + recipient.user.save! + subject.perform + end + + it 'does not create a follow from sender to recipient' do + expect(sender.following?(recipient)).to be true + end + end + context 'when domain block reject_straight_follow' do before do Fabricate(:domain_block, domain: 'example.com', reject_straight_follow: true) diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index b23aa1cea3..fe2c7cda99 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -21,6 +21,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do searchableBy: searchable_by, indexable: indexable, summary: sender_bio, + actor_type: 'Person', }.with_indifferent_access end