self_destruct_spec.rb 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe 'Self-destruct mode' do
  4. before do
  5. allow(SelfDestructHelper).to receive(:self_destruct?).and_return(true)
  6. end
  7. shared_examples 'generic logged out request' do |path|
  8. it 'returns 410 gone and mentions self-destruct' do
  9. get path, headers: { 'Accept' => 'text/html' }
  10. expect(response).to have_http_status(410)
  11. expect(response.body).to include(I18n.t('self_destruct.title'))
  12. end
  13. end
  14. shared_examples 'accessible logged-in endpoint' do |path|
  15. it 'returns 200 ok' do
  16. get path
  17. expect(response).to have_http_status(200)
  18. end
  19. end
  20. shared_examples 'ActivityPub request' do |path|
  21. context 'without signature' do
  22. it 'returns 410 gone' do
  23. get path, headers: {
  24. 'Accept' => 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
  25. }
  26. expect(response).to have_http_status(410)
  27. end
  28. end
  29. context 'with invalid signature' do
  30. it 'returns 410 gone' do
  31. get path, headers: {
  32. 'Accept' => 'application/activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
  33. 'Signature' => 'keyId="https://remote.domain/users/bob#main-key",algorithm="rsa-sha256",headers="date host (request-target)",signature="bar"',
  34. }
  35. expect(response).to have_http_status(410)
  36. end
  37. end
  38. end
  39. context 'when requesting various unavailable endpoints' do
  40. it_behaves_like 'generic logged out request', '/'
  41. it_behaves_like 'generic logged out request', '/about'
  42. it_behaves_like 'generic logged out request', '/public'
  43. end
  44. context 'when requesting a suspended account' do
  45. let(:suspended) { Fabricate(:account, username: 'suspended') }
  46. before do
  47. suspended.suspend!
  48. end
  49. it_behaves_like 'generic logged out request', '/@suspended'
  50. it_behaves_like 'ActivityPub request', '/users/suspended'
  51. it_behaves_like 'ActivityPub request', '/users/suspended/followers'
  52. it_behaves_like 'ActivityPub request', '/users/suspended/outbox'
  53. end
  54. context 'when requesting a non-suspended account' do
  55. before do
  56. Fabricate(:account, username: 'bob')
  57. end
  58. it_behaves_like 'generic logged out request', '/@bob'
  59. it_behaves_like 'ActivityPub request', '/users/bob'
  60. it_behaves_like 'ActivityPub request', '/users/bob/followers'
  61. it_behaves_like 'ActivityPub request', '/users/bob/outbox'
  62. end
  63. context 'when accessing still-enabled endpoints when logged in' do
  64. let(:user) { Fabricate(:user) }
  65. before do
  66. sign_in(user)
  67. end
  68. it_behaves_like 'accessible logged-in endpoint', '/auth/edit'
  69. it_behaves_like 'accessible logged-in endpoint', '/settings/export'
  70. it_behaves_like 'accessible logged-in endpoint', '/settings/login_activities'
  71. it_behaves_like 'accessible logged-in endpoint', '/settings/exports/follows.csv'
  72. end
  73. end