collections_controller_spec.rb 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::CollectionsController do
  4. let!(:account) { Fabricate(:account) }
  5. let!(:private_pinned) { Fabricate(:status, account: account, text: 'secret private stuff', visibility: :private) }
  6. let(:remote_account) { nil }
  7. before do
  8. allow(controller).to receive(:signed_request_actor).and_return(remote_account)
  9. Fabricate(:status_pin, account: account)
  10. Fabricate(:status_pin, account: account)
  11. Fabricate(:status_pin, account: account, status: private_pinned)
  12. Fabricate(:status, account: account, visibility: :private)
  13. end
  14. describe 'GET #show' do
  15. subject(:response) { get :show, params: { id: id, account_username: account.username } }
  16. context 'when id is "featured"' do
  17. let(:id) { 'featured' }
  18. context 'without signature' do
  19. let(:remote_account) { nil }
  20. it 'returns http success and correct media type and correct items' do
  21. expect(response)
  22. .to have_http_status(200)
  23. .and have_cacheable_headers
  24. expect(response.media_type).to eq 'application/activity+json'
  25. expect(response.parsed_body[:orderedItems])
  26. .to be_an(Array)
  27. .and have_attributes(size: 3)
  28. .and include(ActivityPub::TagManager.instance.uri_for(private_pinned))
  29. .and not_include(private_pinned.text)
  30. end
  31. context 'when account is permanently suspended' do
  32. before do
  33. account.suspend!
  34. account.deletion_request.destroy
  35. end
  36. it 'returns http gone' do
  37. expect(response).to have_http_status(410)
  38. end
  39. end
  40. context 'when account is temporarily suspended' do
  41. before do
  42. account.suspend!
  43. end
  44. it 'returns http forbidden' do
  45. expect(response).to have_http_status(403)
  46. end
  47. end
  48. end
  49. context 'with signature' do
  50. let(:remote_account) { Fabricate(:account, domain: 'example.com') }
  51. context 'when getting a featured resource' do
  52. it 'returns http success and correct media type and expected items' do
  53. expect(response)
  54. .to have_http_status(200)
  55. .and have_cacheable_headers
  56. expect(response.media_type).to eq 'application/activity+json'
  57. expect(response.parsed_body[:orderedItems])
  58. .to be_an(Array)
  59. .and have_attributes(size: 3)
  60. .and include(ActivityPub::TagManager.instance.uri_for(private_pinned))
  61. .and not_include(private_pinned.text)
  62. end
  63. end
  64. context 'with authorized fetch mode' do
  65. before do
  66. allow(controller).to receive(:authorized_fetch_mode?).and_return(true)
  67. end
  68. context 'when signed request account is blocked' do
  69. before do
  70. account.block!(remote_account)
  71. end
  72. it 'returns http success and correct media type and cache headers and empty items' do
  73. expect(response).to have_http_status(200)
  74. expect(response.media_type).to eq 'application/activity+json'
  75. expect(response.headers['Cache-Control']).to include 'private'
  76. expect(response.parsed_body[:orderedItems])
  77. .to be_an(Array)
  78. .and be_empty
  79. end
  80. end
  81. context 'when signed request account is domain blocked' do
  82. before do
  83. account.block_domain!(remote_account.domain)
  84. end
  85. it 'returns http success and correct media type and cache headers and empty items' do
  86. expect(response).to have_http_status(200)
  87. expect(response.media_type).to eq 'application/activity+json'
  88. expect(response.headers['Cache-Control']).to include 'private'
  89. expect(response.parsed_body[:orderedItems])
  90. .to be_an(Array)
  91. .and be_empty
  92. end
  93. end
  94. end
  95. end
  96. end
  97. context 'when id is not "featured"' do
  98. let(:id) { 'hoge' }
  99. it 'returns http not found' do
  100. expect(response).to have_http_status(404)
  101. end
  102. end
  103. end
  104. end