Register an XML encoder for response tests (#32220)
Some checks are pending
Bundler Audit / security (push) Waiting to run
Check i18n / check-i18n (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (ruby) (push) Waiting to run
Check formatting / lint (push) Waiting to run
CSS Linting / lint (push) Waiting to run
Haml Linting / lint (push) Waiting to run
JavaScript Linting / lint (push) Waiting to run
Ruby Linting / lint (push) Waiting to run
JavaScript Testing / test (push) Waiting to run
Historical data migration test / test (14-alpine) (push) Waiting to run
Historical data migration test / test (15-alpine) (push) Waiting to run
Ruby Testing / build (production) (push) Waiting to run
Ruby Testing / build (test) (push) Waiting to run
Ruby Testing / test (.ruby-version) (push) Blocked by required conditions
Ruby Testing / test (3.1) (push) Blocked by required conditions
Ruby Testing / test (3.2) (push) Blocked by required conditions
Ruby Testing / Libvips tests (.ruby-version) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.1) (push) Blocked by required conditions
Ruby Testing / Libvips tests (3.2) (push) Blocked by required conditions
Ruby Testing / End to End testing (.ruby-version) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.1) (push) Blocked by required conditions
Ruby Testing / End to End testing (3.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, docker.elastic.co/elasticsearch/elasticsearch:8.10.2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (.ruby-version, opensearchproject/opensearch:2) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.1, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions
Ruby Testing / Elastic Search integration testing (3.2, docker.elastic.co/elasticsearch/elasticsearch:7.17.13) (push) Blocked by required conditions

This commit is contained in:
Matt Jankowski 2024-10-03 09:10:27 -04:00 committed by GitHub
parent d95f6f4410
commit cc8d723e71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 32 deletions

View File

@ -3,7 +3,8 @@
require 'rails_helper'
RSpec.describe 'The /.well-known/host-meta request' do
it 'returns http success with valid XML response' do
context 'without extension format or accept header' do
it 'returns http success with expected XML' do
get '/.well-known/host-meta'
expect(response)
@ -12,12 +13,20 @@ RSpec.describe 'The /.well-known/host-meta request' do
media_type: 'application/xrd+xml'
)
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)
expect(xrd_link_template_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
def xrd_link_template_value
response
.parsed_body
.at_xpath('/xrd:XRD/xrd:Link[@rel="lrdd"]/@template', 'xrd' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0')
.value
end
end
context 'with a .json format extension' do
it 'returns http success with expected JSON' do
get '/.well-known/host-meta.json'
expect(response)
@ -25,17 +34,13 @@ RSpec.describe 'The /.well-known/host-meta request' do
.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}',
]
)
.to include(expected_json_template)
end
end
it 'returns http success with valid JSON response with Accept header' do
context 'with a JSON `Accept` header' do
it 'returns http success with expected JSON' do
get '/.well-known/host-meta', headers: { 'Accept' => 'application/json' }
expect(response)
@ -43,5 +48,17 @@ RSpec.describe 'The /.well-known/host-meta request' do
.and have_attributes(
media_type: 'application/json'
)
expect(response.parsed_body)
.to include(expected_json_template)
end
end
def expected_json_template
{
links: [
'rel' => 'lrdd',
'template' => 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}',
],
}
end
end

View File

@ -0,0 +1,4 @@
# frozen_string_literal: true
ActionDispatch::IntegrationTest
.register_encoder :xml, response_parser: ->(body) { Nokogiri::XML(body) }