authlogic 1.1.0 → 1.1.1

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 (39) hide show
  1. data/CHANGELOG.rdoc +11 -2
  2. data/Manifest +9 -3
  3. data/README.rdoc +32 -7
  4. data/Rakefile +1 -1
  5. data/authlogic.gemspec +4 -7
  6. data/lib/authlogic.rb +2 -4
  7. data/lib/authlogic/controller_adapters/abstract_adapter.rb +4 -0
  8. data/lib/authlogic/controller_adapters/rails_adapter.rb +4 -0
  9. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb +2 -76
  10. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb +132 -0
  11. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb +77 -116
  12. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb +35 -24
  13. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb +51 -44
  14. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb +64 -54
  15. data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb +61 -0
  16. data/lib/authlogic/session/base.rb +20 -9
  17. data/lib/authlogic/session/config.rb +54 -63
  18. data/lib/authlogic/session/cookies.rb +2 -2
  19. data/lib/authlogic/session/params.rb +9 -6
  20. data/lib/authlogic/session/session.rb +3 -3
  21. data/lib/authlogic/version.rb +1 -1
  22. data/shoulda_macros/authlogic.rb +13 -0
  23. data/test/fixtures/employees.yml +2 -2
  24. data/test/fixtures/users.yml +2 -0
  25. data/test/libs/mock_controller.rb +5 -0
  26. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb +36 -0
  27. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb +129 -0
  28. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb +24 -0
  29. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb +45 -0
  30. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb +62 -0
  31. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb +41 -0
  32. data/test/session_tests/base_test.rb +15 -0
  33. data/test/session_tests/config_test.rb +31 -14
  34. data/test/session_tests/params_test.rb +17 -1
  35. data/test/test_helper.rb +10 -2
  36. metadata +18 -17
  37. data/lib/authlogic/session/openid.rb +0 -106
  38. data/lib/authlogic/testing/shoulda_macros.rb +0 -17
  39. data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_test.rb +0 -217
@@ -7,10 +7,26 @@ module SessionTests
7
7
  session = UserSession.new
8
8
 
9
9
  assert !session.valid_params?
10
-
11
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")
12
27
  assert session.valid_params?
13
28
  assert_equal ben, session.unauthorized_record
29
+ assert !@controller.session["user_credentials"]
14
30
  end
15
31
  end
16
32
  end
data/test/test_helper.rb CHANGED
@@ -38,8 +38,8 @@ ActiveRecord::Schema.define(:version => 1) do
38
38
  t.string :login
39
39
  t.string :crypted_password
40
40
  t.string :password_salt
41
- t.string :openid
42
41
  t.string :remember_token
42
+ t.string :single_access_token
43
43
  t.string :first_name
44
44
  t.string :last_name
45
45
  t.integer :login_count
@@ -134,13 +134,21 @@ class Test::Unit::TestCase
134
134
  end
135
135
 
136
136
  def set_params_for(user, id = nil)
137
- @controller.params["user_credentials"] = user.remember_token
137
+ @controller.params["user_credentials"] = user.single_access_token
138
138
  end
139
139
 
140
140
  def unset_params
141
141
  @controller.params["user_credentials"] = nil
142
142
  end
143
143
 
144
+ def set_request_content_type(type)
145
+ @controller.request_content_type = type
146
+ end
147
+
148
+ def unset_request_content_type
149
+ @controller.request_content_type = nil
150
+ end
151
+
144
152
  def set_session_for(user, id = nil)
145
153
  @controller.session["user_credentials"] = user.remember_token
146
154
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic
@@ -22,16 +22,6 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
24
  version:
25
- - !ruby/object:Gem::Dependency
26
- name: activerecord
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
35
25
  - !ruby/object:Gem::Dependency
36
26
  name: echoe
37
27
  type: :development
@@ -55,10 +45,12 @@ extra_rdoc_files:
55
45
  - lib/authlogic/controller_adapters/rails_adapter.rb
56
46
  - lib/authlogic/crypto_providers/sha1.rb
57
47
  - lib/authlogic/crypto_providers/sha512.rb
48
+ - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb
58
49
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb
59
50
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb
60
51
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb
61
52
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb
53
+ - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb
62
54
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb
63
55
  - lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb
64
56
  - lib/authlogic/session/active_record_trickery.rb
@@ -68,11 +60,9 @@ extra_rdoc_files:
68
60
  - lib/authlogic/session/config.rb
69
61
  - lib/authlogic/session/cookies.rb
70
62
  - lib/authlogic/session/errors.rb
71
- - lib/authlogic/session/openid.rb
72
63
  - lib/authlogic/session/params.rb
73
64
  - lib/authlogic/session/scopes.rb
74
65
  - lib/authlogic/session/session.rb
75
- - lib/authlogic/testing/shoulda_macros.rb
76
66
  - lib/authlogic/version.rb
77
67
  - lib/authlogic.rb
78
68
  - README.rdoc
@@ -84,10 +74,12 @@ files:
84
74
  - lib/authlogic/controller_adapters/rails_adapter.rb
85
75
  - lib/authlogic/crypto_providers/sha1.rb
86
76
  - lib/authlogic/crypto_providers/sha512.rb
77
+ - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb
87
78
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb
88
79
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb
89
80
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb
90
81
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb
82
+ - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb
91
83
  - lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic.rb
92
84
  - lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb
93
85
  - lib/authlogic/session/active_record_trickery.rb
@@ -97,17 +89,16 @@ files:
97
89
  - lib/authlogic/session/config.rb
98
90
  - lib/authlogic/session/cookies.rb
99
91
  - lib/authlogic/session/errors.rb
100
- - lib/authlogic/session/openid.rb
101
92
  - lib/authlogic/session/params.rb
102
93
  - lib/authlogic/session/scopes.rb
103
94
  - lib/authlogic/session/session.rb
104
- - lib/authlogic/testing/shoulda_macros.rb
105
95
  - lib/authlogic/version.rb
106
96
  - lib/authlogic.rb
107
97
  - Manifest
108
98
  - MIT-LICENSE
109
99
  - Rakefile
110
100
  - README.rdoc
101
+ - shoulda_macros/authlogic.rb
111
102
  - test/fixtures/companies.yml
112
103
  - test/fixtures/employees.yml
113
104
  - test/fixtures/projects.yml
@@ -117,7 +108,12 @@ files:
117
108
  - test/libs/mock_cookie_jar.rb
118
109
  - test/libs/mock_request.rb
119
110
  - test/libs/ordered_hash.rb
120
- - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_test.rb
111
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb
112
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb
113
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb
114
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb
115
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb
116
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb
121
117
  - test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb
122
118
  - test/session_tests/active_record_trickery_test.rb
123
119
  - test/session_tests/authenticates_many_association_test.rb
@@ -161,7 +157,12 @@ signing_key:
161
157
  specification_version: 2
162
158
  summary: A clean, simple, and unobtrusive ruby authentication solution.
163
159
  test_files:
164
- - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_test.rb
160
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb
161
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb
162
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb
163
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb
164
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb
165
+ - test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb
165
166
  - test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb
166
167
  - test/session_tests/active_record_trickery_test.rb
167
168
  - test/session_tests/authenticates_many_association_test.rb
@@ -1,106 +0,0 @@
1
- module Authlogic
2
- module Session
3
- module OpenID
4
- def self.included(klass)
5
- klass.class_eval do
6
- alias_method_chain :initialize, :openid
7
- alias_method_chain :credentials=, :openid
8
- alias_method_chain :create_configurable_methods!, :openid
9
- before_validation :valid_openid?
10
- attr_accessor :openid_response
11
- end
12
- end
13
-
14
- def initialize_with_openid(*args)
15
- initialize_without_openid(*args)
16
- self.authenticating_with = :openid if openid_verification_complete?
17
- end
18
-
19
- def credentials_with_openid=(values)
20
- result = self.credentials_without_openid = values
21
- return result if openid_field.blank? || values.blank? || !values.is_a?(Hash) || values[:openid].blank?
22
- self.openid = values[:openid]
23
- result
24
- end
25
-
26
- # Returns true if logging in with openid. Credentials mean username and password.
27
- def authenticating_with_openid?
28
- authenticating_with == :openid
29
- end
30
-
31
- def verify_openid?
32
- authenticating_with_openid? && controller.params[:openid_complete] != "1"
33
- end
34
-
35
- def openid_verified?
36
- controller.params[:openid_complete] == "1"
37
- end
38
-
39
- def valid_openid?
40
- return false if openid_field.blank?
41
-
42
- if openid_verification_complete?
43
- case openid_response.status
44
- when OpenID::Consumer::SUCCESS
45
-
46
- when OpenID::Consumer::CANCEL
47
- errors.add_to_base("OpenID authentication was cancelled.")
48
- when OpenID::Consumer::FAILURE
49
- errors.add_to_base("OpenID authentication failed.")
50
- when OpenID::Consumer::SETUP_NEEDED
51
- errors.add_to_Base("OpenID authentication needs setup.")
52
- end
53
- else
54
- if authenticating_with_openid?
55
- if send(openid_field).blank?
56
- errors.add(openid_field, "can not be blank")
57
- return false
58
- end
59
-
60
- unless search_for_record(find_by_openid_method, send(openid_field))
61
- errors.add(openid_field, "did not match any records in our database")
62
- return false
63
- end
64
-
65
- begin
66
- self.openid_response = openid_consumer.begin(send(openid_field))
67
- rescue OpenID::OpenIDError => e
68
- errors.add("The OpenID identifier #{send(openid_field)} could not be found: #{e}")
69
- return false
70
- end
71
-
72
- sregreq = OpenID::SReg::Request.new
73
- # required fields
74
- #sregreq.request_fields(['email','nickname'], true)
75
- # optional fields
76
- #sregreq.request_fields(['dob', 'fullname'], false)
77
- oidreq.add_extension(sregreq)
78
- oidreq.return_to_args["openid_complete"] = 1
79
- end
80
- end
81
- end
82
-
83
- private
84
- def create_configurable_methods_with_openid!
85
- create_configurable_methods_without_openid!
86
-
87
- return if openid_field.blank? || respond_to?(openid_field)
88
-
89
- if openid_field
90
- self.class.class_eval <<-"end_eval", __FILE__, __LINE__
91
- attr_reader :#{openid_field}
92
-
93
- def #{openid_field}=(value)
94
- self.authenticating_with = :openid
95
- @#{openid_field} = value
96
- end
97
- end_eval
98
- end
99
- end
100
-
101
- def openid_consumer
102
- @openid_consumer ||= OpenID::Consumer.new(controller.session, OpenID::FilesystemStore.new(openid_file_store_path))
103
- end
104
- end
105
- end
106
- end
@@ -1,17 +0,0 @@
1
- require "test/unit"
2
-
3
- module Authlogic
4
- module Testing
5
- module ShouldaMacros
6
- def should_be_authentic(model)
7
- should "acts as authentic" do
8
- assert model.respond_to?(:unique_token)
9
- assert model.respond_to?(:forget_all!)
10
- assert model.respond_to?(:crypto_provider)
11
- end
12
- end
13
- end
14
- end
15
- end
16
-
17
- Test::Unit::TestCase.extend Authlogic::Testing::ShouldaMacros
@@ -1,217 +0,0 @@
1
- require File.dirname(__FILE__) + '/../../test_helper.rb'
2
-
3
- module ORMAdaptersTests
4
- module ActiveRecordAdapterTests
5
- class ActsAsAuthenticTest < ActiveSupport::TestCase
6
- def test_user_validations
7
- user = User.new
8
- assert !user.valid?
9
- assert user.errors.on(:login)
10
- assert user.errors.on(:password)
11
-
12
- user.login = "a"
13
- assert !user.valid?
14
- assert user.errors.on(:login)
15
- assert user.errors.on(:password)
16
-
17
- user.login = "%ben*"
18
- assert !user.valid?
19
- assert user.errors.on(:login)
20
- assert user.errors.on(:password)
21
-
22
- user.login = "bjohnson"
23
- assert !user.valid?
24
- assert user.errors.on(:login)
25
- assert user.errors.on(:password)
26
-
27
- user.login = "my login"
28
- assert !user.valid?
29
- assert !user.errors.on(:login)
30
- assert user.errors.on(:password)
31
-
32
- user.password = "my pass"
33
- assert !user.valid?
34
- assert !user.errors.on(:password)
35
- assert user.errors.on(:confirm_password)
36
-
37
- user.confirm_password = "my pizass"
38
- assert !user.valid?
39
- assert !user.errors.on(:password)
40
- assert user.errors.on(:confirm_password)
41
-
42
- user.confirm_password = "my pass"
43
- assert user.valid?
44
- end
45
-
46
- def test_employee_validations
47
- employee = Employee.new
48
- employee.password = "pass"
49
- employee.confirm_password = "pass"
50
-
51
- assert !employee.valid?
52
- assert employee.errors.on(:email)
53
-
54
- employee.email = "fdsf"
55
- assert !employee.valid?
56
- assert employee.errors.on(:email)
57
-
58
- employee.email = "fake@email.fake"
59
- assert !employee.valid?
60
- assert employee.errors.on(:email)
61
-
62
- employee.email = "notfake@email.com"
63
- assert employee.valid?
64
- end
65
-
66
- def test_named_scopes
67
- assert_equal 0, User.logged_in.count
68
- assert_equal User.count, User.logged_out.count
69
- http_basic_auth_for(users(:ben)) { UserSession.find }
70
- assert_equal 1, User.logged_in.count
71
- assert_equal User.count - 1, User.logged_out.count
72
- end
73
-
74
- def test_unique_token
75
- assert_equal 128, User.unique_token.length
76
- assert_equal 128, Employee.unique_token.length # make sure encryptions use hashes also
77
-
78
- unique_tokens = []
79
- 1000.times { unique_tokens << User.unique_token }
80
- unique_tokens.uniq!
81
-
82
- assert_equal 1000, unique_tokens.size
83
- end
84
-
85
- def test_crypto_provider
86
- assert_equal Authlogic::CryptoProviders::Sha512, User.crypto_provider
87
- assert_equal AES128CryptoProvider, Employee.crypto_provider
88
- end
89
-
90
- def test_forget_all
91
- http_basic_auth_for(users(:ben)) { UserSession.find }
92
- http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) }
93
- assert UserSession.find
94
- assert UserSession.find(:ziggity_zack)
95
- User.forget_all!
96
- assert !UserSession.find
97
- assert !UserSession.find(:ziggity_zack)
98
- end
99
-
100
- def test_logged_in
101
- ben = users(:ben)
102
- assert !ben.logged_in?
103
- http_basic_auth_for(ben) { UserSession.find }
104
- assert ben.reload.logged_in?
105
- end
106
-
107
- def test_password
108
- user = User.new
109
- user.password = "sillywilly"
110
- assert user.crypted_password
111
- assert user.password_salt
112
- assert user.remember_token
113
- assert_equal true, user.tried_to_set_password
114
- assert_nil user.password
115
-
116
- employee = Employee.new
117
- employee.password = "awesome"
118
- assert employee.crypted_password
119
- assert employee.remember_token
120
- assert_equal true, employee.tried_to_set_password
121
- assert_nil employee.password
122
- end
123
-
124
- def test_valid_password
125
- ben = users(:ben)
126
- assert ben.valid_password?("benrocks")
127
- assert ben.valid_password?(ben.crypted_password)
128
-
129
- drew = employees(:drew)
130
- assert drew.valid_password?("drewrocks")
131
- assert drew.valid_password?(drew.crypted_password)
132
- end
133
-
134
- def test_forget
135
- ben = users(:ben)
136
- zack = users(:zack)
137
- http_basic_auth_for(ben) { UserSession.find }
138
- http_basic_auth_for(zack) { UserSession.find(:ziggity_zack) }
139
-
140
- assert ben.reload.logged_in?
141
- assert zack.reload.logged_in?
142
-
143
- ben.forget!
144
-
145
- assert !UserSession.find
146
- assert UserSession.find(:ziggity_zack)
147
- end
148
-
149
- def test_reset_password
150
- ben = users(:ben)
151
- UserSession.create(ben)
152
- old_password = ben.crypted_password
153
- old_salt = ben.password_salt
154
- old_remember_token = ben.remember_token
155
- ben.reset_password!
156
- ben.reload
157
- assert_not_equal old_password, ben.crypted_password
158
- assert_not_equal old_salt, ben.password_salt
159
- assert_not_equal old_remember_token, ben.remember_token
160
- assert !UserSession.find
161
- end
162
-
163
- def test_login_after_create
164
- assert User.create(:login => "awesome", :password => "saweet", :confirm_password => "saweet")
165
- assert UserSession.find
166
- end
167
-
168
- def test_update_session_after_password_modify
169
- ben = users(:ben)
170
- UserSession.create(ben)
171
- old_session_key = @controller.session["user_credentials"]
172
- old_cookie_key = @controller.cookies["user_credentials"]
173
- ben.password = "newpass"
174
- ben.confirm_password = "newpass"
175
- ben.save
176
- assert @controller.session["user_credentials"]
177
- assert @controller.cookies["user_credentials"]
178
- assert_not_equal @controller.session["user_credentials"], old_session_key
179
- assert_not_equal @controller.cookies["user_credentials"], old_cookie_key
180
- end
181
-
182
- def test_no_session_update_after_modify
183
- ben = users(:ben)
184
- UserSession.create(ben)
185
- old_session_key = @controller.session["user_credentials"]
186
- old_cookie_key = @controller.cookies["user_credentials"]
187
- ben.first_name = "Ben"
188
- ben.save
189
- assert_equal @controller.session["user_credentials"], old_session_key
190
- assert_equal @controller.cookies["user_credentials"], old_cookie_key
191
- end
192
-
193
- def test_updating_other_user
194
- ben = users(:ben)
195
- UserSession.create(ben)
196
- old_session_key = @controller.session["user_credentials"]
197
- old_cookie_key = @controller.cookies["user_credentials"]
198
- zack = users(:zack)
199
- zack.password = "newpass"
200
- zack.confirm_password = "newpass"
201
- zack.save
202
- assert_equal @controller.session["user_credentials"], old_session_key
203
- assert_equal @controller.cookies["user_credentials"], old_cookie_key
204
- end
205
-
206
- def test_resetting_password_when_logged_out
207
- ben = users(:ben)
208
- assert !UserSession.find
209
- ben.password = "newpass"
210
- ben.confirm_password = "newpass"
211
- ben.save
212
- assert UserSession.find
213
- assert_equal ben, UserSession.find.record
214
- end
215
- end
216
- end
217
- end