clearance 1.0.0.rc4 → 1.0.0.rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +15 -0
- data/.travis.yml +14 -3
- data/Appraisals +7 -1
- data/Gemfile.lock +33 -26
- data/LICENSE +1 -1
- data/NEWS.md +13 -10
- data/README.md +44 -37
- data/Rakefile +3 -0
- data/app/controllers/clearance/passwords_controller.rb +6 -2
- data/app/views/clearance_mailer/change_password.html.erb +2 -2
- data/app/views/passwords/create.html.erb +3 -1
- data/app/views/passwords/edit.html.erb +15 -13
- data/app/views/passwords/new.html.erb +13 -11
- data/app/views/sessions/_form.html.erb +8 -3
- data/app/views/sessions/new.html.erb +4 -11
- data/app/views/users/_form.html.erb +2 -2
- data/app/views/users/new.html.erb +14 -5
- data/clearance.gemspec +5 -3
- data/config/locales/clearance.en.yml +53 -23
- data/config/routes.rb +3 -3
- data/gemfiles/{3.0.17.gemfile → 3.0.20.gemfile} +1 -1
- data/gemfiles/{3.0.17.gemfile.lock → 3.0.20.gemfile.lock} +62 -57
- data/gemfiles/{3.2.8.gemfile → 3.1.11.gemfile} +1 -1
- data/gemfiles/{3.1.8.gemfile.lock → 3.1.11.gemfile.lock} +70 -65
- data/gemfiles/{3.1.8.gemfile → 3.2.12.gemfile} +1 -1
- data/gemfiles/{3.2.8.gemfile.lock → 3.2.12.gemfile.lock} +74 -68
- data/gemfiles/3.2.13.rc2.gemfile +7 -0
- data/gemfiles/3.2.13.rc2.gemfile.lock +182 -0
- data/lib/clearance.rb +2 -1
- data/lib/clearance/authentication.rb +8 -53
- data/lib/clearance/authorization.rb +62 -0
- data/lib/clearance/back_door.rb +42 -0
- data/lib/clearance/controller.rb +11 -0
- data/lib/clearance/password_strategies/bcrypt.rb +13 -1
- data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +1 -0
- data/lib/clearance/password_strategies/blowfish.rb +5 -1
- data/lib/clearance/password_strategies/sha1.rb +5 -1
- data/lib/clearance/testing.rb +1 -1
- data/lib/clearance/testing/app/controllers/application_controller.rb +1 -1
- data/lib/clearance/user.rb +23 -10
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/install/install_generator.rb +1 -1
- data/lib/generators/clearance/specs/templates/support/integration.rb +2 -0
- data/spec/clearance/back_door_spec.rb +39 -0
- data/spec/controllers/denies_controller_spec.rb +3 -2
- data/spec/controllers/flashes_controller_spec.rb +3 -3
- data/spec/controllers/forgeries_controller_spec.rb +3 -2
- data/spec/controllers/passwords_controller_spec.rb +14 -0
- data/spec/mailers/clearance_mailer_spec.rb +9 -1
- data/spec/models/bcrypt_migration_from_sha1_spec.rb +10 -9
- data/spec/models/bcrypt_spec.rb +21 -7
- data/spec/models/blowfish_spec.rb +1 -6
- data/spec/models/password_strategies_spec.rb +9 -3
- data/spec/models/sha1_spec.rb +1 -6
- data/spec/models/user_spec.rb +19 -9
- data/spec/support/clearance.rb +1 -1
- data/spec/support/fake_model_with_password_strategy.rb +14 -0
- metadata +54 -47
@@ -0,0 +1,182 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
clearance (1.0.0.rc5)
|
5
|
+
bcrypt-ruby
|
6
|
+
email_validator
|
7
|
+
rails (>= 3.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionmailer (3.2.13.rc2)
|
13
|
+
actionpack (= 3.2.13.rc2)
|
14
|
+
mail (~> 2.5.3)
|
15
|
+
actionpack (3.2.13.rc2)
|
16
|
+
activemodel (= 3.2.13.rc2)
|
17
|
+
activesupport (= 3.2.13.rc2)
|
18
|
+
builder (~> 3.0.0)
|
19
|
+
erubis (~> 2.7.0)
|
20
|
+
journey (~> 1.0.4)
|
21
|
+
rack (~> 1.4.5)
|
22
|
+
rack-cache (~> 1.2)
|
23
|
+
rack-test (~> 0.6.1)
|
24
|
+
sprockets (~> 2.2.1)
|
25
|
+
activemodel (3.2.13.rc2)
|
26
|
+
activesupport (= 3.2.13.rc2)
|
27
|
+
builder (~> 3.0.0)
|
28
|
+
activerecord (3.2.13.rc2)
|
29
|
+
activemodel (= 3.2.13.rc2)
|
30
|
+
activesupport (= 3.2.13.rc2)
|
31
|
+
arel (~> 3.0.2)
|
32
|
+
tzinfo (~> 0.3.29)
|
33
|
+
activeresource (3.2.13.rc2)
|
34
|
+
activemodel (= 3.2.13.rc2)
|
35
|
+
activesupport (= 3.2.13.rc2)
|
36
|
+
activesupport (3.2.13.rc2)
|
37
|
+
i18n (= 0.6.1)
|
38
|
+
multi_json (~> 1.0)
|
39
|
+
appraisal (0.4.1)
|
40
|
+
bundler
|
41
|
+
rake
|
42
|
+
arel (3.0.2)
|
43
|
+
aruba (0.4.11)
|
44
|
+
childprocess (>= 0.2.3)
|
45
|
+
cucumber (>= 1.1.1)
|
46
|
+
ffi (>= 1.0.11)
|
47
|
+
rspec (>= 2.7.0)
|
48
|
+
bcrypt-ruby (3.0.1)
|
49
|
+
bourne (1.3.0)
|
50
|
+
mocha (= 0.13.0)
|
51
|
+
builder (3.0.4)
|
52
|
+
capybara (1.1.2)
|
53
|
+
mime-types (>= 1.16)
|
54
|
+
nokogiri (>= 1.3.3)
|
55
|
+
rack (>= 1.0.0)
|
56
|
+
rack-test (>= 0.5.4)
|
57
|
+
selenium-webdriver (~> 2.0)
|
58
|
+
xpath (~> 0.1.4)
|
59
|
+
childprocess (0.3.9)
|
60
|
+
ffi (~> 1.0, >= 1.0.11)
|
61
|
+
cucumber (1.2.3)
|
62
|
+
builder (>= 2.1.2)
|
63
|
+
diff-lcs (>= 1.1.3)
|
64
|
+
gherkin (~> 2.11.6)
|
65
|
+
multi_json (~> 1.3)
|
66
|
+
cucumber-rails (1.1.1)
|
67
|
+
capybara (>= 1.1.1)
|
68
|
+
cucumber (>= 1.1.0)
|
69
|
+
nokogiri (>= 1.5.0)
|
70
|
+
database_cleaner (0.8.0)
|
71
|
+
diff-lcs (1.1.3)
|
72
|
+
email_validator (1.3.0)
|
73
|
+
activemodel
|
74
|
+
erubis (2.7.0)
|
75
|
+
factory_girl (3.5.0)
|
76
|
+
activesupport (>= 3.0.0)
|
77
|
+
factory_girl_rails (3.5.0)
|
78
|
+
factory_girl (~> 3.5.0)
|
79
|
+
railties (>= 3.0.0)
|
80
|
+
ffi (1.4.0)
|
81
|
+
gherkin (2.11.6)
|
82
|
+
json (>= 1.7.6)
|
83
|
+
hike (1.2.1)
|
84
|
+
i18n (0.6.1)
|
85
|
+
journey (1.0.4)
|
86
|
+
json (1.7.7)
|
87
|
+
mail (2.5.3)
|
88
|
+
i18n (>= 0.4.0)
|
89
|
+
mime-types (~> 1.16)
|
90
|
+
treetop (~> 1.4.8)
|
91
|
+
metaclass (0.0.1)
|
92
|
+
mime-types (1.21)
|
93
|
+
mocha (0.13.0)
|
94
|
+
metaclass (~> 0.0.1)
|
95
|
+
multi_json (1.6.1)
|
96
|
+
nokogiri (1.5.6)
|
97
|
+
polyglot (0.3.3)
|
98
|
+
psych (1.3.4)
|
99
|
+
rack (1.4.5)
|
100
|
+
rack-cache (1.2)
|
101
|
+
rack (>= 0.4)
|
102
|
+
rack-ssl (1.3.3)
|
103
|
+
rack
|
104
|
+
rack-test (0.6.2)
|
105
|
+
rack (>= 1.0)
|
106
|
+
rails (3.2.13.rc2)
|
107
|
+
actionmailer (= 3.2.13.rc2)
|
108
|
+
actionpack (= 3.2.13.rc2)
|
109
|
+
activerecord (= 3.2.13.rc2)
|
110
|
+
activeresource (= 3.2.13.rc2)
|
111
|
+
activesupport (= 3.2.13.rc2)
|
112
|
+
bundler (~> 1.0)
|
113
|
+
railties (= 3.2.13.rc2)
|
114
|
+
railties (3.2.13.rc2)
|
115
|
+
actionpack (= 3.2.13.rc2)
|
116
|
+
activesupport (= 3.2.13.rc2)
|
117
|
+
rack-ssl (~> 1.3.2)
|
118
|
+
rake (>= 0.8.7)
|
119
|
+
rdoc (~> 3.4)
|
120
|
+
thor (>= 0.14.6, < 2.0)
|
121
|
+
rake (10.0.3)
|
122
|
+
rdoc (3.12.2)
|
123
|
+
json (~> 1.4)
|
124
|
+
rspec (2.12.0)
|
125
|
+
rspec-core (~> 2.12.0)
|
126
|
+
rspec-expectations (~> 2.12.0)
|
127
|
+
rspec-mocks (~> 2.12.0)
|
128
|
+
rspec-core (2.12.2)
|
129
|
+
rspec-expectations (2.12.1)
|
130
|
+
diff-lcs (~> 1.1.3)
|
131
|
+
rspec-mocks (2.12.2)
|
132
|
+
rspec-rails (2.12.2)
|
133
|
+
actionpack (>= 3.0)
|
134
|
+
activesupport (>= 3.0)
|
135
|
+
railties (>= 3.0)
|
136
|
+
rspec-core (~> 2.12.0)
|
137
|
+
rspec-expectations (~> 2.12.0)
|
138
|
+
rspec-mocks (~> 2.12.0)
|
139
|
+
rubyzip (0.9.9)
|
140
|
+
selenium-webdriver (2.31.0)
|
141
|
+
childprocess (>= 0.2.5)
|
142
|
+
multi_json (~> 1.0)
|
143
|
+
rubyzip
|
144
|
+
websocket (~> 1.0.4)
|
145
|
+
shoulda-matchers (1.2.0)
|
146
|
+
activesupport (>= 3.0.0)
|
147
|
+
sprockets (2.2.2)
|
148
|
+
hike (~> 1.2)
|
149
|
+
multi_json (~> 1.0)
|
150
|
+
rack (~> 1.0)
|
151
|
+
tilt (~> 1.1, != 1.3.0)
|
152
|
+
sqlite3 (1.3.6)
|
153
|
+
thor (0.17.0)
|
154
|
+
tilt (1.3.5)
|
155
|
+
timecop (0.3.5)
|
156
|
+
treetop (1.4.12)
|
157
|
+
polyglot
|
158
|
+
polyglot (>= 0.3.1)
|
159
|
+
tzinfo (0.3.37)
|
160
|
+
websocket (1.0.7)
|
161
|
+
xpath (0.1.4)
|
162
|
+
nokogiri (~> 1.3)
|
163
|
+
|
164
|
+
PLATFORMS
|
165
|
+
ruby
|
166
|
+
|
167
|
+
DEPENDENCIES
|
168
|
+
appraisal (= 0.4.1)
|
169
|
+
aruba (= 0.4.11)
|
170
|
+
bourne (= 1.3.0)
|
171
|
+
bundler (~> 1.1)
|
172
|
+
capybara (= 1.1.2)
|
173
|
+
clearance!
|
174
|
+
cucumber-rails (= 1.1.1)
|
175
|
+
database_cleaner (= 0.8.0)
|
176
|
+
factory_girl_rails (= 3.5.0)
|
177
|
+
psych (~> 1.3.4)
|
178
|
+
rails (= 3.2.13.rc2)
|
179
|
+
rspec-rails (= 2.12.2)
|
180
|
+
shoulda-matchers (= 1.2.0)
|
181
|
+
sqlite3 (= 1.3.6)
|
182
|
+
timecop (= 0.3.5)
|
data/lib/clearance.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'clearance/configuration'
|
2
2
|
require 'clearance/session'
|
3
3
|
require 'clearance/rack_session'
|
4
|
-
require 'clearance/
|
4
|
+
require 'clearance/back_door'
|
5
|
+
require 'clearance/controller'
|
5
6
|
require 'clearance/user'
|
6
7
|
require 'clearance/engine'
|
7
8
|
require 'clearance/password_strategies'
|
@@ -4,8 +4,14 @@ module Clearance
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
helper_method :current_user, :signed_in?, :signed_out?
|
7
|
-
hide_action
|
8
|
-
:
|
7
|
+
hide_action(
|
8
|
+
:current_user,
|
9
|
+
:current_user=,
|
10
|
+
:sign_in,
|
11
|
+
:sign_out,
|
12
|
+
:signed_in?,
|
13
|
+
:signed_out?
|
14
|
+
)
|
9
15
|
end
|
10
16
|
|
11
17
|
def authenticate(params)
|
@@ -14,12 +20,6 @@ module Clearance
|
|
14
20
|
)
|
15
21
|
end
|
16
22
|
|
17
|
-
def authorize
|
18
|
-
unless signed_in?
|
19
|
-
deny_access
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
23
|
def current_user
|
24
24
|
clearance_session.current_user
|
25
25
|
end
|
@@ -28,20 +28,6 @@ module Clearance
|
|
28
28
|
clearance_session.sign_in user
|
29
29
|
end
|
30
30
|
|
31
|
-
def deny_access(flash_message = nil)
|
32
|
-
store_location
|
33
|
-
|
34
|
-
if flash_message
|
35
|
-
flash[:notice] = flash_message
|
36
|
-
end
|
37
|
-
|
38
|
-
if signed_in?
|
39
|
-
redirect_to url_after_denied_access_when_signed_in
|
40
|
-
else
|
41
|
-
redirect_to url_after_denied_access_when_signed_out
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
31
|
def sign_in(user)
|
46
32
|
clearance_session.sign_in user
|
47
33
|
end
|
@@ -67,39 +53,8 @@ module Clearance
|
|
67
53
|
|
68
54
|
protected
|
69
55
|
|
70
|
-
def clear_return_to
|
71
|
-
session[:return_to] = nil
|
72
|
-
end
|
73
|
-
|
74
56
|
def clearance_session
|
75
57
|
request.env[:clearance]
|
76
58
|
end
|
77
|
-
|
78
|
-
def store_location
|
79
|
-
if request.get?
|
80
|
-
session[:return_to] = request.fullpath
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def redirect_back_or(default)
|
85
|
-
redirect_to(return_to || default)
|
86
|
-
clear_return_to
|
87
|
-
end
|
88
|
-
|
89
|
-
def redirect_to_root
|
90
|
-
redirect_to('/')
|
91
|
-
end
|
92
|
-
|
93
|
-
def return_to
|
94
|
-
session[:return_to] || params[:return_to]
|
95
|
-
end
|
96
|
-
|
97
|
-
def url_after_denied_access_when_signed_in
|
98
|
-
'/'
|
99
|
-
end
|
100
|
-
|
101
|
-
def url_after_denied_access_when_signed_out
|
102
|
-
sign_in_url
|
103
|
-
end
|
104
59
|
end
|
105
60
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Clearance
|
2
|
+
module Authorization
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
hide_action :authorize, :deny_access
|
7
|
+
end
|
8
|
+
|
9
|
+
def authorize
|
10
|
+
unless signed_in?
|
11
|
+
deny_access
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def deny_access(flash_message = nil)
|
16
|
+
store_location
|
17
|
+
|
18
|
+
if flash_message
|
19
|
+
flash[:notice] = flash_message
|
20
|
+
end
|
21
|
+
|
22
|
+
if signed_in?
|
23
|
+
redirect_to url_after_denied_access_when_signed_in
|
24
|
+
else
|
25
|
+
redirect_to url_after_denied_access_when_signed_out
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def clear_return_to
|
32
|
+
session[:return_to] = nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def store_location
|
36
|
+
if request.get?
|
37
|
+
session[:return_to] = request.fullpath
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def redirect_back_or(default)
|
42
|
+
redirect_to(return_to || default)
|
43
|
+
clear_return_to
|
44
|
+
end
|
45
|
+
|
46
|
+
def redirect_to_root
|
47
|
+
redirect_to('/')
|
48
|
+
end
|
49
|
+
|
50
|
+
def return_to
|
51
|
+
session[:return_to] || params[:return_to]
|
52
|
+
end
|
53
|
+
|
54
|
+
def url_after_denied_access_when_signed_in
|
55
|
+
'/'
|
56
|
+
end
|
57
|
+
|
58
|
+
def url_after_denied_access_when_signed_out
|
59
|
+
sign_in_url
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Clearance
|
2
|
+
# Middleware which allows signing in by passing as=USER_ID in a query
|
3
|
+
# parameter.
|
4
|
+
#
|
5
|
+
# Designed to eliminate time in integration tests wasted by visiting and
|
6
|
+
# submitting the sign in form.
|
7
|
+
#
|
8
|
+
# Configuration:
|
9
|
+
#
|
10
|
+
# # config/environments/test.rb
|
11
|
+
# MyRailsApp::Application.configure do
|
12
|
+
# # ...
|
13
|
+
# config.middleware.use ClearanceBackDoor
|
14
|
+
# # ...
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Usage:
|
18
|
+
#
|
19
|
+
# visit new_feedback_path(as: user)
|
20
|
+
class BackDoor
|
21
|
+
def initialize(app)
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
sign_in_through_the_back_door(env)
|
27
|
+
@app.call(env)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def sign_in_through_the_back_door(env)
|
33
|
+
params = Rack::Utils.parse_query(env['QUERY_STRING'])
|
34
|
+
user_id = params['as']
|
35
|
+
|
36
|
+
if user_id.present?
|
37
|
+
user = Clearance.configuration.user_model.find(user_id)
|
38
|
+
env[:clearance].sign_in(user)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -20,7 +20,19 @@ module Clearance
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def encrypt(password)
|
23
|
-
::BCrypt::Password.create(password)
|
23
|
+
::BCrypt::Password.create(password, :cost => cost)
|
24
|
+
end
|
25
|
+
|
26
|
+
def cost
|
27
|
+
if test_environment?
|
28
|
+
::BCrypt::Engine::MIN_COST
|
29
|
+
else
|
30
|
+
::BCrypt::Engine::DEFAULT_COST
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_environment?
|
35
|
+
defined?(::Rails) && ::Rails.env.test?
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|