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,59 +0,0 @@
1
- module Clearance
2
- module PasswordStrategies
3
- # @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies` gem
4
- module SHA1
5
- require 'digest/sha1'
6
-
7
- DEPRECATION_MESSAGE = "[DEPRECATION] The SHA1 password strategy " \
8
- "has been deprecated and will be removed from Clearance 2.0. BCrypt " \
9
- "is the only officially supported strategy, though you are free to " \
10
- "provide your own. To continue using this strategy add " \
11
- "clearance-deprecated_password_strategies to your Gemfile."
12
-
13
- extend ActiveSupport::Concern
14
-
15
- # @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
16
- # gem
17
- def authenticated?(password)
18
- warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
19
- encrypted_password == encrypt(password)
20
- end
21
-
22
- # @deprecated Use {BCrypt} or `clearance-deprecated_password_strategies`
23
- # gem
24
- def password=(new_password)
25
- warn "#{Kernel.caller.first}: #{DEPRECATION_MESSAGE}"
26
- @password = new_password
27
- initialize_salt_if_necessary
28
-
29
- if new_password.present?
30
- self.encrypted_password = encrypt(new_password)
31
- end
32
- end
33
-
34
- private
35
-
36
- # @api private
37
- def encrypt(string)
38
- generate_hash "--#{salt}--#{string}--"
39
- end
40
-
41
- # @api private
42
- def generate_hash(string)
43
- Digest::SHA1.hexdigest(string).encode 'UTF-8'
44
- end
45
-
46
- # @api private
47
- def initialize_salt_if_necessary
48
- if salt.blank?
49
- self.salt = generate_salt
50
- end
51
- end
52
-
53
- # @api private
54
- def generate_salt
55
- SecureRandom.hex(20).encode('UTF-8')
56
- end
57
- end
58
- end
59
- end
@@ -1,11 +0,0 @@
1
- if defined?(RSpec)
2
- require 'clearance/rspec'
3
- elsif defined?(ActionController::TestCase)
4
- require 'clearance/test_unit'
5
- end
6
-
7
- warn(
8
- "#{Kernel.caller.first} [DEPRECATION] Requiring `clearance/testing` in " +
9
- '`spec/spec_helper.rb` (or in `test/test_helper.rb`) is deprecated. ' +
10
- 'Require `clearance/rspec` or `clearance/test_unit` instead.'
11
- )
@@ -1,15 +0,0 @@
1
- require "clerance/testing/controller_helpers"
2
-
3
- module Clearance
4
- module Testing
5
- # @deprecated Use Clearance::Testing::ControllerHelpers
6
- module Helpers
7
- warn(
8
- "#{Kernel.caller.first} [DEPRECATION] Clearance::Testing::Helpers is "\
9
- "deprecated and has been replaced with " \
10
- "Clearance::Testing::ControllerHelpers. Require " \
11
- "clearance/testing/controller_helpers instead."
12
- )
13
- end
14
- end
15
- end
@@ -1,122 +0,0 @@
1
- require "spec_helper"
2
- include FakeModelWithPasswordStrategy
3
-
4
- describe Clearance::PasswordStrategies::BCryptMigrationFromSHA1 do
5
- around do |example|
6
- silence_warnings do
7
- example.run
8
- end
9
- end
10
-
11
- describe "#password=" do
12
- it "encrypts the password into a BCrypt-encrypted encrypted_password" do
13
- stub_bcrypt_password
14
-
15
- expect(model_instance.encrypted_password).to eq encrypted_password
16
- end
17
-
18
- it "encrypts with BCrypt" do
19
- stub_bcrypt_password
20
-
21
- expect(BCrypt::Password).to have_received(:create).
22
- with(password, anything)
23
- end
24
-
25
- it "sets the pasword on the subject" do
26
- stub_bcrypt_password
27
-
28
- expect(model_instance.password).to be_present
29
- end
30
-
31
- def stub_bcrypt_password
32
- model_instance.salt = salt
33
- digestable = "--#{salt}--#{password}--"
34
- model_instance.encrypted_password = Digest::SHA1.hexdigest(digestable)
35
- allow(BCrypt::Password).to receive(:create).and_return(encrypted_password)
36
- model_instance.password = password
37
- end
38
-
39
- def encrypted_password
40
- @encrypted_password ||= double("encrypted password")
41
- end
42
- end
43
-
44
- describe "#authenticated?" do
45
- context "with a SHA1-encrypted password" do
46
- it "is authenticated" do
47
- model_instance.salt = salt
48
- model_instance.encrypted_password = sha1_hash
49
- allow(model_instance).to receive(:save)
50
-
51
- expect(model_instance).to be_authenticated(password)
52
- end
53
-
54
- it "changes the hash into a BCrypt-encrypted one" do
55
- model_instance.salt = salt
56
- model_instance.encrypted_password = sha1_hash
57
- allow(model_instance).to receive(:save)
58
-
59
- model_instance.authenticated? password
60
-
61
- expect(model_instance.encrypted_password).not_to eq sha1_hash
62
- end
63
-
64
- it "does not raise a BCrypt error for invalid passwords" do
65
- model_instance.salt = salt
66
- model_instance.encrypted_password = sha1_hash
67
-
68
- expect do
69
- model_instance.authenticated? "bad" + password
70
- end.not_to raise_error
71
- end
72
-
73
- it "saves the subject to database" do
74
- model_instance.salt = salt
75
- model_instance.encrypted_password = sha1_hash
76
- allow(model_instance).to receive(:save)
77
-
78
- model_instance.authenticated? password
79
-
80
- expect(model_instance).to have_received(:save)
81
- end
82
-
83
- def sha1_hash
84
- Digest::SHA1.hexdigest("--#{salt}--#{password}--")
85
- end
86
- end
87
-
88
- context "with a BCrypt-encrypted password" do
89
- it "is authenticated" do
90
- model_instance.encrypted_password = bcrypt_hash
91
-
92
- expect(model_instance).to be_authenticated(password)
93
- end
94
-
95
- it "does not change the hash" do
96
- model_instance.encrypted_password = bcrypt_hash
97
-
98
- model_instance.authenticated? password
99
-
100
- expect(model_instance.encrypted_password.to_s).to eq bcrypt_hash.to_s
101
- end
102
-
103
- def bcrypt_hash
104
- @bcrypt_hash ||= ::BCrypt::Password.create(password)
105
- end
106
- end
107
- end
108
-
109
- def model_instance
110
- @model_instance ||= fake_model_with_password_strategy(
111
- Clearance::PasswordStrategies::BCryptMigrationFromSHA1
112
- )
113
- end
114
-
115
- def salt
116
- "salt"
117
- end
118
-
119
- def password
120
- "password"
121
- end
122
- end
@@ -1,61 +0,0 @@
1
- require "spec_helper"
2
- include FakeModelWithPasswordStrategy
3
-
4
- describe Clearance::PasswordStrategies::Blowfish do
5
- around do |example|
6
- silence_warnings do
7
- example.run
8
- end
9
- end
10
-
11
- describe "#password=" do
12
- context "when the password is set" do
13
- it "does not initialize the salt" do
14
- model_instance = fake_model_with_blowfish_strategy
15
- model_instance.salt = salt
16
- model_instance.password = password
17
-
18
- expect(model_instance.salt).to eq salt
19
- end
20
-
21
- it "encrypts the password using Blowfish and the existing salt" do
22
- model_instance = fake_model_with_blowfish_strategy
23
- model_instance.salt = salt
24
- model_instance.salt = salt
25
- model_instance.password = password
26
- cipher = OpenSSL::Cipher::Cipher.new("bf-cbc").encrypt
27
- cipher.key = Digest::SHA256.digest(salt).first(16)
28
- expected = cipher.update("--#{salt}--#{password}--") << cipher.final
29
-
30
- encrypted_password = Base64.decode64(model_instance.encrypted_password)
31
-
32
- expect(encrypted_password).to eq expected
33
- end
34
- end
35
-
36
- context "when the salt is not set" do
37
- it "should initialize the salt" do
38
- model_instance = fake_model_with_blowfish_strategy
39
- model_instance.salt = salt
40
- model_instance.salt = nil
41
- model_instance.password = password
42
-
43
- expect(model_instance.salt).not_to be_nil
44
- end
45
- end
46
- end
47
-
48
- def fake_model_with_blowfish_strategy
49
- @model_instance ||= fake_model_with_password_strategy(
50
- Clearance::PasswordStrategies::Blowfish
51
- )
52
- end
53
-
54
- def salt
55
- "salt"
56
- end
57
-
58
- def password
59
- "password"
60
- end
61
- end
@@ -1,59 +0,0 @@
1
- require "spec_helper"
2
- include FakeModelWithPasswordStrategy
3
-
4
- describe Clearance::PasswordStrategies::SHA1 do
5
- around do |example|
6
- silence_warnings do
7
- example.run
8
- end
9
- end
10
-
11
- describe "#password=" do
12
- context "when the salt is set" do
13
- it "does not initialize the salt when assigned" do
14
- model_instance = fake_model_with_sha1_strategy
15
-
16
- model_instance.salt = salt
17
-
18
- expect(model_instance.salt).to eq salt
19
- end
20
-
21
- it "encrypts the password using SHA1 and the existing salt" do
22
- model_instance = fake_model_with_sha1_strategy
23
- model_instance.salt = salt
24
- model_instance.password = password
25
-
26
- expected = Digest::SHA1.hexdigest("--#{salt}--#{password}--")
27
-
28
- expect(model_instance.encrypted_password).to eq expected
29
- end
30
- end
31
-
32
- context "when the salt is set" do
33
- it "generates the salt" do
34
- model_instance = fake_model_with_sha1_strategy
35
- model_instance.password = ""
36
-
37
- expect(model_instance.salt).not_to be_nil
38
- end
39
-
40
- it "doesn't encrypt the password" do
41
- model_instance = fake_model_with_sha1_strategy
42
-
43
- expect(model_instance.encrypted_password).to be_nil
44
- end
45
- end
46
- end
47
-
48
- def fake_model_with_sha1_strategy
49
- fake_model_with_password_strategy(Clearance::PasswordStrategies::SHA1)
50
- end
51
-
52
- def salt
53
- "salt"
54
- end
55
-
56
- def password
57
- "password"
58
- end
59
- end