mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-20 03:25:17 +01:00
Support /.well-known/host-meta.json (#32206)
This commit is contained in:
parent
f0716368e6
commit
33d3ca7cf1
@ -7,7 +7,23 @@ module WellKnown
|
|||||||
def show
|
def show
|
||||||
@webfinger_template = "#{webfinger_url}?resource={uri}"
|
@webfinger_template = "#{webfinger_url}?resource={uri}"
|
||||||
expires_in 3.days, public: true
|
expires_in 3.days, public: true
|
||||||
render content_type: 'application/xrd+xml', formats: [:xml]
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.any do
|
||||||
|
render content_type: 'application/xrd+xml', formats: [:xml]
|
||||||
|
end
|
||||||
|
|
||||||
|
format.json do
|
||||||
|
render json: {
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
rel: 'lrdd',
|
||||||
|
template: @webfinger_template,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -67,7 +67,7 @@ Rails.application.routes.draw do
|
|||||||
scope path: '.well-known' do
|
scope path: '.well-known' do
|
||||||
scope module: :well_known do
|
scope module: :well_known do
|
||||||
get 'oauth-authorization-server', to: 'oauth_metadata#show', as: :oauth_metadata, defaults: { format: 'json' }
|
get 'oauth-authorization-server', to: 'oauth_metadata#show', as: :oauth_metadata, defaults: { format: 'json' }
|
||||||
get 'host-meta', to: 'host_meta#show', as: :host_meta, defaults: { format: 'xml' }
|
get 'host-meta', to: 'host_meta#show', as: :host_meta
|
||||||
get 'nodeinfo', to: 'node_info#index', as: :nodeinfo, defaults: { format: 'json' }
|
get 'nodeinfo', to: 'node_info#index', as: :nodeinfo, defaults: { format: 'json' }
|
||||||
get 'webfinger', to: 'webfinger#show', as: :webfinger
|
get 'webfinger', to: 'webfinger#show', as: :webfinger
|
||||||
end
|
end
|
||||||
|
@ -9,19 +9,39 @@ RSpec.describe 'The /.well-known/host-meta request' do
|
|||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
.and have_attributes(
|
.and have_attributes(
|
||||||
media_type: 'application/xrd+xml',
|
media_type: 'application/xrd+xml'
|
||||||
body: host_meta_xml_template
|
)
|
||||||
|
|
||||||
|
doc = Nokogiri::XML(response.parsed_body)
|
||||||
|
expect(doc.at_xpath('/xrd:XRD/xrd:Link[@rel="lrdd"]/@template', 'xrd' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0').value)
|
||||||
|
.to eq 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns http success with valid JSON response with .json extension' do
|
||||||
|
get '/.well-known/host-meta.json'
|
||||||
|
|
||||||
|
expect(response)
|
||||||
|
.to have_http_status(200)
|
||||||
|
.and have_attributes(
|
||||||
|
media_type: 'application/json'
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(response.parsed_body)
|
||||||
|
.to include(
|
||||||
|
links: [
|
||||||
|
'rel' => 'lrdd',
|
||||||
|
'template' => 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}',
|
||||||
|
]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
it 'returns http success with valid JSON response with Accept header' do
|
||||||
|
get '/.well-known/host-meta', headers: { 'Accept' => 'application/json' }
|
||||||
|
|
||||||
def host_meta_xml_template
|
expect(response)
|
||||||
<<~XML
|
.to have_http_status(200)
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
.and have_attributes(
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
media_type: 'application/json'
|
||||||
<Link rel="lrdd" template="https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}"/>
|
)
|
||||||
</XRD>
|
|
||||||
XML
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,9 +4,14 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe 'Well Known routes' do
|
RSpec.describe 'Well Known routes' do
|
||||||
describe 'the host-meta route' do
|
describe 'the host-meta route' do
|
||||||
it 'routes to correct place with xml format' do
|
it 'routes to correct place' do
|
||||||
expect(get('/.well-known/host-meta'))
|
expect(get('/.well-known/host-meta'))
|
||||||
.to route_to('well_known/host_meta#show', format: 'xml')
|
.to route_to('well_known/host_meta#show')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'routes to correct place with json format' do
|
||||||
|
expect(get('/.well-known/host-meta.json'))
|
||||||
|
.to route_to('well_known/host_meta#show', format: 'json')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user