devise_masquerade 0.6.4 → 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/controllers/helpers.rb +27 -8
- data/lib/devise_masquerade/controllers/url_helpers.rb +18 -4
- data/lib/devise_masquerade/models/masqueradable.rb +13 -0
- data/lib/devise_masquerade/models.rb +9 -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/lib/devise_masquerade.rb +3 -9
- 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
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_masquerade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Korsak
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,42 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.2.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.2.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: devise
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 4.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 4.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: globalid
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.3.6
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.3.6
|
55
69
|
description: devise masquerade library
|
56
70
|
email:
|
57
71
|
- alex.korsak@gmail.com
|
@@ -59,12 +73,16 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".github/FUNDING.yml"
|
77
|
+
- ".github/workflows/brakeman-analysis.yml"
|
78
|
+
- ".github/workflows/rubocop-analysis.yml"
|
62
79
|
- ".gitignore"
|
63
80
|
- ".rspec"
|
64
81
|
- ".ruby-version"
|
65
82
|
- ".rvmrc"
|
66
83
|
- ".travis.yml"
|
67
84
|
- Gemfile
|
85
|
+
- Gemfile.lock
|
68
86
|
- Guardfile
|
69
87
|
- LICENSE.txt
|
70
88
|
- Makefile
|
@@ -74,13 +92,17 @@ files:
|
|
74
92
|
- config/environment.rb
|
75
93
|
- devise_masquerade.gemspec
|
76
94
|
- features/back.feature
|
95
|
+
- features/multiple_masquerading_models.feature
|
77
96
|
- features/step_definitions/auth_steps.rb
|
78
97
|
- features/step_definitions/back_steps.rb
|
98
|
+
- features/step_definitions/url_helpers_steps.rb
|
79
99
|
- features/support/env.rb
|
100
|
+
- features/url_helpers.feature
|
80
101
|
- lib/devise_masquerade.rb
|
81
102
|
- lib/devise_masquerade/controllers/helpers.rb
|
82
103
|
- lib/devise_masquerade/controllers/url_helpers.rb
|
83
|
-
- lib/devise_masquerade/
|
104
|
+
- lib/devise_masquerade/models.rb
|
105
|
+
- lib/devise_masquerade/models/masqueradable.rb
|
84
106
|
- lib/devise_masquerade/rails.rb
|
85
107
|
- lib/devise_masquerade/routes.rb
|
86
108
|
- lib/devise_masquerade/version.rb
|
@@ -88,20 +110,25 @@ files:
|
|
88
110
|
- spec/controllers/admin/dashboard_controller_spec.rb
|
89
111
|
- spec/controllers/dashboard_controller_spec.rb
|
90
112
|
- spec/controllers/devise/masquerades_controller_spec.rb
|
91
|
-
- spec/controllers/
|
113
|
+
- spec/controllers/masquerades_tests_controller_spec.rb
|
92
114
|
- spec/dummy/Rakefile
|
93
115
|
- spec/dummy/app/controllers/admin/dashboard_controller.rb
|
94
116
|
- spec/dummy/app/controllers/application_controller.rb
|
95
117
|
- spec/dummy/app/controllers/dashboard_controller.rb
|
96
|
-
- spec/dummy/app/controllers/
|
118
|
+
- spec/dummy/app/controllers/masquerades_tests_controller.rb
|
119
|
+
- spec/dummy/app/controllers/students_controller.rb
|
97
120
|
- spec/dummy/app/controllers/users/masquerades_controller.rb
|
98
121
|
- spec/dummy/app/helpers/application_helper.rb
|
99
122
|
- spec/dummy/app/models/admin.rb
|
100
123
|
- spec/dummy/app/models/admin/user.rb
|
124
|
+
- spec/dummy/app/models/student.rb
|
101
125
|
- spec/dummy/app/models/user.rb
|
102
126
|
- spec/dummy/app/views/admin/dashboard/index.html.erb
|
127
|
+
- spec/dummy/app/views/dashboard/extra_params.html.erb
|
103
128
|
- spec/dummy/app/views/dashboard/index.html.erb
|
104
129
|
- spec/dummy/app/views/layouts/application.html.erb
|
130
|
+
- spec/dummy/app/views/students/_student.html.erb
|
131
|
+
- spec/dummy/app/views/students/index.html.erb
|
105
132
|
- spec/dummy/app/views/users/_user.html.erb
|
106
133
|
- spec/dummy/config.ru
|
107
134
|
- spec/dummy/config/application.rb
|
@@ -120,8 +147,10 @@ files:
|
|
120
147
|
- spec/dummy/config/locales/devise.en.yml
|
121
148
|
- spec/dummy/config/locales/en.yml
|
122
149
|
- spec/dummy/config/routes.rb
|
150
|
+
- spec/dummy/db/.gitignore
|
123
151
|
- spec/dummy/db/migrate/20121119085620_devise_create_users.rb
|
124
152
|
- spec/dummy/db/migrate/20140418160449_create_admin_users.rb
|
153
|
+
- spec/dummy/db/migrate/20191022100000_create_students.rb
|
125
154
|
- spec/dummy/db/schema.rb
|
126
155
|
- spec/dummy/db/seeds.rb
|
127
156
|
- spec/dummy/public/.empty
|
@@ -131,11 +160,11 @@ files:
|
|
131
160
|
- spec/spec_helper.rb
|
132
161
|
- spec/support/authentication.rb
|
133
162
|
- spec/support/factories.rb
|
134
|
-
homepage: http://github.com/oivoodoo/devise_masquerade
|
163
|
+
homepage: http://github.com/oivoodoo/devise_masquerade
|
135
164
|
licenses:
|
136
165
|
- MIT
|
137
166
|
metadata: {}
|
138
|
-
post_install_message:
|
167
|
+
post_install_message:
|
139
168
|
rdoc_options: []
|
140
169
|
require_paths:
|
141
170
|
- lib
|
@@ -150,33 +179,40 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
179
|
- !ruby/object:Gem::Version
|
151
180
|
version: '0'
|
152
181
|
requirements: []
|
153
|
-
|
154
|
-
|
155
|
-
signing_key:
|
182
|
+
rubygems_version: 3.1.4
|
183
|
+
signing_key:
|
156
184
|
specification_version: 4
|
157
185
|
summary: use for login as functionallity on your admin users pages
|
158
186
|
test_files:
|
159
187
|
- features/back.feature
|
188
|
+
- features/multiple_masquerading_models.feature
|
160
189
|
- features/step_definitions/auth_steps.rb
|
161
190
|
- features/step_definitions/back_steps.rb
|
191
|
+
- features/step_definitions/url_helpers_steps.rb
|
162
192
|
- features/support/env.rb
|
193
|
+
- features/url_helpers.feature
|
163
194
|
- spec/controllers/admin/dashboard_controller_spec.rb
|
164
195
|
- spec/controllers/dashboard_controller_spec.rb
|
165
196
|
- spec/controllers/devise/masquerades_controller_spec.rb
|
166
|
-
- spec/controllers/
|
197
|
+
- spec/controllers/masquerades_tests_controller_spec.rb
|
167
198
|
- spec/dummy/Rakefile
|
168
199
|
- spec/dummy/app/controllers/admin/dashboard_controller.rb
|
169
200
|
- spec/dummy/app/controllers/application_controller.rb
|
170
201
|
- spec/dummy/app/controllers/dashboard_controller.rb
|
171
|
-
- spec/dummy/app/controllers/
|
202
|
+
- spec/dummy/app/controllers/masquerades_tests_controller.rb
|
203
|
+
- spec/dummy/app/controllers/students_controller.rb
|
172
204
|
- spec/dummy/app/controllers/users/masquerades_controller.rb
|
173
205
|
- spec/dummy/app/helpers/application_helper.rb
|
174
206
|
- spec/dummy/app/models/admin.rb
|
175
207
|
- spec/dummy/app/models/admin/user.rb
|
208
|
+
- spec/dummy/app/models/student.rb
|
176
209
|
- spec/dummy/app/models/user.rb
|
177
210
|
- spec/dummy/app/views/admin/dashboard/index.html.erb
|
211
|
+
- spec/dummy/app/views/dashboard/extra_params.html.erb
|
178
212
|
- spec/dummy/app/views/dashboard/index.html.erb
|
179
213
|
- spec/dummy/app/views/layouts/application.html.erb
|
214
|
+
- spec/dummy/app/views/students/_student.html.erb
|
215
|
+
- spec/dummy/app/views/students/index.html.erb
|
180
216
|
- spec/dummy/app/views/users/_user.html.erb
|
181
217
|
- spec/dummy/config.ru
|
182
218
|
- spec/dummy/config/application.rb
|
@@ -195,8 +231,10 @@ test_files:
|
|
195
231
|
- spec/dummy/config/locales/devise.en.yml
|
196
232
|
- spec/dummy/config/locales/en.yml
|
197
233
|
- spec/dummy/config/routes.rb
|
234
|
+
- spec/dummy/db/.gitignore
|
198
235
|
- spec/dummy/db/migrate/20121119085620_devise_create_users.rb
|
199
236
|
- spec/dummy/db/migrate/20140418160449_create_admin_users.rb
|
237
|
+
- spec/dummy/db/migrate/20191022100000_create_students.rb
|
200
238
|
- spec/dummy/db/schema.rb
|
201
239
|
- spec/dummy/db/seeds.rb
|
202
240
|
- spec/dummy/public/.empty
|
@@ -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
|