1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Add have_http_header rspec matcher

This commit is contained in:
Matt Jankowski 2024-07-11 09:30:40 -04:00
parent dfd43869c9
commit 2224f22b4d
29 changed files with 135 additions and 135 deletions

View file

@ -89,9 +89,10 @@ RSpec.describe ActivityPub::CollectionsController do
end
it 'returns http success and correct media type and cache headers and empty items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private')
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to include 'private'
expect(body_as_json[:orderedItems])
.to be_an(Array)
@ -105,9 +106,10 @@ RSpec.describe ActivityPub::CollectionsController do
end
it 'returns http success and correct media type and cache headers and empty items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private')
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to include 'private'
expect(body_as_json[:orderedItems])
.to be_an(Array)

View file

@ -38,8 +38,9 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController do
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
it 'returns http success and cache control and activity json types and correct items' do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to eq 'max-age=0, private'
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'max-age=0, private')
expect(response.media_type).to eq 'application/activity+json'
expect(body[:orderedItems])

View file

@ -62,7 +62,10 @@ RSpec.describe ActivityPub::OutboxesController do
it_behaves_like 'cacheable response'
it 'returns http success and correct media type and vary header and items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_http_header('Vary', 'Signature')
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Vary']).to include 'Signature'
@ -104,10 +107,11 @@ RSpec.describe ActivityPub::OutboxesController do
end
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'max-age=60, private')
expect(response.media_type).to eq 'application/activity+json'
expect(body_as_json[:orderedItems]).to be_an Array
expect(body_as_json[:orderedItems].size).to eq 2
expect(body_as_json[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
@ -121,9 +125,10 @@ RSpec.describe ActivityPub::OutboxesController do
end
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'max-age=60, private')
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems]).to be_an Array
expect(body_as_json[:orderedItems].size).to eq 3
@ -138,10 +143,10 @@ RSpec.describe ActivityPub::OutboxesController do
end
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'max-age=60, private')
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and be_empty
@ -155,10 +160,10 @@ RSpec.describe ActivityPub::OutboxesController do
end
it 'returns http success and correct media type and headers and items' do
expect(response).to have_http_status(200)
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'max-age=60, private')
expect(response.media_type).to eq 'application/activity+json'
expect(response.headers['Cache-Control']).to eq 'max-age=60, private'
expect(body_as_json[:orderedItems])
.to be_an(Array)
.and be_empty

View file

@ -23,7 +23,7 @@ describe Admin::BaseController do
sign_in(Fabricate(:user, role: UserRole.find_by(name: 'Moderator')))
get :success
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response).to have_http_header('Cache-Control', 'private, no-store')
end
it 'renders admin layout as a moderator' do

View file

@ -16,7 +16,7 @@ describe Api::BaseController do
it 'returns private cache control headers by default' do
routes.draw { get 'success' => 'api/base#success' }
get :success
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response).to have_http_header('Cache-Control', 'private, no-store')
end
describe 'forgery protection' do

View file

@ -14,9 +14,10 @@ RSpec.describe Api::OEmbedController do
get :show, params: { url: short_account_status_url(alice, status) }, format: :json
end
it 'returns private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end
end

View file

@ -35,12 +35,10 @@ RSpec.describe Auth::RegistrationsController do
get :edit
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns private cache control header' do
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end
@ -51,16 +49,13 @@ RSpec.describe Auth::RegistrationsController do
before do
request.env['devise.mapping'] = Devise.mappings[:user]
sign_in(user, scope: :user)
put :update
end
it 'returns http success' do
put :update
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
put :update
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
it 'can update the user email' do

View file

@ -23,12 +23,10 @@ describe Filters::StatusesController do
get :index, params: { filter_id: filter }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -22,12 +22,10 @@ describe FiltersController do
get :index
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end
end

View file

@ -22,12 +22,10 @@ describe InvitesController do
get :index
end
it 'returns http success' do
expect(response).to have_http_status(:success)
end
it 'returns private cache control headers' do
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(:success)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -46,14 +46,12 @@ RSpec.describe Oauth::AuthorizationsController do
sign_in user, scope: :user
end
it 'returns http success' do
it 'returns http success and private cache control and authorize body' do
subject
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
subject
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
include_examples 'shows authorize and deny buttons'

View file

@ -22,14 +22,12 @@ describe Oauth::AuthorizedApplicationsController do
sign_in Fabricate(:user), scope: :user
end
it 'returns http success' do
it 'returns http success and private cache control' do
subject
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
subject
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
include_examples 'stores location for user'

View file

@ -14,12 +14,10 @@ describe RelationshipsController do
get :show, params: { page: 2, relationship: 'followed_by' }
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -17,9 +17,10 @@ describe Settings::AliasesController do
get :index
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -18,9 +18,10 @@ describe Settings::ApplicationsController do
get :index
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -14,17 +14,19 @@ describe Settings::DeletesController do
get :show
end
it 'renders confirmation page with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
context 'when suspended' do
let(:user) { Fabricate(:user, account_attributes: { suspended_at: Time.now.utc }) }
it 'returns http forbidden with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(403)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http forbidden and private cache control' do
expect(response)
.to have_http_status(403)
.and have_http_header('Cache-Control', 'private, no-store')
end
end
end

View file

@ -14,9 +14,10 @@ describe Settings::ExportsController do
get :show
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -19,11 +19,13 @@ RSpec.describe Settings::ImportsController do
get :index
end
it 'assigns the expected imports', :aggregate_failures do
expect(response).to have_http_status(200)
expect(assigns(:recent_imports)).to eq [import]
expect(assigns(:recent_imports)).to_not include(other_import)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'assigns expected imports and returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
expect(assigns(:recent_imports))
.to eq([import])
.and not_include(other_import)
end
end

View file

@ -18,8 +18,9 @@ describe Settings::LoginActivitiesController do
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
expect(response.body)
.to include(login_activity.user_agent)
.and include(login_activity.authentication_method)

View file

@ -16,9 +16,10 @@ describe Settings::Migration::RedirectsController do
get :new
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -16,9 +16,10 @@ describe Settings::Preferences::AppearanceController do
get :show
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -16,9 +16,10 @@ describe Settings::Preferences::NotificationsController do
get :show
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -16,9 +16,10 @@ describe Settings::Preferences::OtherController do
get :show
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -17,9 +17,10 @@ RSpec.describe Settings::ProfilesController do
get :show
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -29,9 +29,10 @@ describe Settings::TwoFactorAuthenticationMethodsController do
get :index
end
it 'returns http success with private cache control headers', :aggregate_failures do
expect(response).to have_http_status(200)
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -16,12 +16,10 @@ RSpec.describe StatusesCleanupController do
get :show
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'returns private cache control headers' do
expect(response.headers['Cache-Control']).to include('private, no-store')
it 'returns http success and private cache control' do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private, no-store')
end
end

View file

@ -159,12 +159,11 @@ describe 'Accounts show response' do
it 'returns a private JSON version of the account', :aggregate_failures do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private')
.and have_attributes(
media_type: eq('application/activity+json')
)
expect(response.headers['Cache-Control']).to include 'private'
expect(body_as_json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
end
end
@ -194,13 +193,12 @@ describe 'Accounts show response' do
it 'returns a private signature JSON version of the account', :aggregate_failures do
expect(response)
.to have_http_status(200)
.and have_http_header('Cache-Control', 'private')
.and have_http_header('Vary', 'Signature')
.and have_attributes(
media_type: eq('application/activity+json')
)
expect(response.headers['Cache-Control']).to include 'private'
expect(response.headers['Vary']).to include 'Signature'
expect(body_as_json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
end
end

View file

@ -18,9 +18,9 @@ describe 'The /.well-known/webfinger endpoint' do
shared_examples 'a successful response' do
it 'returns http success with correct media type and headers and body json' do
expect(response).to have_http_status(200)
expect(response.headers['Vary']).to eq('Origin')
expect(response)
.to have_http_status(200)
.and have_http_header('Vary', 'Origin')
expect(response.media_type).to eq 'application/jrd+json'
@ -116,12 +116,10 @@ describe 'The /.well-known/webfinger endpoint' do
perform_request!
end
it 'returns http success' do
expect(response).to have_http_status(200)
end
it 'sets only a Vary Origin header' do
expect(response.headers['Vary']).to eq('Origin')
it 'returns http success and vary origin header' do
expect(response)
.to have_http_status(200)
.and have_http_header('Vary', 'Origin')
end
it 'returns application/jrd+json' do

View file

@ -7,8 +7,8 @@ shared_examples 'cacheable response' do |expects_vary: false|
expect(session).to be_empty
expect(response.headers['Vary']).to include(expects_vary) if expects_vary
expect(response).to have_http_header('Vary', expects_vary) if expects_vary
expect(response.headers['Cache-Control']).to include('public')
expect(response).to have_http_header('Cache-Control', 'public')
end
end