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.

196 lines
6.3 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ActivityPub::RepliesController, type: :controller do
  4. let(:status) { Fabricate(:status, visibility: parent_visibility) }
  5. let(:remote_account) { nil }
  6. before do
  7. allow(controller).to receive(:signed_request_account).and_return(remote_account)
  8. Fabricate(:status, thread: status, visibility: :public)
  9. Fabricate(:status, thread: status, visibility: :public)
  10. Fabricate(:status, thread: status, visibility: :private)
  11. Fabricate(:status, account: status.account, thread: status, visibility: :public)
  12. Fabricate(:status, account: status.account, thread: status, visibility: :private)
  13. end
  14. describe 'GET #index' do
  15. context 'with no signature' do
  16. before do
  17. get :index, params: { account_username: status.account.username, status_id: status.id }
  18. end
  19. context 'when status is public' do
  20. let(:parent_visibility) { :public }
  21. it 'returns http success' do
  22. expect(response).to have_http_status(200)
  23. end
  24. it 'returns application/activity+json' do
  25. expect(response.content_type).to eq 'application/activity+json'
  26. end
  27. it 'returns public Cache-Control header' do
  28. expect(response.headers['Cache-Control']).to include 'public'
  29. end
  30. it 'returns items with account\'s own replies' do
  31. json = body_as_json
  32. expect(json[:first]).to be_a Hash
  33. expect(json[:first][:items]).to be_an Array
  34. expect(json[:first][:items].size).to eq 1
  35. expect(json[:first][:items].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true
  36. end
  37. end
  38. context 'when status is private' do
  39. let(:parent_visibility) { :private }
  40. it 'returns http not found' do
  41. expect(response).to have_http_status(404)
  42. end
  43. end
  44. context 'when status is direct' do
  45. let(:parent_visibility) { :direct }
  46. it 'returns http not found' do
  47. expect(response).to have_http_status(404)
  48. end
  49. end
  50. end
  51. context 'with signature' do
  52. let(:remote_account) { Fabricate(:account, domain: 'example.com') }
  53. let(:only_other_accounts) { nil }
  54. context do
  55. before do
  56. get :index, params: { account_username: status.account.username, status_id: status.id, only_other_accounts: only_other_accounts }
  57. end
  58. context 'when status is public' do
  59. let(:parent_visibility) { :public }
  60. it 'returns http success' do
  61. expect(response).to have_http_status(200)
  62. end
  63. it 'returns application/activity+json' do
  64. expect(response.content_type).to eq 'application/activity+json'
  65. end
  66. it 'returns public Cache-Control header' do
  67. expect(response.headers['Cache-Control']).to include 'public'
  68. end
  69. context 'without only_other_accounts' do
  70. it 'returns items with account\'s own replies' do
  71. json = body_as_json
  72. expect(json[:first]).to be_a Hash
  73. expect(json[:first][:items]).to be_an Array
  74. expect(json[:first][:items].size).to eq 1
  75. expect(json[:first][:items].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true
  76. end
  77. end
  78. context 'with only_other_accounts' do
  79. let(:only_other_accounts) { 'true' }
  80. it 'returns items with other public or unlisted replies' do
  81. json = body_as_json
  82. expect(json[:first]).to be_a Hash
  83. expect(json[:first][:items]).to be_an Array
  84. expect(json[:first][:items].size).to eq 2
  85. expect(json[:first][:items].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true
  86. end
  87. end
  88. end
  89. context 'when status is private' do
  90. let(:parent_visibility) { :private }
  91. it 'returns http not found' do
  92. expect(response).to have_http_status(404)
  93. end
  94. end
  95. context 'when status is direct' do
  96. let(:parent_visibility) { :direct }
  97. it 'returns http not found' do
  98. expect(response).to have_http_status(404)
  99. end
  100. end
  101. end
  102. context 'when signed request account is blocked' do
  103. before do
  104. status.account.block!(remote_account)
  105. get :index, params: { account_username: status.account.username, status_id: status.id }
  106. end
  107. context 'when status is public' do
  108. let(:parent_visibility) { :public }
  109. it 'returns http not found' do
  110. expect(response).to have_http_status(404)
  111. end
  112. end
  113. context 'when status is private' do
  114. let(:parent_visibility) { :private }
  115. it 'returns http not found' do
  116. expect(response).to have_http_status(404)
  117. end
  118. end
  119. context 'when status is direct' do
  120. let(:parent_visibility) { :direct }
  121. it 'returns http not found' do
  122. expect(response).to have_http_status(404)
  123. end
  124. end
  125. end
  126. context 'when signed request account is domain blocked' do
  127. before do
  128. status.account.block_domain!(remote_account.domain)
  129. get :index, params: { account_username: status.account.username, status_id: status.id }
  130. end
  131. context 'when status is public' do
  132. let(:parent_visibility) { :public }
  133. it 'returns http not found' do
  134. expect(response).to have_http_status(404)
  135. end
  136. end
  137. context 'when status is private' do
  138. let(:parent_visibility) { :private }
  139. it 'returns http not found' do
  140. expect(response).to have_http_status(404)
  141. end
  142. end
  143. context 'when status is direct' do
  144. let(:parent_visibility) { :direct }
  145. it 'returns http not found' do
  146. expect(response).to have_http_status(404)
  147. end
  148. end
  149. end
  150. end
  151. end
  152. end