mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Use http link header matcher
This commit is contained in:
parent
71fa939640
commit
f44e0a722d
5 changed files with 15 additions and 35 deletions
|
@ -55,15 +55,10 @@ describe AccountControllerConcern do
|
|||
get 'success', params: { account_username: account.username }
|
||||
|
||||
expect(assigns(:account)).to eq account
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.headers['Link'].to_s).to eq(expected_link_headers)
|
||||
end
|
||||
|
||||
def expected_link_headers
|
||||
[
|
||||
'<http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io>; rel="lrdd"; type="application/jrd+json"',
|
||||
'<https://cb6e6126.ngrok.io/users/username>; rel="alternate"; type="application/activity+json"',
|
||||
].join(', ')
|
||||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and have_http_link_header(:lrdd, 'http://test.host/.well-known/webfinger?resource=acct%3Ausername%40cb6e6126.ngrok.io').with_type('application/jrd+json')
|
||||
.and have_http_link_header(:alternate, 'https://cb6e6126.ngrok.io/users/username').with_type('application/activity+json')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,8 +69,7 @@ describe 'Accounts show response' do
|
|||
expect(response)
|
||||
.to have_http_status(200)
|
||||
.and render_template(:show)
|
||||
|
||||
expect(response.headers['Link'].to_s).to include ActivityPub::TagManager.instance.uri_for(account)
|
||||
.and have_http_link_header(:alternate, ActivityPub::TagManager.instance.uri_for(account))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -94,8 +94,9 @@ describe 'Home', :inline_jobs do
|
|||
it 'returns http unprocessable entity', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
expect(response)
|
||||
.to have_http_status(422)
|
||||
.and not_have_http_link_header
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -47,8 +47,9 @@ describe 'API V1 Timelines List' do
|
|||
it 'returns http unprocessable entity' do
|
||||
get "/api/v1/timelines/list/#{list.id}", headers: headers
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.headers['Link']).to be_nil
|
||||
expect(response)
|
||||
.to have_http_status(422)
|
||||
.and not_have_http_link_header
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,28 +6,12 @@ describe 'Link headers' do
|
|||
describe 'on the account show page' do
|
||||
let(:account) { Fabricate(:account, username: 'test') }
|
||||
|
||||
before do
|
||||
it 'contains webfinger and activitypub urls in link header' do
|
||||
get short_account_path(username: account)
|
||||
end
|
||||
|
||||
it 'contains webfinger url in link header' do
|
||||
link_header = link_header_with_type('application/jrd+json')
|
||||
|
||||
expect(link_header.href).to eq 'http://www.example.com/.well-known/webfinger?resource=acct%3Atest%40cb6e6126.ngrok.io'
|
||||
expect(link_header.attr_pairs.first).to eq %w(rel lrdd)
|
||||
end
|
||||
|
||||
it 'contains activitypub url in link header' do
|
||||
link_header = link_header_with_type('application/activity+json')
|
||||
|
||||
expect(link_header.href).to eq 'https://cb6e6126.ngrok.io/users/test'
|
||||
expect(link_header.attr_pairs.first).to eq %w(rel alternate)
|
||||
end
|
||||
|
||||
def link_header_with_type(type)
|
||||
LinkHeader.parse(response.headers['Link'].to_s).links.find do |link|
|
||||
link.attr_pairs.any?(['type', type])
|
||||
end
|
||||
expect(response)
|
||||
.to have_http_link_header(:lrdd, 'http://www.example.com/.well-known/webfinger?resource=acct%3Atest%40cb6e6126.ngrok.io').with_type('application/jrd+json')
|
||||
.and have_http_link_header(:alternate, 'https://cb6e6126.ngrok.io/users/test').with_type('application/activity+json')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue