authlogic 1.4.3 → 2.0.0

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

Potentially problematic release.


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

Files changed (131) hide show
  1. data/CHANGELOG.rdoc +19 -0
  2. data/Manifest.txt +111 -0
  3. data/README.rdoc +116 -389
  4. data/Rakefile +14 -7
  5. data/lib/authlogic.rb +33 -35
  6. data/lib/authlogic/acts_as_authentic/base.rb +91 -0
  7. data/lib/authlogic/acts_as_authentic/email.rb +77 -0
  8. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +54 -0
  9. data/lib/authlogic/acts_as_authentic/login.rb +65 -0
  10. data/lib/authlogic/acts_as_authentic/magic_columns.rb +24 -0
  11. data/lib/authlogic/acts_as_authentic/password.rb +215 -0
  12. data/lib/authlogic/acts_as_authentic/perishable_token.rb +100 -0
  13. data/lib/authlogic/acts_as_authentic/persistence_token.rb +66 -0
  14. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +60 -0
  15. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +127 -0
  16. data/lib/authlogic/acts_as_authentic/single_access_token.rb +58 -0
  17. data/lib/authlogic/acts_as_authentic/validations_scope.rb +32 -0
  18. data/lib/authlogic/{session/authenticates_many_association.rb → authenticates_many/association.rb} +10 -6
  19. data/lib/authlogic/authenticates_many/base.rb +55 -0
  20. data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -3
  21. data/lib/authlogic/controller_adapters/merb_adapter.rb +0 -4
  22. data/lib/authlogic/controller_adapters/rails_adapter.rb +0 -4
  23. data/lib/authlogic/crypto_providers/aes256.rb +0 -2
  24. data/lib/authlogic/crypto_providers/bcrypt.rb +0 -2
  25. data/lib/authlogic/crypto_providers/md5.rb +34 -0
  26. data/lib/authlogic/crypto_providers/sha1.rb +0 -2
  27. data/lib/authlogic/crypto_providers/sha512.rb +1 -3
  28. data/lib/authlogic/i18n.rb +1 -4
  29. data/lib/authlogic/random.rb +33 -0
  30. data/lib/authlogic/session/activation.rb +56 -0
  31. data/lib/authlogic/session/active_record_trickery.rb +15 -7
  32. data/lib/authlogic/session/base.rb +31 -456
  33. data/lib/authlogic/session/brute_force_protection.rb +50 -27
  34. data/lib/authlogic/session/callbacks.rb +24 -15
  35. data/lib/authlogic/session/cookies.rb +108 -22
  36. data/lib/authlogic/session/existence.rb +89 -0
  37. data/lib/authlogic/session/foundation.rb +63 -0
  38. data/lib/authlogic/session/http_auth.rb +23 -0
  39. data/lib/authlogic/session/id.rb +41 -0
  40. data/lib/authlogic/session/klass.rb +75 -0
  41. data/lib/authlogic/session/magic_columns.rb +75 -0
  42. data/lib/authlogic/session/magic_states.rb +58 -0
  43. data/lib/authlogic/session/params.rb +82 -19
  44. data/lib/authlogic/session/password.rb +156 -0
  45. data/lib/authlogic/session/{perishability.rb → perishable_token.rb} +4 -4
  46. data/lib/authlogic/session/persistence.rb +70 -0
  47. data/lib/authlogic/session/priority_record.rb +34 -0
  48. data/lib/authlogic/session/scopes.rb +57 -53
  49. data/lib/authlogic/session/session.rb +46 -31
  50. data/lib/authlogic/session/timeout.rb +65 -31
  51. data/lib/authlogic/session/unauthorized_record.rb +50 -0
  52. data/lib/authlogic/session/validation.rb +76 -0
  53. data/lib/authlogic/testing/test_unit_helpers.rb +3 -3
  54. data/lib/authlogic/version.rb +3 -3
  55. data/test/acts_as_authentic_test/base_test.rb +12 -0
  56. data/test/acts_as_authentic_test/email_test.rb +79 -0
  57. data/test/acts_as_authentic_test/logged_in_status_test.rb +36 -0
  58. data/test/acts_as_authentic_test/login_test.rb +79 -0
  59. data/test/acts_as_authentic_test/magic_columns_test.rb +27 -0
  60. data/test/acts_as_authentic_test/password_test.rb +212 -0
  61. data/test/acts_as_authentic_test/perishable_token_test.rb +56 -0
  62. data/test/acts_as_authentic_test/persistence_token_test.rb +55 -0
  63. data/test/acts_as_authentic_test/session_maintenance_test.rb +68 -0
  64. data/test/acts_as_authentic_test/single_access_test.rb +39 -0
  65. data/test/authenticates_many_test.rb +16 -0
  66. data/test/{crypto_provider_tests → crypto_provider_test}/aes256_test.rb +1 -1
  67. data/test/{crypto_provider_tests → crypto_provider_test}/bcrypt_test.rb +1 -1
  68. data/test/{crypto_provider_tests → crypto_provider_test}/sha1_test.rb +1 -1
  69. data/test/{crypto_provider_tests → crypto_provider_test}/sha512_test.rb +1 -1
  70. data/test/fixtures/employees.yml +4 -4
  71. data/test/fixtures/users.yml +6 -6
  72. data/test/libs/company.rb +6 -0
  73. data/test/libs/employee.rb +7 -0
  74. data/test/libs/employee_session.rb +2 -0
  75. data/test/libs/project.rb +3 -0
  76. data/test/libs/user_session.rb +2 -0
  77. data/test/random_test.rb +49 -0
  78. data/test/session_test/activation_test.rb +43 -0
  79. data/test/session_test/active_record_trickery_test.rb +26 -0
  80. data/test/session_test/brute_force_protection_test.rb +76 -0
  81. data/test/session_test/callbacks_test.rb +6 -0
  82. data/test/session_test/cookies_test.rb +107 -0
  83. data/test/session_test/credentials_test.rb +0 -0
  84. data/test/session_test/existence_test.rb +64 -0
  85. data/test/session_test/http_auth_test.rb +16 -0
  86. data/test/session_test/id_test.rb +17 -0
  87. data/test/session_test/klass_test.rb +35 -0
  88. data/test/session_test/magic_columns_test.rb +59 -0
  89. data/test/session_test/magic_states_test.rb +60 -0
  90. data/test/session_test/params_test.rb +53 -0
  91. data/test/session_test/password_test.rb +84 -0
  92. data/test/{session_tests → session_test}/perishability_test.rb +1 -1
  93. data/test/session_test/persistence_test.rb +21 -0
  94. data/test/{session_tests → session_test}/scopes_test.rb +2 -3
  95. data/test/session_test/session_test.rb +59 -0
  96. data/test/session_test/timeout_test.rb +43 -0
  97. data/test/session_test/unauthorized_record_test.rb +13 -0
  98. data/test/session_test/validation_test.rb +23 -0
  99. data/test/test_helper.rb +14 -29
  100. metadata +120 -112
  101. data/Manifest +0 -76
  102. data/authlogic.gemspec +0 -38
  103. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb +0 -22
  104. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb +0 -238
  105. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb +0 -155
  106. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb +0 -51
  107. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb +0 -71
  108. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb +0 -94
  109. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb +0 -87
  110. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb +0 -61
  111. data/lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb +0 -58
  112. data/lib/authlogic/session/config.rb +0 -421
  113. data/lib/authlogic/session/errors.rb +0 -18
  114. data/lib/authlogic/session/record_info.rb +0 -24
  115. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb +0 -154
  116. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb +0 -157
  117. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb +0 -24
  118. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb +0 -41
  119. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb +0 -54
  120. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb +0 -62
  121. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb +0 -41
  122. data/test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb +0 -32
  123. data/test/session_tests/active_record_trickery_test.rb +0 -14
  124. data/test/session_tests/authenticates_many_association_test.rb +0 -28
  125. data/test/session_tests/base_test.rb +0 -307
  126. data/test/session_tests/brute_force_protection_test.rb +0 -53
  127. data/test/session_tests/config_test.rb +0 -184
  128. data/test/session_tests/cookies_test.rb +0 -32
  129. data/test/session_tests/params_test.rb +0 -32
  130. data/test/session_tests/session_test.rb +0 -45
  131. data/test/session_tests/timeout_test.rb +0 -71
@@ -1,62 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper.rb'
2
-
3
- module ORMAdaptersTests
4
- module ActiveRecordAdapterTests
5
- module ActsAsAuthenticTests
6
- class SessionMaintenanceTest < ActiveSupport::TestCase
7
- def test_login_after_create
8
- assert User.create(:login => "awesome", :password => "saweet", :password_confirmation => "saweet", :email => "awesome@awesome.com")
9
- assert UserSession.find
10
- end
11
-
12
- def test_update_session_after_password_modify
13
- ben = users(:ben)
14
- UserSession.create(ben)
15
- old_session_key = @controller.session["user_credentials"]
16
- old_cookie_key = @controller.cookies["user_credentials"]
17
- ben.password = "newpass"
18
- ben.password_confirmation = "newpass"
19
- ben.save
20
- assert @controller.session["user_credentials"]
21
- assert @controller.cookies["user_credentials"]
22
- assert_not_equal @controller.session["user_credentials"], old_session_key
23
- assert_not_equal @controller.cookies["user_credentials"], old_cookie_key
24
- end
25
-
26
- def test_no_session_update_after_modify
27
- ben = users(:ben)
28
- UserSession.create(ben)
29
- old_session_key = @controller.session["user_credentials"]
30
- old_cookie_key = @controller.cookies["user_credentials"]
31
- ben.first_name = "Ben"
32
- ben.save
33
- assert_equal @controller.session["user_credentials"], old_session_key
34
- assert_equal @controller.cookies["user_credentials"], old_cookie_key
35
- end
36
-
37
- def test_updating_other_user
38
- ben = users(:ben)
39
- UserSession.create(ben)
40
- old_session_key = @controller.session["user_credentials"]
41
- old_cookie_key = @controller.cookies["user_credentials"]
42
- zack = users(:zack)
43
- zack.password = "newpass"
44
- zack.password_confirmation = "newpass"
45
- zack.save
46
- assert_equal @controller.session["user_credentials"], old_session_key
47
- assert_equal @controller.cookies["user_credentials"], old_cookie_key
48
- end
49
-
50
- def test_resetting_password_when_logged_out
51
- ben = users(:ben)
52
- assert !UserSession.find
53
- ben.password = "newpass"
54
- ben.password_confirmation = "newpass"
55
- ben.save
56
- assert UserSession.find
57
- assert_equal ben, UserSession.find.record
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,41 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../../test_helper.rb'
2
-
3
- module ORMAdaptersTests
4
- module ActiveRecordAdapterTests
5
- module ActsAsAuthenticTests
6
- class SingleAccessTest < ActiveSupport::TestCase
7
- def test_before_validation
8
- user = User.new
9
- assert_equal nil, user.single_access_token
10
- assert !user.valid?
11
- assert user.single_access_token
12
- end
13
-
14
- def test_change_with_password
15
- ben = users(:ben)
16
- old_single_access_token = ben.single_access_token
17
-
18
- User.acts_as_authentic(:change_single_access_token_with_password => true)
19
- ben.password = "new_pass"
20
- assert_not_equal old_single_access_token, ben.single_access_token
21
-
22
- ben.reload
23
- User.acts_as_authentic(:change_single_access_token_with_password => false)
24
- ben.password = "new_pass"
25
- assert_equal old_single_access_token, ben.single_access_token
26
- end
27
-
28
- def test_reset_single_access_token
29
- ben = users(:ben)
30
- old_single_access_token = ben.single_access_token
31
- ben.reset_single_access_token
32
- assert_not_equal old_single_access_token, ben.single_access_token
33
- ben.reload
34
- assert_equal old_single_access_token, ben.single_access_token
35
- ben.reset_single_access_token!
36
- assert_not_equal old_single_access_token, ben.single_access_token
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper.rb'
2
-
3
- module ORMAdaptersTests
4
- module ActiveRecordAdapterTests
5
- class AuthenticatesManyTest < ActiveSupport::TestCase
6
- def test_authenticates_many_new
7
- binary_logic = companies(:binary_logic)
8
- user_session = binary_logic.user_sessions.new
9
- assert_equal({:find_options => {:conditions => "\"users\".company_id = #{binary_logic.id}"}, :id => nil}, user_session.scope)
10
-
11
- employee_session = binary_logic.employee_sessions.new
12
- assert_equal({:find_options => {:conditions => "\"employees\".company_id = #{binary_logic.id}"}, :id => nil}, employee_session.scope)
13
- end
14
-
15
- def test_authenticates_many_create_and_find
16
- binary_logic = companies(:binary_logic)
17
- logic_over_data = companies(:logic_over_data)
18
- ben = users(:ben)
19
- zack = users(:zack)
20
-
21
- assert !binary_logic.user_sessions.find
22
- assert !logic_over_data.user_sessions.find
23
- assert logic_over_data.user_sessions.create(zack)
24
- assert !binary_logic.user_sessions.find
25
- assert logic_over_data.user_sessions.find
26
- assert binary_logic.user_sessions.create(ben)
27
- assert binary_logic.user_sessions.find
28
- assert !logic_over_data.user_sessions.find
29
- end
30
- end
31
- end
32
- end
@@ -1,14 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class ActiveRecordTrickeryTest < ActiveSupport::TestCase
5
- def test_human_attribute_name
6
- assert_equal "Some attribute", UserSession.human_attribute_name("some_attribute")
7
- end
8
-
9
- def test_new_record
10
- session = UserSession.new
11
- assert session.new_record?
12
- end
13
- end
14
- end
@@ -1,28 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class AuthenticatesManyAssociationTest < ActiveSupport::TestCase
5
- def test_initialize
6
- assoc = Authlogic::Session::AuthenticatesManyAssociation.new(UserSession, {:conditions => ["1 = ?", 1]}, :some_id)
7
- assert_equal UserSession, assoc.klass
8
- assert_equal({:conditions => ["1 = ?", 1]}, assoc.find_options)
9
- assert_equal :some_id, assoc.id
10
- end
11
-
12
- def test_new
13
- ben = users(:ben)
14
- assoc = Authlogic::Session::AuthenticatesManyAssociation.new(UserSession, {:conditions => ["1 = ?", 1]}, :some_id)
15
- session = assoc.new(ben)
16
- assert_equal ben, session.unauthorized_record
17
- assert_equal({:find_options => {:conditions => ["1 = ?", 1]}, :id => :some_id}, session.scope)
18
- end
19
-
20
- def test_build
21
- binary_logic = companies(:binary_logic)
22
- ben = users(:ben)
23
- session = binary_logic.user_sessions.build(ben)
24
- assert_equal ben, session.unauthorized_record
25
- assert_equal({:find_options => {:conditions => "\"users\".company_id = #{binary_logic.id}"}, :id => nil}, session.scope)
26
- end
27
- end
28
- end
@@ -1,307 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class BaseTest < ActiveSupport::TestCase
5
- def test_activated
6
- assert UserSession.activated?
7
- Authlogic::Session::Base.controller = nil
8
- assert !UserSession.activated?
9
- end
10
-
11
- def test_controller
12
- Authlogic::Session::Base.controller = nil
13
- assert_nil Authlogic::Session::Base.controller
14
- thread1 = Thread.new do
15
- controller = MockController.new
16
- Authlogic::Session::Base.controller = controller
17
- assert_equal controller, Authlogic::Session::Base.controller
18
- end
19
- thread1.join
20
-
21
- assert_nil Authlogic::Session::Base.controller
22
-
23
- thread2 = Thread.new do
24
- controller = MockController.new
25
- Authlogic::Session::Base.controller = controller
26
- assert_equal controller, Authlogic::Session::Base.controller
27
- end
28
- thread2.join
29
-
30
- assert_nil Authlogic::Session::Base.controller
31
- end
32
-
33
- def test_create
34
- ben = users(:ben)
35
- assert !UserSession.create(:login => ben.login, :password => "badpw")
36
- assert UserSession.create(:login => ben.login, :password => "benrocks")
37
- assert_raise(Authlogic::Session::SessionInvalid) { UserSession.create!(:login => ben.login, :password => "badpw") }
38
- assert UserSession.create!(:login => ben.login, :password => "benrocks")
39
- end
40
-
41
- def test_find
42
- ben = users(:ben)
43
- assert !UserSession.find
44
- http_basic_auth_for(ben) { assert UserSession.find }
45
- set_cookie_for(ben)
46
- assert UserSession.find
47
- unset_cookie
48
- set_session_for(ben)
49
- session = UserSession.find
50
- assert session
51
- end
52
-
53
- def test_klass
54
- assert_equal User, UserSession.klass
55
- end
56
-
57
- def test_klass_name
58
- assert_equal "User", UserSession.klass_name
59
- end
60
-
61
- def test_record_method
62
- ben = users(:ben)
63
- set_session_for(ben)
64
- session = UserSession.find
65
- assert_equal ben, session.record
66
- assert_equal ben, session.user
67
- end
68
-
69
- def test_init
70
- UserSession.controller = nil
71
- assert_raise(Authlogic::Session::NotActivated) { UserSession.new }
72
- UserSession.controller = @controller
73
-
74
- session = UserSession.new
75
- assert session.respond_to?(:login)
76
- assert session.respond_to?(:login=)
77
- assert session.respond_to?(:password)
78
- assert session.respond_to?(:password=)
79
- assert session.respond_to?(:protected_password, true)
80
-
81
- session = UserSession.new(:my_id)
82
- assert_equal :my_id, session.id
83
-
84
- session = UserSession.new({:login => "login", :password => "pass", :remember_me => true}, :my_id)
85
- assert_equal "login", session.login
86
- assert_nil session.password
87
- assert_equal "pass", session.send(:protected_password)
88
- assert_equal true, session.remember_me
89
- assert_equal :my_id, session.id
90
-
91
- session = UserSession.new(users(:ben), true, :my_id)
92
- assert_nil session.login
93
- assert_nil session.password
94
- assert_nil session.send(:protected_password)
95
- assert session.remember_me
96
- assert_equal :my_id, session.id
97
- assert_equal users(:ben), session.unauthorized_record
98
- end
99
-
100
- def test_credentials
101
- session = UserSession.new
102
- session.credentials = {:login => "login", :password => "pass", :remember_me => true}
103
- assert_equal "login", session.login
104
- assert_nil session.password
105
- assert_equal "pass", session.send(:protected_password)
106
- assert_equal true, session.remember_me
107
- assert_equal({:password => "<Protected>", :login => "login"}, session.credentials)
108
- end
109
-
110
- def test_destroy
111
- ben = users(:ben)
112
- session = UserSession.new
113
- assert !session.valid?
114
- assert !session.errors.empty?
115
- assert session.destroy
116
- assert session.errors.empty?
117
- session.unauthorized_record = ben
118
- assert session.save
119
- assert session.record
120
- assert session.destroy
121
- assert !session.record
122
- end
123
-
124
- def test_errors
125
- session = UserSession.new
126
- assert session.errors.is_a?(Authlogic::Session::Errors)
127
- end
128
-
129
- def test_find_record
130
- # tested thoroughly in test_find
131
- end
132
-
133
- def test_id
134
- ben = users(:ben)
135
- session = UserSession.new(ben, :my_id)
136
- assert_equal :my_id, session.id
137
- assert_equal "my_id_user_credentials", session.cookie_key
138
- assert_equal "my_id_user_credentials", session.session_key
139
- end
140
-
141
- def test_inspect
142
- session = UserSession.new
143
- assert_equal "#<UserSession #{{:login=>nil, :password=>"<protected>"}.inspect}>", session.inspect
144
- session.login = "login"
145
- session.password = "pass"
146
- assert "#<UserSession #{{:login=>"login", :password=>"<protected>"}.inspect}>" == session.inspect
147
- end
148
-
149
- def test_new_session
150
- session = UserSession.new
151
- assert session.new_session?
152
-
153
- set_session_for(users(:ben))
154
- session = UserSession.find
155
- assert !session.new_session?
156
- end
157
-
158
- def test_remember_me
159
- session = UserSession.new
160
- assert_nil session.remember_me
161
- assert !session.remember_me?
162
-
163
- session.remember_me = false
164
- assert_equal false, session.remember_me
165
- assert !session.remember_me?
166
-
167
- session.remember_me = true
168
- assert_equal true, session.remember_me
169
- assert session.remember_me?
170
-
171
- session.remember_me = nil
172
- assert_nil session.remember_me
173
- assert !session.remember_me?
174
-
175
- session.remember_me = "1"
176
- assert_equal "1", session.remember_me
177
- assert session.remember_me?
178
-
179
- session.remember_me = "true"
180
- assert_equal "true", session.remember_me
181
- assert session.remember_me?
182
- end
183
-
184
- def test_remember_me_until
185
- session = UserSession.new
186
- assert_nil session.remember_me_until
187
-
188
- session.remember_me = true
189
- assert 3.months.from_now <= session.remember_me_until
190
- end
191
-
192
- def test_save_with_nothing
193
- session = UserSession.new
194
- assert !session.save
195
- assert session.new_session?
196
- end
197
-
198
- def test_save_with_credentials
199
- ben = users(:ben)
200
- session = UserSession.new(:login => ben.login, :password => "benrocks")
201
- assert session.save
202
- assert !session.new_session?
203
- assert_equal 1, session.record.login_count
204
- assert Time.now >= session.record.current_login_at
205
- assert_equal "1.1.1.1", session.record.current_login_ip
206
- end
207
-
208
- def test_save_with_record
209
- ben = users(:ben)
210
- session = UserSession.new(ben)
211
- assert session.save
212
- assert !session.new_session?
213
- assert_equal 1, session.record.login_count
214
- assert Time.now >= session.record.current_login_at
215
- assert_equal "1.1.1.1", session.record.current_login_ip
216
- end
217
-
218
- def test_save_with_block
219
- ben = users(:ben)
220
- session = UserSession.new(:login => ben.login, :password => "benrocks")
221
- block_result = session.save do |result|
222
- assert result
223
- end
224
- assert_equal session, block_result
225
- assert !session.new_session?
226
- assert_equal 1, session.record.login_count
227
- assert Time.now >= session.record.current_login_at
228
- assert_equal "1.1.1.1", session.record.current_login_ip
229
- end
230
-
231
- def test_save_with_bang
232
- session = UserSession.new
233
- assert_raise(Authlogic::Session::SessionInvalid) { session.save! }
234
-
235
- session.unauthorized_record = users(:ben)
236
- assert session.save!
237
- end
238
-
239
- def test_unauthorized_record
240
- session = UserSession.new
241
- ben = users(:ben)
242
- session.unauthorized_record = ben
243
- assert_equal ben, session.unauthorized_record
244
- assert_equal :unauthorized_record, session.authenticating_with
245
- end
246
-
247
- def test_valid
248
- session = UserSession.new
249
- assert !session.valid?
250
- assert_nil session.record
251
- assert session.errors.count > 0
252
-
253
- ben = users(:ben)
254
- session.unauthorized_record = ben
255
- assert session.valid?
256
- assert_equal ben, session.record
257
- assert session.errors.empty?
258
- end
259
-
260
- def test_valid_record
261
- session = UserSession.new
262
- ben = users(:ben)
263
- session.send(:record=, ben)
264
- assert session.send(:valid_record?)
265
- assert session.errors.empty?
266
-
267
- ben.update_attribute(:active, false)
268
- assert !session.send(:valid_record?)
269
- assert session.errors.on_base.size > 0
270
-
271
- ben.active = true
272
- ben.approved = false
273
- ben.save
274
- assert !session.send(:valid_record?)
275
- assert session.errors.on_base.size > 0
276
-
277
- ben.approved = true
278
- ben.confirmed = false
279
- ben.save
280
- assert !session.send(:valid_record?)
281
- assert session.errors.on_base.size > 0
282
-
283
- ben.approved = false
284
- ben.confirmed = false
285
- ben.active = false
286
-
287
- UserSession.disable_magic_states = true
288
- session = UserSession.new
289
- session.send(:record=, ben)
290
- assert session.send(:valid_record?)
291
- end
292
-
293
- def test_valid_http_auth
294
- ben = users(:ben)
295
- session = UserSession.new
296
-
297
- http_basic_auth_for { assert !session.valid_http_auth? }
298
-
299
- http_basic_auth_for(ben) do
300
- assert session.valid_http_auth?
301
- assert_equal ben, session.record
302
- assert_equal ben.login, session.login
303
- assert_equal "benrocks", session.send(:protected_password)
304
- end
305
- end
306
- end
307
- end