1
0
Fork 0
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:
Matt Jankowski 2024-07-11 12:21:15 -04:00
parent 71fa939640
commit f44e0a722d
5 changed files with 15 additions and 35 deletions

View file

@ -55,15 +55,10 @@ describe AccountControllerConcern do
get 'success', params: { account_username: account.username } get 'success', params: { account_username: account.username }
expect(assigns(:account)).to eq account expect(assigns(:account)).to eq account
expect(response).to have_http_status(200) expect(response)
expect(response.headers['Link'].to_s).to eq(expected_link_headers) .to have_http_status(200)
end .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')
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(', ')
end end
end end
end end

View file

@ -69,8 +69,7 @@ describe 'Accounts show response' do
expect(response) expect(response)
.to have_http_status(200) .to have_http_status(200)
.and render_template(:show) .and render_template(:show)
.and have_http_link_header(:alternate, ActivityPub::TagManager.instance.uri_for(account))
expect(response.headers['Link'].to_s).to include ActivityPub::TagManager.instance.uri_for(account)
end end
end end

View file

@ -94,8 +94,9 @@ describe 'Home', :inline_jobs do
it 'returns http unprocessable entity', :aggregate_failures do it 'returns http unprocessable entity', :aggregate_failures do
subject subject
expect(response).to have_http_status(422) expect(response)
expect(response.headers['Link']).to be_nil .to have_http_status(422)
.and not_have_http_link_header
end end
end end
end end

View file

@ -47,8 +47,9 @@ describe 'API V1 Timelines List' do
it 'returns http unprocessable entity' do it 'returns http unprocessable entity' do
get "/api/v1/timelines/list/#{list.id}", headers: headers get "/api/v1/timelines/list/#{list.id}", headers: headers
expect(response).to have_http_status(422) expect(response)
expect(response.headers['Link']).to be_nil .to have_http_status(422)
.and not_have_http_link_header
end end
end end
end end

View file

@ -6,28 +6,12 @@ describe 'Link headers' do
describe 'on the account show page' do describe 'on the account show page' do
let(:account) { Fabricate(:account, username: 'test') } let(:account) { Fabricate(:account, username: 'test') }
before do it 'contains webfinger and activitypub urls in link header' do
get short_account_path(username: account) get short_account_path(username: account)
end
it 'contains webfinger url in link header' do expect(response)
link_header = link_header_with_type('application/jrd+json') .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')
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
end end
end end
end end