devise 2.1.0.rc → 2.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise might be problematic. Click here for more details.

Files changed (65) hide show
  1. data/CHANGELOG.rdoc +23 -1
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +4 -6
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +7 -3
  6. data/Rakefile +1 -1
  7. data/app/controllers/devise/sessions_controller.rb +2 -4
  8. data/app/controllers/devise/unlocks_controller.rb +15 -2
  9. data/app/controllers/devise_controller.rb +24 -11
  10. data/devise.gemspec +1 -1
  11. data/gemfiles/Gemfile.rails-3.1.x +1 -1
  12. data/gemfiles/Gemfile.rails-3.1.x.lock +38 -40
  13. data/lib/devise.rb +13 -55
  14. data/lib/devise/controllers/helpers.rb +0 -5
  15. data/lib/devise/failure_app.rb +3 -1
  16. data/lib/devise/hooks/lockable.rb +7 -0
  17. data/lib/devise/hooks/timeoutable.rb +1 -0
  18. data/lib/devise/models.rb +9 -3
  19. data/lib/devise/models/authenticatable.rb +13 -3
  20. data/lib/devise/models/confirmable.rb +2 -5
  21. data/lib/devise/models/database_authenticatable.rb +4 -6
  22. data/lib/devise/models/lockable.rb +6 -6
  23. data/lib/devise/models/rememberable.rb +3 -3
  24. data/lib/devise/models/token_authenticatable.rb +4 -1
  25. data/lib/devise/modules.rb +0 -1
  26. data/lib/devise/orm/active_record.rb +1 -42
  27. data/lib/devise/orm/mongoid.rb +1 -29
  28. data/lib/devise/rails.rb +1 -58
  29. data/lib/devise/rails/routes.rb +1 -1
  30. data/lib/devise/rails/warden_compat.rb +10 -4
  31. data/lib/devise/strategies/rememberable.rb +1 -1
  32. data/lib/devise/test_helpers.rb +48 -9
  33. data/lib/devise/version.rb +1 -1
  34. data/lib/generators/active_record/devise_generator.rb +8 -4
  35. data/lib/generators/devise/orm_helpers.rb +2 -1
  36. data/lib/generators/mongoid/devise_generator.rb +0 -3
  37. data/lib/generators/templates/devise.rb +1 -8
  38. data/test/controllers/custom_strategy_test.rb +62 -0
  39. data/test/controllers/sessions_controller_test.rb +21 -1
  40. data/test/failure_app_test.rb +13 -3
  41. data/test/generators/active_record_generator_test.rb +32 -0
  42. data/test/integration/authenticatable_test.rb +2 -2
  43. data/test/integration/recoverable_test.rb +13 -0
  44. data/test/integration/token_authenticatable_test.rb +13 -0
  45. data/test/models/lockable_test.rb +0 -9
  46. data/test/models/rememberable_test.rb +1 -2
  47. data/test/models_test.rb +5 -5
  48. data/test/rails_app/app/mongoid/admin.rb +0 -3
  49. data/test/rails_app/app/mongoid/user.rb +0 -3
  50. data/test/rails_app/config/initializers/devise.rb +0 -15
  51. data/test/rails_app/config/routes.rb +1 -0
  52. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -6
  53. data/test/rails_app/lib/shared_admin.rb +1 -1
  54. metadata +17 -24
  55. data/lib/devise/encryptors/authlogic_sha512.rb +0 -19
  56. data/lib/devise/encryptors/base.rb +0 -24
  57. data/lib/devise/encryptors/bcrypt.rb +0 -14
  58. data/lib/devise/encryptors/clearance_sha1.rb +0 -17
  59. data/lib/devise/encryptors/restful_authentication_sha1.rb +0 -22
  60. data/lib/devise/encryptors/sha1.rb +0 -25
  61. data/lib/devise/encryptors/sha512.rb +0 -25
  62. data/lib/devise/models/encryptable.rb +0 -80
  63. data/lib/devise/schema.rb +0 -109
  64. data/test/encryptors_test.rb +0 -30
  65. data/test/models/encryptable_test.rb +0 -73
data/lib/devise/schema.rb DELETED
@@ -1,109 +0,0 @@
1
- module Devise
2
- # Holds devise schema information. To use it, just include its methods
3
- # and overwrite the apply_schema method.
4
- module Schema
5
-
6
- # Creates encrypted_password, and email when it is used as an authentication
7
- # key (default).
8
- #
9
- # == Options
10
- # * :null - When true, allow columns to be null.
11
- # * :default - Set to "" when :null is false, unless overridden.
12
- #
13
- # == Notes
14
- # For Datamapper compatibility, we explicitly hardcode the limit for the
15
- # encrypter password field in 128 characters.
16
- def database_authenticatable(options={})
17
- null = options[:null] || false
18
- default = options.key?(:default) ? options[:default] : ("" if null == false)
19
- include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email)
20
-
21
- apply_devise_schema :email, String, :null => null, :default => default if include_email
22
- apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128
23
- end
24
-
25
- # Creates password salt for encryption support when using encryptors other
26
- # than the database_authenticable default of bcrypt.
27
- def encryptable
28
- apply_devise_schema :password_salt, String
29
- end
30
-
31
- # Creates authentication_token.
32
- def token_authenticatable
33
- apply_devise_schema :authentication_token, String
34
- end
35
-
36
- # Creates confirmation_token, confirmed_at and confirmation_sent_at.
37
- def confirmable
38
- apply_devise_schema :confirmation_token, String
39
- apply_devise_schema :confirmed_at, DateTime
40
- apply_devise_schema :confirmation_sent_at, DateTime
41
- end
42
-
43
- # Creates unconfirmed_email
44
- def reconfirmable
45
- apply_devise_schema :unconfirmed_email, String
46
- end
47
-
48
- # Creates reset_password_token and reset_password_sent_at.
49
- #
50
- # == Options
51
- # * :reset_within - When true, adds a column that reset passwords within some date
52
- def recoverable(options={})
53
- use_within = options.fetch(:reset_within, Devise.reset_password_within.present?)
54
- apply_devise_schema :reset_password_token, String
55
- apply_devise_schema :reset_password_sent_at, DateTime if use_within
56
- end
57
-
58
- # Creates remember_token and remember_created_at.
59
- #
60
- # == Options
61
- # * :use_salt - When true, does not create a remember_token and use password_salt instead.
62
- def rememberable(options={})
63
- use_salt = options.fetch(:use_salt, Devise.use_salt_as_remember_token)
64
- apply_devise_schema :remember_token, String unless use_salt
65
- apply_devise_schema :remember_created_at, DateTime
66
- end
67
-
68
- # Creates sign_in_count, current_sign_in_at, last_sign_in_at,
69
- # current_sign_in_ip, last_sign_in_ip.
70
- def trackable
71
- apply_devise_schema :sign_in_count, Integer, :default => 0
72
- apply_devise_schema :current_sign_in_at, DateTime
73
- apply_devise_schema :last_sign_in_at, DateTime
74
- apply_devise_schema :current_sign_in_ip, String
75
- apply_devise_schema :last_sign_in_ip, String
76
- end
77
-
78
- # Creates failed_attempts, unlock_token and locked_at depending on the options given.
79
- #
80
- # == Options
81
- # * :unlock_strategy - The strategy used for unlock. Can be :time, :email, :both (default), :none.
82
- # If :email or :both, creates a unlock_token field.
83
- # * :lock_strategy - The strategy used for locking. Can be :failed_attempts (default) or :none.
84
- def lockable(options={})
85
- unlock_strategy = options[:unlock_strategy]
86
- unlock_strategy ||= self.unlock_strategy if respond_to?(:unlock_strategy)
87
- unlock_strategy ||= :both
88
-
89
- lock_strategy = options[:lock_strategy]
90
- lock_strategy ||= self.lock_strategy if respond_to?(:lock_strategy)
91
- lock_strategy ||= :failed_attempts
92
-
93
- if lock_strategy == :failed_attempts
94
- apply_devise_schema :failed_attempts, Integer, :default => 0
95
- end
96
-
97
- if [:both, :email].include?(unlock_strategy)
98
- apply_devise_schema :unlock_token, String
99
- end
100
-
101
- apply_devise_schema :locked_at, DateTime
102
- end
103
-
104
- # Overwrite with specific modification to create your own schema.
105
- def apply_devise_schema(name, type, options={})
106
- raise NotImplementedError
107
- end
108
- end
109
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Encryptors < ActiveSupport::TestCase
4
- test 'should match a password created by authlogic' do
5
- authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
6
- encryptor = Devise::Encryptors::AuthlogicSha512.digest('123mudar', 20, 'usZK_z_EAaF61Gwkw-ed', '')
7
- assert_equal authlogic, encryptor
8
- end
9
-
10
- test 'should match a password created by restful_authentication' do
11
- restful_authentication = "93110f71309ce91366375ea44e2a6f5cc73fa8d4"
12
- encryptor = Devise::Encryptors::RestfulAuthenticationSha1.digest('123mudar', 10, '48901d2b247a54088acb7f8ea3e695e50fe6791b', 'fee9a51ec0a28d11be380ca6dee6b4b760c1a3bf')
13
- assert_equal restful_authentication, encryptor
14
- end
15
-
16
- test 'should match a password created by clearance' do
17
- clearance = "0f40bbae18ddefd7066276c3ef209d40729b0378"
18
- encryptor = Devise::Encryptors::ClearanceSha1.digest('123mudar', nil, '65c58472c207c829f28c68619d3e3aefed18ab3f', nil)
19
- assert_equal clearance, encryptor
20
- end
21
-
22
- Devise::ENCRYPTORS_LENGTH.each do |key, value|
23
- test "should have length #{value} for #{key.inspect}" do
24
- swap Devise, :encryptor => key do
25
- encryptor = Devise::Encryptors.const_get(key.to_s.classify)
26
- assert_equal value, encryptor.digest('a', 4, encryptor.salt(4), nil).size
27
- end
28
- end
29
- end
30
- end
@@ -1,73 +0,0 @@
1
- require 'test_helper'
2
-
3
- class EncryptableTest < ActiveSupport::TestCase
4
- def encrypt_password(admin, pepper=Admin.pepper, stretches=Admin.stretches, encryptor=Admin.encryptor_class)
5
- encryptor.digest('123456', stretches, admin.password_salt, pepper)
6
- end
7
-
8
- def swap_with_encryptor(klass, encryptor, options={})
9
- klass.instance_variable_set(:@encryptor_class, nil)
10
-
11
- swap klass, options.merge(:encryptor => encryptor) do
12
- begin
13
- yield
14
- ensure
15
- klass.instance_variable_set(:@encryptor_class, nil)
16
- end
17
- end
18
- end
19
-
20
- test 'should generate salt while setting password' do
21
- assert_present create_admin.password_salt
22
- end
23
-
24
- test 'should not change password salt when updating' do
25
- admin = create_admin
26
- salt = admin.password_salt
27
- admin.expects(:password_salt=).never
28
- admin.save!
29
- assert_equal salt, admin.password_salt
30
- end
31
-
32
- test 'should generate a base64 hash using SecureRandom for password salt' do
33
- swap_with_encryptor Admin, :sha1 do
34
- SecureRandom.expects(:base64).with(15).returns('01lI').twice
35
- salt = create_admin.password_salt
36
- assert_not_equal '01lI', salt
37
- assert_equal 4, salt.size
38
- end
39
- end
40
-
41
- test 'should not generate salt if password is blank' do
42
- assert_blank create_admin(:password => nil).password_salt
43
- assert_blank create_admin(:password => '').password_salt
44
- end
45
-
46
- test 'should encrypt password again if password has changed' do
47
- admin = create_admin
48
- encrypted_password = admin.encrypted_password
49
- admin.password = admin.password_confirmation = 'new_password'
50
- admin.save!
51
- assert_not_equal encrypted_password, admin.encrypted_password
52
- end
53
-
54
- test 'should respect encryptor configuration' do
55
- swap_with_encryptor Admin, :sha512 do
56
- admin = create_admin
57
- assert_equal admin.encrypted_password, encrypt_password(admin, Admin.pepper, Admin.stretches, ::Devise::Encryptors::Sha512)
58
- end
59
- end
60
-
61
- test 'should not validate password when salt is nil' do
62
- admin = create_admin
63
- admin.password_salt = nil
64
- admin.save
65
- assert_not admin.valid_password?('123456')
66
- end
67
-
68
- test 'required_fields should contain the fields that Devise uses' do
69
- assert_same_content Devise::Models::Encryptable.required_fields(User), [
70
- :password_salt
71
- ]
72
- end
73
- end