authorized_applications_controller_spec.rb 1.8 KB

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