instance_actor_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Instance actor endpoint' do
  4. describe 'GET /actor' do
  5. let!(:original_federation_mode) { Rails.configuration.x.limited_federation_mode }
  6. shared_examples 'instance actor endpoint' do
  7. before { get instance_actor_path(format: :json) }
  8. it 'returns http success with correct media type and body' do
  9. expect(response)
  10. .to have_http_status(200)
  11. .and have_cacheable_headers
  12. expect(response.content_type)
  13. .to start_with('application/activity+json')
  14. expect(response.parsed_body)
  15. .to include(
  16. id: instance_actor_url,
  17. type: 'Application',
  18. preferredUsername: 'mastodon.internal',
  19. inbox: instance_actor_inbox_url,
  20. outbox: instance_actor_outbox_url,
  21. publicKey: include(
  22. id: instance_actor_url(anchor: 'main-key')
  23. ),
  24. url: about_more_url(instance_actor: true)
  25. )
  26. end
  27. end
  28. context 'with limited federation mode disabled' do
  29. before { Rails.configuration.x.limited_federation_mode = false }
  30. after { Rails.configuration.x.limited_federation_mode = original_federation_mode }
  31. it_behaves_like 'instance actor endpoint'
  32. context 'with a disabled instance actor' do
  33. before { disable_instance_actor }
  34. it_behaves_like 'instance actor endpoint'
  35. end
  36. end
  37. context 'with limited federation mode enabled' do
  38. before { Rails.configuration.x.limited_federation_mode = true }
  39. after { Rails.configuration.x.limited_federation_mode = original_federation_mode }
  40. it_behaves_like 'instance actor endpoint'
  41. context 'with a disabled instance actor' do
  42. before { disable_instance_actor }
  43. it_behaves_like 'instance actor endpoint'
  44. end
  45. end
  46. def disable_instance_actor
  47. Account
  48. .representative
  49. .update(suspended_at: 10.days.ago)
  50. end
  51. end
  52. end