From 8bd228822cd19dc4fec7f45f45fbcf4b4b53a1dd Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 2 May 2023 17:42:42 +0200 Subject: [PATCH] Add fallback redirection when getting a webfinger query `LOCAL_DOMAIN@LOCAL_DOMAIN` (#23600) Co-authored-by: Eugen Rochko --- .../well_known/webfinger_controller.rb | 9 +++- .../well_known/webfinger_controller_spec.rb | 44 +++++++++++++++---- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/app/controllers/well_known/webfinger_controller.rb b/app/controllers/well_known/webfinger_controller.rb index a06253f4568a02..0d897e8e24635f 100644 --- a/app/controllers/well_known/webfinger_controller.rb +++ b/app/controllers/well_known/webfinger_controller.rb @@ -18,7 +18,14 @@ def show private def set_account - @account = Account.find_local!(username_from_resource) + username = username_from_resource + @account = begin + if username == Rails.configuration.x.local_domain + Account.representative + else + Account.find_local!(username) + end + end end def username_from_resource diff --git a/spec/controllers/well_known/webfinger_controller_spec.rb b/spec/controllers/well_known/webfinger_controller_spec.rb index 00103df7065101..401f7421fe5e38 100644 --- a/spec/controllers/well_known/webfinger_controller_spec.rb +++ b/spec/controllers/well_known/webfinger_controller_spec.rb @@ -6,7 +6,7 @@ render_views describe 'GET #show' do - subject do + subject(:perform_show!) do get :show, params: { resource: resource }, format: :json end @@ -45,7 +45,7 @@ let(:resource) { alice.to_webfinger_s } before do - subject + perform_show! end it_behaves_like 'a successful response' @@ -56,7 +56,7 @@ before do alice.suspend! - subject + perform_show! end it_behaves_like 'a successful response' @@ -68,7 +68,7 @@ before do alice.suspend! alice.deletion_request.destroy - subject + perform_show! end it 'returns http gone' do @@ -80,7 +80,7 @@ let(:resource) { 'acct:not@existing.com' } before do - subject + perform_show! end it 'returns http not found' do @@ -92,7 +92,7 @@ let(:alternate_domains) { ['foo.org'] } before do - subject + perform_show! end context 'when an account exists' do @@ -116,11 +116,39 @@ end end + context 'when the old name scheme is used to query the instance actor' do + let(:resource) do + "#{Rails.configuration.x.local_domain}@#{Rails.configuration.x.local_domain}" + end + + before do + perform_show! + end + + it 'returns http success' do + expect(response).to have_http_status(200) + end + + it 'does not set a Vary header' do + expect(response.headers['Vary']).to be_nil + end + + it 'returns application/jrd+json' do + expect(response.media_type).to eq 'application/jrd+json' + end + + it 'returns links for the internal account' do + json = body_as_json + expect(json[:subject]).to eq 'acct:mastodon.internal@cb6e6126.ngrok.io' + expect(json[:aliases]).to eq ['https://cb6e6126.ngrok.io/actor'] + end + end + context 'with no resource parameter' do let(:resource) { nil } before do - subject + perform_show! end it 'returns http bad request' do @@ -132,7 +160,7 @@ let(:resource) { 'df/:dfkj' } before do - subject + perform_show! end it 'returns http bad request' do