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.
- checksums.yaml +5 -5
- data/.github/FUNDING.yml +1 -0
- data/.github/workflows/brakeman-analysis.yml +44 -0
- data/.github/workflows/rubocop-analysis.yml +39 -0
- data/.gitignore +1 -2
- data/.ruby-version +1 -1
- data/.travis.yml +3 -4
- data/Gemfile +16 -10
- data/Gemfile.lock +307 -0
- data/Makefile +6 -1
- data/README.md +33 -1
- data/app/controllers/devise/masquerades_controller.rb +75 -59
- data/devise_masquerade.gemspec +5 -4
- data/features/back.feature +0 -1
- data/features/multiple_masquerading_models.feature +17 -0
- data/features/step_definitions/auth_steps.rb +1 -0
- data/features/step_definitions/back_steps.rb +18 -3
- data/features/step_definitions/url_helpers_steps.rb +11 -0
- data/features/support/env.rb +23 -4
- data/features/url_helpers.feature +14 -0
- data/lib/devise_masquerade.rb +3 -9
- data/lib/devise_masquerade/controllers/helpers.rb +27 -8
- data/lib/devise_masquerade/controllers/url_helpers.rb +16 -2
- data/lib/devise_masquerade/models.rb +9 -0
- data/lib/devise_masquerade/models/masqueradable.rb +13 -0
- data/lib/devise_masquerade/rails.rb +14 -4
- data/lib/devise_masquerade/routes.rb +11 -8
- data/lib/devise_masquerade/version.rb +1 -1
- data/spec/controllers/admin/dashboard_controller_spec.rb +3 -4
- data/spec/controllers/dashboard_controller_spec.rb +3 -5
- data/spec/controllers/devise/masquerades_controller_spec.rb +62 -38
- data/spec/controllers/masquerades_tests_controller_spec.rb +41 -0
- data/spec/dummy/app/controllers/admin/dashboard_controller.rb +1 -2
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/dashboard_controller.rb +5 -2
- data/spec/dummy/app/controllers/masquerades_tests_controller.rb +7 -0
- data/spec/dummy/app/controllers/students_controller.rb +8 -0
- data/spec/dummy/app/models/admin/user.rb +0 -7
- data/spec/dummy/app/models/student.rb +3 -0
- data/spec/dummy/app/models/user.rb +1 -10
- data/spec/dummy/app/views/admin/dashboard/index.html.erb +0 -2
- data/spec/dummy/app/views/dashboard/extra_params.html.erb +7 -0
- data/spec/dummy/app/views/dashboard/index.html.erb +0 -2
- data/spec/dummy/app/views/layouts/application.html.erb +7 -1
- data/spec/dummy/app/views/students/_student.html.erb +6 -0
- data/spec/dummy/app/views/students/index.html.erb +1 -0
- data/spec/dummy/app/views/users/_user.html.erb +1 -1
- data/spec/dummy/config/application.rb +2 -0
- data/spec/dummy/config/environment.rb +1 -0
- data/spec/dummy/config/routes.rb +9 -5
- data/spec/dummy/db/.gitignore +1 -0
- data/spec/dummy/db/migrate/20121119085620_devise_create_users.rb +1 -1
- data/spec/dummy/db/migrate/20140418160449_create_admin_users.rb +1 -1
- data/spec/dummy/db/migrate/20191022100000_create_students.rb +14 -0
- data/spec/dummy/db/schema.rb +37 -31
- data/spec/models/user_spec.rb +3 -30
- data/spec/orm/active_record.rb +5 -2
- data/spec/spec_helper.rb +3 -3
- data/spec/support/factories.rb +13 -9
- metadata +57 -19
- data/lib/devise_masquerade/model.rb +0 -42
- data/spec/controllers/masquerades_controller_spec.rb +0 -42
- 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
|