You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.2 KiB

  1. require 'rails_helper'
  2. describe WellKnown::WebfingerController, type: :controller do
  3. render_views
  4. describe 'GET #show' do
  5. let(:alternate_domains) { [] }
  6. let(:alice) { Fabricate(:account, username: 'alice') }
  7. let(:resource) { nil }
  8. around(:each) do |example|
  9. tmp = Rails.configuration.x.alternate_domains
  10. Rails.configuration.x.alternate_domains = alternate_domains
  11. example.run
  12. Rails.configuration.x.alternate_domains = tmp
  13. end
  14. subject do
  15. get :show, params: { resource: resource }, format: :json
  16. end
  17. shared_examples 'a successful response' do
  18. it 'returns http success' do
  19. expect(response).to have_http_status(200)
  20. end
  21. it 'does not set a Vary header' do
  22. expect(response.headers['Vary']).to be_nil
  23. end
  24. it 'returns application/jrd+json' do
  25. expect(response.media_type).to eq 'application/jrd+json'
  26. end
  27. it 'returns links for the account' do
  28. json = body_as_json
  29. expect(json[:subject]).to eq 'acct:alice@cb6e6126.ngrok.io'
  30. expect(json[:aliases]).to include('https://cb6e6126.ngrok.io/@alice', 'https://cb6e6126.ngrok.io/users/alice')
  31. end
  32. end
  33. context 'when an account exists' do
  34. let(:resource) { alice.to_webfinger_s }
  35. before do
  36. subject
  37. end
  38. it_behaves_like 'a successful response'
  39. end
  40. context 'when an account is temporarily suspended' do
  41. let(:resource) { alice.to_webfinger_s }
  42. before do
  43. alice.suspend!
  44. subject
  45. end
  46. it_behaves_like 'a successful response'
  47. end
  48. context 'when an account is permanently suspended or deleted' do
  49. let(:resource) { alice.to_webfinger_s }
  50. before do
  51. alice.suspend!
  52. alice.deletion_request.destroy
  53. subject
  54. end
  55. it 'returns http gone' do
  56. expect(response).to have_http_status(410)
  57. end
  58. end
  59. context 'when an account is not found' do
  60. let(:resource) { 'acct:not@existing.com' }
  61. before do
  62. subject
  63. end
  64. it 'returns http not found' do
  65. expect(response).to have_http_status(404)
  66. end
  67. end
  68. context 'with an alternate domain' do
  69. let(:alternate_domains) { ['foo.org'] }
  70. before do
  71. subject
  72. end
  73. context 'when an account exists' do
  74. let(:resource) do
  75. username, = alice.to_webfinger_s.split('@')
  76. "#{username}@foo.org"
  77. end
  78. it_behaves_like 'a successful response'
  79. end
  80. context 'when the domain is wrong' do
  81. let(:resource) do
  82. username, = alice.to_webfinger_s.split('@')
  83. "#{username}@bar.org"
  84. end
  85. it 'returns http not found' do
  86. expect(response).to have_http_status(404)
  87. end
  88. end
  89. end
  90. context 'with no resource parameter' do
  91. let(:resource) { nil }
  92. before do
  93. subject
  94. end
  95. it 'returns http bad request' do
  96. expect(response).to have_http_status(400)
  97. end
  98. end
  99. context 'with a nonsense parameter' do
  100. let(:resource) { 'df/:dfkj' }
  101. before do
  102. subject
  103. end
  104. it 'returns http bad request' do
  105. expect(response).to have_http_status(400)
  106. end
  107. end
  108. end
  109. end