devise 2.1.2 → 3.5.10

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 (242) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +39 -10
  3. data/.yardopts +9 -0
  4. data/{CHANGELOG.rdoc → CHANGELOG.md} +445 -112
  5. data/CODE_OF_CONDUCT.md +22 -0
  6. data/CONTRIBUTING.md +16 -0
  7. data/Gemfile +10 -15
  8. data/Gemfile.lock +151 -129
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +256 -96
  11. data/Rakefile +4 -2
  12. data/app/controllers/devise/confirmations_controller.rb +15 -7
  13. data/app/controllers/devise/omniauth_callbacks_controller.rb +6 -2
  14. data/app/controllers/devise/passwords_controller.rb +33 -9
  15. data/app/controllers/devise/registrations_controller.rb +66 -26
  16. data/app/controllers/devise/sessions_controller.rb +52 -21
  17. data/app/controllers/devise/unlocks_controller.rb +11 -6
  18. data/app/controllers/devise_controller.rb +65 -58
  19. data/app/helpers/devise_helper.rb +2 -2
  20. data/app/mailers/devise/mailer.rb +19 -10
  21. data/app/views/devise/confirmations/new.html.erb +8 -4
  22. data/app/views/devise/mailer/confirmation_instructions.html.erb +2 -2
  23. data/app/views/devise/mailer/password_change.html.erb +3 -0
  24. data/app/views/devise/mailer/reset_password_instructions.html.erb +2 -2
  25. data/app/views/devise/mailer/unlock_instructions.html.erb +2 -2
  26. data/app/views/devise/passwords/edit.html.erb +15 -6
  27. data/app/views/devise/passwords/new.html.erb +8 -4
  28. data/app/views/devise/registrations/edit.html.erb +29 -15
  29. data/app/views/devise/registrations/new.html.erb +19 -8
  30. data/app/views/devise/sessions/new.html.erb +17 -8
  31. data/app/views/devise/shared/{_links.erb → _links.html.erb} +4 -4
  32. data/app/views/devise/unlocks/new.html.erb +8 -4
  33. data/config/locales/en.yml +51 -47
  34. data/devise.gemspec +8 -6
  35. data/devise.png +0 -0
  36. data/gemfiles/Gemfile.rails-3.2-stable +29 -0
  37. data/gemfiles/Gemfile.rails-3.2-stable.lock +172 -0
  38. data/gemfiles/Gemfile.rails-4.0-stable +30 -0
  39. data/gemfiles/Gemfile.rails-4.0-stable.lock +166 -0
  40. data/gemfiles/Gemfile.rails-4.1-stable +30 -0
  41. data/gemfiles/Gemfile.rails-4.1-stable.lock +171 -0
  42. data/gemfiles/Gemfile.rails-4.2-stable +30 -0
  43. data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
  44. data/lib/devise/controllers/helpers.rb +126 -108
  45. data/lib/devise/controllers/rememberable.rb +19 -17
  46. data/lib/devise/controllers/scoped_views.rb +1 -1
  47. data/lib/devise/controllers/sign_in_out.rb +96 -0
  48. data/lib/devise/controllers/store_location.rb +58 -0
  49. data/lib/devise/controllers/url_helpers.rb +7 -7
  50. data/lib/devise/encryptor.rb +22 -0
  51. data/lib/devise/failure_app.rb +85 -25
  52. data/lib/devise/hooks/activatable.rb +5 -6
  53. data/lib/devise/hooks/csrf_cleaner.rb +7 -0
  54. data/lib/devise/hooks/forgetable.rb +1 -1
  55. data/lib/devise/hooks/lockable.rb +2 -2
  56. data/lib/devise/hooks/proxy.rb +21 -0
  57. data/lib/devise/hooks/rememberable.rb +5 -4
  58. data/lib/devise/hooks/timeoutable.rb +16 -8
  59. data/lib/devise/hooks/trackable.rb +1 -1
  60. data/lib/devise/mailers/helpers.rb +27 -23
  61. data/lib/devise/mapping.rb +11 -7
  62. data/lib/devise/models/authenticatable.rb +82 -66
  63. data/lib/devise/models/confirmable.rb +142 -55
  64. data/lib/devise/models/database_authenticatable.rb +59 -15
  65. data/lib/devise/models/lockable.rb +41 -30
  66. data/lib/devise/models/omniauthable.rb +3 -3
  67. data/lib/devise/models/recoverable.rb +56 -41
  68. data/lib/devise/models/rememberable.rb +65 -27
  69. data/lib/devise/models/timeoutable.rb +2 -8
  70. data/lib/devise/models/trackable.rb +6 -4
  71. data/lib/devise/models/validatable.rb +9 -9
  72. data/lib/devise/models.rb +4 -13
  73. data/lib/devise/modules.rb +10 -11
  74. data/lib/devise/omniauth/url_helpers.rb +2 -2
  75. data/lib/devise/orm/active_record.rb +1 -1
  76. data/lib/devise/orm/mongoid.rb +1 -1
  77. data/lib/devise/{param_filter.rb → parameter_filter.rb} +10 -11
  78. data/lib/devise/parameter_sanitizer.rb +99 -0
  79. data/lib/devise/rails/routes.rb +173 -115
  80. data/lib/devise/rails/warden_compat.rb +10 -31
  81. data/lib/devise/rails.rb +14 -12
  82. data/lib/devise/strategies/authenticatable.rb +26 -26
  83. data/lib/devise/strategies/base.rb +1 -1
  84. data/lib/devise/strategies/database_authenticatable.rb +8 -4
  85. data/lib/devise/strategies/rememberable.rb +15 -5
  86. data/lib/devise/test_helpers.rb +7 -5
  87. data/lib/devise/time_inflector.rb +14 -0
  88. data/lib/devise/token_generator.rb +70 -0
  89. data/lib/devise/version.rb +1 -1
  90. data/lib/devise.rb +110 -52
  91. data/lib/generators/active_record/devise_generator.rb +34 -18
  92. data/lib/generators/active_record/templates/migration.rb +5 -6
  93. data/lib/generators/active_record/templates/migration_existing.rb +5 -6
  94. data/lib/generators/devise/controllers_generator.rb +44 -0
  95. data/lib/generators/devise/devise_generator.rb +5 -3
  96. data/lib/generators/devise/install_generator.rb +5 -0
  97. data/lib/generators/devise/orm_helpers.rb +25 -6
  98. data/lib/generators/devise/views_generator.rb +52 -22
  99. data/lib/generators/mongoid/devise_generator.rb +21 -26
  100. data/lib/generators/templates/README +9 -5
  101. data/lib/generators/templates/controllers/README +14 -0
  102. data/lib/generators/templates/controllers/confirmations_controller.rb +28 -0
  103. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +28 -0
  104. data/lib/generators/templates/controllers/passwords_controller.rb +32 -0
  105. data/lib/generators/templates/controllers/registrations_controller.rb +60 -0
  106. data/lib/generators/templates/controllers/sessions_controller.rb +25 -0
  107. data/lib/generators/templates/controllers/unlocks_controller.rb +28 -0
  108. data/lib/generators/templates/devise.rb +80 -43
  109. data/lib/generators/templates/markerb/confirmation_instructions.markerb +2 -2
  110. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  111. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  112. data/lib/generators/templates/markerb/unlock_instructions.markerb +2 -2
  113. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +3 -2
  114. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
  115. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
  116. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +11 -6
  117. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
  118. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +6 -6
  119. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +3 -2
  120. data/script/cached-bundle +49 -0
  121. data/script/s3-put +71 -0
  122. data/test/controllers/custom_registrations_controller_test.rb +40 -0
  123. data/test/controllers/helper_methods_test.rb +21 -0
  124. data/test/controllers/helpers_test.rb +95 -32
  125. data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
  126. data/test/controllers/internal_helpers_test.rb +39 -14
  127. data/test/controllers/load_hooks_controller_test.rb +19 -0
  128. data/test/controllers/passwords_controller_test.rb +31 -0
  129. data/test/controllers/sessions_controller_test.rb +66 -6
  130. data/test/controllers/url_helpers_test.rb +10 -4
  131. data/test/delegator_test.rb +1 -1
  132. data/test/devise_test.rb +45 -10
  133. data/test/failure_app_test.rb +121 -27
  134. data/test/generators/active_record_generator_test.rb +48 -8
  135. data/test/generators/controllers_generator_test.rb +48 -0
  136. data/test/generators/devise_generator_test.rb +2 -2
  137. data/test/generators/mongoid_generator_test.rb +3 -3
  138. data/test/generators/views_generator_test.rb +54 -3
  139. data/test/helpers/devise_helper_test.rb +18 -20
  140. data/test/integration/authenticatable_test.rb +161 -65
  141. data/test/integration/confirmable_test.rb +146 -77
  142. data/test/integration/database_authenticatable_test.rb +43 -30
  143. data/test/integration/http_authenticatable_test.rb +30 -22
  144. data/test/integration/lockable_test.rb +64 -49
  145. data/test/integration/omniauthable_test.rb +17 -15
  146. data/test/integration/recoverable_test.rb +111 -70
  147. data/test/integration/registerable_test.rb +114 -79
  148. data/test/integration/rememberable_test.rb +87 -31
  149. data/test/integration/timeoutable_test.rb +77 -33
  150. data/test/integration/trackable_test.rb +5 -5
  151. data/test/mailers/confirmation_instructions_test.rb +28 -8
  152. data/test/mailers/reset_password_instructions_test.rb +21 -8
  153. data/test/mailers/unlock_instructions_test.rb +20 -6
  154. data/test/mapping_test.rb +12 -5
  155. data/test/models/authenticatable_test.rb +17 -1
  156. data/test/models/confirmable_test.rb +216 -62
  157. data/test/models/database_authenticatable_test.rb +129 -49
  158. data/test/models/lockable_test.rb +132 -45
  159. data/test/models/recoverable_test.rb +100 -54
  160. data/test/models/rememberable_test.rb +89 -94
  161. data/test/models/serializable_test.rb +12 -11
  162. data/test/models/timeoutable_test.rb +6 -1
  163. data/test/models/trackable_test.rb +28 -0
  164. data/test/models/validatable_test.rb +31 -21
  165. data/test/models_test.rb +22 -48
  166. data/test/omniauth/config_test.rb +4 -4
  167. data/test/omniauth/url_helpers_test.rb +7 -4
  168. data/test/orm/active_record.rb +1 -0
  169. data/test/orm/mongoid.rb +2 -3
  170. data/test/parameter_sanitizer_test.rb +81 -0
  171. data/test/rails_app/Rakefile +0 -4
  172. data/test/rails_app/app/active_record/shim.rb +1 -1
  173. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  174. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  175. data/test/rails_app/app/active_record/user_without_email.rb +8 -0
  176. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
  177. data/test/rails_app/app/controllers/admins_controller.rb +0 -5
  178. data/test/rails_app/app/controllers/application_controller.rb +6 -2
  179. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  180. data/test/rails_app/app/controllers/custom/registrations_controller.rb +31 -0
  181. data/test/rails_app/app/controllers/home_controller.rb +1 -1
  182. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
  183. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
  184. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
  185. data/test/rails_app/app/controllers/users_controller.rb +12 -4
  186. data/test/rails_app/app/mailers/users/from_proc_mailer.rb +3 -0
  187. data/test/rails_app/app/mailers/users/mailer.rb +1 -1
  188. data/test/rails_app/app/mailers/users/reply_to_mailer.rb +4 -0
  189. data/test/rails_app/app/mongoid/admin.rb +12 -10
  190. data/test/rails_app/app/mongoid/shim.rb +4 -5
  191. data/test/rails_app/app/mongoid/user.rb +19 -22
  192. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  193. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  194. data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
  195. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  196. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  197. data/test/rails_app/app/views/home/index.html.erb +1 -1
  198. data/test/rails_app/app/views/home/join.html.erb +1 -1
  199. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  200. data/test/rails_app/app/views/layouts/application.html.erb +1 -1
  201. data/test/rails_app/app/views/users/edit_form.html.erb +1 -0
  202. data/test/rails_app/bin/bundle +3 -0
  203. data/test/rails_app/bin/rails +4 -0
  204. data/test/rails_app/bin/rake +4 -0
  205. data/test/rails_app/config/application.rb +4 -5
  206. data/test/rails_app/config/boot.rb +9 -3
  207. data/test/rails_app/config/environment.rb +2 -2
  208. data/test/rails_app/config/environments/development.rb +19 -7
  209. data/test/rails_app/config/environments/production.rb +68 -17
  210. data/test/rails_app/config/environments/test.rb +24 -16
  211. data/test/rails_app/config/initializers/devise.rb +22 -20
  212. data/test/rails_app/config/initializers/secret_token.rb +8 -2
  213. data/test/rails_app/config/initializers/session_store.rb +1 -0
  214. data/test/rails_app/config/routes.rb +71 -46
  215. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +9 -12
  216. data/test/rails_app/db/schema.rb +21 -18
  217. data/test/rails_app/lib/shared_admin.rb +7 -4
  218. data/test/rails_app/lib/shared_user.rb +6 -3
  219. data/test/rails_app/lib/shared_user_without_email.rb +26 -0
  220. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  221. data/test/rails_test.rb +9 -0
  222. data/test/routes_test.rb +94 -78
  223. data/test/support/action_controller/record_identifier.rb +10 -0
  224. data/test/support/assertions.rb +2 -3
  225. data/test/support/helpers.rb +18 -32
  226. data/test/support/integration.rb +17 -16
  227. data/test/support/locale/en.yml +4 -0
  228. data/test/support/mongoid.yml +6 -0
  229. data/test/test_helper.rb +8 -1
  230. data/test/test_helpers_test.rb +64 -20
  231. data/test/test_models.rb +33 -0
  232. data/test/time_helpers.rb +137 -0
  233. metadata +172 -51
  234. data/app/views/devise/_links.erb +0 -3
  235. data/gemfiles/Gemfile.rails-3.1.x +0 -35
  236. data/gemfiles/Gemfile.rails-3.1.x.lock +0 -167
  237. data/lib/devise/models/token_authenticatable.rb +0 -77
  238. data/lib/devise/strategies/token_authenticatable.rb +0 -56
  239. data/test/indifferent_hash.rb +0 -33
  240. data/test/integration/token_authenticatable_test.rb +0 -161
  241. data/test/models/token_authenticatable_test.rb +0 -55
  242. data/test/rails_app/script/rails +0 -10
@@ -6,32 +6,33 @@ class SerializableTest < ActiveSupport::TestCase
6
6
  end
7
7
 
8
8
  test 'should not include unsafe keys on XML' do
9
- assert_match /email/, @user.to_xml
10
- assert_no_match /confirmation-token/, @user.to_xml
9
+ assert_match(/email/, @user.to_xml)
10
+ assert_no_match(/confirmation-token/, @user.to_xml)
11
11
  end
12
12
 
13
13
  test 'should not include unsafe keys on XML even if a new except is provided' do
14
- assert_no_match /email/, @user.to_xml(:except => :email)
15
- assert_no_match /confirmation-token/, @user.to_xml(:except => :email)
14
+ assert_no_match(/email/, @user.to_xml(except: :email))
15
+ assert_no_match(/confirmation-token/, @user.to_xml(except: :email))
16
16
  end
17
17
 
18
18
  test 'should include unsafe keys on XML if a force_except is provided' do
19
- assert_no_match /<email/, @user.to_xml(:force_except => :email)
20
- assert_match /confirmation-token/, @user.to_xml(:force_except => :email)
19
+ assert_no_match(/<email/, @user.to_xml(force_except: :email))
20
+ assert_match(/confirmation-token/, @user.to_xml(force_except: :email))
21
21
  end
22
22
 
23
23
  test 'should not include unsafe keys on JSON' do
24
- assert_equal %w(created_at email facebook_token id updated_at username), from_json().keys.sort
24
+ keys = from_json().keys.select{ |key| !key.include?("id") }
25
+ assert_equal %w(created_at email facebook_token updated_at username), keys.sort
25
26
  end
26
27
 
27
28
  test 'should not include unsafe keys on JSON even if a new except is provided' do
28
- assert_no_key "email", from_json(:except => :email)
29
- assert_no_key "confirmation_token", from_json(:except => :email)
29
+ assert_no_key "email", from_json(except: :email)
30
+ assert_no_key "confirmation_token", from_json(except: :email)
30
31
  end
31
32
 
32
33
  test 'should include unsafe keys on JSON if a force_except is provided' do
33
- assert_no_key "email", from_json(:force_except => :email)
34
- assert_key "confirmation_token", from_json(:force_except => :email)
34
+ assert_no_key "email", from_json(force_except: :email)
35
+ assert_key "confirmation_token", from_json(force_except: :email)
35
36
  end
36
37
 
37
38
  def assert_key(key, subject)
@@ -29,7 +29,7 @@ class TimeoutableTest < ActiveSupport::TestCase
29
29
  end
30
30
 
31
31
  test 'fallback to Devise config option' do
32
- swap Devise, :timeout_in => 1.minute do
32
+ swap Devise, timeout_in: 1.minute do
33
33
  user = new_user
34
34
  assert user.timedout?(2.minutes.ago)
35
35
  assert_not user.timedout?(30.seconds.ago)
@@ -43,4 +43,9 @@ class TimeoutableTest < ActiveSupport::TestCase
43
43
  test 'required_fields should contain the fields that Devise uses' do
44
44
  assert_same_content Devise::Models::Timeoutable.required_fields(User), []
45
45
  end
46
+
47
+ test 'should not raise error if remember_created_at is not empty and rememberable is disabled' do
48
+ user = create_admin(remember_created_at: Time.current)
49
+ assert user.timedout?(31.minutes.ago)
50
+ end
46
51
  end
@@ -10,4 +10,32 @@ class TrackableTest < ActiveSupport::TestCase
10
10
  :sign_in_count
11
11
  ]
12
12
  end
13
+
14
+ test 'update_tracked_fields should only set attributes but not save the record' do
15
+ user = create_user
16
+ request = mock
17
+ request.stubs(:remote_ip).returns("127.0.0.1")
18
+
19
+ assert_nil user.current_sign_in_ip
20
+ assert_nil user.last_sign_in_ip
21
+ assert_nil user.current_sign_in_at
22
+ assert_nil user.last_sign_in_at
23
+ assert_equal 0, user.sign_in_count
24
+
25
+ user.update_tracked_fields(request)
26
+
27
+ assert_equal "127.0.0.1", user.current_sign_in_ip
28
+ assert_equal "127.0.0.1", user.last_sign_in_ip
29
+ assert_not_nil user.current_sign_in_at
30
+ assert_not_nil user.last_sign_in_at
31
+ assert_equal 1, user.sign_in_count
32
+
33
+ user.reload
34
+
35
+ assert_nil user.current_sign_in_ip
36
+ assert_nil user.last_sign_in_ip
37
+ assert_nil user.current_sign_in_at
38
+ assert_nil user.last_sign_in_at
39
+ assert_equal 0, user.sign_in_count
40
+ end
13
41
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
 
4
4
  class ValidatableTest < ActiveSupport::TestCase
5
5
  test 'should require email to be set' do
6
- user = new_user(:email => nil)
6
+ user = new_user(email: nil)
7
7
  assert user.invalid?
8
8
  assert user.errors[:email]
9
9
  assert_equal 'can\'t be blank', user.errors[:email].join
@@ -12,7 +12,7 @@ class ValidatableTest < ActiveSupport::TestCase
12
12
  test 'should require uniqueness of email if email has changed, allowing blank' do
13
13
  existing_user = create_user
14
14
 
15
- user = new_user(:email => '')
15
+ user = new_user(email: '')
16
16
  assert user.invalid?
17
17
  assert_no_match(/taken/, user.errors[:email].join)
18
18
 
@@ -20,12 +20,12 @@ class ValidatableTest < ActiveSupport::TestCase
20
20
  assert user.invalid?
21
21
  assert_match(/taken/, user.errors[:email].join)
22
22
 
23
- user.save(:validate => false)
23
+ user.save(validate: false)
24
24
  assert user.valid?
25
25
  end
26
26
 
27
27
  test 'should require correct email format if email has changed, allowing blank' do
28
- user = new_user(:email => '')
28
+ user = new_user(email: '')
29
29
  assert user.invalid?
30
30
  assert_not_equal 'is invalid', user.errors[:email].join
31
31
 
@@ -35,31 +35,36 @@ class ValidatableTest < ActiveSupport::TestCase
35
35
  assert_equal 'is invalid', user.errors[:email].join
36
36
  end
37
37
 
38
- user.save(:validate => false)
38
+ user.save(validate: false)
39
39
  assert user.valid?
40
40
  end
41
41
 
42
42
  test 'should accept valid emails' do
43
43
  %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|
44
- user = new_user(:email => email)
44
+ user = new_user(email: email)
45
45
  assert user.valid?, 'should be valid with email ' << email
46
46
  assert_blank user.errors[:email]
47
47
  end
48
48
  end
49
49
 
50
50
  test 'should require password to be set when creating a new record' do
51
- user = new_user(:password => '', :password_confirmation => '')
51
+ user = new_user(password: '', password_confirmation: '')
52
52
  assert user.invalid?
53
53
  assert_equal 'can\'t be blank', user.errors[:password].join
54
54
  end
55
55
 
56
56
  test 'should require confirmation to be set when creating a new record' do
57
- user = new_user(:password => 'new_password', :password_confirmation => 'blabla')
57
+ user = new_user(password: 'new_password', password_confirmation: 'blabla')
58
58
  assert user.invalid?
59
- assert_equal 'doesn\'t match confirmation', user.errors[:password].join
59
+
60
+ if Devise.rails4?
61
+ assert_equal 'doesn\'t match Password', user.errors[:password_confirmation].join
62
+ else
63
+ assert_equal 'doesn\'t match confirmation', user.errors[:password].join
64
+ end
60
65
  end
61
66
 
62
- test 'should require password when updating/reseting password' do
67
+ test 'should require password when updating/resetting password' do
63
68
  user = create_user
64
69
 
65
70
  user.password = ''
@@ -69,23 +74,28 @@ class ValidatableTest < ActiveSupport::TestCase
69
74
  assert_equal 'can\'t be blank', user.errors[:password].join
70
75
  end
71
76
 
72
- test 'should require confirmation when updating/reseting password' do
77
+ test 'should require confirmation when updating/resetting password' do
73
78
  user = create_user
74
79
  user.password_confirmation = 'another_password'
75
80
  assert user.invalid?
76
- assert_equal 'doesn\'t match confirmation', user.errors[:password].join
81
+
82
+ if Devise.rails4?
83
+ assert_equal 'doesn\'t match Password', user.errors[:password_confirmation].join
84
+ else
85
+ assert_equal 'doesn\'t match confirmation', user.errors[:password].join
86
+ end
77
87
  end
78
88
 
79
- test 'should require a password with minimum of 6 characters' do
80
- user = new_user(:password => '12345', :password_confirmation => '12345')
89
+ test 'should require a password with minimum of 7 characters' do
90
+ user = new_user(password: '12345', password_confirmation: '12345')
81
91
  assert user.invalid?
82
- assert_equal 'is too short (minimum is 6 characters)', user.errors[:password].join
92
+ assert_equal 'is too short (minimum is 7 characters)', user.errors[:password].join
83
93
  end
84
94
 
85
- test 'should require a password with maximum of 128 characters long' do
86
- user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
95
+ test 'should require a password with maximum of 72 characters long' do
96
+ user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
87
97
  assert user.invalid?
88
- assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
98
+ assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
89
99
  end
90
100
 
91
101
  test 'should not require password length when it\'s not changed' do
@@ -98,11 +108,11 @@ class ValidatableTest < ActiveSupport::TestCase
98
108
  assert_not (user.errors[:password].join =~ /is too long/)
99
109
  end
100
110
 
101
- test 'should complain about length even if possword is not required' do
102
- user = new_user(:password => 'x'*129, :password_confirmation => 'x'*129)
111
+ test 'should complain about length even if password is not required' do
112
+ user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
103
113
  user.stubs(:password_required?).returns(false)
104
114
  assert user.invalid?
105
- assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
115
+ assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
106
116
  end
107
117
 
108
118
  test 'should not be included in objects with invalid API' do
data/test/models_test.rb CHANGED
@@ -1,26 +1,5 @@
1
1
  require 'test_helper'
2
-
3
- class Configurable < User
4
- devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
5
- :stretches => 15, :pepper => 'abcdef', :allow_unconfirmed_access_for => 5.days,
6
- :remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
7
- end
8
-
9
- class WithValidation < Admin
10
- devise :database_authenticatable, :validatable, :password_length => 2..6
11
- end
12
-
13
- class UserWithValidation < User
14
- validates_presence_of :username
15
- end
16
-
17
- class Several < Admin
18
- devise :validatable
19
- devise :lockable
20
- end
21
-
22
- class Inheritable < Admin
23
- end
2
+ require 'test_models'
24
3
 
25
4
  class ActiveRecordTest < ActiveSupport::TestCase
26
5
  def include_module?(klass, mod)
@@ -104,7 +83,18 @@ class ActiveRecordTest < ActiveSupport::TestCase
104
83
  end
105
84
 
106
85
  test 'set null fields on migrations' do
107
- Admin.create!
86
+ # Ignore email sending since no email exists.
87
+ klass = Class.new(Admin) do
88
+ def send_devise_notification(*); end
89
+ end
90
+
91
+ klass.create!
92
+ end
93
+ end
94
+
95
+ module StubModelFilters
96
+ def stub_filter(name)
97
+ define_singleton_method(name) { |*| nil }
108
98
  end
109
99
  end
110
100
 
@@ -112,9 +102,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
112
102
  test 'checks if the class respond_to the required fields' do
113
103
  Player = Class.new do
114
104
  extend Devise::Models
105
+ extend StubModelFilters
115
106
 
116
- def self.before_validation(instance)
117
- end
107
+ stub_filter :before_validation
108
+ stub_filter :after_update
118
109
 
119
110
  devise :database_authenticatable
120
111
 
@@ -129,9 +120,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
129
120
  test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
130
121
  Clown = Class.new do
131
122
  extend Devise::Models
123
+ extend StubModelFilters
132
124
 
133
- def self.before_validation(instance)
134
- end
125
+ stub_filter :before_validation
126
+ stub_filter :after_update
135
127
 
136
128
  devise :database_authenticatable
137
129
 
@@ -146,9 +138,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
146
138
  test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
147
139
  Magician = Class.new do
148
140
  extend Devise::Models
141
+ extend StubModelFilters
149
142
 
150
- def self.before_validation(instance)
151
- end
143
+ stub_filter :before_validation
144
+ stub_filter :after_update
152
145
 
153
146
  devise :database_authenticatable
154
147
  end
@@ -157,23 +150,4 @@ class CheckFieldsTest < ActiveSupport::TestCase
157
150
  Devise::Models.check_fields!(Magician)
158
151
  end
159
152
  end
160
-
161
- test "doesn't raise a NoMethodError exception when the module doesn't have a required_field(klass) class method" do
162
- driver = Class.new do
163
- extend Devise::Models
164
-
165
- def self.before_validation(instance)
166
- end
167
-
168
- attr_accessor :encrypted_password, :email
169
-
170
- devise :database_authenticatable
171
- end
172
-
173
- swap_module_method_existence Devise::Models::DatabaseAuthenticatable, :required_fields do
174
- assert_deprecated do
175
- Devise::Models.check_fields!(driver)
176
- end
177
- end
178
- end
179
153
  end
@@ -11,12 +11,12 @@ class OmniAuthConfigTest < ActiveSupport::TestCase
11
11
  end
12
12
 
13
13
  test 'strategy_name returns provider if no name option are given' do
14
- config = Devise::OmniAuth::Config.new :facebook, [{ :other => :option }]
14
+ config = Devise::OmniAuth::Config.new :facebook, [{ other: :option }]
15
15
  assert_equal :facebook, config.strategy_name
16
16
  end
17
17
 
18
18
  test 'returns name option when have a name' do
19
- config = Devise::OmniAuth::Config.new :facebook, [{ :name => :github }]
19
+ config = Devise::OmniAuth::Config.new :facebook, [{ name: :github }]
20
20
  assert_equal :github, config.strategy_name
21
21
  end
22
22
 
@@ -50,8 +50,8 @@ class OmniAuthConfigTest < ActiveSupport::TestCase
50
50
  end
51
51
 
52
52
  test 'allows the user to define a custom require path' do
53
- config = Devise::OmniAuth::Config.new :my_strategy, [{:strategy_class => MyStrategy}]
53
+ config = Devise::OmniAuth::Config.new :my_strategy, [{strategy_class: MyStrategy}]
54
54
  config_class = config.strategy_class
55
55
  assert_equal MyStrategy, config_class
56
56
  end
57
- end
57
+ end
@@ -1,6 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class OmniAuthRoutesTest < ActionController::TestCase
4
+ ExpectedUrlGeneratiorError = Devise.rails4? ?
5
+ ActionController::UrlGenerationError : ActionController::RoutingError
6
+
4
7
  tests ApplicationController
5
8
 
6
9
  def assert_path(action, provider, with_param=true)
@@ -14,8 +17,8 @@ class OmniAuthRoutesTest < ActionController::TestCase
14
17
 
15
18
  if with_param
16
19
  # Default url params
17
- assert_equal @controller.send(action, :user, provider, :param => 123),
18
- @controller.send("user_#{action}", provider, :param => 123)
20
+ assert_equal @controller.send(action, :user, provider, param: 123),
21
+ @controller.send("user_#{action}", provider, param: 123)
19
22
  end
20
23
  end
21
24
 
@@ -30,7 +33,7 @@ class OmniAuthRoutesTest < ActionController::TestCase
30
33
  test 'should generate authorization path' do
31
34
  assert_match "/users/auth/facebook", @controller.omniauth_authorize_path(:user, :facebook)
32
35
 
33
- assert_raise ActionController::RoutingError do
36
+ assert_raise ExpectedUrlGeneratiorError do
34
37
  @controller.omniauth_authorize_path(:user, :github)
35
38
  end
36
39
  end
@@ -41,7 +44,7 @@ class OmniAuthRoutesTest < ActionController::TestCase
41
44
 
42
45
  test 'should generate authorization path with params' do
43
46
  assert_match "/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com",
44
- @controller.omniauth_authorize_path(:user, :openid, :openid_url => "http://yahoo.com")
47
+ @controller.omniauth_authorize_path(:user, :openid, openid_url: "http://yahoo.com")
45
48
  end
46
49
 
47
50
  test 'should not add a "?" if no param was sent' do
@@ -1,5 +1,6 @@
1
1
  ActiveRecord::Migration.verbose = false
2
2
  ActiveRecord::Base.logger = Logger.new(nil)
3
+ ActiveRecord::Base.include_root_in_json = true
3
4
 
4
5
  ActiveRecord::Migrator.migrate(File.expand_path("../../rails_app/db/migrate/", __FILE__))
5
6
 
data/test/orm/mongoid.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  require 'mongoid/version'
2
2
 
3
3
  Mongoid.configure do |config|
4
- config.master = Mongo::Connection.new('127.0.0.1', 27017).db("devise-test-suite")
4
+ config.load!('test/support/mongoid.yml')
5
5
  config.use_utc = true
6
6
  config.include_root_in_json = true
7
7
  end
8
8
 
9
9
  class ActiveSupport::TestCase
10
10
  setup do
11
- User.delete_all
12
- Admin.delete_all
11
+ Mongoid.purge!
13
12
  end
14
13
  end
@@ -0,0 +1,81 @@
1
+ require 'test_helper'
2
+ require 'devise/parameter_sanitizer'
3
+
4
+ class BaseSanitizerTest < ActiveSupport::TestCase
5
+ def sanitizer(params)
6
+ Devise::BaseSanitizer.new(User, :user, params)
7
+ end
8
+
9
+ test 'returns chosen params' do
10
+ sanitizer = sanitizer(user: { "email" => "jose" })
11
+ assert_equal({ "email" => "jose" }, sanitizer.sanitize(:sign_in))
12
+ end
13
+ end
14
+
15
+ if defined?(ActionController::StrongParameters)
16
+ require 'active_model/forbidden_attributes_protection'
17
+
18
+ class ParameterSanitizerTest < ActiveSupport::TestCase
19
+ def sanitizer(params)
20
+ params = ActionController::Parameters.new(params)
21
+ Devise::ParameterSanitizer.new(User, :user, params)
22
+ end
23
+
24
+ test 'filters some parameters on sign in by default' do
25
+ sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid", "remember_me" => "1" })
26
+ assert_equal({ "email" => "jose", "password" => "invalid", "remember_me" => "1" }, sanitizer.sanitize(:sign_in))
27
+ end
28
+
29
+ test 'handles auth keys as a hash' do
30
+ swap Devise, authentication_keys: {email: true} do
31
+ sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid" })
32
+ assert_equal({ "email" => "jose", "password" => "invalid" }, sanitizer.sanitize(:sign_in))
33
+ end
34
+ end
35
+
36
+ test 'filters some parameters on sign up by default' do
37
+ sanitizer = sanitizer(user: { "email" => "jose", "role" => "invalid" })
38
+ assert_equal({ "email" => "jose" }, sanitizer.sanitize(:sign_up))
39
+ end
40
+
41
+ test 'filters some parameters on account update by default' do
42
+ sanitizer = sanitizer(user: { "email" => "jose", "role" => "invalid" })
43
+ assert_equal({ "email" => "jose" }, sanitizer.sanitize(:account_update))
44
+ end
45
+
46
+ test 'allows custom hooks' do
47
+ sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid" })
48
+ sanitizer.for(:sign_in) { |user| user.permit(:email, :password) }
49
+ assert_equal({ "email" => "jose", "password" => "invalid" }, sanitizer.sanitize(:sign_in))
50
+ end
51
+
52
+ test 'adding multiple permitted parameters' do
53
+ sanitizer = sanitizer(user: { "email" => "jose", "username" => "jose1", "role" => "valid" })
54
+ sanitizer.for(:sign_in).concat([:username, :role])
55
+ assert_equal({ "email" => "jose", "username" => "jose1", "role" => "valid" }, sanitizer.sanitize(:sign_in))
56
+ end
57
+
58
+ test 'removing multiple default parameters' do
59
+ sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid", "remember_me" => "1" })
60
+ sanitizer.for(:sign_in).delete(:email)
61
+ sanitizer.for(:sign_in).delete(:password)
62
+ assert_equal({ "remember_me" => "1" }, sanitizer.sanitize(:sign_in))
63
+ end
64
+
65
+ test 'raises on unknown hooks' do
66
+ sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid" })
67
+ assert_raise NotImplementedError do
68
+ sanitizer.sanitize(:unknown)
69
+ end
70
+ end
71
+
72
+ test 'passes parameters to filter as arguments to sanitizer' do
73
+ params = {user: stub}
74
+ sanitizer = Devise::ParameterSanitizer.new(User, :user, params)
75
+
76
+ params[:user].expects(:permit).with(kind_of(Symbol), kind_of(Symbol), kind_of(Symbol))
77
+
78
+ sanitizer.sanitize(:sign_in)
79
+ end
80
+ end
81
+ end