devise_masquerade 0.6.5 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +1 -0
  3. data/.github/workflows/brakeman-analysis.yml +44 -0
  4. data/.github/workflows/rubocop-analysis.yml +39 -0
  5. data/.gitignore +1 -2
  6. data/.ruby-version +1 -1
  7. data/.travis.yml +3 -4
  8. data/Gemfile +16 -10
  9. data/Gemfile.lock +307 -0
  10. data/Makefile +6 -1
  11. data/README.md +33 -1
  12. data/app/controllers/devise/masquerades_controller.rb +75 -59
  13. data/devise_masquerade.gemspec +5 -4
  14. data/features/back.feature +0 -1
  15. data/features/multiple_masquerading_models.feature +17 -0
  16. data/features/step_definitions/auth_steps.rb +1 -0
  17. data/features/step_definitions/back_steps.rb +18 -3
  18. data/features/step_definitions/url_helpers_steps.rb +11 -0
  19. data/features/support/env.rb +23 -4
  20. data/features/url_helpers.feature +14 -0
  21. data/lib/devise_masquerade.rb +3 -9
  22. data/lib/devise_masquerade/controllers/helpers.rb +27 -8
  23. data/lib/devise_masquerade/controllers/url_helpers.rb +16 -2
  24. data/lib/devise_masquerade/models.rb +9 -0
  25. data/lib/devise_masquerade/models/masqueradable.rb +13 -0
  26. data/lib/devise_masquerade/rails.rb +14 -4
  27. data/lib/devise_masquerade/routes.rb +11 -8
  28. data/lib/devise_masquerade/version.rb +1 -1
  29. data/spec/controllers/admin/dashboard_controller_spec.rb +3 -4
  30. data/spec/controllers/dashboard_controller_spec.rb +3 -5
  31. data/spec/controllers/devise/masquerades_controller_spec.rb +62 -38
  32. data/spec/controllers/masquerades_tests_controller_spec.rb +41 -0
  33. data/spec/dummy/app/controllers/admin/dashboard_controller.rb +1 -2
  34. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  35. data/spec/dummy/app/controllers/dashboard_controller.rb +5 -2
  36. data/spec/dummy/app/controllers/masquerades_tests_controller.rb +7 -0
  37. data/spec/dummy/app/controllers/students_controller.rb +8 -0
  38. data/spec/dummy/app/models/admin/user.rb +0 -7
  39. data/spec/dummy/app/models/student.rb +3 -0
  40. data/spec/dummy/app/models/user.rb +1 -10
  41. data/spec/dummy/app/views/admin/dashboard/index.html.erb +0 -2
  42. data/spec/dummy/app/views/dashboard/extra_params.html.erb +7 -0
  43. data/spec/dummy/app/views/dashboard/index.html.erb +0 -2
  44. data/spec/dummy/app/views/layouts/application.html.erb +7 -1
  45. data/spec/dummy/app/views/students/_student.html.erb +6 -0
  46. data/spec/dummy/app/views/students/index.html.erb +1 -0
  47. data/spec/dummy/app/views/users/_user.html.erb +1 -1
  48. data/spec/dummy/config/application.rb +2 -0
  49. data/spec/dummy/config/environment.rb +1 -0
  50. data/spec/dummy/config/routes.rb +9 -5
  51. data/spec/dummy/db/.gitignore +1 -0
  52. data/spec/dummy/db/migrate/20121119085620_devise_create_users.rb +1 -1
  53. data/spec/dummy/db/migrate/20140418160449_create_admin_users.rb +1 -1
  54. data/spec/dummy/db/migrate/20191022100000_create_students.rb +14 -0
  55. data/spec/dummy/db/schema.rb +37 -31
  56. data/spec/models/user_spec.rb +3 -30
  57. data/spec/orm/active_record.rb +5 -2
  58. data/spec/spec_helper.rb +3 -3
  59. data/spec/support/factories.rb +13 -9
  60. metadata +57 -19
  61. data/lib/devise_masquerade/model.rb +0 -42
  62. data/spec/controllers/masquerades_controller_spec.rb +0 -42
  63. data/spec/dummy/app/controllers/masquerades_controller.rb +0 -5
@@ -1,42 +0,0 @@
1
- module Devise
2
- module Models
3
- module Masqueradable
4
- def self.included(base)
5
- base.class_eval do
6
- attr_reader :masquerade_key
7
-
8
- include InstanceMethods
9
- extend ClassMethods
10
- end
11
- end
12
-
13
- module InstanceMethods
14
- def masquerade!
15
- @masquerade_key = SecureRandom.urlsafe_base64(Devise.masquerade_key_size)
16
- cache_key = self.class.cache_masquerade_key_by(@masquerade_key)
17
- Rails.cache.write(cache_key, id, :expires_in => Devise.masquerade_expires_in)
18
- end
19
- end
20
-
21
- module ClassMethods
22
- def cache_masquerade_key_by(key)
23
- "#{self.name.pluralize.underscore}:#{key}:masquerade"
24
- end
25
-
26
- def remove_masquerade_key!(key)
27
- Rails.cache.delete(cache_masquerade_key_by(key))
28
- end
29
-
30
- def find_by_masquerade_key(key)
31
- id = Rails.cache.read(cache_masquerade_key_by(key))
32
-
33
- # clean up the cached masquerade key value
34
- remove_masquerade_key!(key)
35
-
36
- where(id: id).first
37
- end
38
- end # ClassMethods
39
- end
40
- end
41
- end
42
-
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe MasqueradesController, type: :controller do
4
- before { @request.env['devise.mapping'] = Devise.mappings[:user] }
5
-
6
- context 'no access for masquerade' do
7
- before do
8
- session.clear
9
- allow_any_instance_of(MasqueradesController).to receive(:masquerade_authorized?) { false }
10
- end
11
-
12
- before { logged_in }
13
-
14
- let(:mask) { create(:user) }
15
-
16
- before { get :show, :id => mask.to_param }
17
-
18
- it { expect(response.status).to eq(403) }
19
- it { expect(session.keys).not_to include('devise_masquerade_user') }
20
- it { expect(session["warden.user.user.key"].first.first).not_to eq(mask.id) }
21
- end
22
-
23
- context 'access for masquerade' do
24
- before do
25
- session.clear
26
- allow_any_instance_of(MasqueradesController).to receive(:masquerade_authorized?) { true }
27
- end
28
-
29
- before { logged_in }
30
-
31
- let(:mask) { create(:user) }
32
-
33
- before do
34
- expect(SecureRandom).to receive(:urlsafe_base64) { "secure_key" }
35
- get :show, :id => mask.to_param
36
- end
37
-
38
- it { expect(response.status).to eq(302) }
39
- it { expect(session.keys).to include('devise_masquerade_user') }
40
- it { expect(session["warden.user.user.key"].first.first).to eq(mask.id) }
41
- end
42
- end
@@ -1,5 +0,0 @@
1
- class MasqueradesController < Devise::MasqueradesController
2
- def show
3
- super
4
- end
5
- end