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.

177 lines
6.0 KiB

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