unallow_domain_service_spec.rb 2.4 KB

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