Skip to content

Commit

Permalink
Add fallback redirection when getting a webfinger query `LOCAL_DOMAIN…
Browse files Browse the repository at this point in the history
…@LOCAL_DOMAIN` (mastodon#23600)

Co-authored-by: Eugen Rochko <eugen@zeonfederated.com>
  • Loading branch information
ClearlyClaire and Gargron committed Jul 6, 2023
1 parent 210ff36 commit 2779bce
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
9 changes: 8 additions & 1 deletion app/controllers/well_known/webfinger_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 39 additions & 11 deletions spec/controllers/well_known/webfinger_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
render_views

describe 'GET #show' do
subject(:perform_show!) do
get :show, params: { resource: resource }, format: :json
end

let(:alternate_domains) { [] }
let(:alice) { Fabricate(:account, username: 'alice') }
let(:resource) { nil }
Expand All @@ -15,10 +19,6 @@
Rails.configuration.x.alternate_domains = tmp
end

subject do
get :show, params: { resource: resource }, format: :json
end

shared_examples 'a successful response' do
it 'returns http success' do
expect(response).to have_http_status(200)
Expand All @@ -43,7 +43,7 @@
let(:resource) { alice.to_webfinger_s }

before do
subject
perform_show!
end

it_behaves_like 'a successful response'
Expand All @@ -54,7 +54,7 @@

before do
alice.suspend!
subject
perform_show!
end

it_behaves_like 'a successful response'
Expand All @@ -66,7 +66,7 @@
before do
alice.suspend!
alice.deletion_request.destroy
subject
perform_show!
end

it 'returns http gone' do
Expand All @@ -78,7 +78,7 @@
let(:resource) { 'acct:not@existing.com' }

before do
subject
perform_show!
end

it 'returns http not found' do
Expand All @@ -90,7 +90,7 @@
let(:alternate_domains) { ['foo.org'] }

before do
subject
perform_show!
end

context 'when an account exists' do
Expand All @@ -114,11 +114,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
Expand All @@ -130,7 +158,7 @@
let(:resource) { 'df/:dfkj' }

before do
subject
perform_show!
end

it 'returns http bad request' do
Expand Down

0 comments on commit 2779bce

Please sign in to comment.