Merge remote-tracking branch 'parent/main' into upstream-20240128
This commit is contained in:
commit
bd5b417d2b
107 changed files with 795 additions and 246 deletions
|
@ -1,68 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::EmailDomainBlocksController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
sign_in Fabricate(:admin_user), scope: :user
|
||||
end
|
||||
|
||||
describe 'GET #index' do
|
||||
around do |example|
|
||||
default_per_page = EmailDomainBlock.default_per_page
|
||||
EmailDomainBlock.paginates_per 2
|
||||
example.run
|
||||
EmailDomainBlock.paginates_per default_per_page
|
||||
end
|
||||
|
||||
it 'returns http success' do
|
||||
2.times { Fabricate(:email_domain_block) }
|
||||
Fabricate(:email_domain_block, allow_with_approval: true)
|
||||
get :index, params: { page: 2 }
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET #new' do
|
||||
it 'returns http success' do
|
||||
get :new
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #create' do
|
||||
context 'when resolve button is pressed' do
|
||||
before do
|
||||
resolver = instance_double(Resolv::DNS)
|
||||
|
||||
allow(resolver).to receive(:getresources)
|
||||
.with('example.com', Resolv::DNS::Resource::IN::MX)
|
||||
.and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::A).and_return([])
|
||||
allow(resolver).to receive(:getresources).with('example.com', Resolv::DNS::Resource::IN::AAAA).and_return([])
|
||||
allow(resolver).to receive(:timeouts=).and_return(nil)
|
||||
allow(Resolv::DNS).to receive(:open).and_yield(resolver)
|
||||
|
||||
post :create, params: { email_domain_block: { domain: 'example.com' } }
|
||||
end
|
||||
|
||||
it 'renders new template' do
|
||||
expect(response).to render_template(:new)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when save button is pressed' do
|
||||
before do
|
||||
post :create, params: { email_domain_block: { domain: 'example.com' }, save: '' }
|
||||
end
|
||||
|
||||
it 'blocks the domain and redirects to email domain blocks' do
|
||||
expect(EmailDomainBlock.find_by(domain: 'example.com')).to_not be_nil
|
||||
|
||||
expect(response).to redirect_to(admin_email_domain_blocks_path)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -60,16 +60,12 @@ RSpec.describe Request do
|
|||
expect(a_request(:get, 'http://example.com')).to have_been_made.once
|
||||
end
|
||||
|
||||
it 'sets headers' do
|
||||
expect { |block| subject.perform(&block) }.to yield_control
|
||||
expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
|
||||
end
|
||||
|
||||
it 'closes underlying connection' do
|
||||
it 'makes a request with expected headers, yields, and closes the underlying connection' do
|
||||
allow(subject.send(:http_client)).to receive(:close)
|
||||
|
||||
expect { |block| subject.perform(&block) }.to yield_control
|
||||
|
||||
expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made
|
||||
expect(subject.send(:http_client)).to have_received(:close)
|
||||
end
|
||||
|
||||
|
@ -80,6 +76,29 @@ RSpec.describe Request do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with a redirect and HTTP signatures' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
before do
|
||||
stub_request(:get, 'http://example.com').to_return(status: 301, headers: { Location: 'http://redirected.example.com/foo' })
|
||||
stub_request(:get, 'http://redirected.example.com/foo').to_return(body: 'lorem ipsum')
|
||||
end
|
||||
|
||||
it 'makes a request with expected headers and follows redirects' do
|
||||
expect { |block| subject.on_behalf_of(account).perform(&block) }.to yield_control
|
||||
|
||||
# request.headers includes the `Signature` sent for the first request
|
||||
expect(a_request(:get, 'http://example.com').with(headers: subject.headers)).to have_been_made.once
|
||||
|
||||
# request.headers includes the `Signature`, but it has changed
|
||||
expect(a_request(:get, 'http://redirected.example.com/foo').with(headers: subject.headers.merge({ 'Host' => 'redirected.example.com' }))).to_not have_been_made
|
||||
|
||||
# `with(headers: )` matching tests for inclusion, so strip `Signature`
|
||||
# This doesn't actually test that there is a signature, but it tests that the original signature is not passed
|
||||
expect(a_request(:get, 'http://redirected.example.com/foo').with(headers: subject.headers.without('Signature').merge({ 'Host' => 'redirected.example.com' }))).to have_been_made.once
|
||||
end
|
||||
end
|
||||
|
||||
context 'with private host' do
|
||||
around do |example|
|
||||
WebMock.disable!
|
||||
|
|
|
@ -59,7 +59,7 @@ RSpec.describe 'Instances' do
|
|||
description_limit: MediaAttachment::MAX_DESCRIPTION_LENGTH
|
||||
),
|
||||
polls: include(
|
||||
max_options: PollValidator::MAX_OPTIONS
|
||||
max_options: PollOptionsValidator::MAX_OPTIONS
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
|
@ -153,7 +153,7 @@ RSpec.describe 'Notifications' do
|
|||
it 'returns a notification group covering all notifications' do
|
||||
subject
|
||||
|
||||
notification_ids = user.account.notifications.reload.pluck(:id)
|
||||
notification_ids = user.account.notifications.order(id: :asc).pluck(:id)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
|
@ -175,7 +175,7 @@ RSpec.describe 'Notifications' do
|
|||
it 'returns a notification group covering all notifications' do
|
||||
subject
|
||||
|
||||
notification_ids = user.account.notifications.reload.pluck(:id)
|
||||
notification_ids = user.account.notifications.order(id: :asc).pluck(:id)
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
|
|
|
@ -7,31 +7,69 @@ RSpec.describe PrecomputeFeedService do
|
|||
|
||||
describe 'call' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let!(:list) { Fabricate(:list, account: account, exclusive: false) }
|
||||
|
||||
it 'fills a user timeline with statuses' do
|
||||
account = Fabricate(:account)
|
||||
status = Fabricate(:status, account: account)
|
||||
context 'when no eligible status exist' do
|
||||
it 'raises no error and results in an empty timeline' do
|
||||
expect { subject.call(account) }.to_not raise_error
|
||||
|
||||
subject.call(account)
|
||||
|
||||
expect(redis.zscore(FeedManager.instance.key(:home, account.id), status.id)).to be_within(0.1).of(status.id.to_f)
|
||||
expect(redis.zcard(FeedManager.instance.key(:home, account.id))).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not raise an error even if it could not find any status' do
|
||||
account = Fabricate(:account)
|
||||
expect { subject.call(account) }.to_not raise_error
|
||||
end
|
||||
context 'with eligible statuses' do
|
||||
let(:muted_account) { Fabricate(:account) }
|
||||
let!(:followed_account) { Fabricate(:account) }
|
||||
let!(:requested_account) { Fabricate(:account) }
|
||||
let!(:own_status) { Fabricate(:status, account: account) }
|
||||
let!(:followed_status) { Fabricate(:status, account: followed_account) }
|
||||
let!(:unreadable_dm_from_followed) { Fabricate(:status, account: followed_account, visibility: :direct) }
|
||||
let!(:requested_status) { Fabricate(:status, account: requested_account) }
|
||||
let!(:muted_status) { Fabricate(:status, account: muted_account) }
|
||||
let!(:muted_reblog) { Fabricate(:status, account: followed_account, reblog: muted_status) }
|
||||
let!(:known_reply) { Fabricate(:status, account: followed_account, in_reply_to_id: own_status.id) }
|
||||
let!(:unknown_reply) { Fabricate(:status, account: followed_account, in_reply_to_id: requested_status.id) }
|
||||
|
||||
it 'filters statuses' do
|
||||
account = Fabricate(:account)
|
||||
muted_account = Fabricate(:account)
|
||||
Fabricate(:mute, account: account, target_account: muted_account)
|
||||
reblog = Fabricate(:status, account: muted_account)
|
||||
Fabricate(:status, account: account, reblog: reblog)
|
||||
before do
|
||||
account.follow!(followed_account)
|
||||
account.request_follow!(requested_account)
|
||||
account.mute!(muted_account)
|
||||
|
||||
subject.call(account)
|
||||
AddAccountsToListService.new.call(list, [followed_account])
|
||||
end
|
||||
|
||||
expect(redis.zscore(FeedManager.instance.key(:home, account.id), reblog.id)).to be_nil
|
||||
it "fills a user's home and list timelines with the expected posts" do
|
||||
subject.call(account)
|
||||
|
||||
home_timeline_ids = redis.zrevrangebyscore(FeedManager.instance.key(:home, account.id), '(+inf', '(-inf', limit: [0, 30], with_scores: true).map { |id| id.first.to_i }
|
||||
list_timeline_ids = redis.zrevrangebyscore(FeedManager.instance.key(:list, list.id), '(+inf', '(-inf', limit: [0, 30], with_scores: true).map { |id| id.first.to_i }
|
||||
|
||||
expect(home_timeline_ids).to include(
|
||||
own_status.id,
|
||||
followed_status.id,
|
||||
known_reply.id
|
||||
)
|
||||
|
||||
expect(list_timeline_ids).to include(
|
||||
followed_status.id
|
||||
)
|
||||
|
||||
expect(home_timeline_ids).to_not include(
|
||||
requested_status.id,
|
||||
unknown_reply.id,
|
||||
unreadable_dm_from_followed.id,
|
||||
muted_status.id,
|
||||
muted_reblog.id
|
||||
)
|
||||
|
||||
expect(list_timeline_ids).to_not include(
|
||||
requested_status.id,
|
||||
unknown_reply.id,
|
||||
unreadable_dm_from_followed.id,
|
||||
muted_status.id,
|
||||
muted_reblog.id
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,25 @@ module DomainHelpers
|
|||
.and_yield(resolver)
|
||||
end
|
||||
|
||||
def configure_dns(domain:, results:)
|
||||
resolver = instance_double(Resolv::DNS, :timeouts= => nil)
|
||||
|
||||
allow(resolver).to receive(:getresources)
|
||||
.with(domain, Resolv::DNS::Resource::IN::MX)
|
||||
.and_return(results)
|
||||
allow(resolver)
|
||||
.to receive(:getresources)
|
||||
.with(domain, Resolv::DNS::Resource::IN::A)
|
||||
.and_return(results)
|
||||
allow(resolver)
|
||||
.to receive(:getresources)
|
||||
.with(domain, Resolv::DNS::Resource::IN::AAAA)
|
||||
.and_return(results)
|
||||
allow(Resolv::DNS)
|
||||
.to receive(:open)
|
||||
.and_yield(resolver)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def double_mx(exchange)
|
||||
|
|
|
@ -7,6 +7,43 @@ RSpec.describe 'Admin::EmailDomainBlocks' do
|
|||
|
||||
before { sign_in current_user }
|
||||
|
||||
describe 'Managing email domain blocks' do
|
||||
before { configure_dns(domain: 'example.com', results: []) }
|
||||
|
||||
let!(:email_domain_block) { Fabricate :email_domain_block }
|
||||
|
||||
it 'views and creates new blocks' do
|
||||
visit admin_email_domain_blocks_path
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.email_domain_blocks.title'))
|
||||
.and have_content(email_domain_block.domain)
|
||||
|
||||
click_on I18n.t('admin.email_domain_blocks.add_new')
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.email_domain_blocks.new.title'))
|
||||
|
||||
fill_in I18n.t('admin.email_domain_blocks.domain'), with: 'example.com'
|
||||
expect { submit_resolve }
|
||||
.to_not change(EmailDomainBlock, :count)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.email_domain_blocks.new.title'))
|
||||
|
||||
expect { submit_create }
|
||||
.to change(EmailDomainBlock.where(domain: 'example.com'), :count).by(1)
|
||||
expect(page)
|
||||
.to have_content(I18n.t('admin.email_domain_blocks.title'))
|
||||
.and have_content(I18n.t('admin.email_domain_blocks.created_msg'))
|
||||
end
|
||||
|
||||
def submit_resolve
|
||||
click_on I18n.t('admin.email_domain_blocks.new.resolve')
|
||||
end
|
||||
|
||||
def submit_create
|
||||
click_on I18n.t('admin.email_domain_blocks.new.create')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Performing batch updates' do
|
||||
before do
|
||||
visit admin_email_domain_blocks_path
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PollValidator do
|
||||
RSpec.describe PollExpirationValidator do
|
||||
describe '#validate' do
|
||||
before do
|
||||
validator.validate(poll)
|
||||
|
@ -14,16 +14,24 @@ RSpec.describe PollValidator do
|
|||
let(:options) { %w(foo bar) }
|
||||
let(:expires_at) { 1.day.from_now }
|
||||
|
||||
it 'have no errors' do
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
context 'when expires is just 5 min ago' do
|
||||
context 'when the poll expires in 5 min from now' do
|
||||
let(:expires_at) { 5.minutes.from_now }
|
||||
|
||||
it 'not calls errors add' do
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the poll expires in the past' do
|
||||
let(:expires_at) { 5.minutes.ago }
|
||||
|
||||
it 'has errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
spec/validators/poll_options_validator_spec.rb
Normal file
45
spec/validators/poll_options_validator_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PollOptionsValidator do
|
||||
describe '#validate' do
|
||||
before do
|
||||
validator.validate(poll)
|
||||
end
|
||||
|
||||
let(:validator) { described_class.new }
|
||||
let(:poll) { instance_double(Poll, options: options, expires_at: expires_at, errors: errors) }
|
||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
||||
let(:options) { %w(foo bar) }
|
||||
let(:expires_at) { 1.day.from_now }
|
||||
|
||||
it 'has no errors' do
|
||||
expect(errors).to_not have_received(:add)
|
||||
end
|
||||
|
||||
context 'when the poll has duplicate options' do
|
||||
let(:options) { %w(foo foo) }
|
||||
|
||||
it 'adds errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the poll has no options' do
|
||||
let(:options) { [] }
|
||||
|
||||
it 'adds errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the poll has too many options' do
|
||||
let(:options) { Array.new(described_class::MAX_OPTIONS + 1) { |i| "option #{i}" } }
|
||||
|
||||
it 'adds errors' do
|
||||
expect(errors).to have_received(:add)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue