unallow_domain_service_spec.rb 2.3 KB

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