authlogic 3.8.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/.github/triage.md +87 -0
  3. data/.gitignore +2 -1
  4. data/.rubocop.yml +62 -6
  5. data/.rubocop_todo.yml +51 -267
  6. data/.travis.yml +4 -26
  7. data/CHANGELOG.md +226 -2
  8. data/CONTRIBUTING.md +15 -5
  9. data/Gemfile +2 -2
  10. data/README.md +183 -91
  11. data/Rakefile +1 -1
  12. data/UPGRADING.md +20 -0
  13. data/authlogic.gemspec +25 -16
  14. data/lib/authlogic.rb +45 -45
  15. data/lib/authlogic/acts_as_authentic/base.rb +18 -11
  16. data/lib/authlogic/acts_as_authentic/email.rb +32 -28
  17. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +1 -1
  18. data/lib/authlogic/acts_as_authentic/login.rb +32 -42
  19. data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
  20. data/lib/authlogic/acts_as_authentic/password.rb +53 -31
  21. data/lib/authlogic/acts_as_authentic/perishable_token.rb +18 -17
  22. data/lib/authlogic/acts_as_authentic/persistence_token.rb +7 -12
  23. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +64 -0
  24. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +11 -3
  25. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +30 -10
  26. data/lib/authlogic/acts_as_authentic/single_access_token.rb +4 -4
  27. data/lib/authlogic/authenticates_many/association.rb +3 -3
  28. data/lib/authlogic/authenticates_many/base.rb +2 -2
  29. data/lib/authlogic/config.rb +0 -1
  30. data/lib/authlogic/controller_adapters/abstract_adapter.rb +11 -4
  31. data/lib/authlogic/controller_adapters/rack_adapter.rb +7 -3
  32. data/lib/authlogic/controller_adapters/rails_adapter.rb +2 -0
  33. data/lib/authlogic/crypto_providers/aes256.rb +1 -1
  34. data/lib/authlogic/crypto_providers/bcrypt.rb +1 -1
  35. data/lib/authlogic/crypto_providers/scrypt.rb +6 -6
  36. data/lib/authlogic/crypto_providers/sha1.rb +10 -5
  37. data/lib/authlogic/crypto_providers/sha256.rb +11 -8
  38. data/lib/authlogic/crypto_providers/wordpress.rb +2 -2
  39. data/lib/authlogic/i18n.rb +4 -2
  40. data/lib/authlogic/random.rb +10 -28
  41. data/lib/authlogic/regex.rb +11 -8
  42. data/lib/authlogic/session/activation.rb +6 -3
  43. data/lib/authlogic/session/active_record_trickery.rb +13 -9
  44. data/lib/authlogic/session/base.rb +15 -4
  45. data/lib/authlogic/session/brute_force_protection.rb +14 -7
  46. data/lib/authlogic/session/callbacks.rb +53 -30
  47. data/lib/authlogic/session/cookies.rb +57 -16
  48. data/lib/authlogic/session/existence.rb +21 -11
  49. data/lib/authlogic/session/foundation.rb +56 -10
  50. data/lib/authlogic/session/http_auth.rb +15 -8
  51. data/lib/authlogic/session/klass.rb +7 -5
  52. data/lib/authlogic/session/magic_columns.rb +24 -11
  53. data/lib/authlogic/session/magic_states.rb +11 -4
  54. data/lib/authlogic/session/params.rb +6 -2
  55. data/lib/authlogic/session/password.rb +46 -73
  56. data/lib/authlogic/session/persistence.rb +11 -7
  57. data/lib/authlogic/session/priority_record.rb +7 -4
  58. data/lib/authlogic/session/scopes.rb +15 -6
  59. data/lib/authlogic/session/session.rb +20 -10
  60. data/lib/authlogic/session/timeout.rb +2 -2
  61. data/lib/authlogic/session/unauthorized_record.rb +1 -1
  62. data/lib/authlogic/session/validation.rb +1 -1
  63. data/lib/authlogic/test_case.rb +65 -2
  64. data/lib/authlogic/test_case/mock_controller.rb +5 -4
  65. data/lib/authlogic/test_case/mock_cookie_jar.rb +11 -2
  66. data/lib/authlogic/test_case/mock_request.rb +5 -1
  67. data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
  68. data/lib/authlogic/version.rb +16 -0
  69. data/test/acts_as_authentic_test/email_test.rb +33 -34
  70. data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
  71. data/test/acts_as_authentic_test/login_test.rb +73 -78
  72. data/test/acts_as_authentic_test/password_test.rb +30 -18
  73. data/test/acts_as_authentic_test/perishable_token_test.rb +9 -3
  74. data/test/acts_as_authentic_test/persistence_token_test.rb +4 -0
  75. data/test/acts_as_authentic_test/session_maintenance_test.rb +66 -14
  76. data/test/adapter_test.rb +21 -0
  77. data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
  78. data/test/gemfiles/Gemfile.rails-5.0.x +2 -2
  79. data/test/gemfiles/Gemfile.rails-master +6 -0
  80. data/test/i18n_test.rb +1 -1
  81. data/test/libs/company.rb +2 -2
  82. data/test/random_test.rb +7 -37
  83. data/test/session_test/active_record_trickery_test.rb +4 -3
  84. data/test/session_test/brute_force_protection_test.rb +8 -8
  85. data/test/session_test/callbacks_test.rb +1 -1
  86. data/test/session_test/cookies_test.rb +27 -4
  87. data/test/session_test/existence_test.rb +15 -4
  88. data/test/session_test/foundation_test.rb +16 -0
  89. data/test/session_test/http_auth_test.rb +3 -1
  90. data/test/session_test/magic_columns_test.rb +10 -12
  91. data/test/session_test/params_test.rb +4 -1
  92. data/test/session_test/password_test.rb +7 -7
  93. data/test/session_test/persistence_test.rb +1 -0
  94. data/test/session_test/scopes_test.rb +7 -7
  95. data/test/session_test/session_test.rb +2 -2
  96. data/test/session_test/timeout_test.rb +1 -1
  97. data/test/session_test/unauthorized_record_test.rb +1 -1
  98. data/test/test_helper.rb +111 -103
  99. metadata +68 -64
  100. data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
  101. data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
  102. data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module ActsAsAuthenticTest
4
4
  class LoggedInStatusTest < ActiveSupport::TestCase
5
- ERROR_MSG = 'Multiple calls to %s should result in different relations'
5
+ ERROR_MSG = 'Multiple calls to %s should result in different relations'.freeze
6
6
 
7
7
  def test_logged_in_timeout_config
8
8
  assert_equal 10.minutes.to_i, User.logged_in_timeout
@@ -1,44 +1,43 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module ActsAsAuthenticTest
4
- class LoginTest < ActiveSupport::TestCase
5
- def test_login_field_config
6
- assert_equal :login, User.login_field
7
- assert_nil Employee.login_field
8
-
9
- User.login_field = :nope
10
- assert_equal :nope, User.login_field
11
- User.login_field :login
12
- assert_equal :login, User.login_field
13
- end
14
-
15
- def test_validate_login_field_config
16
- assert User.validate_login_field
17
- assert Employee.validate_login_field
18
-
19
- User.validate_login_field = false
20
- refute User.validate_login_field
21
- User.validate_login_field true
22
- assert User.validate_login_field
4
+ # Tests for configuration option: `validates_format_of_login_field_options`
5
+ class ValidatesFormatOfLoginTest < ActiveSupport::TestCase
6
+ def test_invalid_format
7
+ [
8
+ "fdsf@^&*",
9
+ " space",
10
+ ".dot",
11
+ "-hyphen",
12
+ "@atmark",
13
+ "+plus"
14
+ ].each do |login|
15
+ u = User.new(login: login)
16
+ refute u.valid?
17
+ refute u.errors[:login].empty?
18
+ end
23
19
  end
24
20
 
25
- def test_validates_length_of_login_field_options_config
26
- assert_equal({ :within => 3..100 }, User.validates_length_of_login_field_options)
27
- assert_equal({ :within => 3..100 }, Employee.validates_length_of_login_field_options)
28
-
29
- User.validates_length_of_login_field_options = { :yes => "no" }
30
- assert_equal({ :yes => "no" }, User.validates_length_of_login_field_options)
31
- User.validates_length_of_login_field_options({ :within => 3..100 })
32
- assert_equal({ :within => 3..100 }, User.validates_length_of_login_field_options)
21
+ def test_valid_format
22
+ [
23
+ "fdsfdsfdsfdsfs",
24
+ "dakota.dux+1@gmail.com",
25
+ "marks .-_@+",
26
+ "_underscore"
27
+ ].each do |login|
28
+ u = User.new(login: login)
29
+ refute u.valid?
30
+ assert u.errors[:login].empty?
31
+ end
33
32
  end
34
33
 
35
34
  def test_validates_format_of_login_field_options_config
36
35
  default = {
37
- :with => /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
38
- :message => proc do
36
+ with: /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
37
+ message: proc do
39
38
  I18n.t(
40
39
  'error_messages.login_invalid',
41
- :default => "should use only letters, numbers, spaces, and .-_@+ please."
40
+ default: "should use only letters, numbers, spaces, and .-_@+ please."
42
41
  )
43
42
  end
44
43
  }
@@ -56,18 +55,57 @@ module ActsAsAuthenticTest
56
55
  assert_equal default_message, message.call
57
56
  assert_equal default, options
58
57
 
59
- User.validates_format_of_login_field_options = { :yes => "no" }
60
- assert_equal({ :yes => "no" }, User.validates_format_of_login_field_options)
58
+ User.validates_format_of_login_field_options = { yes: "no" }
59
+ assert_equal({ yes: "no" }, User.validates_format_of_login_field_options)
61
60
  User.validates_format_of_login_field_options default
62
61
  assert_equal default, User.validates_format_of_login_field_options
63
62
  end
63
+ end
64
+
65
+ # Miscellaneous tests for configuration options related to the `login_field`.
66
+ # Feel free to organize these into separate `TestCase`s as we have done above
67
+ # with `ValidatesFormatOfLoginTest`.
68
+ class MiscellaneousLoginTest < ActiveSupport::TestCase
69
+ def test_login_field_config
70
+ assert_equal :login, User.login_field
71
+ assert_nil Employee.login_field
72
+
73
+ User.login_field = :nope
74
+ assert_equal :nope, User.login_field
75
+ User.login_field :login
76
+ assert_equal :login, User.login_field
77
+ end
78
+
79
+ def test_validate_login_field_config
80
+ assert User.validate_login_field
81
+ assert Employee.validate_login_field
82
+
83
+ User.validate_login_field = false
84
+ refute User.validate_login_field
85
+ User.validate_login_field true
86
+ assert User.validate_login_field
87
+ end
88
+
89
+ def test_validates_length_of_login_field_options_config
90
+ assert_equal({ within: 3..100 }, User.validates_length_of_login_field_options)
91
+ assert_equal({ within: 3..100 }, Employee.validates_length_of_login_field_options)
92
+
93
+ User.validates_length_of_login_field_options = { yes: "no" }
94
+ assert_equal({ yes: "no" }, User.validates_length_of_login_field_options)
95
+ User.validates_length_of_login_field_options(within: 3..100)
96
+ assert_equal({ within: 3..100 }, User.validates_length_of_login_field_options)
97
+ end
64
98
 
65
99
  def test_validates_uniqueness_of_login_field_options_config
66
- default = { :case_sensitive => false, :scope => User.validations_scope, :if => "#{User.login_field}_changed?".to_sym }
100
+ default = {
101
+ case_sensitive: false,
102
+ scope: User.validations_scope,
103
+ if: "#{User.login_field}_changed?".to_sym
104
+ }
67
105
  assert_equal default, User.validates_uniqueness_of_login_field_options
68
106
 
69
- User.validates_uniqueness_of_login_field_options = { :yes => "no" }
70
- assert_equal({ :yes => "no" }, User.validates_uniqueness_of_login_field_options)
107
+ User.validates_uniqueness_of_login_field_options = { yes: "no" }
108
+ assert_equal({ yes: "no" }, User.validates_uniqueness_of_login_field_options)
71
109
  User.validates_uniqueness_of_login_field_options default
72
110
  assert_equal default, User.validates_uniqueness_of_login_field_options
73
111
  end
@@ -83,49 +121,6 @@ module ActsAsAuthenticTest
83
121
  assert u.errors[:login].empty?
84
122
  end
85
123
 
86
- def test_validates_format_of_login_field
87
- u = User.new
88
- u.login = "fdsf@^&*"
89
- refute u.valid?
90
- refute u.errors[:login].empty?
91
-
92
- u.login = "fdsfdsfdsfdsfs"
93
- refute u.valid?
94
- assert u.errors[:login].empty?
95
-
96
- u.login = "dakota.dux+1@gmail.com"
97
- refute u.valid?
98
- assert u.errors[:login].empty?
99
-
100
- u.login = "marks .-_@+"
101
- refute u.valid?
102
- assert u.errors[:login].empty?
103
-
104
- u.login = " space"
105
- refute u.valid?
106
- refute u.errors[:login].empty?
107
-
108
- u.login = ".dot"
109
- refute u.valid?
110
- refute u.errors[:login].empty?
111
-
112
- u.login = "-hyphen"
113
- refute u.valid?
114
- refute u.errors[:login].empty?
115
-
116
- u.login = "_underscore"
117
- refute u.valid?
118
- assert u.errors[:login].empty?
119
-
120
- u.login = "@atmark"
121
- refute u.valid?
122
- refute u.errors[:login].empty?
123
-
124
- u.login = "+plus"
125
- refute u.valid?
126
- refute u.errors[:login].empty?
127
- end
128
-
129
124
  def test_validates_uniqueness_of_login_field
130
125
  u = User.new
131
126
  u.login = "bjohnson"
@@ -2,7 +2,9 @@ require 'test_helper'
2
2
 
3
3
  module ActsAsAuthenticTest
4
4
  class PasswordTest < ActiveSupport::TestCase
5
- i_suck_and_my_tests_are_order_dependent! # If test_human_name is executed after test_i18n_of_human_name the test will fail.
5
+ # If test_human_name is executed after test_i18n_of_human_name the test will fail.
6
+ i_suck_and_my_tests_are_order_dependent!
7
+
6
8
  def test_crypted_password_field_config
7
9
  assert_equal :crypted_password, User.crypted_password_field
8
10
  assert_equal :crypted_password, Employee.crypted_password_field
@@ -52,34 +54,34 @@ module ActsAsAuthenticTest
52
54
  end
53
55
 
54
56
  def test_validates_length_of_password_field_options_config
55
- default = { :minimum => 8, :if => :require_password? }
57
+ default = { minimum: 8, if: :require_password? }
56
58
  assert_equal default, User.validates_length_of_password_field_options
57
59
  assert_equal default, Employee.validates_length_of_password_field_options
58
60
 
59
- User.validates_length_of_password_field_options = { :yes => "no" }
60
- assert_equal({ :yes => "no" }, User.validates_length_of_password_field_options)
61
+ User.validates_length_of_password_field_options = { yes: "no" }
62
+ assert_equal({ yes: "no" }, User.validates_length_of_password_field_options)
61
63
  User.validates_length_of_password_field_options default
62
64
  assert_equal default, User.validates_length_of_password_field_options
63
65
  end
64
66
 
65
67
  def test_validates_confirmation_of_password_field_options_config
66
- default = { :if => :require_password? }
68
+ default = { if: :require_password? }
67
69
  assert_equal default, User.validates_confirmation_of_password_field_options
68
70
  assert_equal default, Employee.validates_confirmation_of_password_field_options
69
71
 
70
- User.validates_confirmation_of_password_field_options = { :yes => "no" }
71
- assert_equal({ :yes => "no" }, User.validates_confirmation_of_password_field_options)
72
+ User.validates_confirmation_of_password_field_options = { yes: "no" }
73
+ assert_equal({ yes: "no" }, User.validates_confirmation_of_password_field_options)
72
74
  User.validates_confirmation_of_password_field_options default
73
75
  assert_equal default, User.validates_confirmation_of_password_field_options
74
76
  end
75
77
 
76
78
  def test_validates_length_of_password_confirmation_field_options_config
77
- default = { :minimum => 8, :if => :require_password? }
79
+ default = { minimum: 8, if: :require_password? }
78
80
  assert_equal default, User.validates_length_of_password_confirmation_field_options
79
81
  assert_equal default, Employee.validates_length_of_password_confirmation_field_options
80
82
 
81
- User.validates_length_of_password_confirmation_field_options = { :yes => "no" }
82
- assert_equal({ :yes => "no" }, User.validates_length_of_password_confirmation_field_options)
83
+ User.validates_length_of_password_confirmation_field_options = { yes: "no" }
84
+ assert_equal({ yes: "no" }, User.validates_length_of_password_confirmation_field_options)
83
85
  User.validates_length_of_password_confirmation_field_options default
84
86
  assert_equal default, User.validates_length_of_password_confirmation_field_options
85
87
  end
@@ -105,7 +107,12 @@ module ActsAsAuthenticTest
105
107
  end
106
108
 
107
109
  def test_validates_length_of_password
108
- u = User.new(login: "abcde", email: "abcde@test.com", password: "abcdefgh", password_confirmation: "abcdefgh")
110
+ u = User.new(
111
+ login: "abcde",
112
+ email: "abcde@test.com",
113
+ password: "abcdefgh",
114
+ password_confirmation: "abcdefgh"
115
+ )
109
116
  assert u.valid?
110
117
 
111
118
  u.password = u.password_confirmation = "abcdef"
@@ -116,17 +123,18 @@ module ActsAsAuthenticTest
116
123
  end
117
124
 
118
125
  def test_validates_confirmation_of_password
119
- u = User.new(login: "abcde", email: "abcde@test.com", password: "abcdefgh", password_confirmation: "abcdefgh")
126
+ u = User.new(
127
+ login: "abcde",
128
+ email: "abcde@test.com",
129
+ password: "abcdefgh",
130
+ password_confirmation: "abcdefgh"
131
+ )
120
132
  assert u.valid?
121
133
 
122
134
  u.password_confirmation = "abcdefghij"
123
135
  refute u.valid?
124
136
 
125
- if ActiveModel.respond_to?(:version) and ActiveModel.version.segments.first >= 4
126
- assert u.errors[:password_confirmation].include?("doesn't match Password")
127
- else
128
- assert u.errors[:password].include?("doesn't match confirmation")
129
- end
137
+ assert u.errors[:password_confirmation].include?("doesn't match Password")
130
138
  end
131
139
 
132
140
  def test_validates_length_of_password_confirmation
@@ -225,7 +233,11 @@ module ActsAsAuthenticTest
225
233
 
226
234
  private
227
235
 
228
- def transition_password_to(crypto_provider, records, from_crypto_providers = Authlogic::CryptoProviders::Sha512)
236
+ def transition_password_to(
237
+ crypto_provider,
238
+ records,
239
+ from_crypto_providers = Authlogic::CryptoProviders::Sha512
240
+ )
229
241
  records = [records] unless records.is_a?(Array)
230
242
  User.acts_as_authentic do |c|
231
243
  c.crypto_provider = crypto_provider
@@ -60,14 +60,18 @@ module ActsAsAuthenticTest
60
60
 
61
61
  def test_find_using_perishable_token_when_perished
62
62
  ben = users(:ben)
63
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{1.week.ago.to_s(:db)}' where id = #{ben.id}")
63
+ ActiveRecord::Base.connection.execute(
64
+ "UPDATE users set updated_at = '#{1.week.ago.to_s(:db)}' where id = #{ben.id}"
65
+ )
64
66
  assert_nil User.find_using_perishable_token(ben.perishable_token)
65
67
  end
66
68
 
67
69
  def test_find_using_perishable_token_when_perished_2
68
70
  User.perishable_token_valid_for = 1.minute
69
71
  ben = users(:ben)
70
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{2.minutes.ago.to_s(:db)}' where id = #{ben.id}")
72
+ ActiveRecord::Base.connection.execute(
73
+ "UPDATE users set updated_at = '#{2.minutes.ago.to_s(:db)}' where id = #{ben.id}"
74
+ )
71
75
  assert_nil User.find_using_perishable_token(ben.perishable_token)
72
76
  User.perishable_token_valid_for = 10.minutes
73
77
  end
@@ -75,7 +79,9 @@ module ActsAsAuthenticTest
75
79
  def test_find_using_perishable_token_when_passing_threshold
76
80
  User.perishable_token_valid_for = 1.minute
77
81
  ben = users(:ben)
78
- ActiveRecord::Base.connection.execute("UPDATE users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = #{ben.id}")
82
+ ActiveRecord::Base.connection.execute(
83
+ "UPDATE users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = #{ben.id}"
84
+ )
79
85
  assert_nil User.find_using_perishable_token(ben.perishable_token, 5.minutes)
80
86
  assert_equal ben, User.find_using_perishable_token(ben.perishable_token, 20.minutes)
81
87
  User.perishable_token_valid_for = 10.minutes
@@ -29,6 +29,8 @@ module ActsAsAuthenticTest
29
29
  end
30
30
 
31
31
  def test_forget_all
32
+ UserSession.allow_http_basic_auth = true
33
+
32
34
  http_basic_auth_for(users(:ben)) { UserSession.find }
33
35
  http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) }
34
36
  assert UserSession.find
@@ -39,6 +41,8 @@ module ActsAsAuthenticTest
39
41
  end
40
42
 
41
43
  def test_forget
44
+ UserSession.allow_http_basic_auth = true
45
+
42
46
  ben = users(:ben)
43
47
  zack = users(:zack)
44
48
  http_basic_auth_for(ben) { UserSession.find }
@@ -2,23 +2,59 @@ require 'test_helper'
2
2
 
3
3
  module ActsAsAuthenticTest
4
4
  class SessionMaintenanceTest < ActiveSupport::TestCase
5
- def test_maintain_sessions_config
6
- assert User.maintain_sessions
7
- User.maintain_sessions = false
8
- refute User.maintain_sessions
9
- User.maintain_sessions true
10
- assert User.maintain_sessions
5
+ def setup
6
+ User.log_in_after_create = true
7
+ User.log_in_after_password_change = true
8
+ end
9
+
10
+ def test_log_in_after_create_config
11
+ assert User.log_in_after_create
12
+ User.log_in_after_create = false
13
+ refute User.log_in_after_create
14
+ User.log_in_after_create = true
15
+ assert User.log_in_after_create
16
+ end
17
+
18
+ def test_log_in_after_password_change_config
19
+ assert User.log_in_after_password_change
20
+ User.log_in_after_password_change = false
21
+ refute User.log_in_after_password_change
22
+ User.log_in_after_password_change = true
23
+ assert User.log_in_after_password_change
11
24
  end
12
25
 
13
26
  def test_login_after_create
27
+ User.log_in_after_create = true
14
28
  user = User.create(
15
- :login => "awesome",
16
- :password => "saweeeet",
17
- :password_confirmation => "saweeeet",
18
- :email => "awesome@awesome.com"
29
+ login: "awesome",
30
+ password: "saweeeet",
31
+ password_confirmation: "saweeeet",
32
+ email: "awesome@awesome.com"
19
33
  )
20
34
  assert user.persisted?
21
35
  assert UserSession.find
36
+ logged_in_user = UserSession.find.user
37
+ assert_equal logged_in_user, user
38
+ end
39
+
40
+ def test_no_login_after_create
41
+ old_user = User.create(
42
+ login: "awesome",
43
+ password: "saweeeet",
44
+ password_confirmation: "saweeeet",
45
+ email: "awesome@awesome.com"
46
+ )
47
+ User.log_in_after_create = false
48
+ user2 = User.create(
49
+ login: "awesome2",
50
+ password: "saweeeet2",
51
+ password_confirmation: "saweeeet2",
52
+ email: "awesome2@awesome.com"
53
+ )
54
+ assert user2.persisted?
55
+ logged_in_user = UserSession.find.user
56
+ assert_not_equal logged_in_user, user2
57
+ assert_equal logged_in_user, old_user
22
58
  end
23
59
 
24
60
  def test_updating_session_with_failed_magic_state
@@ -30,6 +66,7 @@ module ActsAsAuthenticTest
30
66
  end
31
67
 
32
68
  def test_update_session_after_password_modify
69
+ User.log_in_after_password_change = true
33
70
  ben = users(:ben)
34
71
  UserSession.create(ben)
35
72
  old_session_key = controller.session["user_credentials"]
@@ -43,6 +80,21 @@ module ActsAsAuthenticTest
43
80
  assert_not_equal controller.cookies["user_credentials"], old_cookie_key
44
81
  end
45
82
 
83
+ def test_no_update_session_after_password_modify
84
+ User.log_in_after_password_change = false
85
+ ben = users(:ben)
86
+ UserSession.create(ben)
87
+ old_session_key = controller.session["user_credentials"]
88
+ old_cookie_key = controller.cookies["user_credentials"]
89
+ ben.password = "newpasswd"
90
+ ben.password_confirmation = "newpasswd"
91
+ assert ben.save
92
+ assert controller.session["user_credentials"]
93
+ assert controller.cookies["user_credentials"]
94
+ assert_equal controller.session["user_credentials"], old_session_key
95
+ assert_equal controller.cookies["user_credentials"], old_cookie_key
96
+ end
97
+
46
98
  def test_no_session_update_after_modify
47
99
  ben = users(:ben)
48
100
  UserSession.create(ben)
@@ -60,10 +112,10 @@ module ActsAsAuthenticTest
60
112
  old_session_key = controller.session["user_credentials"]
61
113
  old_cookie_key = controller.cookies["user_credentials"]
62
114
  user = User.create(
63
- :login => "awesome",
64
- :password => "saweet", # Password is too short, user invalid
65
- :password_confirmation => "saweet",
66
- :email => "awesome@saweet.com"
115
+ login: "awesome",
116
+ password: "saweet", # Password is too short, user invalid
117
+ password_confirmation: "saweet",
118
+ email: "awesome@saweet.com"
67
119
  )
68
120
  refute user.persisted?
69
121
  assert_equal controller.session["user_credentials"], old_session_key