inboxes_controller_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::InboxesController, type: :controller do
  4. let(:remote_account) { nil }
  5. before do
  6. allow(controller).to receive(:signed_request_actor).and_return(remote_account)
  7. end
  8. describe 'POST #create' do
  9. context 'with signature' do
  10. let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub) }
  11. before do
  12. post :create, body: '{}'
  13. end
  14. it 'returns http accepted' do
  15. expect(response).to have_http_status(202)
  16. end
  17. context 'for a specific account' do
  18. let(:account) { Fabricate(:account) }
  19. subject(:response) { post :create, params: { account_username: account.username }, body: '{}' }
  20. context 'when account is permanently suspended' do
  21. before do
  22. account.suspend!
  23. account.deletion_request.destroy
  24. end
  25. it 'returns http gone' do
  26. expect(response).to have_http_status(410)
  27. end
  28. end
  29. context 'when account is temporarily suspended' do
  30. before do
  31. account.suspend!
  32. end
  33. it 'returns http accepted' do
  34. expect(response).to have_http_status(202)
  35. end
  36. end
  37. end
  38. end
  39. context 'with Collection-Synchronization header' do
  40. let(:remote_account) { Fabricate(:account, followers_url: 'https://example.com/followers', domain: 'example.com', uri: 'https://example.com/actor', protocol: :activitypub) }
  41. let(:synchronization_collection) { remote_account.followers_url }
  42. let(:synchronization_url) { 'https://example.com/followers-for-domain' }
  43. let(:synchronization_hash) { 'somehash' }
  44. let(:synchronization_header) { "collectionId=\"#{synchronization_collection}\", digest=\"#{synchronization_hash}\", url=\"#{synchronization_url}\"" }
  45. before do
  46. allow(ActivityPub::FollowersSynchronizationWorker).to receive(:perform_async).and_return(nil)
  47. allow_any_instance_of(Account).to receive(:local_followers_hash).and_return('somehash')
  48. request.headers['Collection-Synchronization'] = synchronization_header
  49. post :create, body: '{}'
  50. end
  51. context 'with mismatching target collection' do
  52. let(:synchronization_collection) { 'https://example.com/followers2' }
  53. it 'does not start a synchronization job' do
  54. expect(ActivityPub::FollowersSynchronizationWorker).not_to have_received(:perform_async)
  55. end
  56. end
  57. context 'with mismatching domain in partial collection attribute' do
  58. let(:synchronization_url) { 'https://example.org/followers' }
  59. it 'does not start a synchronization job' do
  60. expect(ActivityPub::FollowersSynchronizationWorker).not_to have_received(:perform_async)
  61. end
  62. end
  63. context 'with matching digest' do
  64. it 'does not start a synchronization job' do
  65. expect(ActivityPub::FollowersSynchronizationWorker).not_to have_received(:perform_async)
  66. end
  67. end
  68. context 'with mismatching digest' do
  69. let(:synchronization_hash) { 'wronghash' }
  70. it 'starts a synchronization job' do
  71. expect(ActivityPub::FollowersSynchronizationWorker).to have_received(:perform_async)
  72. end
  73. end
  74. it 'returns http accepted' do
  75. expect(response).to have_http_status(202)
  76. end
  77. end
  78. context 'without signature' do
  79. before do
  80. post :create, body: '{}'
  81. end
  82. it 'returns http not authorized' do
  83. expect(response).to have_http_status(401)
  84. end
  85. end
  86. end
  87. end