2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-29 19:42:08 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
describe 'Accounts show response' do
|
2022-01-28 00:46:42 +01:00
|
|
|
let(:account) { Fabricate(:account) }
|
2016-02-29 19:42:08 +01:00
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
context 'with an unapproved account' do
|
2023-10-17 13:32:10 +02:00
|
|
|
before { account.user.update(approved: false) }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns http not found' do
|
2023-11-09 17:21:11 +01:00
|
|
|
%w(html json rss).each do |format|
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), as: format
|
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(404)
|
|
|
|
end
|
2016-02-29 19:42:08 +01:00
|
|
|
end
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2016-02-29 19:42:08 +01:00
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
context 'with a permanently suspended account' do
|
2023-10-17 13:32:10 +02:00
|
|
|
before do
|
|
|
|
account.suspend!
|
|
|
|
account.deletion_request.destroy
|
2020-11-08 00:28:39 +01:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns http gone' do
|
2023-11-09 17:21:11 +01:00
|
|
|
%w(html json rss).each do |format|
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), as: format
|
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(410)
|
|
|
|
end
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
context 'with a temporarily suspended account' do
|
2023-10-17 13:32:10 +02:00
|
|
|
before { account.suspend! }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns appropriate http response code' do
|
2023-11-09 17:21:11 +01:00
|
|
|
{ html: 403, json: 200, rss: 403 }.each do |format, code|
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), as: format
|
2017-05-23 02:53:01 +02:00
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(code)
|
|
|
|
end
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
|
|
|
end
|
2017-05-23 02:53:01 +02:00
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
describe 'GET to short username paths' do
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with existing statuses' do
|
|
|
|
let!(:status) { Fabricate(:status, account: account) }
|
|
|
|
let!(:status_reply) { Fabricate(:status, account: account, thread: Fabricate(:status)) }
|
|
|
|
let!(:status_self_reply) { Fabricate(:status, account: account, thread: status) }
|
|
|
|
let!(:status_media) { Fabricate(:status, account: account) }
|
|
|
|
let!(:status_pinned) { Fabricate(:status, account: account) }
|
|
|
|
let!(:status_private) { Fabricate(:status, account: account, visibility: :private) }
|
|
|
|
let!(:status_direct) { Fabricate(:status, account: account, visibility: :direct) }
|
|
|
|
let!(:status_reblog) { Fabricate(:status, account: account, reblog: Fabricate(:status)) }
|
2017-11-09 14:36:17 +01:00
|
|
|
|
2020-05-03 22:19:24 +02:00
|
|
|
before do
|
2023-10-17 13:32:10 +02:00
|
|
|
status_media.media_attachments << Fabricate(:media_attachment, account: account, type: :image)
|
|
|
|
account.pinned_statuses << status_pinned
|
|
|
|
account.pinned_statuses << status_private
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with HTML' do
|
|
|
|
let(:format) { 'html' }
|
2020-11-08 00:28:39 +01:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
shared_examples 'common HTML response' do
|
|
|
|
it 'returns a standard HTML response', :aggregate_failures do
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and render_template(:show)
|
2020-11-08 00:28:39 +01:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(response.headers['Link'].to_s).to include ActivityPub::TagManager.instance.uri_for(account)
|
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with a normal account in an HTML request' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), as: format
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it_behaves_like 'common HTML response'
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with replies' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_with_replies_path(username: account.username), as: format
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it_behaves_like 'common HTML response'
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with media' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_media_path(username: account.username), as: format
|
2017-11-09 14:36:17 +01:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it_behaves_like 'common HTML response'
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with tag' do
|
|
|
|
let(:tag) { Fabricate(:tag) }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
let!(:status_tag) { Fabricate(:status, account: account) }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
before do
|
|
|
|
status_tag.tags << tag
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_tag_path(username: account.username, tag: tag), as: format
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it_behaves_like 'common HTML response'
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with JSON' do
|
|
|
|
let(:authorized_fetch_mode) { false }
|
2023-11-30 15:28:05 +01:00
|
|
|
let(:headers) { { 'ACCEPT' => 'application/json' } }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
around do |example|
|
|
|
|
ClimateControl.modify AUTHORIZED_FETCH: authorized_fetch_mode.to_s do
|
|
|
|
example.run
|
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with a normal account in a JSON request' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), headers: headers
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2017-05-23 02:53:01 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns a JSON version of the account', :aggregate_failures do
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_attributes(
|
|
|
|
media_type: eq('application/activity+json')
|
|
|
|
)
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(body_as_json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
|
2017-11-09 14:36:17 +01:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
2016-09-08 00:33:07 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with authorized fetch mode' do
|
|
|
|
let(:authorized_fetch_mode) { true }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns http unauthorized' do
|
|
|
|
expect(response).to have_http_status(401)
|
|
|
|
end
|
|
|
|
end
|
2020-11-08 00:28:39 +01:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'when signed in' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
2020-11-08 00:28:39 +01:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), headers: headers.merge({ 'Cookie' => '123' })
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2017-11-09 14:36:17 +01:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns a private JSON version of the account', :aggregate_failures do
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_attributes(
|
|
|
|
media_type: eq('application/activity+json')
|
|
|
|
)
|
2017-11-09 14:36:17 +01:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(response.headers['Cache-Control']).to include 'private'
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(body_as_json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
|
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
2017-11-09 14:36:17 +01:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with signature' do
|
|
|
|
let(:remote_account) { Fabricate(:account, domain: 'example.com') }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username), headers: headers, sign_with: remote_account
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns a JSON version of the account', :aggregate_failures do
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_attributes(
|
|
|
|
media_type: eq('application/activity+json')
|
|
|
|
)
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(body_as_json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
|
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with authorized fetch mode' do
|
|
|
|
let(:authorized_fetch_mode) { true }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'returns a private signature JSON version of the account', :aggregate_failures do
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response)
|
|
|
|
.to have_http_status(200)
|
|
|
|
.and have_attributes(
|
|
|
|
media_type: eq('application/activity+json')
|
|
|
|
)
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(response.headers['Cache-Control']).to include 'private'
|
|
|
|
expect(response.headers['Vary']).to include 'Signature'
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
expect(body_as_json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
|
|
|
|
end
|
|
|
|
end
|
2017-11-09 14:36:17 +01:00
|
|
|
end
|
2017-08-25 18:50:52 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with RSS' do
|
|
|
|
let(:format) { 'rss' }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with a normal account in an RSS request' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_path(username: account.username, format: format)
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'responds with correct statuses', :aggregate_failures do
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(200)
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response.body).to include(status_tag_for(status_media))
|
|
|
|
expect(response.body).to include(status_tag_for(status_self_reply))
|
|
|
|
expect(response.body).to include(status_tag_for(status))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_direct))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_private))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reblog.reblog))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reply))
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with replies' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_with_replies_path(username: account.username, format: format)
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'responds with correct statuses with replies', :aggregate_failures do
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(200)
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response.body).to include(status_tag_for(status_media))
|
|
|
|
expect(response.body).to include(status_tag_for(status_reply))
|
|
|
|
expect(response.body).to include(status_tag_for(status_self_reply))
|
|
|
|
expect(response.body).to include(status_tag_for(status))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_direct))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_private))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reblog.reblog))
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with media' do
|
|
|
|
before do
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_media_path(username: account.username, format: format)
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
it 'responds with correct statuses with media', :aggregate_failures do
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(200)
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response.body).to include(status_tag_for(status_media))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_direct))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_private))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reblog.reblog))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reply))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_self_reply))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status))
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2020-05-03 22:19:24 +02:00
|
|
|
end
|
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
context 'with tag' do
|
|
|
|
let(:tag) { Fabricate(:tag) }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
let!(:status_tag) { Fabricate(:status, account: account) }
|
2020-05-03 22:19:24 +02:00
|
|
|
|
2023-10-17 13:32:10 +02:00
|
|
|
before do
|
|
|
|
status_tag.tags << tag
|
2023-11-30 15:28:05 +01:00
|
|
|
get short_account_tag_path(username: account.username, tag: tag, format: format)
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2017-11-09 14:36:17 +01:00
|
|
|
|
2023-11-09 17:21:11 +01:00
|
|
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
2023-10-17 13:32:10 +02:00
|
|
|
|
|
|
|
it 'responds with correct statuses with a tag', :aggregate_failures do
|
2023-11-09 17:21:11 +01:00
|
|
|
expect(response).to have_http_status(200)
|
2023-11-30 15:28:05 +01:00
|
|
|
expect(response.body).to include(status_tag_for(status_tag))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_direct))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_media))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_private))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reblog.reblog))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_reply))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status_self_reply))
|
|
|
|
expect(response.body).to_not include(status_tag_for(status))
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2017-11-09 14:36:17 +01:00
|
|
|
end
|
2016-09-08 00:33:07 +02:00
|
|
|
end
|
2016-02-29 19:42:08 +01:00
|
|
|
end
|
|
|
|
end
|
2023-10-17 13:32:10 +02:00
|
|
|
|
2023-11-30 15:28:05 +01:00
|
|
|
def status_tag_for(status)
|
|
|
|
ActivityPub::TagManager.instance.url_for(status)
|
2023-10-17 13:32:10 +02:00
|
|
|
end
|
2016-02-29 19:42:08 +01:00
|
|
|
end
|