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,53 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class BruteForceProtectionTest < ActiveSupport::TestCase
5
- def test_under_limit
6
- ben = users(:ben)
7
- ben.failed_login_count = UserSession.consecutive_failed_logins_limit - 1
8
- assert ben.save
9
- assert UserSession.create(:login => ben.login, :password => "benrocks")
10
- end
11
-
12
- def test_exceeded_limit
13
- ben = users(:ben)
14
- ben.failed_login_count = UserSession.consecutive_failed_logins_limit
15
- assert ben.save
16
- assert !UserSession.create(:login => ben.login, :password => "benrocks")
17
- end
18
-
19
- def test_exeeding_failed_logins_limit
20
- UserSession.consecutive_failed_logins_limit = 2
21
- ben = users(:ben)
22
-
23
- 2.times do |i|
24
- session = UserSession.new(:login => ben.login, :password => "badpassword")
25
- assert !session.save
26
- assert session.errors.on(:password)
27
- assert_equal i + 1, ben.reload.failed_login_count
28
- end
29
-
30
- session = UserSession.new(:login => ben.login, :password => "badpassword2")
31
- assert !session.save
32
- assert !session.errors.on(:password)
33
- assert_equal 2, ben.reload.failed_login_count
34
-
35
- UserSession.consecutive_failed_logins_limit = 50
36
- end
37
-
38
- def test_resetting_failed_logins_count
39
- ben = users(:ben)
40
-
41
- 2.times do |i|
42
- session = UserSession.new(:login => ben.login, :password => "badpassword")
43
- assert !session.save
44
- assert session.errors.on(:password)
45
- assert_equal i + 1, ben.reload.failed_login_count
46
- end
47
-
48
- session = UserSession.new(:login => ben.login, :password => "benrocks")
49
- assert session.save
50
- assert_equal 0, ben.reload.failed_login_count
51
- end
52
- end
53
- end
@@ -1,184 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class ConfigTest < ActiveSupport::TestCase
5
- def test_authenticate_with
6
- UserSession.authenticate_with = Employee
7
- assert_equal "Employee", UserSession.klass_name
8
- assert_equal Employee, UserSession.klass
9
-
10
- UserSession.authenticate_with User
11
- assert_equal "User", UserSession.klass_name
12
- assert_equal User, UserSession.klass
13
- end
14
-
15
- def test_cookie_key
16
- UserSession.cookie_key = "my_cookie_key"
17
- assert_equal "my_cookie_key", UserSession.cookie_key
18
- session = UserSession.new
19
- assert_equal "my_cookie_key", session.cookie_key
20
-
21
- UserSession.cookie_key "user_credentials"
22
- assert_equal "user_credentials", UserSession.cookie_key
23
- session = UserSession.new
24
- assert_equal "user_credentials", session.cookie_key
25
- end
26
-
27
- def test_disable_magic_states
28
- UserSession.disable_magic_states = true
29
- assert_equal true, UserSession.disable_magic_states
30
- session = UserSession.new
31
- assert_equal true, session.disable_magic_states?
32
-
33
- UserSession.disable_magic_states false
34
- assert_equal false, UserSession.disable_magic_states
35
- session = UserSession.new
36
- assert_equal false, session.disable_magic_states?
37
- end
38
-
39
- def test_find_by_login_method
40
- UserSession.find_by_login_method = "my_login_method"
41
- assert_equal "my_login_method", UserSession.find_by_login_method
42
- session = UserSession.new
43
- assert_equal "my_login_method", session.find_by_login_method
44
-
45
- UserSession.find_by_login_method "find_by_login"
46
- assert_equal "find_by_login", UserSession.find_by_login_method
47
- session = UserSession.new
48
- assert_equal "find_by_login", session.find_by_login_method
49
- end
50
-
51
- def test_find_with
52
- UserSession.find_with = [:session]
53
- assert_equal [:session], UserSession.find_with
54
- session = UserSession.new
55
- assert_equal [:session], session.find_with
56
-
57
- set_cookie_for(users(:ben))
58
- assert !UserSession.find
59
-
60
- UserSession.find_with :session, :cookie, :http_auth
61
- assert_equal [:session, :cookie, :http_auth], UserSession.find_with
62
- session = UserSession.new
63
- assert_equal [:session, :cookie, :http_auth], session.find_with
64
-
65
- assert UserSession.find
66
- end
67
-
68
- def test_last_request_at_threshold
69
- UserSession.last_request_at_threshold = 2.minutes
70
- assert_equal 2.minutes, UserSession.last_request_at_threshold
71
- session = UserSession.new
72
- assert_equal 2.minutes, session.last_request_at_threshold
73
-
74
- UserSession.last_request_at_threshold 0
75
- assert_equal 0, UserSession.last_request_at_threshold
76
- session = UserSession.new
77
- assert_equal 0, session.last_request_at_threshold
78
- end
79
-
80
- def test_login_field
81
- UserSession.methods_configured = false
82
- UserSession.login_field = :saweet
83
- assert_equal :saweet, UserSession.login_field
84
- session = UserSession.new
85
- assert_equal :saweet, session.login_field
86
- assert session.respond_to?(:saweet)
87
-
88
- UserSession.login_field :login
89
- assert_equal :login, UserSession.login_field
90
- session = UserSession.new
91
- assert_equal :login, session.login_field
92
- assert session.respond_to?(:login)
93
- end
94
-
95
- def test_params_key
96
- UserSession.params_key = "my_params_key"
97
- assert_equal "my_params_key", UserSession.params_key
98
- session = UserSession.new
99
- assert_equal "my_params_key", session.params_key
100
-
101
- UserSession.params_key "user_credentials"
102
- assert_equal "user_credentials", UserSession.params_key
103
- session = UserSession.new
104
- assert_equal "user_credentials", session.params_key
105
- end
106
-
107
- def test_password_field
108
- UserSession.methods_configured = false
109
- UserSession.password_field = :saweet
110
- assert_equal :saweet, UserSession.password_field
111
- session = UserSession.new
112
- assert_equal :saweet, session.password_field
113
- assert session.respond_to?(:saweet)
114
-
115
- UserSession.password_field :password
116
- assert_equal :password, UserSession.password_field
117
- session = UserSession.new
118
- assert_equal :password, session.password_field
119
- assert session.respond_to?(:password)
120
- end
121
-
122
- def test_remember_me
123
- UserSession.remember_me = true
124
- assert_equal true, UserSession.remember_me
125
- session = UserSession.new
126
- assert_equal true, session.remember_me
127
-
128
- UserSession.remember_me false
129
- assert_equal false, UserSession.remember_me
130
- session = UserSession.new
131
- assert_equal false, session.remember_me
132
- end
133
-
134
- def test_remember_me_for
135
- UserSession.remember_me_for = 3.years
136
- assert_equal 3.years, UserSession.remember_me_for
137
- session = UserSession.new
138
- session.remember_me = true
139
- assert_equal 3.years, session.remember_me_for
140
-
141
- UserSession.remember_me_for 3.months
142
- assert_equal 3.months, UserSession.remember_me_for
143
- session = UserSession.new
144
- session.remember_me = true
145
- assert_equal 3.months, session.remember_me_for
146
- end
147
-
148
- def test_session_key
149
- UserSession.session_key = "my_session_key"
150
- assert_equal "my_session_key", UserSession.session_key
151
- session = UserSession.new
152
- assert_equal "my_session_key", session.session_key
153
-
154
- UserSession.session_key "user_credentials"
155
- assert_equal "user_credentials", UserSession.session_key
156
- session = UserSession.new
157
- assert_equal "user_credentials", session.session_key
158
- end
159
-
160
- def test_single_access_allowed_request_types
161
- UserSession.single_access_allowed_request_types = "my request type"
162
- assert_equal ["my request type"], UserSession.single_access_allowed_request_types
163
- session = UserSession.new
164
- assert_equal ["my request type"], session.single_access_allowed_request_types
165
-
166
- UserSession.single_access_allowed_request_types "application/rss+xml", "application/atom+xml"
167
- assert_equal ["application/rss+xml", "application/atom+xml"], UserSession.single_access_allowed_request_types
168
- session = UserSession.new
169
- assert_equal ["application/rss+xml", "application/atom+xml"], session.single_access_allowed_request_types
170
- end
171
-
172
- def test_verify_password_method
173
- UserSession.verify_password_method = "my_login_method"
174
- assert_equal "my_login_method", UserSession.verify_password_method
175
- session = UserSession.new
176
- assert_equal "my_login_method", session.verify_password_method
177
-
178
- UserSession.verify_password_method "valid_password?"
179
- assert_equal "valid_password?", UserSession.verify_password_method
180
- session = UserSession.new
181
- assert_equal "valid_password?", session.verify_password_method
182
- end
183
- end
184
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class CookiesTest < ActiveSupport::TestCase
5
- def test_valid_cookie
6
- ben = users(:ben)
7
- session = UserSession.new
8
-
9
- assert !session.valid_cookie?
10
-
11
- set_cookie_for(ben)
12
- assert session.valid_cookie?
13
- assert_equal ben, session.unauthorized_record
14
- end
15
-
16
- def test_save
17
- ben = users(:ben)
18
- session = UserSession.new(ben)
19
- assert session.save
20
- assert_equal ben.persistence_token, @controller.cookies["user_credentials"]
21
- end
22
-
23
- def test_destroy
24
- ben = users(:ben)
25
- set_cookie_for(ben)
26
- session = UserSession.find
27
- assert @controller.cookies["user_credentials"]
28
- assert session.destroy
29
- assert !@controller.cookies["user_credentials"]
30
- end
31
- end
32
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class ParamsTest < ActiveSupport::TestCase
5
- def test_valid_params
6
- ben = users(:ben)
7
- session = UserSession.new
8
-
9
- assert !session.valid_params?
10
- set_params_for(ben)
11
-
12
- assert !session.valid_params?
13
- assert !session.unauthorized_record
14
- assert !@controller.session["user_credentials"]
15
-
16
- set_request_content_type("text/plain")
17
- assert !session.valid_params?
18
- assert !session.unauthorized_record
19
- assert !@controller.session["user_credentials"]
20
-
21
- set_request_content_type("application/atom+xml")
22
- assert session.valid_params?
23
- assert_equal ben, session.unauthorized_record
24
- assert !@controller.session["user_credentials"]
25
-
26
- set_request_content_type("application/rss+xml")
27
- assert session.valid_params?
28
- assert_equal ben, session.unauthorized_record
29
- assert !@controller.session["user_credentials"]
30
- end
31
- end
32
- end
@@ -1,45 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class SessionTest < ActiveSupport::TestCase
5
- def test_valid_session
6
- ben = users(:ben)
7
- session = UserSession.new
8
-
9
- assert !session.valid_session?
10
-
11
- set_session_for(ben)
12
- assert session.valid_session?
13
- assert session.find_record
14
- assert_equal ben, session.record
15
- assert_equal ben.persistence_token, @controller.session["user_credentials"]
16
- assert_equal ben, session.unauthorized_record
17
- assert !session.new_session?
18
- end
19
-
20
- def test_save
21
- ben = users(:ben)
22
- session = UserSession.new(ben)
23
- assert @controller.session["user_credentials"].blank?
24
- assert session.save
25
- assert_equal ben.persistence_token, @controller.session["user_credentials"]
26
- end
27
-
28
- def test_destroy
29
- ben = users(:ben)
30
- set_session_for(ben)
31
- assert_equal ben.persistence_token, @controller.session["user_credentials"]
32
- session = UserSession.find
33
- assert session.destroy
34
- assert @controller.session["user_credentials"].blank?
35
- end
36
-
37
- def test_find
38
- ben = users(:ben)
39
- set_cookie_for(ben)
40
- assert @controller.session["user_credentials"].blank?
41
- assert UserSession.find
42
- assert_equal ben.persistence_token, @controller.session["user_credentials"]
43
- end
44
- end
45
- end
@@ -1,71 +0,0 @@
1
- require File.dirname(__FILE__) + '/../test_helper.rb'
2
-
3
- module SessionTests
4
- class TimeoutTest < ActiveSupport::TestCase
5
- def test_after_find
6
- ben = users(:ben)
7
- set_session_for(ben)
8
- session = UserSession.find
9
- assert session
10
- assert !session.record.last_request_at.nil?
11
-
12
- UserSession.last_request_at_threshold = 2.seconds
13
- assert_equal 2.seconds, UserSession.last_request_at_threshold
14
-
15
- assert UserSession.find
16
- last_request_at = ben.reload.last_request_at
17
- sleep(0.5)
18
- assert UserSession.find
19
- assert_equal last_request_at, ben.reload.last_request_at
20
- sleep(2)
21
- assert UserSession.find
22
- assert_not_equal last_request_at, ben.reload.last_request_at
23
-
24
- UserSession.last_request_at_threshold 0
25
- assert_equal 0, UserSession.last_request_at_threshold
26
- end
27
-
28
- def test_after_save
29
- ben = users(:ben)
30
- session = UserSession.new(ben)
31
- assert session.save
32
- assert !session.record.last_request_at.nil?
33
- assert !session.stale?
34
- end
35
-
36
- def test_not_stale
37
- UserSession.logout_on_timeout = true
38
- ben = users(:ben)
39
- ben.update_attribute(:last_request_at, Time.now)
40
- set_session_for(ben)
41
- session = UserSession.find
42
- assert !session.stale?
43
- end
44
-
45
- def test_stale
46
- ben = users(:ben)
47
- set_session_for(ben)
48
- ben.update_attribute(:last_request_at, 3.years.ago)
49
- session = UserSession.find
50
- assert session.stale?
51
- assert_nil @controller.session["user_credentials"]
52
- assert_nil @controller.session["user_credentials_id"]
53
- UserSession.logout_on_timeout = false
54
- end
55
-
56
- def test_stale_find
57
- UserSession.logout_on_timeout = true
58
- ben = users(:ben)
59
-
60
- ben.update_attribute(:last_request_at, 3.years.ago)
61
- set_session_for(ben)
62
- session = UserSession.find
63
- assert session.stale?
64
-
65
- ben.update_attribute(:last_request_at, Time.now)
66
- set_session_for(ben)
67
- session = UserSession.find
68
- assert !session.stale?
69
- end
70
- end
71
- end