require 'rails_helper' describe WellKnown::WebfingerController, type: :controller do render_views describe 'GET #show' do let(:alice) do Fabricate(:account, username: 'alice') end before do alice.private_key = < acct:alice@cb6e6126.ngrok.io https://cb6e6126.ngrok.io/@alice https://cb6e6126.ngrok.io/users/alice XML end it 'returns http not found when account cannot be found' do get :show, params: { resource: 'acct:not@existing.com' }, format: :json expect(response).to have_http_status(:not_found) end it 'returns JSON when account can be found with alternate domains' do Rails.configuration.x.alternate_domains = ["foo.org"] username, domain = alice.to_webfinger_s.split("@") get :show, params: { resource: "#{username}@foo.org" }, format: :json expect(response).to have_http_status(:success) expect(response.content_type).to eq 'application/jrd+json' expect(response.body).to eq "{\"subject\":\"acct:alice@cb6e6126.ngrok.io\",\"aliases\":[\"https://cb6e6126.ngrok.io/@alice\",\"https://cb6e6126.ngrok.io/users/alice\"],\"links\":[{\"rel\":\"http://webfinger.net/rel/profile-page\",\"type\":\"text/html\",\"href\":\"https://cb6e6126.ngrok.io/@alice\"},{\"rel\":\"http://schemas.google.com/g/2010#updates-from\",\"type\":\"application/atom+xml\",\"href\":\"https://cb6e6126.ngrok.io/users/alice.atom\"},{\"rel\":\"self\",\"type\":\"application/activity+json\",\"href\":\"https://cb6e6126.ngrok.io/@alice\"},{\"rel\":\"salmon\",\"href\":\"#{api_salmon_url(alice.id)}\"},{\"rel\":\"magic-public-key\",\"href\":\"data:application/magic-public-key,RSA.x4D6DyZa3zGa1XLhd_VG1bLGvK-Dmyz93WJfWNezIKeSuJkmA0f2NmoOfLUoumq9szN2Xt0GLDX06tDajdYPPXgLtDG0o1qqTrIJ7UTyYhbo94Wotl9iJvEwa5IjP1Mn00YJ_KvFrzKCm15PC7up6r-NtHsqoYS8X1KAqcbnptU=.AQAB\"},{\"rel\":\"http://ostatus.org/schema/1.0/subscribe\",\"template\":\"https://cb6e6126.ngrok.io/authorize_follow?acct={uri}\"}]}" end it 'returns http not found when account can not be found with alternate domains' do Rails.configuration.x.alternate_domains = ["foo.org"] username, domain = alice.to_webfinger_s.split("@") get :show, params: { resource: "#{username}@bar.org" }, format: :json expect(response).to have_http_status(:not_found) end end end