From a0843948aa8593948f4d5ad6d42f0e412246a109 Mon Sep 17 00:00:00 2001 From: KMY Date: Tue, 22 Aug 2023 13:02:45 +0900 Subject: [PATCH] Add antenna/list privacy test --- .../fabricators/antenna_account_fabricator.rb | 5 + spec/fabricators/circle_account_fabricator.rb | 3 + spec/fabricators/circle_fabricator.rb | 6 + .../services/fan_out_on_write_service_spec.rb | 157 +++++++++++++++++- 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 spec/fabricators/antenna_account_fabricator.rb create mode 100644 spec/fabricators/circle_account_fabricator.rb create mode 100644 spec/fabricators/circle_fabricator.rb diff --git a/spec/fabricators/antenna_account_fabricator.rb b/spec/fabricators/antenna_account_fabricator.rb new file mode 100644 index 0000000000..70d4067d20 --- /dev/null +++ b/spec/fabricators/antenna_account_fabricator.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Fabricator(:antenna_account) do + exclude false +end diff --git a/spec/fabricators/circle_account_fabricator.rb b/spec/fabricators/circle_account_fabricator.rb new file mode 100644 index 0000000000..2de537bc31 --- /dev/null +++ b/spec/fabricators/circle_account_fabricator.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +Fabricator(:circle_account) diff --git a/spec/fabricators/circle_fabricator.rb b/spec/fabricators/circle_fabricator.rb new file mode 100644 index 0000000000..874b41fa13 --- /dev/null +++ b/spec/fabricators/circle_fabricator.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +Fabricator(:circle) do + account { Fabricate.build(:account) } + title 'MyString' +end diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index 3b554f9ea3..1c81880432 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -6,15 +6,23 @@ RSpec.describe FanOutOnWriteService, type: :service do subject { described_class.new } let(:last_active_at) { Time.now.utc } - let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') } + let(:searchability) { 'public' } + let(:status) { Fabricate(:status, account: alice, visibility: visibility, searchability: searchability, text: 'Hello @bob #hoge') } let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account } let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account } let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account } + let!(:ohagi) { Fabricate(:user, current_sign_in_at: last_active_at).account } + + let!(:list) { nil } + let!(:empty_list) { nil } + let!(:antenna) { nil } + let!(:empty_antenna) { nil } before do bob.follow!(alice) tom.follow!(alice) + ohagi.follow!(bob) ProcessMentionsService.new.call(status) ProcessHashtagsService.new.call(status) @@ -28,6 +36,26 @@ RSpec.describe FanOutOnWriteService, type: :service do HomeFeed.new(account).get(10).map(&:id) end + def list_feed_of(list) + ListFeed.new(list).get(10).map(&:id) + end + + def antenna_feed_of(antenna) + AntennaFeed.new(antenna).get(10).map(&:id) + end + + def list_with_account(owner, target_account) + list = Fabricate(:list, account: owner) + Fabricate(:list_account, list: list, account: target_account) + list + end + + def antenna_with_account(owner, target_account) + antenna = Fabricate(:antenna, account: owner, any_accounts: false) + Fabricate(:antenna_account, antenna: antenna, account: target_account) + antenna + end + context 'when status is public' do let(:visibility) { 'public' } @@ -49,6 +77,26 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(redis).to have_received(:publish).with('timeline:public', anything) expect(redis).to have_received(:publish).with('timeline:public:local', anything) end + + context 'with list' do + let!(:list) { list_with_account(bob, alice) } + let!(:empty_list) { Fabricate(:list, account: tom) } + + it 'is added to the list feed of list follower' do + expect(list_feed_of(list)).to include status.id + expect(list_feed_of(empty_list)).to_not include status.id + end + end + + context 'with antenna' do + let!(:antenna) { antenna_with_account(bob, alice) } + let!(:empty_antenna) { antenna_with_account(tom, bob) } + + it 'is added to the antenna feed of antenna follower' do + expect(antenna_feed_of(antenna)).to include status.id + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end end context 'when status is limited' do @@ -70,6 +118,26 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything) expect(redis).to_not have_received(:publish).with('timeline:public', anything) end + + context 'with list' do + let!(:list) { list_with_account(bob, alice) } + let!(:empty_list) { list_with_account(tom, alice) } + + it 'is added to the list feed of list follower' do + expect(list_feed_of(list)).to include status.id + expect(list_feed_of(empty_list)).to_not include status.id + end + end + + context 'with antenna' do + let!(:antenna) { antenna_with_account(bob, alice) } + let!(:empty_antenna) { antenna_with_account(tom, alice) } + + it 'is added to the list feed of list follower' do + expect(antenna_feed_of(antenna)).to include status.id + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end end context 'when status is private' do @@ -88,6 +156,73 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything) expect(redis).to_not have_received(:publish).with('timeline:public', anything) end + + context 'with list' do + let!(:list) { list_with_account(bob, alice) } + let!(:empty_list) { list_with_account(ohagi, bob) } + + it 'is added to the list feed of list follower' do + expect(list_feed_of(list)).to include status.id + expect(list_feed_of(empty_list)).to_not include status.id + end + end + + context 'with antenna' do + let!(:antenna) { antenna_with_account(bob, alice) } + let!(:empty_antenna) { antenna_with_account(ohagi, alice) } + + it 'is added to the list feed of list follower' do + expect(antenna_feed_of(antenna)).to include status.id + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end + end + + context 'when status is unlisted' do + let(:visibility) { 'unlisted' } + + it 'is added to the home feed of its author' do + expect(home_feed_of(alice)).to include status.id + end + + it 'is added to the home feed of a follower' do + expect(home_feed_of(bob)).to include status.id + expect(home_feed_of(tom)).to include status.id + end + + it 'is not broadcast publicly' do + expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything) + expect(redis).to_not have_received(:publish).with('timeline:public', anything) + end + + context 'with list' do + let!(:list) { list_with_account(bob, alice) } + let!(:empty_list) { list_with_account(ohagi, bob) } + + it 'is added to the list feed of list follower' do + expect(list_feed_of(list)).to include status.id + expect(list_feed_of(empty_list)).to_not include status.id + end + end + + context 'with antenna' do + let!(:antenna) { antenna_with_account(bob, alice) } + let!(:empty_antenna) { antenna_with_account(ohagi, alice) } + + it 'is added to the list feed of list follower' do + expect(antenna_feed_of(antenna)).to include status.id + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end + + context 'with non-public searchability' do + let(:searchability) { 'direct' } + + it 'hashtag-timeline is not detected' do + expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything) + expect(redis).to_not have_received(:publish).with('timeline:public', anything) + end + end end context 'when status is direct' do @@ -109,5 +244,25 @@ RSpec.describe FanOutOnWriteService, type: :service do expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything) expect(redis).to_not have_received(:publish).with('timeline:public', anything) end + + context 'with list' do + let!(:list) { list_with_account(bob, alice) } + let!(:empty_list) { list_with_account(ohagi, bob) } + + it 'is added to the list feed of list follower' do + expect(list_feed_of(list)).to_not include status.id + expect(list_feed_of(empty_list)).to_not include status.id + end + end + + context 'with antenna' do + let!(:antenna) { antenna_with_account(bob, alice) } + let!(:empty_antenna) { antenna_with_account(ohagi, alice) } + + it 'is added to the list feed of list follower' do + expect(antenna_feed_of(antenna)).to_not include status.id + expect(antenna_feed_of(empty_antenna)).to_not include status.id + end + end end end