1634e71bd6
* Fix misuse of foreign_type * Fix use of removed "add_template_helper" * Use response.media_type instead of response.content_type in tests * Fix CSV export controller test on Rails 6 Rails 6 sets a "filename*" field in the Content-Disposition header to explicitly encode the filename as UTF-8. This changes checks the first part of the Content-Disposition header so it matches in both Rails 5 and Rails 6. * Fix emoji formatting with Rails 6 * Make emoji output more idiomatic and robust * Switch from redis-rails gem to built-in Rails redis cache storage
137 lines
3.1 KiB
Ruby
137 lines
3.1 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe WellKnown::WebfingerController, type: :controller do
|
|
render_views
|
|
|
|
describe 'GET #show' do
|
|
let(:alternate_domains) { [] }
|
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
|
let(:resource) { nil }
|
|
|
|
around(:each) do |example|
|
|
tmp = Rails.configuration.x.alternate_domains
|
|
Rails.configuration.x.alternate_domains = alternate_domains
|
|
example.run
|
|
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)
|
|
end
|
|
|
|
it 'returns application/jrd+json' do
|
|
expect(response.media_type).to eq 'application/jrd+json'
|
|
end
|
|
|
|
it 'returns links for the account' do
|
|
json = body_as_json
|
|
expect(json[:subject]).to eq 'acct:alice@cb6e6126.ngrok.io'
|
|
expect(json[:aliases]).to include('https://cb6e6126.ngrok.io/@alice', 'https://cb6e6126.ngrok.io/users/alice')
|
|
end
|
|
end
|
|
|
|
context 'when an account exists' do
|
|
let(:resource) { alice.to_webfinger_s }
|
|
|
|
before do
|
|
subject
|
|
end
|
|
|
|
it_behaves_like 'a successful response'
|
|
end
|
|
|
|
context 'when an account is temporarily suspended' do
|
|
let(:resource) { alice.to_webfinger_s }
|
|
|
|
before do
|
|
alice.suspend!
|
|
subject
|
|
end
|
|
|
|
it_behaves_like 'a successful response'
|
|
end
|
|
|
|
context 'when an account is permanently suspended or deleted' do
|
|
let(:resource) { alice.to_webfinger_s }
|
|
|
|
before do
|
|
alice.suspend!
|
|
alice.deletion_request.destroy
|
|
subject
|
|
end
|
|
|
|
it 'returns http gone' do
|
|
expect(response).to have_http_status(410)
|
|
end
|
|
end
|
|
|
|
context 'when an account is not found' do
|
|
let(:resource) { 'acct:not@existing.com' }
|
|
|
|
before do
|
|
subject
|
|
end
|
|
|
|
it 'returns http not found' do
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
end
|
|
|
|
context 'with an alternate domain' do
|
|
let(:alternate_domains) { ['foo.org'] }
|
|
|
|
before do
|
|
subject
|
|
end
|
|
|
|
context 'when an account exists' do
|
|
let(:resource) do
|
|
username, = alice.to_webfinger_s.split('@')
|
|
"#{username}@foo.org"
|
|
end
|
|
|
|
it_behaves_like 'a successful response'
|
|
end
|
|
|
|
context 'when the domain is wrong' do
|
|
let(:resource) do
|
|
username, = alice.to_webfinger_s.split('@')
|
|
"#{username}@bar.org"
|
|
end
|
|
|
|
it 'returns http not found' do
|
|
expect(response).to have_http_status(404)
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with no resource parameter' do
|
|
let(:resource) { nil }
|
|
|
|
before do
|
|
subject
|
|
end
|
|
|
|
it 'returns http bad request' do
|
|
expect(response).to have_http_status(400)
|
|
end
|
|
end
|
|
|
|
context 'with a nonsense parameter' do
|
|
let(:resource) { 'df/:dfkj' }
|
|
|
|
before do
|
|
subject
|
|
end
|
|
|
|
it 'returns http bad request' do
|
|
expect(response).to have_http_status(400)
|
|
end
|
|
end
|
|
end
|
|
end
|