1
0

process_mentions_service_spec.rb 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. require 'rails_helper'
  2. RSpec.describe ProcessMentionsService, type: :service do
  3. let(:account) { Fabricate(:account, username: 'alice') }
  4. subject { ProcessMentionsService.new }
  5. context 'when mentions contain blocked accounts' do
  6. let(:non_blocked_account) { Fabricate(:account) }
  7. let(:individually_blocked_account) { Fabricate(:account) }
  8. let(:domain_blocked_account) { Fabricate(:account, domain: 'evil.com') }
  9. let(:status) { Fabricate(:status, account: account, text: "Hello @#{non_blocked_account.acct} @#{individually_blocked_account.acct} @#{domain_blocked_account.acct}", visibility: :public) }
  10. before do
  11. account.block!(individually_blocked_account)
  12. account.domain_blocks.create!(domain: domain_blocked_account.domain)
  13. subject.call(status)
  14. end
  15. it 'creates a mention to the non-blocked account' do
  16. expect(non_blocked_account.mentions.where(status: status).count).to eq 1
  17. end
  18. it 'does not create a mention to the individually blocked account' do
  19. expect(individually_blocked_account.mentions.where(status: status).count).to eq 0
  20. end
  21. it 'does not create a mention to the domain-blocked account' do
  22. expect(domain_blocked_account.mentions.where(status: status).count).to eq 0
  23. end
  24. end
  25. context 'resolving a mention to a remote account' do
  26. let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: :public) }
  27. context 'ActivityPub' do
  28. context do
  29. let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
  30. before do
  31. subject.call(status)
  32. end
  33. it 'creates a mention' do
  34. expect(remote_user.mentions.where(status: status).count).to eq 1
  35. end
  36. end
  37. context 'with an IDN domain' do
  38. let!(:remote_user) { Fabricate(:account, username: 'sneak', protocol: :activitypub, domain: 'xn--hresiar-mxa.ch', inbox_url: 'http://example.com/inbox') }
  39. let!(:status) { Fabricate(:status, account: account, text: "Hello @sneak@hæresiar.ch") }
  40. before do
  41. subject.call(status)
  42. end
  43. it 'creates a mention' do
  44. expect(remote_user.mentions.where(status: status).count).to eq 1
  45. end
  46. end
  47. context 'with an IDN TLD' do
  48. let!(:remote_user) { Fabricate(:account, username: 'foo', protocol: :activitypub, domain: 'xn--y9a3aq.xn--y9a3aq', inbox_url: 'http://example.com/inbox') }
  49. let!(:status) { Fabricate(:status, account: account, text: "Hello @foo@հայ.հայ") }
  50. before do
  51. subject.call(status)
  52. end
  53. it 'creates a mention' do
  54. expect(remote_user.mentions.where(status: status).count).to eq 1
  55. end
  56. end
  57. end
  58. context 'Temporarily-unreachable ActivityPub user' do
  59. let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) }
  60. before do
  61. stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 404)
  62. stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com").to_return(status: 500)
  63. subject.call(status)
  64. end
  65. it 'creates a mention' do
  66. expect(remote_user.mentions.where(status: status).count).to eq 1
  67. end
  68. end
  69. end
  70. end