clearance 1.17.0 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of clearance might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/Gemfile +3 -4
- data/Gemfile.lock +7 -8
- data/NEWS.md +161 -15
- data/app/controllers/clearance/passwords_controller.rb +15 -43
- data/app/controllers/clearance/sessions_controller.rb +3 -18
- data/app/controllers/clearance/users_controller.rb +2 -17
- data/clearance.gemspec +5 -5
- data/gemfiles/rails_4.2.gemfile +3 -4
- data/gemfiles/rails_5.0.gemfile +3 -4
- data/gemfiles/rails_5.1.gemfile +3 -4
- data/gemfiles/rails_5.2.gemfile +3 -4
- data/lib/clearance.rb +0 -8
- data/lib/clearance/authentication.rb +0 -8
- data/lib/clearance/authorization.rb +2 -11
- data/lib/clearance/session.rb +1 -9
- data/lib/clearance/testing/deny_access_matcher.rb +12 -18
- data/lib/clearance/user.rb +0 -21
- data/lib/clearance/version.rb +1 -1
- data/lib/generators/clearance/install/install_generator.rb +1 -5
- data/spec/clearance/session_spec.rb +0 -31
- data/spec/controllers/apis_controller_spec.rb +1 -5
- data/spec/controllers/forgeries_controller_spec.rb +1 -5
- data/spec/controllers/passwords_controller_spec.rb +5 -5
- data/spec/controllers/permissions_controller_spec.rb +2 -6
- data/spec/controllers/sessions_controller_spec.rb +1 -1
- data/spec/dummy/application.rb +1 -3
- data/spec/generators/clearance/install/install_generator_spec.rb +3 -10
- metadata +13 -21
- data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +0 -77
- data/lib/clearance/password_strategies/blowfish.rb +0 -61
- data/lib/clearance/password_strategies/sha1.rb +0 -59
- data/lib/clearance/testing.rb +0 -11
- data/lib/clearance/testing/helpers.rb +0 -15
- data/spec/password_strategies/bcrypt_migration_from_sha1_spec.rb +0 -122
- data/spec/password_strategies/blowfish_spec.rb +0 -61
- data/spec/password_strategies/sha1_spec.rb +0 -59
data/lib/clearance/version.rb
CHANGED
@@ -102,11 +102,7 @@ module Clearance
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def users_table_exists?
|
105
|
-
|
106
|
-
ActiveRecord::Base.connection.data_source_exists?(:users)
|
107
|
-
else
|
108
|
-
ActiveRecord::Base.connection.table_exists?(:users)
|
109
|
-
end
|
105
|
+
ActiveRecord::Base.connection.data_source_exists?(:users)
|
110
106
|
end
|
111
107
|
|
112
108
|
def existing_users_columns
|
@@ -186,37 +186,6 @@ describe Clearance::Session do
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
context 'configured with lambda taking no arguments' do
|
190
|
-
it 'logs a deprecation warning' do
|
191
|
-
expiration = -> { Time.now }
|
192
|
-
with_custom_expiration expiration do
|
193
|
-
session = Clearance::Session.new(env_without_remember_token)
|
194
|
-
session.sign_in user
|
195
|
-
allow(session).to receive(:warn)
|
196
|
-
session.add_cookie_to_headers headers
|
197
|
-
|
198
|
-
expect(session).to have_received(:warn).once
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
it 'is set to the value of the evaluated lambda' do
|
203
|
-
expires_at = -> { 1.day.from_now }
|
204
|
-
with_custom_expiration expires_at do
|
205
|
-
user = double("User", remember_token: "123abc")
|
206
|
-
headers = {}
|
207
|
-
session = Clearance::Session.new(env_without_remember_token)
|
208
|
-
session.sign_in user
|
209
|
-
allow(session).to receive(:warn)
|
210
|
-
session.add_cookie_to_headers headers
|
211
|
-
|
212
|
-
expect(headers).to set_cookie(
|
213
|
-
'remember_token',
|
214
|
-
user.remember_token, expires_at.call
|
215
|
-
)
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
189
|
context 'configured with lambda taking one argument' do
|
221
190
|
it 'it can use other cookies to set the value of the expires token' do
|
222
191
|
remembered_expires = 12.hours.from_now
|
@@ -3,11 +3,7 @@ require 'spec_helper'
|
|
3
3
|
class ApisController < ActionController::Base
|
4
4
|
include Clearance::Controller
|
5
5
|
|
6
|
-
|
7
|
-
before_action :require_login
|
8
|
-
else
|
9
|
-
before_filter :require_login
|
10
|
-
end
|
6
|
+
before_action :require_login
|
11
7
|
|
12
8
|
def show
|
13
9
|
head :ok
|
@@ -5,11 +5,7 @@ class ForgeriesController < ActionController::Base
|
|
5
5
|
|
6
6
|
protect_from_forgery
|
7
7
|
|
8
|
-
|
9
|
-
before_action :require_login
|
10
|
-
else
|
11
|
-
before_filter :require_login
|
12
|
-
end
|
8
|
+
before_action :require_login
|
13
9
|
|
14
10
|
# This is off in test by default, but we need it for this test
|
15
11
|
self.allow_forgery_protection = true
|
@@ -94,19 +94,19 @@ describe Clearance::PasswordsController do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
context "blank token is supplied" do
|
97
|
-
it "renders the new password reset form with a flash
|
97
|
+
it "renders the new password reset form with a flash alert" do
|
98
98
|
get :edit, params: {
|
99
99
|
user_id: 1,
|
100
100
|
token: "",
|
101
101
|
}
|
102
102
|
|
103
103
|
expect(response).to render_template(:new)
|
104
|
-
expect(flash.now[:
|
104
|
+
expect(flash.now[:alert]).to match(/double check the URL/i)
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
context "invalid token is supplied" do
|
109
|
-
it "renders the new password reset form with a flash
|
109
|
+
it "renders the new password reset form with a flash alert" do
|
110
110
|
user = create(:user, :with_forgotten_password)
|
111
111
|
|
112
112
|
get :edit, params: {
|
@@ -115,7 +115,7 @@ describe Clearance::PasswordsController do
|
|
115
115
|
}
|
116
116
|
|
117
117
|
expect(response).to render_template(:new)
|
118
|
-
expect(flash.now[:
|
118
|
+
expect(flash.now[:alert]).to match(/double check the URL/i)
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
@@ -174,7 +174,7 @@ describe Clearance::PasswordsController do
|
|
174
174
|
new_password: "",
|
175
175
|
)
|
176
176
|
|
177
|
-
expect(flash.now[:
|
177
|
+
expect(flash.now[:alert]).to match(/password can't be blank/i)
|
178
178
|
expect(response).to render_template(:edit)
|
179
179
|
expect(cookies[:remember_token]).to be_nil
|
180
180
|
end
|
@@ -3,11 +3,7 @@ require 'spec_helper'
|
|
3
3
|
class PermissionsController < ActionController::Base
|
4
4
|
include Clearance::Controller
|
5
5
|
|
6
|
-
|
7
|
-
before_action :require_login, only: :show
|
8
|
-
else
|
9
|
-
before_filter :require_login, only: :show
|
10
|
-
end
|
6
|
+
before_action :require_login, only: :show
|
11
7
|
|
12
8
|
def new
|
13
9
|
head :ok
|
@@ -62,7 +58,7 @@ describe PermissionsController do
|
|
62
58
|
it "denies access to show and display a flash message" do
|
63
59
|
get :show
|
64
60
|
|
65
|
-
expect(flash[:
|
61
|
+
expect(flash[:alert]).to match(/^Please sign in to continue/)
|
66
62
|
end
|
67
63
|
end
|
68
64
|
|
data/spec/dummy/application.rb
CHANGED
@@ -31,9 +31,7 @@ module Dummy
|
|
31
31
|
config.active_record.sqlite3.represent_boolean_as_integer = true
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
config.active_job.queue_adapter = :inline
|
36
|
-
end
|
34
|
+
config.active_job.queue_adapter = :inline
|
37
35
|
|
38
36
|
def require_environment!
|
39
37
|
initialize!
|
@@ -118,16 +118,9 @@ describe Clearance::Generators::InstallGenerator, :generator do
|
|
118
118
|
|
119
119
|
def table_does_not_exist(name)
|
120
120
|
connection = ActiveRecord::Base.connection
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
with(name).
|
125
|
-
and_return(false)
|
126
|
-
else
|
127
|
-
allow(connection).to receive(:table_exists?).
|
128
|
-
with(name).
|
129
|
-
and_return(false)
|
130
|
-
end
|
121
|
+
allow(connection).to receive(:data_source_exists?).
|
122
|
+
with(name).
|
123
|
+
and_return(false)
|
131
124
|
end
|
132
125
|
|
133
126
|
def contain_models_inherit_from
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clearance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Croak
|
@@ -25,7 +25,7 @@ authors:
|
|
25
25
|
autorequire:
|
26
26
|
bindir: bin
|
27
27
|
cert_chain: []
|
28
|
-
date: 2019-04-
|
28
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
29
29
|
dependencies:
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bcrypt
|
@@ -61,56 +61,56 @@ dependencies:
|
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '4.2'
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
71
|
+
version: '4.2'
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: activemodel
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
78
|
+
version: '4.2'
|
79
79
|
type: :runtime
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
85
|
+
version: '4.2'
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: activerecord
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
92
|
+
version: '4.2'
|
93
93
|
type: :runtime
|
94
94
|
prerelease: false
|
95
95
|
version_requirements: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: '
|
99
|
+
version: '4.2'
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: actionmailer
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '
|
106
|
+
version: '4.2'
|
107
107
|
type: :runtime
|
108
108
|
prerelease: false
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: '
|
113
|
+
version: '4.2'
|
114
114
|
description: Rails authentication & authorization with email & password.
|
115
115
|
email: support@thoughtbot.com
|
116
116
|
executables: []
|
@@ -171,19 +171,14 @@ files:
|
|
171
171
|
- lib/clearance/engine.rb
|
172
172
|
- lib/clearance/password_strategies.rb
|
173
173
|
- lib/clearance/password_strategies/bcrypt.rb
|
174
|
-
- lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb
|
175
|
-
- lib/clearance/password_strategies/blowfish.rb
|
176
|
-
- lib/clearance/password_strategies/sha1.rb
|
177
174
|
- lib/clearance/rack_session.rb
|
178
175
|
- lib/clearance/rspec.rb
|
179
176
|
- lib/clearance/session.rb
|
180
177
|
- lib/clearance/session_status.rb
|
181
178
|
- lib/clearance/sign_in_guard.rb
|
182
179
|
- lib/clearance/test_unit.rb
|
183
|
-
- lib/clearance/testing.rb
|
184
180
|
- lib/clearance/testing/controller_helpers.rb
|
185
181
|
- lib/clearance/testing/deny_access_matcher.rb
|
186
|
-
- lib/clearance/testing/helpers.rb
|
187
182
|
- lib/clearance/testing/view_helpers.rb
|
188
183
|
- lib/clearance/token.rb
|
189
184
|
- lib/clearance/user.rb
|
@@ -250,11 +245,8 @@ files:
|
|
250
245
|
- spec/helpers/helper_helpers_spec.rb
|
251
246
|
- spec/mailers/clearance_mailer_spec.rb
|
252
247
|
- spec/models/user_spec.rb
|
253
|
-
- spec/password_strategies/bcrypt_migration_from_sha1_spec.rb
|
254
248
|
- spec/password_strategies/bcrypt_spec.rb
|
255
|
-
- spec/password_strategies/blowfish_spec.rb
|
256
249
|
- spec/password_strategies/password_strategies_spec.rb
|
257
|
-
- spec/password_strategies/sha1_spec.rb
|
258
250
|
- spec/requests/cookie_options_spec.rb
|
259
251
|
- spec/requests/csrf_rotation_spec.rb
|
260
252
|
- spec/requests/password_maintenance_spec.rb
|
@@ -283,12 +275,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
283
275
|
requirements:
|
284
276
|
- - ">="
|
285
277
|
- !ruby/object:Gem::Version
|
286
|
-
version:
|
278
|
+
version: 2.3.0
|
287
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
288
280
|
requirements:
|
289
|
-
- - "
|
281
|
+
- - ">"
|
290
282
|
- !ruby/object:Gem::Version
|
291
|
-
version:
|
283
|
+
version: 1.3.1
|
292
284
|
requirements: []
|
293
285
|
rubygems_version: 3.0.3
|
294
286
|
signing_key:
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module Clearance
|
2
|
-
module PasswordStrategies
|
3
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies` gem
|
4
|
-
module BCryptMigrationFromSHA1
|
5
|
-
DEPRECATION_MESSAGE = "[DEPRECATION] The BCryptMigrationFromSha1 " \
|
6
|
-
"password strategy has been deprecated and will be removed from " \
|
7
|
-
"Clearance 2.0. BCrypt is the only officially supported strategy, " \
|
8
|
-
"though you are free to provide your own. To continue using this " \
|
9
|
-
"strategy, add clearance-deprecated_password_strategies to your " \
|
10
|
-
"Gemfile."
|
11
|
-
|
12
|
-
# @api private
|
13
|
-
class BCryptUser
|
14
|
-
include Clearance::PasswordStrategies::BCrypt
|
15
|
-
|
16
|
-
def initialize(user)
|
17
|
-
@user = user
|
18
|
-
end
|
19
|
-
|
20
|
-
delegate :encrypted_password, :encrypted_password=, to: :@user
|
21
|
-
end
|
22
|
-
|
23
|
-
# @api private
|
24
|
-
class SHA1User
|
25
|
-
include Clearance::PasswordStrategies::SHA1
|
26
|
-
|
27
|
-
def initialize(user)
|
28
|
-
@user = user
|
29
|
-
end
|
30
|
-
|
31
|
-
delegate :salt, :salt=, :encrypted_password, :encrypted_password=, to: :@user
|
32
|
-
end
|
33
|
-
|
34
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
|
35
|
-
# gem
|
36
|
-
def authenticated?(password)
|
37
|
-
warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
|
38
|
-
authenticated_with_sha1?(password) || authenticated_with_bcrypt?(password)
|
39
|
-
end
|
40
|
-
|
41
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
|
42
|
-
# gem
|
43
|
-
def password=(new_password)
|
44
|
-
warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
|
45
|
-
@password = new_password
|
46
|
-
BCryptUser.new(self).password = new_password
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
# @api private
|
52
|
-
def authenticated_with_bcrypt?(password)
|
53
|
-
begin
|
54
|
-
BCryptUser.new(self).authenticated? password
|
55
|
-
rescue ::BCrypt::Errors::InvalidHash
|
56
|
-
false
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# @api private
|
61
|
-
def authenticated_with_sha1?(password)
|
62
|
-
if sha1_password?
|
63
|
-
if SHA1User.new(self).authenticated? password
|
64
|
-
self.password = password
|
65
|
-
self.save
|
66
|
-
true
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# @api private
|
72
|
-
def sha1_password?
|
73
|
-
self.encrypted_password =~ /^[a-f0-9]{40}$/
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'openssl'
|
2
|
-
require 'base64'
|
3
|
-
|
4
|
-
module Clearance
|
5
|
-
module PasswordStrategies
|
6
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies` gem
|
7
|
-
module Blowfish
|
8
|
-
DEPRECATION_MESSAGE = "[DEPRECATION] The Blowfish password strategy " \
|
9
|
-
"has been deprecated and will be removed from Clearance 2.0. BCrypt " \
|
10
|
-
"is the only officially supported strategy, though you are free to " \
|
11
|
-
"provide your own. To continue using this strategy add " \
|
12
|
-
"clearance-deprecated_password_strategies to your Gemfile."
|
13
|
-
|
14
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
|
15
|
-
# gem
|
16
|
-
def authenticated?(password)
|
17
|
-
warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
|
18
|
-
encrypted_password == encrypt(password)
|
19
|
-
end
|
20
|
-
|
21
|
-
# @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
|
22
|
-
# gem
|
23
|
-
def password=(new_password)
|
24
|
-
warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
|
25
|
-
@password = new_password
|
26
|
-
initialize_salt_if_necessary
|
27
|
-
|
28
|
-
if new_password.present?
|
29
|
-
self.encrypted_password = encrypt(new_password)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
# @api private
|
36
|
-
def encrypt(string)
|
37
|
-
generate_hash("--#{salt}--#{string}--")
|
38
|
-
end
|
39
|
-
|
40
|
-
# @api private
|
41
|
-
def generate_hash(string)
|
42
|
-
cipher = OpenSSL::Cipher::Cipher.new('bf-cbc').encrypt
|
43
|
-
cipher.key = Digest::SHA256.digest(salt).first(16)
|
44
|
-
hash = cipher.update(string) << cipher.final
|
45
|
-
Base64.encode64(hash).encode('utf-8')
|
46
|
-
end
|
47
|
-
|
48
|
-
# @api private
|
49
|
-
def initialize_salt_if_necessary
|
50
|
-
if salt.blank?
|
51
|
-
self.salt = generate_salt
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# @api private
|
56
|
-
def generate_salt
|
57
|
-
Base64.encode64(SecureRandom.hex(20)).encode('utf-8')
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|