From 00586d27cb0f84377614a5ca2a3683c9fe9b74a5 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 28 Aug 2024 03:56:07 -0400 Subject: [PATCH] Convert `instance_actor` controller spec to request spec (#31621) --- .../instance_actors_controller_spec.rb | 54 -------------- spec/requests/instance_actor_spec.rb | 71 +++++++++++++++++++ 2 files changed, 71 insertions(+), 54 deletions(-) delete mode 100644 spec/controllers/instance_actors_controller_spec.rb create mode 100644 spec/requests/instance_actor_spec.rb diff --git a/spec/controllers/instance_actors_controller_spec.rb b/spec/controllers/instance_actors_controller_spec.rb deleted file mode 100644 index 42ffb67988..0000000000 --- a/spec/controllers/instance_actors_controller_spec.rb +++ /dev/null @@ -1,54 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe InstanceActorsController do - describe 'GET #show' do - context 'with JSON' do - let(:format) { 'json' } - - shared_examples 'shared behavior' do - before do - get :show, params: { format: format } - end - - it 'returns http success with correct media type and body' do - expect(response) - .to have_http_status(200) - .and have_attributes( - media_type: eq('application/activity+json') - ) - - expect(body_as_json) - .to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url) - end - - it_behaves_like 'cacheable response' - end - - before do - allow(controller).to receive(:authorized_fetch_mode?).and_return(authorized_fetch_mode) - end - - context 'without authorized fetch mode' do - let(:authorized_fetch_mode) { false } - - it_behaves_like 'shared behavior' - end - - context 'with authorized fetch mode' do - let(:authorized_fetch_mode) { true } - - it_behaves_like 'shared behavior' - end - - context 'with a suspended instance actor' do - let(:authorized_fetch_mode) { false } - - before { Account.representative.update(suspended_at: 10.days.ago) } - - it_behaves_like 'shared behavior' - end - end - end -end diff --git a/spec/requests/instance_actor_spec.rb b/spec/requests/instance_actor_spec.rb new file mode 100644 index 0000000000..9c7ee9ff90 --- /dev/null +++ b/spec/requests/instance_actor_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Instance actor endpoint' do + describe 'GET /actor' do + before do + integration_session.https! # TODO: Move to global rails_helper for all request specs? + host! Rails.configuration.x.local_domain # TODO: Move to global rails_helper for all request specs? + end + + let!(:original_federation_mode) { Rails.configuration.x.limited_federation_mode } + + shared_examples 'instance actor endpoint' do + before { get instance_actor_path(format: :json) } + + it 'returns http success with correct media type and body' do + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to start_with('application/activity+json') + expect(body_as_json) + .to include( + id: instance_actor_url, + type: 'Application', + preferredUsername: 'mastodon.internal', + inbox: instance_actor_inbox_url, + outbox: instance_actor_outbox_url, + publicKey: include( + id: instance_actor_url(anchor: 'main-key') + ), + url: about_more_url(instance_actor: true) + ) + end + + it_behaves_like 'cacheable response' + end + + context 'with limited federation mode disabled' do + before { Rails.configuration.x.limited_federation_mode = false } + after { Rails.configuration.x.limited_federation_mode = original_federation_mode } + + it_behaves_like 'instance actor endpoint' + + context 'with a disabled instance actor' do + before { disable_instance_actor } + + it_behaves_like 'instance actor endpoint' + end + end + + context 'with limited federation mode enabled' do + before { Rails.configuration.x.limited_federation_mode = true } + after { Rails.configuration.x.limited_federation_mode = original_federation_mode } + + it_behaves_like 'instance actor endpoint' + + context 'with a disabled instance actor' do + before { disable_instance_actor } + + it_behaves_like 'instance actor endpoint' + end + end + + def disable_instance_actor + Account + .representative + .update(suspended_at: 10.days.ago) + end + end +end