authorized_applications_controller_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Oauth::AuthorizedApplicationsController do
  4. render_views
  5. describe 'GET #index' do
  6. subject do
  7. get :index
  8. end
  9. context 'when signed in' do
  10. before do
  11. sign_in Fabricate(:user), scope: :user
  12. end
  13. it 'returns http success with private cache control headers' do
  14. subject
  15. expect(response)
  16. .to have_http_status(200)
  17. expect(response.headers['Cache-Control'])
  18. .to include('private, no-store')
  19. expect(controller.stored_location_for(:user))
  20. .to eq '/oauth/authorized_applications'
  21. end
  22. end
  23. context 'when not signed in' do
  24. it 'redirects' do
  25. subject
  26. expect(response)
  27. .to redirect_to '/auth/sign_in'
  28. expect(controller.stored_location_for(:user))
  29. .to eq '/oauth/authorized_applications'
  30. end
  31. end
  32. end
  33. describe 'DELETE #destroy' do
  34. let!(:user) { Fabricate(:user) }
  35. let!(:application) { Fabricate(:application) }
  36. let!(:access_token) { Fabricate(:accessible_access_token, application: application, resource_owner_id: user.id) }
  37. let!(:web_push_subscription) { Fabricate(:web_push_subscription, user: user, access_token: access_token) }
  38. let(:redis_pipeline_stub) { instance_double(Redis::Namespace, publish: nil) }
  39. before do
  40. sign_in user, scope: :user
  41. allow(redis).to receive(:pipelined).and_yield(redis_pipeline_stub)
  42. end
  43. it 'revokes access tokens for the application and removes subscriptions and sends kill payload to streaming' do
  44. post :destroy, params: { id: application.id }
  45. expect(Doorkeeper::AccessToken.where(application: application).first.revoked_at)
  46. .to_not be_nil
  47. expect(Web::PushSubscription.where(user: user).count)
  48. .to eq(0)
  49. expect { web_push_subscription.reload }
  50. .to raise_error(ActiveRecord::RecordNotFound)
  51. expect(redis_pipeline_stub)
  52. .to have_received(:publish).with("timeline:access_token:#{access_token.id}", '{"event":"kill"}')
  53. end
  54. end
  55. end