authlogic 3.8.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ module Authlogic
4
+ module ControllerAdapters
5
+ class AbstractAdapterTest < ActiveSupport::TestCase
6
+ def test_controller
7
+ controller = Class.new(MockController) do
8
+ def controller.an_arbitrary_method
9
+ 'bar'
10
+ end
11
+ end.new
12
+ adapter = Authlogic::ControllerAdapters::AbstractAdapter.new(controller)
13
+
14
+ assert_equal controller, adapter.controller
15
+ assert controller.params.equal?(adapter.params)
16
+ assert adapter.respond_to?(:an_arbitrary_method)
17
+ assert_equal 'bar', adapter.an_arbitrary_method
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec :path => "./../.."
3
3
 
4
- gem "activerecord", "~> 4.2.0"
5
- gem "activesupport", "~> 4.2.0"
4
+ gem "activerecord", "~> 4.2.8.rc1"
5
+ gem "activesupport", "~> 4.2.8.rc1"
6
6
  gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
7
7
  gem 'sqlite3', :platforms => :ruby
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec :path => "./../.."
3
3
 
4
- gem "activerecord", "~> 5.0.0"
5
- gem "activesupport", "~> 5.0.0"
4
+ gem "activerecord", "~> 5.0.1"
5
+ gem "activesupport", "~> 5.0.1"
6
6
  gem 'sqlite3', :platforms => :ruby
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gemspec :path => "./../.."
3
+
4
+ gem "activerecord", github: "rails/rails"
5
+ gem "activesupport", github: "rails/rails"
6
+ gem "sqlite3", :platforms => :ruby
@@ -20,7 +20,7 @@ class I18nTest < ActiveSupport::TestCase
20
20
 
21
21
  assert_nothing_raised do
22
22
  Authlogic::I18n.translator = Class.new do
23
- def translate(key, options = {})
23
+ def translate(key, _options = {})
24
24
  "Translated: #{key}"
25
25
  end
26
26
  end.new
@@ -1,6 +1,6 @@
1
1
  class Company < ActiveRecord::Base
2
2
  authenticates_many :employee_sessions
3
3
  authenticates_many :user_sessions, scope_cookies: true
4
- has_many :employees, :dependent => :destroy
5
- has_many :users, :dependent => :destroy
4
+ has_many :employees, dependent: :destroy
5
+ has_many :users, dependent: :destroy
6
6
  end
@@ -1,43 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class RandomTest < ActiveSupport::TestCase
4
- def test_random_tokens_are_indeed_random
5
- # this might fail if you are *really* unlucky :)
6
- with_any_random do
7
- assert_not_equal Authlogic::Random.hex_token, Authlogic::Random.hex_token
8
- assert_not_equal Authlogic::Random.friendly_token, Authlogic::Random.friendly_token
9
- end
4
+ def test_that_hex_tokens_are_unique
5
+ tokens = Array.new(100) { Authlogic::Random.hex_token }
6
+ assert_equal tokens.size, tokens.uniq.size
10
7
  end
11
8
 
12
- private
13
-
14
- def with_any_random(&block)
15
- [true, false].each { |val| with_secure_random_enabled(val, &block) }
16
- end
17
-
18
- def with_secure_random_enabled(enabled = true)
19
- # can't really test SecureRandom if we don't have an implementation
20
- return if enabled && !Authlogic::Random::SecureRandom
21
-
22
- current_sec_rand = Authlogic::Random::SecureRandom
23
- reload_authlogic_with_sec_random!(current_sec_rand, enabled)
24
-
25
- yield
26
- ensure
27
- reload_authlogic_with_sec_random!(current_sec_rand)
28
- end
29
-
30
- def reload_authlogic_with_sec_random!(secure_random, enabled = true)
31
- silence_warnings do
32
- secure_random.parent.const_set(secure_random.name.sub("#{secure_random.parent}::", ''), enabled ? secure_random : nil)
33
- load(File.dirname(__FILE__) + '/../lib/authlogic/random.rb')
34
- end
35
- end
36
-
37
- def silence_warnings
38
- old_verbose, $VERBOSE = $VERBOSE, nil
39
- yield
40
- ensure
41
- $VERBOSE = old_verbose
42
- end
9
+ def test_that_friendly_tokens_are_unique
10
+ tokens = Array.new(100) { Authlogic::Random.friendly_token }
11
+ assert_equal tokens.size, tokens.uniq.size
12
+ end
43
13
  end
@@ -3,7 +3,8 @@ require 'test_helper'
3
3
  module SessionTest
4
4
  module ActiveRecordTrickeryTest
5
5
  class ClassMethodsTest < ActiveSupport::TestCase
6
- i_suck_and_my_tests_are_order_dependent! # If test_human_name is executed after test_i18n_of_human_name the test will fail.
6
+ # If test_human_name is executed after test_i18n_of_human_name the test will fail.
7
+ i_suck_and_my_tests_are_order_dependent!
7
8
 
8
9
  def test_human_attribute_name
9
10
  assert_equal "Some attribute", UserSession.human_attribute_name("some_attribute")
@@ -15,12 +16,12 @@ module SessionTest
15
16
  end
16
17
 
17
18
  def test_i18n_of_human_name
18
- I18n.backend.store_translations 'en', :authlogic => { :models => { :user_session => "MySession" } }
19
+ I18n.backend.store_translations 'en', authlogic: { models: { user_session: "MySession" } }
19
20
  assert_equal "MySession", UserSession.human_name
20
21
  end
21
22
 
22
23
  def test_i18n_of_model_name_human
23
- I18n.backend.store_translations 'en', :authlogic => { :models => { :user_session => "MySession" } }
24
+ I18n.backend.store_translations 'en', authlogic: { models: { user_session: "MySession" } }
24
25
  assert_equal "MySession", UserSession.model_name.human
25
26
  end
26
27
 
@@ -25,7 +25,7 @@ module SessionTest
25
25
  ben = users(:ben)
26
26
  ben.failed_login_count = UserSession.consecutive_failed_logins_limit - 1
27
27
  assert ben.save
28
- session = UserSession.create(:login => ben.login, :password => "benrocks")
28
+ session = UserSession.create(login: ben.login, password: "benrocks")
29
29
  refute session.new_session?
30
30
  end
31
31
 
@@ -33,7 +33,7 @@ module SessionTest
33
33
  ben = users(:ben)
34
34
  ben.failed_login_count = UserSession.consecutive_failed_logins_limit
35
35
  assert ben.save
36
- session = UserSession.create(:login => ben.login, :password => "benrocks")
36
+ session = UserSession.create(login: ben.login, password: "benrocks")
37
37
  assert session.new_session?
38
38
  assert UserSession.create(ben).new_session?
39
39
  ben.reload
@@ -46,13 +46,13 @@ module SessionTest
46
46
  ben = users(:ben)
47
47
 
48
48
  2.times do |i|
49
- session = UserSession.new(:login => ben.login, :password => "badpassword1")
49
+ session = UserSession.new(login: ben.login, password: "badpassword1")
50
50
  refute session.save
51
51
  refute session.errors[:password].empty?
52
52
  assert_equal i + 1, ben.reload.failed_login_count
53
53
  end
54
54
 
55
- session = UserSession.new(:login => ben.login, :password => "badpassword2")
55
+ session = UserSession.new(login: ben.login, password: "badpassword2")
56
56
  refute session.save
57
57
  assert session.errors[:password].empty?
58
58
  assert_equal 3, ben.reload.failed_login_count
@@ -66,7 +66,7 @@ module SessionTest
66
66
  ben = users(:ben)
67
67
 
68
68
  2.times do |i|
69
- session = UserSession.new(:login => ben.login, :password => "badpassword1")
69
+ session = UserSession.new(login: ben.login, password: "badpassword1")
70
70
  refute session.save
71
71
  assert session.invalid_password?
72
72
  assert_equal i + 1, ben.reload.failed_login_count
@@ -75,7 +75,7 @@ module SessionTest
75
75
  ActiveRecord::Base.connection.execute(
76
76
  "update users set updated_at = '#{1.day.ago.to_s(:db)}' where login = '#{ben.login}'"
77
77
  )
78
- session = UserSession.new(:login => ben.login, :password => "benrocks")
78
+ session = UserSession.new(login: ben.login, password: "benrocks")
79
79
  assert session.save
80
80
  assert_equal 0, ben.reload.failed_login_count
81
81
 
@@ -88,7 +88,7 @@ module SessionTest
88
88
  ben = users(:ben)
89
89
 
90
90
  2.times do |i|
91
- session = UserSession.new(:login => ben.login, :password => "badpassword1")
91
+ session = UserSession.new(login: ben.login, password: "badpassword1")
92
92
  refute session.save
93
93
  refute session.errors[:password].empty?
94
94
  assert_equal i + 1, ben.reload.failed_login_count
@@ -97,7 +97,7 @@ module SessionTest
97
97
  ActiveRecord::Base.connection.execute(
98
98
  "update users set updated_at = '#{1.day.ago.to_s(:db)}' where login = '#{ben.login}'"
99
99
  )
100
- session = UserSession.new(:login => ben.login, :password => "badpassword1")
100
+ session = UserSession.new(login: ben.login, password: "badpassword1")
101
101
  refute session.save
102
102
  assert_equal 1, ben.reload.failed_login_count
103
103
 
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  module SessionTest
4
4
  class CallbacksTest < ActiveSupport::TestCase
5
5
  def setup
6
- WackyUserSession.reset_callbacks(:persist)
6
+ WackyUserSession.reset_callbacks(:persist)
7
7
  end
8
8
 
9
9
  def test_no_callbacks
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module SessionTest
4
4
  module CookiesTest
5
- class ConfiTest < ActiveSupport::TestCase
5
+ class ConfigTest < ActiveSupport::TestCase
6
6
  def test_cookie_key
7
7
  UserSession.cookie_key = "my_cookie_key"
8
8
  assert_equal "my_cookie_key", UserSession.cookie_key
@@ -43,7 +43,6 @@ module SessionTest
43
43
  end
44
44
 
45
45
  def test_secure
46
- UserSession.secure = true
47
46
  assert_equal true, UserSession.secure
48
47
  session = UserSession.new
49
48
  assert_equal true, session.secure
@@ -55,7 +54,6 @@ module SessionTest
55
54
  end
56
55
 
57
56
  def test_httponly
58
- UserSession.httponly = true
59
57
  assert_equal true, UserSession.httponly
60
58
  session = UserSession.new
61
59
  assert_equal true, session.httponly
@@ -66,6 +64,21 @@ module SessionTest
66
64
  assert_equal false, session.httponly
67
65
  end
68
66
 
67
+ def test_same_site
68
+ assert_nil UserSession.same_site
69
+ assert_nil UserSession.new.same_site
70
+
71
+ UserSession.same_site 'Strict'
72
+ assert_equal 'Strict', UserSession.same_site
73
+ session = UserSession.new
74
+ assert_equal 'Strict', session.same_site
75
+ session.same_site = 'Lax'
76
+ assert_equal 'Lax', session.same_site
77
+
78
+ assert_raise(ArgumentError) { UserSession.same_site 'foo' }
79
+ assert_raise(ArgumentError) { UserSession.new.same_site 'foo' }
80
+ end
81
+
69
82
  def test_sign_cookie
70
83
  UserSession.sign_cookie = true
71
84
  assert_equal true, UserSession.sign_cookie
@@ -82,7 +95,7 @@ module SessionTest
82
95
  class InstanceMethodsTest < ActiveSupport::TestCase
83
96
  def test_credentials
84
97
  session = UserSession.new
85
- session.credentials = { :remember_me => true }
98
+ session.credentials = { remember_me: true }
86
99
  assert_equal true, session.remember_me
87
100
  end
88
101
 
@@ -188,6 +201,16 @@ module SessionTest
188
201
  end
189
202
  end
190
203
 
204
+ def test_after_save_save_cookie_with_same_site
205
+ session = UserSession.new(users(:ben))
206
+ session.same_site = 'Strict'
207
+ assert session.save
208
+ assert_equal(
209
+ 'Strict',
210
+ controller.cookies.set_cookies['user_credentials'][:same_site]
211
+ )
212
+ end
213
+
191
214
  def test_after_destroy_destroy_cookie
192
215
  ben = users(:ben)
193
216
  set_cookie_for(ben)
@@ -5,22 +5,22 @@ module SessionTest
5
5
  class ClassMethodsTest < ActiveSupport::TestCase
6
6
  def test_create_with_good_credentials
7
7
  ben = users(:ben)
8
- session = UserSession.create(:login => ben.login, :password => "benrocks")
8
+ session = UserSession.create(login: ben.login, password: "benrocks")
9
9
  refute session.new_session?
10
10
  end
11
11
 
12
12
  def test_create_with_bad_credentials
13
- session = UserSession.create(:login => "somelogin", :password => "badpw2")
13
+ session = UserSession.create(login: "somelogin", password: "badpw2")
14
14
  assert session.new_session?
15
15
  end
16
16
 
17
17
  def test_create_bang
18
18
  ben = users(:ben)
19
19
  err = assert_raise(Authlogic::Session::Existence::SessionInvalidError) do
20
- UserSession.create!(:login => ben.login, :password => "badpw")
20
+ UserSession.create!(login: ben.login, password: "badpw")
21
21
  end
22
22
  assert_includes err.message, "Password is not valid"
23
- refute UserSession.create!(:login => ben.login, :password => "benrocks").new_session?
23
+ refute UserSession.create!(login: ben.login, password: "benrocks").new_session?
24
24
  end
25
25
  end
26
26
 
@@ -71,5 +71,16 @@ module SessionTest
71
71
  refute session.record
72
72
  end
73
73
  end
74
+
75
+ class SessionInvalidErrorTest < ActiveSupport::TestCase
76
+ def test_message
77
+ session = UserSession.new
78
+ assert !session.valid?
79
+ error = Authlogic::Session::Existence::SessionInvalidError.new(session)
80
+ message = "Your session is invalid and has the following errors: " +
81
+ session.errors.full_messages.to_sentence
82
+ assert_equal message, error.message
83
+ end
84
+ end
74
85
  end
75
86
  end
@@ -1,6 +1,22 @@
1
1
  require 'test_helper'
2
2
 
3
+ # We forbid the use of AC::Parameters, and we have a test to that effect, but we
4
+ # do not want a development dependency on `actionpack`, so we define it here.
5
+ module ActionController
6
+ class Parameters; end
7
+ end
8
+
3
9
  module SessionTest
4
10
  class FoundationTest < ActiveSupport::TestCase
11
+ def test_credentials_raise_if_not_a_hash
12
+ session = UserSession.new
13
+ e = assert_raises(TypeError) {
14
+ session.credentials = ActionController::Parameters.new
15
+ }
16
+ assert_equal(
17
+ ::Authlogic::Session::Foundation::InstanceMethods::E_AC_PARAMETERS,
18
+ e.message
19
+ )
20
+ end
5
21
  end
6
22
  end
@@ -2,7 +2,7 @@ require 'test_helper'
2
2
 
3
3
  module SessionTest
4
4
  class HttpAuthTest < ActiveSupport::TestCase
5
- class ConfiTest < ActiveSupport::TestCase
5
+ class ConfigTest < ActiveSupport::TestCase
6
6
  def test_allow_http_basic_auth
7
7
  UserSession.allow_http_basic_auth = false
8
8
  assert_equal false, UserSession.allow_http_basic_auth
@@ -28,6 +28,8 @@ module SessionTest
28
28
 
29
29
  class InstanceMethodsTest < ActiveSupport::TestCase
30
30
  def test_persist_persist_by_http_auth
31
+ UserSession.allow_http_basic_auth = true
32
+
31
33
  aaron = users(:aaron)
32
34
  http_basic_auth_for do
33
35
  refute UserSession.find
@@ -27,7 +27,7 @@ module SessionTest
27
27
  def test_valid_increase_failed_login_count
28
28
  ben = users(:ben)
29
29
  old_failed_login_count = ben.failed_login_count
30
- session = UserSession.create(:login => ben.login, :password => "wrong")
30
+ session = UserSession.create(login: ben.login, password: "wrong")
31
31
  assert session.new_session?
32
32
  ben.reload
33
33
  assert_equal old_failed_login_count + 1, ben.failed_login_count
@@ -37,24 +37,22 @@ module SessionTest
37
37
  aaron = users(:aaron)
38
38
 
39
39
  # increase failed login count
40
- session = UserSession.create(:login => aaron.login, :password => "wrong")
40
+ session = UserSession.create(login: aaron.login, password: "wrong")
41
41
  assert session.new_session?
42
42
  aaron.reload
43
+ assert_equal 0, aaron.login_count
44
+ assert_nil aaron.current_login_at
45
+ assert_nil aaron.current_login_ip
43
46
 
44
- # grab old values
45
- old_login_count = aaron.login_count
46
- old_current_login_at = aaron.current_login_at
47
- old_current_login_ip = aaron.current_login_ip
48
-
49
- session = UserSession.create(:login => aaron.login, :password => "aaronrocks")
47
+ session = UserSession.create(login: aaron.login, password: "aaronrocks")
50
48
  assert session.valid?
51
49
 
52
50
  aaron.reload
53
- assert_equal old_login_count + 1, aaron.login_count
51
+ assert_equal 1, aaron.login_count
54
52
  assert_equal 0, aaron.failed_login_count
55
- assert_equal old_current_login_at, aaron.last_login_at
56
- assert aaron.current_login_at != old_current_login_at
57
- assert_equal old_current_login_ip, aaron.last_login_ip
53
+ assert_nil aaron.last_login_at
54
+ assert_not_nil aaron.current_login_at
55
+ assert_nil aaron.last_login_ip
58
56
  assert_equal "1.1.1.1", aaron.current_login_ip
59
57
  end
60
58
  end
@@ -16,7 +16,10 @@ module SessionTest
16
16
  assert_equal ["my request type"], UserSession.single_access_allowed_request_types
17
17
 
18
18
  UserSession.single_access_allowed_request_types ["application/rss+xml", "application/atom+xml"]
19
- assert_equal ["application/rss+xml", "application/atom+xml"], UserSession.single_access_allowed_request_types
19
+ assert_equal(
20
+ ["application/rss+xml", "application/atom+xml"],
21
+ UserSession.single_access_allowed_request_types
22
+ )
20
23
  end
21
24
  end
22
25
 
@@ -22,21 +22,21 @@ module SessionTest
22
22
  def test_generalize_credentials_error_mesages_set_to_false
23
23
  UserSession.generalize_credentials_error_messages false
24
24
  refute UserSession.generalize_credentials_error_messages
25
- session = UserSession.create(:login => users(:ben).login, :password => "invalud-password")
25
+ session = UserSession.create(login: users(:ben).login, password: "invalud-password")
26
26
  assert_equal ["Password is not valid"], session.errors.full_messages
27
27
  end
28
28
 
29
29
  def test_generalize_credentials_error_messages_set_to_true
30
30
  UserSession.generalize_credentials_error_messages true
31
31
  assert UserSession.generalize_credentials_error_messages
32
- session = UserSession.create(:login => users(:ben).login, :password => "invalud-password")
32
+ session = UserSession.create(login: users(:ben).login, password: "invalud-password")
33
33
  assert_equal ["Login/Password combination is not valid"], session.errors.full_messages
34
34
  end
35
35
 
36
36
  def test_generalize_credentials_error_messages_set_to_string
37
37
  UserSession.generalize_credentials_error_messages = "Custom Error Message"
38
38
  assert UserSession.generalize_credentials_error_messages
39
- session = UserSession.create(:login => users(:ben).login, :password => "invalud-password")
39
+ session = UserSession.create(login: users(:ben).login, password: "invalud-password")
40
40
  assert_equal ["Custom Error Message"], session.errors.full_messages
41
41
  end
42
42
 
@@ -79,21 +79,21 @@ module SessionTest
79
79
 
80
80
  def test_credentials
81
81
  session = UserSession.new
82
- session.credentials = { :login => "login", :password => "pass" }
82
+ session.credentials = { login: "login", password: "pass" }
83
83
  assert_equal "login", session.login
84
84
  assert_nil session.password
85
85
  assert_equal "pass", session.send(:protected_password)
86
- assert_equal({ :password => "<protected>", :login => "login" }, session.credentials)
86
+ assert_equal({ password: "<protected>", login: "login" }, session.credentials)
87
87
  end
88
88
 
89
89
  def test_credentials_are_params_safe
90
90
  session = UserSession.new
91
- assert_nothing_raised { session.credentials = { :hacker_method => "error!" } }
91
+ assert_nothing_raised { session.credentials = { hacker_method: "error!" } }
92
92
  end
93
93
 
94
94
  def test_save_with_credentials
95
95
  aaron = users(:aaron)
96
- session = UserSession.new(:login => aaron.login, :password => "aaronrocks")
96
+ session = UserSession.new(login: aaron.login, password: "aaronrocks")
97
97
  assert session.save
98
98
  refute session.new_session?
99
99
  assert_equal 1, session.record.login_count