summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-08-08 18:02:09 +0200
committerClaire <claire.github-309c@sitedethib.com>2023-08-08 18:02:09 +0200
commit9e3f0170c2df69347cd5384b7750fc83eb4f130f (patch)
tree8695b1da086a62411608304611abdd2f90f92875
parentac7d40b561101084baf4688167d155600eefe9dc (diff)
Fix blocking subdomains of an already-blocked domainfixes/subdomain-block-4.1.6
-rw-r--r--app/controllers/admin/domain_blocks_controller.rb2
-rw-r--r--spec/controllers/admin/domain_blocks_controller_spec.rb20
2 files changed, 21 insertions, 1 deletions
diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb
index 74764640b8f..1fd244d34ae 100644
--- a/app/controllers/admin/domain_blocks_controller.rb
+++ b/app/controllers/admin/domain_blocks_controller.rb
@@ -37,7 +37,7 @@ module Admin
@domain_block.errors.delete(:domain)
render :new
else
- if existing_domain_block.present?
+ if existing_domain_block.present? && existing_domain_block.domain == resource_params[:domain]
@domain_block = existing_domain_block
@domain_block.update(resource_params)
end
diff --git a/spec/controllers/admin/domain_blocks_controller_spec.rb b/spec/controllers/admin/domain_blocks_controller_spec.rb
index f432060d986..ab8ece9c5fb 100644
--- a/spec/controllers/admin/domain_blocks_controller_spec.rb
+++ b/spec/controllers/admin/domain_blocks_controller_spec.rb
@@ -68,6 +68,26 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
expect(flash[:notice]).to eq I18n.t('admin.domain_blocks.created_msg')
expect(response).to redirect_to(admin_instances_path(limited: '1'))
end
+
+ context 'when a block for a parent domain already exists' do
+ subject { post :create, params: { domain_block: { domain: 'subdomain.example.com', severity: child_severity } } }
+
+ let(:parent_severity) { 'silence' }
+ let(:child_severity) { 'suspend' }
+
+ before do
+ Fabricate(:domain_block, domain: 'example.com', severity: parent_severity)
+ end
+
+ it 'does not change the existing block' do
+ expect { subject }.to_not change { DomainBlock.find_by(domain: 'example.com') }
+ end
+
+ it 'creates a domain block with expected severity' do
+ subject
+ expect(DomainBlock.where(domain: 'subdomain.example.com', severity: child_severity)).to exist
+ end
+ end
end
describe 'PUT #update' do