devise 1.2.1 → 1.3.0

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 (45) hide show
  1. data/.travis.yml +7 -1
  2. data/CHANGELOG.rdoc +21 -1
  3. data/Gemfile.lock +1 -1
  4. data/README.rdoc +4 -5
  5. data/app/controllers/devise/confirmations_controller.rb +14 -6
  6. data/app/controllers/devise/passwords_controller.rb +7 -6
  7. data/app/controllers/devise/registrations_controller.rb +12 -10
  8. data/app/controllers/devise/sessions_controller.rb +23 -1
  9. data/app/controllers/devise/unlocks_controller.rb +7 -6
  10. data/config/locales/en.yml +1 -0
  11. data/lib/devise.rb +7 -8
  12. data/lib/devise/controllers/helpers.rb +0 -6
  13. data/lib/devise/controllers/internal_helpers.rb +38 -2
  14. data/lib/devise/failure_app.rb +4 -10
  15. data/lib/devise/models.rb +27 -4
  16. data/lib/devise/models/authenticatable.rb +1 -13
  17. data/lib/devise/models/confirmable.rb +1 -1
  18. data/lib/devise/models/database_authenticatable.rb +2 -1
  19. data/lib/devise/models/recoverable.rb +41 -5
  20. data/lib/devise/models/validatable.rb +2 -3
  21. data/lib/devise/omniauth.rb +3 -3
  22. data/lib/devise/rails.rb +8 -25
  23. data/lib/devise/rails/routes.rb +8 -0
  24. data/lib/devise/rails/warden_compat.rb +2 -2
  25. data/lib/devise/schema.rb +8 -3
  26. data/lib/devise/strategies/authenticatable.rb +2 -1
  27. data/lib/devise/version.rb +1 -1
  28. data/lib/generators/devise/views_generator.rb +3 -9
  29. data/lib/generators/templates/devise.rb +11 -2
  30. data/test/controllers/internal_helpers_test.rb +15 -0
  31. data/test/controllers/sessions_controller_test.rb +17 -0
  32. data/test/devise_test.rb +0 -3
  33. data/test/integration/authenticatable_test.rb +27 -7
  34. data/test/integration/confirmable_test.rb +28 -0
  35. data/test/integration/lockable_test.rb +35 -1
  36. data/test/integration/recoverable_test.rb +37 -0
  37. data/test/integration/registerable_test.rb +45 -0
  38. data/test/models/database_authenticatable_test.rb +20 -2
  39. data/test/models/recoverable_test.rb +44 -9
  40. data/test/models/validatable_test.rb +3 -3
  41. data/test/models_test.rb +23 -0
  42. data/test/rails_app/config/initializers/devise.rb +7 -2
  43. data/test/rails_app/config/routes.rb +2 -0
  44. data/test/routes_test.rb +7 -0
  45. metadata +7 -5
@@ -101,4 +101,32 @@ class ConfirmationTest < ActionController::IntegrationTest
101
101
  assert_contain 'Not confirmed user'
102
102
  end
103
103
  end
104
+
105
+ test 'resent confirmation token with valid E-Mail in XML format should return valid response' do
106
+ user = create_user(:confirm => false)
107
+ post user_confirmation_path(:format => 'xml'), :user => { :email => user.email }
108
+ assert_response :success
109
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
110
+ end
111
+
112
+ test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
113
+ user = create_user(:confirm => false)
114
+ post user_confirmation_path(:format => 'xml'), :user => { :email => 'invalid.test@test.com' }
115
+ assert_response :unprocessable_entity
116
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
117
+ end
118
+
119
+ test 'confirm account with valid confirmation token in XML format should return valid response' do
120
+ user = create_user(:confirm => false)
121
+ get user_confirmation_path(:confirmation_token => user.confirmation_token, :format => 'xml')
122
+ assert_response :success
123
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
124
+ end
125
+
126
+ test 'confirm account with invalid confirmation token in XML format should return invalid response' do
127
+ user = create_user(:confirm => false)
128
+ get user_confirmation_path(:confirmation_token => 'invalid_confirmation', :format => 'xml')
129
+ assert_response :unprocessable_entity
130
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
131
+ end
104
132
  end
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class LockTest < ActionController::IntegrationTest
4
-
4
+
5
5
  def visit_user_unlock_with_token(unlock_token)
6
6
  visit user_unlock_path(:unlock_token => unlock_token)
7
7
  end
@@ -106,4 +106,38 @@ class LockTest < ActionController::IntegrationTest
106
106
  end
107
107
  end
108
108
 
109
+ test 'user should be able to request a new unlock token via XML request' do
110
+ user = create_user(:locked => true)
111
+ ActionMailer::Base.deliveries.clear
112
+
113
+ post user_unlock_path(:format => 'xml'), :user => {:email => user.email}
114
+ assert_response :success
115
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
116
+ assert_equal 1, ActionMailer::Base.deliveries.size
117
+ end
118
+
119
+ test 'unlocked user should not be able to request a unlock token via XML request' do
120
+ user = create_user(:locked => false)
121
+ ActionMailer::Base.deliveries.clear
122
+
123
+ post user_unlock_path(:format => 'xml'), :user => {:email => user.email}
124
+ assert_response :unprocessable_entity
125
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
126
+ assert_equal 0, ActionMailer::Base.deliveries.size
127
+ end
128
+
129
+ test 'user with valid unlock token should be able to unlock account via XML request' do
130
+ user = create_user(:locked => true)
131
+ assert user.access_locked?
132
+ get user_unlock_path(:format => 'xml', :unlock_token => user.unlock_token)
133
+ assert_response :success
134
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
135
+ end
136
+
137
+
138
+ test 'user with invalid unlock token should not be able to unlock the account via XML request' do
139
+ get user_unlock_path(:format => 'xml', :unlock_token => 'invalid_token')
140
+ assert_response :unprocessable_entity
141
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
142
+ end
109
143
  end
@@ -157,4 +157,41 @@ class PasswordTest < ActionController::IntegrationTest
157
157
  assert !warden.authenticated?(:user)
158
158
  end
159
159
 
160
+ test 'reset password request with valid E-Mail in XML format should return valid response' do
161
+ create_user
162
+ post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"}
163
+ assert_response :success
164
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
165
+ end
166
+
167
+ test 'reset password request with invalid E-Mail in XML format should return valid response' do
168
+ create_user
169
+ post user_password_path(:format => 'xml'), :user => {:email => "invalid.test@test.com"}
170
+ assert_response :unprocessable_entity
171
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
172
+ end
173
+
174
+ test 'change password with valid parameters in XML format should return valid response' do
175
+ user = create_user
176
+ request_forgot_password
177
+ put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '987654321', :password_confirmation => '987654321'}
178
+ assert_response :success
179
+ assert warden.authenticated?(:user)
180
+ end
181
+
182
+ test 'change password with invalid token in XML format should return invalid response' do
183
+ user = create_user
184
+ request_forgot_password
185
+ put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'}
186
+ assert_response :unprocessable_entity
187
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
188
+ end
189
+
190
+ test 'change password with invalid new password in XML format should return invalid response' do
191
+ user = create_user
192
+ request_forgot_password
193
+ put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '', :password_confirmation => '987654321'}
194
+ assert_response :unprocessable_entity
195
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
196
+ end
160
197
  end
@@ -206,4 +206,49 @@ class RegistrationTest < ActionController::IntegrationTest
206
206
  assert_nil @request.session["devise.foo_bar"]
207
207
  assert_redirected_to new_user_registration_path
208
208
  end
209
+
210
+ test 'an admin sign up with valid information in XML format should return valid response' do
211
+ post admin_registration_path(:format => 'xml'), :admin => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
212
+ assert_response :success
213
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
214
+
215
+ admin = Admin.last :order => "id"
216
+ assert_equal admin.email, 'new_user@test.com'
217
+ end
218
+
219
+ test 'a user sign up with valid information in XML format should return valid response' do
220
+ post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
221
+ assert_response :success
222
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
223
+
224
+ user = User.last :order => "id"
225
+ assert_equal user.email, 'new_user@test.com'
226
+ end
227
+
228
+ test 'a user sign up with invalid information in XML format should return invalid response' do
229
+ post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'invalid' }
230
+ assert_response :unprocessable_entity
231
+ assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
232
+ end
233
+
234
+ test 'a user update information with valid data in XML format should return valid response' do
235
+ user = sign_in_as_user
236
+ put user_registration_path(:format => 'xml'), :user => { :current_password => '123456', :email => 'user.new@test.com' }
237
+ assert_response :success
238
+ assert_equal user.reload.email, 'user.new@test.com'
239
+ end
240
+
241
+ test 'a user update information with invalid data in XML format should return invalid response' do
242
+ user = sign_in_as_user
243
+ put user_registration_path(:format => 'xml'), :user => { :current_password => 'invalid', :email => 'user.new@test.com' }
244
+ assert_response :unprocessable_entity
245
+ assert_equal user.reload.email, 'user@test.com'
246
+ end
247
+
248
+ test 'a user cancel his account in XML format should return valid response' do
249
+ user = sign_in_as_user
250
+ delete user_registration_path(:format => 'xml')
251
+ assert_response :success
252
+ assert_equal User.count, 0
253
+ end
209
254
  end
@@ -6,12 +6,12 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
6
6
  # case_insensitive_keys is set to :email by default.
7
7
  email = 'Foo@Bar.com'
8
8
  user = new_user(:email => email)
9
-
9
+
10
10
  assert_equal email, user.email
11
11
  user.save!
12
12
  assert_equal email.downcase, user.email
13
13
  end
14
-
14
+
15
15
  test 'should respond to password and password confirmation' do
16
16
  user = new_user
17
17
  assert user.respond_to?(:password)
@@ -48,6 +48,18 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
48
48
  assert_not user.valid_password?('654321')
49
49
  end
50
50
 
51
+ test 'should not raise error with an empty password' do
52
+ user = create_user
53
+ user.encrypted_password = ''
54
+ assert_nothing_raised { user.valid_password?('123456') }
55
+ end
56
+
57
+ test 'should be an invalid password if the user has an empty password' do
58
+ user = create_user
59
+ user.encrypted_password = ''
60
+ assert_not user.valid_password?('654321')
61
+ end
62
+
51
63
  test 'should respond to current password' do
52
64
  assert new_user.respond_to?(:current_password)
53
65
  end
@@ -95,4 +107,10 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
95
107
  assert user.password.blank?
96
108
  assert user.password_confirmation.blank?
97
109
  end
110
+
111
+ test 'downcase_keys with validation' do
112
+ user = User.create(:email => "HEllO@example.com", :password => "123456")
113
+ user = User.create(:email => "HEllO@example.com", :password => "123456")
114
+ assert !user.valid?
115
+ end
98
116
  end
@@ -10,15 +10,6 @@ class RecoverableTest < ActiveSupport::TestCase
10
10
  assert_nil new_user.reset_password_token
11
11
  end
12
12
 
13
- test 'should regenerate reset password token each time' do
14
- user = create_user
15
- 3.times do
16
- token = user.reset_password_token
17
- user.send_reset_password_instructions
18
- assert_not_equal token, user.reset_password_token
19
- end
20
- end
21
-
22
13
  test 'should never generate the same reset password token for different users' do
23
14
  reset_password_tokens = []
24
15
  3.times do
@@ -161,4 +152,48 @@ class RecoverableTest < ActiveSupport::TestCase
161
152
  assert_not user.valid_password?(old_password)
162
153
  assert user.valid_password?('new_password')
163
154
  end
155
+
156
+ test 'should not reset reset password token during reset_password_within time' do
157
+ swap Devise, :reset_password_within => 1.hour do
158
+ user = create_user
159
+ user.send_reset_password_instructions
160
+ 3.times do
161
+ token = user.reset_password_token
162
+ user.send_reset_password_instructions
163
+ assert_equal token, user.reset_password_token
164
+ end
165
+ end
166
+ end
167
+
168
+ test 'should reset reset password token after reset_password_within time' do
169
+ swap Devise, :reset_password_within => 1.hour do
170
+ user = create_user
171
+ user.reset_password_sent_at = 2.days.ago
172
+ token = user.reset_password_token
173
+ user.send_reset_password_instructions
174
+ assert_not_equal token, user.reset_password_token
175
+ end
176
+ end
177
+
178
+ test 'should not reset password after reset_password_within time' do
179
+ swap Devise, :reset_password_within => 1.hour do
180
+ user = create_user
181
+ old_password = user.password
182
+ user.send :generate_reset_password_token!
183
+ user.reset_password_sent_at = 2.days.ago
184
+ user.save!
185
+
186
+ reset_password_user = User.reset_password_by_token(
187
+ :reset_password_token => user.reset_password_token,
188
+ :password => 'new_password',
189
+ :password_confirmation => 'new_password'
190
+ )
191
+ user.reload
192
+
193
+ assert user.valid_password?(old_password)
194
+ assert_not user.valid_password?('new_password')
195
+ assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join
196
+ end
197
+ end
198
+
164
199
  end
@@ -75,10 +75,10 @@ class ValidatableTest < ActiveSupport::TestCase
75
75
  assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
76
76
  end
77
77
 
78
- test 'should require a password with maximum of 20 characters long' do
79
- user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21)
78
+ test 'should require a password with maximum of 128 characters long' do
79
+ user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
80
80
  assert user.invalid?
81
- assert_equal 'is too long (maximum is 20 characters)', user.errors[:password].join
81
+ assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
82
82
  end
83
83
 
84
84
  test 'should not require password length when it\'s not changed' do
@@ -6,6 +6,15 @@ class Configurable < User
6
6
  :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
7
7
  end
8
8
 
9
+ class WithValidation < Admin
10
+ devise :database_authenticatable, :validatable, :password_length => 2..6
11
+ end
12
+
13
+ class Several < Admin
14
+ devise :validatable
15
+ devise :lockable
16
+ end
17
+
9
18
  class Inheritable < Admin
10
19
  end
11
20
 
@@ -29,6 +38,20 @@ class ActiveRecordTest < ActiveSupport::TestCase
29
38
  assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
30
39
  end
31
40
 
41
+ if DEVISE_ORM == :active_record
42
+ test 'validations options are not applied to late' do
43
+ validators = WithValidation.validators_on :password
44
+ length = validators.find { |v| v.kind == :length }
45
+ assert_equal 2, length.options[:minimum]
46
+ assert_equal 6, length.options[:maximum]
47
+ end
48
+
49
+ test 'validations are applied just once' do
50
+ validators = Several.validators_on :password
51
+ assert_equal 1, validators.select{ |v| v.kind == :length }.length
52
+ end
53
+ end
54
+
32
55
  test 'chosen modules are inheritable' do
33
56
  assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable, :encryptable
34
57
  end
@@ -80,8 +80,8 @@ Devise.setup do |config|
80
80
  config.use_salt_as_remember_token = true
81
81
 
82
82
  # ==> Configuration for :validatable
83
- # Range for password length. Default is 6..20.
84
- # config.password_length = 6..20
83
+ # Range for password length. Default is 6..128.
84
+ # config.password_length = 6..128
85
85
 
86
86
  # Regex to use to validate the email address
87
87
  # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
@@ -119,6 +119,11 @@ Devise.setup do |config|
119
119
  # Defines which key will be used when recovering the password for an account
120
120
  # config.reset_password_keys = [ :email ]
121
121
 
122
+ # Time interval you can reset your password with a reset password key.
123
+ # Don't put a too small interval or your users won't have the time to
124
+ # change their passwords.
125
+ config.reset_password_within = 2.hours
126
+
122
127
  # ==> Configuration for :encryptable
123
128
  # Allow you to use another encryption algorithm besides bcrypt (default). You can use
124
129
  # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
@@ -29,6 +29,8 @@ Rails.application.routes.draw do
29
29
  end
30
30
 
31
31
  # Other routes for routing_test.rb
32
+ devise_for :reader, :class_name => "User", :only => :passwords
33
+
32
34
  namespace :publisher, :path_names => { :sign_in => "i_dont_care", :sign_out => "get_out" } do
33
35
  devise_for :accounts, :class_name => "Admin", :path_names => { :sign_in => "get_in" }
34
36
  end
@@ -123,6 +123,13 @@ class CustomizedRoutingTest < ActionController::TestCase
123
123
  end
124
124
  end
125
125
 
126
+ test 'does only map reader password' do
127
+ assert_raise ActionController::RoutingError do
128
+ assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, 'reader/sessions/new')
129
+ end
130
+ assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'reader/password/new')
131
+ end
132
+
126
133
  test 'map account with custom path name for session sign in' do
127
134
  assert_recognizes({:controller => 'devise/sessions', :action => 'new', :locale => 'en'}, '/en/accounts/login')
128
135
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 1
10
- version: 1.2.1
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jos\xC3\xA9 Valim"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-03-28 00:00:00 +02:00
19
+ date: 2011-04-16 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -167,6 +167,7 @@ files:
167
167
  - lib/generators/templates/devise.rb
168
168
  - test/controllers/helpers_test.rb
169
169
  - test/controllers/internal_helpers_test.rb
170
+ - test/controllers/sessions_controller_test.rb
170
171
  - test/controllers/url_helpers_test.rb
171
172
  - test/devise_test.rb
172
173
  - test/encryptors_test.rb
@@ -299,6 +300,7 @@ summary: Flexible authentication solution for Rails with Warden
299
300
  test_files:
300
301
  - test/controllers/helpers_test.rb
301
302
  - test/controllers/internal_helpers_test.rb
303
+ - test/controllers/sessions_controller_test.rb
302
304
  - test/controllers/url_helpers_test.rb
303
305
  - test/devise_test.rb
304
306
  - test/encryptors_test.rb