From 90f2c7a1e9cc5bd15c446cd57712c675485b6494 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 13 Nov 2024 03:39:58 -0500 Subject: [PATCH] Fix error in CLI EmailDomainBlocks when supplying `--with-dns-records` (#32863) --- lib/mastodon/cli/email_domain_blocks.rb | 2 +- .../lib/mastodon/cli/email_domain_blocks_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/mastodon/cli/email_domain_blocks.rb b/lib/mastodon/cli/email_domain_blocks.rb index 6b9107c8ad..1e90a7c283 100644 --- a/lib/mastodon/cli/email_domain_blocks.rb +++ b/lib/mastodon/cli/email_domain_blocks.rb @@ -46,7 +46,7 @@ module Mastodon::CLI if options[:with_dns_records] Resolv::DNS.open do |dns| dns.timeouts = 5 - other_domains = dns.getresources(@email_domain_block.domain, Resolv::DNS::Resource::IN::MX).to_a + other_domains = dns.getresources(domain, Resolv::DNS::Resource::IN::MX).to_a.map { |e| e.exchange.to_s }.compact_blank end end diff --git a/spec/lib/mastodon/cli/email_domain_blocks_spec.rb b/spec/lib/mastodon/cli/email_domain_blocks_spec.rb index a5fbd23e65..6ce1a7c5f3 100644 --- a/spec/lib/mastodon/cli/email_domain_blocks_spec.rb +++ b/spec/lib/mastodon/cli/email_domain_blocks_spec.rb @@ -63,6 +63,22 @@ RSpec.describe Mastodon::CLI::EmailDomainBlocks do .and(change(EmailDomainBlock, :count).by(1)) end end + + context 'with --with-dns-records true' do + let(:domain) { 'host.example' } + let(:arguments) { [domain] } + let(:options) { { with_dns_records: true } } + + before do + configure_mx(domain: domain, exchange: 'other.host') + end + + it 'adds a new block for parent and children' do + expect { subject } + .to output_results('Added 2') + .and(change(EmailDomainBlock, :count).by(2)) + end + end end describe '#remove' do