1
0

process_mentions_service_spec.rb 4.1 KB

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