collections_controller_spec.rb 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. context 'when id is "featured"' do
  16. context 'without signature' do
  17. subject(:response) { get :show, params: { id: 'featured', account_username: account.username } }
  18. let(:body) { body_as_json }
  19. let(:remote_account) { nil }
  20. it 'returns http success' do
  21. expect(response).to have_http_status(200)
  22. end
  23. it 'returns application/activity+json' do
  24. expect(response.media_type).to eq 'application/activity+json'
  25. end
  26. it_behaves_like 'cacheable response'
  27. it 'returns orderedItems with pinned statuses' do
  28. expect(body[:orderedItems]).to be_an Array
  29. expect(body[:orderedItems].size).to eq 3
  30. end
  31. it 'includes URI of private pinned status' do
  32. expect(body[:orderedItems]).to include(ActivityPub::TagManager.instance.uri_for(private_pinned))
  33. end
  34. it 'does not include contents of private pinned status' do
  35. expect(response.body).to_not include(private_pinned.text)
  36. end
  37. context 'when account is permanently suspended' do
  38. before do
  39. account.suspend!
  40. account.deletion_request.destroy
  41. end
  42. it 'returns http gone' do
  43. expect(response).to have_http_status(410)
  44. end
  45. end
  46. context 'when account is temporarily suspended' do
  47. before do
  48. account.suspend!
  49. end
  50. it 'returns http forbidden' do
  51. expect(response).to have_http_status(403)
  52. end
  53. end
  54. end
  55. context 'with signature' do
  56. let(:remote_account) { Fabricate(:account, domain: 'example.com') }
  57. context 'when getting a featured resource' do
  58. before do
  59. get :show, params: { id: 'featured', account_username: account.username }
  60. end
  61. it 'returns http success' do
  62. expect(response).to have_http_status(200)
  63. end
  64. it 'returns application/activity+json' do
  65. expect(response.media_type).to eq 'application/activity+json'
  66. end
  67. it_behaves_like 'cacheable response'
  68. it 'returns orderedItems with pinned statuses' do
  69. json = body_as_json
  70. expect(json[:orderedItems]).to be_an Array
  71. expect(json[:orderedItems].size).to eq 3
  72. end
  73. it 'includes URI of private pinned status' do
  74. json = body_as_json
  75. expect(json[:orderedItems]).to include(ActivityPub::TagManager.instance.uri_for(private_pinned))
  76. end
  77. it 'does not include contents of private pinned status' do
  78. expect(response.body).to_not include(private_pinned.text)
  79. end
  80. end
  81. context 'with authorized fetch mode' do
  82. before do
  83. allow(controller).to receive(:authorized_fetch_mode?).and_return(true)
  84. end
  85. context 'when signed request account is blocked' do
  86. before do
  87. account.block!(remote_account)
  88. get :show, params: { id: 'featured', account_username: account.username }
  89. end
  90. it 'returns http success' do
  91. expect(response).to have_http_status(200)
  92. end
  93. it 'returns application/activity+json' do
  94. expect(response.media_type).to eq 'application/activity+json'
  95. end
  96. it 'returns private Cache-Control header' do
  97. expect(response.headers['Cache-Control']).to include 'private'
  98. end
  99. it 'returns empty orderedItems' do
  100. json = body_as_json
  101. expect(json[:orderedItems]).to be_an Array
  102. expect(json[:orderedItems].size).to eq 0
  103. end
  104. end
  105. context 'when signed request account is domain blocked' do
  106. before do
  107. account.block_domain!(remote_account.domain)
  108. get :show, params: { id: 'featured', account_username: account.username }
  109. end
  110. it 'returns http success' do
  111. expect(response).to have_http_status(200)
  112. end
  113. it 'returns application/activity+json' do
  114. expect(response.media_type).to eq 'application/activity+json'
  115. end
  116. it 'returns private Cache-Control header' do
  117. expect(response.headers['Cache-Control']).to include 'private'
  118. end
  119. it 'returns empty orderedItems' do
  120. json = body_as_json
  121. expect(json[:orderedItems]).to be_an Array
  122. expect(json[:orderedItems].size).to eq 0
  123. end
  124. end
  125. end
  126. end
  127. end
  128. context 'when id is not "featured"' do
  129. it 'returns http not found' do
  130. get :show, params: { id: 'hoge', account_username: account.username }
  131. expect(response).to have_http_status(404)
  132. end
  133. end
  134. end
  135. end