闭社主体 forked from https://github.com/tootsuite/mastodon
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.

137 lines
3.1 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 'returns application/jrd+json' do
  22. expect(response.content_type).to eq 'application/jrd+json'
  23. end
  24. it 'returns links for the account' do
  25. json = body_as_json
  26. expect(json[:subject]).to eq 'acct:alice@cb6e6126.ngrok.io'
  27. expect(json[:aliases]).to include('https://cb6e6126.ngrok.io/@alice', 'https://cb6e6126.ngrok.io/users/alice')
  28. end
  29. end
  30. context 'when an account exists' do
  31. let(:resource) { alice.to_webfinger_s }
  32. before do
  33. subject
  34. end
  35. it_behaves_like 'a successful response'
  36. end
  37. context 'when an account is temporarily suspended' do
  38. let(:resource) { alice.to_webfinger_s }
  39. before do
  40. alice.suspend!
  41. subject
  42. end
  43. it_behaves_like 'a successful response'
  44. end
  45. context 'when an account is permanently suspended or deleted' do
  46. let(:resource) { alice.to_webfinger_s }
  47. before do
  48. alice.suspend!
  49. alice.deletion_request.destroy
  50. subject
  51. end
  52. it 'returns http gone' do
  53. expect(response).to have_http_status(410)
  54. end
  55. end
  56. context 'when an account is not found' do
  57. let(:resource) { 'acct:not@existing.com' }
  58. before do
  59. subject
  60. end
  61. it 'returns http not found' do
  62. expect(response).to have_http_status(404)
  63. end
  64. end
  65. context 'with an alternate domain' do
  66. let(:alternate_domains) { ['foo.org'] }
  67. before do
  68. subject
  69. end
  70. context 'when an account exists' do
  71. let(:resource) do
  72. username, = alice.to_webfinger_s.split('@')
  73. "#{username}@foo.org"
  74. end
  75. it_behaves_like 'a successful response'
  76. end
  77. context 'when the domain is wrong' do
  78. let(:resource) do
  79. username, = alice.to_webfinger_s.split('@')
  80. "#{username}@bar.org"
  81. end
  82. it 'returns http not found' do
  83. expect(response).to have_http_status(404)
  84. end
  85. end
  86. end
  87. context 'with no resource parameter' do
  88. let(:resource) { nil }
  89. before do
  90. subject
  91. end
  92. it 'returns http bad request' do
  93. expect(response).to have_http_status(400)
  94. end
  95. end
  96. context 'with a nonsense parameter' do
  97. let(:resource) { 'df/:dfkj' }
  98. before do
  99. subject
  100. end
  101. it 'returns http bad request' do
  102. expect(response).to have_http_status(400)
  103. end
  104. end
  105. end
  106. end