unallow_domain_service_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe UnallowDomainService do
  4. subject { described_class.new }
  5. let(:bad_domain) { 'evil.org' }
  6. let!(:bad_account) { Fabricate(:account, username: 'badguy666', domain: bad_domain) }
  7. let!(:bad_status_harassment) { Fabricate(:status, account: bad_account, text: 'You suck') }
  8. let!(:bad_status_mean) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
  9. let!(:bad_attachment) { Fabricate(:media_attachment, account: bad_account, status: bad_status_mean, file: attachment_fixture('attachment.jpg')) }
  10. let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: bad_domain, suspended: true, silenced: true) }
  11. let!(:domain_allow) { Fabricate(:domain_allow, domain: bad_domain) }
  12. context 'with limited federation mode', :inline_jobs do
  13. before do
  14. allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(true)
  15. end
  16. describe '#call' do
  17. it 'makes the domain not allowed and removes accounts from that domain' do
  18. expect { subject.call(domain_allow) }
  19. .to change { bad_domain_allowed }.from(true).to(false)
  20. .and change { bad_domain_account_exists }.from(true).to(false)
  21. expect { already_banned_account.reload }.to raise_error(ActiveRecord::RecordNotFound)
  22. expect { bad_status_harassment.reload }.to raise_error(ActiveRecord::RecordNotFound)
  23. expect { bad_status_mean.reload }.to raise_error(ActiveRecord::RecordNotFound)
  24. expect { bad_attachment.reload }.to raise_error(ActiveRecord::RecordNotFound)
  25. end
  26. end
  27. end
  28. context 'without limited federation mode' do
  29. before do
  30. allow(Rails.configuration.x).to receive(:limited_federation_mode).and_return(false)
  31. end
  32. describe '#call' do
  33. it 'makes the domain not allowed but preserves accounts from the domain' do
  34. expect { subject.call(domain_allow) }
  35. .to change { bad_domain_allowed }.from(true).to(false)
  36. .and not_change { bad_domain_account_exists }.from(true)
  37. expect { bad_status_harassment.reload }.to_not raise_error
  38. expect { bad_status_mean.reload }.to_not raise_error
  39. expect { bad_attachment.reload }.to_not raise_error
  40. end
  41. end
  42. end
  43. def bad_domain_allowed
  44. DomainAllow.allowed?(bad_domain)
  45. end
  46. def bad_domain_account_exists
  47. Account.exists?(domain: bad_domain)
  48. end
  49. end