You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.1 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ProcessMentionsService, type: :service do
  4. subject { ProcessMentionsService.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 'resolving a mention to a remote account' do
  27. let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: :public) }
  28. context 'ActivityPub' do
  29. context 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 '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 '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