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.

Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -4
  3. data/Gemfile +3 -4
  4. data/Gemfile.lock +7 -8
  5. data/NEWS.md +161 -15
  6. data/app/controllers/clearance/passwords_controller.rb +15 -43
  7. data/app/controllers/clearance/sessions_controller.rb +3 -18
  8. data/app/controllers/clearance/users_controller.rb +2 -17
  9. data/clearance.gemspec +5 -5
  10. data/gemfiles/rails_4.2.gemfile +3 -4
  11. data/gemfiles/rails_5.0.gemfile +3 -4
  12. data/gemfiles/rails_5.1.gemfile +3 -4
  13. data/gemfiles/rails_5.2.gemfile +3 -4
  14. data/lib/clearance.rb +0 -8
  15. data/lib/clearance/authentication.rb +0 -8
  16. data/lib/clearance/authorization.rb +2 -11
  17. data/lib/clearance/session.rb +1 -9
  18. data/lib/clearance/testing/deny_access_matcher.rb +12 -18
  19. data/lib/clearance/user.rb +0 -21
  20. data/lib/clearance/version.rb +1 -1
  21. data/lib/generators/clearance/install/install_generator.rb +1 -5
  22. data/spec/clearance/session_spec.rb +0 -31
  23. data/spec/controllers/apis_controller_spec.rb +1 -5
  24. data/spec/controllers/forgeries_controller_spec.rb +1 -5
  25. data/spec/controllers/passwords_controller_spec.rb +5 -5
  26. data/spec/controllers/permissions_controller_spec.rb +2 -6
  27. data/spec/controllers/sessions_controller_spec.rb +1 -1
  28. data/spec/dummy/application.rb +1 -3
  29. data/spec/generators/clearance/install/install_generator_spec.rb +3 -10
  30. metadata +13 -21
  31. data/lib/clearance/password_strategies/bcrypt_migration_from_sha1.rb +0 -77
  32. data/lib/clearance/password_strategies/blowfish.rb +0 -61
  33. data/lib/clearance/password_strategies/sha1.rb +0 -59
  34. data/lib/clearance/testing.rb +0 -11
  35. data/lib/clearance/testing/helpers.rb +0 -15
  36. data/spec/password_strategies/bcrypt_migration_from_sha1_spec.rb +0 -122
  37. data/spec/password_strategies/blowfish_spec.rb +0 -61
  38. data/spec/password_strategies/sha1_spec.rb +0 -59
@@ -1,22 +1,11 @@
1
1
  require 'active_support/deprecation'
2
2
 
3
3
  class Clearance::PasswordsController < Clearance::BaseController
4
- if respond_to?(:before_action)
5
- skip_before_action :require_login,
6
- only: [:create, :edit, :new, :update],
7
- raise: false
8
- skip_before_action :authorize,
9
- only: [:create, :edit, :new, :update],
10
- raise: false
11
- before_action :ensure_existing_user, only: [:edit, :update]
12
- else
13
- skip_before_filter :require_login,
14
- only: [:create, :edit, :new, :update],
15
- raise: false
16
- skip_before_filter :authorize,
17
- only: [:create, :edit, :new, :update],
18
- raise: false
19
- before_filter :ensure_existing_user, only: [:edit, :update]
4
+ before_action :ensure_existing_user, only: [:edit, :update]
5
+ skip_before_action :require_login, only: [:create, :edit, :new, :update], raise: false
6
+
7
+ def new
8
+ render template: "passwords/new"
20
9
  end
21
10
 
22
11
  def create
@@ -24,7 +13,8 @@ class Clearance::PasswordsController < Clearance::BaseController
24
13
  user.forgot_password!
25
14
  deliver_email(user)
26
15
  end
27
- render template: 'passwords/create'
16
+
17
+ render template: "passwords/create"
28
18
  end
29
19
 
30
20
  def edit
@@ -34,14 +24,10 @@ class Clearance::PasswordsController < Clearance::BaseController
34
24
  session[:password_reset_token] = params[:token]
35
25
  redirect_to url_for
36
26
  else
37
- render template: 'passwords/edit'
27
+ render template: "passwords/edit"
38
28
  end
39
29
  end
40
30
 
41
- def new
42
- render template: 'passwords/new'
43
- end
44
-
45
31
  def update
46
32
  @user = find_user_for_update
47
33
 
@@ -51,7 +37,7 @@ class Clearance::PasswordsController < Clearance::BaseController
51
37
  session[:password_reset_token] = nil
52
38
  else
53
39
  flash_failure_after_update
54
- render template: 'passwords/edit'
40
+ render template: "passwords/edit"
55
41
  end
56
42
  end
57
43
 
@@ -59,21 +45,11 @@ class Clearance::PasswordsController < Clearance::BaseController
59
45
 
60
46
  def deliver_email(user)
61
47
  mail = ::ClearanceMailer.change_password(user)
62
-
63
- if mail.respond_to?(:deliver_later)
64
- mail.deliver_later
65
- else
66
- mail.deliver
67
- end
48
+ mail.deliver_later
68
49
  end
69
50
 
70
51
  def password_reset_params
71
- if params.has_key? :user
72
- ActiveSupport::Deprecation.warn %{Since locales functionality was added, accessing params[:user] is no longer supported.}
73
- params[:user][:password]
74
- else
75
- params[:password_reset][:password]
76
- end
52
+ params[:password_reset][:password]
77
53
  end
78
54
 
79
55
  def find_user_by_id_and_confirmation_token
@@ -105,19 +81,15 @@ class Clearance::PasswordsController < Clearance::BaseController
105
81
  end
106
82
 
107
83
  def flash_failure_when_forbidden
108
- flash.now[:notice] = translate(:forbidden,
84
+ flash.now[:alert] = translate(:forbidden,
109
85
  scope: [:clearance, :controllers, :passwords],
110
- default: t('flashes.failure_when_forbidden'))
86
+ default: t("flashes.failure_when_forbidden"))
111
87
  end
112
88
 
113
89
  def flash_failure_after_update
114
- flash.now[:notice] = translate(:blank_password,
90
+ flash.now[:alert] = translate(:blank_password,
115
91
  scope: [:clearance, :controllers, :passwords],
116
- default: t('flashes.failure_after_update'))
117
- end
118
-
119
- def url_after_create
120
- sign_in_url
92
+ default: t("flashes.failure_after_update"))
121
93
  end
122
94
 
123
95
  def url_after_update
@@ -1,21 +1,6 @@
1
1
  class Clearance::SessionsController < Clearance::BaseController
2
- if respond_to?(:before_action)
3
- before_action :redirect_signed_in_users, only: [:new]
4
- skip_before_action :require_login,
5
- only: [:create, :new, :destroy],
6
- raise: false
7
- skip_before_action :authorize,
8
- only: [:create, :new, :destroy],
9
- raise: false
10
- else
11
- before_filter :redirect_signed_in_users, only: [:new]
12
- skip_before_filter :require_login,
13
- only: [:create, :new, :destroy],
14
- raise: false
15
- skip_before_filter :authorize,
16
- only: [:create, :new, :destroy],
17
- raise: false
18
- end
2
+ before_action :redirect_signed_in_users, only: [:new]
3
+ skip_before_action :require_login, only: [:create, :new, :destroy], raise: false
19
4
 
20
5
  def create
21
6
  @user = authenticate(params)
@@ -24,7 +9,7 @@ class Clearance::SessionsController < Clearance::BaseController
24
9
  if status.success?
25
10
  redirect_back_or url_after_create
26
11
  else
27
- flash.now.notice = status.failure_message
12
+ flash.now.alert = status.failure_message
28
13
  render template: "sessions/new", status: :unauthorized
29
14
  end
30
15
  end
@@ -1,13 +1,6 @@
1
1
  class Clearance::UsersController < Clearance::BaseController
2
- if respond_to?(:before_action)
3
- before_action :redirect_signed_in_users, only: [:create, :new]
4
- skip_before_action :require_login, only: [:create, :new], raise: false
5
- skip_before_action :authorize, only: [:create, :new], raise: false
6
- else
7
- before_filter :redirect_signed_in_users, only: [:create, :new]
8
- skip_before_filter :require_login, only: [:create, :new], raise: false
9
- skip_before_filter :authorize, only: [:create, :new], raise: false
10
- end
2
+ before_action :redirect_signed_in_users, only: [:create, :new]
3
+ skip_before_action :require_login, only: [:create, :new], raise: false
11
4
 
12
5
  def new
13
6
  @user = user_from_params
@@ -27,14 +20,6 @@ class Clearance::UsersController < Clearance::BaseController
27
20
 
28
21
  private
29
22
 
30
- def avoid_sign_in
31
- warn "[DEPRECATION] Clearance's `avoid_sign_in` before_filter is " +
32
- "deprecated. Use `redirect_signed_in_users` instead. " +
33
- "Be sure to update any instances of `skip_before_filter :avoid_sign_in`" +
34
- " or `skip_before_action :avoid_sign_in` as well"
35
- redirect_signed_in_users
36
- end
37
-
38
23
  def redirect_signed_in_users
39
24
  if signed_in?
40
25
  redirect_to Clearance.configuration.redirect_url
@@ -5,10 +5,10 @@ require 'date'
5
5
  Gem::Specification.new do |s|
6
6
  s.add_dependency 'bcrypt'
7
7
  s.add_dependency 'email_validator', '~> 1.4'
8
- s.add_dependency 'railties', '>= 3.1'
9
- s.add_dependency 'activemodel', '>= 3.1'
10
- s.add_dependency 'activerecord', '>= 3.1'
11
- s.add_dependency 'actionmailer', '>= 3.1'
8
+ s.add_dependency 'railties', '>= 4.2'
9
+ s.add_dependency 'activemodel', '>= 4.2'
10
+ s.add_dependency 'activerecord', '>= 4.2'
11
+ s.add_dependency 'actionmailer', '>= 4.2'
12
12
  s.authors = [
13
13
  'Dan Croak',
14
14
  'Eugene Bolshakov',
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.name = %q{clearance}
39
39
  s.rdoc_options = ['--charset=UTF-8']
40
40
  s.require_paths = ['lib']
41
- s.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
41
+ s.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
42
42
  s.summary = 'Rails authentication & authorization with email & password.'
43
43
  s.test_files = `git ls-files -- {spec}/*`.split("\n")
44
44
  s.version = Clearance::VERSION
@@ -3,18 +3,17 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "addressable", "~> 2.6.0"
6
- gem "appraisal"
7
6
  gem "ammeter"
8
- gem "bundler", "~> 1.3"
7
+ gem "appraisal"
9
8
  gem "capybara", ">= 2.6.2"
10
9
  gem "database_cleaner", "~> 1.0"
11
10
  gem "factory_bot_rails", "~> 5.0"
12
11
  gem "nokogiri", "~> 1.10.0"
13
- gem "rspec-rails", "~> 3.1"
12
+ gem "pry", require: false
13
+ gem "rspec-rails", "~> 3.5"
14
14
  gem "shoulda-matchers", "~> 4.0"
15
15
  gem "sqlite3", "~> 1.3.13"
16
16
  gem "timecop", "~> 0.6"
17
- gem "pry", require: false
18
17
  gem "railties", "~> 4.2.0"
19
18
 
20
19
  gemspec path: "../"
@@ -3,18 +3,17 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "addressable", "~> 2.6.0"
6
- gem "appraisal"
7
6
  gem "ammeter"
8
- gem "bundler", "~> 1.3"
7
+ gem "appraisal"
9
8
  gem "capybara", ">= 2.6.2"
10
9
  gem "database_cleaner", "~> 1.0"
11
10
  gem "factory_bot_rails", "~> 5.0"
12
11
  gem "nokogiri", "~> 1.10.0"
13
- gem "rspec-rails", "~> 3.1"
12
+ gem "pry", require: false
13
+ gem "rspec-rails", "~> 3.5"
14
14
  gem "shoulda-matchers", "~> 4.0"
15
15
  gem "sqlite3", "~> 1.3.13"
16
16
  gem "timecop", "~> 0.6"
17
- gem "pry", require: false
18
17
  gem "railties", "~> 5.0.0"
19
18
  gem "rails-controller-testing"
20
19
 
@@ -3,18 +3,17 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "addressable", "~> 2.6.0"
6
- gem "appraisal"
7
6
  gem "ammeter"
8
- gem "bundler", "~> 1.3"
7
+ gem "appraisal"
9
8
  gem "capybara", ">= 2.6.2"
10
9
  gem "database_cleaner", "~> 1.0"
11
10
  gem "factory_bot_rails", "~> 5.0"
12
11
  gem "nokogiri", "~> 1.10.0"
13
- gem "rspec-rails", "~> 3.1"
12
+ gem "pry", require: false
13
+ gem "rspec-rails", "~> 3.5"
14
14
  gem "shoulda-matchers", "~> 4.0"
15
15
  gem "sqlite3", "~> 1.3.13"
16
16
  gem "timecop", "~> 0.6"
17
- gem "pry", require: false
18
17
  gem "railties", "~> 5.1.0"
19
18
  gem "rails-controller-testing"
20
19
 
@@ -3,18 +3,17 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "addressable", "~> 2.6.0"
6
- gem "appraisal"
7
6
  gem "ammeter"
8
- gem "bundler", "~> 1.3"
7
+ gem "appraisal"
9
8
  gem "capybara", ">= 2.6.2"
10
9
  gem "database_cleaner", "~> 1.0"
11
10
  gem "factory_bot_rails", "~> 5.0"
12
11
  gem "nokogiri", "~> 1.10.0"
13
- gem "rspec-rails", "~> 3.1"
12
+ gem "pry", require: false
13
+ gem "rspec-rails", "~> 3.5"
14
14
  gem "shoulda-matchers", "~> 4.0"
15
15
  gem "sqlite3", "~> 1.3.13"
16
16
  gem "timecop", "~> 0.6"
17
- gem "pry", require: false
18
17
  gem "railties", "~> 5.2.0"
19
18
  gem "rails-controller-testing"
20
19
 
@@ -10,12 +10,4 @@ require 'clearance/password_strategies'
10
10
  require 'clearance/constraints'
11
11
 
12
12
  module Clearance
13
- # @deprecated Use `Gem::Specification` API if you need to access Clearance's
14
- # Gem root.
15
- def self.root
16
- warn "#{Kernel.caller.first}: [DEPRECATION] `Clearance.root` is " +
17
- "deprecated and will be removed in the next major release. If you need " +
18
- "to find Clearance's root, you can use the `Gem::Specification` API."
19
- File.expand_path('../..', __FILE__)
20
- end
21
13
  end
@@ -10,7 +10,6 @@ module Clearance
10
10
  private(
11
11
  :authenticate,
12
12
  :current_user,
13
- :current_user=,
14
13
  :handle_unverified_request,
15
14
  :sign_in,
16
15
  :sign_out,
@@ -40,13 +39,6 @@ module Clearance
40
39
  clearance_session.current_user
41
40
  end
42
41
 
43
- # @deprecated Use the {#sign_in} method instead.
44
- def current_user=(user)
45
- warn "#{Kernel.caller.first}: [DEPRECATION] " +
46
- 'Assigning the current_user has been deprecated. Use the sign_in method instead.'
47
- clearance_session.sign_in user
48
- end
49
-
50
42
  # Sign in the provided user.
51
43
  # @param [User] user
52
44
  #
@@ -3,7 +3,7 @@ module Clearance
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- private :authorize, :deny_access, :require_login
6
+ private :deny_access, :require_login
7
7
  end
8
8
 
9
9
  # Use as a `before_action` to require a user be signed in to proceed.
@@ -23,15 +23,6 @@ module Clearance
23
23
  end
24
24
  end
25
25
 
26
- # @deprecated use {#require_login}
27
- def authorize
28
- warn "[DEPRECATION] Clearance's `authorize` before_action is " +
29
- "deprecated. Use `require_login` instead. Be sure to update any " +
30
- "instances of `skip_before_action :authorize` or " +
31
- "`skip_before_action :authorize` as well"
32
- require_login
33
- end
34
-
35
26
  # Responds to unauthorized requests in a manner fitting the request format.
36
27
  # `js`, `json`, and `xml` requests will receive a 401 with no body. All
37
28
  # other formats will be redirected appropriately and can optionally have the
@@ -63,7 +54,7 @@ module Clearance
63
54
  store_location
64
55
 
65
56
  if flash_message
66
- flash[:notice] = flash_message
57
+ flash[:alert] = flash_message
67
58
  end
68
59
 
69
60
  if signed_in?
@@ -112,15 +112,7 @@ module Clearance
112
112
 
113
113
  # @api private
114
114
  def remember_token_expires
115
- if expires_configuration.arity == 1
116
- expires_configuration.call(cookies)
117
- else
118
- warn "#{Kernel.caller.first}: [DEPRECATION] " +
119
- 'Clearance.configuration.cookie_expiration lambda with no parameters ' +
120
- 'has been deprecated and will be removed from a future release. The ' +
121
- 'lambda should accept the collection of previously set cookies.'
122
- expires_configuration.call
123
- end
115
+ expires_configuration.call(cookies)
124
116
  end
125
117
 
126
118
  # @api private
@@ -8,7 +8,7 @@ module Clearance
8
8
  module Matchers
9
9
  # The `deny_access` matcher is used to assert that a
10
10
  # request is denied access by clearance.
11
- # @option opts [String] :flash The expected flash notice message. Defaults
11
+ # @option opts [String] :flash The expected flash alert message. Defaults
12
12
  # to nil, which means the flash will not be checked.
13
13
  # @option opts [String] :redirect The expected redirect url. Defaults to
14
14
  # `'/'` if signed in or the `sign_in_url` if signed out.
@@ -78,16 +78,12 @@ module Clearance
78
78
  @controller.request.env[:clearance]
79
79
  end
80
80
 
81
- def flash_notice
82
- @controller.flash[:notice]
81
+ def flash_alert
82
+ @controller.flash[:alert]
83
83
  end
84
84
 
85
- def flash_notice_value
86
- if flash_notice.respond_to?(:values)
87
- flash_notice.values.first
88
- else
89
- flash_notice
90
- end
85
+ def flash_alert_value
86
+ flash_alert.values.first
91
87
  end
92
88
 
93
89
  def redirects_to_url?
@@ -107,16 +103,14 @@ module Clearance
107
103
  def sets_the_flash?
108
104
  if @flash.blank?
109
105
  true
106
+ elsif flash_alert_value == @flash
107
+ @failure_message_when_negated <<
108
+ "Didn't expect to set the flash to #{@flash}"
109
+ true
110
110
  else
111
- if flash_notice_value == @flash
112
- @failure_message_when_negated <<
113
- "Didn't expect to set the flash to #{@flash}"
114
- true
115
- else
116
- @failure_message << "Expected the flash to be set to #{@flash} "\
117
- "but was #{flash_notice_value}"
118
- false
119
- end
111
+ @failure_message << "Expected the flash to be set to #{@flash} "\
112
+ "but was #{flash_alert_value}"
113
+ false
120
114
  end
121
115
  end
122
116
  end
@@ -47,9 +47,6 @@ module Clearance
47
47
  # @return [String] The value used to identify this user in the password
48
48
  # reset link.
49
49
  #
50
- # @!attribute password_changing
51
- # @deprecated Dirty tracking is now handled automatically.
52
- #
53
50
  # @!attribute [r] password
54
51
  # @return [String] Transient (non-persisted) attribute that is set when
55
52
  # updating a user's password. Only the {#encrypted_password} is persisted.
@@ -111,24 +108,6 @@ module Clearance
111
108
  encrypted_password_will_change!
112
109
  super
113
110
  end
114
-
115
- def password_changing
116
- warn "#{Kernel.caller.first}: [DEPRECATION] " \
117
- "The `password_changing` attribute is deprecated. Clearance uses " \
118
- "the dirty state of the `encrypted_password` field to track this " \
119
- "automatically."
120
-
121
- @password_changing
122
- end
123
-
124
- def password_changing=(value)
125
- warn "#{Kernel.caller.first}: [DEPRECATION] " \
126
- "The `password_changing` attribute is deprecated. Clearance uses " \
127
- "the dirty state of the `encrypted_password` field to track this " \
128
- "automatically."
129
-
130
- @password_changing = value
131
- end
132
111
  end
133
112
 
134
113
  # @api private