host_meta_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'The /.well-known/host-meta request' do
  4. context 'without extension format or accept header' do
  5. it 'returns http success with expected XML' do
  6. get '/.well-known/host-meta'
  7. expect(response)
  8. .to have_http_status(200)
  9. .and have_attributes(
  10. media_type: 'application/xrd+xml'
  11. )
  12. expect(xrd_link_template_value)
  13. .to eq 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}'
  14. end
  15. def xrd_link_template_value
  16. response
  17. .parsed_body
  18. .at_xpath('/xrd:XRD/xrd:Link[@rel="lrdd"]/@template', 'xrd' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0')
  19. .value
  20. end
  21. end
  22. context 'with a .json format extension' do
  23. it 'returns http success with expected JSON' do
  24. get '/.well-known/host-meta.json'
  25. expect(response)
  26. .to have_http_status(200)
  27. .and have_attributes(
  28. media_type: 'application/json'
  29. )
  30. expect(response.parsed_body)
  31. .to include(expected_json_template)
  32. end
  33. end
  34. context 'with a JSON `Accept` header' do
  35. it 'returns http success with expected JSON' do
  36. get '/.well-known/host-meta', headers: { 'Accept' => 'application/json' }
  37. expect(response)
  38. .to have_http_status(200)
  39. .and have_attributes(
  40. media_type: 'application/json'
  41. )
  42. expect(response.parsed_body)
  43. .to include(expected_json_template)
  44. end
  45. end
  46. def expected_json_template
  47. {
  48. links: [
  49. 'rel' => 'lrdd',
  50. 'template' => 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource={uri}',
  51. ],
  52. }
  53. end
  54. end